Search in sources :

Example 11 with AxisAlignedBBHandle

use of com.bergerkiller.generated.net.minecraft.world.phys.AxisAlignedBBHandle in project BKCommonLib by bergerhealer.

the class EntityMoveHandler_1_13 method world_getBlockCollisionShapes.

private Stream<VoxelShapeHandle> world_getBlockCollisionShapes(EntityHandle entity, double mx, double my, double mz) {
    if (!this.blockCollisionEnabled) {
        return Stream.empty();
    }
    AxisAlignedBBHandle entityBounds = this.getBlockBoundingBox(entity);
    final double MIN_MOVE = 1.0E-7D;
    VoxelShapeHandle voxelshapeAABB = VoxelShapeHandle.fromAABB(entityBounds);
    VoxelShapeHandle voxelshapeAABBMoved = VoxelShapeHandle.fromAABB(entityBounds.translate(mx > 0.0D ? -MIN_MOVE : MIN_MOVE, my > 0.0D ? -MIN_MOVE : MIN_MOVE, mz > 0.0D ? -MIN_MOVE : MIN_MOVE));
    VoxelShapeHandle voxelshapeBounds = VoxelShapeHandle.mergeOnlyFirst(VoxelShapeHandle.fromAABB(entityBounds.transformB(mx, my, mz).growUniform(MIN_MOVE)), voxelshapeAABBMoved);
    if (voxelshapeBounds.isEmpty()) {
        return Stream.empty();
    }
    // Check and update that the entity is within the world border
    WorldHandle world = entity.getWorld();
    boolean inWorldBorder = world.isWithinWorldBorder(entity);
    if (inWorldBorder == entity.isOutsideWorldBorder()) {
        entity.setOutsideWorldBorder(!inWorldBorder);
    }
    // Execute generated method and convert to Stream<VoxelShapeHandle>
    return logic.getBlockCollisions(world, this, voxelshapeBounds, voxelshapeAABB, inWorldBorder);
}
Also used : AxisAlignedBBHandle(com.bergerkiller.generated.net.minecraft.world.phys.AxisAlignedBBHandle) VoxelShapeHandle(com.bergerkiller.generated.net.minecraft.world.phys.shapes.VoxelShapeHandle) WorldHandle(com.bergerkiller.generated.net.minecraft.world.level.WorldHandle)

Example 12 with AxisAlignedBBHandle

use of com.bergerkiller.generated.net.minecraft.world.phys.AxisAlignedBBHandle in project BKCommonLib by bergerhealer.

the class EntityMoveHandler_1_8 method world_getCubes.

private List<AxisAlignedBBHandle> world_getCubes(EntityHandle entity, double mx, double my, double mz) {
    AxisAlignedBBHandle axisalignedbb_old = entity.getBoundingBox();
    // BKCommonLib edit: use cached list
    collisions_buffer.clear();
    // BKCommonLib start: replace world_getBlockCollisions call; use cached list instead + allow configurable bounds
    // world.a(entity, axisalignedbb, false, arraylist);
    AxisAlignedBBHandle entityBlockAABB = this.getBlockBoundingBox(entity);
    entity.setBoundingBoxField(entityBlockAABB);
    world_getBlockCollisions(entity, entityBlockAABB, entityBlockAABB.transformB(mx, my, mz));
    entity.setBoundingBoxField(axisalignedbb_old);
    // BKCommonLib end
    world_addEntityCubes(entity, axisalignedbb_old.transformB(mx, my, mz));
    return collisions_buffer;
}
Also used : AxisAlignedBBHandle(com.bergerkiller.generated.net.minecraft.world.phys.AxisAlignedBBHandle)

Example 13 with AxisAlignedBBHandle

use of com.bergerkiller.generated.net.minecraft.world.phys.AxisAlignedBBHandle in project BKCommonLib by bergerhealer.

the class EntityMoveHandler_1_8 method world_addEntityCubes.

private void world_addEntityCubes(EntityHandle entity, AxisAlignedBBHandle axisalignedbb) {
    if (entity != null && this.entityCollisionEnabled) {
        List<EntityHandle> list = entity.getWorld().getNearbyEntities(entity, axisalignedbb.growUniform(0.25D));
        for (EntityHandle entity1 : list) {
            if (!entity.isInSameVehicle(entity1)) {
                // BKCommonLib start: block collision event handler
                AxisAlignedBBHandle axisalignedbb1 = entity1.getOtherBoundingBox();
                if (axisalignedbb1 != null && axisalignedbb1.bbTransformA(axisalignedbb) && controller.onEntityCollision(entity1.getBukkitEntity())) {
                    collisions_buffer.add(axisalignedbb1);
                }
                axisalignedbb1 = entity.getEntityBoundingBox(entity1);
                if (axisalignedbb1 != null && axisalignedbb1.bbTransformA(axisalignedbb) && controller.onEntityCollision(entity1.getBukkitEntity())) {
                    collisions_buffer.add(axisalignedbb1);
                }
            // BKCommonLib end
            /*
                    if ((axisalignedbb1 != null) && (axisalignedbb1.c(axisalignedbb))) {
                        list.add(axisalignedbb1);
                    }

                    axisalignedbb1 = entity.j(entity1);
                    if ((axisalignedbb1 != null) && (axisalignedbb1.c(axisalignedbb))) {
                        list.add(axisalignedbb1);
                    }
                    */
            }
        }
    }
}
Also used : AxisAlignedBBHandle(com.bergerkiller.generated.net.minecraft.world.phys.AxisAlignedBBHandle) EntityHandle(com.bergerkiller.generated.net.minecraft.world.entity.EntityHandle)

Example 14 with AxisAlignedBBHandle

use of com.bergerkiller.generated.net.minecraft.world.phys.AxisAlignedBBHandle in project BKCommonLib by bergerhealer.

the class EntityMoveHandler_1_8 method world_getBlockCubes.

/**
 * Adds all the bounding boxes of blocks that collide with the movedBounds boundingbox
 *
 * @param entity that moved
 * @param movedBounds bounding box
 * @param cubes result list
 * @return True if cubes were found
 */
protected boolean world_getBlockCubes(EntityHandle entity, AxisAlignedBBHandle movedBounds, List<AxisAlignedBBHandle> cubes) {
    List<AxisAlignedBBHandle> foundBounds = WorldHandle.T.opt_getCubes_1_8.invoke(entity.getWorld().getRaw(), entity, movedBounds);
    if (foundBounds.isEmpty()) {
        return false;
    }
    // Remove all collisions that have to do with Entities; not Blocks.
    // This is a bit of a hacked in way for backwards <= 1.10.2 support
    // Basically, we repeat getCubes() and ignore all found bounding boxes in here
    List<EntityHandle> list = entity.getWorld().getNearbyEntities(entity, movedBounds.growUniform(0.25D));
    for (EntityHandle entity1 : list) {
        if (CommonCapabilities.VEHICLES_COLLIDE_WITH_PASSENGERS || !entity.isInSameVehicle(entity1)) {
            // BKCommonLib start: block collision event handler
            AxisAlignedBBHandle axisalignedbb1 = entity1.getOtherBoundingBox();
            if (axisalignedbb1 != null && axisalignedbb1.bbTransformA(movedBounds)) {
                removeFromList(foundBounds, axisalignedbb1);
            }
            axisalignedbb1 = entity.getEntityBoundingBox(entity1);
            if (axisalignedbb1 != null && axisalignedbb1.bbTransformA(movedBounds)) {
                removeFromList(foundBounds, axisalignedbb1);
            }
        // BKCommonLib end
        /*
                if ((axisalignedbb1 != null) && (axisalignedbb1.c(axisalignedbb))) {
                    list.add(axisalignedbb1);
                }

                axisalignedbb1 = entity.j(entity1);
                if ((axisalignedbb1 != null) && (axisalignedbb1.c(axisalignedbb))) {
                    list.add(axisalignedbb1);
                }
                */
        }
    }
    cubes.addAll(foundBounds);
    return true;
}
Also used : AxisAlignedBBHandle(com.bergerkiller.generated.net.minecraft.world.phys.AxisAlignedBBHandle) EntityHandle(com.bergerkiller.generated.net.minecraft.world.entity.EntityHandle)

Example 15 with AxisAlignedBBHandle

use of com.bergerkiller.generated.net.minecraft.world.phys.AxisAlignedBBHandle in project BKCommonLib by bergerhealer.

the class EntityMoveHandler_1_14 method onBlockCollided.

// Called from getBlockCollisions_method
public boolean onBlockCollided(Block block) {
    // Find out what direction the block is hit
    BlockFace hitFace;
    AxisAlignedBBHandle entityBounds = this.that.getBoundingBox();
    if (entityBounds.getMaxY() > (block.getY() + 1.0)) {
        hitFace = BlockFace.UP;
    } else if (entityBounds.getMinY() < (double) block.getY()) {
        hitFace = BlockFace.DOWN;
    } else {
        double dx = this.that.getLocX() - block.getX() - 0.5;
        double dz = this.that.getLocZ() - block.getZ() - 0.5;
        hitFace = FaceUtil.getDirection(dx, dz, false);
    }
    // Block collision event
    return controller.onBlockCollision(block, hitFace);
}
Also used : AxisAlignedBBHandle(com.bergerkiller.generated.net.minecraft.world.phys.AxisAlignedBBHandle) BlockFace(org.bukkit.block.BlockFace)

Aggregations

AxisAlignedBBHandle (com.bergerkiller.generated.net.minecraft.world.phys.AxisAlignedBBHandle)15 EntityHandle (com.bergerkiller.generated.net.minecraft.world.entity.EntityHandle)6 VoxelShapeHandle (com.bergerkiller.generated.net.minecraft.world.phys.shapes.VoxelShapeHandle)4 WorldHandle (com.bergerkiller.generated.net.minecraft.world.level.WorldHandle)3 BlockFace (org.bukkit.block.BlockFace)3 Block (org.bukkit.block.Block)2 IntVector3 (com.bergerkiller.bukkit.common.bases.IntVector3)1 BlockData (com.bergerkiller.bukkit.common.wrappers.BlockData)1 CrashReportHandle (com.bergerkiller.generated.net.minecraft.CrashReportHandle)1 CrashReportSystemDetailsHandle (com.bergerkiller.generated.net.minecraft.CrashReportSystemDetailsHandle)1 BlockHandle (com.bergerkiller.generated.net.minecraft.world.level.block.BlockHandle)1 Random (java.util.Random)1 Vehicle (org.bukkit.entity.Vehicle)1 EntityCombustEvent (org.bukkit.event.entity.EntityCombustEvent)1 VehicleBlockCollisionEvent (org.bukkit.event.vehicle.VehicleBlockCollisionEvent)1 Vector (org.bukkit.util.Vector)1