Search in sources :

Example 1 with CraftBlockState

use of org.bukkit.craftbukkit.v1_18_R2.block.CraftBlockState in project Denizen-For-Bukkit by DenizenScript.

the class BlockHelper_v1_8_R3 method setNbtData.

@Override
public void setNbtData(Block block, CompoundTag compoundTag) {
    TileEntity tileEntity = ((CraftBlockState) block.getState()).getTileEntity();
    if (tileEntity == null) {
        return;
    }
    tileEntity.a(((CompoundTag_v1_8_R3) compoundTag).toNMSTag());
    tileEntity.update();
}
Also used : TileEntity(net.minecraft.server.v1_8_R3.TileEntity) CraftBlockState(org.bukkit.craftbukkit.v1_8_R3.block.CraftBlockState)

Example 2 with CraftBlockState

use of org.bukkit.craftbukkit.v1_18_R2.block.CraftBlockState in project Denizen-For-Bukkit by DenizenScript.

the class BlockHelper_v1_9_R2 method setNbtData.

@Override
public void setNbtData(Block block, CompoundTag compoundTag) {
    TileEntity tileEntity = ((CraftBlockState) block.getState()).getTileEntity();
    if (tileEntity == null) {
        return;
    }
    tileEntity.a(((CompoundTag_v1_9_R2) compoundTag).toNMSTag());
    tileEntity.update();
}
Also used : TileEntity(net.minecraft.server.v1_9_R2.TileEntity) CraftBlockState(org.bukkit.craftbukkit.v1_9_R2.block.CraftBlockState)

Example 3 with CraftBlockState

use of org.bukkit.craftbukkit.v1_18_R2.block.CraftBlockState in project MechanicsMain by WeaponMechanics.

the class Block_1_17_R1 method getMultiBlockMaskPacket.

@Override
@NotNull
public List<Object> getMultiBlockMaskPacket(@NotNull List<Block> blocks, @Nullable org.bukkit.block.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());
    BlockState theMask = mask == null ? null : ((CraftBlockState) mask).getHandle();
    for (List<Block> entry : sortedBlocks.values()) {
        packets.add(getMultiBlockMaskPacket(entry, theMask));
    }
    return packets;
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) CraftBlockState(org.bukkit.craftbukkit.v1_17_R1.block.CraftBlockState) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CraftBlock(org.bukkit.craftbukkit.v1_17_R1.block.CraftBlock) Block(org.bukkit.block.Block) ArrayList(java.util.ArrayList) List(java.util.List) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with CraftBlockState

use of org.bukkit.craftbukkit.v1_18_R2.block.CraftBlockState in project MechanicsMain by WeaponMechanics.

the class Block_1_18_R1 method getMultiBlockMaskPacket.

@Override
@NotNull
public List<Object> getMultiBlockMaskPacket(@NotNull List<Block> blocks, @Nullable org.bukkit.block.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());
    BlockState theMask = mask == null ? null : ((CraftBlockState) mask).getHandle();
    for (List<Block> entry : sortedBlocks.values()) {
        packets.add(getMultiBlockMaskPacket(entry, theMask));
    }
    return packets;
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) CraftBlockState(org.bukkit.craftbukkit.v1_18_R1.block.CraftBlockState) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CraftBlock(org.bukkit.craftbukkit.v1_18_R1.block.CraftBlock) Block(org.bukkit.block.Block) ArrayList(java.util.ArrayList) List(java.util.List) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with CraftBlockState

use of org.bukkit.craftbukkit.v1_18_R2.block.CraftBlockState in project NotQuests by AlessioGr.

the class PacketInjector method sendBeaconUpdatePacket.

/* public static void sendMultiBlockChange(Player p, Block block) {
        // Creating some blocks to set
        Location loc = p.getLocation().clone();

        // BlockData is just an object that stores a Location, int and byte
        List<BlockData> blocks = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            blocks.add(new BlockData(loc, block.getType().getId() + 1, (byte) 0));
        }

        // Sending packet
        PacketPlayOutMultiBlockChange packet = new PacketPlayOutMultiBlockChange();
        MultiBlockChangeInfo[] info = new MultiBlockChangeInfo[blocks.size()];
        for (int i = 0; i < blocks.size(); i++) {
            int blockId = blocks.get(i).getTypeId();

            byte horizPos = (byte) (blocks.get(i).getLocation().getBlockX() << 4
                    + blocks.get(i).getLocation().getBlockZ());
            byte heigth = (byte) blocks.get(i).getLocation().getY();
            byte id = (byte) (blockId << 4 | (0 & 15));
            short data = (short) (horizPos + heigth + id);

            info[i] = packet.new MultiBlockChangeInfo(data,
                    net.minecraft.server.v1_8_R3.Block.getByCombinedId(blockId));
        }
        setPrivateObject(PacketPlayOutMultiBlockChange.class, packet, "a",
                new ChunkCoordIntPair(p.getLocation().getChunk().getX(), p.getLocation().getChunk().getZ()));
        setPrivateObject(PacketPlayOutMultiBlockChange.class, packet, "b", info);

        getNMSPlayer(p).playerConnection.sendPacket(packet);

        p.sendMessage("Packet sent");
    }*/
public void sendBeaconUpdatePacket(Player player, Location location, BlockState blockState) {
    Connection connection = getConnection(getServerPlayer(player).connection);
    CraftBlockState craftBlockState = (CraftBlockState) blockState;
    net.minecraft.world.level.block.Block nmsBlock = craftBlockState.getHandle().getBlock();
    BlockPos blockPos = new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ());
    player.teleport(location.clone().add(0, 1, 0));
    // player.sendMessage("nmsBlock: " + nmsBlock.getName().getString());
    // BlockPost, Block, Action ID (1=recalculate), Action Type (ignored for beacons)
    ClientboundBlockEventPacket clientboundBlockEventPacket = new ClientboundBlockEventPacket(blockPos, nmsBlock, 1, 1);
    // player.sendMessage("sent!");
    // connection.send(clientboundBlockEventPacket);
    connection.send(clientboundBlockEventPacket, (future) -> {
    // player.sendMessage("Arrived!");
    });
}
Also used : CraftBlockState(org.bukkit.craftbukkit.v1_18_R2.block.CraftBlockState) ClientboundBlockEventPacket(net.minecraft.network.protocol.game.ClientboundBlockEventPacket) Connection(net.minecraft.network.Connection) BlockPos(net.minecraft.core.BlockPos)

Aggregations

CraftBlockState (org.bukkit.craftbukkit.v1_16_R3.block.CraftBlockState)16 CraftBlockState (org.bukkit.craftbukkit.v1_18_R2.block.CraftBlockState)8 Block (org.bukkit.block.Block)7 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 List (java.util.List)3 BlockState (net.minecraft.world.level.block.state.BlockState)3 BlockFadeEvent (org.bukkit.event.block.BlockFadeEvent)3 BlockFormEvent (org.bukkit.event.block.BlockFormEvent)3 BlockGrowEvent (org.bukkit.event.block.BlockGrowEvent)3 BlockSpreadEvent (org.bukkit.event.block.BlockSpreadEvent)3 EntityBlockFormEvent (org.bukkit.event.block.EntityBlockFormEvent)3 MoistureChangeEvent (org.bukkit.event.block.MoistureChangeEvent)3 NotNull (org.jetbrains.annotations.NotNull)3 BlockPos (net.minecraft.core.BlockPos)2 TileEntity (net.minecraft.server.v1_8_R3.TileEntity)2 BlockPos (net.minecraft.util.math.BlockPos)2 CraftBlock (org.bukkit.craftbukkit.v1_16_R3.block.CraftBlock)2 CraftBlock (org.bukkit.craftbukkit.v1_18_R2.block.CraftBlock)2 CraftBlockState (org.bukkit.craftbukkit.v1_8_R3.block.CraftBlockState)2