Search in sources :

Example 6 with AxisAlignedBBHandle

use of com.bergerkiller.generated.net.minecraft.world.phys.AxisAlignedBBHandle 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 7 with AxisAlignedBBHandle

use of com.bergerkiller.generated.net.minecraft.world.phys.AxisAlignedBBHandle 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 8 with AxisAlignedBBHandle

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

the class MapPlayerInput method updateInterception.

private void updateInterception(boolean intercept) {
    // No receivers, do not do input interception
    if (!intercept) {
        updateInputInterception(false);
        return;
    }
    // If the player is already inside a vehicle, we can not fake-mount him
    if (player.isInsideVehicle()) {
        updateInputInterception(false);
        return;
    }
    // Since Minecraft 1.16, it is not possible to be on the mount while sneaking
    if (!CommonCapabilities.VEHICLE_EXIT_CANCELLABLE && player.isSneaking()) {
        updateInputInterception(false);
        return;
    }
    // Verify the player isn't flying, it results in a kick
    if (!player.isFlying() && !player.isOnGround()) {
        // Check if there is a block below the player, which means onGround is actually true
        // This is because, when the player is 'floating' while intercepting, onGround stays false
        EntityHandle playerHandle = EntityHandle.fromBukkit(player);
        double half_width = 0.5 * (double) playerHandle.getWidth();
        double below = 0.1;
        AxisAlignedBBHandle below_bounds = AxisAlignedBBHandle.createNew(playerHandle.getLocX() - half_width, playerHandle.getLocY() - below, playerHandle.getLocZ() - half_width, playerHandle.getLocX() + half_width, playerHandle.getLocY(), playerHandle.getLocZ() + half_width);
        if (WorldHandle.fromBukkit(player.getWorld()).isNotCollidingWithBlocks(playerHandle, below_bounds)) {
            updateInputInterception(false);
            return;
        }
    }
    // Allowed
    this.updateInputInterception(true);
}
Also used : AxisAlignedBBHandle(com.bergerkiller.generated.net.minecraft.world.phys.AxisAlignedBBHandle) EntityHandle(com.bergerkiller.generated.net.minecraft.world.entity.EntityHandle)

Example 9 with AxisAlignedBBHandle

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

the class EntityMoveHandler method getBlockBoundingBox.

// Gets the AxisAlignedBB bounding box to use for computing Block Collisions
protected AxisAlignedBBHandle getBlockBoundingBox(EntityHandle entity) {
    AxisAlignedBBHandle boundingBox = entity.getBoundingBox();
    if (this.blockCollisionEnabled && this.customBlockCollisionBounds != null) {
        double x = 0.5 * (boundingBox.getMinX() + boundingBox.getMaxX());
        double y = boundingBox.getMinY();
        double z = 0.5 * (boundingBox.getMinZ() + boundingBox.getMaxZ());
        return AxisAlignedBBHandle.createNew(x - 0.5 * this.customBlockCollisionBounds.getX(), y, z - 0.5 * this.customBlockCollisionBounds.getZ(), x + 0.5 * this.customBlockCollisionBounds.getX(), y + this.customBlockCollisionBounds.getY(), z + 0.5 * this.customBlockCollisionBounds.getZ());
    }
    return boundingBox;
}
Also used : AxisAlignedBBHandle(com.bergerkiller.generated.net.minecraft.world.phys.AxisAlignedBBHandle)

Example 10 with AxisAlignedBBHandle

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

the class EntityMoveHandler_1_13 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