From 971f6eebf935e4a0c300aeeb688c180e837f088c Mon Sep 17 00:00:00 2001 From: DoctorMacc Date: Wed, 21 Oct 2020 20:46:44 -0400 Subject: [PATCH] Accomodate for encoding bug --- .../com/github/steveice10/mc/protocol/data/MagicValues.java | 2 +- .../mc/protocol/data/game/entity/player/GameMode.java | 4 ---- .../ingame/server/world/ServerNotifyClientPacket.java | 6 ++++-- 3 files changed, 5 insertions(+), 7 deletions(-) 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 4ed1b776..a65087fb 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,7 +262,7 @@ public class MagicValues { register(CombatState.END_COMBAT, 1); register(CombatState.ENTITY_DEAD, 2); - register(GameMode.UNKNOWN, -1); + register(GameMode.UNKNOWN, 255); // https://bugs.mojang.com/browse/MC-189885 - should be -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 73fa9235..2766052c 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 @@ -1,10 +1,6 @@ package com.github.steveice10.mc.protocol.data.game.entity.player; -import com.github.steveice10.mc.protocol.data.MagicValues; import com.github.steveice10.mc.protocol.data.game.world.notify.ClientNotificationValue; -import com.github.steveice10.packetlib.io.NetOutput; - -import java.io.IOException; public enum GameMode implements ClientNotificationValue { SURVIVAL, diff --git a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/world/ServerNotifyClientPacket.java b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/world/ServerNotifyClientPacket.java index c49b92d1..90a2582e 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/world/ServerNotifyClientPacket.java +++ b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/world/ServerNotifyClientPacket.java @@ -34,7 +34,7 @@ public class ServerNotifyClientPacket implements Packet { this.notification = MagicValues.key(ClientNotification.class, in.readUnsignedByte()); float value = in.readFloat(); if(this.notification == ClientNotification.CHANGE_GAMEMODE) { - this.value = MagicValues.key(GameMode.class, (int) value); + this.value = MagicValues.key(GameMode.class, ((int) value == -1) ? 255 : (int) value); // https://bugs.mojang.com/browse/MC-189885 - since we read as a float this bug doesn't apply here } else if(this.notification == ClientNotification.DEMO_MESSAGE) { this.value = MagicValues.key(DemoMessageValue.class, (int) value); } else if(this.notification == ClientNotification.ENTER_CREDITS) { @@ -52,7 +52,9 @@ public class ServerNotifyClientPacket implements Packet { public void write(NetOutput out) throws IOException { out.writeByte(MagicValues.value(Integer.class, this.notification)); float value = 0; - if(this.value instanceof Enum) { + if (this.value instanceof GameMode && this.value == GameMode.UNKNOWN) { + value = -1; + } else if(this.value instanceof Enum) { value = MagicValues.value(Integer.class, (Enum) this.value); } else if(this.value instanceof RainStrengthValue) { value = ((RainStrengthValue) this.value).getStrength();