From c4f9bb386fe510617d7030455fb987d78f20008e Mon Sep 17 00:00:00 2001 From: Rseifert Date: Tue, 2 Apr 2013 00:51:34 -0400 Subject: [PATCH] more work on pipe addons --- .../fluidmech/client/render/RenderPipe.java | 20 +++++- .../client/render/RenderPipeWindow.java | 63 +++++++++++++++++++ src/minecraft/fluidmech/common/FluidMech.java | 4 ++ .../common/machines/pipes/IPipeExtention.java | 3 +- .../common/machines/pipes/TileEntityPipe.java | 55 +++++++++------- .../pipes/TileEntityPipeExtention.java | 3 +- .../machines/pipes/TileEntityPipeWindow.java | 18 +++--- 7 files changed, 128 insertions(+), 38 deletions(-) create mode 100644 src/minecraft/fluidmech/client/render/RenderPipeWindow.java diff --git a/src/minecraft/fluidmech/client/render/RenderPipe.java b/src/minecraft/fluidmech/client/render/RenderPipe.java index 7c971a762..427104557 100644 --- a/src/minecraft/fluidmech/client/render/RenderPipe.java +++ b/src/minecraft/fluidmech/client/render/RenderPipe.java @@ -43,10 +43,24 @@ public class RenderPipe extends TileEntitySpecialRenderer IPipeExtention extention = (IPipeExtention) pipe.subEntities[i]; if (extention != null) { - IPipeExtentionRender render = extention.getExtentionRenderClass(); - if (render != null) + Object ob; + try { - render.renderAModelAt(pipe, d, d1, d2, f, ForgeDirection.getOrientation(i)); + ob = extention.getExtentionRenderClass().newInstance(); + + if (ob instanceof IPipeExtentionRender) + { + IPipeExtentionRender render = (IPipeExtentionRender) ob; + if (render != null) + { + render.renderAModelAt(pipe, d, d1, d2, f, ForgeDirection.getOrientation(i)); + } + } + } + catch (Exception e) + { + System.out.print("Failed to render a pipe extention"); + e.printStackTrace(); } } } diff --git a/src/minecraft/fluidmech/client/render/RenderPipeWindow.java b/src/minecraft/fluidmech/client/render/RenderPipeWindow.java new file mode 100644 index 000000000..3d0d47b79 --- /dev/null +++ b/src/minecraft/fluidmech/client/render/RenderPipeWindow.java @@ -0,0 +1,63 @@ +package fluidmech.client.render; + +import hydraulic.api.ColorCode; +import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.ForgeDirection; + +import org.lwjgl.opengl.GL11; + +import fluidmech.client.model.ModelLargePipe; +import fluidmech.client.render.pipeextentions.IPipeExtentionRender; +import fluidmech.common.FluidMech; +import fluidmech.common.machines.pipes.IPipeExtention; +import fluidmech.common.machines.pipes.TileEntityPipe; +import fluidmech.common.machines.pipes.TileEntityPipe; + +public class RenderPipeWindow implements IPipeExtentionRender +{ + private ModelLargePipe SixPipe; + private boolean[] renderSide = new boolean[6]; + + public RenderPipeWindow() + { + SixPipe = new ModelLargePipe(); + } + + public void renderAModelAt(TileEntityPipe pipe, double d, double d1, double d2, float size, ForgeDirection facingDirection) + { + // Texture file + GL11.glPushMatrix(); + GL11.glTranslatef((float) d + 0.5F, (float) d1 + 1.5F, (float) d2 + 0.5F); + GL11.glScalef(1.1F, -1.1F, -1.1F); + this.render(facingDirection.ordinal()); + GL11.glPopMatrix(); + + } + + public void render(int side) + { + switch (side) + { + case 0: + SixPipe.renderBottom(); + break; + case 1: + SixPipe.renderTop(); + break; + case 3: + SixPipe.renderFront(); + break; + case 2: + SixPipe.renderBack(); + break; + case 5: + SixPipe.renderRight(); + break; + case 4: + SixPipe.renderLeft(); + break; + } + } + +} \ No newline at end of file diff --git a/src/minecraft/fluidmech/common/FluidMech.java b/src/minecraft/fluidmech/common/FluidMech.java index 7fdf38514..65ef5e64f 100644 --- a/src/minecraft/fluidmech/common/FluidMech.java +++ b/src/minecraft/fluidmech/common/FluidMech.java @@ -24,6 +24,7 @@ import fluidmech.common.machines.pipes.BlockPipe; import fluidmech.common.machines.pipes.BlockPipe; import fluidmech.common.machines.pipes.TileEntityPipe; import fluidmech.common.machines.pipes.TileEntityPipe; +import fluidmech.common.machines.pipes.TileEntityPipeWindow; import hydraulic.api.ColorCode; import hydraulic.helpers.FluidHelper; @@ -169,6 +170,9 @@ public class FluidMech extends DummyModContainer GameRegistry.registerTileEntity(TileEntityTank.class, "lmTank"); GameRegistry.registerTileEntity(TileEntityGenerator.class, "lmGen"); GameRegistry.registerTileEntity(TileEntitySink.class, "lmSink"); + // Pipe Extention TileEntities + GameRegistry.registerTileEntity(TileEntityPipeWindow.class, "lmPipeWidnow"); + FMLog.info(" Loaded: " + TranslationHelper.loadLanguages(LANGUAGE_PATH, LANGUAGES_SUPPORTED) + " Languages."); } diff --git a/src/minecraft/fluidmech/common/machines/pipes/IPipeExtention.java b/src/minecraft/fluidmech/common/machines/pipes/IPipeExtention.java index fa216f784..1462f8b40 100644 --- a/src/minecraft/fluidmech/common/machines/pipes/IPipeExtention.java +++ b/src/minecraft/fluidmech/common/machines/pipes/IPipeExtention.java @@ -1,6 +1,7 @@ package fluidmech.common.machines.pipes; import net.minecraft.nbt.NBTTagCompound; +import fluidmech.client.render.RenderPipeWindow; import fluidmech.client.render.pipeextentions.IPipeExtentionRender; import universalelectricity.prefab.network.IPacketReceiver; @@ -31,6 +32,6 @@ public interface IPipeExtention extends IPacketReceiver /** * render class to be used to render this pipe extension of the face of the main pipe */ - public IPipeExtentionRender getExtentionRenderClass(); + public Class getExtentionRenderClass(); } diff --git a/src/minecraft/fluidmech/common/machines/pipes/TileEntityPipe.java b/src/minecraft/fluidmech/common/machines/pipes/TileEntityPipe.java index 39898337a..3515c0bcf 100644 --- a/src/minecraft/fluidmech/common/machines/pipes/TileEntityPipe.java +++ b/src/minecraft/fluidmech/common/machines/pipes/TileEntityPipe.java @@ -63,26 +63,21 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer public void initiate() { this.updateAdjacentConnections(); - for (int i = 0; i < 6; i++) + if (!worldObj.isRemote) { - TileEntity entity = (TileEntity) this.subEntities[i]; - if (entity != null) + if (this.subEntities[0] == null) { - this.initSubTile(i); - this.sendExtentionToClient(i); + this.subEntities[0] = new TileEntityPipeWindow(); + this.initSubTile(0); + } + for (int i = 0; i < 6; i++) + { + TileEntity entity = (TileEntity) this.subEntities[i]; + if (entity != null) + { + this.initSubTile(i); + } } - } - } - - public void sendExtentionToClient(int side) - { - if (this.subEntities[side] instanceof TileEntity) - { - NBTTagCompound tag = new NBTTagCompound(); - ((Entity) this.subEntities[side]).writeToNBT(tag); - - Packet packet = PacketManager.getPacket(FluidMech.CHANNEL, this, PacketID.EXTENTION_FULL, ForgeDirection.getOrientation(side), tag); - PacketManager.sendPacketToClients(packet, worldObj, new Vector3(this), 50); } } @@ -93,11 +88,6 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer this.updateSubEntities(); if (!worldObj.isRemote) { - if (this.subEntities[0] == null) - { - this.subEntities[0] = new TileEntityPipeWindow(); - this.initSubTile(0); - } if (ticks % ((int) random.nextInt(5) * 40 + 20) == 0) { this.updateAdjacentConnections(); @@ -120,7 +110,7 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer ((TileEntity) extention).updateEntity(); if (extention.shouldSendPacket(!this.worldObj.isRemote) && extention.getExtentionPacketData(!this.worldObj.isRemote) != null) { - Packet packet = PacketManager.getPacket(FluidMech.CHANNEL, this, PacketID.EXTENTION_UPDATE,ForgeDirection.getOrientation(i), extention.getExtentionPacketData(!this.worldObj.isRemote)); + Packet packet = PacketManager.getPacket(FluidMech.CHANNEL, this, PacketID.EXTENTION_UPDATE.ordinal(), ForgeDirection.getOrientation(i), extention.getExtentionPacketData(!this.worldObj.isRemote)); PacketManager.sendPacketToClients(packet, worldObj, new Vector3(this), 50); } } @@ -239,6 +229,7 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer { this.subEntities[side] = (IPipeExtention) tile; this.initSubTile(side); + System.out.println("Creating addon " + (worldObj.isRemote ? "Client" : "Server")); } } } @@ -253,6 +244,19 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer tile.xCoord = this.xCoord; tile.yCoord = this.yCoord; tile.zCoord = this.zCoord; + sendExtentionToClient(side); + } + } + + public void sendExtentionToClient(int side) + { + if (worldObj != null && !worldObj.isRemote && this.subEntities[side] instanceof TileEntity) + { + NBTTagCompound tag = new NBTTagCompound(); + ((TileEntity) this.subEntities[side]).writeToNBT(tag); + + Packet packet = PacketManager.getPacket(FluidMech.CHANNEL, this, PacketID.EXTENTION_FULL.ordinal(), ForgeDirection.getOrientation(side), tag); + PacketManager.sendPacketToClients(packet, worldObj, new Vector3(this), 50); } } @@ -408,6 +412,11 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer { if (!this.worldObj.isRemote && tileEntity != null) { + if (this.subEntities[side.ordinal()] != null) + { + connectedBlocks[side.ordinal()] = null; + return; + } if (tileEntity instanceof IPipeConnection) { if (((IPipeConnection) tileEntity).canConnect(this, side)) diff --git a/src/minecraft/fluidmech/common/machines/pipes/TileEntityPipeExtention.java b/src/minecraft/fluidmech/common/machines/pipes/TileEntityPipeExtention.java index ea353ce81..9c024e69e 100644 --- a/src/minecraft/fluidmech/common/machines/pipes/TileEntityPipeExtention.java +++ b/src/minecraft/fluidmech/common/machines/pipes/TileEntityPipeExtention.java @@ -8,6 +8,7 @@ import net.minecraft.network.INetworkManager; import net.minecraft.network.packet.Packet250CustomPayload; import net.minecraft.tileentity.TileEntity; import universalelectricity.prefab.network.IPacketReceiver; +import universalelectricity.prefab.tile.TileEntityAdvanced; /** * Pipe Extension for the TileEntityPipe.class is a sub TileEntity and is not loaded the same way as @@ -16,7 +17,7 @@ import universalelectricity.prefab.network.IPacketReceiver; * @author Rseifert * */ -public abstract class TileEntityPipeExtention extends TileEntity implements IPipeExtention, IPacketReceiver +public abstract class TileEntityPipeExtention extends TileEntityAdvanced implements IPipeExtention, IPacketReceiver { private TileEntityPipe masterPipe = null; diff --git a/src/minecraft/fluidmech/common/machines/pipes/TileEntityPipeWindow.java b/src/minecraft/fluidmech/common/machines/pipes/TileEntityPipeWindow.java index 7d42850a8..dde4fad0d 100644 --- a/src/minecraft/fluidmech/common/machines/pipes/TileEntityPipeWindow.java +++ b/src/minecraft/fluidmech/common/machines/pipes/TileEntityPipeWindow.java @@ -2,6 +2,7 @@ package fluidmech.common.machines.pipes; import com.google.common.io.ByteArrayDataInput; +import fluidmech.client.render.RenderPipeWindow; import fluidmech.client.render.pipeextentions.IPipeExtentionRender; import net.minecraft.entity.player.EntityPlayer; @@ -22,13 +23,12 @@ public class TileEntityPipeWindow extends TileEntityPipeExtention @Override public void updateEntity() { + super.updateEntity(); + System.out.println("Updating side " + (worldObj.isRemote ? "Client" : "Server") ); if(!worldObj.isRemote && pipe != null) { stack = pipe.getNetwork().getTank().getLiquid(); - } - if(worldObj.isRemote) - { - System.out.println("Alive"); + worldObj.setBlockAndMetadataWithNotify(xCoord, yCoord+1, yCoord, 0, 0, 3); } } @@ -76,15 +76,13 @@ public class TileEntityPipeWindow extends TileEntityPipeExtention @Override public int updateTick() { - return 10; - } - - + return 20; + } @Override - public IPipeExtentionRender getExtentionRenderClass() + public Class getExtentionRenderClass() { - return null; + return RenderPipeWindow.class; } @Override public String toString()