Added gatekind to corestate + some cleanup

This commit is contained in:
Krapht 2012-08-22 21:43:55 +02:00
parent e9469ef933
commit bedc265c66
7 changed files with 33 additions and 118 deletions

View file

@ -1,40 +0,0 @@
package buildcraft.core.network;
import buildcraft.transport.Pipe;
public class PacketPipeDescription extends PacketUpdate {
public PacketPipeDescription() {}
public PacketPipeDescription(int posX, int posY, int posZ, Pipe pipe) {
super(PacketIds.PIPE_DESCRIPTION);
PacketPayload payload = new PacketPayload(5, 0, 0);
this.posX = posX;
this.posY = posY;
this.posZ = posZ;
// / Null pipe
if (pipe == null) {
payload.intPayload[0] = 0;
this.payload = payload;
return;
}
// / Need to synch ID, wires and gates
payload.intPayload[0] = pipe.itemID;
this.payload = payload;
for (int i = 0; i < 4; ++i)
if (pipe.wireSet[i])
payload.intPayload[1 + i] = 1;
else
payload.intPayload[1 + i] = 0;
if (pipe.gate != null)
this.payload.append(pipe.gate.toPayload());
}
}

View file

@ -18,5 +18,5 @@ public interface ISyncedTile {
* Called after a state has been updated
* @param stateId
*/
public void stateUpdated(byte stateId);
public void afterStateUpdated(byte stateId);
}

View file

@ -52,7 +52,7 @@ public class PacketTileState extends PacketCoordinates {
for (int i = 0; i < stateCount; i++) {
byte stateId = data.readByte();
tile.getStateInstance(stateId).readData(data);
tile.stateUpdated(stateId);
tile.afterStateUpdated(stateId);
}
}

View file

@ -320,8 +320,6 @@ public class BlockGenericPipe extends BlockContainer {
pipe.wireSet[IPipe.WireColor.Green.ordinal()] = true;
entityplayer.getCurrentEquippedItem().splitStack(1);
pipe.container.scheduleRenderUpdate();
//world.markBlockNeedsUpdate(i, j, k);
return true;
}
} else if (entityplayer.getCurrentEquippedItem().getItem() == BuildCraftTransport.yellowPipeWire) {
@ -329,8 +327,6 @@ public class BlockGenericPipe extends BlockContainer {
pipe.wireSet[IPipe.WireColor.Yellow.ordinal()] = true;
entityplayer.getCurrentEquippedItem().splitStack(1);
pipe.container.scheduleRenderUpdate();
//world.markBlockNeedsUpdate(i, j, k);
return true;
}
} else if (entityplayer.getCurrentEquippedItem().itemID == BuildCraftTransport.pipeGate.shiftedIndex
@ -340,8 +336,6 @@ public class BlockGenericPipe extends BlockContainer {
pipe.gate = new GateVanilla(pipe, entityplayer.getCurrentEquippedItem());
entityplayer.getCurrentEquippedItem().splitStack(1);
pipe.container.scheduleRenderUpdate();
//world.markBlockNeedsUpdate(i, j, k);
return true;
}

View file

@ -74,10 +74,6 @@ public abstract class Gate {
return payload;
}
public void fromPayload(PacketPayload payload, IndexInPayload index) {
kind = GateKind.values()[payload.intPayload[index.intIndex + 0]];
}
// GUI
public abstract void openGui(EntityPlayer player);

View file

@ -9,6 +9,9 @@
package buildcraft.transport;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
@ -34,7 +37,9 @@ import buildcraft.core.network.PacketPayload;
import buildcraft.core.network.PacketUpdate;
import buildcraft.core.network.TileNetworkData;
import buildcraft.core.network.TilePacketWrapper;
import buildcraft.core.network.v2.IClientState;
import buildcraft.transport.Gate.GateConditional;
import buildcraft.transport.Gate.GateKind;
import net.minecraft.src.Entity;
import net.minecraft.src.EntityItem;
@ -45,7 +50,7 @@ import net.minecraft.src.TileEntity;
import net.minecraft.src.World;
public abstract class Pipe implements IPipe, IDropControlInventory {
public int[] signalStrength = new int[] { 0, 0, 0, 0 };
public int xCoord;
@ -62,9 +67,8 @@ public abstract class Pipe implements IPipe, IDropControlInventory {
private boolean internalUpdateScheduled = false;
@TileNetworkData(intKind = TileNetworkData.UNSIGNED_BYTE)
public boolean[] wireSet = new boolean[] { false, false, false, false };
public Gate gate;
@SuppressWarnings("rawtypes")
@ -74,7 +78,6 @@ public abstract class Pipe implements IPipe, IDropControlInventory {
public ITriggerParameter[] triggerParameters = new ITriggerParameter[8];
public IAction[] activatedActions = new Action[8];
@TileNetworkData(intKind = TileNetworkData.UNSIGNED_BYTE)
public boolean broadcastSignal[] = new boolean[] { false, false, false, false };
public boolean broadcastRedstone = false;
@ -176,8 +179,6 @@ public abstract class Pipe implements IPipe, IDropControlInventory {
// Do not try to update gates client side.
if (worldObj.isRemote) return;
// if(CoreProxy.isRemote())
// return;
if (actionTracker.markTimeIfDelay(worldObj, 10))
resolveActions();
@ -362,47 +363,6 @@ public abstract class Pipe implements IPipe, IDropControlInventory {
}
public PacketPayload getNetworkPacket() {
PacketPayload payload = networkPacket.toPayload(xCoord, yCoord, zCoord, new Object[] { container, transport, logic });
return payload;
}
/**
* This is used by update packets and uses TileNetworkData. Should be
* unified with description packets!
*
* @param packet
*/
public void handlePacket(PacketUpdate packet) {
networkPacket.fromPayload(new Object[] { container, transport, logic }, packet.payload);
}
/**
* This is used by description packets.
*
* @param payload
* @param index
*/
public void handleWirePayload(PacketPayload payload, IndexInPayload index) {
for (int i = index.intIndex; i < index.intIndex + 4; i++)
if (payload.intPayload[i] > 0)
wireSet[i - index.intIndex] = true;
else
wireSet[i - index.intIndex] = false;
}
/**
* This is used by description packets.
*
* @param payload
* @param index
*/
public void handleGatePayload(PacketPayload payload, IndexInPayload index) {
gate = new GateVanilla(this);
gate.fromPayload(payload, index);
}
public boolean isPoweringTo(int l) {
if (!broadcastRedstone)
return false;
@ -683,4 +643,6 @@ public abstract class Pipe implements IPipe, IDropControlInventory {
* Called when TileGenericPipe.onChunkUnload is called
*/
public void onChunkUnload() {}
}

View file

@ -40,6 +40,7 @@ import buildcraft.core.Utils;
import buildcraft.core.network.v2.IClientState;
import buildcraft.core.network.v2.ISyncedTile;
import buildcraft.core.network.v2.PacketTileState;
import buildcraft.transport.Gate.GateKind;
import buildcraft.transport.network.PipeRenderStatePacket;
import net.minecraft.src.Block;
@ -54,16 +55,19 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ITank
private class CoreState implements IClientState {
public int pipeId;
public int pipeId = -1;
public int gateKind = 0;
@Override
public void writeData(DataOutputStream data) throws IOException {
data.writeInt(pipeId);
data.writeInt(gateKind);
}
@Override
public void readData(DataInputStream data) throws IOException {
pipeId = data.readInt();
gateKind = data.readInt();
}
}
@ -84,11 +88,6 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ITank
private int[] facadeBlocks = new int[Orientations.dirs().length];
private int[] facadeMeta = new int[Orientations.dirs().length];
//Store the pipe key to prevent losing pipes when a user forgets to include an addon
int key;
//public int pipeId = -1;
public TileGenericPipe() {
}
@ -101,7 +100,7 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ITank
nbttagcompound.setInteger("pipeId", pipe.itemID);
pipe.writeToNBT(nbttagcompound);
} else
nbttagcompound.setInteger("pipeId", key);
nbttagcompound.setInteger("pipeId", coreState.pipeId);
for (int i = 0; i < Orientations.dirs().length; i++){
nbttagcompound.setInteger("facadeBlocks[" + i + "]", facadeBlocks[i]);
@ -114,9 +113,8 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ITank
public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound);
key = nbttagcompound.getInteger("pipeId");
pipe = BlockGenericPipe.createPipe(key);
coreState.pipeId = nbttagcompound.getInteger("pipeId");
pipe = BlockGenericPipe.createPipe(coreState.pipeId);
if (pipe != null) {
pipe.readFromNBT(nbttagcompound);
@ -144,7 +142,7 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ITank
bindPipe();
if (pipe != null) {
pipe.validate();
}
}
}
public boolean initialized = false;
@ -251,7 +249,6 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ITank
if (renderState.isDirty()){
//worldObj.markBlockAsNeedsUpdate(this.xCoord, this.yCoord, this.zCoord);
worldObj.markBlockNeedsUpdate(this.xCoord, this.yCoord, this.zCoord);
renderState.clean();
}
@ -382,12 +379,14 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ITank
@Override
public Packet getAuxillaryInfoPacket() {
bindPipe();
// PipeRenderStatePacket packet = new PipeRenderStatePacket(this.renderState, this.pipeId, xCoord, yCoord, zCoord);
// return packet.getPacket();
//return super.getAuxillaryInfoPacket();
PacketTileState packet = new PacketTileState(this.xCoord, this.yCoord, this.zCoord);
packet.addStateForSerialization((byte )0, coreState);
if (pipe != null && pipe.gate != null){
coreState.gateKind = pipe.gate.kind.ordinal();
} else {
coreState.gateKind = 0;
}
packet.addStateForSerialization((byte) 0, coreState);
packet.addStateForSerialization((byte) 1, renderState);
return packet.getPacket();
}
@ -564,7 +563,6 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ITank
this.facadeBlocks[direction.ordinal()] = blockid;
this.facadeMeta[direction.ordinal()] = meta;
scheduleRenderUpdate();
//refreshRenderState();
return true;
}
@ -580,7 +578,6 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ITank
this.facadeBlocks[direction.ordinal()] = 0;
this.facadeMeta[direction.ordinal()] = 0;
scheduleRenderUpdate();
//refreshRenderState();
}
/** IPipeRenderState implementation **/
@ -600,7 +597,7 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ITank
}
@Override
public void stateUpdated(byte stateId) {
public void afterStateUpdated(byte stateId) {
if (!worldObj.isRemote) return;
switch (stateId){
@ -608,6 +605,12 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ITank
if (pipe == null && coreState.pipeId != 0){
initialize(BlockGenericPipe.createPipe(coreState.pipeId));
}
if (pipe != null) {
if (pipe.gate == null) {
pipe.gate = new GateVanilla(pipe);
}
pipe.gate.kind = GateKind.values()[coreState.gateKind];
}
break;
}
worldObj.markBlockAsNeedsUpdate(xCoord, yCoord, zCoord);