Added gatekind to corestate + some cleanup
This commit is contained in:
parent
e9469ef933
commit
bedc265c66
7 changed files with 33 additions and 118 deletions
|
@ -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());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -18,5 +18,5 @@ public interface ISyncedTile {
|
||||||
* Called after a state has been updated
|
* Called after a state has been updated
|
||||||
* @param stateId
|
* @param stateId
|
||||||
*/
|
*/
|
||||||
public void stateUpdated(byte stateId);
|
public void afterStateUpdated(byte stateId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ public class PacketTileState extends PacketCoordinates {
|
||||||
for (int i = 0; i < stateCount; i++) {
|
for (int i = 0; i < stateCount; i++) {
|
||||||
byte stateId = data.readByte();
|
byte stateId = data.readByte();
|
||||||
tile.getStateInstance(stateId).readData(data);
|
tile.getStateInstance(stateId).readData(data);
|
||||||
tile.stateUpdated(stateId);
|
tile.afterStateUpdated(stateId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -320,8 +320,6 @@ public class BlockGenericPipe extends BlockContainer {
|
||||||
pipe.wireSet[IPipe.WireColor.Green.ordinal()] = true;
|
pipe.wireSet[IPipe.WireColor.Green.ordinal()] = true;
|
||||||
entityplayer.getCurrentEquippedItem().splitStack(1);
|
entityplayer.getCurrentEquippedItem().splitStack(1);
|
||||||
pipe.container.scheduleRenderUpdate();
|
pipe.container.scheduleRenderUpdate();
|
||||||
//world.markBlockNeedsUpdate(i, j, k);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else if (entityplayer.getCurrentEquippedItem().getItem() == BuildCraftTransport.yellowPipeWire) {
|
} else if (entityplayer.getCurrentEquippedItem().getItem() == BuildCraftTransport.yellowPipeWire) {
|
||||||
|
@ -329,8 +327,6 @@ public class BlockGenericPipe extends BlockContainer {
|
||||||
pipe.wireSet[IPipe.WireColor.Yellow.ordinal()] = true;
|
pipe.wireSet[IPipe.WireColor.Yellow.ordinal()] = true;
|
||||||
entityplayer.getCurrentEquippedItem().splitStack(1);
|
entityplayer.getCurrentEquippedItem().splitStack(1);
|
||||||
pipe.container.scheduleRenderUpdate();
|
pipe.container.scheduleRenderUpdate();
|
||||||
//world.markBlockNeedsUpdate(i, j, k);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else if (entityplayer.getCurrentEquippedItem().itemID == BuildCraftTransport.pipeGate.shiftedIndex
|
} else if (entityplayer.getCurrentEquippedItem().itemID == BuildCraftTransport.pipeGate.shiftedIndex
|
||||||
|
@ -340,8 +336,6 @@ public class BlockGenericPipe extends BlockContainer {
|
||||||
pipe.gate = new GateVanilla(pipe, entityplayer.getCurrentEquippedItem());
|
pipe.gate = new GateVanilla(pipe, entityplayer.getCurrentEquippedItem());
|
||||||
entityplayer.getCurrentEquippedItem().splitStack(1);
|
entityplayer.getCurrentEquippedItem().splitStack(1);
|
||||||
pipe.container.scheduleRenderUpdate();
|
pipe.container.scheduleRenderUpdate();
|
||||||
//world.markBlockNeedsUpdate(i, j, k);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -74,10 +74,6 @@ public abstract class Gate {
|
||||||
return payload;
|
return payload;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fromPayload(PacketPayload payload, IndexInPayload index) {
|
|
||||||
kind = GateKind.values()[payload.intPayload[index.intIndex + 0]];
|
|
||||||
}
|
|
||||||
|
|
||||||
// GUI
|
// GUI
|
||||||
public abstract void openGui(EntityPlayer player);
|
public abstract void openGui(EntityPlayer player);
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,9 @@
|
||||||
|
|
||||||
package buildcraft.transport;
|
package buildcraft.transport;
|
||||||
|
|
||||||
|
import java.io.DataInputStream;
|
||||||
|
import java.io.DataOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -34,7 +37,9 @@ import buildcraft.core.network.PacketPayload;
|
||||||
import buildcraft.core.network.PacketUpdate;
|
import buildcraft.core.network.PacketUpdate;
|
||||||
import buildcraft.core.network.TileNetworkData;
|
import buildcraft.core.network.TileNetworkData;
|
||||||
import buildcraft.core.network.TilePacketWrapper;
|
import buildcraft.core.network.TilePacketWrapper;
|
||||||
|
import buildcraft.core.network.v2.IClientState;
|
||||||
import buildcraft.transport.Gate.GateConditional;
|
import buildcraft.transport.Gate.GateConditional;
|
||||||
|
import buildcraft.transport.Gate.GateKind;
|
||||||
|
|
||||||
import net.minecraft.src.Entity;
|
import net.minecraft.src.Entity;
|
||||||
import net.minecraft.src.EntityItem;
|
import net.minecraft.src.EntityItem;
|
||||||
|
@ -62,7 +67,6 @@ public abstract class Pipe implements IPipe, IDropControlInventory {
|
||||||
|
|
||||||
private boolean internalUpdateScheduled = false;
|
private boolean internalUpdateScheduled = false;
|
||||||
|
|
||||||
@TileNetworkData(intKind = TileNetworkData.UNSIGNED_BYTE)
|
|
||||||
public boolean[] wireSet = new boolean[] { false, false, false, false };
|
public boolean[] wireSet = new boolean[] { false, false, false, false };
|
||||||
|
|
||||||
public Gate gate;
|
public Gate gate;
|
||||||
|
@ -74,7 +78,6 @@ public abstract class Pipe implements IPipe, IDropControlInventory {
|
||||||
public ITriggerParameter[] triggerParameters = new ITriggerParameter[8];
|
public ITriggerParameter[] triggerParameters = new ITriggerParameter[8];
|
||||||
public IAction[] activatedActions = new Action[8];
|
public IAction[] activatedActions = new Action[8];
|
||||||
|
|
||||||
@TileNetworkData(intKind = TileNetworkData.UNSIGNED_BYTE)
|
|
||||||
public boolean broadcastSignal[] = new boolean[] { false, false, false, false };
|
public boolean broadcastSignal[] = new boolean[] { false, false, false, false };
|
||||||
public boolean broadcastRedstone = false;
|
public boolean broadcastRedstone = false;
|
||||||
|
|
||||||
|
@ -176,8 +179,6 @@ public abstract class Pipe implements IPipe, IDropControlInventory {
|
||||||
|
|
||||||
// Do not try to update gates client side.
|
// Do not try to update gates client side.
|
||||||
if (worldObj.isRemote) return;
|
if (worldObj.isRemote) return;
|
||||||
// if(CoreProxy.isRemote())
|
|
||||||
// return;
|
|
||||||
|
|
||||||
if (actionTracker.markTimeIfDelay(worldObj, 10))
|
if (actionTracker.markTimeIfDelay(worldObj, 10))
|
||||||
resolveActions();
|
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) {
|
public boolean isPoweringTo(int l) {
|
||||||
if (!broadcastRedstone)
|
if (!broadcastRedstone)
|
||||||
return false;
|
return false;
|
||||||
|
@ -683,4 +643,6 @@ public abstract class Pipe implements IPipe, IDropControlInventory {
|
||||||
* Called when TileGenericPipe.onChunkUnload is called
|
* Called when TileGenericPipe.onChunkUnload is called
|
||||||
*/
|
*/
|
||||||
public void onChunkUnload() {}
|
public void onChunkUnload() {}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,7 @@ import buildcraft.core.Utils;
|
||||||
import buildcraft.core.network.v2.IClientState;
|
import buildcraft.core.network.v2.IClientState;
|
||||||
import buildcraft.core.network.v2.ISyncedTile;
|
import buildcraft.core.network.v2.ISyncedTile;
|
||||||
import buildcraft.core.network.v2.PacketTileState;
|
import buildcraft.core.network.v2.PacketTileState;
|
||||||
|
import buildcraft.transport.Gate.GateKind;
|
||||||
import buildcraft.transport.network.PipeRenderStatePacket;
|
import buildcraft.transport.network.PipeRenderStatePacket;
|
||||||
|
|
||||||
import net.minecraft.src.Block;
|
import net.minecraft.src.Block;
|
||||||
|
@ -54,16 +55,19 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ITank
|
||||||
|
|
||||||
private class CoreState implements IClientState {
|
private class CoreState implements IClientState {
|
||||||
|
|
||||||
public int pipeId;
|
public int pipeId = -1;
|
||||||
|
public int gateKind = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeData(DataOutputStream data) throws IOException {
|
public void writeData(DataOutputStream data) throws IOException {
|
||||||
data.writeInt(pipeId);
|
data.writeInt(pipeId);
|
||||||
|
data.writeInt(gateKind);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readData(DataInputStream data) throws IOException {
|
public void readData(DataInputStream data) throws IOException {
|
||||||
pipeId = data.readInt();
|
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[] facadeBlocks = new int[Orientations.dirs().length];
|
||||||
private int[] facadeMeta = 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() {
|
public TileGenericPipe() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -101,7 +100,7 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ITank
|
||||||
nbttagcompound.setInteger("pipeId", pipe.itemID);
|
nbttagcompound.setInteger("pipeId", pipe.itemID);
|
||||||
pipe.writeToNBT(nbttagcompound);
|
pipe.writeToNBT(nbttagcompound);
|
||||||
} else
|
} else
|
||||||
nbttagcompound.setInteger("pipeId", key);
|
nbttagcompound.setInteger("pipeId", coreState.pipeId);
|
||||||
|
|
||||||
for (int i = 0; i < Orientations.dirs().length; i++){
|
for (int i = 0; i < Orientations.dirs().length; i++){
|
||||||
nbttagcompound.setInteger("facadeBlocks[" + i + "]", facadeBlocks[i]);
|
nbttagcompound.setInteger("facadeBlocks[" + i + "]", facadeBlocks[i]);
|
||||||
|
@ -114,9 +113,8 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ITank
|
||||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||||
super.readFromNBT(nbttagcompound);
|
super.readFromNBT(nbttagcompound);
|
||||||
|
|
||||||
|
coreState.pipeId = nbttagcompound.getInteger("pipeId");
|
||||||
key = nbttagcompound.getInteger("pipeId");
|
pipe = BlockGenericPipe.createPipe(coreState.pipeId);
|
||||||
pipe = BlockGenericPipe.createPipe(key);
|
|
||||||
|
|
||||||
if (pipe != null) {
|
if (pipe != null) {
|
||||||
pipe.readFromNBT(nbttagcompound);
|
pipe.readFromNBT(nbttagcompound);
|
||||||
|
@ -251,7 +249,6 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ITank
|
||||||
|
|
||||||
|
|
||||||
if (renderState.isDirty()){
|
if (renderState.isDirty()){
|
||||||
//worldObj.markBlockAsNeedsUpdate(this.xCoord, this.yCoord, this.zCoord);
|
|
||||||
worldObj.markBlockNeedsUpdate(this.xCoord, this.yCoord, this.zCoord);
|
worldObj.markBlockNeedsUpdate(this.xCoord, this.yCoord, this.zCoord);
|
||||||
renderState.clean();
|
renderState.clean();
|
||||||
}
|
}
|
||||||
|
@ -382,11 +379,13 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ITank
|
||||||
@Override
|
@Override
|
||||||
public Packet getAuxillaryInfoPacket() {
|
public Packet getAuxillaryInfoPacket() {
|
||||||
bindPipe();
|
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);
|
PacketTileState packet = new PacketTileState(this.xCoord, this.yCoord, this.zCoord);
|
||||||
|
if (pipe != null && pipe.gate != null){
|
||||||
|
coreState.gateKind = pipe.gate.kind.ordinal();
|
||||||
|
} else {
|
||||||
|
coreState.gateKind = 0;
|
||||||
|
}
|
||||||
packet.addStateForSerialization((byte) 0, coreState);
|
packet.addStateForSerialization((byte) 0, coreState);
|
||||||
packet.addStateForSerialization((byte) 1, renderState);
|
packet.addStateForSerialization((byte) 1, renderState);
|
||||||
return packet.getPacket();
|
return packet.getPacket();
|
||||||
|
@ -564,7 +563,6 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ITank
|
||||||
this.facadeBlocks[direction.ordinal()] = blockid;
|
this.facadeBlocks[direction.ordinal()] = blockid;
|
||||||
this.facadeMeta[direction.ordinal()] = meta;
|
this.facadeMeta[direction.ordinal()] = meta;
|
||||||
scheduleRenderUpdate();
|
scheduleRenderUpdate();
|
||||||
//refreshRenderState();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -580,7 +578,6 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ITank
|
||||||
this.facadeBlocks[direction.ordinal()] = 0;
|
this.facadeBlocks[direction.ordinal()] = 0;
|
||||||
this.facadeMeta[direction.ordinal()] = 0;
|
this.facadeMeta[direction.ordinal()] = 0;
|
||||||
scheduleRenderUpdate();
|
scheduleRenderUpdate();
|
||||||
//refreshRenderState();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** IPipeRenderState implementation **/
|
/** IPipeRenderState implementation **/
|
||||||
|
@ -600,7 +597,7 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ITank
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stateUpdated(byte stateId) {
|
public void afterStateUpdated(byte stateId) {
|
||||||
if (!worldObj.isRemote) return;
|
if (!worldObj.isRemote) return;
|
||||||
|
|
||||||
switch (stateId){
|
switch (stateId){
|
||||||
|
@ -608,6 +605,12 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ITank
|
||||||
if (pipe == null && coreState.pipeId != 0){
|
if (pipe == null && coreState.pipeId != 0){
|
||||||
initialize(BlockGenericPipe.createPipe(coreState.pipeId));
|
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;
|
break;
|
||||||
}
|
}
|
||||||
worldObj.markBlockAsNeedsUpdate(xCoord, yCoord, zCoord);
|
worldObj.markBlockAsNeedsUpdate(xCoord, yCoord, zCoord);
|
||||||
|
|
Loading…
Reference in a new issue