Converted PipeMaterial and ItemPipe to Scala

This commit is contained in:
Calclavia 2014-09-14 14:30:39 +08:00
parent 3498515d8f
commit 0b8230f4b1
9 changed files with 101 additions and 111 deletions

View file

@ -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
}

View file

@ -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
*/

View file

@ -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));

View file

@ -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()));
}
}
}

View file

@ -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))
}
}
}

View file

@ -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

View file

@ -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)
}

View file

@ -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)
}

View file

@ -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)