GeyserMC / MCProtocolLib

A library for communication with a Minecraft client/server.
MIT License
724 stars 200 forks source link

1.20.6 vanilla client crashes while receiving chunks #823

Open VenixPLL opened 4 months ago

VenixPLL commented 4 months ago

Sorry if im doing something wrong but there are not enough examples to write that kind of code.

Minecraft version: vanilla 1.20.6 Video of the bug: https://streamable.com/075uuw

Minecraft crash log:

---- Minecraft Crash Report ---- // Don't be sad, have a hug! <3

Time: 2024-05-26 18:52:01 Description: Getting biome dup: Missing Palette entry for index 0. at duo.a(SourceFile:76)

Code used to send the chunk data:


public void packetSent(Session session, Packet packet) {
    if(packet instanceof ClientboundLoginPacket){
       session.send(new ClientboundPlayerPositionPacket(0,0,0,90f,10f,0));
       session.send(new ClientboundGameEventPacket(GameEvent.LEVEL_CHUNKS_LOAD_START, new GameEventValue() {
       }));
        session.send(new ClientboundSetChunkCacheCenterPacket(0,0));
        var chunkSections = new ChunkSection[24]; // One chunk column
         for(int i=0;i<chunkSections.length;i++){
              var section = new ChunkSection(); // Initialize empty
               section.setBlock(0,0,0,1); //Every block on 0,0,0 of every section is set to stone
                chunkSections[i] = section; // Append changes
               System.out.println("Chunk section y="+i + " set! blockCount " + section.getBlockCount());
           }

           var buffer = Unpooled.buffer(); // Empty buffer
           var helper = new MinecraftCodecHelper(Int2ObjectMaps.emptyMap(), Collections.emptyMap());
           for (ChunkSection section : chunkSections) helper.writeChunkSection(buffer,section); // Write data

           var chunkData = new byte[buffer.readableBytes()];
           buffer.readBytes(chunkData);

           session.send(new ClientboundLevelChunkWithLightPacket(
              0,0,chunkData, NbtMap.EMPTY, new BlockEntityInfo[0],
              new LightUpdateData(new BitSet(), new BitSet(), new BitSet(), new BitSet(), Collections.emptyList(), Collections.emptyList())
             ));

      }
      System.out.println("Sending " + packet);
      super.packetSent(session, packet);
}`

This code is written inside MinecraftProtocolTest class 
I saw something wrong with writing chunks on MCProtocolLib and wanted to investigate.