Search in sources :

Example 6 with CraftBlock

use of org.bukkit.craftbukkit.v1_18_R2.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 7 with CraftBlock

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

the class Block_1_16_R3 method getMultiBlockMaskPacket.

private PacketPlayOutMultiBlockChange getMultiBlockMaskPacket(List<Block> blocks, @Nullable IBlockData mask) {
    BlockPosition position = ((CraftBlock) blocks.get(0)).getPosition();
    // Setup default information
    short[] locations = new short[blocks.size()];
    IBlockData[] data = new IBlockData[blocks.size()];
    for (int i = 0; i < locations.length; i++) {
        Block block = blocks.get(i);
        int x = block.getX() & 0xF;
        int y = block.getY() & 0xF;
        int z = block.getZ() & 0xF;
        short shortLocation = (short) (x << 8 | z << 4 | y);
        locations[i] = shortLocation;
        data[i] = mask;
    }
    PacketPlayOutMultiBlockChange packet = new PacketPlayOutMultiBlockChange(SectionPosition.a(position), new ShortArraySet(0), null, false);
    ReflectionUtil.setField(multiBlockChangeB, packet, locations);
    ReflectionUtil.setField(multiBlockChangeC, packet, data);
    return packet;
}
Also used : IBlockData(net.minecraft.server.v1_16_R3.IBlockData) ShortArraySet(org.bukkit.craftbukkit.libs.it.unimi.dsi.fastutil.shorts.ShortArraySet) BlockPosition(net.minecraft.server.v1_16_R3.BlockPosition) PacketPlayOutMultiBlockChange(net.minecraft.server.v1_16_R3.PacketPlayOutMultiBlockChange) CraftBlock(org.bukkit.craftbukkit.v1_16_R3.block.CraftBlock) Block(org.bukkit.block.Block) CraftBlock(org.bukkit.craftbukkit.v1_16_R3.block.CraftBlock)

Example 8 with CraftBlock

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

the class v1_16_R3 method getHitBox.

@Override
public HitBox getHitBox(Block block) {
    if (block.isEmpty() || block.isLiquid() || block.isPassable())
        return null;
    BoundingBox boundingBox = block.getBoundingBox();
    HitBox hitBox = new HitBox(boundingBox.getMinX(), boundingBox.getMinY(), boundingBox.getMinZ(), boundingBox.getMaxX(), boundingBox.getMaxY(), boundingBox.getMaxZ());
    hitBox.setBlockHitBox(block);
    if (WeaponMechanics.getBasicConfigurations().getBool("Check_Accurate_Hitboxes", true)) {
        CraftBlock craftBlock = (CraftBlock) block;
        List<AxisAlignedBB> voxelShape = craftBlock.getNMS().getCollisionShape(craftBlock.getCraftWorld().getHandle(), craftBlock.getPosition()).d();
        if (voxelShape.size() > 1) {
            int x = block.getX();
            int y = block.getY();
            int z = block.getZ();
            for (AxisAlignedBB boxPart : voxelShape) {
                hitBox.addVoxelShapePart(new HitBox(x + boxPart.minX, y + boxPart.minY, z + boxPart.minZ, x + boxPart.maxX, y + boxPart.maxY, z + boxPart.maxZ));
            }
        }
    }
    return hitBox;
}
Also used : AxisAlignedBB(net.minecraft.server.v1_16_R3.AxisAlignedBB) HitBox(me.deecaad.weaponmechanics.weapon.projectile.HitBox) BoundingBox(org.bukkit.util.BoundingBox) CraftBlock(org.bukkit.craftbukkit.v1_16_R3.block.CraftBlock)

Example 9 with CraftBlock

use of org.bukkit.craftbukkit.v1_18_R2.block.CraftBlock in project Atlas by funkemunky.

the class BlockBox1_13_R2 method getCollisionBox.

@Override
public CollisionBox getCollisionBox(Block block) {
    final net.minecraft.server.v1_13_R2.World world = ((org.bukkit.craftbukkit.v1_13_R2.CraftWorld) block.getWorld()).getHandle();
    final int x = block.getX(), y = block.getY(), z = block.getZ();
    net.minecraft.server.v1_13_R2.IBlockData iblockData = ((CraftBlock) block).getNMS();
    net.minecraft.server.v1_13_R2.Block vblock = iblockData.getBlock();
    BlockPosition blockPos = new BlockPosition(x, y, z);
    VoxelShape shape = vblock.a(iblockData, (IBlockAccess) world, blockPos);
    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.minX, box.minY, box.minZ, box.maxX, box.maxY, box.maxZ);
    } else {
        ComplexCollisionBox complexBox = new ComplexCollisionBox();
        for (AxisAlignedBB box : boxes) {
            complexBox.add(new SimpleCollisionBox(box.minX, box.minY, box.minZ, box.maxX, box.maxY, box.maxZ));
        }
        return complexBox;
    }
}
Also used : AxisAlignedBB(net.minecraft.server.v1_13_R2.AxisAlignedBB) BlockPosition(net.minecraft.server.v1_13_R2.BlockPosition) ComplexCollisionBox(cc.funkemunky.api.utils.world.types.ComplexCollisionBox) CraftBlock(org.bukkit.craftbukkit.v1_13_R2.block.CraftBlock) SimpleCollisionBox(cc.funkemunky.api.utils.world.types.SimpleCollisionBox) VoxelShape(net.minecraft.server.v1_13_R2.VoxelShape)

Example 10 with CraftBlock

use of org.bukkit.craftbukkit.v1_18_R2.block.CraftBlock in project Atlas by funkemunky.

the class BlockBox1_15_R1 method getCollisionBox.

@Override
public CollisionBox getCollisionBox(org.bukkit.block.Block block) {
    final net.minecraft.server.v1_15_R1.World world = ((org.bukkit.craftbukkit.v1_15_R1.CraftWorld) block.getWorld()).getHandle();
    final int x = block.getX(), y = block.getY(), z = block.getZ();
    net.minecraft.server.v1_15_R1.IBlockData iblockData = ((CraftBlock) block).getNMS();
    net.minecraft.server.v1_15_R1.Block vblock = iblockData.getBlock();
    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.minX, box.minY, box.minZ, box.maxX, box.maxY, box.maxZ);
    } else {
        ComplexCollisionBox complexBox = new ComplexCollisionBox();
        for (AxisAlignedBB box : boxes) {
            complexBox.add(new SimpleCollisionBox(box.minX, box.minY, box.minZ, box.maxX, box.maxY, box.maxZ));
        }
        return complexBox;
    }
}
Also used : ComplexCollisionBox(cc.funkemunky.api.utils.world.types.ComplexCollisionBox) CraftBlock(org.bukkit.craftbukkit.v1_15_R1.block.CraftBlock) World(net.minecraft.server.v1_15_R1.World) SimpleCollisionBox(cc.funkemunky.api.utils.world.types.SimpleCollisionBox) net.minecraft.server.v1_15_R1(net.minecraft.server.v1_15_R1) CraftWorld(org.bukkit.craftbukkit.v1_15_R1.CraftWorld)

Aggregations

BlockPos (net.minecraft.core.BlockPos)14 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)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_17_R1.CraftWorld)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 Block (org.bukkit.block.Block)4 CraftWorld (org.bukkit.craftbukkit.v1_18_R2.CraftWorld)4 ShortArraySet (it.unimi.dsi.fastutil.shorts.ShortArraySet)3 ClientboundSectionBlocksUpdatePacket (net.minecraft.network.protocol.game.ClientboundSectionBlocksUpdatePacket)3