Search in sources :

Example 1 with ChunkAwareBlockCollisionSweeper

use of me.jellysquid.mods.lithium.common.entity.movement.ChunkAwareBlockCollisionSweeper in project lithium-fabric by CaffeineMC.

the class LithiumEntityCollisions method getBlockCollisions.

/**
 * [VanillaCopy] CollisionView#getBlockCollisions(Entity, Box)
 * This is a much, much faster implementation which uses simple collision testing against full-cube block shapes.
 * Checks against the world border are replaced with our own optimized functions which do not go through the
 * VoxelShape system.
 */
public static List<VoxelShape> getBlockCollisions(CollisionView world, Entity entity, Box box) {
    ArrayList<VoxelShape> shapes = new ArrayList<>();
    ChunkAwareBlockCollisionSweeper sweeper = new ChunkAwareBlockCollisionSweeper(world, entity, box);
    while (sweeper.hasNext()) {
        shapes.add(sweeper.next());
    }
    return shapes;
}
Also used : VoxelShape(net.minecraft.util.shape.VoxelShape) ArrayList(java.util.ArrayList) ChunkAwareBlockCollisionSweeper(me.jellysquid.mods.lithium.common.entity.movement.ChunkAwareBlockCollisionSweeper)

Example 2 with ChunkAwareBlockCollisionSweeper

use of me.jellysquid.mods.lithium.common.entity.movement.ChunkAwareBlockCollisionSweeper in project roadrunner by MaxNeedsSnacks.

the class LithiumEntityCollisions method doesBoxCollideWithBlocks.

/**
 * See {@link LithiumEntityCollisions#getBlockCollisions(CollisionView, Entity, Box, BlockCollisionPredicate)}
 *
 * @return True if the box (possibly that of an entity's) collided with any blocks
 */
public static boolean doesBoxCollideWithBlocks(CollisionView world, Entity entity, Box box, BlockCollisionPredicate predicate) {
    if (isBoxEmpty(box)) {
        return false;
    }
    final ChunkAwareBlockCollisionSweeper sweeper = new ChunkAwareBlockCollisionSweeper(world, entity, box, predicate);
    final VoxelShape shape = sweeper.getNextCollidedShape();
    return shape != null;
}
Also used : VoxelShape(net.minecraft.util.shape.VoxelShape) ChunkAwareBlockCollisionSweeper(me.jellysquid.mods.lithium.common.entity.movement.ChunkAwareBlockCollisionSweeper)

Example 3 with ChunkAwareBlockCollisionSweeper

use of me.jellysquid.mods.lithium.common.entity.movement.ChunkAwareBlockCollisionSweeper in project roadrunner by MaxNeedsSnacks.

the class EntityMixin method isInsideWall.

/**
 * @author JellySquid
 * @reason Use optimized block volume iteration, avoid streams
 */
@Redirect(method = "isInsideWall", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;getBlockCollisions(Lnet/minecraft/entity/Entity;Lnet/minecraft/util/math/Box;Ljava/util/function/BiPredicate;)Ljava/util/stream/Stream;"))
public Stream<VoxelShape> isInsideWall(World world, Entity entity, Box box, BiPredicate<BlockState, BlockPos> biPredicate) {
    final ChunkAwareBlockCollisionSweeper sweeper = new ChunkAwareBlockCollisionSweeper(world, (Entity) (Object) this, box, BlockCollisionPredicate.SUFFOCATES);
    final VoxelShape shape = sweeper.getNextCollidedShape();
    if (shape != null) {
        return Stream.of(shape);
    }
    return Stream.empty();
}
Also used : VoxelShape(net.minecraft.util.shape.VoxelShape) ChunkAwareBlockCollisionSweeper(me.jellysquid.mods.lithium.common.entity.movement.ChunkAwareBlockCollisionSweeper) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 4 with ChunkAwareBlockCollisionSweeper

use of me.jellysquid.mods.lithium.common.entity.movement.ChunkAwareBlockCollisionSweeper in project lithium-fabric by CaffeineMC.

the class LithiumEntityCollisions method doesBoxCollideWithBlocks.

/**
 * @return True if the box (possibly that of an entity's) collided with any blocks
 */
public static boolean doesBoxCollideWithBlocks(CollisionView world, Entity entity, Box box) {
    final ChunkAwareBlockCollisionSweeper sweeper = new ChunkAwareBlockCollisionSweeper(world, entity, box);
    final VoxelShape shape = sweeper.computeNext();
    return shape != null && !shape.isEmpty();
}
Also used : VoxelShape(net.minecraft.util.shape.VoxelShape) ChunkAwareBlockCollisionSweeper(me.jellysquid.mods.lithium.common.entity.movement.ChunkAwareBlockCollisionSweeper)

Aggregations

ChunkAwareBlockCollisionSweeper (me.jellysquid.mods.lithium.common.entity.movement.ChunkAwareBlockCollisionSweeper)4 VoxelShape (net.minecraft.util.shape.VoxelShape)4 ArrayList (java.util.ArrayList)1 Redirect (org.spongepowered.asm.mixin.injection.Redirect)1