diff --git a/src/main/java/com/github/steveice10/mc/protocol/data/MagicValues.java b/src/main/java/com/github/steveice10/mc/protocol/data/MagicValues.java index 95aac643..4ed1b776 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/data/MagicValues.java +++ b/src/main/java/com/github/steveice10/mc/protocol/data/MagicValues.java @@ -262,6 +262,7 @@ public class MagicValues { register(CombatState.END_COMBAT, 1); register(CombatState.ENTITY_DEAD, 2); + register(GameMode.UNKNOWN, -1); register(GameMode.SURVIVAL, 0); register(GameMode.CREATIVE, 1); register(GameMode.ADVENTURE, 2); diff --git a/src/main/java/com/github/steveice10/mc/protocol/data/game/entity/player/GameMode.java b/src/main/java/com/github/steveice10/mc/protocol/data/game/entity/player/GameMode.java index 52c0700e..73fa9235 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/data/game/entity/player/GameMode.java +++ b/src/main/java/com/github/steveice10/mc/protocol/data/game/entity/player/GameMode.java @@ -10,19 +10,7 @@ public enum GameMode implements ClientNotificationValue { SURVIVAL, CREATIVE, ADVENTURE, - SPECTATOR; + SPECTATOR, + UNKNOWN - public static GameMode readPreviousGameMode(int gamemode) { - if (gamemode == 255) // https://bugs.mojang.com/browse/MC-189885 - return null; // Undefined gamemode; we're treating it as null - return MagicValues.key(GameMode.class, gamemode); - } - - public static void writePreviousGameMode(NetOutput out, GameMode gamemode) throws IOException { - if (gamemode == null) { - out.writeByte(255); - } else { - out.writeByte(MagicValues.value(Integer.class, gamemode)); - } - } } diff --git a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerJoinGamePacket.java b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerJoinGamePacket.java index ae3891ef..27fbfc45 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerJoinGamePacket.java +++ b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerJoinGamePacket.java @@ -47,7 +47,7 @@ public class ServerJoinGamePacket implements Packet { this.hardcore = in.readBoolean(); int gameMode = in.readUnsignedByte(); this.gameMode = MagicValues.key(GameMode.class, gameMode & GAMEMODE_MASK); - this.previousGamemode = GameMode.readPreviousGameMode(in.readUnsignedByte()); + this.previousGamemode = MagicValues.key(GameMode.class, in.readUnsignedByte()); this.worldCount = in.readVarInt(); this.worldNames = new String[this.worldCount]; for (int i = 0; i < this.worldCount; i++) { @@ -73,7 +73,7 @@ public class ServerJoinGamePacket implements Packet { int gameMode = MagicValues.value(Integer.class, this.gameMode) & GAMEMODE_MASK; out.writeByte(gameMode); - GameMode.writePreviousGameMode(out, this.previousGamemode); + out.writeByte(MagicValues.value(Integer.class, this.previousGamemode)); out.writeVarInt(this.worldCount); for (String worldName : this.worldNames) { out.writeString(worldName); diff --git a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerRespawnPacket.java b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerRespawnPacket.java index ad9cda79..3b9f847f 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerRespawnPacket.java +++ b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerRespawnPacket.java @@ -36,7 +36,7 @@ public class ServerRespawnPacket implements Packet { this.worldName = in.readString(); this.hashedSeed = in.readLong(); this.gamemode = MagicValues.key(GameMode.class, in.readUnsignedByte()); - this.previousGamemode = GameMode.readPreviousGameMode(in.readUnsignedByte()); + this.previousGamemode = MagicValues.key(GameMode.class, in.readUnsignedByte()); this.debug = in.readBoolean(); this.flat = in.readBoolean(); this.copyMetadata = in.readBoolean(); @@ -48,7 +48,7 @@ public class ServerRespawnPacket implements Packet { out.writeString(this.worldName); out.writeLong(this.hashedSeed); out.writeByte(MagicValues.value(Integer.class, this.gamemode)); - GameMode.writePreviousGameMode(out, this.previousGamemode); + out.writeByte(MagicValues.value(Integer.class, this.previousGamemode)); out.writeBoolean(this.debug); out.writeBoolean(this.flat); out.writeBoolean(this.copyMetadata);