Skip to content

Commit 2c637c6

Browse files
committed
Update BlockSpaceUtil getLayerBoundsByYOffset method
Also adds a new method, getLayerBounds, that takes a field size and Y offset and does the same math. Handy.
1 parent d291ab0 commit 2c637c6

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

src/main/java/dev/compactmods/crafting/compat/jei/JeiMiniaturizationCraftingCategory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ private void renderRecipeLayer(MiniaturizationRecipe recipe, MatrixStack mx, IRe
472472
// Begin layer
473473
mx.pushPose();
474474

475-
AxisAlignedBB layerBounds = BlockSpaceUtil.getLayerBoundsByYOffset(recipe.getDimensions(), layerY);
475+
AxisAlignedBB layerBounds = BlockSpaceUtil.getLayerBounds(recipe.getDimensions(), layerY);
476476
BlockPos.betweenClosedStream(layerBounds).forEach(filledPos -> {
477477
mx.pushPose();
478478

src/main/java/dev/compactmods/crafting/field/render/CraftingPreviewRenderer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public static void render(IMiniaturizationRecipe recipe, double progress, Matrix
5252
Optional<IRecipeLayer> layer = recipe.getLayer(y);
5353
int finalY = y;
5454
layer.ifPresent(l -> {
55-
AxisAlignedBB layerBounds = BlockSpaceUtil.getLayerBoundsByYOffset(recipe.getDimensions(), finalY);
55+
AxisAlignedBB layerBounds = BlockSpaceUtil.getLayerBounds(recipe.getDimensions(), finalY);
5656
BlockPos.betweenClosedStream(layerBounds).forEach(filledPos -> {
5757
stack.pushPose();
5858
stack.translate(filledPos.getX(), 0, filledPos.getZ());

src/main/java/dev/compactmods/crafting/util/BlockSpaceUtil.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.*;
55
import java.util.stream.Collectors;
66
import java.util.stream.Stream;
7+
import dev.compactmods.crafting.api.field.MiniaturizationFieldSize;
78
import net.minecraft.util.Rotation;
89
import net.minecraft.util.math.AxisAlignedBB;
910
import net.minecraft.util.math.BlockPos;
@@ -12,10 +13,15 @@
1213

1314
public abstract class BlockSpaceUtil {
1415

15-
public static AxisAlignedBB getLayerBoundsByYOffset(AxisAlignedBB fullBounds, int yOffset) {
16+
public static AxisAlignedBB getLayerBounds(MiniaturizationFieldSize fieldSize, int layerOffset) {
17+
AxisAlignedBB fieldBounds = fieldSize.getBoundsAtOrigin();
18+
return getLayerBounds(fieldBounds, layerOffset);
19+
}
20+
21+
public static AxisAlignedBB getLayerBounds(AxisAlignedBB fieldBounds, int layerOffset) {
1622
return new AxisAlignedBB(
17-
new Vector3d(fullBounds.minX, fullBounds.minY + yOffset, fullBounds.minZ),
18-
new Vector3d(fullBounds.maxX, (fullBounds.minY + yOffset) + 1, fullBounds.maxZ)
23+
new Vector3d(fieldBounds.minX, fieldBounds.minY + layerOffset, fieldBounds.minZ),
24+
new Vector3d(fieldBounds.maxX, (fieldBounds.minY + layerOffset) + 1, fieldBounds.maxZ)
1925
);
2026
}
2127

@@ -60,6 +66,11 @@ public static boolean boundsFitsInside(AxisAlignedBB inner, AxisAlignedBB outer)
6066
return true;
6167
}
6268

69+
public static Stream<BlockPos> getBlocksIn(MiniaturizationFieldSize fieldSize, int layerOffset) {
70+
AxisAlignedBB layerBounds = getLayerBounds(fieldSize, layerOffset);
71+
return getBlocksIn(layerBounds);
72+
}
73+
6374
@Nonnull
6475
public static Stream<BlockPos> getBlocksIn(AxisAlignedBB bounds) {
6576
return BlockPos.betweenClosedStream(bounds.contract(1, 1, 1));

src/test/java/dev/compactmods/crafting/tests/recipes/util/BlockSpaceUtilTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ void CanSpliceSingleLayer() {
1616
AxisAlignedBB fullBounds = new AxisAlignedBB(0, 0, 0, 10, 10, 10);
1717
AxisAlignedBB slice = new AxisAlignedBB(0, 0, 0, 10, 1, 10);
1818

19-
final AxisAlignedBB actual = BlockSpaceUtil.getLayerBoundsByYOffset(fullBounds, 0);
19+
final AxisAlignedBB actual = BlockSpaceUtil.getLayerBounds(fullBounds, 0);
2020

2121
Assertions.assertEquals(slice, actual, "Slice did not equal actual returned value.");
2222
}

0 commit comments

Comments
 (0)