Skip to content

Commit

Permalink
Add blocksInside and allCorners methods to AABBHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
robotgryphon committed Mar 10, 2024
1 parent d4aadd7 commit 0a67916
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/main/java/dev/compactmods/spatial/aabb/AABBHelper.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
package dev.compactmods.spatial.aabb;

import net.minecraft.core.BlockPos;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;

import java.util.stream.Stream;

public abstract class AABBHelper {

public static Stream<BlockPos> blocksInside(AABB bounds) {
return BlockPos.betweenClosedStream(bounds.contract(1, 1, 1));
}

public static Stream<BlockPos> allCorners(AABB bounds) {
Stream.Builder<BlockPos> stream = Stream.builder();
stream.add(BlockPos.containing(bounds.maxX - 1, bounds.maxY - 1, bounds.maxZ - 1));
stream.add(BlockPos.containing(bounds.minX, bounds.maxY - 1, bounds.maxZ - 1));
stream.add(BlockPos.containing(bounds.maxX - 1, bounds.minY, bounds.maxZ - 1));
stream.add(BlockPos.containing(bounds.minX, bounds.minY, bounds.maxZ - 1));
stream.add(BlockPos.containing(bounds.maxX - 1, bounds.maxY - 1, bounds.minZ));
stream.add(BlockPos.containing(bounds.minX, bounds.maxY - 1, bounds.minZ));
stream.add(BlockPos.containing(bounds.maxX - 1, bounds.minY, bounds.minZ));
stream.add(BlockPos.containing(bounds.minX, bounds.minY, bounds.minZ));
return stream.build();
}

public static Vec3 minCorner(AABB aabb) {
return new Vec3(aabb.minX, aabb.minY, aabb.minZ);
}
Expand Down

0 comments on commit 0a67916

Please sign in to comment.