Search in sources :

Example 1 with EngineBlockBoundingBox

use of thpmc.engine.api.util.collision.EngineBlockBoundingBox in project THP-Engine by TheHollowPlanetMC.

the class NMSHandler method collectBlockCollisions.

@Override
public void collectBlockCollisions(EngineBlock engineBlock, Collection<EngineBoundingBox> boundingBoxCollection, CollideOption collideOption) {
    IBlockData iBlockData = ((IBlockData) engineBlock.getNMSBlockData());
    List<AxisAlignedBB> alignedBBList;
    int blockX = engineBlock.getX();
    int blockY = engineBlock.getY();
    int blockZ = engineBlock.getZ();
    BlockPosition blockPosition = new BlockPosition.MutableBlockPosition(blockX, blockY, blockZ);
    if (collideOption.isIgnorePassableBlocks()) {
        alignedBBList = iBlockData.getCollisionShape(null, blockPosition).d();
    } else {
        alignedBBList = iBlockData.getShape(null, blockPosition).d();
    }
    Fluid fluid = iBlockData.getFluid();
    if (!fluid.isEmpty()) {
        switch(collideOption.getFluidCollisionMode()) {
            case ALWAYS:
                {
                    alignedBBList.addAll(getFluidVoxelShape(fluid, engineBlock).d());
                    break;
                }
            case SOURCE_ONLY:
                {
                    if (fluid.isSource()) {
                        alignedBBList.addAll(getFluidVoxelShape(fluid, engineBlock).d());
                    }
                    break;
                }
        }
    }
    for (AxisAlignedBB aabb : alignedBBList) {
        boundingBoxCollection.add(new EngineBlockBoundingBox(aabb.minX + blockX, aabb.minY + blockY, aabb.minZ + blockZ, aabb.maxX + blockX, aabb.maxY + blockY, aabb.maxZ + blockZ, engineBlock));
    }
}
Also used : EngineBlockBoundingBox(thpmc.engine.api.util.collision.EngineBlockBoundingBox)

Example 2 with EngineBlockBoundingBox

use of thpmc.engine.api.util.collision.EngineBlockBoundingBox in project THP-Engine by TheHollowPlanetMC.

the class EngineWorld method rayTraceForCollisionList.

@Nullable
default EngineRayTraceResult rayTraceForCollisionList(@NotNull Vector startPosition, @NotNull Vector direction, double distance, Collection<EngineBoundingBox> boxList, @NotNull CollideOption collideOption) {
    RayTraceResult nearestResult = null;
    EngineBoundingBox nearestBB = null;
    for (EngineBoundingBox boundingBox : boxList) {
        if (collideOption.getBoundingBoxGrow() != 0.0) {
            boundingBox = (EngineBoundingBox) boundingBox.clone().expand(collideOption.getBoundingBoxGrow());
        }
        if (collideOption.getCollideBoundingBoxFunction() != null) {
            if (!collideOption.getCollideBoundingBoxFunction().apply(boundingBox)) {
                continue;
            }
        }
        if (collideOption.getCollideBlockFunction() != null) {
            if (boundingBox instanceof EngineBlockBoundingBox) {
                if (!collideOption.getCollideBlockFunction().apply(((EngineBlockBoundingBox) boundingBox).getBlock())) {
                    continue;
                }
            }
        }
        if (collideOption.getCollideEntityFunction() != null) {
            if (boundingBox instanceof EngineEntityBoundingBox) {
                if (!collideOption.getCollideEntityFunction().apply(((EngineEntityBoundingBox) boundingBox).getEntity())) {
                    continue;
                }
            }
        }
        RayTraceResult result = boundingBox.rayTrace(startPosition, direction, distance);
        if (result != null) {
            if (nearestResult == null) {
                nearestResult = result;
                nearestBB = boundingBox;
            } else if (nearestResult.getHitPosition().distanceSquared(startPosition) > result.getHitPosition().distanceSquared(startPosition)) {
                nearestResult = result;
                nearestBB = boundingBox;
            }
        }
    }
    if (nearestResult == null || nearestResult.getHitBlockFace() == null) {
        return null;
    } else {
        return new EngineRayTraceResult(nearestBB, nearestResult.getHitPosition(), nearestResult.getHitBlockFace());
    }
}
Also used : EngineBlockBoundingBox(thpmc.engine.api.util.collision.EngineBlockBoundingBox) EngineEntityBoundingBox(thpmc.engine.api.util.collision.EngineEntityBoundingBox) RayTraceResult(org.bukkit.util.RayTraceResult) EngineBoundingBox(thpmc.engine.api.util.collision.EngineBoundingBox) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with EngineBlockBoundingBox

use of thpmc.engine.api.util.collision.EngineBlockBoundingBox in project THP-Engine by TheHollowPlanetMC.

the class NMSHandler method collectBlockCollisions.

@Override
public void collectBlockCollisions(EngineBlock engineBlock, Collection<EngineBoundingBox> boundingBoxCollection, CollideOption collideOption) {
    IBlockData iBlockData = ((IBlockData) engineBlock.getNMSBlockData());
    List<AxisAlignedBB> alignedBBList;
    int blockX = engineBlock.getX();
    int blockY = engineBlock.getY();
    int blockZ = engineBlock.getZ();
    BlockPosition blockPosition = new BlockPosition.MutableBlockPosition(blockX, blockY, blockZ);
    if (collideOption.isIgnorePassableBlocks()) {
        alignedBBList = iBlockData.getCollisionShape(null, blockPosition).d();
    } else {
        alignedBBList = iBlockData.getShape(null, blockPosition).d();
    }
    Fluid fluid = iBlockData.getFluid();
    if (!fluid.isEmpty()) {
        switch(collideOption.getFluidCollisionMode()) {
            case ALWAYS:
                {
                    alignedBBList.addAll(getFluidVoxelShape(fluid, engineBlock).d());
                    break;
                }
            case SOURCE_ONLY:
                {
                    if (fluid.isSource()) {
                        alignedBBList.addAll(getFluidVoxelShape(fluid, engineBlock).d());
                    }
                    break;
                }
        }
    }
    for (AxisAlignedBB aabb : alignedBBList) {
        boundingBoxCollection.add(new EngineBlockBoundingBox(aabb.minX + blockX, aabb.minY + blockY, aabb.minZ + blockZ, aabb.maxX + blockX, aabb.maxY + blockY, aabb.maxZ + blockZ, engineBlock));
    }
}
Also used : EngineBlockBoundingBox(thpmc.engine.api.util.collision.EngineBlockBoundingBox)

Aggregations

EngineBlockBoundingBox (thpmc.engine.api.util.collision.EngineBlockBoundingBox)3 RayTraceResult (org.bukkit.util.RayTraceResult)1 Nullable (org.jetbrains.annotations.Nullable)1 EngineBoundingBox (thpmc.engine.api.util.collision.EngineBoundingBox)1 EngineEntityBoundingBox (thpmc.engine.api.util.collision.EngineEntityBoundingBox)1