Search in sources :

Example 16 with SectionTypeArray

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

the class PacketManager method sendChunkMultiBlockChangeUpdatePacket.

public static void sendChunkMultiBlockChangeUpdatePacket(Player player, ParallelChunk parallelChunk, NMSHandler nmsHandler) {
    for (int sectionIndex = 0; sectionIndex < 16; sectionIndex++) {
        SectionTypeArray sectionTypeArray = parallelChunk.getSectionTypeArray(sectionIndex);
        if (sectionTypeArray == null)
            continue;
        List<Short> coordList = new ArrayList<>();
        List<IBlockData> dataList = new ArrayList<>();
        boolean notEmpty = sectionTypeArray.threadsafeIteration((x, y, z, iBlockData) -> {
            coordList.add((short) (x << 8 | z << 4 | y));
            dataList.add((IBlockData) iBlockData);
        });
        if (!notEmpty)
            continue;
        short[] coordArray = new short[coordList.size()];
        IBlockData[] dataArray = new IBlockData[dataList.size()];
        for (int i = 0; i < coordList.size(); i++) {
            coordArray[i] = coordList.get(i);
            dataArray[i] = dataList.get(i);
        }
        try {
            PacketPlayOutMultiBlockChange packet = new PacketPlayOutMultiBlockChange();
            MultiBlockChangePacketHandler.a.set(packet, SectionPosition.a(parallelChunk.getChunkX(), sectionIndex, parallelChunk.getChunkZ()));
            MultiBlockChangePacketHandler.b.set(packet, coordArray);
            MultiBlockChangePacketHandler.c.set(packet, dataArray);
            MultiBlockChangePacketHandler.d.setBoolean(packet, true);
            nmsHandler.sendPacket(player, packet);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : SectionTypeArray(thpmc.vanilla_source.util.SectionTypeArray)

Example 17 with SectionTypeArray

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

the class PacketManager method createMultiBlockChangePacket.

public static Set<Object> createMultiBlockChangePacket(ParallelWorld parallelWorld, Set<BlockPosition3i> blocks) {
    Map<BlockPosition3i, Set<BlockPosition3i>> chunkMap = new HashMap<>();
    for (BlockPosition3i bp : blocks) {
        chunkMap.computeIfAbsent(new BlockPosition3i(bp.getX() >> 4, bp.getY() >> 4, bp.getZ() >> 4), cp -> new HashSet<>()).add(bp);
    }
    Set<Object> packets = new HashSet<>();
    for (Map.Entry<BlockPosition3i, Set<BlockPosition3i>> entry : chunkMap.entrySet()) {
        BlockPosition3i sectionPosition = entry.getKey();
        Set<BlockPosition3i> bps = entry.getValue();
        ParallelChunk parallelChunk = parallelWorld.getChunk(sectionPosition.getX(), sectionPosition.getZ());
        if (parallelChunk == null)
            continue;
        SectionTypeArray sectionTypeArray = parallelChunk.getSectionTypeArray(sectionPosition.getY());
        if (sectionTypeArray == null)
            continue;
        List<Short> coordList = new ArrayList<>();
        List<IBlockData> dataList = new ArrayList<>();
        for (BlockPosition3i bp : bps) {
            IBlockData iBlockData = (IBlockData) sectionTypeArray.getType(bp.getX() & 0xF, bp.getY() & 0xF, bp.getZ() & 0xF);
            if (iBlockData == null)
                continue;
            coordList.add((short) ((bp.getX() & 0xF) << 8 | (bp.getZ() & 0xF) << 4 | bp.getY() & 0xF));
            dataList.add(iBlockData);
        }
        short[] coordArray = new short[coordList.size()];
        IBlockData[] dataArray = new IBlockData[dataList.size()];
        for (int i = 0; i < coordList.size(); i++) {
            coordArray[i] = coordList.get(i);
            dataArray[i] = dataList.get(i);
        }
        try {
            PacketPlayOutMultiBlockChange packet = new PacketPlayOutMultiBlockChange();
            MultiBlockChangePacketHandler.a.set(packet, SectionPosition.a(sectionPosition.getX(), sectionPosition.getY(), sectionPosition.getZ()));
            MultiBlockChangePacketHandler.b.set(packet, coordArray);
            MultiBlockChangePacketHandler.c.set(packet, dataArray);
            MultiBlockChangePacketHandler.d.setBoolean(packet, true);
            packets.add(packet);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return packets;
}
Also used : ParallelChunk(thpmc.vanilla_source.api.world.parallel.ParallelChunk) java.util(java.util) BlockData(org.bukkit.block.data.BlockData) BlockChangePacketHandler(thpmc.vanilla_source.nms.v1_16_R3.BlockChangePacketHandler) CraftWorld(org.bukkit.craftbukkit.v1_16_R3.CraftWorld) ParallelWorld(thpmc.vanilla_source.api.world.parallel.ParallelWorld) SectionLevelArray(thpmc.vanilla_source.util.SectionLevelArray) Player(org.bukkit.entity.Player) net.minecraft.server.v1_16_R3(net.minecraft.server.v1_16_R3) BlockPosition3i(thpmc.vanilla_source.util.BlockPosition3i) Nullable(org.jetbrains.annotations.Nullable) NMSHandler(thpmc.vanilla_source.nms.v1_16_R3.NMSHandler) CraftBlockData(org.bukkit.craftbukkit.v1_16_R3.block.data.CraftBlockData) CraftChunk(org.bukkit.craftbukkit.v1_16_R3.CraftChunk) MultiBlockChangePacketHandler(thpmc.vanilla_source.nms.v1_16_R3.MultiBlockChangePacketHandler) SectionTypeArray(thpmc.vanilla_source.util.SectionTypeArray) Bukkit(org.bukkit.Bukkit) ParallelChunk(thpmc.vanilla_source.api.world.parallel.ParallelChunk) SectionTypeArray(thpmc.vanilla_source.util.SectionTypeArray) BlockPosition3i(thpmc.vanilla_source.util.BlockPosition3i)

Example 18 with SectionTypeArray

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

the class ImplParallelChunk method setNMSBlockData.

@Override
public void setNMSBlockData(int blockX, int blockY, int blockZ, Object blockData) {
    int sectionIndex = ChunkUtil.getSectionIndex(blockY);
    SectionTypeArray sectionTypeArray = sectionTypeArrays[sectionIndex];
    if (sectionTypeArray == null) {
        sectionTypeArray = new SectionTypeArray();
        sectionTypeArrays[sectionIndex] = sectionTypeArray;
    }
    sectionTypeArray.setType(blockX & 0xF, blockY & 0xF, blockZ & 0xF, blockData);
    mapChunkPacketCache = null;
}
Also used : SectionTypeArray(thpmc.vanilla_source.util.SectionTypeArray)

Aggregations

SectionTypeArray (thpmc.vanilla_source.util.SectionTypeArray)18 ParallelChunk (thpmc.vanilla_source.api.world.parallel.ParallelChunk)5 ParallelWorld (thpmc.vanilla_source.api.world.parallel.ParallelWorld)5 Nullable (org.jetbrains.annotations.Nullable)4 ParallelUniverse (thpmc.vanilla_source.api.world.parallel.ParallelUniverse)3 List (java.util.List)2 net.minecraft.server.v1_16_R3 (net.minecraft.server.v1_16_R3)2 ChunkSnapshot (org.bukkit.ChunkSnapshot)2 World (org.bukkit.World)2 CraftChunk (org.bukkit.craftbukkit.v1_16_R3.CraftChunk)2 CraftWorld (org.bukkit.craftbukkit.v1_16_R3.CraftWorld)2 CraftBlockData (org.bukkit.craftbukkit.v1_16_R3.block.data.CraftBlockData)2 SectionLevelArray (thpmc.vanilla_source.util.SectionLevelArray)2 java.util (java.util)1 net.minecraft.server.v1_15_R1 (net.minecraft.server.v1_15_R1)1 IBlockData (net.minecraft.server.v1_16_R3.IBlockData)1 PacketPlayOutMultiBlockChange (net.minecraft.server.v1_16_R3.PacketPlayOutMultiBlockChange)1 SectionPosition (net.minecraft.server.v1_16_R3.SectionPosition)1 Bukkit (org.bukkit.Bukkit)1 BlockData (org.bukkit.block.data.BlockData)1