Search in sources :

Example 11 with CraftBlockState

use of org.bukkit.craftbukkit.v1_17_R1.block.CraftBlockState in project LoliServer by Loli-Server.

the class CraftEventFactory method handleMoistureChangeEvent.

public static boolean handleMoistureChangeEvent(World world, BlockPos pos, net.minecraft.block.BlockState newBlock, int flag) {
    CraftBlockState state = CraftBlockState.getBlockState(world, pos, flag);
    state.setData(newBlock);
    MoistureChangeEvent event = new MoistureChangeEvent(state.getBlock(), state);
    Bukkit.getPluginManager().callEvent(event);
    if (!event.isCancelled()) {
        state.update(true);
    }
    return !event.isCancelled();
}
Also used : MoistureChangeEvent(org.bukkit.event.block.MoistureChangeEvent) CraftBlockState(org.bukkit.craftbukkit.v1_16_R3.block.CraftBlockState)

Example 12 with CraftBlockState

use of org.bukkit.craftbukkit.v1_17_R1.block.CraftBlockState in project LoliServer by Loli-Server.

the class CraftWorld method generateTree.

@Override
public boolean generateTree(Location loc, TreeType type, BlockChangeDelegate delegate) {
    world.captureTreeGeneration = true;
    world.captureBlockStates = true;
    boolean grownTree = generateTree(loc, type);
    world.captureBlockStates = false;
    world.captureTreeGeneration = false;
    if (grownTree) {
        // Copy block data to delegate
        for (org.bukkit.block.BlockState blockstate : world.capturedBlockStates.values()) {
            BlockPos position = ((CraftBlockState) blockstate).getPosition();
            net.minecraft.block.BlockState oldBlock = world.getBlockState(position);
            int flag = ((CraftBlockState) blockstate).getFlag();
            delegate.setBlockData(blockstate.getX(), blockstate.getY(), blockstate.getZ(), blockstate.getBlockData());
            net.minecraft.block.BlockState newBlock = world.getBlockState(position);
            world.markAndNotifyBlock(position, null, oldBlock, newBlock, flag, 512);
        }
        world.capturedBlockStates.clear();
        return true;
    } else {
        world.capturedBlockStates.clear();
        return false;
    }
}
Also used : CraftBlockState(org.bukkit.craftbukkit.v1_16_R3.block.CraftBlockState) BlockPos(net.minecraft.util.math.BlockPos)

Example 13 with CraftBlockState

use of org.bukkit.craftbukkit.v1_17_R1.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 14 with CraftBlockState

use of org.bukkit.craftbukkit.v1_17_R1.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 15 with CraftBlockState

use of org.bukkit.craftbukkit.v1_17_R1.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 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 BlockPos (net.minecraft.core.BlockPos)1