Accomodate for encoding bug

This commit is contained in:
DoctorMacc 2020-10-21 20:46:44 -04:00
parent e408dd250d
commit 971f6eebf9
No known key found for this signature in database
GPG key ID: 6D6E7E059F186DB4
3 changed files with 5 additions and 7 deletions

View file

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

View file

@ -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,

View file

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