Search in sources :

Example 1 with VoxelShapeHandle

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

the class EntityMoveHandler_1_13 method world_getEntityCollisionShapes.

private Stream<VoxelShapeHandle> world_getEntityCollisionShapes(EntityHandle entity, double mx, double my, double mz) {
    if (!this.entityCollisionEnabled) {
        return Stream.empty();
    }
    AxisAlignedBBHandle entityBounds = entity.getBoundingBox();
    final double MIN_MOVE = 1.0E-7D;
    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();
    }
    // default VoxelShape IWorldReader::a(@Nullable Entity entity, VoxelShape voxelshape, boolean flag, Set<Entity> set)
    AxisAlignedBBHandle axisalignedbb = voxelshapeBounds.getBoundingBox();
    VoxelShapeHandle shape = VoxelShapeHandle.empty();
    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())) {
                    shape = VoxelShapeHandle.merge(shape, VoxelShapeHandle.fromAABB(axisalignedbb1));
                }
                axisalignedbb1 = entity.getEntityBoundingBox(entity1);
                if (axisalignedbb1 != null && axisalignedbb1.bbTransformA(axisalignedbb) && controller.onEntityCollision(entity1.getBukkitEntity())) {
                    shape = VoxelShapeHandle.merge(shape, VoxelShapeHandle.fromAABB(axisalignedbb1));
                }
            // BKCommonLib end
            /*
                    if (axisalignedbb1 != null && axisalignedbb1.c(axisalignedbb)) {
                        voxelshape1 = VoxelShapes.b(voxelshape1, VoxelShapes.a(axisalignedbb1), OperatorBoolean.OR);
                        if (flag) {
                            break;
                        }
                    }

                    axisalignedbb1 = entity.j(entity1);
                    if (axisalignedbb1 != null && axisalignedbb1.c(axisalignedbb)) {
                        voxelshape1 = VoxelShapes.b(voxelshape1, VoxelShapes.a(axisalignedbb1), OperatorBoolean.OR);
                        if (flag) {
                            break;
                        }
                    }
                    */
            }
        }
    }
    if (shape.isEmpty()) {
        return Stream.empty();
    } else {
        return MountiplexUtil.toStream(shape);
    }
}
Also used : AxisAlignedBBHandle(com.bergerkiller.generated.net.minecraft.world.phys.AxisAlignedBBHandle) VoxelShapeHandle(com.bergerkiller.generated.net.minecraft.world.phys.shapes.VoxelShapeHandle) EntityHandle(com.bergerkiller.generated.net.minecraft.world.entity.EntityHandle)

Example 2 with VoxelShapeHandle

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

the class EntityMoveHandler_1_14 method world_getEntityCollisionShapes.

private Stream<VoxelShapeHandle> world_getEntityCollisionShapes(EntityHandle entity, double mx, double my, double mz) {
    if (!this.entityCollisionEnabled) {
        return Stream.empty();
    }
    AxisAlignedBBHandle entityBounds = entity.getBoundingBox();
    final double MIN_MOVE = 1.0E-7D;
    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();
    }
    // default VoxelShape IWorldReader::a(@Nullable Entity entity, VoxelShape voxelshape, boolean flag, Set<Entity> set)
    AxisAlignedBBHandle axisalignedbb = voxelshapeBounds.getBoundingBox();
    VoxelShapeHandle shape = VoxelShapeHandle.empty();
    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())) {
                    shape = VoxelShapeHandle.merge(shape, VoxelShapeHandle.fromAABB(axisalignedbb1));
                }
                axisalignedbb1 = entity.getEntityBoundingBox(entity1);
                if (axisalignedbb1 != null && axisalignedbb1.bbTransformA(axisalignedbb) && controller.onEntityCollision(entity1.getBukkitEntity())) {
                    shape = VoxelShapeHandle.merge(shape, VoxelShapeHandle.fromAABB(axisalignedbb1));
                }
            // BKCommonLib end
            /*
                    if (axisalignedbb1 != null && axisalignedbb1.c(axisalignedbb)) {
                        voxelshape1 = VoxelShapes.b(voxelshape1, VoxelShapes.a(axisalignedbb1), OperatorBoolean.OR);
                        if (flag) {
                            break;
                        }
                    }

                    axisalignedbb1 = entity.j(entity1);
                    if (axisalignedbb1 != null && axisalignedbb1.c(axisalignedbb)) {
                        voxelshape1 = VoxelShapes.b(voxelshape1, VoxelShapes.a(axisalignedbb1), OperatorBoolean.OR);
                        if (flag) {
                            break;
                        }
                    }
                    */
            }
        }
    }
    if (shape.isEmpty()) {
        return Stream.empty();
    } else {
        return MountiplexUtil.toStream(shape);
    }
}
Also used : AxisAlignedBBHandle(com.bergerkiller.generated.net.minecraft.world.phys.AxisAlignedBBHandle) VoxelShapeHandle(com.bergerkiller.generated.net.minecraft.world.phys.shapes.VoxelShapeHandle) EntityHandle(com.bergerkiller.generated.net.minecraft.world.entity.EntityHandle)

Example 3 with VoxelShapeHandle

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

the class EntityMoveHandler_1_14 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();
    // Execute generated method and convert to Stream<VoxelShapeHandle>
    return logic.getBlockCollisions(world, this, voxelshapeBounds, voxelshapeAABB);
}
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 4 with VoxelShapeHandle

use of com.bergerkiller.generated.net.minecraft.world.phys.shapes.VoxelShapeHandle 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)

Aggregations

AxisAlignedBBHandle (com.bergerkiller.generated.net.minecraft.world.phys.AxisAlignedBBHandle)4 VoxelShapeHandle (com.bergerkiller.generated.net.minecraft.world.phys.shapes.VoxelShapeHandle)4 EntityHandle (com.bergerkiller.generated.net.minecraft.world.entity.EntityHandle)2 WorldHandle (com.bergerkiller.generated.net.minecraft.world.level.WorldHandle)2