mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 00:04:42 +00:00
Read an explicit world Y below zero as a height, not as automatic
An object or structure piece placed at world Y -1, or at any Y that lands below zero, was treated as "sample the height" because every stage tested requestedY < 0. Automatic height is now an explicit flag on the placement run, set by the automatic entry points, and explicit heights of any sign are placed where asked. Automatic placements keep their seeds and heights.
Upstream: 9f0615a97
This commit is contained in:
1 parent
ccdfad8ba5
commit
e3dd61c177
15 files changed
+157
-57
No files matched your search
@@ -45,6 +45,7 @@ import java.util.OptionalInt;
|
||||
*/
|
||||
public final class ObjectRun {
|
||||
private static final int NOT_ANCHORED = Integer.MIN_VALUE;
|
||||
private static final int AUTOMATIC_Y = -1;
|
||||
private static final int NEIGHBOR_READ_BLOCKS = 1;
|
||||
private static final long X_MULTIPLIER = 0x9E3779B97F4A7C15L;
|
||||
private static final long Z_MULTIPLIER = 0xC2B2AE3D27D4EB4FL;
|
||||
@@ -56,28 +57,41 @@ public final class ObjectRun {
|
||||
private final ObjectPlacement settings;
|
||||
private final int x;
|
||||
private final int requestedY;
|
||||
private final boolean automaticHeight;
|
||||
private final int z;
|
||||
private final Cave cave;
|
||||
private final List<BlockPosition> objectBlocks = new ArrayList<>();
|
||||
private int anchorY = NOT_ANCHORED;
|
||||
|
||||
private ObjectRun(PlaceableObject object, ObjectPlacement settings, int x, int requestedY, int z, Cave cave) {
|
||||
private ObjectRun(PlaceableObject object, ObjectPlacement settings, int x, int requestedY, boolean automaticHeight, int z,
|
||||
Cave cave) {
|
||||
this.object = Objects.requireNonNull(object, "object");
|
||||
this.settings = Objects.requireNonNull(settings, "settings");
|
||||
this.x = x;
|
||||
this.requestedY = requestedY;
|
||||
this.automaticHeight = automaticHeight;
|
||||
this.z = z;
|
||||
this.cave = cave;
|
||||
}
|
||||
|
||||
/** @param requestedY the height to place at, or a negative value for the stages to sample it */
|
||||
/** @param requestedY the height to place at, which may be below zero in a dimension that reaches down there */
|
||||
public static ObjectRun of(PlaceableObject object, ObjectPlacement settings, int x, int requestedY, int z) {
|
||||
return new ObjectRun(object, settings, x, requestedY, z, null);
|
||||
return new ObjectRun(object, settings, x, requestedY, false, z, null);
|
||||
}
|
||||
|
||||
/** A placement inside {@code cave}, which the stages anchor in and keep the object's height within. */
|
||||
/** A placement at the height the stages sample from the terrain. */
|
||||
public static ObjectRun automatic(PlaceableObject object, ObjectPlacement settings, int x, int z) {
|
||||
return new ObjectRun(object, settings, x, AUTOMATIC_Y, true, z, null);
|
||||
}
|
||||
|
||||
/** A placement at {@code requestedY} inside {@code cave}, which the stages anchor in and keep the object's height within. */
|
||||
public static ObjectRun inCave(PlaceableObject object, ObjectPlacement settings, int x, int requestedY, int z, Cave cave) {
|
||||
return new ObjectRun(object, settings, x, requestedY, z, Objects.requireNonNull(cave, "cave"));
|
||||
return new ObjectRun(object, settings, x, requestedY, false, z, Objects.requireNonNull(cave, "cave"));
|
||||
}
|
||||
|
||||
/** A placement inside {@code cave} at the height the stages sample from it. */
|
||||
public static ObjectRun automaticInCave(PlaceableObject object, ObjectPlacement settings, int x, int z, Cave cave) {
|
||||
return new ObjectRun(object, settings, x, AUTOMATIC_Y, true, z, Objects.requireNonNull(cave, "cave"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -127,11 +141,16 @@ public final class ObjectRun {
|
||||
return x;
|
||||
}
|
||||
|
||||
/** The height the caller asked for, negative when the stages sample it. */
|
||||
/** The height the caller asked for; meaningless when {@link #automaticHeight()}. */
|
||||
public int requestedY() {
|
||||
return requestedY;
|
||||
}
|
||||
|
||||
/** Whether the stages sample the height from the terrain instead of placing at {@link #requestedY()}. */
|
||||
public boolean automaticHeight() {
|
||||
return automaticHeight;
|
||||
}
|
||||
|
||||
public int z() {
|
||||
return z;
|
||||
}
|
||||
|
||||
@@ -53,7 +53,6 @@ import java.util.Set;
|
||||
*/
|
||||
final class FloatingPlacer {
|
||||
private static final ObjectRotation NO_ROTATION = ObjectRotation.of(0, 0, 0);
|
||||
private static final int SAMPLED_HEIGHT = -1;
|
||||
private static final Set<String> AIR_MATERIALS = Set.of("minecraft:air", "minecraft:cave_air");
|
||||
|
||||
private final PackWorld world;
|
||||
@@ -110,7 +109,7 @@ final class FloatingPlacer {
|
||||
ObjectPlacement floating = placement.toBuilder().place(List.of(object.name())).build();
|
||||
int id = random.i(0, Integer.MAX_VALUE);
|
||||
try {
|
||||
place(ObjectRun.of(object, floating, worldX, SAMPLED_HEIGHT, worldZ), context.placementTerrain(), object, id);
|
||||
place(ObjectRun.automatic(object, floating, worldX, worldZ), context.placementTerrain(), object, id);
|
||||
} catch (Throwable failure) {
|
||||
log.error("Failed to place a floating object", failure);
|
||||
}
|
||||
|
||||
@@ -48,7 +48,6 @@ import com.volmit.world.PackWorld;
|
||||
*/
|
||||
final class ObjectChunk {
|
||||
private static final int REJECTED = -1;
|
||||
private static final int SAMPLED_HEIGHT = -1;
|
||||
|
||||
private final PackWorld world;
|
||||
private final PlacementTerrain terrain;
|
||||
@@ -85,7 +84,7 @@ final class ObjectChunk {
|
||||
int placeOnSurface(PlaceableObject object, int x, int z, ObjectPlacement placement, PlacementChanges changes,
|
||||
PlacementTags tags, String goldenTag) {
|
||||
PlacementTerrain placer = proceduralTerrain(terrain, object, goldenTag);
|
||||
return place(ObjectRun.of(object, EffectiveSettings.withChanges(placement, changes), x, SAMPLED_HEIGHT, z), placer, tags);
|
||||
return place(ObjectRun.automatic(object, EffectiveSettings.withChanges(placement, changes), x, z), placer, tags);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -66,7 +66,7 @@ public final class AnchorModule implements IrisModule {
|
||||
PreparedPlacement prepared = context.output(PlacementStages.Prepare.TRANSFORMS);
|
||||
PlacementSettings settings = prepared.settings();
|
||||
boolean structurePiece = prepared.mode().has(PlaceTrait.RAW_STAMP);
|
||||
if (!settings.fromBottom() && placement.requestedY() < 0) {
|
||||
if (!settings.fromBottom() && placement.automaticHeight()) {
|
||||
return new AnchorHeight(sampled(context, placement, prepared));
|
||||
}
|
||||
ObjectShape object = placement.object();
|
||||
@@ -75,7 +75,7 @@ public final class AnchorModule implements IrisModule {
|
||||
context.reject(CARVING_ANCHOR);
|
||||
return null;
|
||||
}
|
||||
if (placement.requestedY() < 0 || !settings.bottom() || structurePiece) {
|
||||
if (placement.automaticHeight() || !settings.bottom() || structurePiece) {
|
||||
return new AnchorHeight(y);
|
||||
}
|
||||
y += Math.floorDiv(object.height(), 2);
|
||||
|
||||
@@ -127,7 +127,7 @@ public final class BlocksModule implements IrisModule {
|
||||
if (settings.meld() && !structurePiece && !world.isSolid(x, y, z)) {
|
||||
return;
|
||||
}
|
||||
if (data.properties().containsKey(WATERLOGGED) && shouldWaterlog(world, settings, placement.requestedY(), x, y, z)) {
|
||||
if (data.properties().containsKey(WATERLOGGED) && shouldWaterlog(world, settings, placement.automaticHeight(), x, y, z)) {
|
||||
data = data.withProperty(WATERLOGGED, TRUE);
|
||||
}
|
||||
if (world.has(data, BlockTrait.VINE)) {
|
||||
@@ -185,11 +185,11 @@ public final class BlocksModule implements IrisModule {
|
||||
}
|
||||
|
||||
/** Whether a waterloggable block lands in water a waterloggable or underwater placement keeps. */
|
||||
static boolean shouldWaterlog(PlacementWorld world, PlacementSettings settings, int requestedY, int x, int y, int z) {
|
||||
static boolean shouldWaterlog(PlacementWorld world, PlacementSettings settings, boolean automaticHeight, int x, int y, int z) {
|
||||
if (!(settings.waterloggable() || settings.underwater())) {
|
||||
return false;
|
||||
}
|
||||
if (requestedY >= 0 && settings.carvingSupport() == CarvingMode.CARVING_ONLY) {
|
||||
if (!automaticHeight && settings.carvingSupport() == CarvingMode.CARVING_ONLY) {
|
||||
return false;
|
||||
}
|
||||
BlockState existing = world.get(x, y, z);
|
||||
|
||||
@@ -195,7 +195,7 @@ public final class StiltModule implements IrisModule {
|
||||
int top = layerY + anchorY;
|
||||
int highest = prepared.terrain().highest(x, z, true);
|
||||
if (state.properties().containsKey(BlocksModule.WATERLOGGED)
|
||||
&& BlocksModule.shouldWaterlog(world, config, placement.requestedY(), x, highest, z)) {
|
||||
&& BlocksModule.shouldWaterlog(world, config, placement.automaticHeight(), x, highest, z)) {
|
||||
state = state.withProperty(BlocksModule.WATERLOGGED, BlocksModule.TRUE);
|
||||
}
|
||||
int lowerBound = highest - 1;
|
||||
|
||||
@@ -84,7 +84,7 @@ public final class ValidateModule implements IrisModule {
|
||||
return;
|
||||
}
|
||||
int y = context.output(PlacementStages.Anchor.HEIGHT).y();
|
||||
boolean sampled = placement.requestedY() < 0;
|
||||
boolean sampled = placement.automaticHeight();
|
||||
if (sampled && settings.carvingSupport().supportsSurface() && isOnBedrock(context, prepared, y)) {
|
||||
warnImplausibleBedrockPlacement(placement, settings, y, context.log());
|
||||
context.reject("bedrock-anchor");
|
||||
@@ -124,7 +124,7 @@ public final class ValidateModule implements IrisModule {
|
||||
int rotated = prepared.rotatedCenterY();
|
||||
int translated = prepared.translatedCenterY();
|
||||
Optional<ObjectRun.Cave> cave = placement.cave();
|
||||
if (placement.requestedY() < 0 && !prepared.mode().has(PlaceTrait.FREE_HEIGHT) && !settings.underwater()
|
||||
if (placement.automaticHeight() && !prepared.mode().has(PlaceTrait.FREE_HEIGHT) && !settings.underwater()
|
||||
&& !settings.onwater() && prepared.terrain().isUnderwater(placement.x(), placement.z())) {
|
||||
context.reject("underwater-anchor");
|
||||
} else if (cave.isPresent()
|
||||
|
||||
@@ -53,6 +53,6 @@ record WorldVolume(int minX, int maxX, int minY, int maxY, int minZ, int maxZ) {
|
||||
|
||||
/** Whether each block of the placement follows the surface of its own column. */
|
||||
static boolean isPainted(RunningPlacement placement, PreparedPlacement prepared) {
|
||||
return placement.requestedY() < 0 && prepared.mode().anchor() == AnchorSampling.SURFACE;
|
||||
return placement.automaticHeight() && prepared.mode().anchor() == AnchorSampling.SURFACE;
|
||||
}
|
||||
}
|
||||
@@ -79,11 +79,16 @@ public final class RunningPlacement {
|
||||
return run.x();
|
||||
}
|
||||
|
||||
/** The height the caller asked for, negative when the placement samples it. */
|
||||
/** The height the caller asked for; meaningless when {@link #automaticHeight()}. */
|
||||
public int requestedY() {
|
||||
return run.requestedY();
|
||||
}
|
||||
|
||||
/** Whether the placement samples its height from the terrain instead of placing at {@link #requestedY()}. */
|
||||
public boolean automaticHeight() {
|
||||
return run.automaticHeight();
|
||||
}
|
||||
|
||||
public int z() {
|
||||
return run.z();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user