Search in sources :

Example 21 with IBlockData

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

the class Block_1_10_R1 method getMultiBlockMaskPacket.

@SuppressWarnings("deprecation")
@Override
@NotNull
public List<Object> getMultiBlockMaskPacket(@NotNull List<Block> blocks, @Nullable org.bukkit.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 : net.minecraft.server.v1_10_R1.Block.getByCombinedId(mask.getId() | data << 12);
    for (List<Block> entry : sortedBlocks.values()) {
        packets.add(getMultiBlockMaskPacket(entry, theMask));
    }
    return packets;
}
Also used : IBlockData(net.minecraft.server.v1_10_R1.IBlockData) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Block(org.bukkit.block.Block) ArrayList(java.util.ArrayList) List(java.util.List) Chunk(org.bukkit.Chunk) CraftChunk(org.bukkit.craftbukkit.v1_10_R1.CraftChunk) NotNull(org.jetbrains.annotations.NotNull)

Example 22 with IBlockData

use of net.minecraft.server.v1_16_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 org.bukkit.Material mask, byte data) {
    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 : ((CraftBlockData) mask.createBlockData()).getState();
    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 23 with IBlockData

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

the class Block_1_16_R3 method getMultiBlockMaskPacket.

private PacketPlayOutMultiBlockChange getMultiBlockMaskPacket(List<Block> blocks, @Nullable IBlockData mask) {
    BlockPosition position = ((CraftBlock) blocks.get(0)).getPosition();
    // Setup default information
    short[] locations = new short[blocks.size()];
    IBlockData[] data = new IBlockData[blocks.size()];
    for (int i = 0; i < locations.length; i++) {
        Block block = blocks.get(i);
        int x = block.getX() & 0xF;
        int y = block.getY() & 0xF;
        int z = block.getZ() & 0xF;
        short shortLocation = (short) (x << 8 | z << 4 | y);
        locations[i] = shortLocation;
        data[i] = mask;
    }
    PacketPlayOutMultiBlockChange packet = new PacketPlayOutMultiBlockChange(SectionPosition.a(position), new ShortArraySet(0), null, false);
    ReflectionUtil.setField(multiBlockChangeB, packet, locations);
    ReflectionUtil.setField(multiBlockChangeC, packet, data);
    return packet;
}
Also used : IBlockData(net.minecraft.server.v1_16_R3.IBlockData) ShortArraySet(org.bukkit.craftbukkit.libs.it.unimi.dsi.fastutil.shorts.ShortArraySet) BlockPosition(net.minecraft.server.v1_16_R3.BlockPosition) PacketPlayOutMultiBlockChange(net.minecraft.server.v1_16_R3.PacketPlayOutMultiBlockChange) CraftBlock(org.bukkit.craftbukkit.v1_16_R3.block.CraftBlock) Block(org.bukkit.block.Block) CraftBlock(org.bukkit.craftbukkit.v1_16_R3.block.CraftBlock)

Example 24 with IBlockData

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

the class Block_1_12_R1 method getMultiBlockMaskPacket.

@SuppressWarnings("deprecation")
@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 : net.minecraft.server.v1_12_R1.Block.getByCombinedId(mask.getId() | data << 12);
    for (List<Block> entry : sortedBlocks.values()) {
        packets.add(getMultiBlockMaskPacket(entry, theMask));
    }
    return packets;
}
Also used : IBlockData(net.minecraft.server.v1_12_R1.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_12_R1.CraftChunk) Chunk(org.bukkit.Chunk) NotNull(org.jetbrains.annotations.NotNull)

Example 25 with IBlockData

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

the class Block_1_12_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<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 blockData = null;
    if (mask != null) {
        WorldServer world = ((CraftWorld) mask.getWorld()).getHandle();
        BlockPosition pos = new BlockPosition(mask.getX(), mask.getY(), mask.getZ());
        blockData = world.c(pos).getBlock().getBlockData();
    }
    for (List<Block> entry : sortedBlocks.values()) {
        packets.add(getMultiBlockMaskPacket(entry, blockData));
    }
    return packets;
}
Also used : HashMap(java.util.HashMap) BlockPosition(net.minecraft.server.v1_12_R1.BlockPosition) ArrayList(java.util.ArrayList) WorldServer(net.minecraft.server.v1_12_R1.WorldServer) CraftChunk(org.bukkit.craftbukkit.v1_12_R1.CraftChunk) Chunk(org.bukkit.Chunk) IBlockData(net.minecraft.server.v1_12_R1.IBlockData) Block(org.bukkit.block.Block) ArrayList(java.util.ArrayList) List(java.util.List) CraftWorld(org.bukkit.craftbukkit.v1_12_R1.CraftWorld) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

HashMap (java.util.HashMap)24 ArrayList (java.util.ArrayList)20 Block (org.bukkit.block.Block)17 List (java.util.List)16 IBlockData (net.minecraft.server.v1_16_R3.IBlockData)16 NotNull (org.jetbrains.annotations.NotNull)16 Chunk (org.bukkit.Chunk)15 IBlockData (net.minecraft.server.v1_14_R1.IBlockData)10 IBlockData (net.minecraft.server.v1_12_R1.IBlockData)9 IBlockData (net.minecraft.server.v1_10_R1.IBlockData)8 BlockPosition (net.minecraft.server.v1_12_R1.BlockPosition)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