From a1ab29186b26145c88f07552f6a1ad81bdd2cc22 Mon Sep 17 00:00:00 2001 From: "Five (Xer)" Date: Tue, 16 Jun 2020 17:56:56 +0200 Subject: [PATCH] Changes 1.16-pre6 --- .../api/network/ProtocolVersion.java | 2 +- .../client/ClientPlaySessionHandler.java | 4 ++-- .../proxy/protocol/packet/JoinGame.java | 21 ++++++++++++------- .../proxy/protocol/packet/Respawn.java | 20 +++++++++++++++--- 4 files changed, 34 insertions(+), 13 deletions(-) diff --git a/api/src/main/java/com/velocitypowered/api/network/ProtocolVersion.java b/api/src/main/java/com/velocitypowered/api/network/ProtocolVersion.java index 46d515ed7..fbdb2b9b9 100644 --- a/api/src/main/java/com/velocitypowered/api/network/ProtocolVersion.java +++ b/api/src/main/java/com/velocitypowered/api/network/ProtocolVersion.java @@ -35,7 +35,7 @@ public enum ProtocolVersion { MINECRAFT_1_15(573, "1.15"), MINECRAFT_1_15_1(575, "1.15.1"), MINECRAFT_1_15_2(578, "1.15.2"), - MINECRAFT_1_16(729, "1.16"); + MINECRAFT_1_16(730, "1.16"); private final int protocol; private final String name; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java index 4f64edff7..0e6dbe729 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java @@ -339,13 +339,13 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { player.getMinecraftConnection().delayedWrite( new Respawn(tempDim, joinGame.getPartialHashedSeed(), joinGame.getDifficulty(), joinGame.getGamemode(), joinGame.getLevelType(), - false, joinGame.getDimensionInfo())); + false, joinGame.getDimensionInfo(), joinGame.getPreviousGamemode())); } player.getMinecraftConnection().delayedWrite( new Respawn(joinGame.getDimension(), joinGame.getPartialHashedSeed(), joinGame.getDifficulty(), joinGame.getGamemode(), joinGame.getLevelType(), - false, joinGame.getDimensionInfo())); + false, joinGame.getDimensionInfo(), joinGame.getPreviousGamemode())); destination.setActiveDimensionRegistry(joinGame.getDimensionRegistry()); // 1.16 } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/JoinGame.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/JoinGame.java index d000320ac..630a60de2 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/JoinGame.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/JoinGame.java @@ -24,6 +24,7 @@ public class JoinGame implements MinecraftPacket { private boolean showRespawnScreen; private DimensionRegistry dimensionRegistry; // 1.16+ private DimensionInfo dimensionInfo; // 1.16+ + private short previousGamemode; // 1.16+ public int getEntityId() { return entityId; @@ -69,10 +70,7 @@ public class JoinGame implements MinecraftPacket { this.maxPlayers = maxPlayers; } - public String getLevelType() { - if (levelType == null) { - throw new IllegalStateException("No level type specified."); - } + public @Nullable String getLevelType() { return levelType; } @@ -112,6 +110,14 @@ public class JoinGame implements MinecraftPacket { this.dimensionRegistry = dimensionRegistry; } + public short getPreviousGamemode() { + return previousGamemode; + } + + public void setPreviousGamemode(short previousGamemode) { + this.previousGamemode = previousGamemode; + } + @Override public String toString() { return "JoinGame{" @@ -126,16 +132,18 @@ public class JoinGame implements MinecraftPacket { + ", reducedDebugInfo=" + reducedDebugInfo + ", dimensionRegistry='" + dimensionRegistry.toString() + '\'' + ", dimensionInfo='" + dimensionInfo.toString() + '\'' + + ", previousGamemode=" + previousGamemode + '}'; } @Override public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { this.entityId = buf.readInt(); - this.gamemode = buf.readUnsignedByte(); + this.gamemode = buf.readByte(); String dimensionIdentifier = null; String levelName = null; if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) { + this.previousGamemode = buf.readByte(); ImmutableSet levelNames = ImmutableSet.copyOf(ProtocolUtils.readStringArray(buf)); ImmutableSet readData = DimensionRegistry.fromGameData(ProtocolUtils.readCompoundTag(buf)); this.dimensionRegistry = new DimensionRegistry(readData, levelNames); @@ -155,8 +163,6 @@ public class JoinGame implements MinecraftPacket { this.maxPlayers = buf.readUnsignedByte(); if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) < 0) { this.levelType = ProtocolUtils.readString(buf, 16); - } else { - this.levelType = "default"; // I didn't have the courage to rework this yet. } if (version.compareTo(ProtocolVersion.MINECRAFT_1_14) >= 0) { this.viewDistance = ProtocolUtils.readVarInt(buf); @@ -177,6 +183,7 @@ public class JoinGame implements MinecraftPacket { buf.writeInt(entityId); buf.writeByte(gamemode); if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) { + buf.writeByte(previousGamemode); ProtocolUtils.writeStringArray(buf, dimensionRegistry.getLevelNames().toArray( new String[dimensionRegistry.getLevelNames().size()])); ProtocolUtils.writeCompoundTag(buf, dimensionRegistry.encodeRegistry()); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Respawn.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Respawn.java index 5f883c538..d14e9f8c8 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Respawn.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Respawn.java @@ -15,13 +15,15 @@ public class Respawn implements MinecraftPacket { private short gamemode; private String levelType = ""; private boolean shouldKeepPlayerData; // 1.16+ - private DimensionInfo dimensionInfo; + private DimensionInfo dimensionInfo; // 1.16+ + private short previousGamemode; // 1.16+ public Respawn() { } public Respawn(int dimension, long partialHashedSeed, short difficulty, short gamemode, - String levelType, boolean shouldKeepPlayerData, DimensionInfo dimensionInfo) { + String levelType, boolean shouldKeepPlayerData, DimensionInfo dimensionInfo, + short previousGamemode) { this.dimension = dimension; this.partialHashedSeed = partialHashedSeed; this.difficulty = difficulty; @@ -29,6 +31,7 @@ public class Respawn implements MinecraftPacket { this.levelType = levelType; this.shouldKeepPlayerData = shouldKeepPlayerData; this.dimensionInfo = dimensionInfo; + this.previousGamemode = previousGamemode; } public int getDimension() { @@ -79,6 +82,14 @@ public class Respawn implements MinecraftPacket { this.shouldKeepPlayerData = shouldKeepPlayerData; } + public short getPreviousGamemode() { + return previousGamemode; + } + + public void setPreviousGamemode(short previousGamemode) { + this.previousGamemode = previousGamemode; + } + @Override public String toString() { return "Respawn{" @@ -89,6 +100,7 @@ public class Respawn implements MinecraftPacket { + ", levelType='" + levelType + '\'' + ", shouldKeepPlayerData=" + shouldKeepPlayerData + ", dimensionRegistryName='" + dimensionInfo.toString() + '\'' + + ", previousGamemode=" + previousGamemode + '}'; } @@ -108,8 +120,9 @@ public class Respawn implements MinecraftPacket { if (version.compareTo(ProtocolVersion.MINECRAFT_1_15) >= 0) { this.partialHashedSeed = buf.readLong(); } - this.gamemode = buf.readUnsignedByte(); + this.gamemode = buf.readByte(); if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) { + this.previousGamemode = buf.readByte(); boolean isDebug = buf.readBoolean(); boolean isFlat = buf.readBoolean(); this.dimensionInfo = new DimensionInfo(dimensionIdentifier, levelName, isFlat, isDebug); @@ -135,6 +148,7 @@ public class Respawn implements MinecraftPacket { } buf.writeByte(gamemode); if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) { + buf.writeByte(previousGamemode); buf.writeBoolean(dimensionInfo.isDebugType()); buf.writeBoolean(dimensionInfo.isFlat()); buf.writeBoolean(shouldKeepPlayerData);