mirror of
https://github.com/Nan1t/NanoLimbo.git
synced 2026-02-11 03:16:14 +01:00
Rewrite JoinGame packet for supported versions
This commit is contained in:
@@ -4,6 +4,7 @@ import net.kyori.adventure.nbt.CompoundBinaryTag;
|
||||
import ru.nanit.limbo.protocol.ByteMessage;
|
||||
import ru.nanit.limbo.protocol.PacketOut;
|
||||
import ru.nanit.limbo.protocol.registry.Version;
|
||||
import ru.nanit.limbo.world.Dimension;
|
||||
|
||||
public class PacketJoinGame implements PacketOut {
|
||||
|
||||
@@ -13,7 +14,7 @@ public class PacketJoinGame implements PacketOut {
|
||||
private int previousGameMode = -1;
|
||||
private String[] worldNames;
|
||||
private CompoundBinaryTag dimensionCodec;
|
||||
private CompoundBinaryTag dimension;
|
||||
private Dimension dimension;
|
||||
private String worldName;
|
||||
private long hashedSeed;
|
||||
private int maxPlayers;
|
||||
@@ -47,7 +48,7 @@ public class PacketJoinGame implements PacketOut {
|
||||
this.dimensionCodec = dimensionCodec;
|
||||
}
|
||||
|
||||
public void setDimension(CompoundBinaryTag dimension) {
|
||||
public void setDimension(Dimension dimension) {
|
||||
this.dimension = dimension;
|
||||
}
|
||||
|
||||
@@ -86,20 +87,69 @@ public class PacketJoinGame implements PacketOut {
|
||||
@Override
|
||||
public void encode(ByteMessage msg, Version version) {
|
||||
msg.writeInt(entityId);
|
||||
msg.writeBoolean(isHardcore);
|
||||
msg.writeByte(gameMode);
|
||||
msg.writeByte(previousGameMode);
|
||||
msg.writeStringsArray(worldNames);
|
||||
msg.writeCompoundTag(dimensionCodec);
|
||||
msg.writeCompoundTag(dimension);
|
||||
msg.writeString(worldName);
|
||||
msg.writeLong(hashedSeed);
|
||||
msg.writeVarInt(maxPlayers);
|
||||
msg.writeVarInt(viewDistance);
|
||||
msg.writeBoolean(reducedDebugInfo);
|
||||
msg.writeBoolean(enableRespawnScreen);
|
||||
msg.writeBoolean(isDebug);
|
||||
msg.writeBoolean(isFlat);
|
||||
|
||||
if (version.fromTo(Version.V1_8, Version.V1_13_2)) {
|
||||
msg.writeByte(gameMode);
|
||||
msg.writeByte(dimension.getId());
|
||||
msg.writeByte(0); // Difficulty
|
||||
msg.writeByte(maxPlayers);
|
||||
msg.writeString("flat"); // Level type
|
||||
msg.writeBoolean(reducedDebugInfo);
|
||||
}
|
||||
|
||||
if (version.fromTo(Version.V1_14, Version.V1_14_4)) {
|
||||
msg.writeByte(gameMode);
|
||||
msg.writeByte(dimension.getId());
|
||||
msg.writeByte(maxPlayers);
|
||||
msg.writeString("flat"); // Level type
|
||||
msg.writeVarInt(viewDistance);
|
||||
msg.writeBoolean(reducedDebugInfo);
|
||||
}
|
||||
|
||||
if (version.fromTo(Version.V1_15, Version.V1_15_2)) {
|
||||
msg.writeByte(gameMode);
|
||||
msg.writeByte(dimension.getId());
|
||||
msg.writeLong(hashedSeed);
|
||||
msg.writeByte(maxPlayers);
|
||||
msg.writeString("flat"); // Level type
|
||||
msg.writeVarInt(viewDistance);
|
||||
msg.writeBoolean(reducedDebugInfo);
|
||||
msg.writeBoolean(enableRespawnScreen);
|
||||
}
|
||||
|
||||
if (version.fromTo(Version.V1_16, Version.V1_16_1)) {
|
||||
msg.writeBoolean(isHardcore);
|
||||
msg.writeByte(gameMode);
|
||||
msg.writeByte(previousGameMode);
|
||||
msg.writeStringsArray(worldNames);
|
||||
msg.writeCompoundTag(dimensionCodec);
|
||||
msg.writeInt(dimension.getId());
|
||||
msg.writeString(worldName);
|
||||
msg.writeLong(hashedSeed);
|
||||
msg.writeByte(maxPlayers);
|
||||
msg.writeVarInt(viewDistance);
|
||||
msg.writeBoolean(reducedDebugInfo);
|
||||
msg.writeBoolean(enableRespawnScreen);
|
||||
msg.writeBoolean(isDebug);
|
||||
msg.writeBoolean(isFlat);
|
||||
}
|
||||
|
||||
if (version.fromTo(Version.V1_16_2, Version.V1_17_1)) {
|
||||
msg.writeBoolean(isHardcore);
|
||||
msg.writeByte(gameMode);
|
||||
msg.writeByte(previousGameMode);
|
||||
msg.writeStringsArray(worldNames);
|
||||
msg.writeCompoundTag(dimensionCodec);
|
||||
msg.writeCompoundTag(dimension.getData());
|
||||
msg.writeString(worldName);
|
||||
msg.writeLong(hashedSeed);
|
||||
msg.writeVarInt(maxPlayers);
|
||||
msg.writeVarInt(viewDistance);
|
||||
msg.writeBoolean(reducedDebugInfo);
|
||||
msg.writeBoolean(enableRespawnScreen);
|
||||
msg.writeBoolean(isDebug);
|
||||
msg.writeBoolean(isFlat);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ public enum Version {
|
||||
V1_9_2(109),
|
||||
V1_9_4(110),
|
||||
V1_10(210),
|
||||
// 1.10-1.10.2 has same protocol numbers
|
||||
V1_11(315),
|
||||
V1_11_1(316),
|
||||
// 1.11.2 has same protocol number
|
||||
@@ -82,6 +83,14 @@ public enum Version {
|
||||
return this.protocolNumber <= another.protocolNumber;
|
||||
}
|
||||
|
||||
public boolean between(Version min, Version max) {
|
||||
return this.protocolNumber > min.protocolNumber && this.protocolNumber < max.protocolNumber;
|
||||
}
|
||||
|
||||
public boolean fromTo(Version min, Version max) {
|
||||
return this.protocolNumber >= min.protocolNumber && this.protocolNumber <= max.protocolNumber;
|
||||
}
|
||||
|
||||
public static Version getMin() {
|
||||
return V1_8;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user