Fix pipe selection box sync

Closes #1104

Also, pipes were running server code on the client. This is bad, fixed.

And killed the dead PipeRenderStatePacket.
This commit is contained in:
CovertJaguar 2013-08-14 22:58:47 -07:00
parent 4d03135b85
commit fa7faceab5
5 changed files with 18 additions and 114 deletions

View file

@ -3,7 +3,7 @@ package buildcraft.core.network;
public class PacketIds {
public static final int TILE_UPDATE = 0;
public static final int PIPE_DESCRIPTION = 1;
// public static final int PIPE_DESCRIPTION = 1;
public static final int PIPE_CONTENTS = 2;
public static final int PIPE_LIQUID = 3;
public static final int PIPE_POWER = 4;

View file

@ -566,8 +566,8 @@ public class BlockGenericPipe extends BlockContainer {
/* Wrappers ************************************************************ */
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, int l) {
super.onNeighborBlockChange(world, x, y, z, l);
public void onNeighborBlockChange(World world, int x, int y, int z, int id) {
super.onNeighborBlockChange(world, x, y, z, id);
Pipe pipe = getPipe(world, x, y, z);

View file

@ -30,12 +30,12 @@ import buildcraft.core.network.IClientState;
import buildcraft.core.network.ISyncedTile;
import buildcraft.core.network.PacketTileState;
import buildcraft.transport.Gate.GateKind;
import buildcraft.transport.network.PipeRenderStatePacket;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.logging.Level;
import net.minecraft.block.Block;
@ -149,6 +149,8 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
@Override
public void updateEntity() {
if (worldObj.isRemote)
return;
if (deletePipe)
worldObj.setBlockToAir(xCoord, yCoord, zCoord);
@ -163,7 +165,6 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
return;
if (blockNeighborChange) {
computeConnections();
pipe.onNeighborBlockChange(0);
blockNeighborChange = false;
@ -186,11 +187,6 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
// PRECONDITION: worldObj must not be null
private void refreshRenderState() {
// Only done on server/SSP
if (worldObj.isRemote)
return;
// Pipe connections;
for (ForgeDirection o : ForgeDirection.VALID_DIRECTIONS) {
renderState.pipeConnectionMatrix.setConnected(o, this.pipeConnectionsBuffer[o.ordinal()]);
@ -344,15 +340,6 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
}
/* SMP */
public void handleDescriptionPacket(PipeRenderStatePacket packet) {
if (worldObj.isRemote) {
if (pipe == null && packet.getPipeId() != 0)
initialize(BlockGenericPipe.createPipe(packet.getPipeId()));
renderState = packet.getRenderState();
worldObj.markBlockForRenderUpdate(xCoord, yCoord, zCoord);
}
}
@Override
public Packet getDescriptionPacket() {
bindPipe();
@ -429,6 +416,9 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
* @return true if pipes are considered connected
*/
protected boolean canPipeConnect(TileEntity with, ForgeDirection side) {
if (with == null)
return false;
if (hasPlug(side))
return false;
@ -458,21 +448,21 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
private void computeConnections() {
TileBuffer[] cache = getTileCache();
if (cache != null) {
pipeConnectionsBuffer = new boolean[6];
if (cache == null)
return;
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
TileBuffer t = cache[side.ordinal()];
t.refresh();
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
TileBuffer t = cache[side.ordinal()];
t.refresh();
if (t.getTile() != null)
pipeConnectionsBuffer[side.ordinal()] = canPipeConnect(t.getTile(), side);
}
pipeConnectionsBuffer[side.ordinal()] = canPipeConnect(t.getTile(), side);
}
}
@Override
public boolean isPipeConnected(ForgeDirection with) {
if (worldObj.isRemote)
return renderState.pipeConnectionMatrix.isConnected(with);
return pipeConnectionsBuffer[with.ordinal()];
}
@ -618,6 +608,7 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
case 0:
if (pipe == null && coreState.pipeId != 0)
initialize(BlockGenericPipe.createPipe(coreState.pipeId));
if (pipe != null && coreState.gateKind != GateKind.None.ordinal()) {
if (pipe.gate == null)
pipe.gate = new GateVanilla(pipe);

View file

@ -43,11 +43,6 @@ public class PacketHandlerTransport implements IPacketHandler {
PacketFluidUpdate packetFluid = new PacketFluidUpdate();
packetFluid.readData(data);
break;
case PacketIds.PIPE_DESCRIPTION:
PipeRenderStatePacket descPacket = new PipeRenderStatePacket();
descPacket.readData(data);
onPipeDescription((EntityPlayer) player, descPacket);
break;
case PacketIds.PIPE_CONTENTS:
PacketPipeTransportContent packetC = new PacketPipeTransportContent();
packetC.readData(data);
@ -172,30 +167,6 @@ public class PacketHandlerTransport implements IPacketHandler {
((PipeTransportItems)pipe.pipe.transport).handleNBTPacket(packet);
}
/**
* Handles a pipe description packet. (Creates the pipe object client side if needed.)
*
* @param descPacket
*/
private void onPipeDescription(EntityPlayer player, PipeRenderStatePacket descPacket) {
World world = player.worldObj;
if (!world.blockExists(descPacket.posX, descPacket.posY, descPacket.posZ))
return;
TileEntity entity = world.getBlockTileEntity(descPacket.posX, descPacket.posY, descPacket.posZ);
if (entity == null)
return;
// entity = new TileGenericPipeProxy();
// world.setBlockTileEntity(descPacket.posX, descPacket.posY, descPacket.posZ, entity);
if (!(entity instanceof TileGenericPipe))
return;
TileGenericPipe tile = (TileGenericPipe) entity;
tile.handleDescriptionPacket(descPacket);
}
/**
* Updates items in a pipe.
*

View file

@ -1,58 +0,0 @@
package buildcraft.transport.network;
import buildcraft.core.network.PacketCoordinates;
import buildcraft.core.network.PacketIds;
import buildcraft.transport.PipeRenderState;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
public class PipeRenderStatePacket extends PacketCoordinates {
private PipeRenderState renderState;
public int pipeId;
public PipeRenderStatePacket() {
}
public PipeRenderStatePacket(PipeRenderState renderState, int pipeId, int x, int y, int z) {
super(PacketIds.PIPE_DESCRIPTION, x, y, z);
this.pipeId = pipeId;
this.isChunkDataPacket = true;
this.renderState = renderState;
}
public PipeRenderState getRenderState() {
return this.renderState;
}
@Override
public void writeData(DataOutputStream data) throws IOException {
super.writeData(data);
data.writeInt(pipeId);
renderState.writeData(data);
}
@Override
public void readData(DataInputStream data) throws IOException {
super.readData(data);
pipeId = data.readInt();
renderState = new PipeRenderState();
renderState.readData(data);
}
@Override
public int getID() {
return PacketIds.PIPE_DESCRIPTION;
}
public void setPipeId(int pipeId) {
this.pipeId = pipeId;
}
public int getPipeId() {
return pipeId;
}
}