Search in sources :

Example 86 with IBlockData

use of net.minecraft.server.v1_13_R2.IBlockData in project MechanicsMain by WeaponMechanics.

the class Block_1_15_R1 method getMultiBlockMaskPacket.

@Override
@NotNull
public List<Object> getMultiBlockMaskPacket(@NotNull List<Block> blocks, @Nullable BlockState mask) {
    if (blocks == null || blocks.isEmpty()) {
        throw new IllegalArgumentException("No blocks are being changed!");
    }
    Map<org.bukkit.Chunk, List<Block>> sortedBlocks = new HashMap<>();
    for (Block block : blocks) {
        List<Block> list = sortedBlocks.computeIfAbsent(block.getChunk(), chunk -> new ArrayList<>());
        list.add(block);
    }
    List<Object> packets = new ArrayList<>(sortedBlocks.size());
    IBlockData theMask = mask == null ? null : ((CraftBlockState) mask).getHandle();
    for (List<Block> entry : sortedBlocks.values()) {
        packets.add(getMultiBlockMaskPacket(entry, theMask));
    }
    return packets;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Chunk(net.minecraft.server.v1_15_R1.Chunk) CraftChunk(org.bukkit.craftbukkit.v1_15_R1.CraftChunk) IBlockData(net.minecraft.server.v1_15_R1.IBlockData) Block(org.bukkit.block.Block) ArrayList(java.util.ArrayList) List(java.util.List) NotNull(org.jetbrains.annotations.NotNull)

Example 87 with IBlockData

use of net.minecraft.server.v1_13_R2.IBlockData in project MechanicsMain by WeaponMechanics.

the class Block_1_16_R3 method getMultiBlockMaskPacket.

@Override
@NotNull
public List<Object> getMultiBlockMaskPacket(@NotNull List<Block> blocks, @Nullable BlockState mask) {
    if (blocks == null || blocks.isEmpty()) {
        throw new IllegalArgumentException("No blocks are being changed!");
    }
    Map<SubChunk, List<Block>> sortedBlocks = new HashMap<>();
    for (Block block : blocks) {
        List<Block> list = sortedBlocks.computeIfAbsent(SubChunk.byBlock(block), chunk -> new ArrayList<>());
        list.add(block);
    }
    List<Object> packets = new ArrayList<>(sortedBlocks.size());
    IBlockData theMask = mask == null ? null : ((CraftBlockState) mask).getHandle();
    for (List<Block> entry : sortedBlocks.values()) {
        packets.add(getMultiBlockMaskPacket(entry, theMask));
    }
    return packets;
}
Also used : IBlockData(net.minecraft.server.v1_16_R3.IBlockData) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CraftBlock(org.bukkit.craftbukkit.v1_16_R3.block.CraftBlock) Block(org.bukkit.block.Block) ArrayList(java.util.ArrayList) List(java.util.List) NotNull(org.jetbrains.annotations.NotNull)

Example 88 with IBlockData

use of net.minecraft.server.v1_13_R2.IBlockData in project MechanicsMain by WeaponMechanics.

the class Block_1_13_R2 method getMultiBlockMaskPacket.

@Override
@NotNull
public List<Object> getMultiBlockMaskPacket(@NotNull List<Block> blocks, @Nullable Material mask, byte data) {
    if (blocks == null || blocks.isEmpty()) {
        throw new IllegalArgumentException("No blocks are being changed!");
    }
    Map<Chunk, List<Block>> sortedBlocks = new HashMap<>();
    for (Block block : blocks) {
        List<Block> list = sortedBlocks.computeIfAbsent(block.getChunk(), chunk -> new ArrayList<>());
        list.add(block);
    }
    List<Object> packets = new ArrayList<>(sortedBlocks.size());
    IBlockData theMask = mask == null ? null : ((CraftBlockData) mask.createBlockData()).getState();
    for (List<Block> entry : sortedBlocks.values()) {
        packets.add(getMultiBlockMaskPacket(entry, theMask));
    }
    return packets;
}
Also used : IBlockData(net.minecraft.server.v1_13_R2.IBlockData) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Block(org.bukkit.block.Block) ArrayList(java.util.ArrayList) List(java.util.List) CraftChunk(org.bukkit.craftbukkit.v1_13_R2.CraftChunk) Chunk(org.bukkit.Chunk) NotNull(org.jetbrains.annotations.NotNull)

Example 89 with IBlockData

use of net.minecraft.server.v1_13_R2.IBlockData in project MechanicsMain by WeaponMechanics.

the class Block_1_13_R2 method getMultiBlockMaskPacket.

@Override
@NotNull
public List<Object> getMultiBlockMaskPacket(@NotNull List<Block> blocks, @Nullable BlockState mask) {
    if (blocks == null || blocks.isEmpty()) {
        throw new IllegalArgumentException("No blocks are being changed!");
    }
    Map<Chunk, List<Block>> sortedBlocks = new HashMap<>();
    for (Block block : blocks) {
        List<Block> list = sortedBlocks.computeIfAbsent(block.getChunk(), chunk -> new ArrayList<>());
        list.add(block);
    }
    List<Object> packets = new ArrayList<>(sortedBlocks.size());
    IBlockData theMask = mask == null ? null : ((CraftBlockState) mask).getHandle();
    for (List<Block> entry : sortedBlocks.values()) {
        packets.add(getMultiBlockMaskPacket(entry, theMask));
    }
    return packets;
}
Also used : IBlockData(net.minecraft.server.v1_13_R2.IBlockData) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Block(org.bukkit.block.Block) ArrayList(java.util.ArrayList) List(java.util.List) CraftChunk(org.bukkit.craftbukkit.v1_13_R2.CraftChunk) Chunk(org.bukkit.Chunk) NotNull(org.jetbrains.annotations.NotNull)

Example 90 with IBlockData

use of net.minecraft.server.v1_13_R2.IBlockData in project MechanicsMain by WeaponMechanics.

the class Block_1_13_R2 method getMultiBlockMaskPacket.

private PacketPlayOutMultiBlockChange getMultiBlockMaskPacket(List<Block> blocks, @Nullable IBlockData mask) {
    net.minecraft.server.v1_13_R2.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_13_R2.PacketPlayOutMultiBlockChange) Block(org.bukkit.block.Block) CraftChunk(org.bukkit.craftbukkit.v1_13_R2.CraftChunk)

Aggregations

HashMap (java.util.HashMap)24 ArrayList (java.util.ArrayList)20 Block (org.bukkit.block.Block)19 List (java.util.List)16 IBlockData (net.minecraft.server.v1_16_R3.IBlockData)16 NotNull (org.jetbrains.annotations.NotNull)16 Chunk (org.bukkit.Chunk)14 IBlockData (net.minecraft.server.v1_12_R1.IBlockData)11 IBlockData (net.minecraft.server.v1_14_R1.IBlockData)10 BlockPosition (net.minecraft.server.v1_12_R1.BlockPosition)9 IBlockData (net.minecraft.server.v1_10_R1.IBlockData)8 IBlockData (net.minecraft.server.v1_15_R1.IBlockData)8 BlockPosition (net.minecraft.server.v1_16_R3.BlockPosition)8 BlockPosition (net.minecraft.server.v1_10_R1.BlockPosition)7 IBlockData (net.minecraft.server.v1_11_R1.IBlockData)7 BlockPosition (net.minecraft.server.v1_8_R3.BlockPosition)7 IBlockData (net.minecraft.server.v1_8_R3.IBlockData)7 IdentityHashMap (java.util.IdentityHashMap)6 BlockPosition (net.minecraft.server.v1_11_R1.BlockPosition)6 BlockPosition (net.minecraft.server.v1_14_R1.BlockPosition)6