Add full support for the UNKNOWN gamemode

Previously we correctly handled the unknown gamemode for 'previous gamemode'; however, this functionality can extend to the main gamemode. The gamemode writing we've been doing has been replaced with the UNKNOWN enum, so we aren't dealing with a null value.
This commit is contained in:
DoctorMacc 2020-10-21 17:02:39 -04:00
parent 1b01b1ffef
commit e408dd250d
No known key found for this signature in database
GPG key ID: 6D6E7E059F186DB4
4 changed files with 7 additions and 18 deletions

View file

@ -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);

View file

@ -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));
}
}
}

View file

@ -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);

View file

@ -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);