narunaru114

Untitled

Jul 8th, 2024 (edited)
1,157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.82 KB | None | 0 0
  1. public class ChunkTestCommand implements CommandExecutor {
  2.     @Override
  3.     public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
  4.         Player player = (Player) sender;
  5.         // This sample code is only for empty light array. If you need to send non-empty light array, additional code is needed.
  6.         User packetUser = PacketEvents.getAPI().getPlayerManager().getUser(player);
  7.         int y = packetUser.getTotalWorldHeight() >> 4;
  8.         List<BaseChunk> chunks = new ArrayList<>();
  9.         for (int i = 0; i < y; i++) {
  10.             Chunk_v1_18 baseChunk = new Chunk_v1_18();
  11.             baseChunk.set(1 & 0xF, 1 & 0xF, 1 & 0xF, WrappedBlockState.getDefaultState(StateTypes.AIR));
  12.             baseChunk.set(5 & 0xF, 5 & 0xF, 5 & 0xF, WrappedBlockState.getDefaultState(StateTypes.TORCH));
  13.             for (int j = 0; j < 4; j++) {
  14.                 for (int k = 0; k < 4; k++) {
  15.                     for (int l = 0; l < 4; l++) {
  16.                         //baseChunk.getBiomeData().set(j, k, l, 0); //TODO: Seems like packet events are bugged on biome data pallet.
  17.                         int id = baseChunk.getBiomeData().palette.stateToId(2); // Basalt deltas biome // Checked on 1.20.6
  18.                         baseChunk.getBiomeData().storage.set((k << 2 | l) << 2 | j, id); //Bits per
  19.                     }
  20.                 }
  21.             }
  22.             chunks.add(baseChunk);
  23.         }
  24.         Column column = new Column(player.getLocation().getChunk().getX(), player.getLocation().getChunk().getZ(), true, chunks.toArray(new BaseChunk[0]), null);
  25.         LightData lightData = new LightData();
  26.         byte[][] emptyLightArray = new byte[y][0];
  27.         BitSet emptyBitSet = new BitSet();
  28.         BitSet lightBitSet = new BitSet(); // Empty Bit Set
  29.         for (int i = 0; i < y; i++) {
  30.             // If you have non-empty light array, you need to write it here.
  31.             //lightArray[i] = light array;
  32.  
  33.             // BitSets are very important!!
  34.             // If there is a non-empty light array, it needs to be set correctly.
  35.             // However, this time we are only sending an empty light array.
  36.             // so here, simply setting emptyBitSet to true is enough.
  37.             emptyBitSet.set(i, true);
  38.         }
  39.         lightData.setBlockLightArray(emptyLightArray);
  40.         lightData.setSkyLightArray(emptyLightArray);
  41.         lightData.setBlockLightCount(y);
  42.         lightData.setSkyLightCount(y);
  43.         lightData.setBlockLightMask(lightBitSet);
  44.         lightData.setSkyLightMask(lightBitSet);
  45.         lightData.setEmptyBlockLightMask(emptyBitSet);
  46.         lightData.setEmptySkyLightMask(emptyBitSet);
  47.         WrapperPlayServerChunkData chunkData = new WrapperPlayServerChunkData(column, lightData);
  48.         packetUser.sendPacket(chunkData);
  49.         return true;
  50.     }
  51. }
Advertisement