added packet and tick update for pipe addons
Added Tick updating to the pipe addons Added packet sending for the pipe addons though reading packets still needs to be done Added IPipeExtentionRender interface so the pipe render can render the pipe addon on one of its sides.
This commit is contained in:
parent
b0f4273a92
commit
1e464d4b41
6 changed files with 173 additions and 20 deletions
|
@ -8,6 +8,7 @@ import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
import fluidmech.client.model.ModelLargePipe;
|
import fluidmech.client.model.ModelLargePipe;
|
||||||
import fluidmech.common.FluidMech;
|
import fluidmech.common.FluidMech;
|
||||||
|
import fluidmech.common.machines.pipes.IPipeExtention;
|
||||||
import fluidmech.common.machines.pipes.TileEntityPipe;
|
import fluidmech.common.machines.pipes.TileEntityPipe;
|
||||||
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)
|
if (te instanceof TileEntityPipe)
|
||||||
{
|
{
|
||||||
meta = te.getBlockMetadata();
|
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);
|
this.render(meta, renderSide);
|
||||||
GL11.glPopMatrix();
|
GL11.glPopMatrix();
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
|
@ -1,8 +1,10 @@
|
||||||
package fluidmech.common.machines.pipes;
|
package fluidmech.common.machines.pipes;
|
||||||
|
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import fluidmech.client.render.pipeextentions.IPipeExtentionRender;
|
||||||
import universalelectricity.prefab.network.IPacketReceiver;
|
import universalelectricity.prefab.network.IPacketReceiver;
|
||||||
|
|
||||||
public interface IPipeExtention extends IPacketReceiver
|
public interface IPipeExtention
|
||||||
{
|
{
|
||||||
public boolean canBePlacedOnPipe(TileEntityPipe pipe);
|
public boolean canBePlacedOnPipe(TileEntityPipe pipe);
|
||||||
|
|
||||||
|
@ -17,9 +19,18 @@ public interface IPipeExtention extends IPacketReceiver
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* if this sub tile needs a packet update
|
* if this sub tile needs a packet update
|
||||||
*
|
* @param
|
||||||
* Note it pulls the packet from description packet
|
|
||||||
*/
|
*/
|
||||||
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();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ import net.minecraftforge.liquids.LiquidTank;
|
||||||
|
|
||||||
import org.bouncycastle.util.Arrays;
|
import org.bouncycastle.util.Arrays;
|
||||||
|
|
||||||
|
import universalelectricity.core.vector.Vector3;
|
||||||
import universalelectricity.prefab.network.IPacketReceiver;
|
import universalelectricity.prefab.network.IPacketReceiver;
|
||||||
import universalelectricity.prefab.network.PacketManager;
|
import universalelectricity.prefab.network.PacketManager;
|
||||||
import universalelectricity.prefab.tile.TileEntityAdvanced;
|
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
|
public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer, IReadOut, IColorCoded, IFluidNetworkPart, IPacketReceiver
|
||||||
{
|
{
|
||||||
|
|
||||||
/* TANK TO FAKE OTHER TILES INTO BELIVING THIS HAS AN INTERNAL STORAGE */
|
/* TANK TO FAKE OTHER TILES INTO BELIVING THIS HAS AN INTERNAL STORAGE */
|
||||||
private LiquidTank fakeTank = new LiquidTank(LiquidContainerRegistry.BUCKET_VOLUME);
|
private LiquidTank fakeTank = new LiquidTank(LiquidContainerRegistry.BUCKET_VOLUME);
|
||||||
/* CURRENTLY CONNECTED TILE ENTITIES TO THIS */
|
/* CURRENTLY CONNECTED TILE ENTITIES TO THIS */
|
||||||
private TileEntity[] connectedBlocks = new TileEntity[6];
|
private TileEntity[] connectedBlocks = new TileEntity[6];
|
||||||
public boolean[] renderConnection = new boolean[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 */
|
/* RANDOM INSTANCE USED BY THE UPDATE TICK */
|
||||||
private Random random = new Random();
|
private Random random = new Random();
|
||||||
/* NETWORK INSTANCE THAT THIS PIPE USES */
|
/* NETWORK INSTANCE THAT THIS PIPE USES */
|
||||||
private HydraulicNetwork pipeNetwork;
|
private HydraulicNetwork pipeNetwork;
|
||||||
|
|
||||||
|
public enum PacketID
|
||||||
|
{
|
||||||
|
PIPE_CONNECTIONS, EXTENTION;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateEntity()
|
public void updateEntity()
|
||||||
{
|
{
|
||||||
super.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];
|
this.updateAdjacentConnections();
|
||||||
if(this.ticks % extention.updateTick() == 0)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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
|
@Override
|
||||||
public void handlePacketData(INetworkManager network, int type, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream)
|
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[0] = dataStream.readBoolean();
|
||||||
this.renderConnection[1] = dataStream.readBoolean();
|
this.renderConnection[1] = dataStream.readBoolean();
|
||||||
|
@ -105,7 +129,7 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer
|
||||||
@Override
|
@Override
|
||||||
public Packet getDescriptionPacket()
|
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]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,14 +2,22 @@ package fluidmech.common.machines.pipes;
|
||||||
|
|
||||||
import com.google.common.io.ByteArrayDataInput;
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
|
|
||||||
|
import fluidmech.client.render.pipeextentions.IPipeExtentionRender;
|
||||||
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.network.INetworkManager;
|
import net.minecraft.network.INetworkManager;
|
||||||
import net.minecraft.network.packet.Packet250CustomPayload;
|
import net.minecraft.network.packet.Packet250CustomPayload;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraftforge.liquids.LiquidStack;
|
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 TileEntityPipe pipe = null;
|
||||||
private boolean shouldUpdate = false;
|
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
|
@Override
|
||||||
public boolean canBePlacedOnPipe(TileEntityPipe pipe)
|
public boolean canBePlacedOnPipe(TileEntityPipe pipe)
|
||||||
{
|
{
|
||||||
|
@ -59,10 +79,13 @@ public class TileEntityPipeWindow extends TileEntity implements IPipeExtention
|
||||||
return 10;
|
return 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldSendPacket()
|
public IPipeExtentionRender getExtentionRenderClass()
|
||||||
{
|
{
|
||||||
return shouldUpdate;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue