#[1.18.2, ProtocolLib] How to properly create a RESPAWN packet?

1 messages · Page 1 of 1 (latest)

blazing quiver
#

Hi, I'm in the process of updating some 1.17 code, and I've hit a problem trying to update some ProtocolLib code. I'm trying to properly create a RESPAWN packet, and it seems like I don't understand the new format.

Here are the required packet components inside ClientboundRespawnPacket:

DimensionType[0] - Dimension info
ResourceLocation[0] - Dimension name
Long[0] - World seed
Byte[0] - Player gamemode
Byte[1] - Previous gamemode
Boolean[0] - Is world debug?
Boolean[1] - Is world flat?
Boolean[2] - Keep all player data?

I seem to be failing at the first step, writing a DimensionType. This line 4 fails:

var respawn = new PacketContainer(RESPAWN);
var world = player.getWorld();

respawn.getDimensionTypes().write(0, world);

Error:

FieldAccessException: No field with type net.minecraft.world.level.dimension.DimensionManager exists in class PacketPlayOutRespawn.
forest steeple
forest steeple
blazing quiver
#

I'm currently testing this out instead, to see if it works:

respawn.getWorldKeys().write(0, world);

Saw a handful of Github issues about it on the plib repo

#

Will be back in a few with results

forest steeple
#

Okay, good luck

blazing quiver
#

Alright, looks like that works for dimension data... now for the ResourceLocation!

#

Currently, I'm doing this:

#
var resourceKey = nmsWorld.dimension();
var modifier = respawn.getSpecificModifier(ResourceKey.class);
modifier.write(0, resourceKey);```
#

The error:

#
java.lang.NullPointerException: Cannot invoke "net.minecraft.core.Holder.a()" because "holder" is null
#

I've verified that nothing I'm sending into this is null, so I'm guessing I'm just missing a step before setting into the modifier to instantiate something

forest steeple
blazing quiver
blazing quiver
#

Figured it out! Turns out I needed to pass in ServerLevel.dimensionTypeRegistration() , which is... wait for it... a Holder<DimensionType>!