worked on pipe addon's packet handling
Its really hard to test this code at the moment but it should be mostly done.
This commit is contained in:
parent
dc40ad0eef
commit
0ae6eb5283
5 changed files with 144 additions and 50 deletions
|
@ -3,10 +3,12 @@ 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;
|
||||
|
@ -36,9 +38,17 @@ public class RenderPipe extends TileEntitySpecialRenderer
|
|||
meta = te.getBlockMetadata();
|
||||
TileEntityPipe pipe = ((TileEntityPipe) te);
|
||||
this.renderSide = pipe.renderConnection;
|
||||
for(int i = 0; i < 6; i++)
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
IPipeExtention extention = (IPipeExtention) pipe.subEntities[i];
|
||||
if (extention != null)
|
||||
{
|
||||
IPipeExtentionRender render = extention.getExtentionRenderClass();
|
||||
if (render != null)
|
||||
{
|
||||
render.renderAModelAt(pipe, d, d1, d2, f, ForgeDirection.getOrientation(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
this.render(meta, renderSide);
|
||||
|
|
|
@ -4,7 +4,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||
import fluidmech.client.render.pipeextentions.IPipeExtentionRender;
|
||||
import universalelectricity.prefab.network.IPacketReceiver;
|
||||
|
||||
public interface IPipeExtention
|
||||
public interface IPipeExtention extends IPacketReceiver
|
||||
{
|
||||
public boolean canBePlacedOnPipe(TileEntityPipe pipe);
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ import hydraulic.helpers.FluidHelper;
|
|||
import java.io.IOException;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
@ -55,7 +56,34 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer
|
|||
|
||||
public enum PacketID
|
||||
{
|
||||
PIPE_CONNECTIONS, EXTENTION;
|
||||
PIPE_CONNECTIONS, EXTENTION_FULL, EXTENTION_UPDATE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initiate()
|
||||
{
|
||||
this.updateAdjacentConnections();
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
TileEntity entity = (TileEntity) this.subEntities[i];
|
||||
if (entity != null)
|
||||
{
|
||||
this.initSubTile(i);
|
||||
this.sendExtentionToClient(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);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -65,6 +93,11 @@ 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();
|
||||
|
@ -87,7 +120,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, 0, ForgeDirection.getOrientation(i), extention.getExtentionPacketData(!this.worldObj.isRemote));
|
||||
Packet packet = PacketManager.getPacket(FluidMech.CHANNEL, this, PacketID.EXTENTION_UPDATE,ForgeDirection.getOrientation(i), extention.getExtentionPacketData(!this.worldObj.isRemote));
|
||||
PacketManager.sendPacketToClients(packet, worldObj, new Vector3(this), 50);
|
||||
}
|
||||
}
|
||||
|
@ -95,12 +128,6 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initiate()
|
||||
{
|
||||
this.updateAdjacentConnections();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate()
|
||||
{
|
||||
|
@ -129,27 +156,19 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer
|
|||
this.renderConnection[4] = dataStream.readBoolean();
|
||||
this.renderConnection[5] = dataStream.readBoolean();
|
||||
}
|
||||
if (id == PacketID.EXTENTION)
|
||||
else if (id == PacketID.EXTENTION_FULL)
|
||||
{
|
||||
int loadType = dataStream.readInt();
|
||||
int side = dataStream.readInt();
|
||||
NBTTagCompound tag = PacketManager.readNBTTagCompound(dataStream);
|
||||
/* Normal packet update */
|
||||
if (loadType == 0)
|
||||
{
|
||||
this.loadOrCreateSubTile(side, PacketManager.readNBTTagCompound(dataStream));
|
||||
|
||||
}
|
||||
/* Full packet Load */
|
||||
else if (loadType == 1)
|
||||
}
|
||||
else if (id == PacketID.EXTENTION_UPDATE)
|
||||
{
|
||||
int side = dataStream.readInt();
|
||||
if (this.subEntities[side] instanceof IPipeExtention)
|
||||
{
|
||||
this.subEntities[side] = null;
|
||||
TileEntity entity = TileEntity.createAndLoadEntity(tag);
|
||||
if (entity != null && entity instanceof IPipeExtention)
|
||||
{
|
||||
this.subEntities[side] = (IPipeExtention) entity;
|
||||
}
|
||||
this.subEntities[side].handlePacketData(network, type, packet, player, dataStream);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -182,24 +201,67 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer
|
|||
}
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
if (this.subEntities[i] != null)
|
||||
if (nbt.hasKey("Addon" + i))
|
||||
{
|
||||
if (nbt.hasKey("Addon" + i))
|
||||
{
|
||||
NBTTagCompound tag = nbt.getCompoundTag("Addon" + i);
|
||||
if (tag != null && tag.getTags().size() != 0)
|
||||
{
|
||||
TileEntity tile = TileEntity.createAndLoadEntity(tag);
|
||||
if (tile instanceof IPipeExtention)
|
||||
{
|
||||
this.subEntities[i] = (IPipeExtention) tile;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.loadOrCreateSubTile(i, nbt.getCompoundTag("Addon" + i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean addNewExtention(int side, Class<? extends TileEntity> partClass)
|
||||
{
|
||||
if (partClass == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
try
|
||||
{
|
||||
TileEntity tile = partClass.newInstance();
|
||||
if (tile instanceof IPipeExtention)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.print("Failed to add a Pipe Extention using Class " + partClass.toString());
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void loadOrCreateSubTile(int side, NBTTagCompound tag)
|
||||
{
|
||||
if (tag != null && tag.getTags().size() != 0)
|
||||
{
|
||||
TileEntity tile = TileEntity.createAndLoadEntity(tag);
|
||||
if (tile instanceof IPipeExtention)
|
||||
{
|
||||
this.subEntities[side] = (IPipeExtention) tile;
|
||||
this.initSubTile(side);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void initSubTile(int side)
|
||||
{
|
||||
if (this.subEntities[side] instanceof TileEntity)
|
||||
{
|
||||
TileEntity tile = (TileEntity) subEntities[side];
|
||||
((IPipeExtention) tile).setPipe(this);
|
||||
tile.worldObj = this.worldObj;
|
||||
tile.xCoord = this.xCoord;
|
||||
tile.yCoord = this.yCoord;
|
||||
tile.zCoord = this.zCoord;
|
||||
}
|
||||
}
|
||||
|
||||
public TileEntity getEntitySide(ForgeDirection side)
|
||||
{
|
||||
return (TileEntity) this.subEntities[side.ordinal() & 5];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a tile entity to NBT.
|
||||
*/
|
||||
|
@ -251,6 +313,7 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer
|
|||
/* DEBUG CODE ACTIVATERS */
|
||||
boolean testConnections = false;
|
||||
boolean testNetwork = false;
|
||||
boolean testSubs = true;
|
||||
|
||||
/* NORMAL OUTPUT */
|
||||
String string = this.getNetwork().pressureProduced + "p " + this.getNetwork().getStorageFluid() + " Extra";
|
||||
|
@ -267,6 +330,22 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer
|
|||
{
|
||||
string += " " + this.getNetwork().toString();
|
||||
}
|
||||
if (testSubs)
|
||||
{
|
||||
string += " ";
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
if (this.subEntities[i] == null)
|
||||
{
|
||||
string += ":" + "Null";
|
||||
}
|
||||
else
|
||||
{
|
||||
string += ":" + this.subEntities[i].toString();
|
||||
}
|
||||
}
|
||||
string += " ";
|
||||
}
|
||||
|
||||
return string;
|
||||
}
|
||||
|
|
|
@ -21,11 +21,6 @@ public abstract class TileEntityPipeExtention extends TileEntity implements IPip
|
|||
|
||||
private TileEntityPipe masterPipe = null;
|
||||
|
||||
public TileEntityPipeExtention(TileEntityPipe pipe)
|
||||
{
|
||||
this.masterPipe = pipe;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a tile entity from NBT.
|
||||
*/
|
||||
|
@ -60,4 +55,10 @@ public abstract class TileEntityPipeExtention extends TileEntity implements IPip
|
|||
{
|
||||
this.masterPipe = pipe;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "PipeExtention";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,10 +13,6 @@ import net.minecraftforge.liquids.LiquidStack;
|
|||
|
||||
public class TileEntityPipeWindow extends TileEntityPipeExtention
|
||||
{
|
||||
public TileEntityPipeWindow(TileEntityPipe pipe)
|
||||
{
|
||||
super(pipe);
|
||||
}
|
||||
|
||||
private TileEntityPipe pipe = null;
|
||||
private boolean shouldUpdate = false;
|
||||
|
@ -26,10 +22,14 @@ public class TileEntityPipeWindow extends TileEntityPipeExtention
|
|||
@Override
|
||||
public void updateEntity()
|
||||
{
|
||||
if(pipe != null)
|
||||
if(!worldObj.isRemote && pipe != null)
|
||||
{
|
||||
stack = pipe.getNetwork().getTank().getLiquid();
|
||||
}
|
||||
if(worldObj.isRemote)
|
||||
{
|
||||
System.out.println("Alive");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -86,6 +86,10 @@ public class TileEntityPipeWindow extends TileEntityPipeExtention
|
|||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "PipeWindow";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue