Skip to content

Commit

Permalink
fix: Respawn packet codec for 1.20.2+ (#1156)
Browse files Browse the repository at this point in the history
  • Loading branch information
ishland authored Dec 11, 2023
1 parent b270206 commit c8ca28c
Showing 1 changed file with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,10 @@ public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersi
boolean isDebug = buf.readBoolean();
boolean isFlat = buf.readBoolean();
this.dimensionInfo = new DimensionInfo(dimensionIdentifier, levelName, isFlat, isDebug);
if (version.compareTo(ProtocolVersion.MINECRAFT_1_19_3) >= 0) {
if (version.compareTo(ProtocolVersion.MINECRAFT_1_19_3) < 0) {
this.dataToKeep = (byte) (buf.readBoolean() ? 1 : 0);
} else if (version.compareTo(ProtocolVersion.MINECRAFT_1_20_2) < 0) {
this.dataToKeep = buf.readByte();
} else if (buf.readBoolean()) {
this.dataToKeep = 1;
} else {
this.dataToKeep = 0;
}
} else {
this.levelType = ProtocolUtils.readString(buf, 16);
Expand All @@ -202,6 +200,9 @@ public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersi
if (version.compareTo(ProtocolVersion.MINECRAFT_1_20) >= 0) {
this.portalCooldown = ProtocolUtils.readVarInt(buf);
}
if (version.compareTo(ProtocolVersion.MINECRAFT_1_20_2) >= 0) {
this.dataToKeep = buf.readByte();
}
}

@Override
Expand Down Expand Up @@ -229,10 +230,10 @@ public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersi
buf.writeByte(previousGamemode);
buf.writeBoolean(dimensionInfo.isDebugType());
buf.writeBoolean(dimensionInfo.isFlat());
if (version.compareTo(ProtocolVersion.MINECRAFT_1_19_3) >= 0) {
buf.writeByte(dataToKeep);
} else {
if (version.compareTo(ProtocolVersion.MINECRAFT_1_19_3) < 0) {
buf.writeBoolean(dataToKeep != 0);
} else if (version.compareTo(ProtocolVersion.MINECRAFT_1_20_2) < 0) {
buf.writeByte(dataToKeep);
}
} else {
ProtocolUtils.writeString(buf, levelType);
Expand All @@ -252,6 +253,10 @@ public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersi
if (version.compareTo(ProtocolVersion.MINECRAFT_1_20) >= 0) {
ProtocolUtils.writeVarInt(buf, portalCooldown);
}

if (version.compareTo(ProtocolVersion.MINECRAFT_1_20_2) >= 0) {
buf.writeByte(dataToKeep);
}
}

@Override
Expand Down

0 comments on commit c8ca28c

Please sign in to comment.