feat: tring to figure out 1.20.5-6/1.21

This commit is contained in:
ineanto 2024-06-14 23:38:21 +02:00
parent 653c229b85
commit 278c801de1
Signed by: ineanto
GPG key ID: E511F9CAA2F9CE84

View file

@ -22,24 +22,23 @@ import org.bukkit.World;
public class WrapperPlayServerRespawn extends AbstractPacket { public class WrapperPlayServerRespawn extends AbstractPacket {
public static final PacketType TYPE = PacketType.Play.Server.RESPAWN; public static final PacketType TYPE = PacketType.Play.Server.RESPAWN;
private InternalStructure commonPlayerSpawnInfoStructure; private final InternalStructure commonPlayerSpawnInfoStructure;
public WrapperPlayServerRespawn() { public WrapperPlayServerRespawn() {
super(new PacketContainer(TYPE), TYPE); super(new PacketContainer(TYPE), TYPE);
handle.getModifier().writeDefaults(); handle.getModifier().writeDefaults();
if (MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) { commonPlayerSpawnInfoStructure = handle.getStructures().readSafely(0);
commonPlayerSpawnInfoStructure = handle.getStructures().read(0);
}
} }
public void setDimension(World value) { public void setDimension(World value) {
if (MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) { if (commonPlayerSpawnInfoStructure == null) {
// 1.20.2 to 1.20.4
writeDimensionToStructure(value, commonPlayerSpawnInfoStructure.getStructures(), commonPlayerSpawnInfoStructure.getWorldKeys());
} else if (MinecraftVersion.WILD_UPDATE.atOrAbove()) {
// 1.19 to 1.20.1, props to lukalt for helping me figure this out. // 1.19 to 1.20.1, props to lukalt for helping me figure this out.
writeDimensionToStructure(value, handle.getStructures(), handle.getWorldKeys()); writeDimensionToStructure(value, handle.getStructures(), handle.getWorldKeys());
return;
} }
// 1.20.2 to 1.21
writeDimensionToStructure(value, commonPlayerSpawnInfoStructure.getStructures(), commonPlayerSpawnInfoStructure.getWorldKeys());
} }
public void setGameMode(GameMode value) { public void setGameMode(GameMode value) {
@ -74,10 +73,15 @@ public class WrapperPlayServerRespawn extends AbstractPacket {
} }
private void writeDimensionToStructure(World value, StructureModifier<InternalStructure> structures, StructureModifier<World> worldKeys) { private void writeDimensionToStructure(World value, StructureModifier<InternalStructure> structures, StructureModifier<World> worldKeys) {
final InternalStructure dimensionType = structures.read(0); final InternalStructure dimensionType = structures.readSafely(0);
if (dimensionType != null) {
// 1.20.2 to 1.20.5
dimensionType.getMinecraftKeys().writeSafely(0, new MinecraftKey("minecraft", "dimension_type")); dimensionType.getMinecraftKeys().writeSafely(0, new MinecraftKey("minecraft", "dimension_type"));
dimensionType.getMinecraftKeys().writeSafely(1, new MinecraftKey("minecraft", "overworld")); dimensionType.getMinecraftKeys().writeSafely(1, new MinecraftKey("minecraft", "overworld"));
structures.writeSafely(0, dimensionType); structures.writeSafely(0, dimensionType);
}
worldKeys.writeSafely(0, value); worldKeys.writeSafely(0, value);
} }
} }