Search in sources :

Example 1 with SimpleCollisionBox

use of cc.funkemunky.api.utils.world.types.SimpleCollisionBox in project Atlas by funkemunky.

the class BlockBox1_8_R3 method getCollisionBox.

@Override
public CollisionBox getCollisionBox(Block block) {
    final net.minecraft.server.v1_8_R3.World world = ((org.bukkit.craftbukkit.v1_8_R3.CraftWorld) block.getWorld()).getHandle();
    final int x = block.getX(), y = block.getY(), z = block.getZ();
    final AxisAlignedBB collide = BlockBoxManager.cbox.copy().offset(x, y, z).toAxisAlignedBB();
    List<AxisAlignedBB> boxes = new ArrayList<>();
    net.minecraft.server.v1_8_R3.Block vblock = CraftMagicNumbers.getBlock(block);
    net.minecraft.server.v1_8_R3.BlockPosition blockPos = new net.minecraft.server.v1_8_R3.BlockPosition(x, y, z);
    vblock.a(world, blockPos, vblock.getBlockData(), collide, boxes, null);
    if (boxes.size() == 0) {
        AxisAlignedBB box = vblock.a(world, blockPos, vblock.getBlockData());
        return new SimpleCollisionBox(box.a, box.b, box.c, box.d, box.e, box.f);
    } 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;
    }
}
Also used : AxisAlignedBB(net.minecraft.server.v1_8_R3.AxisAlignedBB) BlockPosition(net.minecraft.server.v1_8_R3.BlockPosition) ArrayList(java.util.ArrayList) ComplexCollisionBox(cc.funkemunky.api.utils.world.types.ComplexCollisionBox) SimpleCollisionBox(cc.funkemunky.api.utils.world.types.SimpleCollisionBox) BlockPosition(net.minecraft.server.v1_8_R3.BlockPosition) CraftWorld(org.bukkit.craftbukkit.v1_8_R3.CraftWorld)

Example 2 with SimpleCollisionBox

use of cc.funkemunky.api.utils.world.types.SimpleCollisionBox in project Atlas by funkemunky.

the class PlayerSizeHandlerModern method bounds.

@Override
@SneakyThrows
public SimpleCollisionBox bounds(Player player, double x, double y, double z) {
    double width = (double) this.width.invoke(player) / 2;
    double height = this.height.invoke(player);
    return new SimpleCollisionBox().offset(x, y, z).expand(width, 0, width).expandMax(0, height, 0);
}
Also used : SimpleCollisionBox(cc.funkemunky.api.utils.world.types.SimpleCollisionBox) SneakyThrows(lombok.SneakyThrows)

Example 3 with SimpleCollisionBox

use of cc.funkemunky.api.utils.world.types.SimpleCollisionBox in project Atlas by funkemunky.

the class PlayerSizeHandlerModern method bounds.

@SneakyThrows
public SimpleCollisionBox bounds(Player player) {
    Location l = player.getLocation();
    double width = (double) this.width.invoke(player) / 2;
    double height = this.height.invoke(player);
    return new SimpleCollisionBox().offset(l.getX(), l.getY(), l.getZ()).expand(width, 0, width).expandMax(0, height, 0);
}
Also used : SimpleCollisionBox(cc.funkemunky.api.utils.world.types.SimpleCollisionBox) Location(org.bukkit.Location) SneakyThrows(lombok.SneakyThrows)

Example 4 with SimpleCollisionBox

use of cc.funkemunky.api.utils.world.types.SimpleCollisionBox in project Atlas by funkemunky.

the class MinecraftReflection method getCollisionBox.

public static CollisionBox getCollisionBox(Block block) {
    Validate.isTrue(ProtocolVersion.getGameVersion().isBelow(ProtocolVersion.V1_13));
    Object vanillaBlock = CraftReflection.getVanillaBlock(block);
    Object vanillaWorld = CraftReflection.getVanillaWorld(block.getWorld());
    if (ProtocolVersion.getGameVersion().isBelow(ProtocolVersion.V1_8)) {
        Object axisAlignedBB = methodBlockCollisionBox.invoke(vanillaBlock, vanillaWorld, block.getX(), block.getY(), block.getZ());
        if (axisAlignedBB != null) {
            return new SimpleCollisionBox(axisAlignedBB);
        } else
            return NoCollisionBox.INSTANCE;
    } else {
        Object blockPos = new BaseBlockPosition(block.getX(), block.getY(), block.getZ()).getAsBlockPosition();
        Object blockData = getBlockData(vanillaBlock);
        Object axisAlignedBB = ProtocolVersion.getGameVersion().isOrAbove(ProtocolVersion.V1_9) ? methodBlockCollisionBox.invoke(vanillaBlock, blockData, vanillaWorld, blockPos) : methodBlockCollisionBox.invoke(vanillaBlock, vanillaWorld, blockPos, blockData);
        if (axisAlignedBB != null) {
            return new SimpleCollisionBox(axisAlignedBB);
        } else
            return NoCollisionBox.INSTANCE;
    }
}
Also used : SimpleCollisionBox(cc.funkemunky.api.utils.world.types.SimpleCollisionBox) BaseBlockPosition(cc.funkemunky.api.tinyprotocol.packet.types.BaseBlockPosition)

Example 5 with SimpleCollisionBox

use of cc.funkemunky.api.utils.world.types.SimpleCollisionBox in project Atlas by funkemunky.

the class BlockBox1_12_R1 method getCollisionBox.

@Override
public CollisionBox getCollisionBox(Block block) {
    final net.minecraft.server.v1_12_R1.World world = ((org.bukkit.craftbukkit.v1_12_R1.CraftWorld) block.getWorld()).getHandle();
    final int x = block.getX(), y = block.getY(), z = block.getZ();
    final AxisAlignedBB collide = BlockBoxManager.cbox.copy().offset(x, y, z).toAxisAlignedBB();
    List<AxisAlignedBB> boxes = new ArrayList<>();
    net.minecraft.server.v1_12_R1.Block vblock = CraftMagicNumbers.getBlock(block);
    BlockPosition blockPos = new BlockPosition(x, y, z);
    vblock.a(vblock.getBlockData(), world, blockPos, collide, boxes, null, false);
    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;
    }
}
Also used : AxisAlignedBB(net.minecraft.server.v1_12_R1.AxisAlignedBB) BlockPosition(net.minecraft.server.v1_12_R1.BlockPosition) ArrayList(java.util.ArrayList) ComplexCollisionBox(cc.funkemunky.api.utils.world.types.ComplexCollisionBox) SimpleCollisionBox(cc.funkemunky.api.utils.world.types.SimpleCollisionBox)

Aggregations

SimpleCollisionBox (cc.funkemunky.api.utils.world.types.SimpleCollisionBox)24 ComplexCollisionBox (cc.funkemunky.api.utils.world.types.ComplexCollisionBox)20 ArrayList (java.util.ArrayList)9 SneakyThrows (lombok.SneakyThrows)2 BlockPosition (net.minecraft.core.BlockPosition)2 World (net.minecraft.world.level.World)2 Block (net.minecraft.world.level.block.Block)2 IBlockData (net.minecraft.world.level.block.state.IBlockData)2 AxisAlignedBB (net.minecraft.world.phys.AxisAlignedBB)2 VoxelShape (net.minecraft.world.phys.shapes.VoxelShape)2 BaseBlockPosition (cc.funkemunky.api.tinyprotocol.packet.types.BaseBlockPosition)1 Optional (java.util.Optional)1 AxisAlignedBB (net.minecraft.server.v1_10_R1.AxisAlignedBB)1 BlockPosition (net.minecraft.server.v1_10_R1.BlockPosition)1 AxisAlignedBB (net.minecraft.server.v1_11_R1.AxisAlignedBB)1 BlockPosition (net.minecraft.server.v1_11_R1.BlockPosition)1 AxisAlignedBB (net.minecraft.server.v1_12_R1.AxisAlignedBB)1 BlockPosition (net.minecraft.server.v1_12_R1.BlockPosition)1 net.minecraft.server.v1_13_R1 (net.minecraft.server.v1_13_R1)1 AxisAlignedBB (net.minecraft.server.v1_13_R2.AxisAlignedBB)1