Skip to content

Commit

Permalink
1.20
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrygames committed Jun 6, 2023
1 parent e0cf2e2 commit 5ef90c4
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class JoinGame implements MinecraftPacket {
private short previousGamemode; // 1.16+
private int simulationDistance; // 1.18+
private @Nullable Pair<String, Long> lastDeathPosition; // 1.19+
private int portalCooldown; // 1.20+

public int getEntityId() {
return entityId;
Expand Down Expand Up @@ -162,6 +163,14 @@ public void setLastDeathPosition(Pair<String, Long> lastDeathPosition) {
this.lastDeathPosition = lastDeathPosition;
}

public int getPortalCooldown() {
return portalCooldown;
}

public void setPortalCooldown(int portalCooldown) {
this.portalCooldown = portalCooldown;
}

public CompoundBinaryTag getRegistry() {
return registry;
}
Expand All @@ -187,6 +196,7 @@ public String toString() {
+ ", previousGamemode=" + previousGamemode
+ ", simulationDistance=" + simulationDistance
+ ", lastDeathPosition='" + lastDeathPosition + '\''
+ ", portalCooldown=" + portalCooldown
+ '}';
}

Expand Down Expand Up @@ -279,6 +289,10 @@ private void decode116Up(ByteBuf buf, ProtocolVersion version) {
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
Expand Down Expand Up @@ -376,6 +390,10 @@ private void encode116Up(ByteBuf buf, ProtocolVersion version) {
buf.writeBoolean(false);
}
}

if (version.compareTo(ProtocolVersion.MINECRAFT_1_20) >= 0) {
ProtocolUtils.writeVarInt(buf, portalCooldown);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@ public class Respawn implements MinecraftPacket {
private short previousGamemode; // 1.16+
private CompoundBinaryTag currentDimensionData; // 1.16.2+
private @Nullable Pair<String, Long> lastDeathPosition; // 1.19+
private int portalCooldown; // 1.20+

public Respawn() {
}

public Respawn(int dimension, long partialHashedSeed, short difficulty, short gamemode,
String levelType, byte dataToKeep, DimensionInfo dimensionInfo,
short previousGamemode, CompoundBinaryTag currentDimensionData,
@Nullable Pair<String, Long> lastDeathPosition) {
@Nullable Pair<String, Long> lastDeathPosition, int portalCooldown) {
this.dimension = dimension;
this.partialHashedSeed = partialHashedSeed;
this.difficulty = difficulty;
Expand All @@ -58,13 +59,14 @@ public Respawn(int dimension, long partialHashedSeed, short difficulty, short ga
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() {
Expand Down Expand Up @@ -123,12 +125,20 @@ public void setPreviousGamemode(short previousGamemode) {
this.previousGamemode = previousGamemode;
}

public Pair<String, Long> getLastDeathPosition() {
return lastDeathPosition;
}

public void setLastDeathPosition(Pair<String, Long> lastDeathPosition) {
this.lastDeathPosition = lastDeathPosition;
}

public Pair<String, Long> getLastDeathPosition() {
return lastDeathPosition;
public int getPortalCooldown() {
return portalCooldown;
}

public void setPortalCooldown(int portalCooldown) {
this.portalCooldown = portalCooldown;
}

@Override
Expand All @@ -144,6 +154,7 @@ public String toString() {
+ ", dimensionInfo=" + dimensionInfo
+ ", previousGamemode=" + previousGamemode
+ ", dimensionData=" + currentDimensionData
+ ", portalCooldown=" + portalCooldown
+ '}';
}

Expand Down Expand Up @@ -188,6 +199,9 @@ public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersi
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
Expand Down Expand Up @@ -234,6 +248,10 @@ public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersi
buf.writeBoolean(false);
}
}

if (version.compareTo(ProtocolVersion.MINECRAFT_1_20) >= 0) {
ProtocolUtils.writeVarInt(buf, portalCooldown);
}
}

@Override
Expand Down

0 comments on commit 5ef90c4

Please sign in to comment.