more work on pipe addons

This commit is contained in:
Rseifert 2013-04-02 00:51:34 -04:00
parent 0ae6eb5283
commit c4f9bb386f
7 changed files with 128 additions and 38 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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<RenderPipeWindow> getExtentionRenderClass()
{
return null;
return RenderPipeWindow.class;
}
@Override
public String toString()