Search in sources :

Example 26 with CraftBlockState

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

the class CraftEventFactory method handleBlockFormEvent.

public static boolean handleBlockFormEvent(World world, BlockPos pos, net.minecraft.block.BlockState block, int flag, @Nullable Entity entity) {
    CraftBlockState blockState = CraftBlockState.getBlockState(world, pos, flag);
    blockState.setData(block);
    BlockFormEvent event = (entity == null) ? new BlockFormEvent(blockState.getBlock(), blockState) : new EntityBlockFormEvent(entity.getBukkitEntity(), blockState.getBlock(), blockState);
    world.getCBServer().getPluginManager().callEvent(event);
    if (!event.isCancelled()) {
        blockState.update(true);
    }
    return !event.isCancelled();
}
Also used : CraftBlockState(org.bukkit.craftbukkit.v1_16_R3.block.CraftBlockState) EntityBlockFormEvent(org.bukkit.event.block.EntityBlockFormEvent) BlockFormEvent(org.bukkit.event.block.BlockFormEvent) EntityBlockFormEvent(org.bukkit.event.block.EntityBlockFormEvent)

Example 27 with CraftBlockState

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

the class CraftEventFactory method handleBlockGrowEvent.

public static boolean handleBlockGrowEvent(World world, BlockPos pos, net.minecraft.block.BlockState newData, int flag) {
    Block block = world.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ());
    CraftBlockState state = (CraftBlockState) block.getState();
    state.setData(newData);
    BlockGrowEvent event = new BlockGrowEvent(block, state);
    Bukkit.getPluginManager().callEvent(event);
    if (!event.isCancelled()) {
        state.update(true);
    }
    return !event.isCancelled();
}
Also used : CraftBlockState(org.bukkit.craftbukkit.v1_16_R3.block.CraftBlockState) Block(org.bukkit.block.Block) CraftBlock(org.bukkit.craftbukkit.v1_16_R3.block.CraftBlock) BlockGrowEvent(org.bukkit.event.block.BlockGrowEvent)

Example 28 with CraftBlockState

use of org.bukkit.craftbukkit.v1_16_R3.block.CraftBlockState 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 29 with CraftBlockState

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

the class Block_1_18_R2 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 : CraftBlockState(org.bukkit.craftbukkit.v1_18_R2.block.CraftBlockState) BlockState(net.minecraft.world.level.block.state.BlockState) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Block(org.bukkit.block.Block) CraftBlock(org.bukkit.craftbukkit.v1_18_R2.block.CraftBlock) ArrayList(java.util.ArrayList) List(java.util.List) NotNull(org.jetbrains.annotations.NotNull)

Example 30 with CraftBlockState

use of org.bukkit.craftbukkit.v1_16_R3.block.CraftBlockState in project Mohist by MohistMC.

the class CraftEventFactory method handleBlockSpreadEvent.

public static boolean handleBlockSpreadEvent(LevelAccessor world, BlockPos source, BlockPos target, net.minecraft.world.level.block.state.BlockState block, int flag) {
    // Suppress during worldgen
    if (!(world instanceof Level)) {
        world.setBlock(target, block, flag);
        return true;
    }
    CraftBlockState state = CraftBlockStates.getBlockState(world, target, flag);
    state.setData(block);
    BlockSpreadEvent event = new BlockSpreadEvent(state.getBlock(), CraftBlock.at(world, source), state);
    Bukkit.getPluginManager().callEvent(event);
    if (!event.isCancelled()) {
        state.update(true);
    }
    return !event.isCancelled();
}
Also used : CraftBlockState(org.bukkit.craftbukkit.v1_18_R2.block.CraftBlockState) BlockSpreadEvent(org.bukkit.event.block.BlockSpreadEvent) Level(net.minecraft.world.level.Level) ServerLevel(net.minecraft.server.level.ServerLevel)

Aggregations

CraftBlockState (org.bukkit.craftbukkit.v1_16_R3.block.CraftBlockState)16 Block (org.bukkit.block.Block)8 CraftBlockState (org.bukkit.craftbukkit.v1_18_R2.block.CraftBlockState)8 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 List (java.util.List)4 NotNull (org.jetbrains.annotations.NotNull)4 BlockState (net.minecraft.world.level.block.state.BlockState)3 CraftBlock (org.bukkit.craftbukkit.v1_16_R3.block.CraftBlock)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 TileEntity (net.minecraft.server.v1_8_R3.TileEntity)2 BlockPos (net.minecraft.util.math.BlockPos)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