use of org.bukkit.craftbukkit.v1_12_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;
}
use of org.bukkit.craftbukkit.v1_12_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;
}
use of org.bukkit.craftbukkit.v1_12_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;
}
use of org.bukkit.craftbukkit.v1_12_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;
}
use of org.bukkit.craftbukkit.v1_12_R1.block.CraftBlock in project Atlas by funkemunky.
the class BlockBox1_18_R1 method getCollisionBox.
@Override
public CollisionBox getCollisionBox(org.bukkit.block.Block block) {
final World world = ((org.bukkit.craftbukkit.v1_18_R1.CraftWorld) block.getWorld()).getHandle();
final int x = block.getX(), y = block.getY(), z = block.getZ();
IBlockData iblockData = ((CraftBlock) block).getNMS();
Block vblock = iblockData.b();
BlockPosition blockPos = new BlockPosition(x, y, z);
VoxelShape shape = vblock.a(iblockData, world, blockPos, VoxelShapeCollision.a());
List<AxisAlignedBB> boxes = shape.d();
if (boxes.size() == 0) {
return BlockData.getData(block.getType()).getBox(block, ProtocolVersion.getGameVersion());
} else if (boxes.size() == 1) {
AxisAlignedBB box = boxes.get(0);
return new SimpleCollisionBox(box.a, box.b, box.c, box.d, box.e, box.f);
} else {
ComplexCollisionBox complexBox = new ComplexCollisionBox();
for (AxisAlignedBB box : boxes) {
complexBox.add(new SimpleCollisionBox(box.a, box.b, box.c, box.d, box.e, box.f));
}
return complexBox;
}
}
Aggregations