Search in sources :

Example 1 with ChunkPosition

use of thpmc.vanilla_source.util.ChunkPosition in project VanillaSource by TheHollowPlanetMC.

the class PacketManager method createMultiBlockChangePacket.

public static Set<Object> createMultiBlockChangePacket(ParallelWorld parallelWorld, Set<BlockPosition3i> blocks) {
    Map<ChunkPosition, Set<BlockPosition3i>> chunkMap = new HashMap<>();
    for (BlockPosition3i bp : blocks) {
        chunkMap.computeIfAbsent(new ChunkPosition(bp.getX(), bp.getZ()), cp -> new HashSet<>()).add(bp);
    }
    Set<Object> packets = new HashSet<>();
    for (Map.Entry<ChunkPosition, Set<BlockPosition3i>> entry : chunkMap.entrySet()) {
        ChunkPosition chunkPosition = entry.getKey();
        Set<BlockPosition3i> bps = entry.getValue();
        ParallelChunk parallelChunk = parallelWorld.getChunk(chunkPosition.x, chunkPosition.z);
        if (parallelChunk == null)
            continue;
        PacketPlayOutMultiBlockChange packet = new PacketPlayOutMultiBlockChange();
        List<PacketPlayOutMultiBlockChange.MultiBlockChangeInfo> infoList = new ArrayList<>();
        for (BlockPosition3i bp : bps) {
            BlockData blockData = parallelChunk.getBlockData(bp.getX(), bp.getY(), bp.getZ());
            if (blockData == null)
                continue;
            short loc = (short) ((bp.getX() & 0xF) << 12 | (bp.getZ() & 0xF) << 8 | bp.getY());
            infoList.add(packet.new MultiBlockChangeInfo(loc, ((CraftBlockData) blockData).getState()));
        }
        PacketPlayOutMultiBlockChange.MultiBlockChangeInfo[] array = infoList.toArray(new PacketPlayOutMultiBlockChange.MultiBlockChangeInfo[infoList.size()]);
        try {
            MultiBlockChangePacketHandler.a.set(packet, new ChunkCoordIntPair(chunkPosition.x, chunkPosition.z));
            MultiBlockChangePacketHandler.b.set(packet, array);
            packets.add(packet);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return packets;
}
Also used : ParallelChunk(thpmc.vanilla_source.api.world.parallel.ParallelChunk) java.util(java.util) CraftWorld(org.bukkit.craftbukkit.v1_15_R1.CraftWorld) BlockData(org.bukkit.block.data.BlockData) ChunkPosition(thpmc.vanilla_source.util.ChunkPosition) ParallelWorld(thpmc.vanilla_source.api.world.parallel.ParallelWorld) SectionLevelArray(thpmc.vanilla_source.util.SectionLevelArray) Player(org.bukkit.entity.Player) MultiBlockChangePacketHandler(thpmc.vanilla_source.nms.v1_15_R1.MultiBlockChangePacketHandler) BlockPosition3i(thpmc.vanilla_source.util.BlockPosition3i) Nullable(org.jetbrains.annotations.Nullable) net.minecraft.server.v1_15_R1(net.minecraft.server.v1_15_R1) CraftChunk(org.bukkit.craftbukkit.v1_15_R1.CraftChunk) NMSHandler(thpmc.vanilla_source.nms.v1_15_R1.NMSHandler) CraftBlockData(org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData) BlockChangePacketHandler(thpmc.vanilla_source.nms.v1_15_R1.BlockChangePacketHandler) SectionTypeArray(thpmc.vanilla_source.util.SectionTypeArray) Bukkit(org.bukkit.Bukkit) ChunkPosition(thpmc.vanilla_source.util.ChunkPosition) ParallelChunk(thpmc.vanilla_source.api.world.parallel.ParallelChunk) CraftBlockData(org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData) BlockPosition3i(thpmc.vanilla_source.util.BlockPosition3i) BlockData(org.bukkit.block.data.BlockData) CraftBlockData(org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData)

Aggregations

java.util (java.util)1 net.minecraft.server.v1_15_R1 (net.minecraft.server.v1_15_R1)1 Bukkit (org.bukkit.Bukkit)1 BlockData (org.bukkit.block.data.BlockData)1 CraftChunk (org.bukkit.craftbukkit.v1_15_R1.CraftChunk)1 CraftWorld (org.bukkit.craftbukkit.v1_15_R1.CraftWorld)1 CraftBlockData (org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData)1 Player (org.bukkit.entity.Player)1 Nullable (org.jetbrains.annotations.Nullable)1 ParallelChunk (thpmc.vanilla_source.api.world.parallel.ParallelChunk)1 ParallelWorld (thpmc.vanilla_source.api.world.parallel.ParallelWorld)1 BlockChangePacketHandler (thpmc.vanilla_source.nms.v1_15_R1.BlockChangePacketHandler)1 MultiBlockChangePacketHandler (thpmc.vanilla_source.nms.v1_15_R1.MultiBlockChangePacketHandler)1 NMSHandler (thpmc.vanilla_source.nms.v1_15_R1.NMSHandler)1 BlockPosition3i (thpmc.vanilla_source.util.BlockPosition3i)1 ChunkPosition (thpmc.vanilla_source.util.ChunkPosition)1 SectionLevelArray (thpmc.vanilla_source.util.SectionLevelArray)1 SectionTypeArray (thpmc.vanilla_source.util.SectionTypeArray)1