+ *
+ * Packet changes history (not accurate) + *
+ * In 1.20.2, all the fields were replaced with a + * single "CommonPlayerSpawnInfo" record object. + *
+ * The dimension field was changed numerous times: + * - 1.8 through 1.17 (?) required an integer, + * - 1.18 need an instance of a Holder of a ResourceKey, + * - 1.19 and after dropped this requirement. + * N.b.: this field is a nightmare please mojang stop refactoring + * your code to change things that were working perfectly fine before + *
+ * The Seed field was added in 1.15. + * The Difficulty field was removed in 1.14. */ public class WrapperPlayServerRespawn extends AbstractPacket { public static final PacketType TYPE = PacketType.Play.Server.RESPAWN; + private InternalStructure commonPlayerSpawnInfoStructure; + public WrapperPlayServerRespawn() { super(new PacketContainer(TYPE), TYPE); handle.getModifier().writeDefaults(); + if (MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) { + commonPlayerSpawnInfoStructure = handle.getStructures().read(0); + } } - //............. - // Dimension/World Field - // The dimension field has changed numerous times: - // - 1.8 through 1.17 (?) need an integer, - // - 1.18 need a Holder of a World ResourceKey, - // - 1.19 and beyond don't require a Holder. - // - // n.b.: this field is a nightmare please mojang stop refactoring - // your code to change things that were working perfectly fine before - //............. - public void setDimension(World value) { - if (MinecraftVersion.WILD_UPDATE.atOrAbove()) { + if (MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) { + // 1.20.2 + final InternalStructure dimensionType = commonPlayerSpawnInfoStructure.getStructures().read(0); + dimensionType.getMinecraftKeys().write(0, new MinecraftKey("minecraft", "dimension_type")); + dimensionType.getMinecraftKeys().write(1, new MinecraftKey("minecraft", "overworld")); + commonPlayerSpawnInfoStructure.getStructures().write(0, dimensionType); + commonPlayerSpawnInfoStructure.getWorldKeys().write(0, value); + } else if (MinecraftVersion.WILD_UPDATE.atOrAbove()) { // 1.19 to 1.20.1 // Thank you lukalt! final InternalStructure dimensionType = handle.getStructures().read(0); @@ -59,50 +76,38 @@ public class WrapperPlayServerRespawn extends AbstractPacket { } } - //............. - // GameMode Field - //............. - public void setGameMode(GameMode value) { + if (MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) { + commonPlayerSpawnInfoStructure.getGameModes().write(0, EnumWrappers.NativeGameMode.fromBukkit(value)); + return; + } + handle.getGameModes().write(0, EnumWrappers.NativeGameMode.fromBukkit(value)); } - //............. - // Previous GameMode Field - //............. - public void setPreviousGameMode(GameMode value) { + if (MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) { + commonPlayerSpawnInfoStructure.getGameModes().write(1, EnumWrappers.NativeGameMode.fromBukkit(value)); + return; + } handle.getGameModes().write(1, EnumWrappers.NativeGameMode.fromBukkit(value)); } - //............. - // Copy Metadata Field - //............. - public void setCopyMetadata(boolean value) { - if(MinecraftVersion.FEATURE_PREVIEW_UPDATE.atOrAbove()) { + if (MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) return; + if (MinecraftVersion.FEATURE_PREVIEW_UPDATE.atOrAbove()) { handle.getBytes().write(0, ((byte) (value ? 0x01 : 0x00))); } else { handle.getBooleans().write(0, value); } } - //............. - // Seed Field - // Added in 1.15. - //............. - public void setSeed(long value) { - if (MinecraftVersion.BEE_UPDATE.atOrAbove()) { + if (MinecraftVersion.BEE_UPDATE.atOrAbove() && !MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) { handle.getLongs().write(0, Hashing.sha256().hashLong(value).asLong()); } } - //............. - // Difficulty Field - // Removed in 1.14. - //............. - public void setDifficulty(Difficulty difficulty) { if (difficulty != null && !MinecraftVersion.VILLAGE_UPDATE.atOrAbove()) { handle.getDifficulties().write(0, EnumWrappers.Difficulty.valueOf(difficulty.name())); diff --git a/src/main/java/xyz/atnrch/nicko/wrapper/WrapperPlayServerNamedEntitySpawn.java b/src/main/java/xyz/atnrch/nicko/wrapper/WrapperPlayServerSpawnEntity.java similarity index 96% rename from src/main/java/xyz/atnrch/nicko/wrapper/WrapperPlayServerNamedEntitySpawn.java rename to src/main/java/xyz/atnrch/nicko/wrapper/WrapperPlayServerSpawnEntity.java index fb82152..8a37c41 100644 --- a/src/main/java/xyz/atnrch/nicko/wrapper/WrapperPlayServerNamedEntitySpawn.java +++ b/src/main/java/xyz/atnrch/nicko/wrapper/WrapperPlayServerSpawnEntity.java @@ -12,16 +12,16 @@ import java.util.UUID; /** * This packet is sent by the server when a player comes into visible range, not when a player joins. */ -public class WrapperPlayServerNamedEntitySpawn extends AbstractPacket { +public class WrapperPlayServerSpawnEntity extends AbstractPacket { /** * The packet type that is wrapped by this wrapper. */ - public static final PacketType TYPE = PacketType.Play.Server.NAMED_ENTITY_SPAWN; + public static final PacketType TYPE = PacketType.Play.Server.SPAWN_ENTITY; /** * Constructors a new wrapper for the specified packet */ - public WrapperPlayServerNamedEntitySpawn() { + public WrapperPlayServerSpawnEntity() { super(new PacketContainer(TYPE), TYPE); handle.getModifier().writeDefaults(); }