Skip to content

Commit

Permalink
Refactor spawn state to an enum
Browse files Browse the repository at this point in the history
  • Loading branch information
SupremeMortal committed Nov 25, 2019
1 parent 41819ea commit d7591f7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@
@EqualsAndHashCode(callSuper = true)
public class RespawnPacket extends BedrockPacket {
private Vector3f position;
private int spawnState; // 0 server searching, 1 server ready, 3 client ready (server bound)
private State spawnState;
private long runtimeEntityId; // Only used server bound and pretty pointless

@Override
public final boolean handle(BedrockPacketHandler handler) {
return handler.handle(this);
}

public enum State {
SERVER_SEARCHING,
SERVER_READY,
CLIENT_READY
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@
public class RespawnSerializer_v388 implements PacketSerializer<RespawnPacket> {
public static final RespawnSerializer_v388 INSTANCE = new RespawnSerializer_v388();

private static final RespawnPacket.State[] VALUES = RespawnPacket.State.values();

@Override
public void serialize(ByteBuf buffer, RespawnPacket packet) {
BedrockUtils.writeVector3f(buffer, packet.getPosition());
buffer.writeByte(packet.getSpawnState());
buffer.writeByte(packet.getSpawnState().ordinal());
VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId());
}

@Override
public void deserialize(ByteBuf buffer, RespawnPacket packet) {
packet.setPosition(BedrockUtils.readVector3f(buffer));
packet.setSpawnState(buffer.readUnsignedByte());
packet.setSpawnState(VALUES[buffer.readUnsignedByte()]);
packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer));
}
}

0 comments on commit d7591f7

Please sign in to comment.