Skip to content

Commit

Permalink
Merge pull request #759 from booky10/fix/joingame-1.16.1
Browse files Browse the repository at this point in the history
Fix reading/writing of JoinGame packet on 1.16/1.16.1
  • Loading branch information
retrooper committed May 8, 2024
2 parents 6869ac5 + 90968ca commit 5513c0f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,8 @@ public Dimension readDimension() {
if (this.serverVersion.isNewerThanOrEquals(ServerVersion.V_1_20_5)) {
return new Dimension(this.readVarInt());
}
if (serverVersion.isNewerThanOrEquals(ServerVersion.V_1_19)) {
if (this.serverVersion.isNewerThanOrEquals(ServerVersion.V_1_19)
|| this.serverVersion.isOlderThan(ServerVersion.V_1_16_2)) {
Dimension dimension = new Dimension(new NBTCompound());
dimension.setDimensionName(readIdentifier().toString());
return dimension;
Expand All @@ -968,9 +969,8 @@ public void writeDimension(Dimension dimension) {
this.writeVarInt(dimension.getId());
return;
}
boolean v1_19 = serverVersion.isNewerThanOrEquals(ServerVersion.V_1_19);
boolean v1_16_2 = serverVersion.isNewerThanOrEquals(ServerVersion.V_1_16_2);
if (v1_19 || !v1_16_2) {
if (this.serverVersion.isNewerThanOrEquals(ServerVersion.V_1_19)
|| this.serverVersion.isOlderThan(ServerVersion.V_1_16_2)) {
writeString(dimension.getDimensionName(), 32767);
} else {
writeNBT(dimension.getAttributes());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
import com.github.retrooper.packetevents.protocol.nbt.NBTCompound;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.protocol.player.GameMode;
import com.github.retrooper.packetevents.protocol.world.*;
import com.github.retrooper.packetevents.protocol.world.Difficulty;
import com.github.retrooper.packetevents.protocol.world.Dimension;
import com.github.retrooper.packetevents.protocol.world.DimensionType;
import com.github.retrooper.packetevents.protocol.world.WorldBlockPosition;
import com.github.retrooper.packetevents.protocol.world.WorldType;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -124,18 +128,19 @@ public void read() {
boolean v1_20_2 = serverVersion.isNewerThanOrEquals(ServerVersion.V_1_20_2);
boolean v1_19 = serverVersion.isNewerThanOrEquals(ServerVersion.V_1_19);
boolean v1_18 = serverVersion.isNewerThanOrEquals(ServerVersion.V_1_18);
boolean v1_16_2 = serverVersion.isNewerThanOrEquals(ServerVersion.V_1_16_2);
boolean v1_16 = serverVersion.isNewerThanOrEquals(ServerVersion.V_1_16);
boolean v1_15 = serverVersion.isNewerThanOrEquals(ServerVersion.V_1_15);
boolean v1_14 = serverVersion.isNewerThanOrEquals(ServerVersion.V_1_14);
if (v1_16) {
if (v1_16_2) {
hardcore = readBoolean();
if (!v1_20_2) {
gameMode = readGameMode();
}
} else {
int gameModeId = readUnsignedByte();
hardcore = (gameModeId & 0x8) == 0x8;
gameMode = GameMode.getById(gameModeId & -0x9);
gameMode = GameMode.getById(gameModeId & ~0x08);
}
if (v1_16) {
if (!v1_20_2) {
Expand Down Expand Up @@ -163,7 +168,7 @@ public void read() {
hashedSeed = readLong();
}
if (v1_16) {
maxPlayers = readVarInt();
this.maxPlayers = v1_16_2 ? this.readVarInt() : this.readUnsignedByte();
viewDistance = readVarInt();
if (v1_18) simulationDistance = readVarInt();
reducedDebugInfo = readBoolean();
Expand Down Expand Up @@ -208,10 +213,11 @@ public void write() {
boolean v1_20_2 = serverVersion.isNewerThanOrEquals(ServerVersion.V_1_20_2);
boolean v1_19 = serverVersion.isNewerThanOrEquals(ServerVersion.V_1_19);
boolean v1_18 = serverVersion.isNewerThanOrEquals(ServerVersion.V_1_18);
boolean v1_16_2 = serverVersion.isNewerThanOrEquals(ServerVersion.V_1_16_2);
boolean v1_16 = serverVersion.isNewerThanOrEquals(ServerVersion.V_1_16);
boolean v1_14 = serverVersion.isNewerThanOrEquals(ServerVersion.V_1_14);
boolean v1_15 = serverVersion.isNewerThanOrEquals(ServerVersion.V_1_15);
if (v1_16) {
if (v1_16_2) {
writeBoolean(hardcore);
if (!v1_20_2) {
writeGameMode(gameMode);
Expand Down Expand Up @@ -254,7 +260,11 @@ public void write() {
writeLong(hashedSeed);
}
if (v1_16) {
writeVarInt(maxPlayers);
if (v1_16_2) {
this.writeVarInt(this.maxPlayers);
} else {
this.writeByte(this.maxPlayers);
}
writeVarInt(viewDistance);
if (v1_18) writeVarInt(simulationDistance);
writeBoolean(reducedDebugInfo);
Expand Down

0 comments on commit 5513c0f

Please sign in to comment.