mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 00:34:19 +00:00
Merge lane B structures
This commit is contained in:
commit
b08d181823
68 files changed
+2268
-319
No files matched your search
+7
-5
@@ -1,5 +1,7 @@
|
||||
package art.arcane.iris.nativegen;
|
||||
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureWater;
|
||||
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructurePalette;
|
||||
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureTerrainSettings;
|
||||
@@ -90,7 +92,7 @@ public class NativeStructurePostProcessorEncaseTest {
|
||||
.setHorizontalPadding(1)
|
||||
.setCeilingPadding(1)
|
||||
.setFloorPadding(1),
|
||||
null);
|
||||
null, StructureWater.DRY);
|
||||
|
||||
assertEquals(Blocks.DIRT.defaultBlockState(),
|
||||
state(blocks, bounds.minX(), bounds.minY(), bounds.minZ()));
|
||||
@@ -111,7 +113,7 @@ public class NativeStructurePostProcessorEncaseTest {
|
||||
NativeStructureTerrainIntegrator.integrateTerrain(
|
||||
world(blocks), bounds, "minecraft:stronghold", start,
|
||||
new IrisStructureTerrain().setMode(StructureTerrainMode.ENCASE),
|
||||
null);
|
||||
null, StructureWater.DRY);
|
||||
|
||||
assertEquals(-1, bounds.minY());
|
||||
assertEquals(Blocks.DEEPSLATE.defaultBlockState(),
|
||||
@@ -222,7 +224,7 @@ public class NativeStructurePostProcessorEncaseTest {
|
||||
new IrisStructureTerrain()
|
||||
.setMode(StructureTerrainMode.ENCASE)
|
||||
.setEncasePalette(palette),
|
||||
NativeStructurePostProcessorEncaseTest::tuffBlock);
|
||||
NativeStructurePostProcessorEncaseTest::tuffBlock, StructureWater.DRY);
|
||||
|
||||
assertEquals(Blocks.TUFF.defaultBlockState(),
|
||||
state(blocks, bounds.minX(), bounds.minY(), bounds.minZ()));
|
||||
@@ -250,7 +252,7 @@ public class NativeStructurePostProcessorEncaseTest {
|
||||
|
||||
NativeStructureTerrainIntegrator.integrateTerrain(
|
||||
world(blocks), area, "test:bury", start,
|
||||
new IrisStructureTerrain().setMode(StructureTerrainMode.SOURCE), null);
|
||||
new IrisStructureTerrain().setMode(StructureTerrainMode.SOURCE), null, StructureWater.DRY);
|
||||
|
||||
assertEquals(Blocks.STONE.defaultBlockState(),
|
||||
state(blocks, bounds.minX() - 5, groundY, bounds.minZ()));
|
||||
@@ -277,7 +279,7 @@ public class NativeStructurePostProcessorEncaseTest {
|
||||
|
||||
NativeStructureTerrainIntegrator.integrateTerrain(
|
||||
world(blocks), area, "test:encapsulate", start,
|
||||
new IrisStructureTerrain().setMode(StructureTerrainMode.SOURCE), null);
|
||||
new IrisStructureTerrain().setMode(StructureTerrainMode.SOURCE), null, StructureWater.DRY);
|
||||
|
||||
assertEquals(Blocks.STONE.defaultBlockState(),
|
||||
state(blocks, bounds.minX() - 11, bounds.minY(), bounds.minZ()));
|
||||
|
||||
+12
-10
@@ -1,5 +1,7 @@
|
||||
package art.arcane.iris.nativegen;
|
||||
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureWater;
|
||||
|
||||
import art.arcane.volmlib.nativelib.minecraft26_2.terrain.NativeStructureVerticalPlacer;
|
||||
|
||||
import art.arcane.volmlib.nativelib.minecraft26_2.terrain.NativeStructureReferenceEnvelope;
|
||||
@@ -2185,7 +2187,7 @@ public class NativeStructurePostProcessorSurfaceTerrainTest {
|
||||
|
||||
NativeStructureTerrainIntegrator.integrateTerrain(
|
||||
world(blocks), bounds, "minecraft:desert_pyramid", start,
|
||||
new IrisStructureTerrain().setMode(StructureTerrainMode.VACUUM), null);
|
||||
new IrisStructureTerrain().setMode(StructureTerrainMode.VACUUM), null, StructureWater.DRY);
|
||||
|
||||
assertEquals(Blocks.STONE.defaultBlockState(),
|
||||
state(blocks, bounds.minX(), bounds.minY(), bounds.minZ()));
|
||||
@@ -2209,7 +2211,7 @@ public class NativeStructurePostProcessorSurfaceTerrainTest {
|
||||
new IrisStructureTerrain()
|
||||
.setMode(StructureTerrainMode.FORCE_CARVE)
|
||||
.setHorizontalPadding(1)
|
||||
.setCeilingPadding(1), null);
|
||||
.setCeilingPadding(1), null, StructureWater.DRY);
|
||||
|
||||
assertEquals(Blocks.AIR.defaultBlockState(),
|
||||
state(blocks, bounds.maxX() + 1, bounds.minY(), bounds.maxZ()));
|
||||
@@ -2241,7 +2243,7 @@ public class NativeStructurePostProcessorSurfaceTerrainTest {
|
||||
|
||||
NativeStructureTerrainIntegrator.integrateTerrain(
|
||||
world(blocks), area, "minecraft:ancient_city", start,
|
||||
new IrisStructureTerrain().setMode(StructureTerrainMode.FORCE_CARVE), null);
|
||||
new IrisStructureTerrain().setMode(StructureTerrainMode.FORCE_CARVE), null, StructureWater.DRY);
|
||||
|
||||
assertEquals(Blocks.AIR.defaultBlockState(),
|
||||
state(blocks, firstBounds.minX(), y, z));
|
||||
@@ -2382,7 +2384,7 @@ public class NativeStructurePostProcessorSurfaceTerrainTest {
|
||||
bounds.maxX() + 6, bounds.maxY() + 12, bounds.maxZ() + 6);
|
||||
Map<BlockPos, BlockState> blocks = fill(area);
|
||||
|
||||
NativeStructureTerrainIntegrator.carveOrganicColumns(world(blocks), area, carve);
|
||||
NativeStructureTerrainIntegrator.carveOrganicColumns(world(blocks), area, StructureWater.DRY, carve);
|
||||
|
||||
int centerX = bounds.minX() + bounds.getXSpan() / 2;
|
||||
int centerZ = bounds.minZ() + bounds.getZSpan() / 2;
|
||||
@@ -2407,9 +2409,9 @@ public class NativeStructurePostProcessorSurfaceTerrainTest {
|
||||
Map<BlockPos, BlockState> lobedBlocks = fill(area);
|
||||
|
||||
NativeStructureTerrainIntegrator.carveOrganicColumns(
|
||||
world(uniformBlocks), area, organicCarve(start, 10, 0D));
|
||||
world(uniformBlocks), area, StructureWater.DRY, organicCarve(start, 10, 0D));
|
||||
NativeStructureTerrainIntegrator.carveOrganicColumns(
|
||||
world(lobedBlocks), area, organicCarve(start, 10, 0.85D));
|
||||
world(lobedBlocks), area, StructureWater.DRY, organicCarve(start, 10, 0.85D));
|
||||
|
||||
int uniform = 0;
|
||||
int lobed = 0;
|
||||
@@ -2457,9 +2459,9 @@ public class NativeStructurePostProcessorSurfaceTerrainTest {
|
||||
|
||||
// Each chunk context rebuilds its own noise channels from the shared start identity.
|
||||
NativeStructureTerrainIntegrator.carveOrganicColumns(
|
||||
world(wideBlocks), wide, organicCarve(start, 6));
|
||||
world(wideBlocks), wide, StructureWater.DRY, organicCarve(start, 6));
|
||||
NativeStructureTerrainIntegrator.carveOrganicColumns(
|
||||
world(narrowBlocks), narrow, organicCarve(start, 6));
|
||||
world(narrowBlocks), narrow, StructureWater.DRY, organicCarve(start, 6));
|
||||
|
||||
int carved = 0;
|
||||
for (int x = narrow.minX(); x <= narrow.maxX(); x++) {
|
||||
@@ -2496,7 +2498,7 @@ public class NativeStructurePostProcessorSurfaceTerrainTest {
|
||||
.setCeilingPadding(8)
|
||||
.setFloorPadding(0)
|
||||
.setErosionStrength(1D)
|
||||
.setErosionFrequency(0.05D), null);
|
||||
.setErosionFrequency(0.05D), null, StructureWater.DRY);
|
||||
|
||||
assertEquals(Blocks.AIR.defaultBlockState(), state(blocks, centerX, bounds.minY(), centerZ));
|
||||
assertEquals(Blocks.STONE.defaultBlockState(),
|
||||
@@ -2814,7 +2816,7 @@ public class NativeStructurePostProcessorSurfaceTerrainTest {
|
||||
SLAB_WIDTH - 1 + SLAB_PADDING, transectY, SLAB_DEPTH - 1);
|
||||
Map<BlockPos, BlockState> blocks = fill(area);
|
||||
|
||||
NativeStructureTerrainIntegrator.carveOrganicColumns(world(blocks), area,
|
||||
NativeStructureTerrainIntegrator.carveOrganicColumns(world(blocks), area, StructureWater.DRY,
|
||||
NativeStructureTerrainIntegrator.organicCarve(
|
||||
footprint, terrain, StructureCarveShape.ERODED, TEST_SEED));
|
||||
|
||||
|
||||
+4
-2
@@ -1,5 +1,7 @@
|
||||
package art.arcane.iris.platform.bukkit.nms.v26_2_R1;
|
||||
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureWater;
|
||||
|
||||
import art.arcane.volmlib.nativelib.v26_2_R1.terrain.NativeStructureWorldgenAccess;
|
||||
|
||||
import art.arcane.iris.structure.placement.IrisStructureTerrain;
|
||||
@@ -94,13 +96,13 @@ public class NativeStructureWorldgenAccessTest {
|
||||
unbounded.rejectDistantTerrainReads = true;
|
||||
|
||||
assertThrows(IllegalStateException.class, () -> NativeStructurePostProcessor.prepareTerrain(
|
||||
unbounded.world(), area, targets, (palette, rng, x, y, z) -> Blocks.STONE.defaultBlockState()));
|
||||
unbounded.world(), area, targets, (palette, rng, x, y, z) -> Blocks.STONE.defaultBlockState(), StructureWater.DRY));
|
||||
|
||||
RecordingDelegate recording = new RecordingDelegate();
|
||||
recording.rejectDistantTerrainReads = true;
|
||||
NativeStructureWorldgenAccess access = access(recording);
|
||||
NativeStructurePostProcessor.prepareTerrain(
|
||||
access, area, targets, (palette, rng, x, y, z) -> Blocks.STONE.defaultBlockState());
|
||||
access, area, targets, (palette, rng, x, y, z) -> Blocks.STONE.defaultBlockState(), StructureWater.DRY);
|
||||
|
||||
assertEquals(0, recording.heightReads);
|
||||
assertEquals(0, recording.chunkReads);
|
||||
|
||||
+9
-1
@@ -1,6 +1,8 @@
|
||||
package art.arcane.iris.probe;
|
||||
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeGenerationScope;
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureWater;
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureWaterRules;
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureInjectionPolicy;
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureOwnershipRecordView;
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructurePlacementDecision;
|
||||
@@ -159,6 +161,11 @@ final class HeadlessStructurePlanner {
|
||||
policies.injection().discard(plan.structureKey(), chunk.getPos().x(), chunk.getPos().z());
|
||||
continue;
|
||||
}
|
||||
if (!StructureWaterRules.admitsStart(plan, policies.water(), NativeStructureTerrainIntegrator.pieceFootprints(generated))) {
|
||||
chunk.setStartForStructure(structure, StructureStart.INVALID_START);
|
||||
policies.injection().discard(plan.structureKey(), chunk.getPos().x(), chunk.getPos().z());
|
||||
continue;
|
||||
}
|
||||
BoundingBox envelope = NativeStructureReferenceEnvelope.referenceBounds(generated, structure,
|
||||
plan.terrain(), plan.structureKey());
|
||||
policies.injection().record(plan, NativeStructureOwnershipFingerprint.capture(plan.structureKey(), generated, envelope));
|
||||
@@ -319,11 +326,12 @@ final class HeadlessStructurePlanner {
|
||||
|
||||
record Policies<P extends StructureStartPlan, O extends StructureOwnershipRecordView<O>>(
|
||||
StructureInjectionPolicy<P> injection, StructureReferencePolicy<P, O> references,
|
||||
Predicate<BoundingBox> allowsFootprint) {
|
||||
Predicate<BoundingBox> allowsFootprint, StructureWater water) {
|
||||
Policies {
|
||||
Objects.requireNonNull(injection, "injection");
|
||||
Objects.requireNonNull(references, "references");
|
||||
Objects.requireNonNull(allowsFootprint, "allowsFootprint");
|
||||
Objects.requireNonNull(water, "water");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-1
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.probe;
|
||||
|
||||
import art.arcane.iris.structure.placement.IrisStructureWater;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.platform.bukkit.nms.BukkitBiomePolicy;
|
||||
import art.arcane.iris.structure.nativegen.IrisStructurePolicy;
|
||||
@@ -63,7 +64,8 @@ final class HeadlessTerrainContext implements AutoCloseable {
|
||||
IrisStructurePolicy policy = new IrisStructurePolicy(engine);
|
||||
policies = new HeadlessStructurePlanner.Policies<>(policy, policy,
|
||||
bounds -> engine.getComplex().allowsNewGenerationFootprint(
|
||||
bounds.minX(), bounds.minZ(), bounds.maxX(), bounds.maxZ()));
|
||||
bounds.minX(), bounds.minZ(), bounds.maxX(), bounds.maxZ()),
|
||||
IrisStructureWater.world(engine));
|
||||
NativeBiomeRegistryImpl registry = new NativeBiomeRegistryImpl(runtime.registries().lookupOrThrow(Registries.BIOME));
|
||||
biomes = new BukkitBiomePolicy<>(new BukkitBiomePolicy.RuntimeOptions<>(seed, engine, null, () -> registry), registry);
|
||||
serialization = new HeadlessChunkSerialization.Context(new StructurePieceSerializationContext(
|
||||
|
||||
+7
-5
@@ -1,5 +1,7 @@
|
||||
package art.arcane.iris.nativegen.v26_3_R1;
|
||||
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureWater;
|
||||
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructurePalette;
|
||||
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureTerrainSettings;
|
||||
@@ -90,7 +92,7 @@ public class NativeStructurePostProcessorEncaseTest {
|
||||
.setHorizontalPadding(1)
|
||||
.setCeilingPadding(1)
|
||||
.setFloorPadding(1),
|
||||
null);
|
||||
null, StructureWater.DRY);
|
||||
|
||||
assertEquals(Blocks.DIRT.defaultBlockState(),
|
||||
state(blocks, bounds.minX(), bounds.minY(), bounds.minZ()));
|
||||
@@ -111,7 +113,7 @@ public class NativeStructurePostProcessorEncaseTest {
|
||||
NativeStructureTerrainIntegrator.integrateTerrain(
|
||||
world(blocks), bounds, "minecraft:stronghold", start,
|
||||
new IrisStructureTerrain().setMode(StructureTerrainMode.ENCASE),
|
||||
null);
|
||||
null, StructureWater.DRY);
|
||||
|
||||
assertEquals(-1, bounds.minY());
|
||||
assertEquals(Blocks.DEEPSLATE.defaultBlockState(),
|
||||
@@ -222,7 +224,7 @@ public class NativeStructurePostProcessorEncaseTest {
|
||||
new IrisStructureTerrain()
|
||||
.setMode(StructureTerrainMode.ENCASE)
|
||||
.setEncasePalette(palette),
|
||||
NativeStructurePostProcessorEncaseTest::tuffBlock);
|
||||
NativeStructurePostProcessorEncaseTest::tuffBlock, StructureWater.DRY);
|
||||
|
||||
assertEquals(Blocks.TUFF.defaultBlockState(),
|
||||
state(blocks, bounds.minX(), bounds.minY(), bounds.minZ()));
|
||||
@@ -250,7 +252,7 @@ public class NativeStructurePostProcessorEncaseTest {
|
||||
|
||||
NativeStructureTerrainIntegrator.integrateTerrain(
|
||||
world(blocks), area, "test:bury", start,
|
||||
new IrisStructureTerrain().setMode(StructureTerrainMode.SOURCE), null);
|
||||
new IrisStructureTerrain().setMode(StructureTerrainMode.SOURCE), null, StructureWater.DRY);
|
||||
|
||||
assertEquals(Blocks.STONE.defaultBlockState(),
|
||||
state(blocks, bounds.minX() - 5, groundY, bounds.minZ()));
|
||||
@@ -277,7 +279,7 @@ public class NativeStructurePostProcessorEncaseTest {
|
||||
|
||||
NativeStructureTerrainIntegrator.integrateTerrain(
|
||||
world(blocks), area, "test:encapsulate", start,
|
||||
new IrisStructureTerrain().setMode(StructureTerrainMode.SOURCE), null);
|
||||
new IrisStructureTerrain().setMode(StructureTerrainMode.SOURCE), null, StructureWater.DRY);
|
||||
|
||||
assertEquals(Blocks.STONE.defaultBlockState(),
|
||||
state(blocks, bounds.minX() - 11, bounds.minY(), bounds.minZ()));
|
||||
|
||||
+12
-10
@@ -1,5 +1,7 @@
|
||||
package art.arcane.iris.nativegen.v26_3_R1;
|
||||
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureWater;
|
||||
|
||||
import art.arcane.volmlib.nativelib.v26_3_R1.terrain.NativeStructureVerticalPlacer;
|
||||
|
||||
import art.arcane.volmlib.nativelib.v26_3_R1.terrain.NativeStructureReferenceEnvelope;
|
||||
@@ -2185,7 +2187,7 @@ public class NativeStructurePostProcessorSurfaceTerrainTest {
|
||||
|
||||
NativeStructureTerrainIntegrator.integrateTerrain(
|
||||
world(blocks), bounds, "minecraft:desert_pyramid", start,
|
||||
new IrisStructureTerrain().setMode(StructureTerrainMode.VACUUM), null);
|
||||
new IrisStructureTerrain().setMode(StructureTerrainMode.VACUUM), null, StructureWater.DRY);
|
||||
|
||||
assertEquals(Blocks.STONE.defaultBlockState(),
|
||||
state(blocks, bounds.minX(), bounds.minY(), bounds.minZ()));
|
||||
@@ -2209,7 +2211,7 @@ public class NativeStructurePostProcessorSurfaceTerrainTest {
|
||||
new IrisStructureTerrain()
|
||||
.setMode(StructureTerrainMode.FORCE_CARVE)
|
||||
.setHorizontalPadding(1)
|
||||
.setCeilingPadding(1), null);
|
||||
.setCeilingPadding(1), null, StructureWater.DRY);
|
||||
|
||||
assertEquals(Blocks.AIR.defaultBlockState(),
|
||||
state(blocks, bounds.maxX() + 1, bounds.minY(), bounds.maxZ()));
|
||||
@@ -2241,7 +2243,7 @@ public class NativeStructurePostProcessorSurfaceTerrainTest {
|
||||
|
||||
NativeStructureTerrainIntegrator.integrateTerrain(
|
||||
world(blocks), area, "minecraft:ancient_city", start,
|
||||
new IrisStructureTerrain().setMode(StructureTerrainMode.FORCE_CARVE), null);
|
||||
new IrisStructureTerrain().setMode(StructureTerrainMode.FORCE_CARVE), null, StructureWater.DRY);
|
||||
|
||||
assertEquals(Blocks.AIR.defaultBlockState(),
|
||||
state(blocks, firstBounds.minX(), y, z));
|
||||
@@ -2382,7 +2384,7 @@ public class NativeStructurePostProcessorSurfaceTerrainTest {
|
||||
bounds.maxX() + 6, bounds.maxY() + 12, bounds.maxZ() + 6);
|
||||
Map<BlockPos, BlockState> blocks = fill(area);
|
||||
|
||||
NativeStructureTerrainIntegrator.carveOrganicColumns(world(blocks), area, carve);
|
||||
NativeStructureTerrainIntegrator.carveOrganicColumns(world(blocks), area, StructureWater.DRY, carve);
|
||||
|
||||
int centerX = bounds.minX() + bounds.getXSpan() / 2;
|
||||
int centerZ = bounds.minZ() + bounds.getZSpan() / 2;
|
||||
@@ -2407,9 +2409,9 @@ public class NativeStructurePostProcessorSurfaceTerrainTest {
|
||||
Map<BlockPos, BlockState> lobedBlocks = fill(area);
|
||||
|
||||
NativeStructureTerrainIntegrator.carveOrganicColumns(
|
||||
world(uniformBlocks), area, organicCarve(start, 10, 0D));
|
||||
world(uniformBlocks), area, StructureWater.DRY, organicCarve(start, 10, 0D));
|
||||
NativeStructureTerrainIntegrator.carveOrganicColumns(
|
||||
world(lobedBlocks), area, organicCarve(start, 10, 0.85D));
|
||||
world(lobedBlocks), area, StructureWater.DRY, organicCarve(start, 10, 0.85D));
|
||||
|
||||
int uniform = 0;
|
||||
int lobed = 0;
|
||||
@@ -2457,9 +2459,9 @@ public class NativeStructurePostProcessorSurfaceTerrainTest {
|
||||
|
||||
// Each chunk context rebuilds its own noise channels from the shared start identity.
|
||||
NativeStructureTerrainIntegrator.carveOrganicColumns(
|
||||
world(wideBlocks), wide, organicCarve(start, 6));
|
||||
world(wideBlocks), wide, StructureWater.DRY, organicCarve(start, 6));
|
||||
NativeStructureTerrainIntegrator.carveOrganicColumns(
|
||||
world(narrowBlocks), narrow, organicCarve(start, 6));
|
||||
world(narrowBlocks), narrow, StructureWater.DRY, organicCarve(start, 6));
|
||||
|
||||
int carved = 0;
|
||||
for (int x = narrow.minX(); x <= narrow.maxX(); x++) {
|
||||
@@ -2496,7 +2498,7 @@ public class NativeStructurePostProcessorSurfaceTerrainTest {
|
||||
.setCeilingPadding(8)
|
||||
.setFloorPadding(0)
|
||||
.setErosionStrength(1D)
|
||||
.setErosionFrequency(0.05D), null);
|
||||
.setErosionFrequency(0.05D), null, StructureWater.DRY);
|
||||
|
||||
assertEquals(Blocks.AIR.defaultBlockState(), state(blocks, centerX, bounds.minY(), centerZ));
|
||||
assertEquals(Blocks.STONE.defaultBlockState(),
|
||||
@@ -2814,7 +2816,7 @@ public class NativeStructurePostProcessorSurfaceTerrainTest {
|
||||
SLAB_WIDTH - 1 + SLAB_PADDING, transectY, SLAB_DEPTH - 1);
|
||||
Map<BlockPos, BlockState> blocks = fill(area);
|
||||
|
||||
NativeStructureTerrainIntegrator.carveOrganicColumns(world(blocks), area,
|
||||
NativeStructureTerrainIntegrator.carveOrganicColumns(world(blocks), area, StructureWater.DRY,
|
||||
NativeStructureTerrainIntegrator.organicCarve(
|
||||
footprint, terrain, StructureCarveShape.ERODED, TEST_SEED));
|
||||
|
||||
|
||||
+4
-2
@@ -1,5 +1,7 @@
|
||||
package art.arcane.iris.platform.bukkit.nms.v26_3_R1;
|
||||
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureWater;
|
||||
|
||||
import art.arcane.volmlib.nativelib.v26_3_R1.terrain.NativeStructureWorldgenAccess;
|
||||
|
||||
import art.arcane.iris.structure.placement.IrisStructureTerrain;
|
||||
@@ -94,13 +96,13 @@ public class NativeStructureWorldgenAccessTest {
|
||||
unbounded.rejectDistantTerrainReads = true;
|
||||
|
||||
assertThrows(IllegalStateException.class, () -> NativeStructurePostProcessor.prepareTerrain(
|
||||
unbounded.world(), area, targets, (palette, rng, x, y, z) -> Blocks.STONE.defaultBlockState()));
|
||||
unbounded.world(), area, targets, (palette, rng, x, y, z) -> Blocks.STONE.defaultBlockState(), StructureWater.DRY));
|
||||
|
||||
RecordingDelegate recording = new RecordingDelegate();
|
||||
recording.rejectDistantTerrainReads = true;
|
||||
NativeStructureWorldgenAccess access = access(recording);
|
||||
NativeStructurePostProcessor.prepareTerrain(
|
||||
access, area, targets, (palette, rng, x, y, z) -> Blocks.STONE.defaultBlockState());
|
||||
access, area, targets, (palette, rng, x, y, z) -> Blocks.STONE.defaultBlockState(), StructureWater.DRY);
|
||||
|
||||
assertEquals(0, recording.heightReads);
|
||||
assertEquals(0, recording.chunkReads);
|
||||
|
||||
+4
-2
@@ -1,5 +1,7 @@
|
||||
package art.arcane.iris.probe;
|
||||
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureWater;
|
||||
|
||||
import art.arcane.iris.structure.nativegen.IrisNativeStructure;
|
||||
import art.arcane.iris.structure.nativegen.IrisNativeStructureDecision;
|
||||
import art.arcane.iris.structure.nativegen.NativeStructureGenerationStatus;
|
||||
@@ -215,7 +217,7 @@ public class HeadlessStructurePlannerTest {
|
||||
new IrisNativeStructure().setStructure("probe:hut"), -1, 0, 30);
|
||||
TestPolicy policy = new TestPolicy(plan);
|
||||
HeadlessStructurePlanner.Policies<NativeStructureStartPlan, NativeStructureOwnershipRecord> policies =
|
||||
new HeadlessStructurePlanner.Policies<>(policy, policy, footprint -> true);
|
||||
new HeadlessStructurePlanner.Policies<>(policy, policy, footprint -> true, StructureWater.DRY);
|
||||
try (MultiPackResourceManager resources = resources();
|
||||
LevelStorageSource.LevelStorageAccess storage = LevelStorageSource.createDefault(temporary.newFolder().toPath()).createAccess("world")) {
|
||||
StructureTemplateManager templates = new StructureTemplateManager(resources, storage,
|
||||
@@ -249,7 +251,7 @@ public class HeadlessStructurePlannerTest {
|
||||
assertTrue(target.chunk().getAllReferences().get(hut.value()).contains(new ChunkPos(-1, 0).pack()));
|
||||
assertEquals(ChunkStatus.STRUCTURE_REFERENCES, target.chunk().getPersistedStatus());
|
||||
HeadlessStructurePlanner.Policies<NativeStructureStartPlan, NativeStructureOwnershipRecord> excluded =
|
||||
new HeadlessStructurePlanner.Policies<>(policy, policy, footprint -> false);
|
||||
new HeadlessStructurePlanner.Policies<>(policy, policy, footprint -> false, StructureWater.DRY);
|
||||
HeadlessStructurePlanner.PlannedChunk<NativeStructureOwnershipRecord> rejected = HeadlessStructurePlanner.plan(
|
||||
context, excluded, new ChunkPos(-1, 0));
|
||||
assertFalse(rejected.chunk().getStartForStructure(hut.value()).isValid());
|
||||
|
||||
@@ -24,6 +24,7 @@ import art.arcane.iris.structure.BulkStructureImporter;
|
||||
import art.arcane.iris.structure.StructureCaptureImporter;
|
||||
import art.arcane.iris.structure.StructureImporter;
|
||||
import art.arcane.iris.structure.StructureIndexService;
|
||||
import art.arcane.iris.studio.object.ObjectSVC;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.structure.placement.IrisStructureLocator;
|
||||
import art.arcane.iris.structure.nativegen.NativeStructureGenerationPolicy;
|
||||
@@ -368,6 +369,7 @@ public class CommandStructure implements DirectorExecutor {
|
||||
}
|
||||
p.getObject().place(p.getX(), p.getY(), p.getZ(), placer, config, rng, null, null, data);
|
||||
}
|
||||
J.runGlobal(() -> Iris.service(ObjectSVC.class).addChanges(future));
|
||||
int blockChanges = 0;
|
||||
for (Map.Entry<Block, BlockData> entry : future.entrySet()) {
|
||||
if (!entry.getKey().getBlockData().equals(entry.getValue())) {
|
||||
|
||||
+7
@@ -12,6 +12,7 @@ import art.arcane.iris.structure.nativegen.NativeStructureStartPlan;
|
||||
import art.arcane.iris.structure.nativegen.NativeStructureVolumeIndex;
|
||||
import art.arcane.iris.structure.nativegen.StructureLocateSearch;
|
||||
import art.arcane.iris.structure.placement.IrisStructureLocator;
|
||||
import art.arcane.iris.structure.placement.IrisStructureWater;
|
||||
import art.arcane.volmlib.nativelib.minecraft26_2.modded.NativeModdedStructureStage;
|
||||
import art.arcane.volmlib.nativelib.minecraft26_2.terrain.NativeStructureVolumeSource;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockChangeSet;
|
||||
@@ -23,6 +24,7 @@ import art.arcane.volmlib.nativelib.terrain.structure.StructurePlacementDecision
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureReferencePolicy;
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureSeaSurface;
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureVolumePolicy;
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureWater;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -130,6 +132,11 @@ final class ModdedNativeStructurePolicy implements NativeModdedStructureStage.Po
|
||||
return GenerationWritePolicy.seaSurface(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StructureWater water(Engine context) {
|
||||
return IrisStructureWater.world(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IntBinaryOperator worldgenHeight(Engine context, int runtimeMinY, boolean floor) {
|
||||
return (x, z) -> Engine.hostHeight(context, x, z, floor) + runtimeMinY + 1;
|
||||
|
||||
+4
-2
@@ -1,5 +1,7 @@
|
||||
package art.arcane.iris.modded;
|
||||
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureWater;
|
||||
|
||||
import art.arcane.volmlib.nativelib.minecraft26_2.modded.ModdedNativeStructureWorldgenAccess;
|
||||
|
||||
import art.arcane.iris.structure.placement.IrisStructureTerrain;
|
||||
@@ -94,13 +96,13 @@ public class ModdedNativeStructureWorldgenAccessTest {
|
||||
unbounded.rejectDistantTerrainReads = true;
|
||||
|
||||
assertThrows(IllegalStateException.class, () -> NativeStructurePostProcessor.prepareTerrain(
|
||||
unbounded.world(), area, targets, (palette, rng, x, y, z) -> Blocks.STONE.defaultBlockState()));
|
||||
unbounded.world(), area, targets, (palette, rng, x, y, z) -> Blocks.STONE.defaultBlockState(), StructureWater.DRY));
|
||||
|
||||
RecordingDelegate recording = new RecordingDelegate();
|
||||
recording.rejectDistantTerrainReads = true;
|
||||
ModdedNativeStructureWorldgenAccess access = access(recording);
|
||||
NativeStructurePostProcessor.prepareTerrain(
|
||||
access, area, targets, (palette, rng, x, y, z) -> Blocks.STONE.defaultBlockState());
|
||||
access, area, targets, (palette, rng, x, y, z) -> Blocks.STONE.defaultBlockState(), StructureWater.DRY);
|
||||
|
||||
assertEquals(0, recording.heightReads);
|
||||
assertEquals(0, recording.chunkReads);
|
||||
|
||||
+22
-3
@@ -35,6 +35,7 @@ import java.util.function.Supplier;
|
||||
import java.util.Objects;
|
||||
import art.arcane.volmlib.util.matter.IrisMatter;
|
||||
import art.arcane.volmlib.util.matter.Matter;
|
||||
import art.arcane.volmlib.util.matter.MatterCavern;
|
||||
import art.arcane.iris.world.storage.matter.IrisMatterSupport;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -43,14 +44,18 @@ final class FloatingObjectPlacementTransaction implements IObjectPlacer {
|
||||
private final ObjectContinuationBundle.PlacementKey placementKey;
|
||||
private final KList<BufferedMutation> mutations;
|
||||
private final Map<PositionKey, NativeBlockState> bufferedBlocks;
|
||||
private final boolean entersWater;
|
||||
private ObjectHydrologyVeto waterVeto;
|
||||
private int blockWrites;
|
||||
private BlockPosition canopyPosition;
|
||||
|
||||
FloatingObjectPlacementTransaction(IObjectPlacer delegate, ObjectContinuationBundle.PlacementKey placementKey) {
|
||||
FloatingObjectPlacementTransaction(IObjectPlacer delegate, ObjectContinuationBundle.PlacementKey placementKey,
|
||||
boolean entersWater) {
|
||||
this.delegate = Objects.requireNonNull(delegate);
|
||||
this.placementKey = Objects.requireNonNull(placementKey);
|
||||
this.mutations = new KList<>();
|
||||
this.bufferedBlocks = new HashMap<>();
|
||||
this.entersWater = entersWater;
|
||||
}
|
||||
|
||||
CommitResult commit() {
|
||||
@@ -156,7 +161,7 @@ final class FloatingObjectPlacementTransaction implements IObjectPlacer {
|
||||
|
||||
@Override
|
||||
public void set(int x, int y, int z, NativeBlockState state) {
|
||||
if (state == null) {
|
||||
if (state == null || waterVeto().keepsBlock(x, y, z, state, entersWater)) {
|
||||
return;
|
||||
}
|
||||
mutations.add(new BlockMutation(x, y, z, state, isCanopy(x, y, z)));
|
||||
@@ -234,7 +239,7 @@ final class FloatingObjectPlacementTransaction implements IObjectPlacer {
|
||||
|
||||
@Override
|
||||
public <T> void setData(int x, int y, int z, T data) {
|
||||
if (data == null) {
|
||||
if (data == null || keepsWater(x, y, z, data)) {
|
||||
return;
|
||||
}
|
||||
mutations.add(new DataMutation(x, y, z, data, isCanopy(x, y, z)));
|
||||
@@ -244,6 +249,20 @@ final class FloatingObjectPlacementTransaction implements IObjectPlacer {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean keepsWater(int x, int y, int z, Object data) {
|
||||
if (data instanceof NativeBlockState state) {
|
||||
return waterVeto().keepsBlock(x, y, z, state, entersWater);
|
||||
}
|
||||
return data instanceof MatterCavern && waterVeto().keeps(x, y, z, false, entersWater);
|
||||
}
|
||||
|
||||
private ObjectHydrologyVeto waterVeto() {
|
||||
if (waterVeto == null) {
|
||||
waterVeto = ObjectHydrologyVeto.of(delegate.getEngine());
|
||||
}
|
||||
return waterVeto;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> @Nullable T getData(int x, int y, int z, Class<T> type) {
|
||||
for (int i = mutations.size() - 1; i >= 0; i--) {
|
||||
|
||||
@@ -22,11 +22,14 @@ import art.arcane.volmlib.util.structure.StructureCarvingFootprint;
|
||||
|
||||
import art.arcane.volmlib.util.structure.StructureCarveEnvelope;
|
||||
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureWaterRules;
|
||||
|
||||
import art.arcane.iris.configuration.IrisSettings;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.generation.cache.Cache;
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
import art.arcane.iris.structure.placement.IrisStructureLocator;
|
||||
import art.arcane.iris.structure.placement.IrisStructureWater;
|
||||
import art.arcane.iris.structure.placement.PlacedStructurePiece;
|
||||
import art.arcane.iris.structure.placement.StructurePlacementScope;
|
||||
import art.arcane.iris.structure.placement.StructurePlacementMarker;
|
||||
@@ -58,6 +61,7 @@ import art.arcane.volmlib.util.matter.Matter;
|
||||
import art.arcane.volmlib.util.matter.MatterCavern;
|
||||
import art.arcane.volmlib.util.matter.MatterStructurePOI;
|
||||
import art.arcane.volmlib.util.mantle.flag.ReservedFlag;
|
||||
import art.arcane.volmlib.util.math.BlockPosition;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import it.unimi.dsi.fastutil.longs.Long2IntMap;
|
||||
import it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap;
|
||||
@@ -65,6 +69,7 @@ import it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
@ComponentFlag(ReservedFlag.JIGSAW)
|
||||
public class IrisStructureComponent extends IrisMantleComponent {
|
||||
@@ -145,51 +150,51 @@ public class IrisStructureComponent extends IrisMantleComponent {
|
||||
+ " is not implemented for structure '" + key + "'");
|
||||
}
|
||||
|
||||
ObjectPlaceMode mode = structure.getPlaceMode();
|
||||
int failedPieces = 0;
|
||||
IrisStructureStiltSettings stilt = placement.getStilt();
|
||||
Long2IntOpenHashMap foundationColumns = stilt == null
|
||||
? null : new Long2IntOpenHashMap();
|
||||
boolean supportNonOccluding = stilt != null && stilt.isSupportNonOccluding();
|
||||
if (placement.isAnchoredUnderground()) {
|
||||
ObjectPlaceMode undergroundMode = (mode == ObjectPlaceMode.ORGANIC_STILT || mode == ObjectPlaceMode.CEILING_HANG)
|
||||
? mode : ObjectPlaceMode.STRUCTURE_PIECE;
|
||||
for (PlacedStructurePiece p : pieces) {
|
||||
if (placeObject(writer, structure, p, undergroundMode, p.getY(), rng,
|
||||
foundationColumns, supportNonOccluding) == -1) {
|
||||
failedPieces++;
|
||||
}
|
||||
}
|
||||
} else if (mode == ObjectPlaceMode.STRUCTURE_PIECE || mode == ObjectPlaceMode.FLOATING) {
|
||||
for (PlacedStructurePiece p : pieces) {
|
||||
if (placeObject(writer, structure, p, ObjectPlaceMode.STRUCTURE_PIECE, p.getY(), rng,
|
||||
foundationColumns, supportNonOccluding) == -1) {
|
||||
failedPieces++;
|
||||
}
|
||||
}
|
||||
} else if (pieces.size() == 1) {
|
||||
if (placeObject(writer, structure, pieces.getFirst(), mode, -1, rng,
|
||||
foundationColumns, supportNonOccluding) == -1) {
|
||||
failedPieces++;
|
||||
}
|
||||
} else {
|
||||
for (PlacedStructurePiece p : pieces) {
|
||||
if (placeObject(writer, structure, p, ObjectPlaceMode.STRUCTURE_PIECE, p.getY(), rng,
|
||||
foundationColumns, supportNonOccluding) == -1) {
|
||||
failedPieces++;
|
||||
}
|
||||
}
|
||||
}
|
||||
int failedPieces = placePieces(writer, placement, structure, pieces, rng);
|
||||
requireAppliedPieces(resolved, cx, cz, failedPieces);
|
||||
if (failedPieces == 0 && stilt != null) {
|
||||
placeFoundation(writer, foundationColumns, stilt, rng, !placement.isAnchoredUnderground());
|
||||
}
|
||||
if (failedPieces == 0) {
|
||||
capture.commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int placePieces(MantleWriter writer, IrisStructurePlacement placement, IrisStructure structure,
|
||||
KList<PlacedStructurePiece> pieces, RNG rng) {
|
||||
IrisStructureStiltSettings stilt = placement.getStilt();
|
||||
PieceRun run = new PieceRun(structure, rng, stilt == null ? null : new Long2IntOpenHashMap(),
|
||||
stilt != null && stilt.isSupportNonOccluding(), placement.isAllowWater());
|
||||
ObjectPlaceMode mode = structure.getPlaceMode();
|
||||
int failedPieces = 0;
|
||||
int water = writer.beginObjectPlacement(run.allowWater());
|
||||
try {
|
||||
if (placement.isAnchoredUnderground()) {
|
||||
ObjectPlaceMode undergroundMode = (mode == ObjectPlaceMode.ORGANIC_STILT || mode == ObjectPlaceMode.CEILING_HANG)
|
||||
? mode : ObjectPlaceMode.STRUCTURE_PIECE;
|
||||
for (PlacedStructurePiece p : pieces) {
|
||||
if (placeObject(writer, run, p, undergroundMode, false) == -1) {
|
||||
failedPieces++;
|
||||
}
|
||||
}
|
||||
} else if (pieces.size() == 1 && mode != ObjectPlaceMode.STRUCTURE_PIECE && mode != ObjectPlaceMode.FLOATING) {
|
||||
if (placeObject(writer, run, pieces.getFirst(), mode, true) == -1) {
|
||||
failedPieces++;
|
||||
}
|
||||
} else {
|
||||
for (PlacedStructurePiece p : pieces) {
|
||||
if (placeObject(writer, run, p, ObjectPlaceMode.STRUCTURE_PIECE, false) == -1) {
|
||||
failedPieces++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (failedPieces == 0 && stilt != null) {
|
||||
placeFoundation(writer, run.foundationColumns(), stilt, rng, !placement.isAnchoredUnderground());
|
||||
}
|
||||
} finally {
|
||||
writer.endObjectPlacement(water);
|
||||
}
|
||||
return failedPieces;
|
||||
}
|
||||
|
||||
private void placeFoundation(MantleWriter writer, Long2IntOpenHashMap columns,
|
||||
IrisStructureStiltSettings settings, RNG rng,
|
||||
boolean surfaceStructure) {
|
||||
@@ -268,8 +273,8 @@ public class IrisStructureComponent extends IrisMantleComponent {
|
||||
+ " assembled piece(s)");
|
||||
}
|
||||
|
||||
private void boreStructure(MantleWriter writer, KList<PlacedStructurePiece> pieces,
|
||||
IrisStructureTerrain terrain) {
|
||||
void boreStructure(MantleWriter writer, KList<PlacedStructurePiece> pieces,
|
||||
IrisStructureTerrain terrain) {
|
||||
int[] bounds = computePieceBounds(pieces);
|
||||
if (bounds == null) {
|
||||
return;
|
||||
@@ -289,17 +294,11 @@ public class IrisStructureComponent extends IrisMantleComponent {
|
||||
return;
|
||||
}
|
||||
int mantleOffset = getEngineMantle().getEngine().getMinHeight();
|
||||
for (int bx = minX; bx <= maxX; bx++) {
|
||||
for (int by = minY; by <= maxY; by++) {
|
||||
for (int bz = minZ; bz <= maxZ; bz++) {
|
||||
writer.setForcedCarve(bx, by - mantleOffset, bz, CARVE_CAVERN);
|
||||
}
|
||||
}
|
||||
}
|
||||
carveBox(writer, minX, minY, minZ, maxX, maxY, maxZ, mantleOffset);
|
||||
}
|
||||
|
||||
private void forceCarveStructure(MantleWriter writer, KList<PlacedStructurePiece> pieces,
|
||||
IrisStructureTerrain terrain) {
|
||||
void forceCarveStructure(MantleWriter writer, KList<PlacedStructurePiece> pieces,
|
||||
IrisStructureTerrain terrain) {
|
||||
int[] bounds = computePieceBounds(pieces);
|
||||
if (bounds == null) {
|
||||
return;
|
||||
@@ -342,6 +341,8 @@ public class IrisStructureComponent extends IrisMantleComponent {
|
||||
+ " margin=" + margin + " head=" + head + " floorCut=" + floorCut + " work=" + work);
|
||||
}
|
||||
|
||||
StructureWaterRules.Carve water = StructureWaterRules.carve(IrisStructureWater.mantle(getEngineMantle().getComplex()),
|
||||
footprint.minX(), footprint.minZ(), footprint.maxX(), footprint.maxZ());
|
||||
double sideReachSquared = (double) margin * margin;
|
||||
double downReach = Math.max(1D, floorCut);
|
||||
for (int bz = footprint.minZ(); bz <= footprint.maxZ(); bz++) {
|
||||
@@ -363,6 +364,9 @@ public class IrisStructureComponent extends IrisMantleComponent {
|
||||
int minY = Math.max(worldMin, sourceMinY - floorCut);
|
||||
int maxY = Math.min(worldMax, sourceMaxY + columnUpExtension);
|
||||
for (int by = minY; by <= maxY; by++) {
|
||||
if (water.keeps(bx, by - mantleOffset, bz)) {
|
||||
continue;
|
||||
}
|
||||
double normalizedY = StructureCarveEnvelope.normalizedVerticalDistance(
|
||||
by, sourceMinY, sourceMaxY, upReach, downReach);
|
||||
double distanceSquared = normalizedHorizontalDistanceSquared
|
||||
@@ -391,16 +395,20 @@ public class IrisStructureComponent extends IrisMantleComponent {
|
||||
|
||||
private void carveOverboreBox(MantleWriter writer, int[] bounds, int margin, int head, int floorCut,
|
||||
int mantleOffset, int worldMin, int worldMax) {
|
||||
int minX = bounds[0] - margin;
|
||||
int minY = Math.max(worldMin, bounds[1] - floorCut);
|
||||
int minZ = bounds[2] - margin;
|
||||
int maxX = bounds[3] + margin;
|
||||
int maxY = Math.min(worldMax, bounds[4] + head);
|
||||
int maxZ = bounds[5] + margin;
|
||||
carveBox(writer, bounds[0] - margin, Math.max(worldMin, bounds[1] - floorCut), bounds[2] - margin,
|
||||
bounds[3] + margin, Math.min(worldMax, bounds[4] + head), bounds[5] + margin, mantleOffset);
|
||||
}
|
||||
|
||||
private void carveBox(MantleWriter writer, int minX, int minY, int minZ, int maxX, int maxY, int maxZ, int mantleOffset) {
|
||||
StructureWaterRules.Carve water = StructureWaterRules.carve(IrisStructureWater.mantle(getEngineMantle().getComplex()),
|
||||
minX, minZ, maxX, maxZ);
|
||||
for (int bx = minX; bx <= maxX; bx++) {
|
||||
for (int by = minY; by <= maxY; by++) {
|
||||
for (int bz = minZ; bz <= maxZ; bz++) {
|
||||
writer.setForcedCarve(bx, by - mantleOffset, bz, CARVE_CAVERN);
|
||||
for (int bz = minZ; bz <= maxZ; bz++) {
|
||||
for (int by = minY; by <= maxY; by++) {
|
||||
int mantleY = by - mantleOffset;
|
||||
if (!water.keeps(bx, mantleY, bz)) {
|
||||
writer.setForcedCarve(bx, mantleY, bz, CARVE_CAVERN);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -557,30 +565,38 @@ public class IrisStructureComponent extends IrisMantleComponent {
|
||||
return new int[]{minX, minY, minZ, maxX, maxY, maxZ};
|
||||
}
|
||||
|
||||
private int placeObject(MantleWriter writer, IrisStructure structure, PlacedStructurePiece p,
|
||||
ObjectPlaceMode mode, int y, RNG rng, Long2IntOpenHashMap foundationColumns,
|
||||
boolean supportNonOccluding) {
|
||||
private int placeObject(MantleWriter writer, PieceRun run, PlacedStructurePiece p, ObjectPlaceMode mode,
|
||||
boolean sampledHeight) {
|
||||
IrisObject object = p.getObject();
|
||||
String objectKey = object.getLoadKey();
|
||||
IrisObjectPlacement config = structure.createLootPlacement(objectKey);
|
||||
IrisObjectPlacement config = piecePlacement(run.structure(), p, mode, run.allowWater());
|
||||
String marker = structurePlacementMarker(run.structure(), p, objectKey);
|
||||
BiConsumer<BlockPosition, NativeBlockState> listener = (position, state) -> {
|
||||
StructureFoundationPlanner.recordBaseCell(
|
||||
run.foundationColumns(), position.getX(), position.getY(), position.getZ(), state,
|
||||
run.supportNonOccluding());
|
||||
if (marker != null && shouldWriteStructureMarker(state)) {
|
||||
writer.setData(position.getX(), position.getY(), position.getZ(), marker);
|
||||
}
|
||||
};
|
||||
return sampledHeight
|
||||
? object.place(p.getX(), p.getZ(), writer, config, run.rng(), listener, null, getData())
|
||||
: object.place(p.getX(), p.getY() - getEngineMantle().getEngine().getMinHeight(), p.getZ(), writer, config, run.rng(), listener, null, getData());
|
||||
}
|
||||
|
||||
static IrisObjectPlacement piecePlacement(IrisStructure structure, PlacedStructurePiece piece, ObjectPlaceMode mode,
|
||||
boolean allowWater) {
|
||||
IrisObjectPlacement config = structure.createLootPlacement(piece.getObject().getLoadKey());
|
||||
config.setMode(mode);
|
||||
config.setRotation(p.getRotation());
|
||||
config.setRotation(piece.getRotation());
|
||||
if (!structure.getEdit().isEmpty()) {
|
||||
config.setEdit(structure.getEdit());
|
||||
}
|
||||
if (mode != ObjectPlaceMode.STRUCTURE_PIECE && mode != ObjectPlaceMode.FLOATING) {
|
||||
config.setForcePlace(true);
|
||||
config.setForcedByStructure(!allowWater);
|
||||
}
|
||||
int placeY = (y == -1) ? -1 : y - getEngineMantle().getEngine().getMinHeight();
|
||||
String marker = structurePlacementMarker(structure, p, objectKey);
|
||||
return object.place(p.getX(), placeY, p.getZ(), writer, config, rng, (position, state) -> {
|
||||
StructureFoundationPlanner.recordBaseCell(
|
||||
foundationColumns, position.getX(), position.getY(), position.getZ(), state,
|
||||
supportNonOccluding);
|
||||
if (marker != null && shouldWriteStructureMarker(state)) {
|
||||
writer.setData(position.getX(), position.getY(), position.getZ(), marker);
|
||||
}
|
||||
}, null, getData());
|
||||
return config;
|
||||
}
|
||||
|
||||
static boolean shouldWriteStructureMarker(NativeBlockState state) {
|
||||
@@ -703,4 +719,8 @@ public class IrisStructureComponent extends IrisMantleComponent {
|
||||
|
||||
private record ObjectBlockPosition(int x, int y, int z) {
|
||||
}
|
||||
|
||||
private record PieceRun(IrisStructure structure, RNG rng, Long2IntOpenHashMap foundationColumns,
|
||||
boolean supportNonOccluding, boolean allowWater) {
|
||||
}
|
||||
}
|
||||
+6
-4
@@ -217,9 +217,9 @@ public class MantleFloatingObjectComponent extends IrisMantleComponent {
|
||||
int id = rng.i(0, Integer.MAX_VALUE);
|
||||
|
||||
FloatingObjectPlacementTransaction transaction = new FloatingObjectPlacementTransaction(
|
||||
writer, placements.next(minX >> 4, minZ >> 4));
|
||||
writer, placements.next(minX >> 4, minZ >> 4), placement.entersWater());
|
||||
try {
|
||||
int resultY = obj.place(xx, -1, zz, transaction, floatingPlacement, rng, (b, bd) -> {
|
||||
int resultY = obj.place(xx, zz, transaction, floatingPlacement, rng, (b, bd) -> {
|
||||
String marker = placementMarker(obj, id);
|
||||
if (marker != null && shouldWritePlacementMarker(transaction, bd, b.getX(), b.getY(), b.getZ())) {
|
||||
transaction.setData(b.getX(), b.getY(), b.getZ(), marker);
|
||||
@@ -311,7 +311,8 @@ public class MantleFloatingObjectComponent extends IrisMantleComponent {
|
||||
int yv = pickTopY + 1 - fp.getLowestSolidKeyY();
|
||||
|
||||
IslandObjectPlacer islandPlacer = IslandObjectPlacer.top(writer, sampleProvider, entry, pickTopY);
|
||||
FloatingObjectPlacementTransaction transaction = new FloatingObjectPlacementTransaction(islandPlacer, placements.next(minX >> 4, minZ >> 4));
|
||||
FloatingObjectPlacementTransaction transaction = new FloatingObjectPlacementTransaction(
|
||||
islandPlacer, placements.next(minX >> 4, minZ >> 4), placement.entersWater());
|
||||
int id = rng.i(0, Integer.MAX_VALUE);
|
||||
|
||||
try {
|
||||
@@ -424,7 +425,8 @@ public class MantleFloatingObjectComponent extends IrisMantleComponent {
|
||||
int yv = invertedBaseY(pickBottomY, fp, invertedRotation);
|
||||
|
||||
IslandObjectPlacer islandPlacer = IslandObjectPlacer.bottom(writer, sampleProvider, entry, pickBottomY);
|
||||
FloatingObjectPlacementTransaction transaction = new FloatingObjectPlacementTransaction(islandPlacer, placements.next(minX >> 4, minZ >> 4));
|
||||
FloatingObjectPlacementTransaction transaction = new FloatingObjectPlacementTransaction(
|
||||
islandPlacer, placements.next(minX >> 4, minZ >> 4), placement.entersWater());
|
||||
int id = rng.i(0, Integer.MAX_VALUE);
|
||||
|
||||
try {
|
||||
|
||||
@@ -751,7 +751,7 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
try {
|
||||
int placeResult = -1;
|
||||
CaveObjectPlacementTransaction.CommitResult commitResult = CaveObjectPlacementTransaction.CommitResult.EMPTY;
|
||||
int continuation = writer.beginObjectPlacement();
|
||||
int continuation = writer.beginObjectPlacement(placement.entersWater());
|
||||
if (carving) {
|
||||
int caveFloorY = caveAnchor.y();
|
||||
if (golden) {
|
||||
@@ -784,7 +784,7 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
continue;
|
||||
}
|
||||
String marker = placementMarker(variant, id, "procedural");
|
||||
placeResult = variant.place(xx, -1, zz, placer, placement, rng, (b, data) -> {
|
||||
placeResult = variant.place(xx, zz, placer, placement, rng, (b, data) -> {
|
||||
if (marker != null) {
|
||||
placer.setData(b.getX(), b.getY(), b.getZ(), marker);
|
||||
}
|
||||
@@ -1013,8 +1013,8 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
}
|
||||
try {
|
||||
String marker = placementMarker(v, id, "surface");
|
||||
int continuation = writer.beginObjectPlacement();
|
||||
int result = v.place(xx, -1, zz, placePlacer, effectivePlacement, rng, (b, data) -> {
|
||||
int continuation = writer.beginObjectPlacement(effectivePlacement.entersWater());
|
||||
int result = v.place(xx, zz, placePlacer, effectivePlacement, rng, (b, data) -> {
|
||||
if (marker != null) {
|
||||
writer.setData(b.getX(), b.getY(), b.getZ(), marker);
|
||||
}
|
||||
@@ -1198,7 +1198,7 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
IrisObjectPlacement effectivePlacement = resolveCavePlacement(objectPlacement, object, caveProfile);
|
||||
|
||||
try {
|
||||
int continuation = writer.beginObjectPlacement();
|
||||
int continuation = writer.beginObjectPlacement(effectivePlacement.entersWater());
|
||||
ContainedPlacementResult contained = placeContainedCaveObject(
|
||||
writer,
|
||||
object,
|
||||
@@ -1394,7 +1394,7 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
}
|
||||
boolean treePlacement = isTreePlacement(v, objectPlacement);
|
||||
String marker = placementMarker(v, id, "upper");
|
||||
int continuation = writer.beginObjectPlacement();
|
||||
int continuation = writer.beginObjectPlacement(placement.entersWater());
|
||||
int result = v.place(xx, anchorY, zz, writer, placement, rng, (b, data) -> {
|
||||
if (marker != null) {
|
||||
writer.setData(b.getX(), b.getY(), b.getZ(), marker);
|
||||
|
||||
@@ -90,6 +90,11 @@ public class MantleWriter implements ObjectPassPlacer, AutoCloseable {
|
||||
@Setter(AccessLevel.NONE)
|
||||
@EqualsAndHashCode.Exclude
|
||||
@ToString.Exclude
|
||||
private final ThreadLocal<ObjectWater> objectWater = new ThreadLocal<>();
|
||||
@Getter(AccessLevel.NONE)
|
||||
@Setter(AccessLevel.NONE)
|
||||
@EqualsAndHashCode.Exclude
|
||||
@ToString.Exclude
|
||||
private TerrainAccess terrainAccess;
|
||||
|
||||
public MantleWriter(EngineMantle engineMantle, Mantle<Matter> mantle, int x, int z, int radius, boolean multicore) {
|
||||
@@ -215,6 +220,28 @@ public class MantleWriter implements ObjectPassPlacer, AutoCloseable {
|
||||
return capture;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int beginObjectPlacement(boolean entersWater) {
|
||||
objectWater.set(new ObjectWater(ObjectHydrologyVeto.of(getEngine()), entersWater));
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endObjectPlacement(int checkpoint) {
|
||||
objectWater.remove();
|
||||
}
|
||||
|
||||
private boolean keepsWater(int x, int y, int z, Object value) {
|
||||
ObjectWater water = objectWater.get();
|
||||
if (water == null) {
|
||||
return false;
|
||||
}
|
||||
if (value instanceof NativeBlockState state) {
|
||||
return water.veto().keepsBlock(x, y, z, state, water.entersWater());
|
||||
}
|
||||
return value instanceof MatterCavern && water.veto().keeps(x, y, z, false, water.entersWater());
|
||||
}
|
||||
|
||||
private void recordObjectValue(int x, int y, int z, Class<?> type, Object value) {
|
||||
ObjectPlacementCapture capture = objectPlacementCapture.get();
|
||||
if (capture != null) {
|
||||
@@ -241,7 +268,7 @@ public class MantleWriter implements ObjectPassPlacer, AutoCloseable {
|
||||
MantleChunk<Matter> chunk = acquireChunk(cx, cz);
|
||||
if (chunk == null) return;
|
||||
|
||||
if (protectsSubterrainPlacement(x, y, z)) {
|
||||
if (protectsSubterrainPlacement(x, y, z) || keepsWater(x, y, z, t)) {
|
||||
return;
|
||||
}
|
||||
synchronized (chunk) {
|
||||
@@ -611,7 +638,7 @@ public class MantleWriter implements ObjectPassPlacer, AutoCloseable {
|
||||
}
|
||||
|
||||
MantleChunk<Matter> chunk = acquireChunk(x >> 4, z >> 4);
|
||||
if (chunk == null) {
|
||||
if (chunk == null || keepsWater(x, y, z, baseState)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1007,6 +1034,9 @@ public class MantleWriter implements ObjectPassPlacer, AutoCloseable {
|
||||
naturalOpening ? ALWAYS : NEVER, cavern ? ALWAYS : NEVER) ? (byte) 1 : 0;
|
||||
}
|
||||
|
||||
private record ObjectWater(ObjectHydrologyVeto veto, boolean entersWater) {
|
||||
}
|
||||
|
||||
public final class ObjectPlacementCapture implements AutoCloseable {
|
||||
private final ObjectContinuationBundle.PlacementKey key;
|
||||
private final Long2ObjectOpenHashMap<Matter> fragments = new Long2ObjectOpenHashMap<>();
|
||||
|
||||
@@ -9,6 +9,7 @@ import java.util.Objects;
|
||||
final class MutationLog {
|
||||
private static final byte CUSTOM = 1;
|
||||
private static final byte CANOPY = 2;
|
||||
private static final byte ENTERS_WATER = 4;
|
||||
|
||||
private int size;
|
||||
private int[] x = new int[32];
|
||||
@@ -29,16 +30,16 @@ final class MutationLog {
|
||||
throw new IllegalArgumentException("Object mutation type " + key.type().getName()
|
||||
+ " does not match its value " + value.getClass().getName());
|
||||
}
|
||||
log.add(key.x(), key.y(), key.z(), value, false, set.canopy());
|
||||
log.add(key.x(), key.y(), key.z(), value, false, set.canopy(), false);
|
||||
}
|
||||
case ObjectDestinationTransaction.CustomBlockMutation block -> log.add(key.x(), key.y(), key.z(),
|
||||
Objects.requireNonNull(block.state(), "custom block state"), true, block.canopy());
|
||||
Objects.requireNonNull(block.state(), "custom block state"), true, block.canopy(), false);
|
||||
}
|
||||
}
|
||||
return log;
|
||||
}
|
||||
|
||||
void add(int blockX, int blockY, int blockZ, Object value, boolean custom, boolean canopy) {
|
||||
void add(int blockX, int blockY, int blockZ, Object value, boolean custom, boolean canopy, boolean entersWater) {
|
||||
if (size == values.length) {
|
||||
int capacity = size * 2;
|
||||
x = Arrays.copyOf(x, capacity);
|
||||
@@ -51,7 +52,7 @@ final class MutationLog {
|
||||
y[size] = blockY;
|
||||
z[size] = blockZ;
|
||||
values[size] = value;
|
||||
flags[size] = (byte) ((custom ? CUSTOM : 0) | (canopy ? CANOPY : 0));
|
||||
flags[size] = (byte) ((custom ? CUSTOM : 0) | (canopy ? CANOPY : 0) | (entersWater ? ENTERS_WATER : 0));
|
||||
size++;
|
||||
}
|
||||
|
||||
@@ -83,6 +84,10 @@ final class MutationLog {
|
||||
return (flags[index] & CANOPY) != 0;
|
||||
}
|
||||
|
||||
boolean entersWater(int index) {
|
||||
return (flags[index] & ENTERS_WATER) != 0;
|
||||
}
|
||||
|
||||
Class<?> type(int index) {
|
||||
return custom(index) ? NativeBlockState.class : ObjectSourcePlan.typeOf(values[index]);
|
||||
}
|
||||
|
||||
+22
-80
@@ -5,10 +5,6 @@ import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.decoration.tree.TreeBlockMaterial;
|
||||
import art.arcane.iris.generation.hydrology.cave.HydrologyCaveCell;
|
||||
import art.arcane.iris.generation.hydrology.engine.HydrologyRuntime;
|
||||
import art.arcane.iris.generation.hydrology.raster.ChunkWaterRaster;
|
||||
import art.arcane.iris.generation.hydrology.raster.WaterRole;
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
import art.arcane.iris.generation.subterrain.SubterrainRasterizer;
|
||||
import art.arcane.iris.generation.block.TileData;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
@@ -30,7 +26,6 @@ import java.util.Map;
|
||||
|
||||
final class ObjectDestinationTransaction implements ObjectPassPlacer {
|
||||
private static final Object CLEARED = new Object();
|
||||
private static final int[][] SIDES = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
|
||||
|
||||
private final MantleWriter writer;
|
||||
private final int destinationChunkX;
|
||||
@@ -45,8 +40,8 @@ final class ObjectDestinationTransaction implements ObjectPassPlacer {
|
||||
private int subterrainY;
|
||||
private int subterrainZ;
|
||||
private boolean subterrainProtects;
|
||||
private boolean hydrologyKnown;
|
||||
private HydrologyRuntime hydrology;
|
||||
private ObjectHydrologyVeto waterVeto;
|
||||
private boolean waterPlacement;
|
||||
|
||||
ObjectDestinationTransaction(MantleWriter writer, int destinationChunkX, int destinationChunkZ) {
|
||||
this.writer = writer;
|
||||
@@ -78,12 +73,14 @@ final class ObjectDestinationTransaction implements ObjectPassPlacer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int beginObjectPlacement() {
|
||||
public int beginObjectPlacement(boolean entersWater) {
|
||||
waterPlacement = entersWater;
|
||||
return log.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endObjectPlacement(int checkpoint) {
|
||||
waterPlacement = false;
|
||||
if (checkpoint >= 0 && checkpoint < log.size()) {
|
||||
placements.add(new PlacementRange(checkpoint, log.size()));
|
||||
}
|
||||
@@ -106,6 +103,7 @@ final class ObjectDestinationTransaction implements ObjectPassPlacer {
|
||||
Object value = plan.valueAt(index);
|
||||
boolean custom = ObjectSourcePlan.isCustom(cell);
|
||||
boolean canopy = ObjectSourcePlan.isCanopy(cell);
|
||||
boolean entersWater = ObjectSourcePlan.entersWater(cell);
|
||||
if (custom || value instanceof NativeBlockState) {
|
||||
NativeBlockState existing = canopy ? get(x, y, z) : null;
|
||||
skipCanopy = existing != null && existing.isSolid();
|
||||
@@ -114,9 +112,9 @@ final class ObjectDestinationTransaction implements ObjectPassPlacer {
|
||||
continue;
|
||||
}
|
||||
if (custom) {
|
||||
set(x, y, z, (NativeBlockState) value, true, canopy);
|
||||
set(x, y, z, (NativeBlockState) value, canopy, entersWater);
|
||||
} else {
|
||||
setData(x, y, z, value, true, canopy);
|
||||
setData(x, y, z, value, canopy, entersWater);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -181,17 +179,17 @@ final class ObjectDestinationTransaction implements ObjectPassPlacer {
|
||||
|
||||
@Override
|
||||
public void set(int x, int y, int z, NativeBlockState state) {
|
||||
set(x, y, z, state, false, false);
|
||||
set(x, y, z, state, isCanopy(x, y, z), waterPlacement);
|
||||
}
|
||||
|
||||
private void set(int x, int y, int z, NativeBlockState state, boolean replayed, boolean replayedCanopy) {
|
||||
private void set(int x, int y, int z, NativeBlockState state, boolean canopy, boolean entersWater) {
|
||||
if (state == null) {
|
||||
return;
|
||||
}
|
||||
String placementKey = state.deferredPlacementKey();
|
||||
NativeBlockState baseState = state.placementBaseState();
|
||||
if (state.isCustom() && placementKey != null && baseState != null) {
|
||||
if (!canSetBlock(x, y, z) || hydrologyKeeps(x, y, z, baseState.isSolid())) {
|
||||
if (!canSetBlock(x, y, z) || hydrologyKeeps(x, y, z, baseState.isSolid(), entersWater)) {
|
||||
return;
|
||||
}
|
||||
Identifier identifier = Identifier.fromString(placementKey);
|
||||
@@ -199,10 +197,10 @@ final class ObjectDestinationTransaction implements ObjectPassPlacer {
|
||||
cell.block = baseState;
|
||||
cell.tile = CLEARED;
|
||||
cell.identifier = identifier;
|
||||
log.add(x, y, z, state, true, replayed ? replayedCanopy : isCanopy(x, y, z));
|
||||
log.add(x, y, z, state, true, canopy, entersWater);
|
||||
return;
|
||||
}
|
||||
setData(x, y, z, state);
|
||||
setData(x, y, z, state, canopy, entersWater);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -293,18 +291,18 @@ final class ObjectDestinationTransaction implements ObjectPassPlacer {
|
||||
|
||||
@Override
|
||||
public <T> void setData(int x, int y, int z, T data) {
|
||||
setData(x, y, z, data, false, false);
|
||||
setData(x, y, z, data, isCanopy(x, y, z), waterPlacement);
|
||||
}
|
||||
|
||||
private void setData(int x, int y, int z, Object data, boolean replayed, boolean replayedCanopy) {
|
||||
private void setData(int x, int y, int z, Object data, boolean canopy, boolean entersWater) {
|
||||
if (data == null || y < 0 || y >= worldHeight
|
||||
|| protectsSubterrain(x, y, z)) {
|
||||
return;
|
||||
}
|
||||
if (data instanceof NativeBlockState state && (!canSetBlock(x, y, z) || hydrologyKeeps(x, y, z, state.isSolid()))) {
|
||||
if (data instanceof NativeBlockState state && (!canSetBlock(x, y, z) || hydrologyKeeps(x, y, z, state.isSolid(), entersWater))) {
|
||||
return;
|
||||
}
|
||||
if (data instanceof MatterCavern && (hasProtectedHydrology(x, y, z) || hydrologyKeeps(x, y, z, false))) {
|
||||
if (data instanceof MatterCavern && (hasProtectedHydrology(x, y, z) || hydrologyKeeps(x, y, z, false, entersWater))) {
|
||||
return;
|
||||
}
|
||||
Class<?> type = data instanceof NativeBlockState ? NativeBlockState.class : data.getClass();
|
||||
@@ -316,7 +314,7 @@ final class ObjectDestinationTransaction implements ObjectPassPlacer {
|
||||
} else {
|
||||
cell.put(type, data);
|
||||
}
|
||||
log.add(x, y, z, data, false, replayed ? replayedCanopy : isCanopy(x, y, z));
|
||||
log.add(x, y, z, data, false, canopy, entersWater);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -413,67 +411,11 @@ final class ObjectDestinationTransaction implements ObjectPassPlacer {
|
||||
&& !protectsSubterrain(x, y, z);
|
||||
}
|
||||
|
||||
private boolean hydrologyKeeps(int x, int y, int z, boolean holdsWater) {
|
||||
HydrologyRuntime runtime = hydrology();
|
||||
if (runtime == null) {
|
||||
return false;
|
||||
private boolean hydrologyKeeps(int x, int y, int z, boolean solid, boolean entersWater) {
|
||||
if (waterVeto == null) {
|
||||
waterVeto = ObjectHydrologyVeto.of(getEngine());
|
||||
}
|
||||
ChunkWaterRaster raster = runtime.raster(x >> 4, z >> 4);
|
||||
if (raster.empty()) {
|
||||
return false;
|
||||
}
|
||||
WaterRole role = raster.role(x & 15, z & 15);
|
||||
if (role == WaterRole.INLET && y >= raster.waterHead(x & 15, z & 15) && y <= getEngine().getComplex().naturalTrueHeight(x, z)) {
|
||||
return true;
|
||||
}
|
||||
if (role.wet()) {
|
||||
int surface = raster.waterHead(x & 15, z & 15);
|
||||
int fallTop = highestHead(runtime, raster, x, z);
|
||||
if (fallTop > surface && y >= surface && y <= fallTop) {
|
||||
return true;
|
||||
}
|
||||
return !holdsWater && y >= raster.terrainHeight(x & 15, z & 15) && y <= surface;
|
||||
}
|
||||
if (holdsWater || role == WaterRole.NONE) {
|
||||
return false;
|
||||
}
|
||||
int head = Integer.MIN_VALUE;
|
||||
int bed = Integer.MAX_VALUE;
|
||||
for (int[] side : SIDES) {
|
||||
int nx = x + side[0];
|
||||
int nz = z + side[1];
|
||||
ChunkWaterRaster neighbour = neighbour(runtime, raster, x, z, nx, nz);
|
||||
if (neighbour.role(nx & 15, nz & 15).wet()) {
|
||||
head = Math.max(head, neighbour.waterHead(nx & 15, nz & 15));
|
||||
bed = Math.min(bed, neighbour.terrainHeight(nx & 15, nz & 15));
|
||||
}
|
||||
}
|
||||
return y > bed && y <= head;
|
||||
}
|
||||
|
||||
private static int highestHead(HydrologyRuntime runtime, ChunkWaterRaster raster, int x, int z) {
|
||||
int top = Integer.MIN_VALUE;
|
||||
for (int[] side : SIDES) {
|
||||
int nx = x + side[0];
|
||||
int nz = z + side[1];
|
||||
top = Math.max(top, neighbour(runtime, raster, x, z, nx, nz).waterHead(nx & 15, nz & 15));
|
||||
}
|
||||
return top;
|
||||
}
|
||||
|
||||
private static ChunkWaterRaster neighbour(HydrologyRuntime runtime, ChunkWaterRaster raster, int x, int z, int nx, int nz) {
|
||||
return (nx >> 4) == (x >> 4) && (nz >> 4) == (z >> 4) ? raster : runtime.raster(nx >> 4, nz >> 4);
|
||||
}
|
||||
|
||||
private HydrologyRuntime hydrology() {
|
||||
if (!hydrologyKnown) {
|
||||
Engine engine = getEngine();
|
||||
IrisComplex complex = engine == null ? null : engine.getComplex();
|
||||
HydrologyRuntime runtime = complex == null ? null : complex.getHydrologyRuntime();
|
||||
hydrology = runtime != null && runtime.enabled() ? runtime : null;
|
||||
hydrologyKnown = true;
|
||||
}
|
||||
return hydrology;
|
||||
return waterVeto.keeps(x, y, z, solid, entersWater);
|
||||
}
|
||||
|
||||
private boolean protectsSubterrain(int x, int y, int z) {
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
package art.arcane.iris.generation.mantle;
|
||||
|
||||
import art.arcane.iris.generation.hydrology.engine.HydrologyRuntime;
|
||||
import art.arcane.iris.generation.hydrology.raster.ChunkWaterRaster;
|
||||
import art.arcane.iris.generation.hydrology.raster.WaterRole;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
|
||||
final class ObjectHydrologyVeto {
|
||||
private static final int[][] SIDES = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
|
||||
private static final ObjectHydrologyVeto NONE = new ObjectHydrologyVeto(null, null);
|
||||
|
||||
private final IrisComplex complex;
|
||||
private final HydrologyRuntime runtime;
|
||||
|
||||
private ObjectHydrologyVeto(IrisComplex complex, HydrologyRuntime runtime) {
|
||||
this.complex = complex;
|
||||
this.runtime = runtime;
|
||||
}
|
||||
|
||||
static ObjectHydrologyVeto of(Engine engine) {
|
||||
IrisComplex complex = engine == null ? null : engine.getComplex();
|
||||
HydrologyRuntime runtime = complex == null ? null : complex.getHydrologyRuntime();
|
||||
return runtime != null && runtime.enabled() ? new ObjectHydrologyVeto(complex, runtime) : NONE;
|
||||
}
|
||||
|
||||
boolean keepsBlock(int x, int y, int z, NativeBlockState state, boolean entersWater) {
|
||||
NativeBlockState base = state.isCustom() && state.placementBaseState() != null ? state.placementBaseState() : state;
|
||||
return keeps(x, y, z, base.isSolid(), entersWater);
|
||||
}
|
||||
|
||||
boolean keeps(int x, int y, int z, boolean solid, boolean entersWater) {
|
||||
if (runtime == null) {
|
||||
return false;
|
||||
}
|
||||
ChunkWaterRaster raster = runtime.raster(x >> 4, z >> 4);
|
||||
if (raster.empty()) {
|
||||
return false;
|
||||
}
|
||||
WaterRole role = raster.role(x & 15, z & 15);
|
||||
if (role == WaterRole.INLET && y >= raster.waterHead(x & 15, z & 15) && y <= complex.naturalTrueHeight(x, z)) {
|
||||
return true;
|
||||
}
|
||||
if (solid && !entersWater && fillsWater(x, y, z)) {
|
||||
return true;
|
||||
}
|
||||
if (role.wet()) {
|
||||
int surface = raster.waterHead(x & 15, z & 15);
|
||||
int fallTop = highestHead(raster, x, z);
|
||||
if (fallTop > surface && y >= surface && y <= fallTop) {
|
||||
return true;
|
||||
}
|
||||
return !solid && y >= raster.terrainHeight(x & 15, z & 15) && y <= surface;
|
||||
}
|
||||
if (solid || role == WaterRole.NONE) {
|
||||
return false;
|
||||
}
|
||||
int head = Integer.MIN_VALUE;
|
||||
int bed = Integer.MAX_VALUE;
|
||||
for (int[] side : SIDES) {
|
||||
int nx = x + side[0];
|
||||
int nz = z + side[1];
|
||||
ChunkWaterRaster neighbour = neighbour(raster, x, z, nx, nz);
|
||||
if (neighbour.role(nx & 15, nz & 15).wet()) {
|
||||
head = Math.max(head, neighbour.waterHead(nx & 15, nz & 15));
|
||||
bed = Math.min(bed, neighbour.terrainHeight(nx & 15, nz & 15));
|
||||
}
|
||||
}
|
||||
return y > bed && y <= head;
|
||||
}
|
||||
|
||||
private boolean fillsWater(int x, int y, int z) {
|
||||
if (!complex.getWaterRoleStream().get(x, z).wet()) {
|
||||
return false;
|
||||
}
|
||||
return y > complex.getRoundedHeighteightStream().get(x, z)
|
||||
&& y <= (int) Math.round(complex.getWaterHeadStream().getDouble(x, z));
|
||||
}
|
||||
|
||||
private int highestHead(ChunkWaterRaster raster, int x, int z) {
|
||||
int top = Integer.MIN_VALUE;
|
||||
for (int[] side : SIDES) {
|
||||
int nx = x + side[0];
|
||||
int nz = z + side[1];
|
||||
top = Math.max(top, neighbour(raster, x, z, nx, nz).waterHead(nx & 15, nz & 15));
|
||||
}
|
||||
return top;
|
||||
}
|
||||
|
||||
private ChunkWaterRaster neighbour(ChunkWaterRaster raster, int x, int z, int nx, int nz) {
|
||||
return (nx >> 4) == (x >> 4) && (nz >> 4) == (z >> 4) ? raster : runtime.raster(nx >> 4, nz >> 4);
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ public interface ObjectPassPlacer extends IObjectPlacer {
|
||||
|
||||
byte[] getCarvedColumn(int x, int z, int height);
|
||||
|
||||
default int beginObjectPlacement() {
|
||||
default int beginObjectPlacement(boolean entersWater) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,8 @@ final class ObjectSourcePlan {
|
||||
private static final int UNKNOWN_PAYLOAD_BYTES = 256;
|
||||
private static final int CUSTOM_BIT = 1 << 8;
|
||||
private static final int CANOPY_BIT = 1 << 9;
|
||||
private static final int Y_SHIFT = 10;
|
||||
private static final int ENTERS_WATER_BIT = 1 << 10;
|
||||
private static final int Y_SHIFT = 11;
|
||||
private static final int MAXIMUM_Y = (1 << (31 - Y_SHIFT)) - 1;
|
||||
|
||||
private final long[] destinations;
|
||||
@@ -90,7 +91,7 @@ final class ObjectSourcePlan {
|
||||
throw new IllegalArgumentException("Object mutation height is outside the plan range: " + y);
|
||||
}
|
||||
cells[position] = (y << Y_SHIFT) | (log.custom(logged) ? CUSTOM_BIT : 0) | (log.canopy(logged) ? CANOPY_BIT : 0)
|
||||
| ((log.z(logged) & 15) << 4) | (log.x(logged) & 15);
|
||||
| (log.entersWater(logged) ? ENTERS_WATER_BIT : 0) | ((log.z(logged) & 15) << 4) | (log.x(logged) & 15);
|
||||
valueIndexes[position] = table.indexOf(log.value(logged));
|
||||
}
|
||||
values = table.values.toArray();
|
||||
@@ -241,6 +242,10 @@ final class ObjectSourcePlan {
|
||||
return (cell & CANOPY_BIT) != 0;
|
||||
}
|
||||
|
||||
static boolean entersWater(int cell) {
|
||||
return (cell & ENTERS_WATER_BIT) != 0;
|
||||
}
|
||||
|
||||
ObjectDestinationTransaction.Mutation mutationAt(int chunkX, int chunkZ, int index) {
|
||||
int cell = cells[index];
|
||||
int x = (chunkX << 4) | cellX(cell);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.generation.runtime;
|
||||
|
||||
import art.arcane.iris.generation.stream.ProvisionalAnswerException;
|
||||
import art.arcane.iris.world.history.SavedBiomeUnavailableException;
|
||||
import art.arcane.volmlib.util.mantle.MantleClosedException;
|
||||
|
||||
@@ -25,6 +26,7 @@ public final class GenerationFailures {
|
||||
public static boolean isEngineFailure(Throwable failure) {
|
||||
return isShutdownFailure(failure) || hasCause(failure, (Throwable cause) -> cause instanceof Error
|
||||
|| cause instanceof WrongEngineBroException
|
||||
|| cause instanceof ProvisionalAnswerException
|
||||
|| cause instanceof SavedBiomeUnavailableException unavailable && unavailable.isLoading()
|
||||
|| cause instanceof TimeoutException);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package art.arcane.iris.generation.stream;
|
||||
|
||||
public final class ProvisionalAnswerException extends IllegalStateException {
|
||||
public ProvisionalAnswerException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import art.arcane.iris.structure.nativegen.NativeStructureStartPlan;
|
||||
import art.arcane.iris.structure.nativegen.NativeStructureVolumeIndex;
|
||||
import art.arcane.iris.structure.nativegen.StructureLocateSearch;
|
||||
import art.arcane.iris.structure.placement.IrisStructureLocator;
|
||||
import art.arcane.iris.structure.placement.IrisStructureWater;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockChangeSet;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockPositionPredicate;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
@@ -23,6 +24,7 @@ import art.arcane.volmlib.nativelib.terrain.structure.StructurePlacementDecision
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureReferencePolicy;
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureSeaSurface;
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureVolumePolicy;
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureWater;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -126,6 +128,11 @@ public final class BukkitStructureStagePolicy implements StructureStagePolicy<
|
||||
return GenerationWritePolicy.seaSurface(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StructureWater water(Engine context) {
|
||||
return IrisStructureWater.world(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IntBinaryOperator worldgenHeight(Engine context, int runtimeMinY, boolean floor) {
|
||||
return (x, z) -> Engine.hostHeight(context, x, z, floor) + runtimeMinY + 1;
|
||||
|
||||
@@ -31,6 +31,11 @@ public record NativeStructureStartPlan(
|
||||
return placement.isUnderground();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowWater() {
|
||||
return placement.isAllowWater();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean replacesSource() {
|
||||
return placement.getNativeSuppression() == NativeStructureSuppression.REPLACE_SOURCE;
|
||||
|
||||
@@ -328,11 +328,16 @@ public class IrisObject extends IrisRegistrant {
|
||||
}
|
||||
|
||||
public int place(int x, int z, IObjectPlacer placer, IrisObjectPlacement config, RNG rng, IrisData rdata) {
|
||||
return place(x, -1, z, placer, config, rng, rdata);
|
||||
return place(x, z, placer, config, rng, null, null, rdata);
|
||||
}
|
||||
|
||||
public int place(int x, int z, IObjectPlacer placer, IrisObjectPlacement config, RNG rng, CarveResult c, IrisData rdata) {
|
||||
return place(x, -1, z, placer, config, rng, null, c, rdata);
|
||||
return place(x, z, placer, config, rng, null, c, rdata);
|
||||
}
|
||||
|
||||
public int place(int x, int z, IObjectPlacer oplacer, IrisObjectPlacement config, RNG rng, BiConsumer<BlockPosition, NativeBlockState> listener, CarveResult c, IrisData rdata) {
|
||||
IrisObject placedObject = config.isSmartBore() ? IrisObjectShaping.smartBoredVariant(this) : this;
|
||||
return new IrisObjectPlacementRunner(placedObject, IrisObjectPlacementAlignment.CENTER).placeAutomatic(x, z, oplacer, config, rng, listener, c, rdata);
|
||||
}
|
||||
|
||||
public int place(int x, int yv, int z, IObjectPlacer placer, IrisObjectPlacement config, RNG rng, IrisData rdata) {
|
||||
|
||||
@@ -201,6 +201,7 @@ public class IrisObjectPlacement {
|
||||
@Description("Ignore any placement restrictions for this object")
|
||||
@SerializedName(value = "forcePlace", alternate = {"force"})
|
||||
private boolean forcePlace = false;
|
||||
private transient boolean forcedByStructure = false;
|
||||
private transient AtomicCache<TableCache> cache = new AtomicCache<>();
|
||||
private transient AtomicCache<CompatStatus> compatCache = new AtomicCache<>();
|
||||
@Getter(AccessLevel.NONE)
|
||||
@@ -306,6 +307,10 @@ public class IrisObjectPlacement {
|
||||
return place.size() == 1 ? place.getFirst() : place.toString(", ");
|
||||
}
|
||||
|
||||
public boolean entersWater() {
|
||||
return underwater || onwater || forcePlace && !forcedByStructure;
|
||||
}
|
||||
|
||||
public IrisObjectPlacement toPlacement(String... place) {
|
||||
IrisObjectPlacement p = new IrisObjectPlacement();
|
||||
p.setPlace(new KList<>(place));
|
||||
@@ -349,6 +354,7 @@ public class IrisObjectPlacement {
|
||||
p.setAllowedCollisions(allowedCollisions);
|
||||
p.setForbiddenCollisions(forbiddenCollisions);
|
||||
p.setForcePlace(forcePlace);
|
||||
p.setForcedByStructure(forcedByStructure);
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,15 @@ final class IrisObjectPlacementRunner {
|
||||
|
||||
int place(int x, int yv, int z, IObjectPlacer placer, IrisObjectPlacement config, RNG rng,
|
||||
BiConsumer<BlockPosition, NativeBlockState> listener, CarveResult cave, IrisData data) {
|
||||
PlacementContext context = new PlacementContext(config, data, placer, cave, rng, self, alignment, x, z, yv, listener);
|
||||
return PlacementLifecycles.defaults().get(config.getMode()).execute(context).heightOrRejected();
|
||||
return execute(new PlacementContext(config, data, placer, cave, rng, self, alignment, x, z, yv, listener));
|
||||
}
|
||||
|
||||
int placeAutomatic(int x, int z, IObjectPlacer placer, IrisObjectPlacement config, RNG rng,
|
||||
BiConsumer<BlockPosition, NativeBlockState> listener, CarveResult cave, IrisData data) {
|
||||
return execute(PlacementContext.automatic(config, data, placer, cave, rng, self, alignment, x, z, listener));
|
||||
}
|
||||
|
||||
private static int execute(PlacementContext context) {
|
||||
return PlacementLifecycles.defaults().get(context.config.getMode()).execute(context).heightOrRejected();
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,8 @@ import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.geometry.IrisBlockVector;
|
||||
import art.arcane.iris.generation.hydrology.raster.WaterRole;
|
||||
import art.arcane.volmlib.util.stream.ProceduralStream;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -60,6 +62,21 @@ public final class IrisSurfaceSupport {
|
||||
return stencil.anyColumnIntersectsHydrology(engine.getComplex(), x, z);
|
||||
}
|
||||
|
||||
public static boolean intersectsUnevenWater(IObjectPlacer placer, int x, int z,
|
||||
IrisObjectTranslate translate, IrisObjectRotation rotation,
|
||||
int spinX, int spinY, int spinZ,
|
||||
List<IrisBlockVector> supportOffsets) {
|
||||
Engine engine = placer.getEngine();
|
||||
if (engine == null || engine.getComplex() == null) {
|
||||
return false;
|
||||
}
|
||||
Stencil stencil = STENCIL.get();
|
||||
if (!stencil.build(supportOffsets, translate, rotation, spinX, spinY, spinZ, 0)) {
|
||||
return true;
|
||||
}
|
||||
return stencil.anyColumnIntersectsUnevenWater(engine.getComplex(), x, z);
|
||||
}
|
||||
|
||||
private static IrisBlockVector transform(IrisBlockVector offset, IrisObjectTranslate translate,
|
||||
IrisObjectRotation rotation, int spinX, int spinY, int spinZ) {
|
||||
IrisBlockVector transformed = offset.clone();
|
||||
@@ -228,6 +245,44 @@ public final class IrisSurfaceSupport {
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean anyColumnIntersectsUnevenWater(IrisComplex complex, int x, int z) {
|
||||
ProceduralStream<WaterRole> roles = complex.getWaterRoleStream();
|
||||
ProceduralStream<Double> heads = complex.getWaterHeadStream();
|
||||
boolean anchorKnown = false;
|
||||
long anchorHead = 0L;
|
||||
for (int stencilX = 0; stencilX < width; stencilX++) {
|
||||
for (int stencilZ = 0; stencilZ < depth; stencilZ++) {
|
||||
if (!cells[(stencilX * depth) + stencilZ]) {
|
||||
continue;
|
||||
}
|
||||
int columnX = x + minX + stencilX;
|
||||
int columnZ = z + minZ + stencilZ;
|
||||
WaterRole role = roles.get(columnX, columnZ);
|
||||
if (breaksFlatWater(role)) {
|
||||
return true;
|
||||
}
|
||||
if (!role.wet()) {
|
||||
continue;
|
||||
}
|
||||
if (!anchorKnown) {
|
||||
anchorHead = Math.round(heads.getDouble(x, z));
|
||||
anchorKnown = true;
|
||||
}
|
||||
if (Math.round(heads.getDouble(columnX, columnZ)) != anchorHead) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean breaksFlatWater(WaterRole role) {
|
||||
return switch (role) {
|
||||
case DAM, CASCADE, WATERFALL -> true;
|
||||
case NONE, CHANNEL, BANK, SHORE, POND, POND_SHORE, MOUTH, INLET -> false;
|
||||
};
|
||||
}
|
||||
|
||||
private boolean isColumnUnsupported(IObjectPlacer placer, IrisData data, int x, int z,
|
||||
int stencilX, int stencilZ, int minSolidDepth,
|
||||
IrisPaintSurfaceProjection projection) {
|
||||
|
||||
@@ -19,6 +19,8 @@ public final class PlacementContext {
|
||||
public record TransformedBounds(int minX, int maxX, int minY, int maxY, int minZ, int maxZ) {}
|
||||
public record WorldBounds(int minX, int maxX, int minY, int maxY, int minZ, int maxZ) {}
|
||||
|
||||
private static final int AUTOMATIC_Y = -1;
|
||||
|
||||
final IrisObjectPlacement config;
|
||||
final IrisData rdata;
|
||||
final IObjectPlacer placer;
|
||||
@@ -29,6 +31,7 @@ public final class PlacementContext {
|
||||
final int x;
|
||||
final int z;
|
||||
final int yv;
|
||||
final boolean automatic;
|
||||
final BiConsumer<BlockPosition, NativeBlockState> listener;
|
||||
|
||||
public PlacementContext(IrisObjectPlacement config, IrisData rdata, IObjectPlacer placer,
|
||||
@@ -40,6 +43,12 @@ public final class PlacementContext {
|
||||
public PlacementContext(IrisObjectPlacement config, IrisData rdata, IObjectPlacer placer,
|
||||
CarveResult caveResult, RNG rng, IrisObject self, IrisObjectPlacementAlignment alignment,
|
||||
int x, int z, int yv, BiConsumer<BlockPosition, NativeBlockState> listener) {
|
||||
this(config, rdata, placer, caveResult, rng, self, alignment, x, z, yv, false, listener);
|
||||
}
|
||||
|
||||
private PlacementContext(IrisObjectPlacement config, IrisData rdata, IObjectPlacer placer,
|
||||
CarveResult caveResult, RNG rng, IrisObject self, IrisObjectPlacementAlignment alignment,
|
||||
int x, int z, int yv, boolean automatic, BiConsumer<BlockPosition, NativeBlockState> listener) {
|
||||
this.placer = Objects.requireNonNull(placer, "Object placer is required.");
|
||||
this.config = Objects.requireNonNull(config, "Object placement config is required.");
|
||||
this.rng = Objects.requireNonNull(rng, "Object placement RNG is required.");
|
||||
@@ -50,6 +59,13 @@ public final class PlacementContext {
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
this.yv = yv;
|
||||
this.automatic = automatic;
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
public static PlacementContext automatic(IrisObjectPlacement config, IrisData rdata, IObjectPlacer placer,
|
||||
CarveResult caveResult, RNG rng, IrisObject self, IrisObjectPlacementAlignment alignment,
|
||||
int x, int z, BiConsumer<BlockPosition, NativeBlockState> listener) {
|
||||
return new PlacementContext(config, rdata, placer, caveResult, rng, self, alignment, x, z, AUTOMATIC_Y, true, listener);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package art.arcane.iris.structure.object;
|
||||
|
||||
import art.arcane.iris.generation.stream.ProvisionalAnswerException;
|
||||
import art.arcane.iris.generation.stream.ProvisionalSampling;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -15,9 +17,12 @@ public final class PlacementLifecycle {
|
||||
/** The block pass and everything after it read one consistent object snapshot. */
|
||||
public PlacementState execute(PlacementContext context) {
|
||||
PlacementState state = new PlacementState(context);
|
||||
for (PlacementStage<Void> stage : PlacementStage.BEFORE_PASS) {
|
||||
long revision = ProvisionalSampling.revision();
|
||||
for (PlacementStage<Void> stage : PlacementStage.DECISION) {
|
||||
run(stage, context, state, null);
|
||||
}
|
||||
requireFinalAnswers(context, revision);
|
||||
run(PlacementStage.BEFORE_BLOCKS, context, state, null);
|
||||
if (state.isRejected()) {
|
||||
return state;
|
||||
}
|
||||
@@ -42,4 +47,13 @@ public final class PlacementLifecycle {
|
||||
function.execute(context, state, input);
|
||||
}
|
||||
}
|
||||
|
||||
private static void requireFinalAnswers(PlacementContext context, long revision) {
|
||||
if (!context.automatic || ProvisionalSampling.revision() == revision) {
|
||||
return;
|
||||
}
|
||||
String key = context.self.getLoadKey();
|
||||
throw new ProvisionalAnswerException("Object " + (key == null ? "<no loadKey>" : key) + " at " + context.x + "," + context.z
|
||||
+ " read a provisional terrain or water answer; automatic placements are only made from final terrain.");
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ final class PlacementModuleAnchor implements PlacementModule {
|
||||
@Override
|
||||
public void install(PlacementLifecycleBuilder lifecycle) {
|
||||
lifecycle.add(POSITIONED, PlacementStage.HEIGHT, (context, state, ignored) -> {
|
||||
if (context.yv >= 0 && state.config.isBottom()
|
||||
if (!context.automatic && state.config.isBottom()
|
||||
&& state.config.getMode() != ObjectPlaceMode.STRUCTURE_PIECE
|
||||
&& context.alignment != IrisObjectPlacementAlignment.FLOOR) {
|
||||
state.y += Math.floorDiv(context.self.h, 2);
|
||||
@@ -36,7 +36,7 @@ final class PlacementModuleAnchor implements PlacementModule {
|
||||
}
|
||||
if (state.config.isFromBottom()) {
|
||||
state.y = context.self.getH() + 1 + state.rty;
|
||||
} else if (context.yv < 0) {
|
||||
} else if (context.automatic) {
|
||||
sampledHeight.execute(context, state, null);
|
||||
return;
|
||||
} else {
|
||||
@@ -52,7 +52,7 @@ final class PlacementModuleAnchor implements PlacementModule {
|
||||
|
||||
/** Seats the lowest occupied block on the caller's first air Y. */
|
||||
private static void alignToFloor(PlacementContext context, PlacementState state) {
|
||||
if (context.yv < 0 || state.ceilingHang || state.config.getMode() == ObjectPlaceMode.STRUCTURE_PIECE) {
|
||||
if (context.automatic || state.ceilingHang || state.config.getMode() == ObjectPlaceMode.STRUCTURE_PIECE) {
|
||||
throw new IllegalArgumentException("Floor alignment requires an explicit floor Y and a floor placement mode.");
|
||||
}
|
||||
int minimumY = minimumOccupiedY(context.self, state.spin);
|
||||
|
||||
@@ -10,7 +10,7 @@ final class PlacementModuleBounds implements PlacementModule {
|
||||
IrisObjectPlacement config = state.config;
|
||||
if (config.isBore() || (!config.isForcePlace() && config.getMode() != ObjectPlaceMode.STRUCTURE_PIECE
|
||||
&& (!config.getAllowedCollisions().isEmpty() || !config.getForbiddenCollisions().isEmpty()))) {
|
||||
state.worldBounds = resolve(context, state, context.yv < 0 && config.getMode() == ObjectPlaceMode.PAINT);
|
||||
state.worldBounds = resolve(context, state, context.automatic && config.getMode() == ObjectPlaceMode.PAINT);
|
||||
}
|
||||
}, PlacementModuleNativeStructureProtection.CHECK);
|
||||
}
|
||||
|
||||
@@ -11,13 +11,13 @@ final class PlacementModuleLimits implements PlacementModule {
|
||||
if (config.isForcePlace() || config.getMode() == ObjectPlaceMode.STRUCTURE_PIECE) {
|
||||
return;
|
||||
}
|
||||
if (context.yv < 0 && config.getMode() != ObjectPlaceMode.FLOATING
|
||||
if (context.automatic && config.getMode() != ObjectPlaceMode.FLOATING
|
||||
&& !config.isUnderwater() && !config.isOnwater()
|
||||
&& state.placer.isUnderwater(context.x, context.z)) {
|
||||
state.reject("underwater-anchor");
|
||||
return;
|
||||
}
|
||||
if (context.yv < 0 && config.getMode() != ObjectPlaceMode.FLOATING
|
||||
if (context.automatic && config.getMode() != ObjectPlaceMode.FLOATING
|
||||
&& config.isOnwater() && !state.placer.isUnderwater(context.x, context.z)) {
|
||||
state.reject("onwater-anchor");
|
||||
return;
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ final class PlacementModuleNativeStructureProtection implements PlacementModule
|
||||
IrisBlockVector translateOffset = state.translateOffset;
|
||||
boolean translating = translateOffset != null;
|
||||
boolean ceilingHang = state.ceilingHang;
|
||||
boolean paint = context.yv < 0 && config.getMode() == ObjectPlaceMode.PAINT;
|
||||
boolean paint = context.automatic && config.getMode() == ObjectPlaceMode.PAINT;
|
||||
int warpMargin = state.warpMargin;
|
||||
int x = context.x;
|
||||
int y = state.y + state.yrand;
|
||||
|
||||
@@ -26,7 +26,7 @@ public final class PlacementModulePaint implements PlacementModule {
|
||||
}
|
||||
static void installProjection(PlacementLifecycleBuilder lifecycle) {
|
||||
lifecycle.add(PROJECT, PlacementStage.VALIDATE, (context, state, ignored) -> {
|
||||
if (context.yv >= 0 || state.config.getMode() != ObjectPlaceMode.PAINT) {
|
||||
if (!context.automatic || state.config.getMode() != ObjectPlaceMode.PAINT) {
|
||||
return;
|
||||
}
|
||||
int buffer = state.config.isRequireSurfaceSupport() ? Math.max(0, state.config.getSurfaceSupportBuffer()) : 0;
|
||||
|
||||
+26
-9
@@ -15,17 +15,13 @@ final class PlacementModuleSurfaceSupport implements PlacementModule {
|
||||
public void install(PlacementLifecycleBuilder lifecycle) {
|
||||
lifecycle.add(CHECK, PlacementStage.VALIDATE, (context, state, ignored) -> {
|
||||
IrisObjectPlacement config = state.config;
|
||||
if (context.yv < 0 && config.getCarvingSupport().supportsSurface()
|
||||
&& config.getMode() != ObjectPlaceMode.FLOATING && config.getMode() != ObjectPlaceMode.STRUCTURE_PIECE
|
||||
&& (state.paintProjection != null
|
||||
? IrisSurfaceSupport.intersectsHydrology(context.placer, context.x, context.z, null, null, 0, 0, 0, state.paintSupport)
|
||||
: IrisSurfaceSupport.intersectsHydrology(context.placer, context.x, context.z, config.getTranslate(),
|
||||
config.getRotation(), state.spinX, state.spinY, state.spinZ, context.self.getSurfaceSupportOffsets()))) {
|
||||
state.reject("hydrology-support");
|
||||
String hydrologyRejection = hydrologyRejection(context, state);
|
||||
if (hydrologyRejection != null) {
|
||||
state.reject(hydrologyRejection);
|
||||
return;
|
||||
}
|
||||
boolean rawStructurePiece = config.getMode() == ObjectPlaceMode.STRUCTURE_PIECE;
|
||||
if (context.yv < 0 && !config.isForcePlace() && !config.isFromBottom()
|
||||
if (context.automatic && !config.isForcePlace() && !config.isFromBottom()
|
||||
&& config.getMode() != ObjectPlaceMode.FLOATING && !rawStructurePiece
|
||||
&& config.getCarvingSupport().supportsSurface() && state.placer.getEngine() != null
|
||||
&& state.placer.getEngine().getDimension().isBedrock() && state.y <= 1) {
|
||||
@@ -33,7 +29,7 @@ final class PlacementModuleSurfaceSupport implements PlacementModule {
|
||||
state.reject("bedrock-anchor");
|
||||
return;
|
||||
}
|
||||
boolean surfaceAnchored = context.yv < 0 ? config.getCarvingSupport().supportsSurface()
|
||||
boolean surfaceAnchored = context.automatic ? config.getCarvingSupport().supportsSurface()
|
||||
: config.getCarvingSupport() == CarvingMode.SURFACE_ONLY;
|
||||
if (surfaceAnchored && !config.isForcePlace() && !config.isFromBottom()
|
||||
&& config.getMode() != ObjectPlaceMode.FLOATING && !rawStructurePiece
|
||||
@@ -58,6 +54,27 @@ final class PlacementModuleSurfaceSupport implements PlacementModule {
|
||||
};
|
||||
}
|
||||
|
||||
private static String hydrologyRejection(PlacementContext context, PlacementState state) {
|
||||
IrisObjectPlacement config = state.config;
|
||||
if (!context.automatic || !config.getCarvingSupport().supportsSurface()
|
||||
|| config.getMode() == ObjectPlaceMode.FLOATING || config.getMode() == ObjectPlaceMode.STRUCTURE_PIECE) {
|
||||
return null;
|
||||
}
|
||||
boolean painted = state.paintProjection != null;
|
||||
if (config.entersWater()) {
|
||||
return (painted
|
||||
? IrisSurfaceSupport.intersectsUnevenWater(context.placer, context.x, context.z, null, null, 0, 0, 0, state.paintSupport)
|
||||
: IrisSurfaceSupport.intersectsUnevenWater(context.placer, context.x, context.z, config.getTranslate(),
|
||||
config.getRotation(), state.spinX, state.spinY, state.spinZ, context.self.getSurfaceSupportOffsets()))
|
||||
? "uneven-water" : null;
|
||||
}
|
||||
return (painted
|
||||
? IrisSurfaceSupport.intersectsHydrology(context.placer, context.x, context.z, null, null, 0, 0, 0, state.paintSupport)
|
||||
: IrisSurfaceSupport.intersectsHydrology(context.placer, context.x, context.z, config.getTranslate(),
|
||||
config.getRotation(), state.spinX, state.spinY, state.spinZ, context.self.getSurfaceSupportOffsets()))
|
||||
? "hydrology-support" : null;
|
||||
}
|
||||
|
||||
private static void warnImplausibleBedrockPlacement(IrisObject self, IObjectPlacer placer, IrisObjectPlacement config, int x, int y, int z) {
|
||||
String key = self.getLoadKey();
|
||||
String fingerprint = (key == null ? "<null>" : key) + "|" + config.getMode();
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ final class PlacementModuleTreeGrounding implements PlacementModule {
|
||||
private static boolean isSurfaceTreePlacement(PlacementContext context, PlacementState state) {
|
||||
IrisObjectPlacement config = state.config;
|
||||
ObjectPlaceMode mode = config.getMode();
|
||||
return context.yv < 0 && config.getCarvingSupport().supportsSurface()
|
||||
return context.automatic && config.getCarvingSupport().supportsSurface()
|
||||
&& !config.isForcePlace() && !config.isFromBottom() && !state.ceilingHang
|
||||
&& mode != ObjectPlaceMode.PAINT && mode != ObjectPlaceMode.FLOATING
|
||||
&& mode != ObjectPlaceMode.STRUCTURE_PIECE;
|
||||
|
||||
@@ -20,7 +20,7 @@ public final class PlacementStage<C> {
|
||||
public static final PlacementStage<Void> AFTER_BLOCKS = new PlacementStage<>("after-blocks", 6);
|
||||
static final List<PlacementStage<?>> ALL = List.of(PREPARE, HEIGHT, VALIDATE, BEFORE_BLOCKS,
|
||||
BLOCK_WRITTEN, BLOCKS, AFTER_BLOCKS);
|
||||
static final List<PlacementStage<Void>> BEFORE_PASS = List.of(PREPARE, HEIGHT, VALIDATE, BEFORE_BLOCKS);
|
||||
static final List<PlacementStage<Void>> DECISION = List.of(PREPARE, HEIGHT, VALIDATE);
|
||||
|
||||
private final String name;
|
||||
final int order;
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
package art.arcane.iris.structure.placement;
|
||||
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureLocateCandidate;
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureStagePolicy;
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureWaterRules;
|
||||
|
||||
import art.arcane.volmlib.nativelib.terrain.StructureLocateLimitException;
|
||||
|
||||
@@ -590,6 +592,10 @@ public final class IrisStructureLocator {
|
||||
"assembled pieces exceed the configured structure or world bounds")) {
|
||||
return null;
|
||||
}
|
||||
if (!placement.isAnchoredUnderground() && !placement.isAllowWater()
|
||||
&& !StructureWaterRules.admitsFootprint(IrisStructureWater.mantle(engine.getComplex()), pieceFootprints(pieces))) {
|
||||
return null;
|
||||
}
|
||||
if (!allowsResolvedFootprint(engine, placement, structure, pieces)) {
|
||||
return null;
|
||||
}
|
||||
@@ -935,6 +941,14 @@ public final class IrisStructureLocator {
|
||||
);
|
||||
}
|
||||
|
||||
private static List<StructureStagePolicy.Footprint> pieceFootprints(KList<PlacedStructurePiece> pieces) {
|
||||
List<StructureStagePolicy.Footprint> footprints = new ArrayList<>(pieces.size());
|
||||
for (PlacedStructurePiece piece : pieces) {
|
||||
footprints.add(new StructureStagePolicy.Footprint(piece.getMinX(), piece.getMinZ(), piece.getMaxX(), piece.getMaxZ()));
|
||||
}
|
||||
return footprints;
|
||||
}
|
||||
|
||||
private static int saturatedOffset(int coordinate, int offset) {
|
||||
long result = (long) coordinate + offset;
|
||||
return (int) Math.max(Integer.MIN_VALUE, Math.min(Integer.MAX_VALUE, result));
|
||||
|
||||
@@ -130,6 +130,9 @@ public class IrisStructurePlacement {
|
||||
@Description("If false, the placement is skipped when its selected surface or cave column is submerged.")
|
||||
private boolean underwater = false;
|
||||
|
||||
@Description("If true, a surface structure may cover river, stream, pond and lake water, and its pieces and stilts may fill it. If false, a surface placement is skipped when more than 10% of its footprint columns are channel, pond, cascade or waterfall water, and its pieces keep their solid blocks out of the water they touch.")
|
||||
private boolean allowWater = false;
|
||||
|
||||
public IrisStructureTerrain resolvedTerrain() {
|
||||
return terrain == null ? new IrisStructureTerrain() : terrain;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package art.arcane.iris.structure.placement;
|
||||
|
||||
import art.arcane.iris.generation.hydrology.raster.WaterRole;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
import art.arcane.iris.generation.stream.ProvisionalAnswerException;
|
||||
import art.arcane.iris.generation.stream.ProvisionalSampling;
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureWater;
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureWaterColumn;
|
||||
|
||||
public final class IrisStructureWater implements StructureWater {
|
||||
private final IrisComplex complex;
|
||||
private final int offsetY;
|
||||
|
||||
private IrisStructureWater(IrisComplex complex, int offsetY) {
|
||||
this.complex = complex;
|
||||
this.offsetY = offsetY;
|
||||
}
|
||||
|
||||
public static StructureWater mantle(IrisComplex complex) {
|
||||
return complex == null ? StructureWater.DRY : new IrisStructureWater(complex, 0);
|
||||
}
|
||||
|
||||
public static StructureWater world(Engine engine) {
|
||||
IrisComplex complex = engine.getComplex();
|
||||
return complex == null ? StructureWater.DRY : new IrisStructureWater(complex, engine.getMinHeight());
|
||||
}
|
||||
|
||||
@Override
|
||||
public StructureWaterColumn column(int x, int z) {
|
||||
long revision = ProvisionalSampling.revision();
|
||||
WaterRole role = complex.getWaterRoleStream().get(x, z);
|
||||
StructureWaterColumn column = role.wet()
|
||||
? new StructureWaterColumn(true, river(role),
|
||||
complex.getRoundedHeighteightStream().get(x, z) + offsetY,
|
||||
(int) Math.round(complex.getWaterHeadStream().getDouble(x, z)) + offsetY)
|
||||
: StructureWaterColumn.DRY;
|
||||
if (ProvisionalSampling.revision() != revision && !complex.isPlatformMainThread()) {
|
||||
throw new ProvisionalAnswerException("Structure water at " + x + "," + z
|
||||
+ " read a provisional answer; structures are only placed and carved around final water.");
|
||||
}
|
||||
return column;
|
||||
}
|
||||
|
||||
static boolean river(WaterRole role) {
|
||||
return switch (role) {
|
||||
case CHANNEL, POND, CASCADE, WATERFALL -> true;
|
||||
case NONE, BANK, SHORE, POND_SHORE, DAM, MOUTH, INLET -> false;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -159,6 +159,9 @@ public final class StructurePlacementGrid {
|
||||
signature = appendLong(signature, placement.isUnderwater() ? 1L : 0L);
|
||||
signature = appendSources(signature, placement);
|
||||
signature = appendAnchor(signature, placement);
|
||||
if (placement.isAllowWater()) {
|
||||
signature = appendLong(signature, 1L);
|
||||
}
|
||||
}
|
||||
return signature;
|
||||
}
|
||||
|
||||
@@ -158,7 +158,6 @@ public class TreeSVC implements IrisService {
|
||||
return;
|
||||
}
|
||||
|
||||
saplingPlane.forEach(block -> block.setType(Material.AIR));
|
||||
IrisObject object = placement.scaleObject(RNG.r,
|
||||
worldAccess.getData().getObjectLoader().load(pool.getRandom(RNG.r)), dimension);
|
||||
|
||||
@@ -268,6 +267,11 @@ public class TreeSVC implements IrisService {
|
||||
);
|
||||
|
||||
event.setCancelled(true);
|
||||
if (blockStateList.isEmpty()) {
|
||||
IrisLogging.debug("Tree placement " + object.getLoadKey() + " placed nothing at " + event.getLocation() + "; the sapling stays");
|
||||
return;
|
||||
}
|
||||
saplingPlane.forEach(block -> block.setType(Material.AIR));
|
||||
|
||||
Runnable growTask = () -> {
|
||||
|
||||
|
||||
+59
-4
@@ -18,8 +18,13 @@
|
||||
|
||||
package art.arcane.iris.generation.mantle;
|
||||
|
||||
import art.arcane.iris.generation.hydrology.engine.HydrologyRuntime;
|
||||
import art.arcane.iris.generation.hydrology.raster.ChunkWaterRaster;
|
||||
import art.arcane.iris.generation.hydrology.raster.WaterRole;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
import art.arcane.iris.generation.block.TileData;
|
||||
import art.arcane.volmlib.util.stream.ProceduralStream;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
import art.arcane.volmlib.util.math.BlockPosition;
|
||||
import org.junit.Test;
|
||||
@@ -36,6 +41,7 @@ import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyDouble;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.inOrder;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -48,7 +54,7 @@ public class FloatingObjectPlacementTransactionTest {
|
||||
public void canopyCommitRechecksSolidsAndSkipsAssociatedMetadata() {
|
||||
IslandObjectPlacer delegate = createPlacer(true);
|
||||
FloatingObjectPlacementTransaction transaction = new FloatingObjectPlacementTransaction(delegate,
|
||||
new ObjectContinuationBundle.PlacementKey(ObjectContinuationBundle.Kind.FLOATING, 0, 0, 0));
|
||||
new ObjectContinuationBundle.PlacementKey(ObjectContinuationBundle.Kind.FLOATING, 0, 0, 0), false);
|
||||
NativeBlockState canopy = mock(NativeBlockState.class);
|
||||
NativeBlockState trunk = mock(NativeBlockState.class);
|
||||
when(trunk.isSolid()).thenReturn(true);
|
||||
@@ -70,7 +76,7 @@ public class FloatingObjectPlacementTransactionTest {
|
||||
public void unsupportedFinalTerrainRejectsBlocksTilesAndMarkersTogether() {
|
||||
IslandObjectPlacer delegate = createPlacer(false);
|
||||
FloatingObjectPlacementTransaction transaction = new FloatingObjectPlacementTransaction(delegate,
|
||||
new ObjectContinuationBundle.PlacementKey(ObjectContinuationBundle.Kind.FLOATING, 0, 0, 0));
|
||||
new ObjectContinuationBundle.PlacementKey(ObjectContinuationBundle.Kind.FLOATING, 0, 0, 0), false);
|
||||
NativeBlockState first = mock(NativeBlockState.class);
|
||||
NativeBlockState second = mock(NativeBlockState.class);
|
||||
TileData tile = mock(TileData.class);
|
||||
@@ -97,7 +103,7 @@ public class FloatingObjectPlacementTransactionTest {
|
||||
public void supportedNeighborChunkCommitsBlocksTilesAndMarkers() {
|
||||
IslandObjectPlacer delegate = createPlacer(true);
|
||||
FloatingObjectPlacementTransaction transaction = new FloatingObjectPlacementTransaction(delegate,
|
||||
new ObjectContinuationBundle.PlacementKey(ObjectContinuationBundle.Kind.FLOATING, 0, 0, 0));
|
||||
new ObjectContinuationBundle.PlacementKey(ObjectContinuationBundle.Kind.FLOATING, 0, 0, 0), false);
|
||||
NativeBlockState first = mock(NativeBlockState.class);
|
||||
NativeBlockState second = mock(NativeBlockState.class);
|
||||
TileData tile = mock(TileData.class);
|
||||
@@ -143,7 +149,7 @@ public class FloatingObjectPlacementTransactionTest {
|
||||
NativeBlockState state = mock(NativeBlockState.class);
|
||||
when(state.key()).thenReturn("minecraft:oak_log");
|
||||
ObjectContinuationBundle.PlacementKey key = new ObjectContinuationBundle.PlacementKey(ObjectContinuationBundle.Kind.FLOATING, 0, 0, 7);
|
||||
FloatingObjectPlacementTransaction transaction = new FloatingObjectPlacementTransaction(delegate, key);
|
||||
FloatingObjectPlacementTransaction transaction = new FloatingObjectPlacementTransaction(delegate, key, false);
|
||||
transaction.set(15, 101, 8, state);
|
||||
transaction.set(16, 101, 8, state);
|
||||
transaction.setData(16, 101, 8, "floating-tree@7");
|
||||
@@ -158,6 +164,55 @@ public class FloatingObjectPlacementTransactionTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void floatingObjectsKeepSolidBlocksOutOfRiverWaterUnlessTheyEnterWater() {
|
||||
IObjectPlacer delegate = mock(IObjectPlacer.class);
|
||||
Engine engine = mock(Engine.class);
|
||||
IrisComplex complex = mock(IrisComplex.class);
|
||||
HydrologyRuntime runtime = mock(HydrologyRuntime.class);
|
||||
ChunkWaterRaster raster = mock(ChunkWaterRaster.class);
|
||||
ProceduralStream<WaterRole> roles = mock(ProceduralStream.class);
|
||||
ProceduralStream<Double> heads = mock(ProceduralStream.class);
|
||||
ProceduralStream<Integer> heights = mock(ProceduralStream.class);
|
||||
when(delegate.getEngine()).thenReturn(engine);
|
||||
when(engine.getComplex()).thenReturn(complex);
|
||||
when(complex.getHydrologyRuntime()).thenReturn(runtime);
|
||||
when(complex.allowsNewDiscreteContentAt(anyInt(), anyInt())).thenReturn(true);
|
||||
when(runtime.enabled()).thenReturn(true);
|
||||
when(runtime.raster(anyInt(), anyInt())).thenReturn(raster);
|
||||
when(raster.role(anyInt(), anyInt())).thenReturn(WaterRole.NONE);
|
||||
when(raster.waterHead(anyInt(), anyInt())).thenReturn(Integer.MIN_VALUE);
|
||||
when(raster.role(3, 3)).thenReturn(WaterRole.CHANNEL);
|
||||
when(raster.waterHead(3, 3)).thenReturn(9);
|
||||
when(raster.terrainHeight(3, 3)).thenReturn(5);
|
||||
when(roles.get(anyDouble(), anyDouble())).thenAnswer(call -> raster.role(local(call.getArgument(0)), local(call.getArgument(1))));
|
||||
when(heads.getDouble(anyDouble(), anyDouble())).thenAnswer(call -> (double) raster.waterHead(local(call.getArgument(0)), local(call.getArgument(1))));
|
||||
when(heights.get(anyDouble(), anyDouble())).thenAnswer(call -> raster.terrainHeight(local(call.getArgument(0)), local(call.getArgument(1))));
|
||||
when(complex.getWaterRoleStream()).thenReturn(roles);
|
||||
when(complex.getWaterHeadStream()).thenReturn(heads);
|
||||
when(complex.getRoundedHeighteightStream()).thenReturn(heights);
|
||||
NativeBlockState stone = mock(NativeBlockState.class);
|
||||
when(stone.isSolid()).thenReturn(true);
|
||||
ObjectContinuationBundle.PlacementKey key = new ObjectContinuationBundle.PlacementKey(ObjectContinuationBundle.Kind.FLOATING, 0, 0, 0);
|
||||
|
||||
FloatingObjectPlacementTransaction land = new FloatingObjectPlacementTransaction(delegate, key, false);
|
||||
land.set(3, 7, 3, stone);
|
||||
land.set(3, 10, 3, stone);
|
||||
assertEquals(FloatingObjectPlacementTransaction.CommitResult.COMMITTED, land.commit());
|
||||
verify(delegate, never()).set(3, 7, 3, stone);
|
||||
verify(delegate).set(3, 10, 3, stone);
|
||||
|
||||
FloatingObjectPlacementTransaction water = new FloatingObjectPlacementTransaction(delegate, key, true);
|
||||
water.set(3, 7, 3, stone);
|
||||
assertEquals(FloatingObjectPlacementTransaction.CommitResult.COMMITTED, water.commit());
|
||||
verify(delegate).set(3, 7, 3, stone);
|
||||
}
|
||||
|
||||
private static int local(Object coordinate) {
|
||||
return (int) Math.floor(((Number) coordinate).doubleValue()) & 15;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private IslandObjectPlacer createPlacer(boolean supportNeighborChunk) {
|
||||
IslandObjectPlacer placer = mock(IslandObjectPlacer.class);
|
||||
|
||||
+170
@@ -0,0 +1,170 @@
|
||||
package art.arcane.iris.generation.mantle;
|
||||
|
||||
import art.arcane.iris.configuration.IrisSettings;
|
||||
import art.arcane.iris.generation.hydrology.raster.WaterRole;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.structure.object.ObjectPlaceMode;
|
||||
import art.arcane.iris.structure.placement.IrisStructure;
|
||||
import art.arcane.iris.structure.placement.IrisStructurePlacement;
|
||||
import art.arcane.iris.structure.object.IrisObject;
|
||||
import art.arcane.iris.structure.object.IrisObjectRotation;
|
||||
import art.arcane.iris.structure.placement.IrisStructureTerrain;
|
||||
import art.arcane.iris.structure.placement.PlacedStructurePiece;
|
||||
import art.arcane.iris.testsupport.PlatformBinding;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import art.arcane.volmlib.util.matter.MatterCavern;
|
||||
import art.arcane.volmlib.util.stream.ProceduralStream;
|
||||
import art.arcane.volmlib.util.structure.StructureCarveShape;
|
||||
import art.arcane.volmlib.util.structure.StructureTerrainMode;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.mockito.InOrder;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyDouble;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.calls;
|
||||
import static org.mockito.Mockito.inOrder;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class IrisStructureComponentCarveWaterTest {
|
||||
private static final int RIVER_BED = 60;
|
||||
private static final int RIVER_HEAD = 64;
|
||||
private static final int LAND = 70;
|
||||
|
||||
@Rule
|
||||
public final PlatformBinding platform = PlatformBinding.mockPlatform();
|
||||
|
||||
private IrisStructureComponent component;
|
||||
private MantleWriter writer;
|
||||
private IrisSettings previousSettings;
|
||||
|
||||
@Before
|
||||
@SuppressWarnings("unchecked")
|
||||
public void setUp() {
|
||||
previousSettings = IrisSettings.settings;
|
||||
IrisSettings.settings = new IrisSettings();
|
||||
EngineMantle engineMantle = mock(EngineMantle.class);
|
||||
Engine engine = mock(Engine.class);
|
||||
IrisComplex complex = mock(IrisComplex.class);
|
||||
ProceduralStream<WaterRole> roles = mock(ProceduralStream.class);
|
||||
ProceduralStream<Integer> heights = mock(ProceduralStream.class);
|
||||
ProceduralStream<Double> heads = mock(ProceduralStream.class);
|
||||
when(engineMantle.getEngine()).thenReturn(engine);
|
||||
when(engineMantle.getComplex()).thenReturn(complex);
|
||||
when(engineMantle.getData()).thenReturn(mock(IrisData.class));
|
||||
when(engine.getComplex()).thenReturn(complex);
|
||||
when(engine.getMinHeight()).thenReturn(-64);
|
||||
when(engine.getHeight()).thenReturn(384);
|
||||
when(roles.get(anyDouble(), anyDouble())).thenAnswer(call -> river(call.getArgument(0)) ? WaterRole.CHANNEL : WaterRole.NONE);
|
||||
when(heights.get(anyDouble(), anyDouble())).thenAnswer(call -> river(call.getArgument(0)) ? RIVER_BED : LAND);
|
||||
when(heads.getDouble(anyDouble(), anyDouble())).thenAnswer(call -> river(call.getArgument(0)) ? (double) RIVER_HEAD : 63D);
|
||||
when(complex.getWaterRoleStream()).thenReturn(roles);
|
||||
when(complex.getRoundedHeighteightStream()).thenReturn(heights);
|
||||
when(complex.getWaterHeadStream()).thenReturn(heads);
|
||||
component = new IrisStructureComponent(engineMantle);
|
||||
writer = mock(MantleWriter.class);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
IrisSettings.settings = previousSettings;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void boreSkipsRiverColumnsAndTheirBanks() {
|
||||
component.boreStructure(writer, box(), terrain(StructureTerrainMode.BORE, StructureCarveShape.BOX));
|
||||
|
||||
assertRiverKept();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void forceCarveBoxSkipsRiverColumnsAndTheirBanks() {
|
||||
component.forceCarveStructure(writer, box(), terrain(StructureTerrainMode.FORCE_CARVE, StructureCarveShape.BOX));
|
||||
|
||||
assertRiverKept();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void roundedForceCarveSkipsRiverColumnsAndTheirBanks() {
|
||||
component.forceCarveStructure(writer, slab(), terrain(StructureTerrainMode.FORCE_CARVE, StructureCarveShape.ROUNDED));
|
||||
|
||||
verify(writer, never()).setForcedCarve(eq(3), eq(60), eq(1), any(MatterCavern.class));
|
||||
verify(writer, never()).setForcedCarve(eq(1), eq(60), eq(1), any(MatterCavern.class));
|
||||
verify(writer).setForcedCarve(eq(3), eq(55), eq(1), any(MatterCavern.class));
|
||||
verify(writer).setForcedCarve(eq(0), eq(60), eq(1), any(MatterCavern.class));
|
||||
verify(writer).setForcedCarve(eq(8), eq(60), eq(1), any(MatterCavern.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void piecesPlaceInsideAWaterAwareObjectPlacement() {
|
||||
IrisStructure structure = new IrisStructure().setPlaceMode(ObjectPlaceMode.STRUCTURE_PIECE);
|
||||
IrisStructurePlacement placement = new IrisStructurePlacement();
|
||||
|
||||
component.placePieces(writer, placement, structure, slab(), new RNG(3L));
|
||||
placement.setAllowWater(true);
|
||||
component.placePieces(writer, placement, structure, slab(), new RNG(3L));
|
||||
|
||||
InOrder order = inOrder(writer);
|
||||
order.verify(writer).beginObjectPlacement(false);
|
||||
order.verify(writer, calls(1)).set(anyInt(), anyInt(), anyInt(), any(NativeBlockState.class));
|
||||
order.verify(writer).endObjectPlacement(anyInt());
|
||||
order.verify(writer).beginObjectPlacement(true);
|
||||
order.verify(writer, calls(1)).set(anyInt(), anyInt(), anyInt(), any(NativeBlockState.class));
|
||||
order.verify(writer).endObjectPlacement(anyInt());
|
||||
}
|
||||
|
||||
private void assertRiverKept() {
|
||||
verify(writer, never()).setForcedCarve(eq(3), eq(62), eq(1), any(MatterCavern.class));
|
||||
verify(writer, never()).setForcedCarve(eq(4), eq(68), eq(1), any(MatterCavern.class));
|
||||
verify(writer, never()).setForcedCarve(eq(1), eq(58), eq(1), any(MatterCavern.class));
|
||||
verify(writer, never()).setForcedCarve(eq(6), eq(64), eq(1), any(MatterCavern.class));
|
||||
verify(writer).setForcedCarve(eq(3), eq(55), eq(1), any(MatterCavern.class));
|
||||
verify(writer).setForcedCarve(eq(1), eq(66), eq(1), any(MatterCavern.class));
|
||||
verify(writer).setForcedCarve(eq(0), eq(62), eq(1), any(MatterCavern.class));
|
||||
verify(writer).setForcedCarve(eq(7), eq(62), eq(1), any(MatterCavern.class));
|
||||
}
|
||||
|
||||
private static boolean river(Object x) {
|
||||
int blockX = (int) Math.floor(((Number) x).doubleValue());
|
||||
return blockX == 3 || blockX == 4;
|
||||
}
|
||||
|
||||
private static IrisStructureTerrain terrain(StructureTerrainMode mode, StructureCarveShape shape) {
|
||||
return new IrisStructureTerrain()
|
||||
.setMode(mode)
|
||||
.setShape(shape)
|
||||
.setFloorPadding(10)
|
||||
.setCeilingPadding(4);
|
||||
}
|
||||
|
||||
private static KList<PlacedStructurePiece> box() {
|
||||
return new KList<>(new PlacedStructurePiece(null, null, 4, -4, 1, IrisObjectRotation.of(0, 0, 0),
|
||||
0, -4, 0, 8, 0, 2));
|
||||
}
|
||||
|
||||
private static KList<PlacedStructurePiece> slab() {
|
||||
NativeBlockState stone = mock(NativeBlockState.class);
|
||||
when(stone.isSolid()).thenReturn(true);
|
||||
when(stone.key()).thenReturn("minecraft:stone");
|
||||
when(stone.materialKey()).thenReturn("minecraft:stone");
|
||||
IrisObject object = new IrisObject(9, 1, 3);
|
||||
for (int x = 0; x < 9; x++) {
|
||||
for (int z = 0; z < 3; z++) {
|
||||
object.setUnsigned(x, 0, z, stone);
|
||||
}
|
||||
}
|
||||
return new KList<>(new PlacedStructurePiece(null, object, 4, -4, 1, IrisObjectRotation.of(0, 0, 0),
|
||||
0, -4, 0, 8, -4, 2));
|
||||
}
|
||||
}
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
package art.arcane.iris.generation.mantle;
|
||||
|
||||
import art.arcane.iris.generation.hydrology.raster.WaterRole;
|
||||
import art.arcane.iris.structure.object.HydrologyWaterFixture;
|
||||
import art.arcane.iris.structure.object.IrisObject;
|
||||
import art.arcane.iris.structure.object.IrisObjectPlacement;
|
||||
import art.arcane.iris.structure.object.IrisObjectRotation;
|
||||
import art.arcane.iris.structure.object.ObjectPlaceMode;
|
||||
import art.arcane.iris.structure.placement.IrisStructure;
|
||||
import art.arcane.iris.structure.placement.PlacedStructurePiece;
|
||||
import art.arcane.iris.testsupport.PlatformBinding;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import art.arcane.volmlib.util.stream.ProceduralStream;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyDouble;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class IrisStructureComponentWaterTest {
|
||||
@Rule
|
||||
public final PlatformBinding platform = PlatformBinding.mockPlatform();
|
||||
|
||||
private final HydrologyWaterFixture world = new HydrologyWaterFixture();
|
||||
|
||||
@Test
|
||||
public void forcedSinglePieceStructureStaysOutOfRiverWater() {
|
||||
world.water(WaterRole.CHANNEL, 9, 13);
|
||||
HydrologyWaterFixture.Placer placer = world.placer();
|
||||
IrisObject object = HydrologyWaterFixture.raft();
|
||||
IrisObjectPlacement config = IrisStructureComponent.piecePlacement(new IrisStructure(), piece(object), ObjectPlaceMode.CENTER_HEIGHT, false);
|
||||
|
||||
assertTrue(config.isForcePlace());
|
||||
assertEquals(-1, object.place(0, 0, placer, config, new RNG(7L), world.data()));
|
||||
assertTrue(placer.writes().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void forcedSinglePieceStructureTurnedTowardsTheSlopeStaysOutOfRiverWater() {
|
||||
world.water(WaterRole.CHANNEL, 9, 13);
|
||||
@SuppressWarnings("unchecked")
|
||||
ProceduralStream<Double> heights = mock(ProceduralStream.class);
|
||||
when(heights.get(anyDouble(), anyDouble())).thenAnswer(invocation -> (double) world.floorAt(
|
||||
(int) Math.floor((Double) invocation.getArgument(0)), (int) Math.floor((Double) invocation.getArgument(1))));
|
||||
when(world.complex().getHeightStream()).thenReturn(heights);
|
||||
HydrologyWaterFixture.Placer placer = world.placer();
|
||||
IrisObject object = HydrologyWaterFixture.raft();
|
||||
IrisObjectPlacement config = IrisStructureComponent.piecePlacement(new IrisStructure(), piece(object), ObjectPlaceMode.CENTER_HEIGHT, false);
|
||||
config.setRotateTowardsSlope(true);
|
||||
|
||||
assertEquals(-1, object.place(0, 0, placer, config, new RNG(7L), world.data()));
|
||||
assertTrue(placer.writes().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void forcedSinglePieceStructureThatAllowsWaterPlacesOnFlatRiverWater() {
|
||||
world.water(WaterRole.CHANNEL, 9, 13);
|
||||
HydrologyWaterFixture.Placer placer = world.placer();
|
||||
IrisObject object = HydrologyWaterFixture.raft();
|
||||
IrisObjectPlacement config = IrisStructureComponent.piecePlacement(new IrisStructure(), piece(object), ObjectPlaceMode.CENTER_HEIGHT, true);
|
||||
|
||||
assertTrue(config.entersWater());
|
||||
assertTrue(object.place(0, 0, placer, config, new RNG(7L), world.data()) >= 0);
|
||||
assertEquals(world.headAt(0, 0), placer.lowestWrite());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void forcedSinglePieceStructureStillPlacesOnDryLand() {
|
||||
HydrologyWaterFixture.Placer placer = world.placer();
|
||||
IrisObject object = HydrologyWaterFixture.raft();
|
||||
IrisObjectPlacement config = IrisStructureComponent.piecePlacement(new IrisStructure(), piece(object), ObjectPlaceMode.CENTER_HEIGHT, false);
|
||||
|
||||
assertTrue(object.place(0, 0, placer, config, new RNG(7L), world.data()) >= 0);
|
||||
assertFalse(placer.writes().isEmpty());
|
||||
}
|
||||
|
||||
private static PlacedStructurePiece piece(IrisObject object) {
|
||||
return new PlacedStructurePiece(null, object, 0, 0, 0, IrisObjectRotation.of(0, 0, 0), -1, 0, -1, 1, 2, 1);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -103,7 +103,7 @@ public class MantleObjectComponentEngineFailureTest {
|
||||
doAnswer((InvocationOnMock invocation) -> {
|
||||
placements.incrementAndGet();
|
||||
throw placementFailure;
|
||||
}).when(object).place(anyInt(), anyInt(), anyInt(), any(IObjectPlacer.class), any(IrisObjectPlacement.class),
|
||||
}).when(object).place(anyInt(), anyInt(), any(IObjectPlacer.class), any(IrisObjectPlacement.class),
|
||||
any(RNG.class), any(), any(), any());
|
||||
|
||||
IrisComplex complex = mock(IrisComplex.class);
|
||||
|
||||
+149
@@ -0,0 +1,149 @@
|
||||
package art.arcane.iris.generation.mantle;
|
||||
|
||||
import art.arcane.iris.generation.hydrology.cave.HydrologyCaveCell;
|
||||
import art.arcane.iris.generation.hydrology.engine.HydrologyRuntime;
|
||||
import art.arcane.iris.generation.hydrology.raster.ChunkWaterRaster;
|
||||
import art.arcane.iris.generation.hydrology.raster.WaterRole;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
import art.arcane.iris.generation.terrain.IrisDimension;
|
||||
import art.arcane.iris.integration.Identifier;
|
||||
import art.arcane.iris.testsupport.PlatformBinding;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
import art.arcane.volmlib.util.mantle.runtime.Mantle;
|
||||
import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
|
||||
import art.arcane.volmlib.util.matter.Matter;
|
||||
import art.arcane.volmlib.util.matter.MatterCavern;
|
||||
import art.arcane.volmlib.util.matter.MatterSlice;
|
||||
import art.arcane.volmlib.util.stream.ProceduralStream;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyDouble;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class MantleWriterObjectWaterTest {
|
||||
@Rule
|
||||
public final PlatformBinding platform = PlatformBinding.mockPlatform();
|
||||
|
||||
private MantleWriter writer;
|
||||
private MatterSlice<NativeBlockState> blocks;
|
||||
private MatterSlice<MatterCavern> caverns;
|
||||
private NativeBlockState stone;
|
||||
private NativeBlockState air;
|
||||
|
||||
@Before
|
||||
@SuppressWarnings("unchecked")
|
||||
public void setUp() {
|
||||
EngineMantle engineMantle = mock(EngineMantle.class);
|
||||
Engine engine = mock(Engine.class);
|
||||
IrisComplex complex = mock(IrisComplex.class);
|
||||
HydrologyRuntime runtime = mock(HydrologyRuntime.class);
|
||||
ChunkWaterRaster raster = mock(ChunkWaterRaster.class);
|
||||
Mantle<Matter> mantle = mock(Mantle.class);
|
||||
MantleChunk<Matter> chunk = mock(MantleChunk.class);
|
||||
Matter matter = mock(Matter.class);
|
||||
blocks = mock(MatterSlice.class);
|
||||
caverns = mock(MatterSlice.class);
|
||||
when(engineMantle.getEngine()).thenReturn(engine);
|
||||
when(engineMantle.getComplex()).thenReturn(complex);
|
||||
when(engine.getComplex()).thenReturn(complex);
|
||||
when(engine.getDimension()).thenReturn(mock(IrisDimension.class));
|
||||
when(complex.getHydrologyRuntime()).thenReturn(runtime);
|
||||
when(runtime.enabled()).thenReturn(true);
|
||||
when(runtime.raster(anyInt(), anyInt())).thenReturn(raster);
|
||||
when(raster.role(anyInt(), anyInt())).thenReturn(WaterRole.NONE);
|
||||
when(raster.waterHead(anyInt(), anyInt())).thenReturn(Integer.MIN_VALUE);
|
||||
when(raster.terrainHeight(anyInt(), anyInt())).thenReturn(12);
|
||||
when(raster.role(3, 3)).thenReturn(WaterRole.CHANNEL);
|
||||
when(raster.waterHead(3, 3)).thenReturn(9);
|
||||
when(raster.terrainHeight(3, 3)).thenReturn(5);
|
||||
followRaster(complex, raster);
|
||||
when(mantle.getWorldHeight()).thenReturn(64);
|
||||
when(mantle.getChunk(0, 0)).thenReturn(chunk);
|
||||
when(chunk.use()).thenReturn(chunk);
|
||||
when(mantle.useChunk(0, 0)).thenAnswer(call -> chunk.use());
|
||||
when(chunk.getOrCreate(0)).thenReturn(matter);
|
||||
when(chunk.exists(0)).thenReturn(true);
|
||||
when(chunk.get(0)).thenReturn(matter);
|
||||
when(matter.getClass(any())).thenAnswer(call -> call.getArgument(0).getClass());
|
||||
doReturn(blocks).when(matter).slice(NativeBlockState.class);
|
||||
doReturn(caverns).when(matter).slice(MatterCavern.class);
|
||||
doReturn(mock(MatterSlice.class)).when(matter).getSlice(Identifier.class);
|
||||
doReturn(null).when(matter).getSlice(HydrologyCaveCell.class);
|
||||
stone = mock(NativeBlockState.class);
|
||||
when(stone.isSolid()).thenReturn(true);
|
||||
air = mock(NativeBlockState.class);
|
||||
writer = new MantleWriter(engineMantle, mantle, 0, 0, 0, false);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
writer.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void structurePiecesKeepOutOfRiverWaterUnlessTheyAllowIt() {
|
||||
MatterCavern cavern = new MatterCavern(true, "", (byte) 3);
|
||||
int land = writer.beginObjectPlacement(false);
|
||||
writer.set(3, 7, 3, stone);
|
||||
writer.set(3, 8, 3, air);
|
||||
writer.setData(3, 6, 3, cavern);
|
||||
writer.set(3, 5, 3, stone);
|
||||
writer.set(3, 10, 3, stone);
|
||||
writer.set(8, 7, 8, stone);
|
||||
writer.endObjectPlacement(land);
|
||||
|
||||
verify(blocks, never()).set(3, 7, 3, stone);
|
||||
verify(blocks, never()).set(3, 8, 3, air);
|
||||
verify(caverns, never()).set(3, 6, 3, cavern);
|
||||
verify(blocks).set(3, 5, 3, stone);
|
||||
verify(blocks).set(3, 10, 3, stone);
|
||||
verify(blocks).set(8, 7, 8, stone);
|
||||
|
||||
int water = writer.beginObjectPlacement(true);
|
||||
writer.set(3, 6, 3, stone);
|
||||
writer.set(3, 9, 3, air);
|
||||
writer.endObjectPlacement(water);
|
||||
|
||||
verify(blocks).set(3, 6, 3, stone);
|
||||
verify(blocks, never()).set(3, 9, 3, air);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void writesOutsideAnObjectPlacementAreNotVetoed() {
|
||||
int land = writer.beginObjectPlacement(false);
|
||||
writer.endObjectPlacement(land);
|
||||
|
||||
writer.set(3, 7, 3, stone);
|
||||
writer.set(3, 8, 3, air);
|
||||
|
||||
verify(blocks).set(3, 7, 3, stone);
|
||||
verify(blocks).set(3, 8, 3, air);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static void followRaster(IrisComplex complex, ChunkWaterRaster raster) {
|
||||
ProceduralStream<WaterRole> roles = mock(ProceduralStream.class);
|
||||
ProceduralStream<Double> heads = mock(ProceduralStream.class);
|
||||
ProceduralStream<Integer> heights = mock(ProceduralStream.class);
|
||||
when(roles.get(anyDouble(), anyDouble())).thenAnswer(call -> raster.role(local(call.getArgument(0)), local(call.getArgument(1))));
|
||||
when(heads.getDouble(anyDouble(), anyDouble())).thenAnswer(call -> (double) raster.waterHead(local(call.getArgument(0)), local(call.getArgument(1))));
|
||||
when(heights.get(anyDouble(), anyDouble())).thenAnswer(call -> raster.terrainHeight(local(call.getArgument(0)), local(call.getArgument(1))));
|
||||
when(complex.getWaterRoleStream()).thenReturn(roles);
|
||||
when(complex.getWaterHeadStream()).thenReturn(heads);
|
||||
when(complex.getRoundedHeighteightStream()).thenReturn(heights);
|
||||
}
|
||||
|
||||
private static int local(Object coordinate) {
|
||||
return (int) Math.floor(((Number) coordinate).doubleValue()) & 15;
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,7 @@ public class MutationLogTest {
|
||||
new ObjectDestinationTransaction.SetMutation(new ObjectDestinationTransaction.DataKey(3, 70, -2, String.class), "marker", true),
|
||||
new ObjectDestinationTransaction.CustomBlockMutation(new ObjectDestinationTransaction.DataKey(-17, 4, 40, NativeBlockState.class), state, false)));
|
||||
for (int index = 0; index < 100; index++) {
|
||||
log.add(index, index + 1, -index, "grow" + index, (index & 1) == 0, (index & 2) == 0);
|
||||
log.add(index, index + 1, -index, "grow" + index, (index & 1) == 0, (index & 2) == 0, (index & 4) == 0);
|
||||
}
|
||||
|
||||
assertEquals(102, log.size());
|
||||
@@ -41,6 +41,9 @@ public class MutationLogTest {
|
||||
assertFalse(log.custom(101));
|
||||
assertTrue(log.canopy(98));
|
||||
assertFalse(log.canopy(100));
|
||||
assertFalse(log.entersWater(0));
|
||||
assertTrue(log.entersWater(98));
|
||||
assertFalse(log.entersWater(6));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -59,7 +62,7 @@ public class MutationLogTest {
|
||||
int z = (index * 5) - 20;
|
||||
String value = "value" + (index % 9);
|
||||
boolean canopy = index % 4 == 0;
|
||||
log.add(x, y, z, value, false, canopy);
|
||||
log.add(x, y, z, value, false, canopy, false);
|
||||
if (index >= 10) {
|
||||
tail.add(new ObjectDestinationTransaction.SetMutation(new ObjectDestinationTransaction.DataKey(x, y, z, String.class), value, canopy));
|
||||
}
|
||||
|
||||
+1
-1
@@ -173,7 +173,7 @@ public class ObjectContinuationCanopyTest {
|
||||
when(firstChunk.getOrCreate(0)).thenReturn(first);
|
||||
when(secondChunk.getOrCreate(0)).thenReturn(second);
|
||||
FloatingObjectPlacementTransaction transaction = new FloatingObjectPlacementTransaction(delegate,
|
||||
new ObjectContinuationBundle.PlacementKey(ObjectContinuationBundle.Kind.FLOATING, 0, 0, 0));
|
||||
new ObjectContinuationBundle.PlacementKey(ObjectContinuationBundle.Kind.FLOATING, 0, 0, 0), false);
|
||||
transaction.set(15, 5, 1, trunk);
|
||||
assertTrue(transaction.beginTreeCanopy(new BlockPosition(16, 5, 1)));
|
||||
transaction.set(16, 5, 1, custom);
|
||||
|
||||
@@ -58,14 +58,14 @@ public class ObjectContinuationTest {
|
||||
public void onlyAcceptedCrossingPlacementsLeaveFutureFragments() throws Exception {
|
||||
Fixture fixture = new Fixture();
|
||||
ObjectDestinationTransaction source = new ObjectDestinationTransaction(fixture.writer, 0, 0);
|
||||
int checkpoint = source.beginObjectPlacement();
|
||||
int checkpoint = source.beginObjectPlacement(false);
|
||||
source.setData(1, 5, 1, "inside");
|
||||
source.endObjectPlacement(checkpoint);
|
||||
checkpoint = source.beginObjectPlacement();
|
||||
checkpoint = source.beginObjectPlacement(false);
|
||||
source.setData(15, 5, 1, "crossing");
|
||||
source.setData(16, 5, 1, "crossing");
|
||||
source.endObjectPlacement(checkpoint);
|
||||
checkpoint = source.beginObjectPlacement();
|
||||
checkpoint = source.beginObjectPlacement(false);
|
||||
source.setData(32, 5, 1, "unrelated");
|
||||
source.setData(48, 5, 1, "unrelated");
|
||||
source.endObjectPlacement(checkpoint);
|
||||
|
||||
+174
-3
@@ -19,6 +19,12 @@ import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
import art.arcane.volmlib.util.math.BlockPosition;
|
||||
import art.arcane.iris.structure.object.DecayControlPlacer;
|
||||
import art.arcane.iris.structure.object.IrisObject;
|
||||
import art.arcane.iris.structure.object.IrisObjectPlacement;
|
||||
import art.arcane.iris.structure.object.IrisObjectRotation;
|
||||
import art.arcane.iris.structure.object.ObjectPlaceMode;
|
||||
import art.arcane.iris.structure.placement.IrisStructure;
|
||||
import art.arcane.iris.structure.placement.PlacedStructurePiece;
|
||||
import art.arcane.iris.spi.PlatformRegistries;
|
||||
import art.arcane.iris.testsupport.BukkitTestServer;
|
||||
import art.arcane.iris.world.storage.matter.IrisMatterSupport;
|
||||
@@ -27,6 +33,7 @@ import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
|
||||
import art.arcane.volmlib.util.matter.IrisMatter;
|
||||
import art.arcane.volmlib.util.matter.Matter;
|
||||
import art.arcane.volmlib.util.matter.MatterCavern;
|
||||
import art.arcane.volmlib.util.stream.ProceduralStream;
|
||||
import org.junit.Test;
|
||||
import org.mockito.InOrder;
|
||||
|
||||
@@ -44,6 +51,7 @@ import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyDouble;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
@@ -139,7 +147,7 @@ public class ObjectDestinationTransactionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void solidObjectBlocksMayDisplaceWaterButNothingOpenOrCarvedBreaksContainment() {
|
||||
public void onlyUnderwaterObjectsDisplaceWaterAndNothingOpenOrCarvedBreaksContainment() {
|
||||
MantleWriter writer = writer();
|
||||
IrisComplex complex = mock(IrisComplex.class);
|
||||
HydrologyRuntime runtime = mock(HydrologyRuntime.class);
|
||||
@@ -163,6 +171,7 @@ public class ObjectDestinationTransactionTest {
|
||||
when(raster.terrainHeight(6, 6)).thenReturn(20);
|
||||
when(raster.role(9, 9)).thenReturn(WaterRole.SHORE);
|
||||
when(raster.terrainHeight(9, 9)).thenReturn(20);
|
||||
followRasterStreams(complex, raster);
|
||||
NativeBlockState pier = mock(NativeBlockState.class);
|
||||
when(pier.isSolid()).thenReturn(true);
|
||||
NativeBlockState vine = mock(NativeBlockState.class);
|
||||
@@ -179,10 +188,19 @@ public class ObjectDestinationTransactionTest {
|
||||
assertEquals("open blocks and carves stay out of water, its bed and the bank below the head, and nothing enters a fall", start,
|
||||
transaction.mutationCheckpoint());
|
||||
transaction.set(3, 10, 3, pier);
|
||||
transaction.set(4, 15, 3, pier);
|
||||
assertEquals("a land object's pier stays out of the river", start, transaction.mutationCheckpoint());
|
||||
transaction.set(3, 9, 3, pier);
|
||||
transaction.set(6, 18, 6, pier);
|
||||
assertEquals("a pier keeps its blocks on the river bed and the shore", start + 2, transaction.mutationCheckpoint());
|
||||
transaction.beginObjectPlacement(true);
|
||||
transaction.set(3, 10, 3, pier);
|
||||
transaction.set(4, 15, 3, pier);
|
||||
assertEquals("a pier into the river keeps its blocks", start + 4, transaction.mutationCheckpoint());
|
||||
assertEquals("an underwater pier keeps its blocks in the river", start + 4, transaction.mutationCheckpoint());
|
||||
transaction.set(3, 12, 3, pier);
|
||||
transaction.set(3, 10, 3, vine);
|
||||
assertEquals("an underwater object still keeps out of falls and open water", start + 4, transaction.mutationCheckpoint());
|
||||
transaction.beginObjectPlacement(false);
|
||||
transaction.set(3, 16, 3, vine);
|
||||
transaction.set(3, 8, 3, vine);
|
||||
transaction.set(6, 19, 6, vine);
|
||||
@@ -208,6 +226,7 @@ public class ObjectDestinationTransactionTest {
|
||||
when(raster.role(3, 3)).thenReturn(WaterRole.INLET);
|
||||
when(raster.waterHead(3, 3)).thenReturn(12);
|
||||
when(raster.terrainHeight(3, 3)).thenReturn(9);
|
||||
followRasterStreams(complex, raster);
|
||||
NativeBlockState boulder = mock(NativeBlockState.class);
|
||||
when(boulder.isSolid()).thenReturn(true);
|
||||
NativeBlockState leaves = mock(NativeBlockState.class);
|
||||
@@ -217,16 +236,145 @@ public class ObjectDestinationTransactionTest {
|
||||
transaction.set(3, 13, 3, boulder);
|
||||
transaction.set(3, 30, 3, boulder);
|
||||
transaction.set(3, 14, 3, leaves);
|
||||
transaction.set(3, 10, 3, boulder);
|
||||
assertEquals("nothing an object places roofs or fills the slot between its water and the cliff top", start,
|
||||
transaction.mutationCheckpoint());
|
||||
transaction.beginObjectPlacement(true);
|
||||
transaction.set(3, 10, 3, boulder);
|
||||
assertEquals("a solid block below the water may still sit on the slot bed", start + 1, transaction.mutationCheckpoint());
|
||||
transaction.set(3, 12, 3, boulder);
|
||||
assertEquals("an underwater object's solid block below the water may still sit on the slot bed", start + 1,
|
||||
transaction.mutationCheckpoint());
|
||||
transaction.beginObjectPlacement(false);
|
||||
transaction.set(3, 31, 3, leaves);
|
||||
transaction.set(3, 36, 3, leaves);
|
||||
transaction.set(3, 33, 3, boulder);
|
||||
assertEquals("a tree canopy above the cliff top keeps its leaves and wood", start + 4, transaction.mutationCheckpoint());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canopiesDoNotFillChannels() {
|
||||
MantleWriter writer = writer();
|
||||
IrisComplex complex = mock(IrisComplex.class);
|
||||
HydrologyRuntime runtime = mock(HydrologyRuntime.class);
|
||||
ChunkWaterRaster raster = mock(ChunkWaterRaster.class);
|
||||
when(writer.getEngine().getComplex()).thenReturn(complex);
|
||||
when(complex.getHydrologyRuntime()).thenReturn(runtime);
|
||||
when(runtime.enabled()).thenReturn(true);
|
||||
when(runtime.raster(anyInt(), anyInt())).thenReturn(raster);
|
||||
when(raster.role(anyInt(), anyInt())).thenReturn(WaterRole.NONE);
|
||||
when(raster.waterHead(anyInt(), anyInt())).thenReturn(Integer.MIN_VALUE);
|
||||
when(raster.terrainHeight(anyInt(), anyInt())).thenReturn(20);
|
||||
when(raster.role(3, 3)).thenReturn(WaterRole.CHANNEL);
|
||||
when(raster.waterHead(3, 3)).thenReturn(14);
|
||||
when(raster.terrainHeight(3, 3)).thenReturn(10);
|
||||
when(raster.role(4, 3)).thenReturn(WaterRole.POND);
|
||||
when(raster.waterHead(4, 3)).thenReturn(14);
|
||||
when(raster.terrainHeight(4, 3)).thenReturn(8);
|
||||
followRasterStreams(complex, raster);
|
||||
NativeBlockState leaves = mock(NativeBlockState.class);
|
||||
when(leaves.isSolid()).thenReturn(true);
|
||||
ObjectDestinationTransaction transaction = new ObjectDestinationTransaction(writer, 0, 0);
|
||||
int start = transaction.mutationCheckpoint();
|
||||
for (int y = 11; y <= 14; y++) {
|
||||
setCanopy(transaction, 3, y, 3, leaves);
|
||||
}
|
||||
for (int y = 9; y <= 14; y++) {
|
||||
setCanopy(transaction, 4, y, 3, leaves);
|
||||
}
|
||||
assertEquals("canopy leaves never fill a channel or pond between its bed and its surface", start,
|
||||
transaction.mutationCheckpoint());
|
||||
setCanopy(transaction, 3, 10, 3, leaves);
|
||||
setCanopy(transaction, 3, 15, 3, leaves);
|
||||
setCanopy(transaction, 4, 8, 3, leaves);
|
||||
setCanopy(transaction, 5, 14, 3, leaves);
|
||||
assertEquals("the bed, the air above the surface and dry land keep their leaves", start + 4,
|
||||
transaction.mutationCheckpoint());
|
||||
int underwater = transaction.beginObjectPlacement(true);
|
||||
transaction.set(3, 12, 3, leaves);
|
||||
transaction.set(4, 9, 3, leaves);
|
||||
assertEquals("an underwater object keeps its solid blocks in the water", underwater + 2,
|
||||
transaction.mutationCheckpoint());
|
||||
transaction.endObjectPlacement(underwater);
|
||||
ObjectDestinationTransaction destination = new ObjectDestinationTransaction(writer, 0, 0);
|
||||
destination.apply(transaction.sourcePlanSince(start));
|
||||
assertEquals("the destination replay keeps the underwater blocks", 6, destination.mutationCheckpoint());
|
||||
assertSame(leaves, destination.get(3, 12, 3));
|
||||
assertSame(leaves, destination.get(4, 9, 3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onwaterRaftsAndOwnForcedObjectsKeepTheirLayerOnRiversButForcedStructurePiecesDoNot() {
|
||||
MantleWriter writer = writer();
|
||||
IrisComplex complex = mock(IrisComplex.class);
|
||||
HydrologyRuntime runtime = mock(HydrologyRuntime.class);
|
||||
ChunkWaterRaster raster = mock(ChunkWaterRaster.class);
|
||||
when(writer.getEngine().getComplex()).thenReturn(complex);
|
||||
when(complex.getHydrologyRuntime()).thenReturn(runtime);
|
||||
when(runtime.enabled()).thenReturn(true);
|
||||
when(runtime.raster(anyInt(), anyInt())).thenReturn(raster);
|
||||
when(raster.role(anyInt(), anyInt())).thenReturn(WaterRole.NONE);
|
||||
when(raster.waterHead(anyInt(), anyInt())).thenReturn(Integer.MIN_VALUE);
|
||||
for (int x = 3; x <= 5; x++) {
|
||||
when(raster.role(x, 3)).thenReturn(WaterRole.CHANNEL);
|
||||
when(raster.waterHead(x, 3)).thenReturn(14);
|
||||
when(raster.terrainHeight(x, 3)).thenReturn(10);
|
||||
}
|
||||
followRasterStreams(complex, raster);
|
||||
NativeBlockState plank = mock(NativeBlockState.class);
|
||||
when(plank.isSolid()).thenReturn(true);
|
||||
IrisObjectPlacement raft = new IrisObjectPlacement().setOnwater(true);
|
||||
IrisObjectPlacement forced = new IrisObjectPlacement().setForcePlace(true);
|
||||
IrisObjectPlacement piece = IrisStructureComponent.piecePlacement(new IrisStructure(), new PlacedStructurePiece(null,
|
||||
new IrisObject(1, 1, 1), 4, 14, 3, IrisObjectRotation.of(0, 0, 0), 4, 14, 3, 4, 14, 3), ObjectPlaceMode.CENTER_HEIGHT, false);
|
||||
assertTrue(piece.isForcePlace());
|
||||
ObjectDestinationTransaction transaction = new ObjectDestinationTransaction(writer, 0, 0);
|
||||
|
||||
int raftStart = transaction.beginObjectPlacement(raft.entersWater());
|
||||
for (int x = 3; x <= 5; x++) {
|
||||
transaction.set(x, 14, 3, plank);
|
||||
}
|
||||
assertEquals("a one-block onwater raft keeps its layer on the river surface", raftStart + 3, transaction.mutationCheckpoint());
|
||||
int forcedStart = transaction.beginObjectPlacement(forced.entersWater());
|
||||
transaction.set(3, 13, 3, plank);
|
||||
assertEquals("an object's own forcePlace keeps its solid blocks in the river", forcedStart + 1, transaction.mutationCheckpoint());
|
||||
int pieceStart = transaction.beginObjectPlacement(piece.entersWater());
|
||||
transaction.set(4, 13, 3, plank);
|
||||
transaction.set(5, 11, 3, plank);
|
||||
assertEquals("a forced structure piece still keeps its solid blocks out of the river", pieceStart, transaction.mutationCheckpoint());
|
||||
ObjectDestinationTransaction destination = new ObjectDestinationTransaction(writer, 0, 0);
|
||||
destination.apply(transaction.sourcePlanSince(raftStart));
|
||||
assertEquals("the destination replay keeps the raft and the forced block", 4, destination.mutationCheckpoint());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void endingAWaterPlacementReturnsTheTransactionToLandRules() {
|
||||
MantleWriter writer = writer();
|
||||
IrisComplex complex = mock(IrisComplex.class);
|
||||
HydrologyRuntime runtime = mock(HydrologyRuntime.class);
|
||||
ChunkWaterRaster raster = mock(ChunkWaterRaster.class);
|
||||
when(writer.getEngine().getComplex()).thenReturn(complex);
|
||||
when(complex.getHydrologyRuntime()).thenReturn(runtime);
|
||||
when(runtime.enabled()).thenReturn(true);
|
||||
when(runtime.raster(anyInt(), anyInt())).thenReturn(raster);
|
||||
when(raster.role(anyInt(), anyInt())).thenReturn(WaterRole.NONE);
|
||||
when(raster.waterHead(anyInt(), anyInt())).thenReturn(Integer.MIN_VALUE);
|
||||
when(raster.role(3, 3)).thenReturn(WaterRole.CHANNEL);
|
||||
when(raster.waterHead(3, 3)).thenReturn(14);
|
||||
when(raster.terrainHeight(3, 3)).thenReturn(10);
|
||||
followRasterStreams(complex, raster);
|
||||
NativeBlockState pier = mock(NativeBlockState.class);
|
||||
when(pier.isSolid()).thenReturn(true);
|
||||
ObjectDestinationTransaction transaction = new ObjectDestinationTransaction(writer, 0, 0);
|
||||
|
||||
int raft = transaction.beginObjectPlacement(true);
|
||||
transaction.set(3, 12, 3, pier);
|
||||
transaction.endObjectPlacement(raft);
|
||||
int afterRaft = transaction.mutationCheckpoint();
|
||||
transaction.set(3, 13, 3, pier);
|
||||
|
||||
assertEquals("a write after the water placement ends follows land rules", afterRaft, transaction.mutationCheckpoint());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sourceCaptureCannotReplaceAuthoredRoomSolids() {
|
||||
MantleWriter writer = writer();
|
||||
@@ -769,6 +917,29 @@ public class ObjectDestinationTransactionTest {
|
||||
verify(writer).restoreData(0, 4, 0, Identifier.class, originalIdentifier);
|
||||
}
|
||||
|
||||
private static void setCanopy(ObjectDestinationTransaction transaction, int x, int y, int z, NativeBlockState state) {
|
||||
assertTrue(transaction.beginTreeCanopy(new BlockPosition(x, y, z)));
|
||||
transaction.set(x, y, z, state);
|
||||
transaction.endTreeCanopy();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static void followRasterStreams(IrisComplex complex, ChunkWaterRaster raster) {
|
||||
ProceduralStream<WaterRole> roles = mock(ProceduralStream.class);
|
||||
ProceduralStream<Double> heads = mock(ProceduralStream.class);
|
||||
ProceduralStream<Integer> heights = mock(ProceduralStream.class);
|
||||
when(roles.get(anyDouble(), anyDouble())).thenAnswer(call -> raster.role(local(call.getArgument(0)), local(call.getArgument(1))));
|
||||
when(heads.getDouble(anyDouble(), anyDouble())).thenAnswer(call -> (double) raster.waterHead(local(call.getArgument(0)), local(call.getArgument(1))));
|
||||
when(heights.get(anyDouble(), anyDouble())).thenAnswer(call -> raster.terrainHeight(local(call.getArgument(0)), local(call.getArgument(1))));
|
||||
when(complex.getWaterRoleStream()).thenReturn(roles);
|
||||
when(complex.getWaterHeadStream()).thenReturn(heads);
|
||||
when(complex.getRoundedHeighteightStream()).thenReturn(heights);
|
||||
}
|
||||
|
||||
private static int local(Object coordinate) {
|
||||
return (int) Math.floor(((Number) coordinate).doubleValue()) & 15;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static MantleWriter writer() {
|
||||
MantleWriter writer = mock(MantleWriter.class);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.generation.runtime;
|
||||
|
||||
import art.arcane.iris.generation.stream.ProvisionalAnswerException;
|
||||
import art.arcane.iris.world.history.SavedBiomeUnavailableException;
|
||||
import art.arcane.volmlib.util.mantle.MantleClosedException;
|
||||
import org.junit.Test;
|
||||
@@ -24,6 +25,7 @@ public class GenerationFailuresTest {
|
||||
assertTrue(GenerationFailures.isEngineFailure(new SavedBiomeUnavailableException("loading", true)));
|
||||
assertTrue(GenerationFailures.isEngineFailure(new GenerationSessionException("sealed", true)));
|
||||
assertTrue(GenerationFailures.isEngineFailure(new OutOfMemoryError()));
|
||||
assertTrue(GenerationFailures.isEngineFailure(new ProvisionalAnswerException("water not planned")));
|
||||
assertTrue(GenerationFailures.isEngineFailure(new CompletionException(
|
||||
new IllegalStateException("placement failed", new GenerationClosedException("router closed")))));
|
||||
}
|
||||
|
||||
+8
-2
@@ -3,6 +3,7 @@ package art.arcane.iris.structure.nativegen;
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.NativeStructureVolume;
|
||||
|
||||
import art.arcane.iris.generation.block.TileData;
|
||||
import art.arcane.iris.generation.hydrology.raster.WaterRole;
|
||||
import art.arcane.iris.generation.terrain.IrisDimension;
|
||||
import art.arcane.iris.structure.object.IObjectPlacer;
|
||||
import art.arcane.iris.structure.object.IrisObject;
|
||||
@@ -30,6 +31,7 @@ import java.util.List;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyDouble;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -52,8 +54,12 @@ public class NativeStructureObjectVetoTest {
|
||||
log = state("minecraft:oak_log", true);
|
||||
@SuppressWarnings("unchecked")
|
||||
ProceduralStream<Double> heightStream = mock(ProceduralStream.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
ProceduralStream<WaterRole> roles = mock(ProceduralStream.class);
|
||||
when(roles.get(anyDouble(), anyDouble())).thenReturn(WaterRole.NONE);
|
||||
IrisComplex complex = mock(IrisComplex.class);
|
||||
when(complex.getHeightStream()).thenReturn(heightStream);
|
||||
when(complex.getWaterRoleStream()).thenReturn(roles);
|
||||
engine = mock(Engine.class);
|
||||
when(engine.getHeight()).thenReturn(256);
|
||||
when(engine.getHeight(anyInt(), anyInt())).thenReturn(SURFACE_Y);
|
||||
@@ -264,7 +270,7 @@ public class NativeStructureObjectVetoTest {
|
||||
IrisObjectPlacement placement = placement();
|
||||
placement.setForcePlace(true);
|
||||
|
||||
assertEquals(-1, tree().place(0, -1, 0, placer, placement, new RNG(1234L), data));
|
||||
assertEquals(-1, tree().place(0, 0, placer, placement, new RNG(1234L), data));
|
||||
assertTrue(placer.written().isEmpty());
|
||||
}
|
||||
|
||||
@@ -304,7 +310,7 @@ public class NativeStructureObjectVetoTest {
|
||||
}
|
||||
|
||||
private int place(RecordingPlacer placer) {
|
||||
return tree().place(0, -1, 0, placer, placement(), new RNG(1234L), data);
|
||||
return tree().place(0, 0, placer, placement(), new RNG(1234L), data);
|
||||
}
|
||||
|
||||
private IrisObjectPlacement placement() {
|
||||
|
||||
+193
@@ -4,29 +4,53 @@ import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.SeedManager;
|
||||
import art.arcane.iris.structure.placement.StructurePlacementGrid;
|
||||
|
||||
import art.arcane.iris.generation.hydrology.raster.WaterRole;
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
import art.arcane.iris.generation.stream.ProvisionalAnswerException;
|
||||
import art.arcane.iris.generation.stream.ProvisionalSampling;
|
||||
import art.arcane.iris.generation.terrain.IrisDimension;
|
||||
import art.arcane.iris.platform.bukkit.nms.BukkitStructureStagePolicy;
|
||||
import art.arcane.iris.structure.placement.IrisStructureAnchorMode;
|
||||
import art.arcane.iris.structure.placement.IrisStructurePlacement;
|
||||
import art.arcane.iris.structure.placement.IrisStructureTerrain;
|
||||
import art.arcane.volmlib.util.structure.StructureTerrainMode;
|
||||
import art.arcane.iris.structure.placement.StructureDistribution;
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureStagePolicy;
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureWater;
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureWaterColumn;
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureWaterRules;
|
||||
import art.arcane.volmlib.util.stream.ProceduralStream;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.ArgumentMatchers.anyDouble;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class NativeStructurePlacementPlannerTest {
|
||||
private static final int BED = 140;
|
||||
private static final int HEAD = 143;
|
||||
private static final long LAND_IDENTITY = 7387932304999188754L;
|
||||
private static final List<StructureStagePolicy.Footprint> VILLAGE = List.of(
|
||||
new StructureStagePolicy.Footprint(0, 0, 15, 15),
|
||||
new StructureStagePolicy.Footprint(16, 0, 39, 15));
|
||||
|
||||
@Test
|
||||
public void undergroundPlanIsDeterministicAndUsesConfiguredBand() {
|
||||
Engine engine = engine(982374L, -64, 384, 90);
|
||||
@@ -130,6 +154,134 @@ public class NativeStructurePlacementPlannerTest {
|
||||
verify(waterHead).get(8, 8);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void structuresAvoidRivers() {
|
||||
Engine engine = engine(77L, -64, 384, 150);
|
||||
Map<Long, WaterRole> roles = new HashMap<>();
|
||||
waterComplex(engine, roles, false);
|
||||
WaterRole[] water = {WaterRole.CHANNEL, WaterRole.POND, WaterRole.CASCADE, WaterRole.WATERFALL};
|
||||
for (int x = 36; x <= 39; x++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
roles.put(columnKey(x, z), water[(x + z) & 3]);
|
||||
}
|
||||
}
|
||||
IrisStructurePlacement placement = nativePlacement();
|
||||
NativeStructureStartPlan plan = NativeStructurePlacementPlanner.planAt(engine, placement, 0, 0);
|
||||
StructureWater stageWater = new BukkitStructureStagePolicy(engine).water(engine);
|
||||
|
||||
assertNotNull(plan);
|
||||
assertTrue("64 of 640 piece columns, all beyond the start chunk, are 10% river",
|
||||
StructureWaterRules.admitsStart(plan, stageWater, VILLAGE));
|
||||
|
||||
roles.put(columnKey(35, 15), WaterRole.CHANNEL);
|
||||
assertFalse("65 of 640 piece columns are more than 10% river",
|
||||
StructureWaterRules.admitsStart(plan, stageWater, VILLAGE));
|
||||
|
||||
roles.clear();
|
||||
WaterRole[] dry = {WaterRole.MOUTH, WaterRole.INLET, WaterRole.SHORE, WaterRole.POND_SHORE, WaterRole.BANK, WaterRole.DAM};
|
||||
int column = 0;
|
||||
for (int x = 0; x <= 39; x++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
roles.put(columnKey(x, z), dry[column++ % dry.length]);
|
||||
}
|
||||
}
|
||||
assertTrue("mouths, inlets, shores, banks and dams do not count as river water",
|
||||
StructureWaterRules.admitsStart(plan, stageWater, VILLAGE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void riverInTheStartChunkLeavesTheDecisionToThePieces() {
|
||||
Engine engine = engine(77L, -64, 384, 150);
|
||||
Map<Long, WaterRole> roles = new HashMap<>();
|
||||
waterComplex(engine, roles, false);
|
||||
flood(roles);
|
||||
|
||||
assertNotNull(NativeStructurePlacementPlanner.planAt(engine, nativePlacement(), 0, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stageWaterReportsWorldHeights() {
|
||||
Engine engine = engine(77L, -64, 384, 150);
|
||||
Map<Long, WaterRole> roles = new HashMap<>();
|
||||
waterComplex(engine, roles, false);
|
||||
roles.put(columnKey(3, 4), WaterRole.MOUTH);
|
||||
roles.put(columnKey(5, 4), WaterRole.POND);
|
||||
StructureWater stageWater = new BukkitStructureStagePolicy(engine).water(engine);
|
||||
|
||||
assertEquals(new StructureWaterColumn(true, false, BED - 64, HEAD - 64), stageWater.column(3, 4));
|
||||
assertEquals(new StructureWaterColumn(true, true, BED - 64, HEAD - 64), stageWater.column(5, 4));
|
||||
assertEquals(StructureWaterColumn.DRY, stageWater.column(6, 4));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void undergroundPlansIgnoreRiversAbove() {
|
||||
Engine engine = engine(982374L, -64, 384, 90);
|
||||
Map<Long, WaterRole> roles = new HashMap<>();
|
||||
waterComplex(engine, roles, false);
|
||||
flood(roles);
|
||||
IrisStructurePlacement placement = nativePlacement()
|
||||
.setUnderground(true)
|
||||
.setMinHeight(-45)
|
||||
.setMaxHeight(-20);
|
||||
NativeStructureStartPlan plan = NativeStructurePlacementPlanner.planAt(engine, placement, 12, -7);
|
||||
|
||||
assertNotNull(plan);
|
||||
assertTrue(StructureWaterRules.admitsStart(plan, new BukkitStructureStagePolicy(engine).water(engine), VILLAGE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void allowWaterLetsNativeStructuresCoverRivers() {
|
||||
Engine engine = engine(77L, -64, 384, 150);
|
||||
Map<Long, WaterRole> roles = new HashMap<>();
|
||||
waterComplex(engine, roles, false);
|
||||
flood(roles);
|
||||
StructureWater stageWater = new BukkitStructureStagePolicy(engine).water(engine);
|
||||
IrisStructurePlacement placement = nativePlacement();
|
||||
|
||||
assertFalse(StructureWaterRules.admitsStart(
|
||||
NativeStructurePlacementPlanner.planAt(engine, placement, 0, 0), stageWater, VILLAGE));
|
||||
|
||||
placement.setAllowWater(true);
|
||||
NativeStructureStartPlan plan = NativeStructurePlacementPlanner.planAt(engine, placement, 0, 0);
|
||||
assertTrue(plan.allowWater());
|
||||
assertTrue(StructureWaterRules.admitsStart(plan, stageWater, VILLAGE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void provisionalWaterAnswersNeverPlaceANativeStructure() {
|
||||
Engine engine = engine(77L, -64, 384, 150);
|
||||
IrisComplex complex = waterComplex(engine, new HashMap<>(), true);
|
||||
StructureWater stageWater = new BukkitStructureStagePolicy(engine).water(engine);
|
||||
|
||||
ProvisionalAnswerException failure = assertThrows(ProvisionalAnswerException.class,
|
||||
() -> stageWater.column(20, 3));
|
||||
assertTrue(failure.getMessage().contains("20,3"));
|
||||
|
||||
when(complex.isPlatformMainThread()).thenReturn(true);
|
||||
assertEquals("the server thread answers from what it has, as for heights",
|
||||
StructureWaterColumn.DRY, stageWater.column(20, 3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void allowWaterSeparatesOtherwiseIdenticalPlacements() {
|
||||
IrisStructurePlacement land = nativePlacement();
|
||||
IrisStructurePlacement water = nativePlacement().setAllowWater(true);
|
||||
|
||||
assertEquals("placements that keep out of water keep their identity",
|
||||
LAND_IDENTITY, StructurePlacementGrid.placementIdentity(land));
|
||||
assertNotEquals(StructurePlacementGrid.placementIdentity(land), StructurePlacementGrid.placementIdentity(water));
|
||||
assertEquals("a placementId stays the whole identity",
|
||||
StructurePlacementGrid.placementIdentity(nativePlacement().setPlacementId("hut")),
|
||||
StructurePlacementGrid.placementIdentity(nativePlacement().setPlacementId("hut").setAllowWater(true)));
|
||||
|
||||
Engine engine = engine(77L, -64, 384, 150);
|
||||
bindPlacements(engine, land, water);
|
||||
IrisStructurePlacement first = NativeStructurePlacementPlanner.plansAt(engine, 0, 0).getFirst().placement();
|
||||
bindPlacements(engine, water, land);
|
||||
assertSame("the deduplicated start does not depend on list order",
|
||||
first, NativeStructurePlacementPlanner.plansAt(engine, 0, 0).getFirst().placement());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void duplicateSelectedStructureUsesOneDeterministicPlan() {
|
||||
Engine engine = engine(77L, -64, 384, 150);
|
||||
@@ -218,6 +370,47 @@ public class NativeStructurePlacementPlannerTest {
|
||||
return engine;
|
||||
}
|
||||
|
||||
private IrisComplex waterComplex(Engine engine, Map<Long, WaterRole> roles, boolean provisional) {
|
||||
IrisComplex complex = mock(IrisComplex.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
ProceduralStream<Double> heads = mock(ProceduralStream.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
ProceduralStream<WaterRole> roleStream = mock(ProceduralStream.class);
|
||||
when(heads.get(anyDouble(), anyDouble())).thenReturn(0D);
|
||||
when(heads.getDouble(anyDouble(), anyDouble())).thenReturn((double) HEAD);
|
||||
@SuppressWarnings("unchecked")
|
||||
ProceduralStream<Integer> heights = mock(ProceduralStream.class);
|
||||
when(heights.get(anyDouble(), anyDouble())).thenReturn(BED);
|
||||
when(complex.getRoundedHeighteightStream()).thenReturn(heights);
|
||||
when(roleStream.get(anyDouble(), anyDouble())).thenAnswer(call -> {
|
||||
if (provisional) {
|
||||
ProvisionalSampling.mark();
|
||||
}
|
||||
return roles.getOrDefault(columnKey(block(call.getArgument(0)), block(call.getArgument(1))), WaterRole.NONE);
|
||||
});
|
||||
when(complex.getWaterHeadStream()).thenReturn(heads);
|
||||
when(complex.getWaterRoleStream()).thenReturn(roleStream);
|
||||
when(complex.allowsNewGenerationChunk(anyInt(), anyInt())).thenReturn(true);
|
||||
when(engine.getComplex()).thenReturn(complex);
|
||||
return complex;
|
||||
}
|
||||
|
||||
private static void flood(Map<Long, WaterRole> roles) {
|
||||
for (int x = 0; x <= 39; x++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
roles.put(columnKey(x, z), WaterRole.CHANNEL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static int block(Object coordinate) {
|
||||
return (int) Math.floor(((Number) coordinate).doubleValue());
|
||||
}
|
||||
|
||||
private static long columnKey(int x, int z) {
|
||||
return ((long) x << 32) ^ (z & 0xffffffffL);
|
||||
}
|
||||
|
||||
private void bindPlacements(Engine engine, IrisStructurePlacement... placements) {
|
||||
IrisDimension dimension = engine.getDimension();
|
||||
KList<IrisStructurePlacement> configured = new KList<>();
|
||||
|
||||
@@ -0,0 +1,248 @@
|
||||
package art.arcane.iris.structure.object;
|
||||
|
||||
import art.arcane.iris.generation.block.TileData;
|
||||
import art.arcane.iris.generation.hydrology.raster.WaterRole;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
import art.arcane.iris.generation.stream.ProvisionalSampling;
|
||||
import art.arcane.iris.generation.terrain.IrisDimension;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
import art.arcane.volmlib.util.stream.ProceduralStream;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyDouble;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public final class HydrologyWaterFixture {
|
||||
public static final int LAND_ABOVE_SEA = 17;
|
||||
public static final int WATER_RADIUS = 8;
|
||||
|
||||
private final Map<Long, Column> columns = new HashMap<>();
|
||||
private final IrisData data;
|
||||
private final Engine engine;
|
||||
private final IrisComplex complex;
|
||||
private final int seaLevel;
|
||||
private Column water;
|
||||
private boolean provisional;
|
||||
|
||||
public HydrologyWaterFixture() {
|
||||
IrisDimension dimension = new IrisDimension();
|
||||
seaLevel = dimension.getFluidHeight();
|
||||
@SuppressWarnings("unchecked")
|
||||
ProceduralStream<Double> heads = mock(ProceduralStream.class);
|
||||
when(heads.get(anyDouble(), anyDouble())).thenAnswer(invocation -> (double) headAt(block(invocation.getArgument(0)), block(invocation.getArgument(1))));
|
||||
when(heads.getDouble(anyDouble(), anyDouble())).thenAnswer(invocation -> (double) headAt(block(invocation.getArgument(0)), block(invocation.getArgument(1))));
|
||||
@SuppressWarnings("unchecked")
|
||||
ProceduralStream<WaterRole> roles = mock(ProceduralStream.class);
|
||||
when(roles.get(anyDouble(), anyDouble())).thenAnswer(invocation -> roleAt(block(invocation.getArgument(0)), block(invocation.getArgument(1))));
|
||||
complex = mock(IrisComplex.class);
|
||||
when(complex.getWaterHeadStream()).thenReturn(heads);
|
||||
when(complex.getWaterRoleStream()).thenReturn(roles);
|
||||
when(complex.hasWaterOrShore(anyInt(), anyInt())).thenAnswer(invocation -> waterOrShore(roleAt(invocation.getArgument(0), invocation.getArgument(1))));
|
||||
engine = mock(Engine.class);
|
||||
when(engine.getHeight()).thenReturn(256);
|
||||
when(engine.getComplex()).thenReturn(complex);
|
||||
when(engine.getDimension()).thenReturn(dimension);
|
||||
data = mock(IrisData.class);
|
||||
when(data.getEngine()).thenReturn(engine);
|
||||
}
|
||||
|
||||
public IrisData data() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public IrisComplex complex() {
|
||||
return complex;
|
||||
}
|
||||
|
||||
public int seaLevel() {
|
||||
return seaLevel;
|
||||
}
|
||||
|
||||
public void water(WaterRole role, int floorAboveSea, int headAboveSea) {
|
||||
water = new Column(role, seaLevel + floorAboveSea, seaLevel + headAboveSea);
|
||||
}
|
||||
|
||||
public void column(int x, int z, WaterRole role, int floorAboveSea, int headAboveSea) {
|
||||
columns.put(key(x, z), new Column(role, seaLevel + floorAboveSea, seaLevel + headAboveSea));
|
||||
}
|
||||
|
||||
public void provisional() {
|
||||
provisional = true;
|
||||
}
|
||||
|
||||
public int floorAt(int x, int z) {
|
||||
return columnAt(x, z).floor();
|
||||
}
|
||||
|
||||
public int headAt(int x, int z) {
|
||||
Column column = columnAt(x, z);
|
||||
return column.role().wet() ? column.head() : seaLevel;
|
||||
}
|
||||
|
||||
public Placer placer() {
|
||||
return new Placer();
|
||||
}
|
||||
|
||||
public static IrisObject pillar() {
|
||||
IrisObject object = new IrisObject(3, 3, 3);
|
||||
object.setUnsigned(1, 0, 1, solid());
|
||||
object.setUnsigned(1, 1, 1, solid());
|
||||
return object;
|
||||
}
|
||||
|
||||
public static IrisObject raft() {
|
||||
IrisObject object = new IrisObject(3, 3, 3);
|
||||
for (int x = 0; x < 3; x++) {
|
||||
for (int z = 0; z < 3; z++) {
|
||||
object.setUnsigned(x, 0, z, solid());
|
||||
}
|
||||
}
|
||||
object.setUnsigned(1, 1, 1, solid());
|
||||
return object;
|
||||
}
|
||||
|
||||
private static NativeBlockState solid() {
|
||||
NativeBlockState solid = mock(NativeBlockState.class);
|
||||
when(solid.isSolid()).thenReturn(true);
|
||||
when(solid.key()).thenReturn("minecraft:stone");
|
||||
when(solid.materialKey()).thenReturn("minecraft:stone");
|
||||
return solid;
|
||||
}
|
||||
|
||||
private WaterRole roleAt(int x, int z) {
|
||||
return columnAt(x, z).role();
|
||||
}
|
||||
|
||||
private Column columnAt(int x, int z) {
|
||||
if (provisional) {
|
||||
ProvisionalSampling.mark();
|
||||
}
|
||||
Column override = columns.get(key(x, z));
|
||||
if (override != null) {
|
||||
return override;
|
||||
}
|
||||
if (water != null && Math.abs(x) <= WATER_RADIUS && Math.abs(z) <= WATER_RADIUS) {
|
||||
return water;
|
||||
}
|
||||
return new Column(WaterRole.NONE, seaLevel + LAND_ABOVE_SEA, seaLevel);
|
||||
}
|
||||
|
||||
private static boolean waterOrShore(WaterRole role) {
|
||||
return switch (role) {
|
||||
case CHANNEL, POND, MOUTH, CASCADE, WATERFALL, INLET, SHORE, POND_SHORE, DAM -> true;
|
||||
case NONE, BANK -> false;
|
||||
};
|
||||
}
|
||||
|
||||
private static int block(Object coordinate) {
|
||||
return (int) Math.floor(((Number) coordinate).doubleValue());
|
||||
}
|
||||
|
||||
private static long key(int x, int z) {
|
||||
return ((long) x << 32) ^ (z & 0xffffffffL);
|
||||
}
|
||||
|
||||
private record Column(WaterRole role, int floor, int head) {
|
||||
}
|
||||
|
||||
public final class Placer implements IObjectPlacer {
|
||||
private final List<Integer> writes = new ArrayList<>();
|
||||
|
||||
public List<Integer> writes() {
|
||||
return writes;
|
||||
}
|
||||
|
||||
public int lowestWrite() {
|
||||
int lowest = Integer.MAX_VALUE;
|
||||
for (int y : writes) {
|
||||
lowest = Math.min(lowest, y);
|
||||
}
|
||||
return lowest;
|
||||
}
|
||||
|
||||
public int highestWrite() {
|
||||
int highest = Integer.MIN_VALUE;
|
||||
for (int y : writes) {
|
||||
highest = Math.max(highest, y);
|
||||
}
|
||||
return highest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHighest(int x, int z, IrisData data) {
|
||||
return getHighest(x, z, data, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHighest(int x, int z, IrisData data, boolean ignoreFluid) {
|
||||
int floor = floorAt(x, z);
|
||||
return ignoreFluid ? floor : Math.max(floor, getFluidHeight(x, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(int x, int y, int z, NativeBlockState state) {
|
||||
writes.add(y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeBlockState get(int x, int y, int z) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPreventingDecay() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCarved(int x, int y, int z) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSolid(int x, int y, int z) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUnderwater(int x, int z) {
|
||||
return getHighest(x, z, data, true) < getFluidHeight(x, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFluidHeight() {
|
||||
return seaLevel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebugSmartBore() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTile(int x, int y, int z, TileData tile) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> void setData(int x, int y, int z, T value) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getData(int x, int y, int z, Class<T> type) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Engine getEngine() {
|
||||
return engine;
|
||||
}
|
||||
}
|
||||
}
|
||||
+51
-11
@@ -17,6 +17,8 @@ import org.junit.ClassRule;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.stream.ProvisionalAnswerException;
|
||||
import art.arcane.iris.generation.stream.ProvisionalSampling;
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.NativeStructureVolume;
|
||||
import art.arcane.iris.structure.placement.PlacedObject;
|
||||
import art.arcane.iris.spi.IrisPlatform;
|
||||
@@ -140,7 +142,7 @@ public class IrisObjectPlacementLifecycleRegressionTest {
|
||||
placement.setMode(ObjectPlaceMode.MAX_HEIGHT);
|
||||
placement.setRotation(IrisObjectRotation.of(0, 45, 0));
|
||||
|
||||
boxObject(5, 1, 3).place(0, -1, 0, placer, placement, new RNG(2L), data);
|
||||
boxObject(5, 1, 3).place(0, 0, placer, placement, new RNG(2L), data);
|
||||
|
||||
assertTrue(placer.sampledColumns().contains("-2:-2"));
|
||||
assertTrue(placer.sampledColumns().contains("2:2"));
|
||||
@@ -254,7 +256,7 @@ public class IrisObjectPlacementLifecycleRegressionTest {
|
||||
RecordingPlacer placer = new RecordingPlacer(null);
|
||||
IrisObjectPlacement config = placement();
|
||||
config.setMode(ObjectPlaceMode.ERODE_STILT);
|
||||
assertEquals(ANCHOR_Y, lineObject(1).place(0, -1, 0, placer, config, new RNG(2L), data));
|
||||
assertEquals(ANCHOR_Y, lineObject(1).place(0, 0, placer, config, new RNG(2L), data));
|
||||
assertFalse(placer.writes().isEmpty());
|
||||
}
|
||||
|
||||
@@ -293,17 +295,42 @@ public class IrisObjectPlacementLifecycleRegressionTest {
|
||||
RecordingPlacer placer = new RecordingPlacer(null);
|
||||
IrisObjectPlacement config = placement();
|
||||
config.setFromBottom(true);
|
||||
assertEquals(2, lineObject(1).place(0, -1, 0, placer, config, new RNG(2L), data));
|
||||
assertEquals(2, lineObject(1).place(0, 0, placer, config, new RNG(2L), data));
|
||||
assertTrue(placer.sampledColumns().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void explicitNegativeWorldYPlacesAtThatYWithoutSamplingTerrain() {
|
||||
RecordingPlacer placer = new RecordingPlacer(null);
|
||||
|
||||
assertEquals(-20, lineObject(3).place(0, -20, 0, placer, placement(), new RNG(2L), data));
|
||||
assertTrue(placer.sampledColumns().isEmpty());
|
||||
assertEquals(3, placer.writes().size());
|
||||
assertTrue(placer.writes().stream().allMatch(write -> write.y() == -20));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void explicitNegativeWorldYIsNotGuardedAgainstProvisionalAnswers() {
|
||||
RecordingPlacer placer = new RecordingPlacer(null);
|
||||
placer.provisional = true;
|
||||
|
||||
assertEquals(-1, lineObject(3).place(0, -1, 0, placer, placement(), new RNG(2L), data));
|
||||
assertEquals(3, placer.writes().size());
|
||||
assertTrue(placer.writes().stream().allMatch(write -> write.y() == -1));
|
||||
RecordingPlacer automatic = new RecordingPlacer(null);
|
||||
automatic.provisional = true;
|
||||
assertThrows(ProvisionalAnswerException.class,
|
||||
() -> lineObject(3).place(0, 0, automatic, placement(), new RNG(2L), data));
|
||||
assertTrue(automatic.writes().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void eligibilityGuardsRejectBeforeBoreAndOwnTheirForcePlaceExemptions() {
|
||||
for (String reason : List.of("carving-anchor", "underwater-anchor", "onwater-anchor", "cave-clearance", "fluid-height", "height-clamp")) {
|
||||
RecordingPlacer placer = new RecordingPlacer(null);
|
||||
IrisObjectPlacement config = placement().setBore(true).setSnow(0.1);
|
||||
CarveResult cave = null;
|
||||
int anchor = ANCHOR_Y;
|
||||
boolean automatic = false;
|
||||
switch (reason) {
|
||||
case "carving-anchor" -> {
|
||||
placer.carved = true;
|
||||
@@ -311,11 +338,11 @@ public class IrisObjectPlacementLifecycleRegressionTest {
|
||||
}
|
||||
case "underwater-anchor" -> {
|
||||
placer.underwater = true;
|
||||
anchor = -1;
|
||||
automatic = true;
|
||||
}
|
||||
case "onwater-anchor" -> {
|
||||
config.setOnwater(true);
|
||||
anchor = -1;
|
||||
automatic = true;
|
||||
}
|
||||
case "cave-clearance" -> cave = new CarveResult(ANCHOR_Y, ANCHOR_Y + 1);
|
||||
case "fluid-height" -> {
|
||||
@@ -324,13 +351,13 @@ public class IrisObjectPlacementLifecycleRegressionTest {
|
||||
}
|
||||
case "height-clamp" -> config.getClamp().setMaximumHeight(ANCHOR_Y - 1);
|
||||
}
|
||||
PlacementState result = execute(config, anchor, placer, cave);
|
||||
PlacementState result = automatic ? executeAutomatic(config, placer, cave) : execute(config, ANCHOR_Y, placer, cave);
|
||||
assertEquals(reason, result.getRejection());
|
||||
assertEquals(-1, result.heightOrRejected());
|
||||
assertTrue(reason, placer.writes().isEmpty());
|
||||
|
||||
config.setForcePlace(true);
|
||||
assertFalse(reason, execute(config, anchor, placer, cave).isRejected());
|
||||
assertFalse(reason, (automatic ? executeAutomatic(config, placer, cave) : execute(config, ANCHOR_Y, placer, cave)).isRejected());
|
||||
assertFalse(reason, placer.writes().isEmpty());
|
||||
}
|
||||
}
|
||||
@@ -429,7 +456,7 @@ public class IrisObjectPlacementLifecycleRegressionTest {
|
||||
IrisObjectPlacement config = placement();
|
||||
config.setHeightmap(new IrisNoiseGenerator(false).setOffsetY(93));
|
||||
|
||||
assertEquals(93, lineObject(1).place(0, -1, 0, placer, config, rng, data));
|
||||
assertEquals(93, lineObject(1).place(0, 0, placer, config, rng, data));
|
||||
assertTrue(placer.sampledColumns().isEmpty());
|
||||
assertEquals(expected.nextLong(), rng.nextLong());
|
||||
}
|
||||
@@ -478,6 +505,11 @@ public class IrisObjectPlacementLifecycleRegressionTest {
|
||||
new PlacementContext(config, data, placer, cave, new RNG(2L), lineObject(1), 0, 0, y, null));
|
||||
}
|
||||
|
||||
private PlacementState executeAutomatic(IrisObjectPlacement config, RecordingPlacer placer, CarveResult cave) {
|
||||
return PlacementLifecycles.defaults().get(config.getMode()).execute(PlacementContext.automatic(
|
||||
config, data, placer, cave, new RNG(2L), lineObject(1), IrisObjectPlacementAlignment.CENTER, 0, 0, null));
|
||||
}
|
||||
|
||||
private IrisObject lineObject(int width) {
|
||||
IrisObject object = new IrisObject(width, 1, 1);
|
||||
for (int x = 0; x < width; x++) {
|
||||
@@ -522,6 +554,7 @@ public class IrisObjectPlacementLifecycleRegressionTest {
|
||||
private boolean debugSmartBore;
|
||||
private boolean carved;
|
||||
private boolean underwater;
|
||||
private boolean provisional;
|
||||
private int fluidHeight;
|
||||
|
||||
private RecordingPlacer(Engine engine) {
|
||||
@@ -550,13 +583,13 @@ public class IrisObjectPlacementLifecycleRegressionTest {
|
||||
|
||||
@Override
|
||||
public int getHighest(int x, int z, IrisData data) {
|
||||
sampledColumns.add(x + ":" + z);
|
||||
return ANCHOR_Y;
|
||||
return getHighest(x, z, data, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHighest(int x, int z, IrisData data, boolean ignoreFluid) {
|
||||
sampledColumns.add(x + ":" + z);
|
||||
markProvisional();
|
||||
return ANCHOR_Y;
|
||||
}
|
||||
|
||||
@@ -581,9 +614,16 @@ public class IrisObjectPlacementLifecycleRegressionTest {
|
||||
|
||||
@Override
|
||||
public boolean isCarved(int x, int y, int z) {
|
||||
markProvisional();
|
||||
return carved;
|
||||
}
|
||||
|
||||
private void markProvisional() {
|
||||
if (provisional) {
|
||||
ProvisionalSampling.mark();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSolid(int x, int y, int z) {
|
||||
NativeBlockState state = get(x, y, z);
|
||||
|
||||
+14
-14
@@ -144,11 +144,11 @@ public class IrisObjectPlacementRunnerRegressionTest {
|
||||
IrisObjectPlacement placement = placement();
|
||||
placement.setOnwater(true);
|
||||
RecordingPlacer dry = new RecordingPlacer(null);
|
||||
assertEquals(-1, lineObject(3).place(0, -1, 0, dry, placement, new RNG(2L), data));
|
||||
assertEquals(-1, lineObject(3).place(0, 0, dry, placement, new RNG(2L), data));
|
||||
assertTrue(dry.writes().isEmpty());
|
||||
RecordingPlacer wet = new RecordingPlacer(null);
|
||||
wet.setUnderwater(true);
|
||||
assertNotEquals(-1, lineObject(3).place(0, -1, 0, wet, placement, new RNG(2L), data));
|
||||
assertNotEquals(-1, lineObject(3).place(0, 0, wet, placement, new RNG(2L), data));
|
||||
assertFalse(wet.writes().isEmpty());
|
||||
}
|
||||
|
||||
@@ -212,7 +212,7 @@ public class IrisObjectPlacementRunnerRegressionTest {
|
||||
placement.setMode(ObjectPlaceMode.MAX_HEIGHT);
|
||||
placement.setRotation(IrisObjectRotation.of(0, 45, 0));
|
||||
|
||||
boxObject(5, 1, 3).place(0, -1, 0, placer, placement, new RNG(2L), data);
|
||||
boxObject(5, 1, 3).place(0, 0, placer, placement, new RNG(2L), data);
|
||||
|
||||
assertTrue(placer.sampledColumns().contains("-2:-2"));
|
||||
assertTrue(placer.sampledColumns().contains("2:2"));
|
||||
@@ -375,7 +375,7 @@ public class IrisObjectPlacementRunnerRegressionTest {
|
||||
IrisObjectPlacement placement = placement().setMode(ObjectPlaceMode.PAINT)
|
||||
.setRequireSurfaceSupport(true).setSurfaceSupportBuffer(0);
|
||||
|
||||
assertEquals(80, lineObject(5).place(0, -1, 0, placer, placement, new RNG(2L), data));
|
||||
assertEquals(80, lineObject(5).place(0, 0, placer, placement, new RNG(2L), data));
|
||||
|
||||
assertEquals(5, placer.writes().size());
|
||||
assertTrue(placer.writes().stream().allMatch(write -> write.y() == 80));
|
||||
@@ -387,7 +387,7 @@ public class IrisObjectPlacementRunnerRegressionTest {
|
||||
placer.terrain(1, 0, 0, 20);
|
||||
IrisObjectPlacement placement = placement().setMode(ObjectPlaceMode.PAINT);
|
||||
|
||||
lineObject(5).place(0, -1, 0, placer, placement, new RNG(2L), data);
|
||||
lineObject(5).place(0, 0, placer, placement, new RNG(2L), data);
|
||||
|
||||
assertEquals(3, placer.writes().size());
|
||||
assertTrue(placer.writes().stream().allMatch(write -> write.x() <= 0 && write.y() == 80));
|
||||
@@ -400,7 +400,7 @@ public class IrisObjectPlacementRunnerRegressionTest {
|
||||
placer.terrain(x, 0, 0, 80 + x * 3);
|
||||
}
|
||||
|
||||
lineObject(13).place(0, -1, 0, placer, placement().setMode(ObjectPlaceMode.PAINT), new RNG(2L), data);
|
||||
lineObject(13).place(0, 0, placer, placement().setMode(ObjectPlaceMode.PAINT), new RNG(2L), data);
|
||||
|
||||
assertEquals(13, placer.writes().size());
|
||||
assertTrue(placer.writes().stream().allMatch(write -> write.y() == 80 + write.x() * 3));
|
||||
@@ -412,7 +412,7 @@ public class IrisObjectPlacementRunnerRegressionTest {
|
||||
placer.highestFollowsWrites = true;
|
||||
IrisObjectPlacement placement = placement().setMode(ObjectPlaceMode.PAINT).setBore(true);
|
||||
|
||||
boxObject(1, 3, 1).place(0, -1, 0, placer, placement, new RNG(2L), data);
|
||||
boxObject(1, 3, 1).place(0, 0, placer, placement, new RNG(2L), data);
|
||||
|
||||
assertEquals(3, placer.writesOf(solid).size());
|
||||
assertTrue(placer.writes().stream().allMatch(write -> write.y() >= 80 && write.y() <= 82));
|
||||
@@ -430,7 +430,7 @@ public class IrisObjectPlacementRunnerRegressionTest {
|
||||
RNG rng = mock(RNG.class);
|
||||
when(rng.i(0, 3)).thenReturn(3);
|
||||
|
||||
assertEquals(113, lineObject(3).place(0, -1, 0, placer, placement, rng, data));
|
||||
assertEquals(113, lineObject(3).place(0, 0, placer, placement, rng, data));
|
||||
|
||||
assertEquals(3, placer.writesOf(solid).size());
|
||||
assertEquals(3, placer.writesOf(IrisObject.States.air()).size());
|
||||
@@ -450,12 +450,12 @@ public class IrisObjectPlacementRunnerRegressionTest {
|
||||
RNG rng = mock(RNG.class);
|
||||
when(rng.i(0, 3)).thenReturn(3);
|
||||
|
||||
assertEquals(-1, lineObject(3).place(0, -1, 0, placer, placement, rng, data));
|
||||
assertEquals(-1, lineObject(3).place(0, 0, placer, placement, rng, data));
|
||||
assertTrue(placer.writes().isEmpty());
|
||||
|
||||
when(engine.getNativeStructureVolumes(anyInt(), anyInt(), anyInt(), anyInt())).thenReturn(
|
||||
new KList<>(NativeStructureVolume.of("test", 1, 101, 0, 1, 101, 0)));
|
||||
assertEquals(83, lineObject(3).place(0, -1, 0, placer, placement, rng, data));
|
||||
assertEquals(83, lineObject(3).place(0, 0, placer, placement, rng, data));
|
||||
assertTrue(placer.writes().stream().allMatch(write -> write.y() == 85));
|
||||
}
|
||||
|
||||
@@ -473,11 +473,11 @@ public class IrisObjectPlacementRunnerRegressionTest {
|
||||
when(engine.getNativeStructureVolumes(anyInt(), anyInt(), anyInt(), anyInt())).thenReturn(
|
||||
new KList<>(NativeStructureVolume.of("test", 3, 80, 2, 3, 80, 2)));
|
||||
|
||||
assertEquals(-1, lineObject(3).place(0, -1, 0, placer, placement, new RNG(2L), data));
|
||||
assertEquals(-1, lineObject(3).place(0, 0, placer, placement, new RNG(2L), data));
|
||||
assertTrue(placer.writes().isEmpty());
|
||||
|
||||
when(engine.getNativeStructureVolumes(anyInt(), anyInt(), anyInt(), anyInt())).thenReturn(NativeStructureVolume.NONE);
|
||||
lineObject(3).place(0, -1, 0, placer, placement, new RNG(2L), data);
|
||||
lineObject(3).place(0, 0, placer, placement, new RNG(2L), data);
|
||||
assertEquals(3, placer.writes().size());
|
||||
assertTrue(placer.writes().stream().allMatch(write -> write.x() >= 1 && write.x() <= 3
|
||||
&& write.z() == 2 && write.y() == 80));
|
||||
@@ -490,7 +490,7 @@ public class IrisObjectPlacementRunnerRegressionTest {
|
||||
IrisObjectPlacement placement = placement().setMode(ObjectPlaceMode.PAINT)
|
||||
.setRequireSurfaceSupport(true).setSurfaceSupportBuffer(0).setSurfaceSupportDepth(2);
|
||||
|
||||
assertEquals(-1, lineObject(3).place(0, -1, 0, placer, placement, new RNG(2L), data));
|
||||
assertEquals(-1, lineObject(3).place(0, 0, placer, placement, new RNG(2L), data));
|
||||
assertTrue(placer.writes().isEmpty());
|
||||
}
|
||||
|
||||
@@ -711,7 +711,7 @@ public class IrisObjectPlacementRunnerRegressionTest {
|
||||
IrisObjectPlacement placement = new IrisObjectPlacement()
|
||||
.setRotation(IrisObjectRotation.of(0, 0, 0));
|
||||
|
||||
assertTrue(tree.place(0, -1, 0, placer, placement, new RNG(2L), data) >= 0);
|
||||
assertTrue(tree.place(0, 0, placer, placement, new RNG(2L), data) >= 0);
|
||||
|
||||
assertSame(wood, placer.get(1, 167, 0));
|
||||
assertNull(placer.get(1, 166, 0));
|
||||
|
||||
+2
@@ -88,6 +88,7 @@ public class IrisObjectPlacementToPlacementTest {
|
||||
source.setAllowedCollisions(allowedCollisions);
|
||||
source.setForbiddenCollisions(forbiddenCollisions);
|
||||
source.setForcePlace(true);
|
||||
source.setForcedByStructure(true);
|
||||
|
||||
IrisObjectPlacement copy = source.toPlacement("objects/replaced");
|
||||
|
||||
@@ -132,5 +133,6 @@ public class IrisObjectPlacementToPlacementTest {
|
||||
assertSame(allowedCollisions, copy.getAllowedCollisions());
|
||||
assertSame(forbiddenCollisions, copy.getForbiddenCollisions());
|
||||
assertTrue(copy.isForcePlace());
|
||||
assertTrue(copy.isForcedByStructure());
|
||||
}
|
||||
}
|
||||
+12
-19
@@ -68,7 +68,7 @@ public class IrisObjectSurfaceSupportPlacementTest {
|
||||
placer.carve(0, SURFACE_Y, 0);
|
||||
|
||||
assertEquals("mode " + mode + " must skip over a carved column",
|
||||
-1, place(placer, placement(mode), -1));
|
||||
-1, place(placer, placement(mode)));
|
||||
assertTrue("mode " + mode + " must not write blocks", placer.written().isEmpty());
|
||||
}
|
||||
}
|
||||
@@ -78,7 +78,7 @@ public class IrisObjectSurfaceSupportPlacementTest {
|
||||
SurfacePlacer placer = new SurfacePlacer();
|
||||
placer.carve(2, SURFACE_Y, 0);
|
||||
|
||||
assertEquals(-1, place(placer, placement(ObjectPlaceMode.CENTER_HEIGHT), -1));
|
||||
assertEquals(-1, place(placer, placement(ObjectPlaceMode.CENTER_HEIGHT)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -86,14 +86,14 @@ public class IrisObjectSurfaceSupportPlacementTest {
|
||||
SurfacePlacer placer = new SurfacePlacer();
|
||||
placer.carve(6, SURFACE_Y, 0);
|
||||
|
||||
assertTrue(place(placer, placement(ObjectPlaceMode.CENTER_HEIGHT), -1) >= 0);
|
||||
assertTrue(place(placer, placement(ObjectPlaceMode.CENTER_HEIGHT)) >= 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void solidGroundStillPlaces() {
|
||||
SurfacePlacer placer = new SurfacePlacer();
|
||||
|
||||
assertTrue(place(placer, placement(ObjectPlaceMode.CENTER_HEIGHT), -1) >= 0);
|
||||
assertTrue(place(placer, placement(ObjectPlaceMode.CENTER_HEIGHT)) >= 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -101,18 +101,7 @@ public class IrisObjectSurfaceSupportPlacementTest {
|
||||
when(complex.hasWaterOrShore(0, 0)).thenReturn(true);
|
||||
SurfacePlacer placer = new SurfacePlacer(engine);
|
||||
|
||||
assertEquals(-1, place(placer, placement(ObjectPlaceMode.CENTER_HEIGHT), -1));
|
||||
assertTrue(placer.written().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void automaticForcePlacementCannotOverlapRiverWater() {
|
||||
when(complex.hasWaterOrShore(0, 0)).thenReturn(true);
|
||||
SurfacePlacer placer = new SurfacePlacer(engine);
|
||||
IrisObjectPlacement placement = placement(ObjectPlaceMode.CENTER_HEIGHT);
|
||||
placement.setForcePlace(true);
|
||||
|
||||
assertEquals(-1, place(placer, placement, -1));
|
||||
assertEquals(-1, place(placer, placement(ObjectPlaceMode.CENTER_HEIGHT)));
|
||||
assertTrue(placer.written().isEmpty());
|
||||
}
|
||||
|
||||
@@ -140,7 +129,7 @@ public class IrisObjectSurfaceSupportPlacementTest {
|
||||
IrisObjectPlacement placement = placement(ObjectPlaceMode.CENTER_HEIGHT);
|
||||
placement.setForcePlace(true);
|
||||
|
||||
assertTrue(place(placer, placement, -1) >= 0);
|
||||
assertTrue(place(placer, placement) >= 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -150,7 +139,7 @@ public class IrisObjectSurfaceSupportPlacementTest {
|
||||
IrisObjectPlacement placement = placement(ObjectPlaceMode.CENTER_HEIGHT);
|
||||
placement.setRequireSurfaceSupport(false);
|
||||
|
||||
assertTrue(place(placer, placement, -1) >= 0);
|
||||
assertTrue(place(placer, placement) >= 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -235,7 +224,11 @@ public class IrisObjectSurfaceSupportPlacementTest {
|
||||
IrisObjectPlacement placement = placement(ObjectPlaceMode.FLOATING);
|
||||
placement.setTranslate(new IrisObjectTranslate().setY(SURFACE_Y + 40));
|
||||
|
||||
assertTrue(place(placer, placement, -1) >= 0);
|
||||
assertTrue(place(placer, placement) >= 0);
|
||||
}
|
||||
|
||||
private int place(SurfacePlacer placer, IrisObjectPlacement placement) {
|
||||
return object().place(0, 0, placer, placement, new RNG(1234L), data);
|
||||
}
|
||||
|
||||
private int place(SurfacePlacer placer, IrisObjectPlacement placement, int anchorY) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.structure.object;
|
||||
|
||||
import art.arcane.iris.generation.hydrology.raster.WaterRole;
|
||||
import art.arcane.iris.generation.block.BlockDataMergeSupport;
|
||||
import art.arcane.iris.generation.block.IrisBlockData;
|
||||
import art.arcane.iris.generation.block.TileData;
|
||||
@@ -47,6 +48,7 @@ import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@@ -110,8 +112,11 @@ public class ObjectPlacementGoldenTest {
|
||||
|
||||
ProceduralStream<NativeBlockState> rock = mock(ProceduralStream.class, withSettings().stubOnly());
|
||||
when(rock.get(anyDouble(), anyDouble())).thenAnswer(invocation -> state("minecraft:stone"));
|
||||
ProceduralStream<WaterRole> roles = mock(ProceduralStream.class, withSettings().stubOnly());
|
||||
when(roles.get(anyDouble(), anyDouble())).thenReturn(WaterRole.NONE);
|
||||
IrisComplex complex = mock(IrisComplex.class, withSettings().stubOnly());
|
||||
when(complex.getRockStream()).thenReturn(rock);
|
||||
when(complex.getWaterRoleStream()).thenReturn(roles);
|
||||
IrisDimension dimension = mock(IrisDimension.class, withSettings().stubOnly());
|
||||
engine = mock(Engine.class, withSettings().stubOnly());
|
||||
when(engine.getHeight()).thenReturn(256);
|
||||
@@ -154,16 +159,15 @@ public class ObjectPlacementGoldenTest {
|
||||
List<String> listened = new ArrayList<>();
|
||||
int x = 400 + index * 3 + seed;
|
||||
int z = -900 + rotationIndex * 5 - seed;
|
||||
int y = explicitY ? 90 + seed : -1;
|
||||
BiConsumer<BlockPosition, NativeBlockState> listener =
|
||||
(position, state) -> listened.add(position.getX() + "," + position.getY() + "," + position.getZ() + "=" + state.key());
|
||||
int result;
|
||||
if (placement.getMode() == ObjectPlaceMode.ORGANIC_STILT && explicitY && seed % 2 == 0) {
|
||||
result = object.placeOnFloor(x, 70, z, placer, placement, rng,
|
||||
(position, state) -> listened.add(position.getX() + "," + position.getY() + "," + position.getZ() + "=" + state.key()),
|
||||
data);
|
||||
result = object.placeOnFloor(x, 70, z, placer, placement, rng, listener, data);
|
||||
} else if (explicitY) {
|
||||
result = object.place(x, 90 + seed, z, placer, placement, rng, listener, null, data);
|
||||
} else {
|
||||
result = object.place(x, y, z, placer, placement, rng,
|
||||
(position, state) -> listened.add(position.getX() + "," + position.getY() + "," + position.getZ() + "=" + state.key()),
|
||||
null, data);
|
||||
result = object.place(x, z, placer, placement, rng, listener, null, data);
|
||||
}
|
||||
long hash = placer.hash;
|
||||
hash = mix(hash, result);
|
||||
@@ -245,8 +249,9 @@ public class ObjectPlacementGoldenTest {
|
||||
for (int seed = 0; seed < 150; seed++) {
|
||||
RNG rng = new RNG(index * 104_729L + seed);
|
||||
GoldenPlacer placer = new GoldenPlacer(engine, (seed & 1) == 0);
|
||||
int y = seed % 3 == 0 ? 90 + (seed & 7) : -1;
|
||||
int result = object.place(300 + seed, y, -400 + index * 7, placer, placement, rng, null, null, data);
|
||||
int result = seed % 3 == 0
|
||||
? object.place(300 + seed, 90 + (seed & 7), -400 + index * 7, placer, placement, rng, null, null, data)
|
||||
: object.place(300 + seed, -400 + index * 7, placer, placement, rng, null, null, data);
|
||||
long hash = mix(placer.hash, result);
|
||||
hash = mix(hash, rng.nextLong());
|
||||
combined = mix(combined, hash);
|
||||
|
||||
@@ -149,8 +149,8 @@ public class PlacementLifecycleTest {
|
||||
when(object.getW()).thenReturn(3);
|
||||
when(object.getH()).thenReturn(1);
|
||||
when(object.getD()).thenReturn(1);
|
||||
PlacementContext context = new PlacementContext(config, mock(IrisData.class), placer, null,
|
||||
new RNG(1), object, x, 0, -1, null);
|
||||
PlacementContext context = PlacementContext.automatic(config, mock(IrisData.class), placer, null,
|
||||
new RNG(1), object, IrisObjectPlacementAlignment.CENTER, x, 0, null);
|
||||
PlacementState state = new PlacementState(context);
|
||||
plan.run(PlacementStage.PREPARE, context, state, null);
|
||||
plan.run(PlacementStage.HEIGHT, context, state, null);
|
||||
@@ -168,8 +168,8 @@ public class PlacementLifecycleTest {
|
||||
builder.add(id("dependent"), PlacementStage.HEIGHT, (c, s, v) -> s.y = 99, id("guard"));
|
||||
PlacementLifecycle plan = builder.build();
|
||||
IrisObjectPlacement config = new IrisObjectPlacement();
|
||||
PlacementContext context = new PlacementContext(config, mock(IrisData.class), mock(IObjectPlacer.class),
|
||||
null, new RNG(1), mock(IrisObject.class), 0, 0, -1, null);
|
||||
PlacementContext context = PlacementContext.automatic(config, mock(IrisData.class), mock(IObjectPlacer.class),
|
||||
null, new RNG(1), mock(IrisObject.class), IrisObjectPlacementAlignment.CENTER, 0, 0, null);
|
||||
PlacementState rejected = new PlacementState(context);
|
||||
plan.run(PlacementStage.HEIGHT, context, rejected, null);
|
||||
assertEquals(-1, rejected.heightOrRejected());
|
||||
|
||||
+215
@@ -0,0 +1,215 @@
|
||||
package art.arcane.iris.structure.object;
|
||||
|
||||
import art.arcane.iris.generation.hydrology.raster.WaterRole;
|
||||
import art.arcane.iris.generation.stream.ProvisionalAnswerException;
|
||||
import art.arcane.iris.testsupport.PlatformBinding;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class PlacementModuleSurfaceSupportTest {
|
||||
@Rule
|
||||
public final PlatformBinding platform = PlatformBinding.mockPlatform();
|
||||
|
||||
private final HydrologyWaterFixture world = new HydrologyWaterFixture();
|
||||
|
||||
@Test
|
||||
public void underwaterObjectsPlaceInPonds() {
|
||||
world.water(WaterRole.POND, 7, 13);
|
||||
HydrologyWaterFixture.Placer placer = world.placer();
|
||||
|
||||
assertTrue(place(HydrologyWaterFixture.pillar(), placer, underwater()) >= 0);
|
||||
assertFalse(placer.writes().isEmpty());
|
||||
assertEquals(world.floorAt(0, 0), placer.lowestWrite());
|
||||
assertTrue(placer.highestWrite() < world.headAt(0, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void underwaterObjectsSkipWaterTooShallowForTheirResolvedY() {
|
||||
world.water(WaterRole.POND, 9, 13);
|
||||
HydrologyWaterFixture.Placer deep = world.placer();
|
||||
assertTrue(place(HydrologyWaterFixture.pillar(), deep, underwater()) >= 0);
|
||||
|
||||
world.water(WaterRole.POND, 10, 13);
|
||||
HydrologyWaterFixture.Placer shallow = world.placer();
|
||||
assertEquals(-1, place(HydrologyWaterFixture.pillar(), shallow, underwater()));
|
||||
assertTrue(shallow.writes().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void underwaterObjectsTreatLavaPondsLikeLavaSeas() {
|
||||
NativeBlockState lava = mock(NativeBlockState.class);
|
||||
when(lava.key()).thenReturn("minecraft:lava");
|
||||
when(world.complex().resolveWaterFluid(anyInt(), anyInt())).thenReturn(lava);
|
||||
world.water(WaterRole.POND, 7, 13);
|
||||
HydrologyWaterFixture.Placer placer = world.placer();
|
||||
|
||||
assertTrue(place(HydrologyWaterFixture.pillar(), placer, underwater()) >= 0);
|
||||
assertEquals(world.floorAt(0, 0), placer.lowestWrite());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onwaterObjectsFloatOnRivers() {
|
||||
world.water(WaterRole.CHANNEL, 9, 13);
|
||||
HydrologyWaterFixture.Placer placer = world.placer();
|
||||
|
||||
assertTrue(place(HydrologyWaterFixture.pillar(), placer, onwater()) >= 0);
|
||||
assertEquals(world.headAt(0, 0), placer.lowestWrite());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onwaterObjectsSkipDryColumns() {
|
||||
HydrologyWaterFixture.Placer placer = world.placer();
|
||||
|
||||
assertEquals(-1, place(HydrologyWaterFixture.pillar(), placer, onwater()));
|
||||
assertTrue(placer.writes().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void forcePlaceObjectsPlaceInRiverWater() {
|
||||
world.water(WaterRole.CHANNEL, 9, 13);
|
||||
HydrologyWaterFixture.Placer placer = world.placer();
|
||||
|
||||
assertTrue(place(HydrologyWaterFixture.pillar(), placer, forced()) >= 0);
|
||||
assertEquals(world.headAt(0, 0), placer.lowestWrite());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void landObjectsStayOutOfRiverWater() {
|
||||
world.water(WaterRole.CHANNEL, 9, 13);
|
||||
HydrologyWaterFixture.Placer placer = world.placer();
|
||||
|
||||
assertEquals(-1, place(HydrologyWaterFixture.pillar(), placer, placement()));
|
||||
assertTrue(placer.writes().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void flatPondsTakeWideWaterObjects() {
|
||||
world.water(WaterRole.POND, 5, 13);
|
||||
|
||||
for (IrisObjectPlacement placement : List.of(underwater(), onwater(), forced())) {
|
||||
HydrologyWaterFixture.Placer placer = world.placer();
|
||||
|
||||
assertTrue(place(HydrologyWaterFixture.raft(), placer, placement) >= 0);
|
||||
assertFalse(placer.writes().isEmpty());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onwaterObjectsSkipCascadeSteps() {
|
||||
world.water(WaterRole.CHANNEL, 9, 13);
|
||||
world.column(1, 0, WaterRole.CASCADE, 8, 11);
|
||||
HydrologyWaterFixture.Placer placer = world.placer();
|
||||
|
||||
assertEquals(-1, place(HydrologyWaterFixture.raft(), placer, onwater()));
|
||||
assertTrue(placer.writes().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void underwaterObjectsSkipDamWalls() {
|
||||
world.water(WaterRole.POND, 5, 13);
|
||||
world.column(1, 0, WaterRole.DAM, 14, 0);
|
||||
HydrologyWaterFixture.Placer placer = world.placer();
|
||||
|
||||
assertEquals(-1, place(HydrologyWaterFixture.raft(), placer, underwater()));
|
||||
assertTrue(placer.writes().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void waterObjectsSkipWaterAtAnotherHead() {
|
||||
world.water(WaterRole.CHANNEL, 9, 13);
|
||||
world.column(1, 0, WaterRole.CHANNEL, 8, 12);
|
||||
|
||||
for (IrisObjectPlacement placement : List.of(underwater(), onwater(), forced())) {
|
||||
HydrologyWaterFixture.Placer placer = world.placer();
|
||||
|
||||
assertEquals(-1, place(HydrologyWaterFixture.raft(), placer, placement));
|
||||
assertTrue(placer.writes().isEmpty());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void waterObjectsNeverPlaceOnProvisionalHydrology() {
|
||||
world.water(WaterRole.POND, 7, 13);
|
||||
world.provisional();
|
||||
|
||||
for (IrisObjectPlacement placement : List.of(underwater(), onwater(), forced())) {
|
||||
HydrologyWaterFixture.Placer placer = world.placer();
|
||||
|
||||
ProvisionalAnswerException error = assertThrows(ProvisionalAnswerException.class,
|
||||
() -> place(HydrologyWaterFixture.pillar(), placer, placement));
|
||||
|
||||
assertTrue(error.getMessage().contains("provisional"));
|
||||
assertTrue(placer.writes().isEmpty());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void landObjectsNeverPlaceOnProvisionalHydrology() {
|
||||
world.provisional();
|
||||
HydrologyWaterFixture.Placer placer = world.placer();
|
||||
|
||||
assertThrows(ProvisionalAnswerException.class, () -> place(HydrologyWaterFixture.pillar(), placer, placement()));
|
||||
assertTrue(placer.writes().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void provisionalAnswersStopABoreBeforeItClearsAir() {
|
||||
world.provisional();
|
||||
HydrologyWaterFixture.Placer placer = world.placer();
|
||||
IrisObjectPlacement placement = placement();
|
||||
placement.setBore(true);
|
||||
|
||||
assertThrows(ProvisionalAnswerException.class, () -> place(HydrologyWaterFixture.pillar(), placer, placement));
|
||||
assertTrue(placer.writes().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void explicitPlacementsIgnoreProvisionalAnswers() {
|
||||
world.provisional();
|
||||
HydrologyWaterFixture.Placer placer = world.placer();
|
||||
int surface = world.floorAt(0, 0);
|
||||
|
||||
assertTrue(HydrologyWaterFixture.pillar().place(0, surface + 1, 0, placer, placement(), new RNG(1234L), world.data()) >= 0);
|
||||
assertFalse(placer.writes().isEmpty());
|
||||
}
|
||||
|
||||
private int place(IrisObject object, HydrologyWaterFixture.Placer placer, IrisObjectPlacement placement) {
|
||||
return object.place(0, 0, placer, placement, new RNG(1234L), world.data());
|
||||
}
|
||||
|
||||
private static IrisObjectPlacement placement() {
|
||||
IrisObjectPlacement placement = new IrisObjectPlacement();
|
||||
placement.setMode(ObjectPlaceMode.CENTER_HEIGHT);
|
||||
return placement;
|
||||
}
|
||||
|
||||
private static IrisObjectPlacement underwater() {
|
||||
IrisObjectPlacement placement = placement();
|
||||
placement.setUnderwater(true);
|
||||
return placement;
|
||||
}
|
||||
|
||||
private static IrisObjectPlacement onwater() {
|
||||
IrisObjectPlacement placement = placement();
|
||||
placement.setOnwater(true);
|
||||
return placement;
|
||||
}
|
||||
|
||||
private static IrisObjectPlacement forced() {
|
||||
IrisObjectPlacement placement = placement();
|
||||
placement.setForcePlace(true);
|
||||
return placement;
|
||||
}
|
||||
}
|
||||
@@ -116,7 +116,7 @@ public class TreeGroundingPlacementTest {
|
||||
terrain.heights.put(new Column(1, 0), 70);
|
||||
Map<Position, NativeBlockState> observed = new HashMap<>();
|
||||
|
||||
int result = tree(true).place(0, -1, 0, terrain.placer, placement(), new RNG(42L),
|
||||
int result = tree(true).place(0, 0, terrain.placer, placement(), new RNG(42L),
|
||||
(position, state) -> observed.put(new Position(position.getX(), position.getY(), position.getZ()), state),
|
||||
null, data);
|
||||
|
||||
@@ -143,7 +143,7 @@ public class TreeGroundingPlacementTest {
|
||||
placement.setRotation(IrisObjectRotation.of(0, 90, 0));
|
||||
placement.setTranslate(new IrisObjectTranslate().setX(2).setY(1).setZ(3));
|
||||
|
||||
int result = tree(true).place(10, -1, 20, terrain.placer, placement, new RNG(42L), data);
|
||||
int result = tree(true).place(10, 20, terrain.placer, placement, new RNG(42L), data);
|
||||
|
||||
assertTrue(result >= 0);
|
||||
assertSame(wood, terrain.written.get(new Position(13, 81, 18)));
|
||||
@@ -173,7 +173,7 @@ public class TreeGroundingPlacementTest {
|
||||
terrain.heights.put(new Column(1, 0), 77);
|
||||
Map<Position, NativeBlockState> observed = new HashMap<>();
|
||||
|
||||
int result = tree(true).place(0, -1, 0, terrain.placer, placement(), new RNG(42L),
|
||||
int result = tree(true).place(0, 0, terrain.placer, placement(), new RNG(42L),
|
||||
(position, state) -> observed.put(new Position(position.getX(), position.getY(), position.getZ()), state),
|
||||
null, data);
|
||||
|
||||
@@ -322,14 +322,14 @@ public class TreeGroundingPlacementTest {
|
||||
Terrain terrain = new Terrain();
|
||||
IrisObject earlier = tree(true);
|
||||
earlier.getBlocks().put(new IrisBlockVector(0, 1, 0), wood);
|
||||
assertTrue(earlier.place(4, -1, 0, terrain.placer, placement(), new RNG(42L), data) >= 0);
|
||||
assertTrue(earlier.place(4, 0, terrain.placer, placement(), new RNG(42L), data) >= 0);
|
||||
IrisObject later = tree(true);
|
||||
later.getBlocks().put(new IrisBlockVector(4, 2, 0), leaves);
|
||||
later.setTreeGrounding(TreeGrounding.create(later.getTreeGrounding().roots(), 3,
|
||||
Set.of(new TreeBlockCanvas.Vec(4, 1, 0), new TreeBlockCanvas.Vec(4, 2, 0))));
|
||||
Map<Position, NativeBlockState> observed = new HashMap<>();
|
||||
|
||||
int result = later.place(0, -1, 0, terrain.placer, placement(), new RNG(42L),
|
||||
int result = later.place(0, 0, terrain.placer, placement(), new RNG(42L),
|
||||
(position, state) -> observed.put(new Position(position.getX(), position.getY(), position.getZ()), state),
|
||||
null, data);
|
||||
|
||||
@@ -398,7 +398,7 @@ public class TreeGroundingPlacementTest {
|
||||
}
|
||||
|
||||
private int place(IrisObject tree, Terrain terrain, IrisObjectPlacement placement) {
|
||||
return tree.place(0, -1, 0, terrain.placer, placement, new RNG(42L), data);
|
||||
return tree.place(0, 0, terrain.placer, placement, new RNG(42L), data);
|
||||
}
|
||||
|
||||
private IrisObjectPlacement placement() {
|
||||
|
||||
+81
@@ -26,6 +26,7 @@ import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.SeedManager;
|
||||
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.generation.hydrology.raster.WaterRole;
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
import art.arcane.iris.structure.graph.StructureGraphCatalog;
|
||||
import art.arcane.iris.pack.value.IrisDirection;
|
||||
@@ -45,6 +46,7 @@ import art.arcane.volmlib.util.math.RNG;
|
||||
import art.arcane.volmlib.util.stream.ProceduralStream;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -447,6 +449,77 @@ public class IrisStructureLocatorContractTest {
|
||||
assertEquals(IrisStructureLocator.LocateStatus.NOT_FOUND, result.status());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void irisStructuresAvoidRivers() {
|
||||
Engine engine = densityEngine(1.0, false, -64, 384, -2032, 2032);
|
||||
IrisObject object = engine.getData().load(IrisObject.class, "test:density/object", false);
|
||||
when(object.getW()).thenReturn(10);
|
||||
when(object.getD()).thenReturn(10);
|
||||
Set<Long> river = new HashSet<>();
|
||||
IrisComplex complex = mock(IrisComplex.class);
|
||||
when(engine.getComplex()).thenReturn(complex);
|
||||
when(complex.allowsNewGenerationFootprint(anyInt(), anyInt(), anyInt(), anyInt())).thenReturn(true);
|
||||
@SuppressWarnings("unchecked")
|
||||
ProceduralStream<Double> waterHead = mock(ProceduralStream.class);
|
||||
when(complex.getWaterHeadStream()).thenReturn(waterHead);
|
||||
when(waterHead.get(anyDouble(), anyDouble())).thenReturn(63D);
|
||||
@SuppressWarnings("unchecked")
|
||||
ProceduralStream<WaterRole> roles = mock(ProceduralStream.class);
|
||||
when(complex.getWaterRoleStream()).thenReturn(roles);
|
||||
when(roles.get(anyDouble(), anyDouble())).thenAnswer(call -> river.contains(columnKey(
|
||||
(int) Math.floor(call.<Double>getArgument(0)), (int) Math.floor(call.<Double>getArgument(1))))
|
||||
? WaterRole.CHANNEL : WaterRole.NONE);
|
||||
@SuppressWarnings("unchecked")
|
||||
ProceduralStream<Integer> beds = mock(ProceduralStream.class);
|
||||
when(beds.get(anyDouble(), anyDouble())).thenReturn(120);
|
||||
when(complex.getRoundedHeighteightStream()).thenReturn(beds);
|
||||
when(waterHead.getDouble(anyDouble(), anyDouble())).thenReturn(124D);
|
||||
when(engine.getHeight(anyInt(), anyInt(), eq(true))).thenReturn(128);
|
||||
when(engine.getDimension().getFluidHeight()).thenReturn(63);
|
||||
IrisStructurePlacement placement = engine.getDimension().getStructures().get(0);
|
||||
|
||||
IrisStructureLocator.ResolvedPlacement dry = IrisStructureLocator.resolvePlacement(engine, placement, 3, 4);
|
||||
assertNotNull(dry);
|
||||
assertEquals(1, dry.pieces().size());
|
||||
PlacedStructurePiece piece = dry.pieces().getFirst();
|
||||
int columns = (piece.getMaxX() - piece.getMinX() + 1) * (piece.getMaxZ() - piece.getMinZ() + 1);
|
||||
int allowed = columns / 10;
|
||||
assertTrue("the footprint must span enough columns to tell 10% apart", allowed >= 4);
|
||||
for (int index = 0; index < allowed; index++) {
|
||||
river.add(columnKey(piece.getMinX() + index, piece.getMinZ()));
|
||||
}
|
||||
|
||||
assertNotNull("a footprint at most 10% river keeps its structure",
|
||||
IrisStructureLocator.resolvePlacement(engine, placement, 3, 4));
|
||||
|
||||
river.add(columnKey(piece.getMinX(), piece.getMaxZ()));
|
||||
assertNull("a footprint more than 10% river is skipped",
|
||||
IrisStructureLocator.resolvePlacement(engine, placement, 3, 4));
|
||||
|
||||
placement.setAllowWater(true);
|
||||
assertNotNull(IrisStructureLocator.resolvePlacement(engine, placement, 3, 4));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void undergroundIrisStructuresIgnoreRiversAbove() {
|
||||
Engine engine = densityEngine(1.0, true, -64, 384, -40, -20);
|
||||
IrisComplex complex = mock(IrisComplex.class);
|
||||
when(engine.getComplex()).thenReturn(complex);
|
||||
when(complex.allowsNewGenerationFootprint(anyInt(), anyInt(), anyInt(), anyInt())).thenReturn(true);
|
||||
@SuppressWarnings("unchecked")
|
||||
ProceduralStream<Double> waterHead = mock(ProceduralStream.class);
|
||||
when(complex.getWaterHeadStream()).thenReturn(waterHead);
|
||||
when(waterHead.get(anyDouble(), anyDouble())).thenReturn(63D);
|
||||
@SuppressWarnings("unchecked")
|
||||
ProceduralStream<WaterRole> roles = mock(ProceduralStream.class);
|
||||
when(complex.getWaterRoleStream()).thenReturn(roles);
|
||||
when(roles.get(anyDouble(), anyDouble())).thenReturn(WaterRole.CHANNEL);
|
||||
when(engine.getHeight(anyInt(), anyInt(), eq(true))).thenReturn(128);
|
||||
IrisStructurePlacement placement = engine.getDimension().getStructures().get(0);
|
||||
|
||||
assertNotNull(IrisStructureLocator.resolvePlacement(engine, placement, 3, 4));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void locateRanksEditableStartsByResolvedBlockOrigin() {
|
||||
Engine engine = densityEngine(1.0, false, -64, 384, -2032, 2032);
|
||||
@@ -457,6 +530,10 @@ public class IrisStructureLocatorContractTest {
|
||||
ProceduralStream<Double> waterHead = mock(ProceduralStream.class);
|
||||
when(complex.getWaterHeadStream()).thenReturn(waterHead);
|
||||
when(waterHead.get(anyDouble(), anyDouble())).thenReturn(63D);
|
||||
@SuppressWarnings("unchecked")
|
||||
ProceduralStream<WaterRole> roles = mock(ProceduralStream.class);
|
||||
when(complex.getWaterRoleStream()).thenReturn(roles);
|
||||
when(roles.get(anyDouble(), anyDouble())).thenReturn(WaterRole.NONE);
|
||||
when(engine.getAllBiomes()).thenReturn(new KList<>());
|
||||
when(engine.getHeight(anyInt(), anyInt(), eq(true))).thenReturn(128);
|
||||
when(engine.getDimension().getFluidHeight()).thenReturn(63);
|
||||
@@ -826,6 +903,10 @@ public class IrisStructureLocatorContractTest {
|
||||
return dx * dx + dz * dz;
|
||||
}
|
||||
|
||||
private static long columnKey(int x, int z) {
|
||||
return ((long) x << 32) ^ (z & 0xffffffffL);
|
||||
}
|
||||
|
||||
private PlacedStructurePiece piece(int minX, int minY, int minZ, int maxX, int maxY, int maxZ) {
|
||||
return new PlacedStructurePiece(null, null, 0, 0, 0, null, minX, minY, minZ, maxX, maxY, maxZ);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,163 @@
|
||||
package art.arcane.iris.world.tree;
|
||||
|
||||
import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.iris.generation.decoration.tree.IrisTree;
|
||||
import art.arcane.iris.generation.decoration.tree.IrisTreeSize;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.EngineTarget;
|
||||
import art.arcane.iris.generation.runtime.GenerationSessionManager;
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
import art.arcane.iris.generation.terrain.IrisDimension;
|
||||
import art.arcane.iris.pack.validation.PackCompatReport;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.pack.loading.ResourceLoader;
|
||||
import art.arcane.iris.platform.generation.PlatformChunkGenerator;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.structure.object.IrisObject;
|
||||
import art.arcane.iris.structure.object.IrisObjectPlacement;
|
||||
import art.arcane.iris.testsupport.PlatformBinding;
|
||||
import art.arcane.iris.world.IrisToolbelt;
|
||||
import art.arcane.iris.world.IrisWorld;
|
||||
import art.arcane.iris.world.task.J;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.data.Cuboid;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.TreeType;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.event.world.StructureGrowEvent;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.mockito.MockedStatic;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.mockStatic;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class TreeSVCSaplingTest {
|
||||
private static final int SAPLING_Y = -20;
|
||||
|
||||
@Rule
|
||||
public final PlatformBinding platform = PlatformBinding.mockPlatform();
|
||||
|
||||
@Test
|
||||
public void saplingBelowZeroGrowsAtItsOwnHeight() {
|
||||
Fixture fixture = new Fixture(SAPLING_Y);
|
||||
StructureGrowEvent event = fixture.event();
|
||||
|
||||
fixture.grow(event);
|
||||
|
||||
assertTrue(event.isCancelled());
|
||||
verify(fixture.saplings).forEach(any());
|
||||
verify(fixture.world).getBlockAt(8, SAPLING_Y, 8);
|
||||
verify(fixture.world).getBlockAt(8, SAPLING_Y + 1, 8);
|
||||
verify(fixture.block, times(2)).getState();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectedTreeKeepsTheSapling() {
|
||||
Fixture fixture = new Fixture(0);
|
||||
StructureGrowEvent event = fixture.event();
|
||||
|
||||
fixture.grow(event);
|
||||
|
||||
assertTrue(event.isCancelled());
|
||||
verify(fixture.saplings, never()).forEach(any());
|
||||
verify(fixture.block, never()).getState();
|
||||
}
|
||||
|
||||
private static final class Fixture {
|
||||
private final Engine engine = mock(Engine.class);
|
||||
private final World world = mock(World.class);
|
||||
private final PlatformChunkGenerator generator = mock(PlatformChunkGenerator.class);
|
||||
private final TreeSVC service = spy(new TreeSVC());
|
||||
private final Cuboid saplings = mock(Cuboid.class);
|
||||
private final Block block = mock(Block.class);
|
||||
|
||||
private Fixture(int lowestTreeY) {
|
||||
IrisDimension dimension = new IrisDimension();
|
||||
dimension.getTreeSettings().setEnabled(true);
|
||||
IrisComplex complex = mock(IrisComplex.class);
|
||||
when(engine.getGenerationSessions()).thenReturn(new GenerationSessionManager(true));
|
||||
when(engine.getDimension()).thenReturn(dimension);
|
||||
when(engine.getComplex()).thenReturn(complex);
|
||||
when(engine.getBiome(8, SAPLING_Y, 8)).thenReturn(biome(lowestTreeY));
|
||||
|
||||
EngineTarget target = mock(EngineTarget.class);
|
||||
when(target.getWorld()).thenReturn(mock(IrisWorld.class));
|
||||
@SuppressWarnings("unchecked")
|
||||
ResourceLoader<IrisObject> objects = mock(ResourceLoader.class);
|
||||
IrisObject tree = tree();
|
||||
when(objects.load(anyString())).thenReturn(tree);
|
||||
IrisData data = mock(IrisData.class);
|
||||
when(data.getObjectLoader()).thenReturn(objects);
|
||||
when(data.getCompatReport()).thenReturn(mock(PackCompatReport.class));
|
||||
when(generator.getEngine()).thenReturn(engine);
|
||||
when(generator.getTarget()).thenReturn(target);
|
||||
when(generator.getData()).thenReturn(data);
|
||||
|
||||
BlockData blockData = mock(BlockData.class);
|
||||
when(world.getBlockAt(anyInt(), anyInt(), anyInt())).thenReturn(block);
|
||||
when(world.getBlockAt(any(Location.class))).thenReturn(block);
|
||||
when(block.getBlockData()).thenReturn(blockData);
|
||||
when(block.getState()).thenReturn(mock(BlockState.class));
|
||||
when(blockData.clone()).thenReturn(blockData);
|
||||
when(saplings.getCenter()).thenReturn(new Location(world, 8, SAPLING_Y, 8));
|
||||
doReturn(saplings).when(service).getSaplings(any(), any(), any());
|
||||
}
|
||||
|
||||
private static IrisObject tree() {
|
||||
NativeBlockState log = mock(NativeBlockState.class);
|
||||
when(log.isSolid()).thenReturn(true);
|
||||
when(log.key()).thenReturn("minecraft:oak_log");
|
||||
when(log.materialKey()).thenReturn("minecraft:oak_log");
|
||||
when(log.nativeHandle()).thenReturn(mock(BlockData.class));
|
||||
IrisObject object = new IrisObject(3, 3, 3);
|
||||
object.setUnsigned(1, 0, 1, log);
|
||||
object.setUnsigned(1, 1, 1, log);
|
||||
return object;
|
||||
}
|
||||
|
||||
private static IrisBiome biome(int lowestTreeY) {
|
||||
IrisTree tree = new IrisTree();
|
||||
tree.getTreeTypes().add(TreeType.TREE.name());
|
||||
tree.getSizes().add(new IrisTreeSize());
|
||||
IrisObjectPlacement placement = new IrisObjectPlacement();
|
||||
placement.getPlace().add("trees/oak");
|
||||
placement.getTrees().add(tree);
|
||||
placement.setRequireSurfaceSupport(false);
|
||||
placement.getClamp().setMinimumHeight(lowestTreeY);
|
||||
IrisBiome biome = new IrisBiome();
|
||||
biome.getObjects().add(placement);
|
||||
return biome;
|
||||
}
|
||||
|
||||
private StructureGrowEvent event() {
|
||||
return new StructureGrowEvent(new Location(world, 8, SAPLING_Y, 8), TreeType.TREE, false, null, List.of());
|
||||
}
|
||||
|
||||
private void grow(StructureGrowEvent event) {
|
||||
try (MockedStatic<IrisToolbelt> toolbelt = mockStatic(IrisToolbelt.class);
|
||||
MockedStatic<IrisLogging> logging = mockStatic(IrisLogging.class);
|
||||
MockedStatic<J> tasks = mockStatic(J.class)) {
|
||||
toolbelt.when(() -> IrisToolbelt.isIrisWorld(world)).thenReturn(true);
|
||||
toolbelt.when(() -> IrisToolbelt.access(world)).thenReturn(generator);
|
||||
service.on(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user