diff --git a/src/main/scala/resonantinduction/core/prefab/node/NodeTank.java b/src/main/scala/resonantinduction/core/prefab/node/NodeTank.java index 7427d99d8..d65df04b5 100644 --- a/src/main/scala/resonantinduction/core/prefab/node/NodeTank.java +++ b/src/main/scala/resonantinduction/core/prefab/node/NodeTank.java @@ -25,7 +25,7 @@ public class NodeTank extends NodeConnector implements IFluidTank, IFluidHandler { static final int PACKET_DESCRIPTION = 100, PACKET_TANK = 101; LimitedTank tank; - byte renderSides = 0; + int renderSides = 0; public NodeTank(INodeProvider parent) { @@ -204,7 +204,7 @@ public class NodeTank extends NodeConnector implements IFluidTank, IFluidHandler return tank.maxOutput; } - public byte getRenderSides() + public int getRenderSides() { return renderSides; } diff --git a/src/main/scala/resonantinduction/core/prefab/part/connector/PartFramedNode.scala b/src/main/scala/resonantinduction/core/prefab/part/connector/PartFramedNode.scala index 5120d36c4..349845a93 100644 --- a/src/main/scala/resonantinduction/core/prefab/part/connector/PartFramedNode.scala +++ b/src/main/scala/resonantinduction/core/prefab/part/connector/PartFramedNode.scala @@ -9,10 +9,8 @@ import codechicken.lib.vec.Cuboid6 import codechicken.multipart._ import cpw.mods.fml.relauncher.{Side, SideOnly} import net.minecraft.entity.player.EntityPlayer -import net.minecraft.nbt.NBTTagCompound import net.minecraft.util.{IIcon, MovingObjectPosition} import net.minecraftforge.common.util.ForgeDirection -import universalelectricity.api.core.grid.{INode, INodeProvider, ISave} object PartFramedNode { @@ -34,17 +32,17 @@ object PartFramedNode insulatedSides(5) = new IndexedCuboid6(5, new Cuboid6(0.7, 0.3, 0.3, 1.0, 0.7, 0.7)) insulatedSides(6) = new IndexedCuboid6(6, new Cuboid6(0.3, 0.3, 0.3, 0.7, 0.7, 0.7)) - def connectionMapContainsSide(connections: Byte, side: ForgeDirection): Boolean = + def connectionMapContainsSide(connections: Int, side: ForgeDirection): Boolean = { - val tester: Byte = (1 << side.ordinal).asInstanceOf[Byte] - return ((connections & tester) > 0) + val tester = 1 << side.ordinal + return (connections & tester) > 0 } } abstract class PartFramedNode extends PartAbstract with TNodePartConnector with TSlottedPart with TNormalOcclusion with TIconHitEffects { /** Bitmask connections */ - var connectionMask: Byte = 0x00 + var connectionMask = 0x00 @SideOnly(Side.CLIENT) protected var breakIcon: IIcon = null @@ -52,11 +50,6 @@ abstract class PartFramedNode extends PartAbstract with TNodePartConnector with /** Client Side */ private var testingSide: ForgeDirection = null - override def occlusionTest(other: TMultiPart): Boolean = - { - return NormalOcclusionTest.apply(this, other) - } - override def getStrength(hit: MovingObjectPosition, player: EntityPlayer): Float = { return 10F @@ -108,15 +101,9 @@ abstract class PartFramedNode extends PartAbstract with TNodePartConnector with return list } - def getAllCurrentConnections: Byte = - { - return (connectionMask) - } + def getAllCurrentConnections = connectionMask - def getSlotMask: Int = - { - return PartMap.CENTER.mask - } + def getSlotMask = PartMap.CENTER.mask def getHollowSize: Int = { diff --git a/src/main/scala/resonantinduction/mechanical/fluid/pipe/ItemPipe.scala b/src/main/scala/resonantinduction/mechanical/fluid/pipe/ItemPipe.scala index 66f967da1..b4fd4f949 100644 --- a/src/main/scala/resonantinduction/mechanical/fluid/pipe/ItemPipe.scala +++ b/src/main/scala/resonantinduction/mechanical/fluid/pipe/ItemPipe.scala @@ -12,6 +12,7 @@ import org.lwjgl.input.Keyboard import resonant.lib.render.EnumColor import resonant.lib.utility.LanguageUtility import resonant.lib.wrapper.WrapList._ +import resonantinduction.core.ResonantPartFactory import universalelectricity.api.UnitDisplay class ItemPipe extends TItemMultiPart @@ -21,7 +22,7 @@ class ItemPipe extends TItemMultiPart 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] + val part = ResonantPartFactory.create(classOf[PartPipe]) part.preparePlacement(itemStack.getItemDamage) return part } diff --git a/src/main/scala/resonantinduction/mechanical/fluid/pipe/PartPipe.scala b/src/main/scala/resonantinduction/mechanical/fluid/pipe/PartPipe.scala index a5f6dc8b2..25cc20e86 100644 --- a/src/main/scala/resonantinduction/mechanical/fluid/pipe/PartPipe.scala +++ b/src/main/scala/resonantinduction/mechanical/fluid/pipe/PartPipe.scala @@ -22,15 +22,17 @@ import resonantinduction.mechanical.fluid.pipe.PipeMaterials.PipeMaterial */ class PartPipe extends PartFramedNode with TMaterial[PipeMaterial] with TColorable with TSlottedPart with TNormalOcclusion with IFluidHandler { - protected final val tank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME) + val tank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME) + + override lazy val node = new PipePressureNode(this) /** * Computes the average fluid for client to render. */ private val averageTankData = new EvictingList[Integer](20) - private var markPacket: Boolean = true + private var markPacket = true - override lazy val node = new PipePressureNode(this) + material = PipeMaterials.ceramic def preparePlacement(meta: Int) { @@ -60,7 +62,7 @@ class PartPipe extends PartFramedNode with TMaterial[PipeMaterial] with TColorab /** * Sends fluid level to the client to be used in the renderer */ - def sendFluidUpdate + def sendFluidUpdate() { val nbt = new NBTTagCompound var averageAmount: Int = 0 @@ -82,15 +84,13 @@ class PartPipe extends PartFramedNode with TMaterial[PipeMaterial] with TColorab override def read(packet: MCDataInput, packetID: Int) { + super.read(packet, packetID) + if (packetID == 3) { tank.setCapacity(packet.readInt) tank.readFromNBT(packet.readNBTTagCompound) } - else - { - super.read(packet, packetID) - } } @SideOnly(Side.CLIENT) diff --git a/src/main/scala/resonantinduction/mechanical/fluid/pipe/PipePressureNode.java b/src/main/scala/resonantinduction/mechanical/fluid/pipe/PipePressureNode.java index 4d326b9c5..bdf06c58a 100644 --- a/src/main/scala/resonantinduction/mechanical/fluid/pipe/PipePressureNode.java +++ b/src/main/scala/resonantinduction/mechanical/fluid/pipe/PipePressureNode.java @@ -9,103 +9,104 @@ import resonantinduction.core.prefab.part.connector.TColorable$; import universalelectricity.api.core.grid.INode; import universalelectricity.api.core.grid.INodeProvider; -/** Pressure node for the pipe +/** + * Pressure node for the pipe * - * @author Calclavia, Darkguardsman */ + * @author Calclavia, Darkguardsman + */ public class PipePressureNode extends NodePressure { - public PipePressureNode(PartPipe parent) - { - super(parent); - } + public PipePressureNode(PartPipe parent) + { + super(parent); + } - public PartPipe pipe() - { - return (PartPipe) this.getParent(); - } + public PartPipe pipe() + { + return (PartPipe) this.getParent(); + } + public void doRecache() + { + connections.clear(); - public void doRecache() - { - connections.clear(); + if (world() != null) + { + int previousConnections = pipe().getAllCurrentConnections(); + pipe().connectionMask_$eq((byte) 0); - if (world() != null) - { - byte previousConnections = pipe().getAllCurrentConnections(); - pipe().connectionMask_$eq((byte) 0); + for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) + { + TileEntity tile = position().add(dir).getTileEntity(world()); - for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) - { - TileEntity tile = position().add(dir).getTileEntity(world()); + if (tile instanceof IFluidHandler) + { + if (tile instanceof INodeProvider) + { + // If anything happens while trying to access the node then forget about it. + INode check = null; + try + { + check = ((INodeProvider) tile).getNode(NodePressure.class, dir.getOpposite()); + } + catch (Exception err) + { + check = null; + } - if (tile instanceof IFluidHandler) - { - if (tile instanceof INodeProvider) - { - // If anything happens while trying to access the node then forget about it. - INode check = null; - try - { - check = ((INodeProvider) tile).getNode(NodePressure.class, dir.getOpposite()); - } - catch (Exception err) - { - check = null; - } + if (check != null && check instanceof NodePressure && canConnect(dir, check) && ((NodePressure) check).canConnect(dir.getOpposite(), this)) + { + pipe().connectionMask_$eq(WorldUtility.setEnableSide(pipe().connectionMask(), dir, true)); + connections.put(check, dir); + } + } + else if (canConnect(dir, tile)) + { + pipe().connectionMask_$eq(WorldUtility.setEnableSide(pipe().connectionMask(), dir, true)); + connections.put(tile, dir); + } + } + } - if (check != null && check instanceof NodePressure && canConnect(dir, check) && ((NodePressure) check).canConnect(dir.getOpposite(), this)) - { - pipe().connectionMask_$eq(WorldUtility.setEnableSide(pipe().connectionMask(), dir, true)); - connections.put(check, dir); - } - } - else if (canConnect(dir, tile)) - { - pipe().connectionMask_$eq(WorldUtility.setEnableSide(pipe().connectionMask(), dir, true)); - connections.put(tile, dir); - } - } - } + /** Only send packet updates if visuallyConnected changed. */ + if (!world().isRemote && previousConnections != pipe().connectionMask()) + { + pipe().sendConnectionUpdate(); + } + } + } - /** Only send packet updates if visuallyConnected changed. */ - if (!world().isRemote && previousConnections != pipe().connectionMask()) - { - pipe().sendConnectionUpdate(); - } - } - } + @Override + public boolean canConnect(ForgeDirection from, Object source) + { + if (!pipe().isBlockedOnSide(from)) + { + if (source instanceof NodePressure) + { + NodePressure otherNode = (NodePressure) source; - @Override - public boolean canConnect(ForgeDirection from, Object source) - { - if (!pipe().isBlockedOnSide(from)) - { - if (source instanceof NodePressure) - { - NodePressure otherNode = (NodePressure) source; + if (otherNode.getParent() instanceof PartPipe) + { + PartPipe otherPipe = (PartPipe) otherNode.getParent(); - if (otherNode.getParent() instanceof PartPipe) - { - PartPipe otherPipe = (PartPipe) otherNode.getParent(); + if (!otherPipe.isBlockedOnSide(from.getOpposite()) && pipe().material() == otherPipe.material()) + { + return pipe().getColor() == otherPipe.getColor() || (pipe().getColor() == TColorable$.MODULE$.defaultColor() || otherPipe.getColor() == TColorable$.MODULE$.defaultColor()); + } - if (!otherPipe.isBlockedOnSide(from.getOpposite()) && pipe().material() == otherPipe.material()) - { - return pipe().getColor() == otherPipe.getColor() || (pipe().getColor() == TColorable$.MODULE$.defaultColor() || otherPipe.getColor() == TColorable$.MODULE$.defaultColor()); - } + return false; + } + } - return false; - } - } + return super.canConnect(from, source) || source instanceof IFluidHandler; + } - return super.canConnect(from, source) || source instanceof IFluidHandler; - } + return false; + } - return false; - } - - @Override - public String toString() - { - return this.getClass().getSimpleName() + this.hashCode(); - } + @Override + public String toString() + { + return this.getClass().getSimpleName() + this.hashCode(); + } } diff --git a/src/main/scala/resonantinduction/mechanical/fluid/pipe/RenderPipe.java b/src/main/scala/resonantinduction/mechanical/fluid/pipe/RenderPipe.java index 4307b527a..ce15dc6cc 100644 --- a/src/main/scala/resonantinduction/mechanical/fluid/pipe/RenderPipe.java +++ b/src/main/scala/resonantinduction/mechanical/fluid/pipe/RenderPipe.java @@ -39,7 +39,7 @@ public class RenderPipe implements ISimpleItemRenderer FluidStack fluid = part.tank().getFluid(); int capacity = part.tank().getCapacity(); - byte renderSides = part.getAllCurrentConnections(); + int renderSides = part.getAllCurrentConnections(); /** if (fluid != null && fluid.amount > 0) { @@ -112,7 +112,7 @@ public class RenderPipe implements ISimpleItemRenderer } @SuppressWarnings("incomplete-switch") - public static void render(int meta, int colorCode, byte sides) + public static void render(int meta, int colorCode, int sides) { RenderUtility.enableBlending(); RenderUtility.bind(TEXTURE); @@ -172,7 +172,7 @@ public class RenderPipe implements ISimpleItemRenderer public void renderInventoryItem(IItemRenderer.ItemRenderType type, ItemStack itemStack, Object... data) { GL11.glPushMatrix(); - render(itemStack.getItemDamage(), -1, Byte.parseByte("001100", 2)); + render(itemStack.getItemDamage(), -1, 0xC); GL11.glPopMatrix(); } } \ No newline at end of file