Search in sources :

Example 6 with PacketPlayOutMultiBlockChange

use of net.minecraft.server.v1_15_R1.PacketPlayOutMultiBlockChange in project MechanicsMain by WeaponMechanics.

the class Block_1_11_R1 method getMultiBlockMaskPacket.

private PacketPlayOutMultiBlockChange getMultiBlockMaskPacket(List<Block> blocks, @Nullable IBlockData mask) {
    net.minecraft.server.v1_11_R1.Chunk chunk = ((CraftChunk) blocks.get(0).getChunk()).getHandle();
    // Setup default information
    PacketPlayOutMultiBlockChange packet = new PacketPlayOutMultiBlockChange(0, new short[0], chunk);
    PacketPlayOutMultiBlockChange.MultiBlockChangeInfo[] changes = new PacketPlayOutMultiBlockChange.MultiBlockChangeInfo[blocks.size()];
    for (int i = 0; i < blocks.size(); i++) {
        Block block = blocks.get(i);
        // Where the block is relative to the chunk it is in
        int x = block.getX() & 0xF;
        int y = block.getY();
        int z = block.getZ() & 0xF;
        // Setting the (x, y, z) location into VarInt format
        short location = (short) (x << 12 | y | z << 8);
        // If mask is null, then undo the mask. Otherwise set the mask
        if (mask == null) {
            changes[i] = packet.new MultiBlockChangeInfo(location, chunk);
        } else {
            changes[i] = packet.new MultiBlockChangeInfo(location, mask);
        }
    }
    assert multiBlockChangeB != null;
    ReflectionUtil.setField(multiBlockChangeB, packet, changes);
    return packet;
}
Also used : PacketPlayOutMultiBlockChange(net.minecraft.server.v1_11_R1.PacketPlayOutMultiBlockChange) Block(org.bukkit.block.Block) CraftChunk(org.bukkit.craftbukkit.v1_11_R1.CraftChunk)

Example 7 with PacketPlayOutMultiBlockChange

use of net.minecraft.server.v1_15_R1.PacketPlayOutMultiBlockChange in project MechanicsMain by WeaponMechanics.

the class Block_1_12_R1 method getMultiBlockMaskPacket.

private PacketPlayOutMultiBlockChange getMultiBlockMaskPacket(List<Block> blocks, @Nullable IBlockData mask) {
    net.minecraft.server.v1_12_R1.Chunk chunk = ((CraftChunk) blocks.get(0).getChunk()).getHandle();
    // Setup default information
    PacketPlayOutMultiBlockChange packet = new PacketPlayOutMultiBlockChange(0, new short[0], chunk);
    PacketPlayOutMultiBlockChange.MultiBlockChangeInfo[] changes = new PacketPlayOutMultiBlockChange.MultiBlockChangeInfo[blocks.size()];
    for (int i = 0; i < blocks.size(); i++) {
        Block block = blocks.get(i);
        // Where the block is relative to the chunk it is in
        int x = block.getX() & 0xF;
        int y = block.getY();
        int z = block.getZ() & 0xF;
        // Setting the (x, y, z) location into VarInt format
        short location = (short) (x << 12 | y | z << 8);
        // If mask is null, then undo the mask. Otherwise set the mask
        if (mask == null) {
            changes[i] = packet.new MultiBlockChangeInfo(location, chunk);
        } else {
            changes[i] = packet.new MultiBlockChangeInfo(location, mask);
        }
    }
    ReflectionUtil.setField(multiBlockChangeB, packet, changes);
    return packet;
}
Also used : PacketPlayOutMultiBlockChange(net.minecraft.server.v1_12_R1.PacketPlayOutMultiBlockChange) Block(org.bukkit.block.Block) CraftChunk(org.bukkit.craftbukkit.v1_12_R1.CraftChunk)

Example 8 with PacketPlayOutMultiBlockChange

use of net.minecraft.server.v1_15_R1.PacketPlayOutMultiBlockChange in project MechanicsMain by WeaponMechanics.

the class Block_1_15_R1 method getMultiBlockMaskPacket.

private PacketPlayOutMultiBlockChange getMultiBlockMaskPacket(List<Block> blocks, @Nullable IBlockData mask) {
    Chunk chunk = ((CraftChunk) blocks.get(0).getChunk()).getHandle();
    // Setup default information
    PacketPlayOutMultiBlockChange packet = new PacketPlayOutMultiBlockChange(0, new short[0], chunk);
    PacketPlayOutMultiBlockChange.MultiBlockChangeInfo[] changes = new PacketPlayOutMultiBlockChange.MultiBlockChangeInfo[blocks.size()];
    for (int i = 0; i < blocks.size(); i++) {
        Block block = blocks.get(i);
        // Where the block is relative to the chunk it is in
        int x = block.getX() & 0xF;
        int y = block.getY();
        int z = block.getZ() & 0xF;
        // Setting the (x, y, z) location into VarInt format
        short location = (short) (x << 12 | y | z << 8);
        // If mask is null, then undo the mask. Otherwise set the mask
        if (mask == null) {
            changes[i] = packet.new MultiBlockChangeInfo(location, chunk);
        } else {
            changes[i] = packet.new MultiBlockChangeInfo(location, mask);
        }
    }
    ReflectionUtil.setField(multiBlockChangeB, packet, changes);
    return packet;
}
Also used : PacketPlayOutMultiBlockChange(net.minecraft.server.v1_15_R1.PacketPlayOutMultiBlockChange) Block(org.bukkit.block.Block) Chunk(net.minecraft.server.v1_15_R1.Chunk) CraftChunk(org.bukkit.craftbukkit.v1_15_R1.CraftChunk) CraftChunk(org.bukkit.craftbukkit.v1_15_R1.CraftChunk)

Example 9 with PacketPlayOutMultiBlockChange

use of net.minecraft.server.v1_15_R1.PacketPlayOutMultiBlockChange in project THP-Engine by TheHollowPlanetMC.

the class PacketManager method sendClearChunkMultiBlockChangePacketAtPrimaryThread.

public static void sendClearChunkMultiBlockChangePacketAtPrimaryThread(Player player, ParallelChunk parallelChunk, NMSHandler nmsHandler) {
    if (!Bukkit.isPrimaryThread())
        throw new IllegalStateException("DO NOT CALL FROM ASYNC THREAD!");
    org.bukkit.World world = Bukkit.getWorld(parallelChunk.getWorld().getName());
    if (world == null)
        return;
    if (player.getWorld() != world)
        return;
    List<Short> coordList = new ArrayList<>();
    boolean has = false;
    for (int sectionIndex = 0; sectionIndex < 16; sectionIndex++) {
        SectionTypeArray sectionTypeArray = parallelChunk.getSectionTypeArray(sectionIndex);
        if (sectionTypeArray == null)
            continue;
        int finalSectionIndex = sectionIndex;
        boolean notEmpty = sectionTypeArray.threadsafeIteration((x, y, z, iBlockData) -> {
            short loc = (short) (x << 12 | z << 8 | (y + (finalSectionIndex << 4)));
            coordList.add(loc);
        });
        if (notEmpty)
            has = true;
    }
    if (!has)
        return;
    if (coordList.size() == 0)
        return;
    org.bukkit.Chunk chunk = world.getChunkAt(parallelChunk.getChunkX(), parallelChunk.getChunkZ());
    net.minecraft.server.v1_15_R1.Chunk nmsChunk = ((CraftChunk) chunk).getHandle();
    short[] array = new short[coordList.size()];
    for (int i = 0; i < coordList.size(); i++) {
        array[i] = coordList.get(i);
    }
    PacketPlayOutMultiBlockChange packet = new PacketPlayOutMultiBlockChange(coordList.size(), array, nmsChunk);
    nmsHandler.sendPacket(player, packet);
}
Also used : SectionTypeArray(thpmc.engine.util.SectionTypeArray) net.minecraft.server.v1_15_R1(net.minecraft.server.v1_15_R1) CraftChunk(org.bukkit.craftbukkit.v1_15_R1.CraftChunk)

Example 10 with PacketPlayOutMultiBlockChange

use of net.minecraft.server.v1_15_R1.PacketPlayOutMultiBlockChange in project THP-Engine 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 : java.util(java.util) CraftWorld(org.bukkit.craftbukkit.v1_15_R1.CraftWorld) BlockData(org.bukkit.block.data.BlockData) Player(org.bukkit.entity.Player) SectionTypeArray(thpmc.engine.util.SectionTypeArray) ParallelWorld(thpmc.engine.api.world.parallel.ParallelWorld) BlockChangePacketHandler(thpmc.engine.nms.v1_15_R1.BlockChangePacketHandler) MultiBlockChangePacketHandler(thpmc.engine.nms.v1_15_R1.MultiBlockChangePacketHandler) Nullable(org.jetbrains.annotations.Nullable) net.minecraft.server.v1_15_R1(net.minecraft.server.v1_15_R1) ParallelChunk(thpmc.engine.api.world.parallel.ParallelChunk) ChunkPosition(thpmc.engine.util.ChunkPosition) CraftChunk(org.bukkit.craftbukkit.v1_15_R1.CraftChunk) NMSHandler(thpmc.engine.nms.v1_15_R1.NMSHandler) CraftBlockData(org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData) BlockPosition3i(thpmc.engine.util.BlockPosition3i) SectionLevelArray(thpmc.engine.util.SectionLevelArray) Bukkit(org.bukkit.Bukkit) ChunkPosition(thpmc.engine.util.ChunkPosition) ParallelChunk(thpmc.engine.api.world.parallel.ParallelChunk) CraftBlockData(org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData) BlockPosition3i(thpmc.engine.util.BlockPosition3i) BlockData(org.bukkit.block.data.BlockData) CraftBlockData(org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData)

Aggregations

Block (org.bukkit.block.Block)8 CraftChunk (org.bukkit.craftbukkit.v1_15_R1.CraftChunk)3 ParallelChunk (thpmc.engine.api.world.parallel.ParallelChunk)3 ParallelWorld (thpmc.engine.api.world.parallel.ParallelWorld)3 SectionTypeArray (thpmc.engine.util.SectionTypeArray)3 net.minecraft.server.v1_15_R1 (net.minecraft.server.v1_15_R1)2 PacketPlayOutMultiBlockChange (net.minecraft.server.v1_15_R1.PacketPlayOutMultiBlockChange)2 IBlockData (net.minecraft.server.v1_16_R3.IBlockData)2 PacketPlayOutMultiBlockChange (net.minecraft.server.v1_16_R3.PacketPlayOutMultiBlockChange)2 BlockData (org.bukkit.block.data.BlockData)2 CraftBlockData (org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData)2 ParallelUniverse (thpmc.engine.api.world.parallel.ParallelUniverse)2 java.util (java.util)1 PacketPlayOutMultiBlockChange (net.minecraft.server.v1_10_R1.PacketPlayOutMultiBlockChange)1 PacketPlayOutMultiBlockChange (net.minecraft.server.v1_11_R1.PacketPlayOutMultiBlockChange)1 PacketPlayOutMultiBlockChange (net.minecraft.server.v1_12_R1.PacketPlayOutMultiBlockChange)1 PacketPlayOutMultiBlockChange (net.minecraft.server.v1_13_R2.PacketPlayOutMultiBlockChange)1 PacketPlayOutMultiBlockChange (net.minecraft.server.v1_14_R1.PacketPlayOutMultiBlockChange)1 BlockPosition (net.minecraft.server.v1_15_R1.BlockPosition)1 Chunk (net.minecraft.server.v1_15_R1.Chunk)1