Convert PartPipe to Scala

This commit is contained in:
Calclavia 2014-09-14 14:16:28 +08:00
parent 362b00865d
commit 3498515d8f
10 changed files with 73 additions and 300 deletions

View file

@ -58,6 +58,7 @@ object ResonantInduction
@EventHandler
def init(evt: FMLInitializationEvent)
{
//TODO: Why is there an if statement check here?
if (ResonantInduction.metadata != null)
{
ResonantInduction.metadata.modId = Reference.name

View file

@ -12,10 +12,13 @@ import resonantinduction.core.util.ResonantUtil
* Trait applied to objects that can associates with a color.
* @author Calclavia
*/
trait TColorable extends TMultiPart with TPart
object TColorable
{
val defaultColor = 15
var colorID = defaultColor
}
trait TColorable extends TMultiPart with TPart
{
var colorID = TColorable.defaultColor
def getColor = colorID

View file

@ -3,13 +3,12 @@ package resonantinduction.mechanical;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import resonant.content.loader.ModManager;
import resonant.content.prefab.itemblock.ItemBlockMetadata;
import resonant.engine.content.debug.TileCreativeBuilder;
import resonant.lib.network.discriminator.PacketAnnotationManager;
import resonantinduction.core.ResonantTab;
import resonantinduction.mechanical.energy.grid.MechanicalNode;
import resonantinduction.mechanical.fluid.pipe.PipeMaterial;
import resonantinduction.mechanical.turbine.*;
import resonantinduction.mechanical.fluid.pipe.EnumPipeMaterial;
import resonantinduction.mechanical.fluid.pipe.ItemPipe;
import resonantinduction.mechanical.fluid.transport.TilePump;
import resonantinduction.mechanical.gear.ItemGear;
@ -27,7 +26,6 @@ import net.minecraftforge.oredict.OreDictionary;
import net.minecraftforge.oredict.ShapedOreRecipe;
import resonant.lib.recipe.UniversalRecipe;
import resonantinduction.core.Reference;
import resonantinduction.core.ResonantInduction;
import resonantinduction.core.interfaces.IMechanicalNode;
import resonantinduction.mechanical.process.mixer.TileMixer;
import cpw.mods.fml.common.Mod;
@ -42,8 +40,6 @@ import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import universalelectricity.api.core.grid.NodeRegistry;
import java.sql.Ref;
/**
* Resonant Induction Mechanical Module
*
@ -165,12 +161,12 @@ public class Mechanical
GameRegistry.addRecipe(new ShapedOreRecipe(blockPump, "PPP", "GGG", "PPP", 'P', itemPipe, 'G', new ItemStack(itemGear, 1, 2)));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(itemPipe, 3, EnumPipeMaterial.CERAMIC.ordinal()), "BBB", " ", "BBB", 'B', Items.brick));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(itemPipe, 3, EnumPipeMaterial.BRONZE.ordinal()), "BBB", " ", "BBB", 'B', "ingotBronze"));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(itemPipe, 3, EnumPipeMaterial.PLASTIC.ordinal()), "BBB", " ", "BBB", 'B', UniversalRecipe.RUBBER.get()));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(itemPipe, 3, EnumPipeMaterial.IRON.ordinal()), "BBB", " ", "BBB", 'B', Items.iron_ingot));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(itemPipe, 3, EnumPipeMaterial.STEEL.ordinal()), "BBB", " ", "BBB", 'B', "ingotSteel"));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(itemPipe, 3, EnumPipeMaterial.FIBERGLASS.ordinal()), "BBB", " ", "BBB", 'B', Items.diamond));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(itemPipe, 3, PipeMaterial.CERAMIC.ordinal()), "BBB", " ", "BBB", 'B', Items.brick));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(itemPipe, 3, PipeMaterial.BRONZE.ordinal()), "BBB", " ", "BBB", 'B', "ingotBronze"));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(itemPipe, 3, PipeMaterial.PLASTIC.ordinal()), "BBB", " ", "BBB", 'B', UniversalRecipe.RUBBER.get()));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(itemPipe, 3, PipeMaterial.IRON.ordinal()), "BBB", " ", "BBB", 'B', Items.iron_ingot));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(itemPipe, 3, PipeMaterial.STEEL.ordinal()), "BBB", " ", "BBB", 'B', "ingotSteel"));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(itemPipe, 3, PipeMaterial.FIBERGLASS.ordinal()), "BBB", " ", "BBB", 'B', Items.diamond));
GameRegistry.addRecipe(new ShapedOreRecipe(blockMechanicalPiston, "SGS", "SPS", "SRS", 'P', Blocks.piston, 'S', Items.iron_ingot, 'R', Items.redstone, 'G', new ItemStack(itemGear, 1, 2)));
GameRegistry.addRecipe(new ShapedOreRecipe(blockGrinderWheel, "III", "LGL", "III", 'I', UniversalRecipe.PRIMARY_METAL.get(), 'L', "logWood", 'G', itemGear));

View file

@ -1,30 +0,0 @@
package resonantinduction.mechanical.fluid.pipe;
import java.awt.Color;
/**
* Enumerator to hold info about each pipe material.
*
* @author Calclavia
*/
public enum EnumPipeMaterial
{
CERAMIC(5, 5, new Color(0xB3866F)), BRONZE(25, 25, new Color(0xD49568)),
PLASTIC(50, 30, new Color(0xDAF4F7)), IRON(100, 50, new Color(0x5C6362)),
STEEL(100, 100, new Color(0x888888)), FIBERGLASS(1000, 200, new Color(0x9F9691));
public final int maxPressure;
/**
* The max flow rate in liters of tick.
*/
public final int maxFlowRate;
public final Color color;
private EnumPipeMaterial(int maxFlowRate, int maxPressure, Color color)
{
this.maxFlowRate = maxFlowRate;
this.maxPressure = maxPressure;
this.color = color;
}
}

View file

@ -45,7 +45,7 @@ public class ItemPipe extends JItemMultiPart
@Override
public String getUnlocalizedName(ItemStack itemStack)
{
return super.getUnlocalizedName(itemStack) + "." + LanguageUtility.underscoreToCamel(EnumPipeMaterial.values()[itemStack.getItemDamage()].name());
return super.getUnlocalizedName(itemStack) + "." + LanguageUtility.underscoreToCamel(PipeMaterial.values()[itemStack.getItemDamage()].name());
}
@Override
@ -58,15 +58,15 @@ public class ItemPipe extends JItemMultiPart
}
else
{
list.add(EnumColor.AQUA + LanguageUtility.getLocal("tooltip.pipe.rate").replace("%v", "" + EnumColor.ORANGE + new UnitDisplay(UnitDisplay.Unit.LITER, EnumPipeMaterial.values()[itemstack.getItemDamage()].maxFlowRate * 20) + "/s"));
list.add(EnumColor.AQUA + LanguageUtility.getLocal("tooltip.pipe.pressure").replace("%v", "" + EnumColor.ORANGE + EnumPipeMaterial.values()[itemstack.getItemDamage()].maxPressure + " Pa"));
list.add(EnumColor.AQUA + LanguageUtility.getLocal("tooltip.pipe.rate").replace("%v", "" + EnumColor.ORANGE + new UnitDisplay(UnitDisplay.Unit.LITER, PipeMaterial.values()[itemstack.getItemDamage()].maxFlowRate * 20) + "/s"));
list.add(EnumColor.AQUA + LanguageUtility.getLocal("tooltip.pipe.pressure").replace("%v", "" + EnumColor.ORANGE + PipeMaterial.values()[itemstack.getItemDamage()].maxPressure + " Pa"));
}
}
@Override
public void getSubItems(Item itemID, CreativeTabs tab, List listToAddTo)
{
for (EnumPipeMaterial material : EnumPipeMaterial.values())
for (PipeMaterial material : PipeMaterial.values())
{
listToAddTo.add(new ItemStack(itemID, 1, material.ordinal()));
}

View file

@ -1,219 +0,0 @@
package resonantinduction.mechanical.fluid.pipe;
import codechicken.lib.data.MCDataInput;
import codechicken.lib.render.CCRenderState;
import codechicken.lib.vec.Cuboid6;
import codechicken.multipart.JNormalOcclusion;
import codechicken.multipart.TNormalOcclusion;
import codechicken.multipart.TSlottedPart;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.*;
import resonant.lib.type.EvictingList;
import resonantinduction.core.prefab.part.PartFramedNode;
import resonantinduction.mechanical.Mechanical;
import universalelectricity.api.core.grid.INode;
import java.util.Set;
/**
* Fluid transport pipe
*
* @author Calclavia, Darkguardsman
*/
public class PartPipe extends PartFramedNode<EnumPipeMaterial> implements TSlottedPart, TNormalOcclusion, IFluidHandler
{
protected final FluidTank tank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME);
/**
* Computes the average fluid for client to render.
*/
private EvictingList<Integer> averageTankData = new EvictingList<Integer>(20);
private boolean markPacket = true;
public PartPipe()
{
super(null);
setMaterial(0);
this.setRequiresInsulation(false);
setNode((INode) new PipePressureNode(this));
}
@Override
public void setMaterial(int i)
{
setMaterial(EnumPipeMaterial.values()[i]);
}
@Override
public int getMaterialID()
{
return 0;
}
@Override
public void setMaterial(EnumPipeMaterial material)
{
super.setMaterial(material);
}
@Override
public String getType()
{
return "resonant_induction_pipe";
}
@Override
public void update()
{
super.update();
averageTankData.add(tank.getFluidAmount());
if (!world().isRemote && markPacket)
{
sendFluidUpdate();
markPacket = false;
}
}
/**
* Sends fluid level to the client to be used in the renderer
*/
public void sendFluidUpdate()
{
NBTTagCompound nbt = new NBTTagCompound();
int averageAmount = 0;
if (averageTankData.size() > 0)
{
for (int i = 0; i < averageTankData.size(); i++)
{
averageAmount += averageTankData.get(i);
}
averageAmount /= averageTankData.size();
}
FluidTank tempTank = tank.getFluid() != null ? new FluidTank(tank.getFluid().getFluid(), averageAmount, tank.getCapacity()) : new FluidTank(tank.getCapacity());
tempTank.writeToNBT(nbt);
tile().getWriteStream(this).writeByte(3).writeInt(tank.getCapacity()).writeNBTTagCompound(nbt);
}
@Override
public void read(MCDataInput packet, int packetID)
{
if (packetID == 3)
{
tank.setCapacity(packet.readInt());
tank.readFromNBT(packet.readNBTTagCompound());
}
else
{
super.read(packet, packetID);
}
}
@Override
@SideOnly(Side.CLIENT)
public void renderDynamic(codechicken.lib.vec.Vector3 pos, float frame, int pass)
{
RenderPipe.INSTANCE.render(this, pos.x, pos.y, pos.z, frame);
}
@Override
public ItemStack getItem()
{
return new ItemStack(Mechanical.itemPipe, 1, getMaterialID());
}
@Override
public int fill(ForgeDirection from, FluidStack resource, boolean doFill)
{
if (!world().isRemote)
{
if (doFill)
{
markPacket = true;
}
return tank.fill(resource, doFill);
}
return 0;
}
@Override
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain)
{
return drain(from, resource.amount, doDrain);
}
@Override
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
{
if (!world().isRemote)
{
if (doDrain)
{
markPacket = true;
}
return tank.drain(maxDrain, doDrain);
}
return null;
}
@Override
public boolean canFill(ForgeDirection from, Fluid fluid)
{
return true;
}
@Override
public boolean canDrain(ForgeDirection from, Fluid fluid)
{
return true;
}
@Override
public FluidTankInfo[] getTankInfo(ForgeDirection from)
{
return new FluidTankInfo[] { tank.getInfo() };
}
@Override
public void drawBreaking(RenderBlocks renderBlocks)
{
CCRenderState.reset();
}
@Override
public void save(NBTTagCompound nbt)
{
super.save(nbt);
tank.writeToNBT(nbt);
}
@Override
public void load(NBTTagCompound nbt)
{
super.load(nbt);
tank.readFromNBT(nbt);
}
@Override
public Set<Cuboid6> getOcclusionBoxes()
{
return null;
}
@Override
public int getSlotMask()
{
return 0;
}
}

View file

@ -1,30 +1,51 @@
package resonantinduction.mechanical.fluid.pipe
import codechicken.lib.data.MCDataInput
import codechicken.lib.render.CCRenderState
import codechicken.lib.vec.{Cuboid6, Vector3}
import codechicken.multipart.{TNormalOcclusion, TSlottedPart}
import cpw.mods.fml.relauncher.{Side, SideOnly}
import net.minecraft.client.renderer.RenderBlocks
import net.minecraft.item.ItemStack
import net.minecraft.nbt.NBTTagCompound
import net.minecraftforge.common.util.ForgeDirection
import net.minecraftforge.fluids._
import resonant.lib.`type`.EvictingList
import resonantinduction.core.prefab.part.{PartFramedNode, TColorable, TMaterial}
import resonantinduction.mechanical.Mechanical
import resonantinduction.mechanical.fluid.pipe.PipeMaterial.PipeMaterial
/**
* Fluid transport pipe
*
* @author Calclavia,
* @author Calclavia
*/
class PartPipe extends PartFramedNode with TMaterial[EnumPipeMaterial] with TColorable with TSlottedPart with TNormalOcclusion with IFluidHandler
class PartPipe extends PartFramedNode with TMaterial[PipeMaterial] with TColorable with TSlottedPart with TNormalOcclusion with IFluidHandler
{
protected final val tank: FluidTank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME)
/**
* Computes the average fluid for client to render.
*/
private val averageTankData = new EvictingList[Integer](20)
private var markPacket: Boolean = true
setNode(new PipePressureNode(this))
def setMaterial(i: Int)
{
material = EnumPipeMaterial.values(i)
material = PipeMaterial(i).asInstanceOf[PipeMaterial]
}
def getMaterialID: Int = material.ordinal
def getMaterialID: Int = material.id
override def update
override def update()
{
super.update
super.update()
averageTankData.add(tank.getFluidAmount)
if (!world.isRemote && markPacket)
{
sendFluidUpdate
@ -37,24 +58,17 @@ class PartPipe extends PartFramedNode with TMaterial[EnumPipeMaterial] with TCol
*/
def sendFluidUpdate
{
val nbt: NBTTagCompound = new NBTTagCompound
val nbt = new NBTTagCompound
var averageAmount: Int = 0
if (averageTankData.size > 0)
{
{
var i: Int = 0
while (i < averageTankData.size)
for (i <- 0 until averageTankData.size)
{
{
averageAmount += averageTankData.get(i)
}
(
{
i += 1;
i - 1
})
}
}
averageAmount /= averageTankData.size
}
val tempTank: FluidTank = if (tank.getFluid != null) new FluidTank(tank.getFluid.getFluid, averageAmount, tank.getCapacity) else new FluidTank(tank.getCapacity)
@ -75,7 +89,8 @@ class PartPipe extends PartFramedNode with TMaterial[EnumPipeMaterial] with TCol
}
}
@SideOnly(Side.CLIENT) override def renderDynamic(pos: Vector3, frame: Float, pass: Int)
@SideOnly(Side.CLIENT)
override def renderDynamic(pos: Vector3, frame: Float, pass: Int)
{
RenderPipe.INSTANCE.render(this, pos.x, pos.y, pos.z, frame)
}
@ -133,7 +148,7 @@ class PartPipe extends PartFramedNode with TMaterial[EnumPipeMaterial] with TCol
override def drawBreaking(renderBlocks: RenderBlocks)
{
CCRenderState.reset
CCRenderState.reset()
}
override def save(nbt: NBTTagCompound)
@ -148,21 +163,9 @@ class PartPipe extends PartFramedNode with TMaterial[EnumPipeMaterial] with TCol
tank.readFromNBT(nbt)
}
override def getOcclusionBoxes: Set[Cuboid6] =
{
return null
}
override def getSlotMask: Int =
{
return 0
}
protected final val tank: FluidTank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME)
/**
* Computes the average fluid for client to render.
*/
private var averageTankData: EvictingList[Integer] = new EvictingList[Integer](20)
private var markPacket: Boolean = true
}

View file

@ -0,0 +1,19 @@
package resonantinduction.mechanical.fluid.pipe
/**
* Enumerator to hold info about each pipe material.
*
* @author Calclavia
*/
object PipeMaterial extends Enumeration
{
case class PipeMaterial(maxPressure: Int, maxFlow: Int, color: Int) extends Val
val CERAMIC = PipeMaterial(5, 5, 0xB3866F)
val BRONZE = PipeMaterial(25, 25, 0xD49568)
val PLASTIC = PipeMaterial(50, 30, 0xDAF4F7)
val IRON = PipeMaterial(100, 50, 0x5C6362)
val STEEL = PipeMaterial(100, 100, 0x888888)
val FIBERGLASS = PipeMaterial(1000, 200, 0x9F9691)
}

View file

@ -6,6 +6,7 @@ import net.minecraftforge.fluids.IFluidHandler;
import resonant.lib.utility.WorldUtility;
import resonantinduction.core.prefab.node.NodePressure;
import resonantinduction.core.prefab.part.TColorable;
import resonantinduction.core.prefab.part.TColorable$;
import universalelectricity.api.core.grid.INode;
import universalelectricity.api.core.grid.INodeProvider;
@ -88,9 +89,9 @@ public class PipePressureNode extends NodePressure
{
PartPipe otherPipe = (PartPipe) otherNode.getParent();
if (!otherPipe.isBlockedOnSide(from.getOpposite()) && pipe().getMaterial() == otherPipe.getMaterial())
if (!otherPipe.isBlockedOnSide(from.getOpposite()) && pipe().material() == otherPipe.material())
{
return pipe().getColor() == otherPipe.getColor() || (pipe().getColor() == TColorable.defaultColor() || otherPipe.getColor() == TColorable.defaultColor());
return pipe().getColor() == otherPipe.getColor() || (pipe().getColor() == TColorable$.MODULE$.defaultColor() || otherPipe.getColor() == TColorable$.MODULE$.defaultColor());
}
return false;

View file

@ -14,7 +14,6 @@ import net.minecraftforge.fluids.FluidStack;
import org.lwjgl.opengl.GL11;
import resonant.content.prefab.scala.render.ISimpleItemRenderer;
import resonant.lib.render.FluidRenderUtility;
import resonant.lib.render.RenderUtility;
import resonant.lib.utility.WorldUtility;
import resonantinduction.core.Reference;
@ -117,7 +116,7 @@ public class RenderPipe implements ISimpleItemRenderer
{
RenderUtility.enableBlending();
RenderUtility.bind(TEXTURE);
EnumPipeMaterial material = EnumPipeMaterial.values()[meta];
PipeMaterial material = PipeMaterial.values()[meta];
GL11.glColor4f(material.color.getRed() / 255f, material.color.getGreen() / 255f, material.color.getBlue() / 255f, 1);
MODEL.renderOnly("Mid");