mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 00:04:42 +00:00
Fix structure river findings
- End object placements in a finally at all four MantleObjectComponent sites - Split recordObjectPlacement for accepted ranges from endObjectPlacement for the water flag - Place forced single-piece structures after admission and let the MantleWriter veto protect the water - Drop the allowWater parameter from piecePlacement - Validate allowWater as a boolean and add it to anonymous grid identity when true - Add placement exit, forced piece, REPLACE_SOURCE, world Y -1 and placePieces failure tests - Add modded stage river start and policy water tests - Rename the misleading planner river test
This commit is contained in:
18 files changed
+922
-64
No files matched your search
+107
@@ -0,0 +1,107 @@
|
||||
package art.arcane.iris.modded;
|
||||
|
||||
import art.arcane.volmlib.nativelib.minecraft26_2.modded.NativeModdedStructureStage;
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureOwnershipRecordView;
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureReferencePolicy;
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureStartPlan;
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureWaterColumn;
|
||||
import net.minecraft.SharedConstants;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.server.Bootstrap;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
import net.minecraft.world.level.levelgen.structure.BoundingBox;
|
||||
import net.minecraft.world.level.levelgen.structure.Structure;
|
||||
import net.minecraft.world.level.levelgen.structure.StructurePiece;
|
||||
import net.minecraft.world.level.levelgen.structure.StructureStart;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
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 ModdedNativeStructureRiverStartTest {
|
||||
private static final String KEY = "minecraft:village_plains";
|
||||
|
||||
@BeforeClass
|
||||
public static void bootstrap() {
|
||||
SharedConstants.tryDetectVersion();
|
||||
Bootstrap.bootStrap();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void plannedStartsWhosePiecesReachARiverBeyondTheStartChunkAreInvalidated() {
|
||||
Fixture fixture = new Fixture(35);
|
||||
|
||||
fixture.adjust(fixture.plan(false));
|
||||
|
||||
verify(fixture.chunk).setStartForStructure(fixture.structure, StructureStart.INVALID_START);
|
||||
verify(fixture.structures).discard(KEY, 0, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void plannedStartsWithinTheLimitOrAllowingWaterKeepTheirStart() {
|
||||
Fixture within = new Fixture(36);
|
||||
within.adjust(within.plan(false));
|
||||
verify(within.chunk, never()).setStartForStructure(any(), any());
|
||||
|
||||
Fixture flooded = new Fixture(35);
|
||||
flooded.adjust(flooded.plan(true));
|
||||
verify(flooded.chunk, never()).setStartForStructure(any(), any());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static final class Fixture {
|
||||
private final NativeModdedStructureStage.Policy<Object, StructureStartPlan, Ownership> policy = mock(NativeModdedStructureStage.Policy.class);
|
||||
private final StructureReferencePolicy<StructureStartPlan, Ownership> structures = mock(StructureReferencePolicy.class);
|
||||
private final RegistryAccess registries = mock(RegistryAccess.class);
|
||||
private final ChunkAccess chunk = mock(ChunkAccess.class);
|
||||
private final Structure structure = mock(Structure.class);
|
||||
private final NativeModdedStructureStage<Object, StructureStartPlan, Ownership> stage;
|
||||
|
||||
private Fixture(int riverEdgeX) {
|
||||
Registry<Structure> registry = mock(Registry.class);
|
||||
StructureStart start = mock(StructureStart.class);
|
||||
StructurePiece home = mock(StructurePiece.class);
|
||||
StructurePiece road = mock(StructurePiece.class);
|
||||
when(registries.lookupOrThrow(Registries.STRUCTURE)).thenReturn(registry);
|
||||
when(registry.getKey(structure)).thenReturn(Identifier.parse(KEY));
|
||||
when(chunk.getPos()).thenReturn(new ChunkPos(0, 0));
|
||||
when(chunk.getAllStarts()).thenReturn(Map.of(structure, start));
|
||||
when(start.isValid()).thenReturn(true);
|
||||
when(start.getChunkPos()).thenReturn(new ChunkPos(0, 0));
|
||||
when(start.getBoundingBox()).thenReturn(new BoundingBox(0, 60, 0, 39, 70, 15));
|
||||
when(home.getBoundingBox()).thenReturn(new BoundingBox(0, 60, 0, 15, 70, 15));
|
||||
when(road.getBoundingBox()).thenReturn(new BoundingBox(16, 64, 0, 39, 65, 15));
|
||||
when(start.getPieces()).thenReturn(List.of(home, road));
|
||||
when(policy.allowsFootprint(any(), any())).thenReturn(true);
|
||||
when(policy.structurePolicy(any())).thenReturn(structures);
|
||||
when(policy.water(any())).thenReturn((x, z) -> x >= riverEdgeX
|
||||
? new StructureWaterColumn(true, true, 58, 62) : StructureWaterColumn.DRY);
|
||||
stage = new NativeModdedStructureStage<>(new NativeModdedStructureStage.Options<>(null, null, policy));
|
||||
}
|
||||
|
||||
private StructureStartPlan plan(boolean allowWater) {
|
||||
StructureStartPlan plan = mock(StructureStartPlan.class);
|
||||
when(plan.structureKey()).thenReturn(KEY);
|
||||
when(plan.allowWater()).thenReturn(allowWater);
|
||||
return plan;
|
||||
}
|
||||
|
||||
private void adjust(StructureStartPlan plan) {
|
||||
stage.adjustGeneratedStructures(registries, chunk, Map.of(), Map.of(structure, plan), null, null);
|
||||
}
|
||||
}
|
||||
|
||||
private interface Ownership extends StructureOwnershipRecordView<Ownership> {
|
||||
}
|
||||
}
|
||||
+35
@@ -1,6 +1,11 @@
|
||||
package art.arcane.iris.modded;
|
||||
|
||||
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.structure.StructureWater;
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureWaterColumn;
|
||||
import art.arcane.volmlib.util.stream.ProceduralStream;
|
||||
|
||||
import art.arcane.volmlib.nativelib.minecraft26_2.modded.ModdedNativeStructureWorldgenAccess;
|
||||
|
||||
@@ -63,6 +68,9 @@ 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.mockito.ArgumentMatchers.anyDouble;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class ModdedNativeStructureWorldgenAccessTest {
|
||||
private static final int GENERATION_CENTER_X = 60;
|
||||
@@ -76,6 +84,33 @@ public class ModdedNativeStructureWorldgenAccessTest {
|
||||
Bootstrap.bootStrap();
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void policyGivesTheStageRealWaterInWorldHeights() {
|
||||
Engine engine = mock(Engine.class);
|
||||
IrisComplex complex = mock(IrisComplex.class);
|
||||
ProceduralStream<WaterRole> roles = mock(ProceduralStream.class);
|
||||
ProceduralStream<Integer> floors = mock(ProceduralStream.class);
|
||||
ProceduralStream<Double> heads = mock(ProceduralStream.class);
|
||||
when(engine.getComplex()).thenReturn(complex);
|
||||
when(engine.getMinHeight()).thenReturn(-64);
|
||||
when(complex.getWaterRoleStream()).thenReturn(roles);
|
||||
when(complex.getRoundedHeighteightStream()).thenReturn(floors);
|
||||
when(complex.getWaterHeadStream()).thenReturn(heads);
|
||||
when(roles.get(anyDouble(), anyDouble())).thenAnswer(call -> {
|
||||
int x = (int) Math.floor(call.<Number>getArgument(0).doubleValue());
|
||||
return x == 5 ? WaterRole.CHANNEL : x == 6 ? WaterRole.MOUTH : WaterRole.NONE;
|
||||
});
|
||||
when(floors.get(anyDouble(), anyDouble())).thenReturn(120);
|
||||
when(heads.getDouble(anyDouble(), anyDouble())).thenReturn(126D);
|
||||
|
||||
StructureWater water = new ModdedNativeStructurePolicy(mock(IrisModdedChunkGenerator.class)).water(engine);
|
||||
|
||||
assertEquals(new StructureWaterColumn(true, true, 56, 62), water.column(5, 0));
|
||||
assertEquals(new StructureWaterColumn(true, false, 56, 62), water.column(6, 0));
|
||||
assertEquals(StructureWaterColumn.DRY, water.column(7, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ordinaryWorldFlattenPreparationHandlesReferencedVillagePiecesBeyondEightChunks() {
|
||||
int farX = (GENERATION_CENTER_X - 9) << 4;
|
||||
|
||||
+107
@@ -0,0 +1,107 @@
|
||||
package art.arcane.iris.modded;
|
||||
|
||||
import art.arcane.volmlib.nativelib.minecraft26_2.modded.NativeModdedStructureStage;
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureOwnershipRecordView;
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureReferencePolicy;
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureStartPlan;
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureWaterColumn;
|
||||
import net.minecraft.SharedConstants;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.Bootstrap;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
import net.minecraft.world.level.levelgen.structure.BoundingBox;
|
||||
import net.minecraft.world.level.levelgen.structure.Structure;
|
||||
import net.minecraft.world.level.levelgen.structure.StructurePiece;
|
||||
import net.minecraft.world.level.levelgen.structure.StructureStart;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
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 ModdedNativeStructureRiverStartTest {
|
||||
private static final String KEY = "minecraft:village_plains";
|
||||
|
||||
@BeforeClass
|
||||
public static void bootstrap() {
|
||||
SharedConstants.tryDetectVersion();
|
||||
Bootstrap.bootStrap();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void plannedStartsWhosePiecesReachARiverBeyondTheStartChunkAreInvalidated() {
|
||||
Fixture fixture = new Fixture(35);
|
||||
|
||||
fixture.adjust(fixture.plan(false));
|
||||
|
||||
verify(fixture.chunk).setStartForStructure(fixture.structure, StructureStart.INVALID_START);
|
||||
verify(fixture.structures).discard(KEY, 0, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void plannedStartsWithinTheLimitOrAllowingWaterKeepTheirStart() {
|
||||
Fixture within = new Fixture(36);
|
||||
within.adjust(within.plan(false));
|
||||
verify(within.chunk, never()).setStartForStructure(any(), any());
|
||||
|
||||
Fixture flooded = new Fixture(35);
|
||||
flooded.adjust(flooded.plan(true));
|
||||
verify(flooded.chunk, never()).setStartForStructure(any(), any());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static final class Fixture {
|
||||
private final NativeModdedStructureStage.Policy<Object, StructureStartPlan, Ownership> policy = mock(NativeModdedStructureStage.Policy.class);
|
||||
private final StructureReferencePolicy<StructureStartPlan, Ownership> structures = mock(StructureReferencePolicy.class);
|
||||
private final RegistryAccess registries = mock(RegistryAccess.class);
|
||||
private final ChunkAccess chunk = mock(ChunkAccess.class);
|
||||
private final Structure structure = mock(Structure.class);
|
||||
private final NativeModdedStructureStage<Object, StructureStartPlan, Ownership> stage;
|
||||
|
||||
private Fixture(int riverEdgeX) {
|
||||
Registry<Structure> registry = mock(Registry.class);
|
||||
StructureStart start = mock(StructureStart.class);
|
||||
StructurePiece home = mock(StructurePiece.class);
|
||||
StructurePiece road = mock(StructurePiece.class);
|
||||
when(registries.registryOrThrow(Registries.STRUCTURE)).thenReturn(registry);
|
||||
when(registry.getKey(structure)).thenReturn(ResourceLocation.parse(KEY));
|
||||
when(chunk.getPos()).thenReturn(new ChunkPos(0, 0));
|
||||
when(chunk.getAllStarts()).thenReturn(Map.of(structure, start));
|
||||
when(start.isValid()).thenReturn(true);
|
||||
when(start.getChunkPos()).thenReturn(new ChunkPos(0, 0));
|
||||
when(start.getBoundingBox()).thenReturn(new BoundingBox(0, 60, 0, 39, 70, 15));
|
||||
when(home.getBoundingBox()).thenReturn(new BoundingBox(0, 60, 0, 15, 70, 15));
|
||||
when(road.getBoundingBox()).thenReturn(new BoundingBox(16, 64, 0, 39, 65, 15));
|
||||
when(start.getPieces()).thenReturn(List.of(home, road));
|
||||
when(policy.allowsFootprint(any(), any())).thenReturn(true);
|
||||
when(policy.structurePolicy(any())).thenReturn(structures);
|
||||
when(policy.water(any())).thenReturn((x, z) -> x >= riverEdgeX
|
||||
? new StructureWaterColumn(true, true, 58, 62) : StructureWaterColumn.DRY);
|
||||
stage = new NativeModdedStructureStage<>(new NativeModdedStructureStage.Options<>(null, null, policy));
|
||||
}
|
||||
|
||||
private StructureStartPlan plan(boolean allowWater) {
|
||||
StructureStartPlan plan = mock(StructureStartPlan.class);
|
||||
when(plan.structureKey()).thenReturn(KEY);
|
||||
when(plan.allowWater()).thenReturn(allowWater);
|
||||
return plan;
|
||||
}
|
||||
|
||||
private void adjust(StructureStartPlan plan) {
|
||||
stage.adjustGeneratedStructures(registries, chunk, Map.of(), Map.of(structure, plan), null, null);
|
||||
}
|
||||
}
|
||||
|
||||
private interface Ownership extends StructureOwnershipRecordView<Ownership> {
|
||||
}
|
||||
}
|
||||
@@ -165,7 +165,7 @@ public class IrisStructureComponent extends IrisMantleComponent {
|
||||
stilt != null && stilt.isSupportNonOccluding(), placement.isAllowWater());
|
||||
ObjectPlaceMode mode = structure.getPlaceMode();
|
||||
int failedPieces = 0;
|
||||
int water = writer.beginObjectPlacement(run.allowWater());
|
||||
writer.beginObjectPlacement(run.allowWater());
|
||||
try {
|
||||
if (placement.isAnchoredUnderground()) {
|
||||
ObjectPlaceMode undergroundMode = (mode == ObjectPlaceMode.ORGANIC_STILT || mode == ObjectPlaceMode.CEILING_HANG)
|
||||
@@ -190,7 +190,7 @@ public class IrisStructureComponent extends IrisMantleComponent {
|
||||
placeFoundation(writer, run.foundationColumns(), stilt, rng, !placement.isAnchoredUnderground());
|
||||
}
|
||||
} finally {
|
||||
writer.endObjectPlacement(water);
|
||||
writer.endObjectPlacement();
|
||||
}
|
||||
return failedPieces;
|
||||
}
|
||||
@@ -569,7 +569,7 @@ public class IrisStructureComponent extends IrisMantleComponent {
|
||||
boolean sampledHeight) {
|
||||
IrisObject object = p.getObject();
|
||||
String objectKey = object.getLoadKey();
|
||||
IrisObjectPlacement config = piecePlacement(run.structure(), p, mode, run.allowWater());
|
||||
IrisObjectPlacement config = piecePlacement(run.structure(), p, mode);
|
||||
String marker = structurePlacementMarker(run.structure(), p, objectKey);
|
||||
BiConsumer<BlockPosition, NativeBlockState> listener = (position, state) -> {
|
||||
StructureFoundationPlanner.recordBaseCell(
|
||||
@@ -584,8 +584,7 @@ public class IrisStructureComponent extends IrisMantleComponent {
|
||||
: 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) {
|
||||
static IrisObjectPlacement piecePlacement(IrisStructure structure, PlacedStructurePiece piece, ObjectPlaceMode mode) {
|
||||
IrisObjectPlacement config = structure.createLootPlacement(piece.getObject().getLoadKey());
|
||||
config.setMode(mode);
|
||||
config.setRotation(piece.getRotation());
|
||||
@@ -594,7 +593,7 @@ public class IrisStructureComponent extends IrisMantleComponent {
|
||||
}
|
||||
if (mode != ObjectPlaceMode.STRUCTURE_PIECE && mode != ObjectPlaceMode.FLOATING) {
|
||||
config.setForcePlace(true);
|
||||
config.setForcedByStructure(!allowWater);
|
||||
config.setForcedByStructure(true);
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
@@ -794,7 +794,7 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
}, null, getData());
|
||||
}
|
||||
if (placeResult >= 0 && (!carving || commitResult == CaveObjectPlacementTransaction.CommitResult.COMMITTED)) {
|
||||
writer.endObjectPlacement(continuation);
|
||||
writer.recordObjectPlacement(continuation);
|
||||
}
|
||||
if (golden) {
|
||||
IrisLogging.debug("Goldendebug procedural result: chunk=" + x + "," + z
|
||||
@@ -809,6 +809,8 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
GenerationFailures.rethrowEngineFailure(e);
|
||||
IrisLogging.reportError(e);
|
||||
IrisLogging.error("Failed to place procedural object '" + p.getName() + "' in " + scope);
|
||||
} finally {
|
||||
writer.endObjectPlacement();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1027,7 +1029,7 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
}, null, getData());
|
||||
|
||||
if (result >= 0) {
|
||||
writer.endObjectPlacement(continuation);
|
||||
writer.recordObjectPlacement(continuation);
|
||||
placed++;
|
||||
} else {
|
||||
rejected++;
|
||||
@@ -1062,6 +1064,8 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
+ " densityIndex=" + i
|
||||
+ " density=" + density
|
||||
+ " error=" + e.getClass().getSimpleName() + ":" + e.getMessage());
|
||||
} finally {
|
||||
writer.endObjectPlacement();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1216,7 +1220,7 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
int result = contained.resultY();
|
||||
boolean wroteBlocks = contained.commitResult() == CaveObjectPlacementTransaction.CommitResult.COMMITTED;
|
||||
if (wroteBlocks) {
|
||||
writer.endObjectPlacement(continuation);
|
||||
writer.recordObjectPlacement(continuation);
|
||||
placed++;
|
||||
} else {
|
||||
rejected++;
|
||||
@@ -1284,6 +1288,8 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
y,
|
||||
e
|
||||
);
|
||||
} finally {
|
||||
writer.endObjectPlacement();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1395,20 +1401,24 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
boolean treePlacement = isTreePlacement(v, objectPlacement);
|
||||
String marker = placementMarker(v, id, "upper");
|
||||
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);
|
||||
int result;
|
||||
try {
|
||||
result = v.place(xx, anchorY, zz, writer, placement, rng, (b, data) -> {
|
||||
if (marker != null) {
|
||||
writer.setData(b.getX(), b.getY(), b.getZ(), marker);
|
||||
}
|
||||
if (treePlacement && marker != null) {
|
||||
writeTreeMaterial(writer, b.getX(), b.getY(), b.getZ(), data);
|
||||
}
|
||||
if (placement.isDolphinTarget() && placement.isUnderwater() && B.isStorageChest(data)) {
|
||||
writer.setData(b.getX(), b.getY(), b.getZ(), MatterStructurePOI.BURIED_TREASURE);
|
||||
}
|
||||
}, null, getData());
|
||||
if (result >= 0) {
|
||||
writer.recordObjectPlacement(continuation);
|
||||
}
|
||||
if (treePlacement && marker != null) {
|
||||
writeTreeMaterial(writer, b.getX(), b.getY(), b.getZ(), data);
|
||||
}
|
||||
if (placement.isDolphinTarget() && placement.isUnderwater() && B.isStorageChest(data)) {
|
||||
writer.setData(b.getX(), b.getY(), b.getZ(), MatterStructurePOI.BURIED_TREASURE);
|
||||
}
|
||||
}, null, getData());
|
||||
|
||||
if (result >= 0) {
|
||||
writer.endObjectPlacement(continuation);
|
||||
} finally {
|
||||
writer.endObjectPlacement();
|
||||
}
|
||||
if (traceRegen) {
|
||||
IrisLogging.debug("Upper object placement: chunk=" + chunkX + "," + chunkZ
|
||||
|
||||
@@ -227,7 +227,7 @@ public class MantleWriter implements ObjectPassPlacer, AutoCloseable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endObjectPlacement(int checkpoint) {
|
||||
public void endObjectPlacement() {
|
||||
objectWater.remove();
|
||||
}
|
||||
|
||||
|
||||
+6
-2
@@ -79,13 +79,17 @@ final class ObjectDestinationTransaction implements ObjectPassPlacer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endObjectPlacement(int checkpoint) {
|
||||
waterPlacement = false;
|
||||
public void recordObjectPlacement(int checkpoint) {
|
||||
if (checkpoint >= 0 && checkpoint < log.size()) {
|
||||
placements.add(new PlacementRange(checkpoint, log.size()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endObjectPlacement() {
|
||||
waterPlacement = false;
|
||||
}
|
||||
|
||||
void apply(ObjectSourcePlan plan) {
|
||||
int slot = plan.destinationSlot(destinationChunkX, destinationChunkZ);
|
||||
if (slot < 0) {
|
||||
|
||||
@@ -12,7 +12,10 @@ public interface ObjectPassPlacer extends IObjectPlacer {
|
||||
return -1;
|
||||
}
|
||||
|
||||
default void endObjectPlacement(int checkpoint) {
|
||||
default void recordObjectPlacement(int checkpoint) {
|
||||
}
|
||||
|
||||
default void endObjectPlacement() {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -223,6 +223,7 @@ final class PackStructurePlacementValidator {
|
||||
path, placement, "maxHeight", Integer.MIN_VALUE, Integer.MAX_VALUE, blockingErrors);
|
||||
PackJsonFieldChecks.validateOptionalBoolean(path, placement, "underground", blockingErrors);
|
||||
PackJsonFieldChecks.validateOptionalBoolean(path, placement, "underwater", blockingErrors);
|
||||
PackJsonFieldChecks.validateOptionalBoolean(path, placement, "allowWater", blockingErrors);
|
||||
PackJsonFieldChecks.validateOptionalEnum(path, placement, "nativeSuppression",
|
||||
Set.of("NONE", "REPLACE_SOURCE"), blockingErrors);
|
||||
|
||||
@@ -299,6 +300,9 @@ final class PackStructurePlacementValidator {
|
||||
appendIdentity(identity, integerValue(placement, "maxHeight", 2032));
|
||||
appendIdentity(identity, placement.opt("underground") instanceof Boolean underground && underground);
|
||||
appendIdentity(identity, placement.opt("underwater") instanceof Boolean underwater && underwater);
|
||||
if (placement.opt("allowWater") instanceof Boolean allowWater && allowWater) {
|
||||
appendIdentity(identity, "allowWater");
|
||||
}
|
||||
JSONArray structures = placement.optJSONArray("structures");
|
||||
JSONArray nativeStructures = placement.optJSONArray("nativeStructures");
|
||||
if (structures != null && structures.length() > 0) {
|
||||
|
||||
+1
-1
@@ -56,7 +56,7 @@ final class PlacementModuleSurfaceSupport implements PlacementModule {
|
||||
|
||||
private static String hydrologyRejection(PlacementContext context, PlacementState state) {
|
||||
IrisObjectPlacement config = state.config;
|
||||
if (!context.automatic || !config.getCarvingSupport().supportsSurface()
|
||||
if (!context.automatic || config.isForcedByStructure() || !config.getCarvingSupport().supportsSurface()
|
||||
|| config.getMode() == ObjectPlaceMode.FLOATING || config.getMode() == ObjectPlaceMode.STRUCTURE_PIECE) {
|
||||
return null;
|
||||
}
|
||||
|
||||
+39
-4
@@ -26,11 +26,16 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.mockito.InOrder;
|
||||
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
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.ArgumentMatchers.intThat;
|
||||
import static org.mockito.Mockito.atLeastOnce;
|
||||
import static org.mockito.Mockito.calls;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.inOrder;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
@@ -118,10 +123,36 @@ public class IrisStructureComponentCarveWaterTest {
|
||||
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).endObjectPlacement();
|
||||
order.verify(writer).beginObjectPlacement(true);
|
||||
order.verify(writer, calls(1)).set(anyInt(), anyInt(), anyInt(), any(NativeBlockState.class));
|
||||
order.verify(writer).endObjectPlacement(anyInt());
|
||||
order.verify(writer).endObjectPlacement();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aPieceAtWorldYMinusOneKeepsItsExplicitHeight() {
|
||||
KList<PlacedStructurePiece> pieces = slabAt(-1);
|
||||
IrisStructure structure = new IrisStructure().setPlaceMode(ObjectPlaceMode.STRUCTURE_PIECE);
|
||||
|
||||
component.placePieces(writer, new IrisStructurePlacement(), structure, pieces, new RNG(3L));
|
||||
|
||||
verify(writer, atLeastOnce()).set(anyInt(), eq(63), anyInt(), any(NativeBlockState.class));
|
||||
verify(writer, never()).set(anyInt(), intThat(y -> y != 63), anyInt(), any(NativeBlockState.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aFailureInsidePlacePiecesStillEndsTheObjectPlacement() {
|
||||
IllegalStateException failure = new IllegalStateException("piece failed");
|
||||
doThrow(failure).when(writer).set(anyInt(), anyInt(), anyInt(), any(NativeBlockState.class));
|
||||
IrisStructure structure = new IrisStructure().setPlaceMode(ObjectPlaceMode.STRUCTURE_PIECE);
|
||||
|
||||
IllegalStateException thrown = assertThrows(IllegalStateException.class,
|
||||
() -> component.placePieces(writer, new IrisStructurePlacement(), structure, slab(), new RNG(3L)));
|
||||
|
||||
assertSame(failure, thrown);
|
||||
InOrder order = inOrder(writer);
|
||||
order.verify(writer).beginObjectPlacement(false);
|
||||
order.verify(writer).endObjectPlacement();
|
||||
}
|
||||
|
||||
private void assertRiverKept() {
|
||||
@@ -154,6 +185,10 @@ public class IrisStructureComponentCarveWaterTest {
|
||||
}
|
||||
|
||||
private static KList<PlacedStructurePiece> slab() {
|
||||
return slabAt(-4);
|
||||
}
|
||||
|
||||
private static KList<PlacedStructurePiece> slabAt(int y) {
|
||||
NativeBlockState stone = mock(NativeBlockState.class);
|
||||
when(stone.isSolid()).thenReturn(true);
|
||||
when(stone.key()).thenReturn("minecraft:stone");
|
||||
@@ -164,7 +199,7 @@ public class IrisStructureComponentCarveWaterTest {
|
||||
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));
|
||||
return new KList<>(new PlacedStructurePiece(null, object, 4, y, 1, IrisObjectRotation.of(0, 0, 0),
|
||||
0, y, 0, 8, y, 2));
|
||||
}
|
||||
}
|
||||
+209
-23
@@ -1,42 +1,117 @@
|
||||
package art.arcane.iris.generation.mantle;
|
||||
|
||||
import art.arcane.iris.configuration.IrisSettings;
|
||||
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.integration.Identifier;
|
||||
import art.arcane.iris.structure.nativegen.NativeStructureSuppression;
|
||||
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.IrisStructureLocator;
|
||||
import art.arcane.iris.structure.placement.IrisStructurePlacement;
|
||||
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.mantle.runtime.Mantle;
|
||||
import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import art.arcane.volmlib.util.matter.Matter;
|
||||
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 java.util.ArrayList;
|
||||
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.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.ArgumentMatchers.anyDouble;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class IrisStructureComponentWaterTest {
|
||||
private static final int X = 4;
|
||||
private static final int Z = 4;
|
||||
|
||||
@Rule
|
||||
public final PlatformBinding platform = PlatformBinding.mockPlatform();
|
||||
|
||||
private final HydrologyWaterFixture world = new HydrologyWaterFixture();
|
||||
private final List<Write> writes = new ArrayList<>();
|
||||
private final Map<Integer, Matter> sections = new HashMap<>();
|
||||
private IrisSettings previousSettings;
|
||||
private MantleWriter writer;
|
||||
private IrisStructureComponent component;
|
||||
|
||||
@Before
|
||||
@SuppressWarnings("unchecked")
|
||||
public void setUp() {
|
||||
previousSettings = IrisSettings.settings;
|
||||
IrisSettings.settings = new IrisSettings();
|
||||
Engine engine = world.data().getEngine();
|
||||
IrisComplex complex = world.complex();
|
||||
HydrologyRuntime runtime = mock(HydrologyRuntime.class);
|
||||
ChunkWaterRaster raster = mock(ChunkWaterRaster.class);
|
||||
ProceduralStream<Integer> floors = mock(ProceduralStream.class);
|
||||
when(floors.get(anyDouble(), anyDouble())).thenAnswer(call -> world.floorAt(block(call.getArgument(0)), block(call.getArgument(1))));
|
||||
when(complex.getRoundedHeighteightStream()).thenReturn(floors);
|
||||
when(complex.getHydrologyRuntime()).thenReturn(runtime);
|
||||
when(runtime.enabled()).thenReturn(true);
|
||||
when(runtime.raster(anyInt(), anyInt())).thenReturn(raster);
|
||||
when(raster.role(anyInt(), anyInt())).thenAnswer(call -> complex.getWaterRoleStream().get((double) call.<Integer>getArgument(0), (double) call.<Integer>getArgument(1)));
|
||||
when(raster.waterHead(anyInt(), anyInt())).thenAnswer(call -> world.headAt(call.getArgument(0), call.getArgument(1)));
|
||||
when(raster.terrainHeight(anyInt(), anyInt())).thenAnswer(call -> world.floorAt(call.getArgument(0), call.getArgument(1)));
|
||||
EngineMantle engineMantle = mock(EngineMantle.class);
|
||||
when(engineMantle.getEngine()).thenReturn(engine);
|
||||
when(engineMantle.getComplex()).thenReturn(complex);
|
||||
when(engineMantle.getData()).thenReturn(world.data());
|
||||
HydrologyWaterFixture.Placer heights = world.placer();
|
||||
when(engineMantle.getHighest(anyInt(), anyInt(), any(), anyBoolean())).thenAnswer(call -> heights.getHighest(call.getArgument(0), call.getArgument(1), world.data(), call.<Boolean>getArgument(3)));
|
||||
Mantle<Matter> mantle = mock(Mantle.class);
|
||||
MantleChunk<Matter> chunk = mock(MantleChunk.class);
|
||||
when(mantle.getWorldHeight()).thenReturn(256);
|
||||
when(mantle.getChunk(0, 0)).thenReturn(chunk);
|
||||
when(mantle.useChunk(0, 0)).thenAnswer(call -> chunk.use());
|
||||
when(chunk.use()).thenReturn(chunk);
|
||||
when(chunk.getOrCreate(anyInt())).thenAnswer(call -> section(call.getArgument(0)));
|
||||
writer = new MantleWriter(engineMantle, mantle, 0, 0, 0, false);
|
||||
component = new IrisStructureComponent(engineMantle);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
writer.close();
|
||||
IrisSettings.settings = previousSettings;
|
||||
}
|
||||
|
||||
@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());
|
||||
int failed = placeSinglePiece(new IrisStructurePlacement());
|
||||
|
||||
assertEquals(0, failed);
|
||||
assertFalse("the part of the piece above the water places", writes.isEmpty());
|
||||
assertNoWaterOverwritten();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -45,40 +120,151 @@ public class IrisStructureComponentWaterTest {
|
||||
@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))));
|
||||
block(invocation.getArgument(0)), block(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);
|
||||
IrisObjectPlacement config = IrisStructureComponent.piecePlacement(new IrisStructure(), piece(object), ObjectPlaceMode.CENTER_HEIGHT);
|
||||
config.setRotateTowardsSlope(true);
|
||||
|
||||
assertEquals(-1, object.place(0, 0, placer, config, new RNG(7L), world.data()));
|
||||
assertTrue(placer.writes().isEmpty());
|
||||
writer.beginObjectPlacement(false);
|
||||
int result = object.place(X, Z, writer, config, new RNG(7L), world.data());
|
||||
writer.endObjectPlacement();
|
||||
|
||||
assertTrue(result >= 0);
|
||||
assertFalse(writes.isEmpty());
|
||||
assertNoWaterOverwritten();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aFewWetSupportColumnsDoNotStopAForcedSinglePiece() {
|
||||
world.column(X + 1, Z, WaterRole.CHANNEL, 15, 19);
|
||||
world.column(X - 1, Z, WaterRole.SHORE, 15, 19);
|
||||
world.column(X, Z + 1, WaterRole.DAM, 15, 19);
|
||||
|
||||
int failed = placeSinglePiece(new IrisStructurePlacement());
|
||||
|
||||
assertEquals(0, failed);
|
||||
int anchorLayer = lowestWriteAt(X, Z);
|
||||
assertEquals("the anchor column keeps its block", world.floorAt(X, Z), anchorLayer);
|
||||
assertTrue("the anchor layer sits inside the river column's water",
|
||||
anchorLayer > world.floorAt(X + 1, Z) && anchorLayer <= world.headAt(X + 1, Z));
|
||||
assertNoWaterOverwritten();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void replaceSourceKeepsAForcedSinglePieceOverWaterWithoutFailingTheChunk() {
|
||||
world.water(WaterRole.CHANNEL, 9, 13);
|
||||
IrisStructurePlacement placement = new IrisStructurePlacement()
|
||||
.setNativeSuppression(NativeStructureSuppression.REPLACE_SOURCE);
|
||||
|
||||
int failed = placeSinglePiece(placement);
|
||||
|
||||
IrisStructureComponent.requireAppliedPieces(resolved(placement), 0, 0, failed);
|
||||
assertEquals(0, failed);
|
||||
assertNoWaterOverwritten();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void replaceSourceKeepsAWaterPieceOnUnevenWaterWithoutFailingTheChunk() {
|
||||
world.water(WaterRole.CHANNEL, 9, 13);
|
||||
world.column(X + 1, Z, WaterRole.CHANNEL, 9, 16);
|
||||
IrisStructurePlacement placement = new IrisStructurePlacement()
|
||||
.setNativeSuppression(NativeStructureSuppression.REPLACE_SOURCE)
|
||||
.setAllowWater(true);
|
||||
|
||||
int failed = placeSinglePiece(placement);
|
||||
|
||||
IrisStructureComponent.requireAppliedPieces(resolved(placement), 0, 0, failed);
|
||||
assertEquals(0, failed);
|
||||
assertEquals("a piece that allows water fills it", world.headAt(X - 1, Z - 1), lowestWriteAt(X - 1, Z - 1));
|
||||
}
|
||||
|
||||
@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());
|
||||
int failed = placeSinglePiece(new IrisStructurePlacement().setAllowWater(true));
|
||||
|
||||
assertEquals(0, failed);
|
||||
assertEquals(world.headAt(X, Z), lowestWriteAt(X, Z));
|
||||
}
|
||||
|
||||
@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);
|
||||
int failed = placeSinglePiece(new IrisStructurePlacement());
|
||||
|
||||
assertTrue(object.place(0, 0, placer, config, new RNG(7L), world.data()) >= 0);
|
||||
assertFalse(placer.writes().isEmpty());
|
||||
assertEquals(0, failed);
|
||||
assertEquals(10, writes.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void objectsThatForcePlaceThemselvesStillStayOffUnevenWater() {
|
||||
world.water(WaterRole.CHANNEL, 9, 13);
|
||||
world.column(X + 1, Z, WaterRole.CHANNEL, 9, 16);
|
||||
IrisObject object = HydrologyWaterFixture.raft();
|
||||
|
||||
int result = object.place(X, Z, writer, new IrisObjectPlacement().setForcePlace(true), new RNG(7L), world.data());
|
||||
|
||||
assertEquals(-1, result);
|
||||
assertTrue(writes.isEmpty());
|
||||
}
|
||||
|
||||
private int placeSinglePiece(IrisStructurePlacement placement) {
|
||||
IrisObject object = HydrologyWaterFixture.raft();
|
||||
IrisStructure structure = new IrisStructure().setPlaceMode(ObjectPlaceMode.CENTER_HEIGHT);
|
||||
return component.placePieces(writer, placement, structure, new KList<>(piece(object)), new RNG(7L));
|
||||
}
|
||||
|
||||
private IrisStructureLocator.ResolvedPlacement resolved(IrisStructurePlacement placement) {
|
||||
IrisObject object = HydrologyWaterFixture.raft();
|
||||
return new IrisStructureLocator.ResolvedPlacement(placement, "test/raft", new IrisStructure(),
|
||||
new KList<>(piece(object)), new RNG(7L), X, 0, Z, false);
|
||||
}
|
||||
|
||||
private void assertNoWaterOverwritten() {
|
||||
for (Write write : writes) {
|
||||
WaterRole role = world.complex().getWaterRoleStream().get((double) write.x(), (double) write.z());
|
||||
if (role.wet()) {
|
||||
assertFalse(write + " overwrites river water",
|
||||
write.y() > world.floorAt(write.x(), write.z()) && write.y() <= world.headAt(write.x(), write.z()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int lowestWriteAt(int x, int z) {
|
||||
int lowest = Integer.MAX_VALUE;
|
||||
for (Write write : writes) {
|
||||
if (write.x() == x && write.z() == z) {
|
||||
lowest = Math.min(lowest, write.y());
|
||||
}
|
||||
}
|
||||
return lowest;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Matter section(int index) {
|
||||
return sections.computeIfAbsent(index, ignored -> {
|
||||
Matter matter = mock(Matter.class);
|
||||
MatterSlice<NativeBlockState> blocks = mock(MatterSlice.class);
|
||||
doAnswer(call -> {
|
||||
writes.add(new Write(call.getArgument(0), (index << 4) | call.<Integer>getArgument(1), call.getArgument(2)));
|
||||
return null;
|
||||
}).when(blocks).set(anyInt(), anyInt(), anyInt(), any());
|
||||
when(matter.getClass(any())).thenAnswer(call -> call.getArgument(0).getClass());
|
||||
doReturn(blocks).when(matter).slice(NativeBlockState.class);
|
||||
doReturn(mock(MatterSlice.class)).when(matter).getSlice(Identifier.class);
|
||||
return matter;
|
||||
});
|
||||
}
|
||||
|
||||
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);
|
||||
return new PlacedStructurePiece(null, object, X, 0, Z, IrisObjectRotation.of(0, 0, 0), X - 1, 0, Z - 1, X + 1, 2, Z + 1);
|
||||
}
|
||||
|
||||
private static int block(Object coordinate) {
|
||||
return (int) Math.floor(((Number) coordinate).doubleValue());
|
||||
}
|
||||
|
||||
private record Write(int x, int y, int z) {
|
||||
}
|
||||
}
|
||||
+298
@@ -0,0 +1,298 @@
|
||||
package art.arcane.iris.generation.mantle;
|
||||
|
||||
import art.arcane.iris.configuration.IrisSettings;
|
||||
import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.iris.generation.cave.CarvingMode;
|
||||
import art.arcane.iris.generation.context.ChunkContext;
|
||||
import art.arcane.iris.generation.decoration.IrisProceduralObjects;
|
||||
import art.arcane.iris.generation.decoration.IrisProceduralPlacement;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
import art.arcane.iris.generation.runtime.SeedManager;
|
||||
import art.arcane.iris.generation.runtime.UpperDimensionContext;
|
||||
import art.arcane.iris.generation.terrain.IrisDimension;
|
||||
import art.arcane.iris.generation.terrain.IrisRegion;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.structure.object.IObjectPlacer;
|
||||
import art.arcane.iris.structure.object.IrisObject;
|
||||
import art.arcane.iris.structure.object.IrisObjectPlacement;
|
||||
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 org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.InOrder;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
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.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
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 MantleObjectComponentWaterPlacementTest {
|
||||
private static final Answer<Integer> PLACES = call -> 64;
|
||||
private static final Answer<Integer> REJECTS = call -> -1;
|
||||
private static final Answer<Integer> THROWS = call -> {
|
||||
throw new IllegalArgumentException("malformed object");
|
||||
};
|
||||
|
||||
private IrisSettings previousSettings;
|
||||
|
||||
@Before
|
||||
public void bindSettings() {
|
||||
previousSettings = IrisSettings.settings;
|
||||
IrisSettings.settings = new IrisSettings();
|
||||
}
|
||||
|
||||
@After
|
||||
public void restoreSettings() {
|
||||
IrisSettings.settings = previousSettings;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void acceptedSurfacePlacementIsRecordedThenEnded() {
|
||||
Fixture fixture = new Fixture(PLACES);
|
||||
fixture.biome.setObjects(new KList<>(fixture.surfacePlacement()));
|
||||
|
||||
fixture.generate();
|
||||
|
||||
fixture.assertRecordedThenEnded();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectedSurfacePlacementEndsWithoutBeingRecorded() {
|
||||
Fixture fixture = new Fixture(REJECTS);
|
||||
fixture.biome.setObjects(new KList<>(fixture.surfacePlacement()));
|
||||
|
||||
fixture.generate();
|
||||
|
||||
fixture.assertEndedUnrecorded();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void thrownSurfacePlacementEndsWithoutBeingRecorded() {
|
||||
Fixture fixture = new Fixture(THROWS);
|
||||
fixture.biome.setObjects(new KList<>(fixture.surfacePlacement()));
|
||||
|
||||
fixture.generate();
|
||||
|
||||
fixture.assertEndedUnrecorded();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectedCavePlacementEndsWithoutBeingRecorded() {
|
||||
Fixture fixture = new Fixture(REJECTS);
|
||||
fixture.biome.setObjects(new KList<>(fixture.cavePlacement()));
|
||||
|
||||
fixture.generate();
|
||||
|
||||
fixture.assertEndedUnrecorded();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void thrownCavePlacementEndsWithoutBeingRecorded() {
|
||||
Fixture fixture = new Fixture(THROWS);
|
||||
fixture.biome.setObjects(new KList<>(fixture.cavePlacement()));
|
||||
|
||||
fixture.generate();
|
||||
|
||||
fixture.assertEndedUnrecorded();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void proceduralPlacementOutsideTheTransitionFootprintEndsWithoutBeingRecorded() {
|
||||
Fixture fixture = new Fixture(PLACES);
|
||||
fixture.biome.setProceduralObjects(fixture.proceduralObjects());
|
||||
when(fixture.complex.allowsNewGenerationFootprint(anyInt(), anyInt(), anyInt(), anyInt())).thenReturn(false);
|
||||
|
||||
fixture.generate();
|
||||
|
||||
fixture.assertEndedUnrecorded();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectedProceduralPlacementEndsWithoutBeingRecorded() {
|
||||
Fixture fixture = new Fixture(REJECTS);
|
||||
fixture.biome.setProceduralObjects(fixture.proceduralObjects());
|
||||
|
||||
fixture.generate();
|
||||
|
||||
fixture.assertEndedUnrecorded();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void thrownProceduralPlacementEndsWithoutBeingRecorded() {
|
||||
Fixture fixture = new Fixture(THROWS);
|
||||
fixture.biome.setProceduralObjects(fixture.proceduralObjects());
|
||||
|
||||
fixture.generate();
|
||||
|
||||
fixture.assertEndedUnrecorded();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectedUpperPlacementEndsWithoutBeingRecorded() {
|
||||
Fixture fixture = new Fixture(REJECTS);
|
||||
fixture.upperObjects();
|
||||
|
||||
fixture.generate();
|
||||
|
||||
fixture.assertEndedUnrecorded();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void thrownUpperPlacementEndsWithoutBeingRecorded() {
|
||||
Fixture fixture = new Fixture(THROWS);
|
||||
fixture.upperObjects();
|
||||
|
||||
fixture.generate();
|
||||
|
||||
fixture.assertEndedUnrecorded();
|
||||
}
|
||||
|
||||
private static final class Fixture {
|
||||
private final IrisBiome biome = new IrisBiome();
|
||||
private final IrisComplex complex = mock(IrisComplex.class);
|
||||
private final IrisObject object = mock(IrisObject.class);
|
||||
private final Engine engine = mock(Engine.class);
|
||||
private final IrisDimension dimension = mock(IrisDimension.class);
|
||||
private final ObjectPassPlacer placer = mock(ObjectPassPlacer.class);
|
||||
private final ChunkContext context = mock(ChunkContext.class);
|
||||
private final MantleObjectComponent component;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Fixture(Answer<Integer> placement) {
|
||||
when(dimension.getAllRegions(any())).thenReturn(new KList<>());
|
||||
when(dimension.getReachableBiomes(any())).thenReturn(new KList<>());
|
||||
when(engine.getDimension()).thenReturn(dimension);
|
||||
when(engine.getSeedManager()).thenReturn(mock(SeedManager.class));
|
||||
when(engine.getHeight()).thenReturn(256);
|
||||
when(engine.getComplex()).thenReturn(complex);
|
||||
EngineMantle engineMantle = mock(EngineMantle.class);
|
||||
when(engineMantle.getEngine()).thenReturn(engine);
|
||||
when(engineMantle.getData()).thenReturn(mock(IrisData.class));
|
||||
when(engineMantle.getComplex()).thenReturn(complex);
|
||||
when(engineMantle.trueHeight(anyInt(), anyInt())).thenReturn(120);
|
||||
|
||||
when(object.getLoadKey()).thenReturn("trees/water");
|
||||
when(object.getW()).thenReturn(1);
|
||||
when(object.getH()).thenReturn(1);
|
||||
when(object.getD()).thenReturn(1);
|
||||
doAnswer(placement).when(object).place(anyInt(), anyInt(), any(IObjectPlacer.class), any(IrisObjectPlacement.class),
|
||||
any(RNG.class), any(), any(), any());
|
||||
doAnswer(placement).when(object).place(anyInt(), anyInt(), anyInt(), any(IObjectPlacer.class), any(IrisObjectPlacement.class),
|
||||
any(RNG.class), any(), any(), any());
|
||||
|
||||
biome.setLoadKey("water-biome");
|
||||
IrisRegion region = new IrisRegion();
|
||||
region.setLoadKey("water-region");
|
||||
ProceduralStream<IrisRegion> regions = mock(ProceduralStream.class);
|
||||
when(regions.get(anyDouble(), anyDouble())).thenReturn(region);
|
||||
ProceduralStream<IrisBiome> biomes = mock(ProceduralStream.class);
|
||||
when(biomes.get(anyDouble(), anyDouble())).thenReturn(biome);
|
||||
ProceduralStream<Integer> heights = mock(ProceduralStream.class);
|
||||
when(heights.get(anyDouble(), anyDouble())).thenReturn(64);
|
||||
when(complex.allowsNewGenerationChunk(anyInt(), anyInt())).thenReturn(true);
|
||||
when(complex.allowsNewGenerationFootprint(anyInt(), anyInt(), anyInt(), anyInt())).thenReturn(true);
|
||||
when(complex.getRegionStream()).thenReturn(regions);
|
||||
when(complex.getTrueBiomeStream()).thenReturn(biomes);
|
||||
when(complex.getRoundedHeighteightStream()).thenReturn(heights);
|
||||
when(context.getComplex()).thenReturn(complex);
|
||||
when(placer.getEngine()).thenReturn(engine);
|
||||
when(placer.getCarvedColumn(anyInt(), anyInt(), anyInt())).thenAnswer(call -> {
|
||||
byte[] column = new byte[call.<Integer>getArgument(2)];
|
||||
Arrays.fill(column, 20, 28, (byte) 1);
|
||||
return column;
|
||||
});
|
||||
when(placer.getDataIfPresent(anyInt(), anyInt(), anyInt(), eq(MatterCavern.class)))
|
||||
.thenReturn(new MatterCavern(true, "", (byte) 0));
|
||||
component = new MantleObjectComponent(engineMantle);
|
||||
}
|
||||
|
||||
private IrisObjectPlacement surfacePlacement() {
|
||||
IrisObjectPlacement placement = placement(CarvingMode.SURFACE_ONLY);
|
||||
when(placement.getDensity(any(RNG.class), anyDouble(), anyDouble(), any())).thenReturn(1);
|
||||
when(placement.getObject(any(), any(RNG.class))).thenReturn(object);
|
||||
return placement;
|
||||
}
|
||||
|
||||
private IrisObjectPlacement cavePlacement() {
|
||||
IrisObjectPlacement placement = placement(CarvingMode.CARVING_ONLY);
|
||||
when(placement.getDensity(any(RNG.class), anyDouble(), anyDouble(), any())).thenReturn(1);
|
||||
when(placement.getObject(any(), any(RNG.class))).thenReturn(object);
|
||||
return placement;
|
||||
}
|
||||
|
||||
private IrisProceduralObjects proceduralObjects() {
|
||||
IrisObjectPlacement placement = placement(CarvingMode.SURFACE_ONLY);
|
||||
IrisProceduralPlacement procedural = mock(IrisProceduralPlacement.class);
|
||||
when(procedural.getChance()).thenReturn(2D);
|
||||
when(procedural.getName()).thenReturn("water-procedural");
|
||||
when(procedural.getDensity()).thenReturn(1);
|
||||
when(procedural.asPlacement()).thenReturn(placement);
|
||||
when(procedural.getVariantObject(any(), any(), any())).thenReturn(object);
|
||||
IrisProceduralObjects objects = mock(IrisProceduralObjects.class);
|
||||
when(objects.isEmpty()).thenReturn(false);
|
||||
when(objects.getAllPlacements()).thenReturn(new KList<>(procedural));
|
||||
return objects;
|
||||
}
|
||||
|
||||
private void upperObjects() {
|
||||
IrisObjectPlacement forced = placement(CarvingMode.ANYWHERE);
|
||||
IrisObjectPlacement source = placement(CarvingMode.SURFACE_ONLY);
|
||||
when(source.getDensity(any(RNG.class), anyDouble(), anyDouble(), any())).thenReturn(1);
|
||||
when(source.getObject(any(UpperDimensionContext.class), any(RNG.class))).thenReturn(object);
|
||||
when(source.toPlacement(anyString())).thenReturn(forced);
|
||||
IrisBiome upperBiome = new IrisBiome();
|
||||
upperBiome.setLoadKey("upper-biome");
|
||||
upperBiome.setObjects(new KList<>(source));
|
||||
UpperDimensionContext upper = mock(UpperDimensionContext.class);
|
||||
when(upper.getUpperBiome(anyInt(), anyInt())).thenReturn(upperBiome);
|
||||
when(upper.getDimension()).thenReturn(dimension);
|
||||
when(upper.getEffectiveSurfaceY(anyInt(), anyInt())).thenReturn(64);
|
||||
when(engine.getUpperContext()).thenReturn(upper);
|
||||
when(dimension.isUpperDimensionObjects()).thenReturn(true);
|
||||
}
|
||||
|
||||
private IrisObjectPlacement placement(CarvingMode carving) {
|
||||
IrisObjectPlacement placement = mock(IrisObjectPlacement.class);
|
||||
when(placement.getChance()).thenReturn(2D);
|
||||
when(placement.getCarvingSupport()).thenReturn(carving);
|
||||
when(placement.getPlace()).thenReturn(new KList<>("trees/water"));
|
||||
when(placement.getAllowedCollisions()).thenReturn(new KList<>());
|
||||
when(placement.getForbiddenCollisions()).thenReturn(new KList<>());
|
||||
when(placement.scaleObject(any(RNG.class), any(), any())).thenReturn(object);
|
||||
when(placement.entersWater()).thenReturn(true);
|
||||
return placement;
|
||||
}
|
||||
|
||||
private void generate() {
|
||||
component.generateOrigin(placer, 0, 0, context);
|
||||
}
|
||||
|
||||
private void assertEndedUnrecorded() {
|
||||
InOrder order = inOrder(placer);
|
||||
order.verify(placer).beginObjectPlacement(true);
|
||||
order.verify(placer).endObjectPlacement();
|
||||
verify(placer, never()).recordObjectPlacement(anyInt());
|
||||
}
|
||||
|
||||
private void assertRecordedThenEnded() {
|
||||
InOrder order = inOrder(placer);
|
||||
order.verify(placer).beginObjectPlacement(true);
|
||||
order.verify(placer).recordObjectPlacement(anyInt());
|
||||
order.verify(placer).endObjectPlacement();
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -100,7 +100,7 @@ public class MantleWriterObjectWaterTest {
|
||||
writer.set(3, 5, 3, stone);
|
||||
writer.set(3, 10, 3, stone);
|
||||
writer.set(8, 7, 8, stone);
|
||||
writer.endObjectPlacement(land);
|
||||
writer.endObjectPlacement();
|
||||
|
||||
verify(blocks, never()).set(3, 7, 3, stone);
|
||||
verify(blocks, never()).set(3, 8, 3, air);
|
||||
@@ -112,7 +112,7 @@ public class MantleWriterObjectWaterTest {
|
||||
int water = writer.beginObjectPlacement(true);
|
||||
writer.set(3, 6, 3, stone);
|
||||
writer.set(3, 9, 3, air);
|
||||
writer.endObjectPlacement(water);
|
||||
writer.endObjectPlacement();
|
||||
|
||||
verify(blocks).set(3, 6, 3, stone);
|
||||
verify(blocks, never()).set(3, 9, 3, air);
|
||||
@@ -121,7 +121,7 @@ public class MantleWriterObjectWaterTest {
|
||||
@Test
|
||||
public void writesOutsideAnObjectPlacementAreNotVetoed() {
|
||||
int land = writer.beginObjectPlacement(false);
|
||||
writer.endObjectPlacement(land);
|
||||
writer.endObjectPlacement();
|
||||
|
||||
writer.set(3, 7, 3, stone);
|
||||
writer.set(3, 8, 3, air);
|
||||
|
||||
@@ -60,15 +60,18 @@ public class ObjectContinuationTest {
|
||||
ObjectDestinationTransaction source = new ObjectDestinationTransaction(fixture.writer, 0, 0);
|
||||
int checkpoint = source.beginObjectPlacement(false);
|
||||
source.setData(1, 5, 1, "inside");
|
||||
source.endObjectPlacement(checkpoint);
|
||||
source.recordObjectPlacement(checkpoint);
|
||||
source.endObjectPlacement();
|
||||
checkpoint = source.beginObjectPlacement(false);
|
||||
source.setData(15, 5, 1, "crossing");
|
||||
source.setData(16, 5, 1, "crossing");
|
||||
source.endObjectPlacement(checkpoint);
|
||||
source.recordObjectPlacement(checkpoint);
|
||||
source.endObjectPlacement();
|
||||
checkpoint = source.beginObjectPlacement(false);
|
||||
source.setData(32, 5, 1, "unrelated");
|
||||
source.setData(48, 5, 1, "unrelated");
|
||||
source.endObjectPlacement(checkpoint);
|
||||
source.recordObjectPlacement(checkpoint);
|
||||
source.endObjectPlacement();
|
||||
source.setData(17, 5, 1, "rejected");
|
||||
ObjectSourcePlan plan = source.sourcePlanSince(0);
|
||||
|
||||
|
||||
+38
-3
@@ -294,7 +294,8 @@ public class ObjectDestinationTransactionTest {
|
||||
transaction.set(4, 9, 3, leaves);
|
||||
assertEquals("an underwater object keeps its solid blocks in the water", underwater + 2,
|
||||
transaction.mutationCheckpoint());
|
||||
transaction.endObjectPlacement(underwater);
|
||||
transaction.recordObjectPlacement(underwater);
|
||||
transaction.endObjectPlacement();
|
||||
ObjectDestinationTransaction destination = new ObjectDestinationTransaction(writer, 0, 0);
|
||||
destination.apply(transaction.sourcePlanSince(start));
|
||||
assertEquals("the destination replay keeps the underwater blocks", 6, destination.mutationCheckpoint());
|
||||
@@ -325,7 +326,7 @@ public class ObjectDestinationTransactionTest {
|
||||
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);
|
||||
new IrisObject(1, 1, 1), 4, 14, 3, IrisObjectRotation.of(0, 0, 0), 4, 14, 3, 4, 14, 3), ObjectPlaceMode.CENTER_HEIGHT);
|
||||
assertTrue(piece.isForcePlace());
|
||||
ObjectDestinationTransaction transaction = new ObjectDestinationTransaction(writer, 0, 0);
|
||||
|
||||
@@ -368,13 +369,47 @@ public class ObjectDestinationTransactionTest {
|
||||
|
||||
int raft = transaction.beginObjectPlacement(true);
|
||||
transaction.set(3, 12, 3, pier);
|
||||
transaction.endObjectPlacement(raft);
|
||||
transaction.recordObjectPlacement(raft);
|
||||
transaction.endObjectPlacement();
|
||||
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 aRejectedWaterPlacementReturnsToLandRules() {
|
||||
MantleWriter writer = writer();
|
||||
waterAtColumnThree(writer);
|
||||
NativeBlockState pier = mock(NativeBlockState.class);
|
||||
when(pier.isSolid()).thenReturn(true);
|
||||
ObjectDestinationTransaction transaction = new ObjectDestinationTransaction(writer, 0, 0);
|
||||
|
||||
transaction.beginObjectPlacement(true);
|
||||
transaction.set(3, 12, 3, pier);
|
||||
transaction.endObjectPlacement();
|
||||
int afterRaft = transaction.mutationCheckpoint();
|
||||
transaction.set(3, 13, 3, pier);
|
||||
|
||||
assertEquals("a write after a rejected water placement follows land rules", afterRaft, transaction.mutationCheckpoint());
|
||||
}
|
||||
|
||||
private static void waterAtColumnThree(MantleWriter 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);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sourceCaptureCannotReplaceAuthoredRoomSolids() {
|
||||
MantleWriter writer = writer();
|
||||
|
||||
@@ -251,6 +251,38 @@ public class PackValidatorStructureGraphTest {
|
||||
assertTrue(errors.toString(), errors.stream().anyMatch(message -> message.contains("duplicates an anonymous placement grid")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void allowWaterMustBeABoolean() throws Exception {
|
||||
File pack = temporaryFolder.newFolder("invalid-allow-water");
|
||||
write(pack, "dimensions/main.json", "{\"structures\":[{"
|
||||
+ "\"nativeStructures\":[{\"structure\":\"minecraft:ancient_city\"}],"
|
||||
+ "\"allowWater\":\"yes\"}]}");
|
||||
|
||||
List<String> errors = PackObjectSurfaceValidator.validateStructureGraph(pack);
|
||||
|
||||
assertTrue(errors.toString(), errors.stream().anyMatch(message -> message.contains("allowWater must be a boolean")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void allowWaterSeparatesAnonymousGridsOnlyWhenTrue() throws Exception {
|
||||
File separate = temporaryFolder.newFolder("allow-water-grid");
|
||||
write(separate, "dimensions/main.json", "{\"structures\":[{"
|
||||
+ "\"nativeStructures\":[{\"structure\":\"minecraft:ancient_city\"}]}]}");
|
||||
write(separate, "regions/river.json", "{\"structures\":[{\"allowWater\":true,"
|
||||
+ "\"nativeStructures\":[{\"structure\":\"minecraft:ancient_city\"}]}]}");
|
||||
File duplicate = temporaryFolder.newFolder("allow-water-false-grid");
|
||||
write(duplicate, "dimensions/main.json", "{\"structures\":[{"
|
||||
+ "\"nativeStructures\":[{\"structure\":\"minecraft:ancient_city\"}]}]}");
|
||||
write(duplicate, "regions/river.json", "{\"structures\":[{\"allowWater\":false,"
|
||||
+ "\"nativeStructures\":[{\"structure\":\"minecraft:ancient_city\"}]}]}");
|
||||
|
||||
List<String> separateErrors = PackObjectSurfaceValidator.validateStructureGraph(separate);
|
||||
List<String> duplicateErrors = PackObjectSurfaceValidator.validateStructureGraph(duplicate);
|
||||
|
||||
assertTrue(separateErrors.toString(), separateErrors.stream().noneMatch(message -> message.contains("duplicates an anonymous placement grid")));
|
||||
assertTrue(duplicateErrors.toString(), duplicateErrors.stream().anyMatch(message -> message.contains("duplicates an anonymous placement grid")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectsDuplicateEditableStructureKeysIgnoringCase() throws Exception {
|
||||
File pack = temporaryFolder.newFolder("duplicate-editable-key");
|
||||
|
||||
+1
-1
@@ -190,7 +190,7 @@ public class NativeStructurePlacementPlannerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void riverInTheStartChunkLeavesTheDecisionToThePieces() {
|
||||
public void waterAroundAStartColumnAboveItsHeadLeavesTheDecisionToThePieces() {
|
||||
Engine engine = engine(77L, -64, 384, 150);
|
||||
Map<Long, WaterRole> roles = new HashMap<>();
|
||||
waterComplex(engine, roles, false);
|
||||
|
||||
Reference in new issue
Block a user