From 89929258d6292c9a13aff2a9418fbd2f63e4b9ba Mon Sep 17 00:00:00 2001 From: Ted Senft Date: Thu, 22 Feb 2024 23:45:11 -0500 Subject: [PATCH] Fix room boundary math (room generation too small) --- .../machines/api/room/RoomTemplate.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/room-api/src/main/java/dev/compactmods/machines/api/room/RoomTemplate.java b/room-api/src/main/java/dev/compactmods/machines/api/room/RoomTemplate.java index 1fda9b1..5e9f251 100644 --- a/room-api/src/main/java/dev/compactmods/machines/api/room/RoomTemplate.java +++ b/room-api/src/main/java/dev/compactmods/machines/api/room/RoomTemplate.java @@ -10,19 +10,17 @@ import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.Vec3; -import java.util.Objects; - import static dev.compactmods.machines.api.Constants.MOD_ID; /** * Template structure for creating a new Compact Machine room. These can be added and removed from the registry * at any point, so persistent data must be stored outside these instances. * - * @param dimensions The internal dimensions of the room when it is created. + * @param internalDimensions The internal dimensions of the room when it is created. * @param color The color of the machine blocks created for this template. * @param prefillTemplate A template (structure) file reference, if specified this will fill the new room post-generation */ -public record RoomTemplate(Vec3i dimensions, int color, ResourceLocation prefillTemplate) { +public record RoomTemplate(Vec3i internalDimensions, int color, ResourceLocation prefillTemplate) { public static final ResourceKey> REGISTRY_KEY = ResourceKey.createRegistryKey(new ResourceLocation(MOD_ID, "room_templates")); @@ -30,17 +28,23 @@ public record RoomTemplate(Vec3i dimensions, int color, ResourceLocation prefill public static final RoomTemplate INVALID_TEMPLATE = new RoomTemplate(0, 0); public static Codec CODEC = RecordCodecBuilder.create(i -> i.group( - Vec3i.CODEC.fieldOf("dimensions").forGetter(RoomTemplate::dimensions), + Vec3i.CODEC.fieldOf("dimensions").forGetter(RoomTemplate::internalDimensions), Codec.INT.fieldOf("color").forGetter(RoomTemplate::color), ResourceLocation.CODEC.optionalFieldOf("template", NO_TEMPLATE).forGetter(RoomTemplate::prefillTemplate) ).apply(i, RoomTemplate::new)); - public RoomTemplate(int cubicSize, int color) { - this(new Vec3i(cubicSize, cubicSize, cubicSize), color, NO_TEMPLATE); + public RoomTemplate(int cubicSizeInternal, int color) { + this(new Vec3i(cubicSizeInternal, cubicSizeInternal, cubicSizeInternal), color, NO_TEMPLATE); } public AABB getZeroBoundaries() { - return AABB.ofSize(Vec3.ZERO, dimensions.getX(), dimensions.getY(), dimensions.getZ()) - .move(0, dimensions.getY() / 2f, 0); + return AABB.ofSize(Vec3.ZERO, internalDimensions.getX(), internalDimensions.getY(), internalDimensions.getZ()) + .inflate(1) + .move(0, internalDimensions.getY() / 2f, 0); + } + + public AABB getBoundariesCenteredAt(Vec3 center) { + return AABB.ofSize(center, internalDimensions.getX(), internalDimensions.getY(), internalDimensions.getZ()) + .inflate(1); } }