Search in sources :

Example 16 with CraftBlock

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

the class BlockEventDispatcher method onBreakBlockEvent.

// For BlockBreakEvent
@SubscribeEvent(receiveCanceled = true)
public void onBreakBlockEvent(BlockEvent.BreakEvent event) {
    if (!event.getWorld().isClientSide()) {
        CraftBlock craftBlock = CraftBlock.at(event.getWorld(), event.getPos());
        BlockBreakEvent breakEvent = new BlockBreakEvent(craftBlock, ((ServerPlayerEntity) event.getPlayer()).getBukkitEntity());
        breakEvent.setCancelled(event.isCanceled());
        breakEvent.setExpToDrop(event.getExpToDrop());
        Bukkit.getPluginManager().callEvent(breakEvent);
        event.setCanceled(breakEvent.isCancelled());
        event.setExpToDrop(breakEvent.getExpToDrop());
        isDropItems = breakEvent.isDropItems();
    }
}
Also used : BlockBreakEvent(org.bukkit.event.block.BlockBreakEvent) CraftBlock(org.bukkit.craftbukkit.v1_16_R3.block.CraftBlock) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 17 with CraftBlock

use of org.bukkit.craftbukkit.v1_17_R1.block.CraftBlock in project MagicPlugin by elBukkit.

the class CompatibilityUtils method forceUpdate.

@Override
public boolean forceUpdate(Block block, boolean physics) {
    if (block == null)
        return false;
    net.minecraft.world.level.block.state.BlockState blockState = ((CraftBlock) block).getNMS();
    if (blockState == null)
        return false;
    net.minecraft.world.level.block.Block nmsBlock = blockState.getBlock();
    net.minecraft.world.level.block.state.BlockState blockData = nmsBlock.defaultBlockState();
    ServerLevel world = ((CraftWorld) block.getWorld()).getHandle();
    BlockPos blockPosition = new BlockPos(block.getX(), block.getY(), block.getZ());
    world.setBlock(blockPosition, blockData, 11);
    return false;
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) BlockPos(net.minecraft.core.BlockPos) CraftBlock(org.bukkit.craftbukkit.v1_17_R1.block.CraftBlock) CraftWorld(org.bukkit.craftbukkit.v1_17_R1.CraftWorld)

Example 18 with CraftBlock

use of org.bukkit.craftbukkit.v1_17_R1.block.CraftBlock in project MagicPlugin by elBukkit.

the class CompatibilityUtils method setAutoBlockState.

@Override
public boolean setAutoBlockState(Block block, Location target, BlockFace facing, boolean physics, Player originator) {
    if (block == null || facing == null || target == null)
        return false;
    net.minecraft.world.level.block.state.BlockState blockState = ((CraftBlock) block).getNMS();
    if (blockState == null)
        return false;
    net.minecraft.world.level.block.Block nmsBlock = blockState.getBlock();
    ItemStack blockItem = new ItemStack(block.getType());
    ServerPlayer originatorHandle = ((CraftPlayer) originator).getHandle();
    ServerLevel world = ((CraftWorld) block.getWorld()).getHandle();
    Object item = platform.getItemUtils().getHandle(platform.getItemUtils().makeReal(blockItem));
    if (originatorHandle == null || world == null || item == null) {
        return false;
    }
    BlockPos blockPosition = new BlockPos(block.getX(), block.getY(), block.getZ());
    Vec3 vec3D = new Vec3(target.getX(), target.getY(), target.getZ());
    Direction direction;
    try {
        direction = Direction.valueOf(facing.name());
    } catch (Exception ex) {
        platform.getLogger().log(Level.SEVERE, "Could not translate to NMS direction: " + facing);
        return false;
    }
    BlockHitResult hitResult = new BlockHitResult(vec3D, direction, blockPosition, false);
    BlockPlaceContext actionContext = new BlockPlaceContext(originatorHandle, InteractionHand.MAIN_HAND, (net.minecraft.world.item.ItemStack) item, hitResult);
    net.minecraft.world.level.block.state.BlockState state = nmsBlock.getStateForPlacement(actionContext);
    if (state == null)
        return false;
    ((CraftBlock) block).setTypeAndData(state, physics);
    return true;
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) BlockPlaceContext(net.minecraft.world.item.context.BlockPlaceContext) CraftPlayer(org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer) CraftBlock(org.bukkit.craftbukkit.v1_17_R1.block.CraftBlock) Direction(net.minecraft.core.Direction) ServerPlayer(net.minecraft.server.level.ServerPlayer) Vec3(net.minecraft.world.phys.Vec3) BlockPos(net.minecraft.core.BlockPos) ItemStack(org.bukkit.inventory.ItemStack) BlockHitResult(net.minecraft.world.phys.BlockHitResult) CraftWorld(org.bukkit.craftbukkit.v1_17_R1.CraftWorld)

Example 19 with CraftBlock

use of org.bukkit.craftbukkit.v1_17_R1.block.CraftBlock in project MagicPlugin by elBukkit.

the class CompatibilityUtils method setAutoBlockState.

@Override
public boolean setAutoBlockState(Block block, Location target, BlockFace facing, boolean physics, Player originator) {
    if (block == null || facing == null || target == null)
        return false;
    net.minecraft.world.level.block.state.BlockState blockState = ((CraftBlock) block).getNMS();
    if (blockState == null)
        return false;
    net.minecraft.world.level.block.Block nmsBlock = blockState.getBlock();
    ItemStack blockItem = new ItemStack(block.getType());
    ServerPlayer originatorHandle = ((CraftPlayer) originator).getHandle();
    ServerLevel world = ((CraftWorld) block.getWorld()).getHandle();
    Object item = platform.getItemUtils().getHandle(platform.getItemUtils().makeReal(blockItem));
    if (originatorHandle == null || world == null || item == null) {
        return false;
    }
    BlockPos blockPosition = new BlockPos(block.getX(), block.getY(), block.getZ());
    Vec3 vec3D = new Vec3(target.getX(), target.getY(), target.getZ());
    Direction direction;
    try {
        direction = Direction.valueOf(facing.name());
    } catch (Exception ex) {
        platform.getLogger().log(Level.SEVERE, "Could not translate to NMS direction: " + facing);
        return false;
    }
    BlockHitResult hitResult = new BlockHitResult(vec3D, direction, blockPosition, false);
    BlockPlaceContext actionContext = new BlockPlaceContext(originatorHandle, InteractionHand.MAIN_HAND, (net.minecraft.world.item.ItemStack) item, hitResult);
    net.minecraft.world.level.block.state.BlockState state = nmsBlock.getStateForPlacement(actionContext);
    if (state == null)
        return false;
    CraftBlock cBlock = (CraftBlock) block;
    CraftBlock.setTypeAndData(cBlock.getHandle(), cBlock.getPosition(), cBlock.getNMS(), state, physics);
    return true;
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) BlockPlaceContext(net.minecraft.world.item.context.BlockPlaceContext) CraftPlayer(org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer) CraftBlock(org.bukkit.craftbukkit.v1_18_R1.block.CraftBlock) Direction(net.minecraft.core.Direction) ServerPlayer(net.minecraft.server.level.ServerPlayer) Vec3(net.minecraft.world.phys.Vec3) BlockPos(net.minecraft.core.BlockPos) ItemStack(org.bukkit.inventory.ItemStack) BlockHitResult(net.minecraft.world.phys.BlockHitResult) CraftWorld(org.bukkit.craftbukkit.v1_18_R1.CraftWorld)

Example 20 with CraftBlock

use of org.bukkit.craftbukkit.v1_17_R1.block.CraftBlock in project MagicPlugin by elBukkit.

the class CompatibilityUtils method forceUpdate.

@Override
public boolean forceUpdate(Block block, boolean physics) {
    if (block == null)
        return false;
    net.minecraft.world.level.block.state.BlockState blockState = ((CraftBlock) block).getNMS();
    if (blockState == null)
        return false;
    net.minecraft.world.level.block.Block nmsBlock = blockState.getBlock();
    net.minecraft.world.level.block.state.BlockState blockData = nmsBlock.defaultBlockState();
    ServerLevel world = ((CraftWorld) block.getWorld()).getHandle();
    BlockPos blockPosition = new BlockPos(block.getX(), block.getY(), block.getZ());
    world.setBlock(blockPosition, blockData, 11);
    return false;
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) BlockPos(net.minecraft.core.BlockPos) CraftBlock(org.bukkit.craftbukkit.v1_18_R1.block.CraftBlock) CraftWorld(org.bukkit.craftbukkit.v1_18_R1.CraftWorld)

Aggregations

BlockPos (net.minecraft.core.BlockPos)13 ServerLevel (net.minecraft.server.level.ServerLevel)11 ComplexCollisionBox (cc.funkemunky.api.utils.world.types.ComplexCollisionBox)9 SimpleCollisionBox (cc.funkemunky.api.utils.world.types.SimpleCollisionBox)9 Direction (net.minecraft.core.Direction)7 CraftWorld (org.bukkit.craftbukkit.v1_17_R1.CraftWorld)6 CraftBlock (org.bukkit.craftbukkit.v1_17_R1.block.CraftBlock)6 CraftBlock (org.bukkit.craftbukkit.v1_18_R1.block.CraftBlock)6 ServerPlayer (net.minecraft.server.level.ServerPlayer)5 BlockPlaceContext (net.minecraft.world.item.context.BlockPlaceContext)5 BlockHitResult (net.minecraft.world.phys.BlockHitResult)5 Vec3 (net.minecraft.world.phys.Vec3)5 CraftWorld (org.bukkit.craftbukkit.v1_18_R1.CraftWorld)5 ItemStack (org.bukkit.inventory.ItemStack)5 HitBox (me.deecaad.weaponmechanics.weapon.projectile.HitBox)4 BlockState (net.minecraft.world.level.block.state.BlockState)4 ShortArraySet (it.unimi.dsi.fastutil.shorts.ShortArraySet)3 ClientboundSectionBlocksUpdatePacket (net.minecraft.network.protocol.game.ClientboundSectionBlocksUpdatePacket)3 VoxelShape (net.minecraft.world.phys.shapes.VoxelShape)3 Block (org.bukkit.block.Block)3