diff --git a/src/minecraft/fluidmech/client/render/RenderPipe.java b/src/minecraft/fluidmech/client/render/RenderPipe.java index 956b769c4..e13dfe8c3 100644 --- a/src/minecraft/fluidmech/client/render/RenderPipe.java +++ b/src/minecraft/fluidmech/client/render/RenderPipe.java @@ -8,6 +8,7 @@ import org.lwjgl.opengl.GL11; import fluidmech.client.model.ModelLargePipe; import fluidmech.common.FluidMech; +import fluidmech.common.machines.pipes.IPipeExtention; import fluidmech.common.machines.pipes.TileEntityPipe; import fluidmech.common.machines.pipes.TileEntityPipe; @@ -33,7 +34,12 @@ public class RenderPipe extends TileEntitySpecialRenderer if (te instanceof TileEntityPipe) { meta = te.getBlockMetadata(); - this.renderSide = ((TileEntityPipe) te).renderConnection; + TileEntityPipe pipe = ((TileEntityPipe) te); + this.renderSide = pipe.renderConnection; + for(int i = 0; i < 6; i++) + { + IPipeExtention extention = (IPipeExtention) pipe.subEntities[i]; + } } this.render(meta, renderSide); GL11.glPopMatrix(); diff --git a/src/minecraft/fluidmech/client/render/pipeextentions/IPipeExtentionRender.java b/src/minecraft/fluidmech/client/render/pipeextentions/IPipeExtentionRender.java new file mode 100644 index 000000000..737eb2d8e --- /dev/null +++ b/src/minecraft/fluidmech/client/render/pipeextentions/IPipeExtentionRender.java @@ -0,0 +1,26 @@ +package fluidmech.client.render.pipeextentions; + +import fluidmech.common.machines.pipes.TileEntityPipe; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.ForgeDirection; + +/** + * Class for TileEntity Renders that extend the pipe class to use instead of extending + * TileEntitySpecialRender + * + * @author Rseifert + * + */ +public interface IPipeExtentionRender +{ + /** + * Renders the pipe extension just like a normal tileEntity render however this is called and + * process threw the RenderPipe.class + * + * @param pipe - TileEntity this extension is attached too + * @param xPos yPos zPos position too be rendered from the players plane + * @param size - This should be the size of the render, correct me if wrong + * @param facingDirection - Facing direction of the extension in relation to its pipe frame + */ + public void renderAModelAt(TileEntityPipe pipe, double xPos, double yPos, double zPos, float size, ForgeDirection facingDirection); +} diff --git a/src/minecraft/fluidmech/common/machines/pipes/IPipeExtention.java b/src/minecraft/fluidmech/common/machines/pipes/IPipeExtention.java index f1e18f752..5e92db232 100644 --- a/src/minecraft/fluidmech/common/machines/pipes/IPipeExtention.java +++ b/src/minecraft/fluidmech/common/machines/pipes/IPipeExtention.java @@ -1,8 +1,10 @@ package fluidmech.common.machines.pipes; +import net.minecraft.nbt.NBTTagCompound; +import fluidmech.client.render.pipeextentions.IPipeExtentionRender; import universalelectricity.prefab.network.IPacketReceiver; -public interface IPipeExtention extends IPacketReceiver +public interface IPipeExtention { public boolean canBePlacedOnPipe(TileEntityPipe pipe); @@ -17,9 +19,18 @@ public interface IPipeExtention extends IPacketReceiver /** * if this sub tile needs a packet update - * - * Note it pulls the packet from description packet + * @param */ - public boolean shouldSendPacket(); + public boolean shouldSendPacket(boolean server); + + /** + * data that will be sent to this extension + */ + public NBTTagCompound getExtentionPacketData(boolean server); + + /** + * render class to be used to render this pipe extension of the face of the main pipe + */ + public IPipeExtentionRender getExtentionRenderClass(); } diff --git a/src/minecraft/fluidmech/common/machines/pipes/TileEntityPipe.java b/src/minecraft/fluidmech/common/machines/pipes/TileEntityPipe.java index 996fe0b51..6155f1472 100644 --- a/src/minecraft/fluidmech/common/machines/pipes/TileEntityPipe.java +++ b/src/minecraft/fluidmech/common/machines/pipes/TileEntityPipe.java @@ -28,6 +28,7 @@ import net.minecraftforge.liquids.LiquidTank; import org.bouncycastle.util.Arrays; +import universalelectricity.core.vector.Vector3; import universalelectricity.prefab.network.IPacketReceiver; import universalelectricity.prefab.network.PacketManager; import universalelectricity.prefab.tile.TileEntityAdvanced; @@ -39,35 +40,57 @@ import cpw.mods.fml.relauncher.SideOnly; public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer, IReadOut, IColorCoded, IFluidNetworkPart, IPacketReceiver { + /* TANK TO FAKE OTHER TILES INTO BELIVING THIS HAS AN INTERNAL STORAGE */ private LiquidTank fakeTank = new LiquidTank(LiquidContainerRegistry.BUCKET_VOLUME); /* CURRENTLY CONNECTED TILE ENTITIES TO THIS */ private TileEntity[] connectedBlocks = new TileEntity[6]; public boolean[] renderConnection = new boolean[6]; - private TileEntity[] subEntities = new TileEntity[6]; + public IPipeExtention[] subEntities = new IPipeExtention[6]; /* RANDOM INSTANCE USED BY THE UPDATE TICK */ private Random random = new Random(); /* NETWORK INSTANCE THAT THIS PIPE USES */ private HydraulicNetwork pipeNetwork; + public enum PacketID + { + PIPE_CONNECTIONS, EXTENTION; + } + @Override public void updateEntity() { super.updateEntity(); - for (int i = 0; i < 6; i++) + this.updateSubEntities(); + if (!worldObj.isRemote) { - if(subEntities[i] instanceof IPipeExtention && subEntities[i] instanceof TileEntity) + if (ticks % ((int) random.nextInt(5) * 40 + 20) == 0) { - IPipeExtention extention = (IPipeExtention) subEntities[i]; - if(this.ticks % extention.updateTick() == 0) - { - - } + this.updateAdjacentConnections(); } } - if (!worldObj.isRemote && ticks % ((int) random.nextInt(5) * 40 + 20) == 0) + } + + /** + * Builds and sends data to client for all PipeExtentions + */ + private void updateSubEntities() + { + for (int i = 0; i < 6; i++) { - this.updateAdjacentConnections(); + if (subEntities[i] instanceof IPipeExtention && subEntities[i] instanceof TileEntity) + { + IPipeExtention extention = subEntities[i]; + if (this.ticks % extention.updateTick() == 0) + { + ((TileEntity) extention).updateEntity(); + if (extention.shouldSendPacket(!this.worldObj.isRemote) && extention.getExtentionPacketData(!this.worldObj.isRemote) != null) + { + Packet packet = PacketManager.getPacket(FluidMech.CHANNEL, this, PacketID.EXTENTION, ForgeDirection.getOrientation(i), extention.getExtentionPacketData(!this.worldObj.isRemote)); + PacketManager.sendPacketToClients(packet, worldObj, new Vector3(this), 50); + } + } + } } } @@ -91,7 +114,8 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer @Override public void handlePacketData(INetworkManager network, int type, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream) { - if (this.worldObj.isRemote) + PacketID id = PacketID.values()[dataStream.readInt()]; + if (this.worldObj.isRemote && id == PacketID.PIPE_CONNECTIONS) { this.renderConnection[0] = dataStream.readBoolean(); this.renderConnection[1] = dataStream.readBoolean(); @@ -105,7 +129,7 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer @Override public Packet getDescriptionPacket() { - return PacketManager.getPacket(FluidMech.CHANNEL, this, this.renderConnection[0], this.renderConnection[1], this.renderConnection[2], this.renderConnection[3], this.renderConnection[4], this.renderConnection[5]); + return PacketManager.getPacket(FluidMech.CHANNEL, this, PacketID.PIPE_CONNECTIONS.ordinal(), this.renderConnection[0], this.renderConnection[1], this.renderConnection[2], this.renderConnection[3], this.renderConnection[4], this.renderConnection[5]); } /** diff --git a/src/minecraft/fluidmech/common/machines/pipes/TileEntityPipeExtention.java b/src/minecraft/fluidmech/common/machines/pipes/TileEntityPipeExtention.java new file mode 100644 index 000000000..4d8ea548a --- /dev/null +++ b/src/minecraft/fluidmech/common/machines/pipes/TileEntityPipeExtention.java @@ -0,0 +1,63 @@ +package fluidmech.common.machines.pipes; + +import com.google.common.io.ByteArrayDataInput; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.INetworkManager; +import net.minecraft.network.packet.Packet250CustomPayload; +import net.minecraft.tileentity.TileEntity; +import universalelectricity.prefab.network.IPacketReceiver; + +/** + * Pipe Extension for the TileEntityPipe.class is a sub TileEntity and is not loaded the same way as + * a normal TileEntity + * + * @author Rseifert + * + */ +public abstract class TileEntityPipeExtention extends TileEntity implements IPipeExtention, IPacketReceiver +{ + + private TileEntityPipe masterPipe = null; + + public TileEntityPipeExtention(TileEntityPipe pipe) + { + this.masterPipe = pipe; + } + + /** + * Reads a tile entity from NBT. + */ + public void readFromNBT(NBTTagCompound par1NBTTagCompound) + { + + } + + /** + * Writes a tile entity to NBT. + */ + public void writeToNBT(NBTTagCompound par1NBTTagCompound) + { + super.writeToNBT(par1NBTTagCompound); + } + + @Override + public void handlePacketData(INetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream) + { + // TODO Auto-generated method stub + + } + + @Override + public TileEntityPipe getPipe() + { + return this.masterPipe; + } + + @Override + public void setPipe(TileEntityPipe pipe) + { + this.masterPipe = pipe; + } +} diff --git a/src/minecraft/fluidmech/common/machines/pipes/TileEntityPipeWindow.java b/src/minecraft/fluidmech/common/machines/pipes/TileEntityPipeWindow.java index ff51e0eee..2f071e7da 100644 --- a/src/minecraft/fluidmech/common/machines/pipes/TileEntityPipeWindow.java +++ b/src/minecraft/fluidmech/common/machines/pipes/TileEntityPipeWindow.java @@ -2,14 +2,22 @@ package fluidmech.common.machines.pipes; import com.google.common.io.ByteArrayDataInput; +import fluidmech.client.render.pipeextentions.IPipeExtentionRender; + import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.INetworkManager; import net.minecraft.network.packet.Packet250CustomPayload; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.liquids.LiquidStack; -public class TileEntityPipeWindow extends TileEntity implements IPipeExtention +public class TileEntityPipeWindow extends TileEntityPipeExtention { + public TileEntityPipeWindow(TileEntityPipe pipe) + { + super(pipe); + } + private TileEntityPipe pipe = null; private boolean shouldUpdate = false; @@ -35,6 +43,18 @@ public class TileEntityPipeWindow extends TileEntity implements IPipeExtention } + @Override + public boolean shouldSendPacket(boolean server) + { + return shouldUpdate; + } + + @Override + public NBTTagCompound getExtentionPacketData(boolean server) + { + // TODO Auto-generated method stub + return null; + } @Override public boolean canBePlacedOnPipe(TileEntityPipe pipe) { @@ -59,10 +79,13 @@ public class TileEntityPipeWindow extends TileEntity implements IPipeExtention return 10; } + + @Override - public boolean shouldSendPacket() + public IPipeExtentionRender getExtentionRenderClass() { - return shouldUpdate; + return null; } + }