mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 16:25:36 +00:00
Merge upstream port lane c
This commit is contained in:
commit
55786d6297
50 files changed
+2014
-256
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;
|
||||
}
|
||||
|
||||
@@ -54,7 +54,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;
|
||||
@@ -111,7 +110,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) {
|
||||
GenerationFailures.skipPlacement(log, failure, "floating object", object.name(), "at " + worldX + "," + worldZ);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -113,21 +113,22 @@ final class PlacementReach {
|
||||
}
|
||||
|
||||
static int of(ObjectSize size, ObjectPlacement placement) {
|
||||
return of(size, placement.mode().placeMode(), placement.scale().maxScale(), placement.rotation(), placement.translate(),
|
||||
placement.warp() == null || placement.warp().isFlat() ? 0 : placement.warp().multiplier(),
|
||||
return of(size, placement.mode().placeMode(), placement.scale().maxScale(), placement.rotation(), placement.rotateTowardsSlope(),
|
||||
placement.translate(), placement.warp() == null || placement.warp().isFlat() ? 0 : placement.warp().multiplier(),
|
||||
placement.vacuumSettings().orElse(null));
|
||||
}
|
||||
|
||||
private static int of(ObjectSize size, PlaceMode mode, Double maxScale, ObjectRotation rotation, ObjectTranslate translate,
|
||||
Double warpMultiplier, VacuumSettings vacuum) {
|
||||
private static int of(ObjectSize size, PlaceMode mode, Double maxScale, ObjectRotation rotation, boolean rotatesTowardsSlope,
|
||||
ObjectTranslate translate, Double warpMultiplier, VacuumSettings vacuum) {
|
||||
double scale = maxScale == null ? 1D : Math.max(1D, maxScale);
|
||||
int width = scaledDimension(size.width(), scale);
|
||||
int height = scaledDimension(size.height(), scale);
|
||||
int depth = scaledDimension(size.depth(), scale);
|
||||
boolean rotateX = rotation != null && rotation.enabled() && rotation.xAxis() != null && rotation.xAxis().enabled();
|
||||
boolean rotateZ = rotation != null && rotation.enabled() && rotation.zAxis() != null && rotation.zAxis().enabled();
|
||||
int footprint = rotateX || rotateZ ? Math.max(width, Math.max(height, depth)) : Math.max(width, depth);
|
||||
int translation = translationReach(translate, rotation, rotateX || rotateZ);
|
||||
boolean tiltsVertically = rotatesTowardsSlope || rotateX || rotateZ;
|
||||
int footprint = tiltsVertically ? Math.max(width, Math.max(height, depth)) : Math.max(width, depth);
|
||||
int translation = translationReach(translate, rotation, tiltsVertically);
|
||||
int warp = warpMultiplier == null ? 0 : (int) Math.ceil(Math.abs(warpMultiplier) / 2D);
|
||||
int vacuumReach = mode.bendsTerrain() ? 2 * vacuumRadius(mode, vacuum) : 0;
|
||||
long reach = (long) footprint + translation + warp + vacuumReach;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -107,7 +107,11 @@ public final class BlocksModule implements IrisModule {
|
||||
data = edited.data();
|
||||
blockEntity = edited.blockEntity();
|
||||
}
|
||||
data = prepared.rotate(data);
|
||||
BlockState rotated = prepared.rotate(data);
|
||||
if (isDroppedByRotation(data, rotated)) {
|
||||
return;
|
||||
}
|
||||
data = rotated;
|
||||
int x = placement.x() + offset.x();
|
||||
int y = anchorY + offset.y();
|
||||
int z = placement.z() + offset.z();
|
||||
@@ -123,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)) {
|
||||
@@ -152,6 +156,11 @@ public final class BlocksModule implements IrisModule {
|
||||
return data;
|
||||
}
|
||||
|
||||
/** A block that turned into air had no valid orientation: it is left out with its block entity, even for structure pieces that write air. */
|
||||
static boolean isDroppedByRotation(BlockState source, BlockState rotated) {
|
||||
return !AIR_MATERIALS.contains(source.material().toString()) && AIR_MATERIALS.contains(rotated.material().toString());
|
||||
}
|
||||
|
||||
private static boolean shouldWrite(PlacementWorld world, BlockState data, int x, int y, int z, boolean structurePiece) {
|
||||
if (world.has(data, BlockTrait.CUSTOM)) {
|
||||
return true;
|
||||
@@ -176,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;
|
||||
|
||||
@@ -22,7 +22,7 @@ import art.arcane.iris.builtin.anchor.PlaceTrait;
|
||||
import art.arcane.iris.builtin.carve.CarvingMode;
|
||||
import art.arcane.iris.builtin.objects.ObjectRun;
|
||||
import art.arcane.iris.builtin.terrain.BedrockSettings;
|
||||
import art.arcane.iris.modules.placement.ObjectShape;
|
||||
import art.arcane.iris.builtin.prepare.TransformedBounds;
|
||||
import art.arcane.iris.modules.placement.PlacementSettings;
|
||||
import art.arcane.iris.modules.placement.PlacementStages;
|
||||
import art.arcane.iris.modules.placement.PreparedPlacement;
|
||||
@@ -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()
|
||||
@@ -156,15 +156,19 @@ public final class ValidateModule implements IrisModule {
|
||||
}
|
||||
int x = placement.x();
|
||||
int z = placement.z();
|
||||
int margin = nativeStructureMargin(placement.object(), prepared);
|
||||
StructureVolumes volumes = terrain.structureVolumes(x - margin, z - margin, x + margin, z + margin);
|
||||
TransformedBounds bounds = prepared.bounds();
|
||||
int minX = x + bounds.minX();
|
||||
int maxX = x + bounds.maxX();
|
||||
int minZ = z + bounds.minZ();
|
||||
int maxZ = z + bounds.maxZ();
|
||||
StructureVolumes volumes = terrain.structureVolumes(minX, minZ, maxX, maxZ);
|
||||
if (volumes.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
boolean painted = WorldVolume.isPainted(placement, prepared);
|
||||
int envelopeMinY = painted ? Integer.MIN_VALUE : y - margin;
|
||||
int envelopeMaxY = painted ? Integer.MAX_VALUE : y + margin;
|
||||
if (!volumes.intersects(x - margin, envelopeMinY, z - margin, x + margin, envelopeMaxY, z + margin)) {
|
||||
int envelopeMinY = painted ? Integer.MIN_VALUE : y + bounds.minY() - prepared.warpMargin();
|
||||
int envelopeMaxY = painted ? Integer.MAX_VALUE : y + bounds.maxY() + prepared.warpMargin();
|
||||
if (!volumes.intersects(minX, envelopeMinY, minZ, maxX, envelopeMaxY, maxZ)) {
|
||||
return false;
|
||||
}
|
||||
for (ObjectBlock block : context.request().object().blocks()) {
|
||||
@@ -185,16 +189,6 @@ public final class ValidateModule implements IrisModule {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** How far around the anchor any block of the transformed object can reach. */
|
||||
private static int nativeStructureMargin(ObjectShape object, PreparedPlacement prepared) {
|
||||
int margin = (Math.max(object.width(), Math.max(object.height(), object.depth())) / 2) + 1 + prepared.warpMargin();
|
||||
if (prepared.translation() == null) {
|
||||
return margin;
|
||||
}
|
||||
return margin + Math.max(Math.abs(prepared.translation().getBlockX()),
|
||||
Math.max(Math.abs(prepared.translation().getBlockY()), Math.abs(prepared.translation().getBlockZ())));
|
||||
}
|
||||
|
||||
private static boolean isAir(BlockState state) {
|
||||
return AIR_MATERIALS.contains(state.material().toString());
|
||||
}
|
||||
|
||||
@@ -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