narunaru114 icon

Untitled

narunaru114 | PRO | 08/02/24 07:25:43 PM UTC (Edited) | 0 ⭐ | 12741 👁️ | Never ⏰ | []
Java |

2.82 KB

|

None

|

0 👍

/

0 👎

public class ChunkTestCommand implements CommandExecutor {
    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        Player player = (Player) sender;
        // This sample code is only for empty light array. If you need to send non-empty light array, additional code is needed.
        User packetUser = PacketEvents.getAPI().getPlayerManager().getUser(player);
        int y = packetUser.getTotalWorldHeight() >> 4;
        List<BaseChunk> chunks = new ArrayList<>();
        for (int i = 0; i < y; i++) {
            Chunk_v1_18 baseChunk = new Chunk_v1_18();
            baseChunk.set(1 & 0xF, 1 & 0xF, 1 & 0xF, WrappedBlockState.getDefaultState(StateTypes.AIR));
            baseChunk.set(5 & 0xF, 5 & 0xF, 5 & 0xF, WrappedBlockState.getDefaultState(StateTypes.TORCH));
            for (int j = 0; j < 4; j++) {
                for (int k = 0; k < 4; k++) {
                    for (int l = 0; l < 4; l++) {
                        //baseChunk.getBiomeData().set(j, k, l, 0); //TODO: Seems like packet events are bugged on biome data pallet.
                        int id = baseChunk.getBiomeData().palette.stateToId(2); // Basalt deltas biome // Checked on 1.20.6
                        baseChunk.getBiomeData().storage.set((k << 2 | l) << 2 | j, id); //Bits per
                    }
                }
            }
            chunks.add(baseChunk);
        }
        Column column = new Column(player.getLocation().getChunk().getX(), player.getLocation().getChunk().getZ(), true, chunks.toArray(new BaseChunk[0]), null);
        LightData lightData = new LightData();
        byte[][] emptyLightArray = new byte[y][0];
        BitSet emptyBitSet = new BitSet();
        BitSet lightBitSet = new BitSet(); // Empty Bit Set
        for (int i = 0; i < y; i++) {
            // If you have non-empty light array, you need to write it here.
            //lightArray[i] = light array;
 
            // BitSets are very important!!
            // If there is a non-empty light array, it needs to be set correctly.
            // However, this time we are only sending an empty light array.
            // so here, simply setting emptyBitSet to true is enough.
            emptyBitSet.set(i, true);
        }
        lightData.setBlockLightArray(emptyLightArray);
        lightData.setSkyLightArray(emptyLightArray);
        lightData.setBlockLightCount(y);
        lightData.setSkyLightCount(y);
        lightData.setBlockLightMask(lightBitSet);
        lightData.setSkyLightMask(lightBitSet);
        lightData.setEmptyBlockLightMask(emptyBitSet);
        lightData.setEmptySkyLightMask(emptyBitSet);
        WrapperPlayServerChunkData chunkData = new WrapperPlayServerChunkData(column, lightData);
        packetUser.sendPacket(chunkData);
        return true;
    }
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎