dmulloy2 / ProtocolLib

Provides read and write access to the Minecraft protocol with Bukkit.
GNU General Public License v2.0
1.03k stars 260 forks source link

[1.20.6] RESPAWN packet error #3108

Open Kowaman opened 3 months ago

Kowaman commented 3 months ago

Describe the bug Cannot create RESPAWN packet, errors as follows using 1.18.2 method:

PacketContainer respawn = new PacketContainer(PacketType.Play.Server.RESPAWN);
respawn.getDimensionTypes().write(0, p.getWorld()); // this line errors
respawn.getWorldKeys().write(0, p.getWorld());
respawn.getLongs().write(0, p.getWorld().getSeed());

respawn.getGameModes().write(0, EnumWrappers.NativeGameMode.fromBukkit(p.getGameMode())); // gamemode
respawn.getGameModes().write(1, EnumWrappers.NativeGameMode.fromBukkit(p.getGameMode())); // previous gamemode

respawn.getBooleans().write(0, false); // is debug
respawn.getBooleans().write(1, false); // is flat
respawn.getBooleans().write(2, false); // copy metadata
Caused by: com.comphenix.protocol.reflect.FieldAccessException: Field index 0 is out of bounds for length 0
    at ProtocolLib.jar/com.comphenix.protocol.reflect.FieldAccessException.fromFormat(FieldAccessException.java:49) ~[ProtocolLib.jar:?]
    at ProtocolLib.jar/com.comphenix.protocol.reflect.StructureModifier.write(StructureModifier.java:318) ~[ProtocolLib.jar:?]

@ThomasMo54 documented this error in #2604, noting that the data was moved to an internal structure, and provided a fix for 1.20.2, though it does not seem to work in 1.20.6:

PacketContainer respawn = new PacketContainer(PacketType.Play.Server.RESPAWN);
InternalStructure structure = respawn .getStructures().read(0); // this line errors
// set other fields
Caused by: java.lang.NullPointerException: Cannot invoke "Object.getClass()" because "generic" is null
    at ProtocolLib.jar/com.comphenix.protocol.events.InternalStructure$1.getSpecific(InternalStructure.java:23) ~[ProtocolLib.jar:?]
    at ProtocolLib.jar/com.comphenix.protocol.events.InternalStructure$1.getSpecific(InternalStructure.java:15) ~[ProtocolLib.jar:?]
    at ProtocolLib.jar/com.comphenix.protocol.reflect.StructureModifier.readInternal(StructureModifier.java:303) ~[ProtocolLib.jar:?]
    at ProtocolLib.jar/com.comphenix.protocol.reflect.StructureModifier.read(StructureModifier.java:253) ~[ProtocolLib.jar:?]

ProtocolLib Version: ProtocolLib v5.3.0-SNAPSHOT-723

Ingrim4 commented 3 months ago

The field you're trying to set doesn't exist as it has a different type: net.minecraft.core.Holder<net.minecraft.world.level.dimension.DimensionType>. This type requires retrieval from some sort of registry due to the Holder.

The behavior you're experiencing for the fix is intended, as many fields can no longer be initialized with non-null values as of version 1.20.5. This is why you encounter a NullPointerException—the field currently holds a null value.