From 24e342abbc2a010f2387f830f031359a7e31e3b1 Mon Sep 17 00:00:00 2001 From: Krapht Date: Tue, 17 Jul 2012 00:12:15 +0200 Subject: [PATCH] Adds sync to renderstate (works in SMP), however, pipe-content sync is now broken, as are any gate interfaces for gates that you have not placed yourself. Also fixes autarchic gates being converted to non-autarchic gates. --- .../transport/network/PacketHandler.java | 30 +++++--- .../src/mod_BuildCraftTransport.java | 6 +- .../buildcraft/core/network/PacketIds.java | 2 - .../transport/BlockGenericPipe.java | 1 + .../buildcraft/transport/EnergyPulser.java | 1 + .../src/buildcraft/transport/GateVanilla.java | 5 +- .../buildcraft/transport/PipeRenderState.java | 6 ++ .../buildcraft/transport/TileGenericPipe.java | 75 +++++++++---------- .../network/PipeRenderStatePacket.java | 32 +++++++- .../transport/utils/TextureMatrix.java | 4 +- .../transport/utils/WireMatrix.java | 2 + 11 files changed, 101 insertions(+), 63 deletions(-) diff --git a/buildcraft_client/net/minecraft/src/buildcraft/transport/network/PacketHandler.java b/buildcraft_client/net/minecraft/src/buildcraft/transport/network/PacketHandler.java index babed103..f462d98b 100644 --- a/buildcraft_client/net/minecraft/src/buildcraft/transport/network/PacketHandler.java +++ b/buildcraft_client/net/minecraft/src/buildcraft/transport/network/PacketHandler.java @@ -19,6 +19,7 @@ import net.minecraft.src.buildcraft.core.network.PacketPipeTransportContent; import net.minecraft.src.buildcraft.core.network.PacketUpdate; import net.minecraft.src.buildcraft.transport.CraftingGateInterface; import net.minecraft.src.buildcraft.transport.PipeLogicDiamond; +import net.minecraft.src.buildcraft.transport.PipeRenderState; import net.minecraft.src.buildcraft.transport.PipeTransportItems; import net.minecraft.src.buildcraft.transport.TileGenericPipe; import net.minecraft.src.forge.IPacketHandler; @@ -42,9 +43,12 @@ public class PacketHandler implements IPacketHandler { onDiamondContents(packetN); break; case PacketIds.PIPE_DESCRIPTION: - PacketPipeDescription packetU = new PacketPipeDescription(); - packetU.readData(data); - onPipeDescription(packetU); + PipeRenderStatePacket descPacket = new PipeRenderStatePacket(); + descPacket.readData(data); + onPipeDescription(descPacket); +// PacketPipeDescription packetU = new PacketPipeDescription(); +// packetU.readData(data); +// onPipeDescription(packetU); break; case PacketIds.PIPE_CONTENTS: PacketPipeTransportContent packetC = new PacketPipeTransportContent(); @@ -116,20 +120,26 @@ public class PacketHandler implements IPacketHandler { * Handles a pipe description packet. (Creates the pipe object client side * if needed.) * - * @param packet + * @param descPacket */ - private void onPipeDescription(PacketPipeDescription packet) { + private void onPipeDescription(PipeRenderStatePacket descPacket) { World world = ModLoader.getMinecraftInstance().theWorld; - if (!world.blockExists(packet.posX, packet.posY, packet.posZ)) + if (!world.blockExists(descPacket.posX, descPacket.posY, descPacket.posZ)) return; - TileEntity entity = world.getBlockTileEntity(packet.posX, packet.posY, packet.posZ); - if (!(entity instanceof ISynchronizedTile)) + 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; - ISynchronizedTile tile = (ISynchronizedTile) entity; - tile.handleDescriptionPacket(packet); + TileGenericPipe tile = (TileGenericPipe) entity; + tile.handleDescriptionPacket(descPacket); } /** diff --git a/buildcraft_client/net/minecraft/src/mod_BuildCraftTransport.java b/buildcraft_client/net/minecraft/src/mod_BuildCraftTransport.java index 5a052b71..3886a04e 100644 --- a/buildcraft_client/net/minecraft/src/mod_BuildCraftTransport.java +++ b/buildcraft_client/net/minecraft/src/mod_BuildCraftTransport.java @@ -94,9 +94,9 @@ public class mod_BuildCraftTransport extends NetworkMod { TileEntity tile = world.getBlockTileEntity(x, y, z); - if (tile instanceof TileGenericPipe){ - TileGenericPipe pipeTile = (TileGenericPipe) tile; - pipeWorldRenderer.renderPipe(renderer, world, block, ((IPipeRenderState)tile).getRenderState(), pipeTile.xCoord, pipeTile.yCoord, pipeTile.zCoord); + if (tile instanceof IPipeRenderState){ + IPipeRenderState pipeTile = (IPipeRenderState) tile; + pipeWorldRenderer.renderPipe(renderer, world, block, pipeTile.getRenderState(), x, y, z); } // if (tile != null && tile instanceof IPipeTile && ((IPipeTile)tile).isInitialized()) { // pipeWorldRenderer.renderPipe(renderer, world, tile, block); diff --git a/common/net/minecraft/src/buildcraft/core/network/PacketIds.java b/common/net/minecraft/src/buildcraft/core/network/PacketIds.java index 6edc4351..e042c4e3 100644 --- a/common/net/minecraft/src/buildcraft/core/network/PacketIds.java +++ b/common/net/minecraft/src/buildcraft/core/network/PacketIds.java @@ -16,6 +16,4 @@ public class PacketIds { public static final int GATE_SELECTION_CHANGE = 44; public static final int GATE_TRIGGERS = 45; public static final int REFINERY_FILTER_SET = 50; - - public static final int PIPE_RENDER_STATE = 60; } diff --git a/common/net/minecraft/src/buildcraft/transport/BlockGenericPipe.java b/common/net/minecraft/src/buildcraft/transport/BlockGenericPipe.java index a39048f8..a665c473 100644 --- a/common/net/minecraft/src/buildcraft/transport/BlockGenericPipe.java +++ b/common/net/minecraft/src/buildcraft/transport/BlockGenericPipe.java @@ -510,6 +510,7 @@ public class BlockGenericPipe extends BlockContainer implements ITextureProvider } public static boolean placePipe(Pipe pipe, World world, int i, int j, int k, int blockId, int meta) { + if (world.isRemote) return true; boolean placed = world.setBlockAndMetadataWithNotify(i, j, k, blockId, meta); diff --git a/common/net/minecraft/src/buildcraft/transport/EnergyPulser.java b/common/net/minecraft/src/buildcraft/transport/EnergyPulser.java index a2265166..c6a65631 100644 --- a/common/net/minecraft/src/buildcraft/transport/EnergyPulser.java +++ b/common/net/minecraft/src/buildcraft/transport/EnergyPulser.java @@ -20,6 +20,7 @@ public class EnergyPulser { } public void update() { + if (powerReceptor == null) return; // Set current pulse speed pulseSpeed = getPulseSpeed(); diff --git a/common/net/minecraft/src/buildcraft/transport/GateVanilla.java b/common/net/minecraft/src/buildcraft/transport/GateVanilla.java index 3fb8e8c7..e479e11b 100644 --- a/common/net/minecraft/src/buildcraft/transport/GateVanilla.java +++ b/common/net/minecraft/src/buildcraft/transport/GateVanilla.java @@ -118,9 +118,10 @@ public class GateVanilla extends Gate { * @return */ private boolean addEnergyPulser(Pipe pipe) { - if (!(pipe instanceof IPowerReceptor)) + if (!(pipe instanceof IPowerReceptor)){ + pulser = new EnergyPulser(null); return false; - + } pulser = new EnergyPulser((IPowerReceptor) pipe); return true; diff --git a/common/net/minecraft/src/buildcraft/transport/PipeRenderState.java b/common/net/minecraft/src/buildcraft/transport/PipeRenderState.java index d642cda8..42ab1129 100644 --- a/common/net/minecraft/src/buildcraft/transport/PipeRenderState.java +++ b/common/net/minecraft/src/buildcraft/transport/PipeRenderState.java @@ -88,16 +88,22 @@ public class PipeRenderState { public void writeData(DataOutputStream data) throws IOException { data.writeUTF(textureFile); + data.writeBoolean(hasGate); + data.writeInt(gateTextureIndex); pipeConnectionMatrix.writeData(data); textureMatrix.writeData(data); wireMatrix.writeData(data); + facadeMatrix.writeData(data); } public void readData(DataInputStream data) throws IOException { textureFile = data.readUTF(); + hasGate = data.readBoolean(); + gateTextureIndex = data.readInt(); pipeConnectionMatrix.readData(data); textureMatrix.readData(data); wireMatrix.readData(data); + facadeMatrix.readData(data); } } diff --git a/common/net/minecraft/src/buildcraft/transport/TileGenericPipe.java b/common/net/minecraft/src/buildcraft/transport/TileGenericPipe.java index 4529f3c8..a93b308d 100644 --- a/common/net/minecraft/src/buildcraft/transport/TileGenericPipe.java +++ b/common/net/minecraft/src/buildcraft/transport/TileGenericPipe.java @@ -42,17 +42,17 @@ import net.minecraft.src.buildcraft.core.IDropControlInventory; import net.minecraft.src.buildcraft.core.ITileBufferHolder; import net.minecraft.src.buildcraft.core.TileBuffer; import net.minecraft.src.buildcraft.core.Utils; -import net.minecraft.src.buildcraft.core.network.ISynchronizedTile; import net.minecraft.src.buildcraft.core.network.IndexInPayload; import net.minecraft.src.buildcraft.core.network.PacketPayload; import net.minecraft.src.buildcraft.core.network.PacketPipeDescription; import net.minecraft.src.buildcraft.core.network.PacketTileUpdate; import net.minecraft.src.buildcraft.core.network.PacketUpdate; +import net.minecraft.src.buildcraft.transport.network.PipeRenderStatePacket; public class TileGenericPipe extends TileEntity implements IPowerReceptor, ILiquidContainer, IPipeEntry, - IPipeTile, ISynchronizedTile, IOverrideDefaultTriggers, ITileBufferHolder, IPipeConnection, IDropControlInventory, IPipeRenderState { + IPipeTile, IOverrideDefaultTriggers, ITileBufferHolder, IPipeConnection, IDropControlInventory, IPipeRenderState { - private final PipeRenderState renderState = new PipeRenderState(); + private PipeRenderState renderState = new PipeRenderState(); public TileBuffer[] tileBuffer; public boolean[] pipeConnectionsBuffer = new boolean[6]; @@ -357,57 +357,50 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ILiqu return false; } - /** - * Description packets and update packets are handled differently. They - * should be unified. - */ - @Override - public void handleDescriptionPacket(PacketUpdate packet) { - - if (pipe == null && packet.payload.intPayload[0] != 0) { - - initialize(BlockGenericPipe.createPipe(packet.payload.intPayload[0])); - - // Check for wire information - pipe.handleWirePayload(packet.payload, new IndexInPayload(1, 0, 0)); - // Check for gate information - if (packet.payload.intPayload.length > 5) - pipe.handleGatePayload(packet.payload, new IndexInPayload(5, 0, 0)); + public void handleDescriptionPacket(PipeRenderStatePacket packet) { + if (worldObj.isRemote){ + if (pipe == null && packet.getPipeId() != 0){ + initialize(BlockGenericPipe.createPipe(packet.getPipeId())); + } + renderState = packet.getRenderState(); + worldObj.markBlockAsNeedsUpdate(xCoord, yCoord, zCoord); } + + + + return; + + +// if (pipe == null && packet.payload.intPayload[0] != 0) { +// +// initialize(BlockGenericPipe.createPipe(packet.payload.intPayload[0])); +// +// // Check for wire information +// pipe.handleWirePayload(packet.payload, new IndexInPayload(1, 0, 0)); +// // Check for gate information +// if (packet.payload.intPayload.length > 5) +// pipe.handleGatePayload(packet.payload, new IndexInPayload(5, 0, 0)); +// } } - @Override + //@Override public void handleUpdatePacket(PacketUpdate packet) { if (BlockGenericPipe.isValid(pipe)) pipe.handlePacket(packet); } - @Override - public void postPacketHandling(PacketUpdate packet) {} - - @Override + //@Override public Packet getUpdatePacket() { - return new PacketTileUpdate(this).getPacket(); + return null; + //return new PacketTileUpdate(this).getPacket(); } - @Override public Packet getDescriptionPacket() { bindPipe(); - - PacketPipeDescription packet; - if (pipe != null) - packet = new PacketPipeDescription(xCoord, yCoord, zCoord, pipe); - else - packet = new PacketPipeDescription(xCoord, yCoord, zCoord, null); - + PipeRenderStatePacket packet = new PipeRenderStatePacket(this.renderState, this.pipeId, xCoord, yCoord, zCoord); return packet.getPacket(); } - @Override - public PacketPayload getPacketPayload() { - return pipe.getNetworkPacket(); - } - @Override public int powerRequest() { return getPowerProvider().maxEnergyReceived; @@ -535,7 +528,8 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ILiqu this.facadeBlocks[direction.ordinal()] = blockid; this.facadeMeta[direction.ordinal()] = meta; - refreshRenderState(); + scheduleRenderUpdate(); + //refreshRenderState(); return true; } @@ -550,7 +544,8 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ILiqu Utils.dropItems(worldObj, new ItemStack(BuildCraftTransport.facadeItem, 1, ItemFacade.encode(this.facadeBlocks[direction.ordinal()], this.facadeMeta[direction.ordinal()])), this.xCoord, this.yCoord, this.zCoord); this.facadeBlocks[direction.ordinal()] = 0; this.facadeMeta[direction.ordinal()] = 0; - refreshRenderState(); + scheduleRenderUpdate(); + //refreshRenderState(); } /** IPipeRenderState implementation **/ diff --git a/common/net/minecraft/src/buildcraft/transport/network/PipeRenderStatePacket.java b/common/net/minecraft/src/buildcraft/transport/network/PipeRenderStatePacket.java index 49f1d289..4823d196 100644 --- a/common/net/minecraft/src/buildcraft/transport/network/PipeRenderStatePacket.java +++ b/common/net/minecraft/src/buildcraft/transport/network/PipeRenderStatePacket.java @@ -11,26 +11,50 @@ import net.minecraft.src.buildcraft.transport.PipeRenderState; public class PipeRenderStatePacket extends PacketCoordinates { private PipeRenderState renderState; + public int pipeId; - public PipeRenderStatePacket(PipeRenderState renderState, int x, int y, int z) { - super(PacketIds.PIPE_RENDER_STATE, x, y, z); + + 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_RENDER_STATE; + return PacketIds.PIPE_DESCRIPTION; + } + + public void setPipeId(int pipeId){ + this.pipeId = pipeId; + } + + public int getPipeId() { + return pipeId; } } diff --git a/common/net/minecraft/src/buildcraft/transport/utils/TextureMatrix.java b/common/net/minecraft/src/buildcraft/transport/utils/TextureMatrix.java index 24c13e67..1b829cef 100644 --- a/common/net/minecraft/src/buildcraft/transport/utils/TextureMatrix.java +++ b/common/net/minecraft/src/buildcraft/transport/utils/TextureMatrix.java @@ -32,13 +32,13 @@ public class TextureMatrix { } public void writeData(DataOutputStream data) throws IOException { - for(int i = 0; i < Orientations.dirs().length; i++){ + for(int i = 0; i < Orientations.values().length; i++){ data.writeInt(_textureIndexes[i]); } } public void readData(DataInputStream data) throws IOException { - for (int i = 0; i < Orientations.dirs().length; i++){ + for (int i = 0; i < Orientations.values().length; i++){ _textureIndexes[i] = data.readInt(); } } diff --git a/common/net/minecraft/src/buildcraft/transport/utils/WireMatrix.java b/common/net/minecraft/src/buildcraft/transport/utils/WireMatrix.java index 1d89547d..76deb92b 100644 --- a/common/net/minecraft/src/buildcraft/transport/utils/WireMatrix.java +++ b/common/net/minecraft/src/buildcraft/transport/utils/WireMatrix.java @@ -71,6 +71,7 @@ public class WireMatrix { for (int i = 0; i < IPipe.WireColor.values().length; i++){ data.writeBoolean(_hasWire[i]); _wires[i].writeData(data); + data.writeInt(_wireTextureIndex[i]); } } @@ -78,6 +79,7 @@ public class WireMatrix { for (int i = 0; i < IPipe.WireColor.values().length; i++){ _hasWire[i] = data.readBoolean(); _wires[i].readData(data); + _wireTextureIndex[i] = data.readInt(); } } }