Skip to content
This repository has been archived by the owner on May 4, 2024. It is now read-only.

Commit

Permalink
Fix room boundary math (room generation too small)
Browse files Browse the repository at this point in the history
  • Loading branch information
robotgryphon committed Feb 23, 2024
1 parent c754635 commit 8992925
Showing 1 changed file with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,41 @@
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<RoomTemplate>> REGISTRY_KEY = ResourceKey.createRegistryKey(new ResourceLocation(MOD_ID, "room_templates"));

public static final ResourceLocation NO_TEMPLATE = new ResourceLocation(Constants.MOD_ID, "empty");
public static final RoomTemplate INVALID_TEMPLATE = new RoomTemplate(0, 0);

public static Codec<RoomTemplate> 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);
}
}

0 comments on commit 8992925

Please sign in to comment.