ProtocolLib

3M Downloads

No Wrapper for net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData

Brokkonaut opened this issue ยท 7 comments

commented

Describe the bug
1.18 has changed the "MAP_CHUNK" packet, it does now contain a field of type net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData and a field of type net.minecraft.network.protocol.game.ClientboundLightUpdatePacketData. Both currently have no wrappers.

commented

Use container.getStructures().read(0) for this, see

public void testMapChunk() {
// this is a special case as we are generating a data serializer class (we only need to construct the packet)
PacketContainer container = new PacketContainer(PacketType.Play.Server.MAP_CHUNK);
// check if we can read an nbt compound from the class
assertTrue(container.getStructures().read(0).getNbtModifier().optionRead(0).isPresent());
}
as a reference :)

commented

Use container.getStructures().read(0) for this

How do I get the tile entity datas (I need the nbt and the coords) from there?

commented

While I'm reading the code it looks like it isn't that trivial with ProtocolLib currently. Let me look into this to give you a better answer :)

commented

Something like this works for me:
List<InternalStructure> chunkData = event.getPacket().getStructures().read(0).getLists(InternalStructure.CONVERTER).read(0);

You can then loop over the chunk data list and read/write to the object normally, something like this:

for (InternalStructure struct : chunkData) {
  int packedXZ = struct.getIntegers().read(0); // calculated with ((blockX & 15) << 4) | (blockZ & 15)
  int relativeY = struct.getIntegers().read(1);
  NbtBase nbt = strct.getNbtModifier().read(0);
  // do stuff with it
}

Hope this helps!

commented

Thank you for your help :) InternalStructure.CONVERTER is not public, so I had to use reflection to get it. But at least it is working now.

commented

Hey (again),

I think we should extend the api we provide to read from / write to internal structures in v5 as Mojang is becoming more and more a friend of "fake" enums. This is something I can look into in the next days, side to side with the improvements to the reflection code which is powering all these things. Currently I am more looking forward to find all issues with the new injection system and fix them...

commented

@Brokkonaut How do you do this? I'm new to Java.