use of cc.funkemunky.api.utils.world.types.SimpleCollisionBox in project Kauri by funkemunky.
the class BukkitListener method boxToString.
private static String boxToString(CollisionBox box) {
if (box instanceof SimpleCollisionBox) {
SimpleCollisionBox sbox = (SimpleCollisionBox) box;
return "SimpleCollisionBox[" + vectorToString(sbox.toBoundingBox().getMinimum()) + ", " + vectorToString(sbox.toBoundingBox().getMaximum()) + "]";
} else {
List<SimpleCollisionBox> downCasted = new ArrayList<>();
box.downCast(downCasted);
return "ComplexBox[" + downCasted.stream().map(sbox -> "SimpleCollisionBox[" + vectorToString(sbox.toBoundingBox().getMinimum()) + ", " + vectorToString(sbox.toBoundingBox().getMaximum()) + "]").collect(Collectors.joining(", ")) + "]";
}
}
use of cc.funkemunky.api.utils.world.types.SimpleCollisionBox in project Kauri by funkemunky.
the class BlockC method onBlockPlace.
@Packet
public void onBlockPlace(WrappedInBlockPlacePacket event) {
Location loc = event.getBlockPosition().toBukkitVector().toLocation(event.getPlayer().getWorld());
Optional<Block> optionalBlock = BlockUtils.getBlockAsync(loc);
if (!optionalBlock.isPresent())
return;
final Block block = optionalBlock.get();
CollisionBox box = BlockData.getData(block.getType()).getBox(block, data.playerVersion);
if (!(box instanceof SimpleCollisionBox)) {
debug("Not SimpleCollisionBox");
return;
}
final SimpleCollisionBox simpleBox = ((SimpleCollisionBox) box);
if (Math.abs(simpleBox.yMax - simpleBox.yMin) != 1. || Math.abs(simpleBox.xMax - simpleBox.xMin) != 1. || Math.abs(simpleBox.zMax - simpleBox.zMin) != 1.) {
debug("not full block: x=%.1f y=%.1f z=%.1f", Math.abs(simpleBox.xMax - simpleBox.xMin), Math.abs(simpleBox.yMax - simpleBox.yMin), Math.abs(simpleBox.zMax - simpleBox.zMin));
return;
}
blockPlacements.add(new Tuple<>(block, simpleBox.expand(0.1)));
}
use of cc.funkemunky.api.utils.world.types.SimpleCollisionBox in project Kauri by funkemunky.
the class MiscUtils method getNearbyEntities.
public static List<Entity> getNearbyEntities(Player player, double horz, double vert) {
final List<Entity> nearbyEntities = new ArrayList<>();
final SimpleCollisionBox playerBox = new SimpleCollisionBox(player.getLocation(), 0.6, 1.8);
for (Entity entity : Atlas.getInstance().getTrackedEntities().values()) {
if (!entity.getWorld().getUID().equals(player.getWorld().getUID()) || player.getEntityId() == entity.getEntityId())
continue;
SimpleCollisionBox box = new SimpleCollisionBox(entity.getLocation(), horz * 2, vert / 2).expandMin(0, -(vert / 2), 0);
if (box.isCollided(playerBox))
nearbyEntities.add(entity);
}
return nearbyEntities;
}
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;
}
}
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);
}
Aggregations