Pipe wires are synched on first connect of client. Wire signal synching is still missing.
This commit is contained in:
parent
8d75f63255
commit
6f8d594197
3 changed files with 50 additions and 13 deletions
|
@ -7,24 +7,34 @@ public class PacketPipeDescription extends PacketUpdate {
|
|||
public PacketPipeDescription() {}
|
||||
|
||||
public PacketPipeDescription(int posX, int posY, int posZ, Pipe pipe) {
|
||||
this(posX, posY, posZ, pipe.itemID);
|
||||
|
||||
if(pipe.gate != null)
|
||||
this.payload.append(pipe.gate.toPayload());
|
||||
|
||||
}
|
||||
|
||||
public PacketPipeDescription(int posX, int posY, int posZ, int pipeId) {
|
||||
super(PacketIds.PIPE_DESCRIPTION);
|
||||
|
||||
PacketPayload payload = new PacketPayload(1, 0, 0);
|
||||
PacketPayload payload = new PacketPayload(5, 0, 0);
|
||||
this.posX = posX;
|
||||
this.posY = posY;
|
||||
this.posZ = posZ;
|
||||
|
||||
payload.intPayload[0] = pipeId;
|
||||
/// 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());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -71,6 +71,7 @@ public class Pipe extends PersistentTile implements IPipe, IDropControlInventory
|
|||
TriggerParameter [] triggerParameters = new TriggerParameter [8];
|
||||
Action[] activatedActions = new Action [8];
|
||||
|
||||
@TileNetworkData (intKind = TileNetworkData.UNSIGNED_BYTE)
|
||||
public boolean broadcastSignal[] = new boolean[] {false, false, false, false};
|
||||
public boolean broadcastRedstone = false;
|
||||
|
||||
|
@ -392,10 +393,31 @@ public class Pipe extends PersistentTile implements IPipe, IDropControlInventory
|
|||
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);
|
||||
|
|
|
@ -362,6 +362,9 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor,
|
|||
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) {
|
||||
|
@ -372,9 +375,11 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor,
|
|||
if (pipe != null)
|
||||
pipe.initialize();
|
||||
|
||||
// Check for wire information
|
||||
pipe.handleWirePayload(packet.payload, new IndexInPayload(1, 0, 0));
|
||||
// Check for gate information
|
||||
if(packet.payload.intPayload.length > 1)
|
||||
pipe.handleGatePayload(packet.payload, new IndexInPayload(1, 0, 0));
|
||||
if(packet.payload.intPayload.length > 5)
|
||||
pipe.handleGatePayload(packet.payload, new IndexInPayload(5, 0, 0));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -400,7 +405,7 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor,
|
|||
if(pipe != null)
|
||||
packet = new PacketPipeDescription(xCoord, yCoord, zCoord, pipe);
|
||||
else
|
||||
packet = new PacketPipeDescription(xCoord, yCoord, zCoord, 0);
|
||||
packet = new PacketPipeDescription(xCoord, yCoord, zCoord, null);
|
||||
|
||||
return packet.getPacket();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue