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.

This commit is contained in:
Krapht 2012-07-17 00:12:15 +02:00
parent 68a911f36a
commit 24e342abbc
11 changed files with 101 additions and 63 deletions

View file

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

View file

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

View file

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

View file

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

View file

@ -20,6 +20,7 @@ public class EnergyPulser {
}
public void update() {
if (powerReceptor == null) return;
// Set current pulse speed
pulseSpeed = getPulseSpeed();

View file

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

View file

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

View file

@ -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 **/

View file

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

View file

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

View file

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