From 5ef90c46e32b9d3fb2b80b9ea6e3a84e7350bfec Mon Sep 17 00:00:00 2001 From: Gero Date: Sat, 13 May 2023 09:59:55 +0200 Subject: [PATCH] 1.20 --- .../api/network/ProtocolVersion.java | 3 ++- .../proxy/protocol/packet/JoinGame.java | 18 +++++++++++++ .../proxy/protocol/packet/Respawn.java | 26 ++++++++++++++++--- 3 files changed, 42 insertions(+), 5 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 62d09a32d..8e77a2f8e 100644 --- a/api/src/main/java/com/velocitypowered/api/network/ProtocolVersion.java +++ b/api/src/main/java/com/velocitypowered/api/network/ProtocolVersion.java @@ -61,7 +61,8 @@ public enum ProtocolVersion { MINECRAFT_1_19(759, "1.19"), MINECRAFT_1_19_1(760, "1.19.1", "1.19.2"), MINECRAFT_1_19_3(761, "1.19.3"), - MINECRAFT_1_19_4(762, "1.19.4"); + MINECRAFT_1_19_4(762, "1.19.4"), + MINECRAFT_1_20(763, "1.20"); private static final int SNAPSHOT_BIT = 30; 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 90320f948..cfbecce31 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 @@ -49,6 +49,7 @@ public class JoinGame implements MinecraftPacket { private short previousGamemode; // 1.16+ private int simulationDistance; // 1.18+ private @Nullable Pair lastDeathPosition; // 1.19+ + private int portalCooldown; // 1.20+ public int getEntityId() { return entityId; @@ -162,6 +163,14 @@ public class JoinGame implements MinecraftPacket { this.lastDeathPosition = lastDeathPosition; } + public int getPortalCooldown() { + return portalCooldown; + } + + public void setPortalCooldown(int portalCooldown) { + this.portalCooldown = portalCooldown; + } + public CompoundBinaryTag getRegistry() { return registry; } @@ -187,6 +196,7 @@ public class JoinGame implements MinecraftPacket { + ", previousGamemode=" + previousGamemode + ", simulationDistance=" + simulationDistance + ", lastDeathPosition='" + lastDeathPosition + '\'' + + ", portalCooldown=" + portalCooldown + '}'; } @@ -279,6 +289,10 @@ public class JoinGame implements MinecraftPacket { if (version.compareTo(ProtocolVersion.MINECRAFT_1_19) >= 0 && buf.readBoolean()) { this.lastDeathPosition = Pair.of(ProtocolUtils.readString(buf), buf.readLong()); } + + if (version.compareTo(ProtocolVersion.MINECRAFT_1_20) >= 0) { + this.portalCooldown = ProtocolUtils.readVarInt(buf); + } } @Override @@ -376,6 +390,10 @@ public class JoinGame implements MinecraftPacket { buf.writeBoolean(false); } } + + if (version.compareTo(ProtocolVersion.MINECRAFT_1_20) >= 0) { + ProtocolUtils.writeVarInt(buf, portalCooldown); + } } @Override 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 11d543c89..712024f63 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 @@ -40,6 +40,7 @@ public class Respawn implements MinecraftPacket { private short previousGamemode; // 1.16+ private CompoundBinaryTag currentDimensionData; // 1.16.2+ private @Nullable Pair lastDeathPosition; // 1.19+ + private int portalCooldown; // 1.20+ public Respawn() { } @@ -47,7 +48,7 @@ public class Respawn implements MinecraftPacket { public Respawn(int dimension, long partialHashedSeed, short difficulty, short gamemode, String levelType, byte dataToKeep, DimensionInfo dimensionInfo, short previousGamemode, CompoundBinaryTag currentDimensionData, - @Nullable Pair lastDeathPosition) { + @Nullable Pair lastDeathPosition, int portalCooldown) { this.dimension = dimension; this.partialHashedSeed = partialHashedSeed; this.difficulty = difficulty; @@ -58,13 +59,14 @@ public class Respawn implements MinecraftPacket { this.previousGamemode = previousGamemode; this.currentDimensionData = currentDimensionData; this.lastDeathPosition = lastDeathPosition; + this.portalCooldown = portalCooldown; } public static Respawn fromJoinGame(JoinGame joinGame) { return new Respawn(joinGame.getDimension(), joinGame.getPartialHashedSeed(), joinGame.getDifficulty(), joinGame.getGamemode(), joinGame.getLevelType(), (byte) 0, joinGame.getDimensionInfo(), joinGame.getPreviousGamemode(), - joinGame.getCurrentDimensionData(), joinGame.getLastDeathPosition()); + joinGame.getCurrentDimensionData(), joinGame.getLastDeathPosition(), joinGame.getPortalCooldown()); } public int getDimension() { @@ -123,12 +125,20 @@ public class Respawn implements MinecraftPacket { this.previousGamemode = previousGamemode; } + public Pair getLastDeathPosition() { + return lastDeathPosition; + } + public void setLastDeathPosition(Pair lastDeathPosition) { this.lastDeathPosition = lastDeathPosition; } - public Pair getLastDeathPosition() { - return lastDeathPosition; + public int getPortalCooldown() { + return portalCooldown; + } + + public void setPortalCooldown(int portalCooldown) { + this.portalCooldown = portalCooldown; } @Override @@ -144,6 +154,7 @@ public class Respawn implements MinecraftPacket { + ", dimensionInfo=" + dimensionInfo + ", previousGamemode=" + previousGamemode + ", dimensionData=" + currentDimensionData + + ", portalCooldown=" + portalCooldown + '}'; } @@ -188,6 +199,9 @@ public class Respawn implements MinecraftPacket { if (version.compareTo(ProtocolVersion.MINECRAFT_1_19) >= 0 && buf.readBoolean()) { this.lastDeathPosition = Pair.of(ProtocolUtils.readString(buf), buf.readLong()); } + if (version.compareTo(ProtocolVersion.MINECRAFT_1_20) >= 0) { + this.portalCooldown = ProtocolUtils.readVarInt(buf); + } } @Override @@ -234,6 +248,10 @@ public class Respawn implements MinecraftPacket { buf.writeBoolean(false); } } + + if (version.compareTo(ProtocolVersion.MINECRAFT_1_20) >= 0) { + ProtocolUtils.writeVarInt(buf, portalCooldown); + } } @Override