From 0b8230f4b154f8d940b0b0786ee4cc983c2d35de Mon Sep 17 00:00:00 2001 From: Calclavia Date: Sun, 14 Sep 2014 14:30:39 +0800 Subject: [PATCH] Converted PipeMaterial and ItemPipe to Scala --- .../electrical/wire/base/TWire.scala | 2 +- .../electrical/wire/flat/PartFlatWire.scala | 2 - .../mechanical/Mechanical.java | 14 ++-- .../mechanical/fluid/pipe/ItemPipe.java | 74 ------------------- .../mechanical/fluid/pipe/ItemPipe.scala | 61 +++++++++++++++ .../mechanical/fluid/pipe/PartPipe.scala | 9 ++- .../mechanical/fluid/pipe/PipeMaterial.scala | 19 ----- .../mechanical/fluid/pipe/PipeMaterials.scala | 19 +++++ .../mechanical/fluid/pipe/RenderPipe.java | 12 +-- 9 files changed, 101 insertions(+), 111 deletions(-) delete mode 100644 src/main/scala/resonantinduction/mechanical/fluid/pipe/ItemPipe.java create mode 100644 src/main/scala/resonantinduction/mechanical/fluid/pipe/ItemPipe.scala delete mode 100644 src/main/scala/resonantinduction/mechanical/fluid/pipe/PipeMaterial.scala create mode 100644 src/main/scala/resonantinduction/mechanical/fluid/pipe/PipeMaterials.scala diff --git a/src/main/scala/resonantinduction/electrical/wire/base/TWire.scala b/src/main/scala/resonantinduction/electrical/wire/base/TWire.scala index 72715d2e3..dd1785d4d 100644 --- a/src/main/scala/resonantinduction/electrical/wire/base/TWire.scala +++ b/src/main/scala/resonantinduction/electrical/wire/base/TWire.scala @@ -83,7 +83,7 @@ abstract class TWire extends TMultiPart with TPart with TMaterial[WireMaterial] if (material == wire.material) { if (insulated && wire.insulated) - return this.getColor == wire.getColor || (getColor == defaultColor || wire.getColor == defaultColor) + return this.getColor == wire.getColor || (getColor == TColorable.defaultColor || wire.getColor == TColorable.defaultColor) return true } diff --git a/src/main/scala/resonantinduction/electrical/wire/flat/PartFlatWire.scala b/src/main/scala/resonantinduction/electrical/wire/flat/PartFlatWire.scala index 4f7885683..386ef4282 100644 --- a/src/main/scala/resonantinduction/electrical/wire/flat/PartFlatWire.scala +++ b/src/main/scala/resonantinduction/electrical/wire/flat/PartFlatWire.scala @@ -731,8 +731,6 @@ class PartFlatWire extends TWire with TFacePart with TNormalOcclusion override def solid(arg0: Int) = false - def getType: String = "resonant_induction_flat_wire" - /** * RENDERING */ diff --git a/src/main/scala/resonantinduction/mechanical/Mechanical.java b/src/main/scala/resonantinduction/mechanical/Mechanical.java index b7f20c992..4ffea191d 100644 --- a/src/main/scala/resonantinduction/mechanical/Mechanical.java +++ b/src/main/scala/resonantinduction/mechanical/Mechanical.java @@ -7,7 +7,7 @@ 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.fluid.pipe.PipeMaterials; import resonantinduction.mechanical.turbine.*; import resonantinduction.mechanical.fluid.pipe.ItemPipe; import resonantinduction.mechanical.fluid.transport.TilePump; @@ -161,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, 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(new ItemStack(itemPipe, 3, PipeMaterials.ceramic().id()), "BBB", " ", "BBB", 'B', Items.brick)); + GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(itemPipe, 3, PipeMaterials.bronze().id()), "BBB", " ", "BBB", 'B', "ingotBronze")); + GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(itemPipe, 3, PipeMaterials.plastic().id()), "BBB", " ", "BBB", 'B', UniversalRecipe.RUBBER.get())); + GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(itemPipe, 3, PipeMaterials.iron().id()), "BBB", " ", "BBB", 'B', Items.iron_ingot)); + GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(itemPipe, 3, PipeMaterials.steel().id()), "BBB", " ", "BBB", 'B', "ingotSteel")); + GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(itemPipe, 3, PipeMaterials.fiberglass().id()), "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)); diff --git a/src/main/scala/resonantinduction/mechanical/fluid/pipe/ItemPipe.java b/src/main/scala/resonantinduction/mechanical/fluid/pipe/ItemPipe.java deleted file mode 100644 index 990846a52..000000000 --- a/src/main/scala/resonantinduction/mechanical/fluid/pipe/ItemPipe.java +++ /dev/null @@ -1,74 +0,0 @@ -package resonantinduction.mechanical.fluid.pipe; - -import java.util.List; - -import net.minecraft.creativetab.CreativeTabs; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.world.World; - -import org.lwjgl.input.Keyboard; - -import resonant.lib.render.EnumColor; -import resonant.lib.utility.LanguageUtility; -import codechicken.lib.vec.BlockCoord; -import codechicken.lib.vec.Vector3; -import codechicken.multipart.JItemMultiPart; -import codechicken.multipart.MultiPartRegistry; -import codechicken.multipart.TMultiPart; -import universalelectricity.api.UnitDisplay; - -public class ItemPipe extends JItemMultiPart -{ - public ItemPipe() - { - super(); - this.setHasSubtypes(true); - this.setMaxDamage(0); - } - - @Override - public TMultiPart newPart(ItemStack itemStack, EntityPlayer player, World world, BlockCoord pos, int side, Vector3 hit) - { - PartPipe part = (PartPipe) MultiPartRegistry.createPart("resonant_induction_pipe", false); - part.preparePlacement(itemStack.getItemDamage()); - return part; - } - - @Override - public int getMetadata(int damage) - { - return damage; - } - - @Override - public String getUnlocalizedName(ItemStack itemStack) - { - return super.getUnlocalizedName(itemStack) + "." + LanguageUtility.underscoreToCamel(PipeMaterial.values()[itemStack.getItemDamage()].name()); - } - - @Override - @SuppressWarnings("unchecked") - public void addInformation(ItemStack itemstack, EntityPlayer player, List list, boolean par4) - { - if (!Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) - { - list.add(LanguageUtility.getLocal("tooltip.noShift").replace("%0", EnumColor.AQUA.toString()).replace("%1", EnumColor.GREY.toString())); - } - else - { - 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 (PipeMaterial material : PipeMaterial.values()) - { - listToAddTo.add(new ItemStack(itemID, 1, material.ordinal())); - } - } -} diff --git a/src/main/scala/resonantinduction/mechanical/fluid/pipe/ItemPipe.scala b/src/main/scala/resonantinduction/mechanical/fluid/pipe/ItemPipe.scala new file mode 100644 index 000000000..66f967da1 --- /dev/null +++ b/src/main/scala/resonantinduction/mechanical/fluid/pipe/ItemPipe.scala @@ -0,0 +1,61 @@ +package resonantinduction.mechanical.fluid.pipe + +import java.util.List + +import codechicken.lib.vec.{BlockCoord, Vector3} +import codechicken.multipart.{MultiPartRegistry, TItemMultiPart, TMultiPart} +import net.minecraft.creativetab.CreativeTabs +import net.minecraft.entity.player.EntityPlayer +import net.minecraft.item.{Item, ItemStack} +import net.minecraft.world.World +import org.lwjgl.input.Keyboard +import resonant.lib.render.EnumColor +import resonant.lib.utility.LanguageUtility +import resonant.lib.wrapper.WrapList._ +import universalelectricity.api.UnitDisplay + +class ItemPipe extends TItemMultiPart +{ + setHasSubtypes(true) + setMaxDamage(0) + + def newPart(itemStack: ItemStack, player: EntityPlayer, world: World, pos: BlockCoord, side: Int, hit: Vector3): TMultiPart = + { + val part: PartPipe = MultiPartRegistry.createPart("resonant_induction_pipe", false).asInstanceOf[PartPipe] + part.preparePlacement(itemStack.getItemDamage) + return part + } + + override def getMetadata(damage: Int): Int = + { + return damage + } + + override def getUnlocalizedName(itemStack: ItemStack): String = + { + return super.getUnlocalizedName(itemStack) + "." + LanguageUtility.underscoreToCamel(PipeMaterials.apply(itemStack.getItemDamage).toString) + } + + @SuppressWarnings(Array("unchecked")) + override def addInformation(itemStack: ItemStack, player: EntityPlayer, list: List[_], par4: Boolean) + { + if (!Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) + { + list.add(LanguageUtility.getLocal("tooltip.noShift").replace("%0", EnumColor.AQUA.toString).replace("%1", EnumColor.GREY.toString)) + } + else + { + val material = PipeMaterials.apply(itemStack.getItemDamage).asInstanceOf[PipeMaterials.PipeMaterial] + list.add(EnumColor.AQUA + LanguageUtility.getLocal("tooltip.pipe.rate").replace("%v", "" + EnumColor.ORANGE + new UnitDisplay(UnitDisplay.Unit.LITER, material.maxFlow * 20) + "/s")) + list.add(EnumColor.AQUA + LanguageUtility.getLocal("tooltip.pipe.pressure").replace("%v", "" + EnumColor.ORANGE + material.maxPressure + " Pa")) + } + } + + override def getSubItems(itemID: Item, tab: CreativeTabs, listToAddTo: List[_]) + { + for (material <- PipeMaterials.values) + { + listToAddTo.add(new ItemStack(itemID, 1, material.id)) + } + } +} \ No newline at end of file diff --git a/src/main/scala/resonantinduction/mechanical/fluid/pipe/PartPipe.scala b/src/main/scala/resonantinduction/mechanical/fluid/pipe/PartPipe.scala index fc6897f73..3417293ac 100644 --- a/src/main/scala/resonantinduction/mechanical/fluid/pipe/PartPipe.scala +++ b/src/main/scala/resonantinduction/mechanical/fluid/pipe/PartPipe.scala @@ -13,7 +13,7 @@ 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 +import resonantinduction.mechanical.fluid.pipe.PipeMaterials.PipeMaterial /** * Fluid transport pipe @@ -32,9 +32,14 @@ class PartPipe extends PartFramedNode with TMaterial[PipeMaterial] with TColorab setNode(new PipePressureNode(this)) + def preparePlacement(meta:Int) + { + setMaterial(meta) + } + def setMaterial(i: Int) { - material = PipeMaterial(i).asInstanceOf[PipeMaterial] + material = PipeMaterials(i).asInstanceOf[PipeMaterial] } def getMaterialID: Int = material.id diff --git a/src/main/scala/resonantinduction/mechanical/fluid/pipe/PipeMaterial.scala b/src/main/scala/resonantinduction/mechanical/fluid/pipe/PipeMaterial.scala deleted file mode 100644 index a21f386b7..000000000 --- a/src/main/scala/resonantinduction/mechanical/fluid/pipe/PipeMaterial.scala +++ /dev/null @@ -1,19 +0,0 @@ -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) -} - diff --git a/src/main/scala/resonantinduction/mechanical/fluid/pipe/PipeMaterials.scala b/src/main/scala/resonantinduction/mechanical/fluid/pipe/PipeMaterials.scala new file mode 100644 index 000000000..6924a7ea3 --- /dev/null +++ b/src/main/scala/resonantinduction/mechanical/fluid/pipe/PipeMaterials.scala @@ -0,0 +1,19 @@ +package resonantinduction.mechanical.fluid.pipe + +/** + * Enumerator to hold info about each pipe material. + * + * @author Calclavia + */ +object PipeMaterials 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) +} + diff --git a/src/main/scala/resonantinduction/mechanical/fluid/pipe/RenderPipe.java b/src/main/scala/resonantinduction/mechanical/fluid/pipe/RenderPipe.java index 12417f257..4307b527a 100644 --- a/src/main/scala/resonantinduction/mechanical/fluid/pipe/RenderPipe.java +++ b/src/main/scala/resonantinduction/mechanical/fluid/pipe/RenderPipe.java @@ -37,8 +37,8 @@ public class RenderPipe implements ISimpleItemRenderer GL11.glPushMatrix(); - FluidStack fluid = part.tank.getFluid(); - int capacity = part.tank.getCapacity(); + FluidStack fluid = part.tank().getFluid(); + int capacity = part.tank().getCapacity(); byte renderSides = part.getAllCurrentConnections(); /** if (fluid != null && fluid.amount > 0) @@ -116,9 +116,9 @@ public class RenderPipe implements ISimpleItemRenderer { RenderUtility.enableBlending(); RenderUtility.bind(TEXTURE); - PipeMaterial material = PipeMaterial.values()[meta]; - - GL11.glColor4f(material.color.getRed() / 255f, material.color.getGreen() / 255f, material.color.getBlue() / 255f, 1); + PipeMaterials.PipeMaterial material = (PipeMaterials.PipeMaterial) PipeMaterials.apply(meta); + Color matColor = new Color(material.color()); + GL11.glColor4f(matColor.getRed() / 255f, matColor.getGreen() / 255f, matColor.getBlue() / 255f, 1); MODEL.renderOnly("Mid"); /** @@ -128,7 +128,7 @@ public class RenderPipe implements ISimpleItemRenderer { if (WorldUtility.isEnabledSide(sides, dir)) { - GL11.glColor4f(material.color.getRed() / 255f, material.color.getGreen() / 255f, material.color.getBlue() / 255f, 1); + GL11.glColor4f(matColor.getRed() / 255f, matColor.getGreen() / 255f, matColor.getBlue() / 255f, 1); String prefix = null; switch (dir)