mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 08:44:50 +00:00
Batch 6 part 3: host side of structure locating and the decoding contract
Structure locating goes through StructureLocator. Ownership records hold one memo text and no placement identity (schema 3; older records fail closed). NativeStructureStartsTest drops the identity column of its golden; the other columns are unchanged. ModuleSettingsDecoder applies the decoding contract (DecodingContract: null members are left out, unknown enum names are errors). NoiseStyle no longer carries cacheSize, a cache knob only. PlacementRequest has no id. Dimension settings reach LinkedBiomes as PackSettings.
This commit is contained in:
1 parent
dc0d61ce63
commit
711fdd078a
31 files changed
+367
-280
No files matched your search
+1
-1
@@ -993,7 +993,7 @@ public class NativeStructureFitBridgeTest {
|
||||
}
|
||||
|
||||
private static NativeStartMemo memo(String terrainMode) {
|
||||
return new NativeStartMemo("{\"mode\":\"" + terrainMode + "\"}", "null");
|
||||
return new NativeStartMemo("{\"terrain\":{\"mode\":\"" + terrainMode + "\"}}");
|
||||
}
|
||||
|
||||
/** {@code piece} as the bridge hands it to the fit. */
|
||||
|
||||
+1
-1
@@ -128,7 +128,7 @@ public class NativeStructureFitPinTest {
|
||||
List<NativeStructureFitBridge.FitTarget> targets = new ArrayList<>();
|
||||
for (FitTarget target : scenario.targets()) {
|
||||
targets.add(new NativeStructureFitBridge.FitTarget(target.structureId(), target.start(),
|
||||
new NativeStartMemo(target.terrainJson(), target.stiltJson())));
|
||||
new NativeStartMemo("{\"terrain\":" + target.terrainJson() + ",\"stilts\":" + target.stiltJson() + "}")));
|
||||
}
|
||||
NativeStructureFitting.Session fit = BuiltInFitting.FITTING.beforePieces(
|
||||
NativeStructureFitBridge.chunk(world, CHUNK_AREA, targets, TerrainWorld::surfaceY));
|
||||
|
||||
+1
-13
@@ -2,10 +2,6 @@ package art.arcane.iris.nativegen;
|
||||
|
||||
import art.arcane.iris.engine.framework.NativeStructureOwnershipRecord;
|
||||
import art.arcane.iris.engine.framework.NativeStructureStartPlan;
|
||||
import art.arcane.iris.engine.framework.StructurePlacementGrid;
|
||||
import art.arcane.iris.builtin.structure.StructurePlacement;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import art.arcane.iris.engine.framework.NativeStartMemo;
|
||||
import art.arcane.iris.engine.framework.NativeStructureReach;
|
||||
import net.minecraft.SharedConstants;
|
||||
@@ -244,8 +240,7 @@ public class NativeStructureOwnershipFingerprintTest {
|
||||
|
||||
private static NativeStructureStartPlan plan(ChunkPos origin, int baseY) {
|
||||
return new NativeStructureStartPlan("minecraft:monument", origin.x(), origin.z(), baseY, false, false,
|
||||
StructurePlacementGrid.placementIdentity(placementWithId("monument-test")),
|
||||
null, new NativeStartMemo("{\"mode\":\"SOURCE\"}", "null"));
|
||||
null, new NativeStartMemo("{\"terrain\":{\"mode\":\"SOURCE\"}}"));
|
||||
}
|
||||
|
||||
private static NativeStructureOwnershipRecord ownership(
|
||||
@@ -330,11 +325,4 @@ public class NativeStructureOwnershipFingerprintTest {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** A structure placement as a pack writing only its {@code placementId} has it. */
|
||||
private static StructurePlacement placementWithId(String placementId) {
|
||||
JsonObject json = new JsonObject();
|
||||
json.addProperty("placementId", placementId);
|
||||
return new Gson().fromJson(json, StructurePlacement.class);
|
||||
}
|
||||
}
|
||||
+17
-43
@@ -2,12 +2,8 @@ package art.arcane.iris.nativegen;
|
||||
|
||||
import art.arcane.iris.engine.framework.NativeStructureOwnershipRecord;
|
||||
import art.arcane.iris.engine.framework.NativeStructureStartPlan;
|
||||
import art.arcane.iris.engine.framework.StructurePlacementGrid;
|
||||
import art.arcane.iris.engine.framework.NativeStartMemo;
|
||||
import art.arcane.iris.engine.framework.NativeStructureReach;
|
||||
import art.arcane.iris.builtin.structure.StructurePlacement;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.SharedConstants;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.HolderSet;
|
||||
@@ -51,7 +47,7 @@ public class NativeStructureOwnershipRecoveryTest {
|
||||
NativeStructureVerticalPlacer.alignOceanMonumentToSeaLevel(
|
||||
expected, 0, 80, -64, 320);
|
||||
int expectedLocatorY = NativeStructureOwnershipFingerprint.locatorY(expected);
|
||||
NativeStructureStartPlan plan = plan(origin, "recovery-exact", 24);
|
||||
NativeStructureStartPlan plan = plan(origin, 24);
|
||||
StructureStart reloaded = new StructureStart(
|
||||
structure,
|
||||
origin,
|
||||
@@ -66,8 +62,6 @@ public class NativeStructureOwnershipRecoveryTest {
|
||||
plan, expected, false, reaches(plan));
|
||||
|
||||
assertNotNull(recovered);
|
||||
assertEquals(plan.placementIdentity(),
|
||||
recovered.placementIdentity());
|
||||
assertEquals(expectedLocatorY, recovered.locatorY());
|
||||
assertNotEquals(NativeStructureOwnershipFingerprint.locatorY(reloaded),
|
||||
recovered.locatorY());
|
||||
@@ -82,7 +76,7 @@ public class NativeStructureOwnershipRecoveryTest {
|
||||
ChunkPos origin = new ChunkPos(-3, 6);
|
||||
OceanMonumentStructure structure = structure();
|
||||
StructureStart natural = monumentStart(structure, origin, seed);
|
||||
NativeStructureStartPlan plan = plan(origin, "natural-ambiguous", 0);
|
||||
NativeStructureStartPlan plan = plan(origin, 0);
|
||||
|
||||
NativeStructureOwnershipRecord recovered =
|
||||
NativeStructureOwnershipRecovery.proveCandidate(
|
||||
@@ -93,7 +87,7 @@ public class NativeStructureOwnershipRecoveryTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void changedPlacementIdentityOrGeometryCannotRecoverOwnership() {
|
||||
public void changedOriginOrGeometryCannotRecoverOwnership() {
|
||||
long seed = 991723L;
|
||||
ChunkPos origin = new ChunkPos(2, 4);
|
||||
OceanMonumentStructure structure = structure();
|
||||
@@ -102,20 +96,14 @@ public class NativeStructureOwnershipRecoveryTest {
|
||||
for (StructurePiece piece : changedGeometry.getPieces()) {
|
||||
piece.move(1, 0, 0);
|
||||
}
|
||||
NativeStructureStartPlan originalIdentity = plan(
|
||||
origin, "original-identity", 0);
|
||||
NativeStructureStartPlan changedIdentity = plan(
|
||||
new ChunkPos(origin.x() + 1, origin.z()), "changed-identity", 0);
|
||||
NativeStructureStartPlan changedOrigin = plan(new ChunkPos(origin.x() + 1, origin.z()), 0);
|
||||
|
||||
assertNotEquals(
|
||||
originalIdentity.placementIdentity(),
|
||||
changedIdentity.placementIdentity());
|
||||
assertNull(NativeStructureOwnershipRecovery.proveCandidate(
|
||||
"minecraft:monument", structure, expected,
|
||||
changedIdentity, expected, false, reaches(changedIdentity)));
|
||||
changedOrigin, expected, false, reaches(changedOrigin)));
|
||||
assertNull(NativeStructureOwnershipRecovery.proveCandidate(
|
||||
"minecraft:monument", structure, changedGeometry,
|
||||
plan(origin, "geometry-check", 0), expected, false, reaches(plan(origin, "geometry-check", 0))));
|
||||
plan(origin, 0), expected, false, reaches(plan(origin, 0))));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -127,7 +115,7 @@ public class NativeStructureOwnershipRecoveryTest {
|
||||
NativeStructureOwnershipRecord recovered =
|
||||
NativeStructureOwnershipRecovery.proveCandidate(
|
||||
"minecraft:monument", structure, expected,
|
||||
plan(origin, "fingerprint-check", 16), expected, false, reaches(plan(origin, "fingerprint-check", 16)));
|
||||
plan(origin, 16), expected, false, reaches(plan(origin, 16)));
|
||||
assertNotNull(recovered);
|
||||
|
||||
StructureStart moved = monumentStart(structure, origin, seed);
|
||||
@@ -146,7 +134,7 @@ public class NativeStructureOwnershipRecoveryTest {
|
||||
OceanMonumentStructure structure = structure();
|
||||
StructureStart start = monumentStart(structure, origin, seed);
|
||||
NativeStructureStartPlan plan = plan(
|
||||
origin, "vacuum-envelope-refresh", "VACUUM", 0);
|
||||
origin, "VACUUM", 0);
|
||||
BoundingBox content = NativeStructureReferenceEnvelope.contentBounds(start);
|
||||
NativeStructureOwnershipRecord stale = NativeStructureOwnershipFingerprint.capture(
|
||||
structureKey, start, plan, content);
|
||||
@@ -159,7 +147,6 @@ public class NativeStructureOwnershipRecoveryTest {
|
||||
assertNotEquals(stale, refreshed);
|
||||
assertEquals(stale.schema(), refreshed.schema());
|
||||
assertEquals(stale.ownershipKey(), refreshed.ownershipKey());
|
||||
assertEquals(stale.placementIdentity(), refreshed.placementIdentity());
|
||||
assertEquals(stale.baseY(), refreshed.baseY());
|
||||
assertEquals(stale.locatorY(), refreshed.locatorY());
|
||||
assertEquals(stale.contentFingerprint(), refreshed.contentFingerprint());
|
||||
@@ -183,7 +170,7 @@ public class NativeStructureOwnershipRecoveryTest {
|
||||
OceanMonumentStructure structure = structure();
|
||||
StructureStart expected = monumentStart(structure, origin, seed);
|
||||
NativeStructureStartPlan plan = plan(
|
||||
origin, "vacuum-content-check", "VACUUM", 0);
|
||||
origin, "VACUUM", 0);
|
||||
NativeStructureOwnershipRecord stale = NativeStructureOwnershipFingerprint.capture(
|
||||
structureKey, expected, plan,
|
||||
NativeStructureReferenceEnvelope.contentBounds(expected));
|
||||
@@ -203,7 +190,7 @@ public class NativeStructureOwnershipRecoveryTest {
|
||||
ChunkPos origin = new ChunkPos(3, 8);
|
||||
OceanMonumentStructure structure = structure();
|
||||
StructureStart start = monumentStart(structure, origin, seed);
|
||||
NativeStructureStartPlan plan = plan(origin, "current-force-carve", 24);
|
||||
NativeStructureStartPlan plan = plan(origin, 24);
|
||||
BoundingBox envelope = NativeStructureReferenceEnvelope.referenceBounds(
|
||||
start, structure, reaches(plan), structureKey);
|
||||
NativeStructureOwnershipRecord ownership = NativeStructureOwnershipFingerprint.capture(
|
||||
@@ -220,7 +207,7 @@ public class NativeStructureOwnershipRecoveryTest {
|
||||
ChunkPos origin = new ChunkPos(3, 8);
|
||||
OceanMonumentStructure structure = structure();
|
||||
StructureStart start = monumentStart(structure, origin, seed);
|
||||
NativeStructureStartPlan plan = plan(origin, "wide-force-carve", 24);
|
||||
NativeStructureStartPlan plan = plan(origin, 24);
|
||||
NativeStructureOwnershipRecord ownership = NativeStructureOwnershipFingerprint.capture(structureKey, start, plan,
|
||||
NativeStructureReferenceEnvelope.referenceBounds(start, structure, reaches(plan), structureKey));
|
||||
|
||||
@@ -243,7 +230,7 @@ public class NativeStructureOwnershipRecoveryTest {
|
||||
piece.move(shiftX, 0, 0);
|
||||
}
|
||||
NativeStructureStartPlan plan = plan(
|
||||
origin, "clipped-vacuum", "VACUUM", 0);
|
||||
origin, "VACUUM", 0);
|
||||
BoundingBox envelope = NativeStructureReferenceEnvelope.referenceBounds(
|
||||
start, structure, reaches(plan), structureKey);
|
||||
NativeStructureOwnershipRecord ownership = NativeStructureOwnershipFingerprint.capture(
|
||||
@@ -277,17 +264,12 @@ public class NativeStructureOwnershipRecoveryTest {
|
||||
structure, origin, 0, new PiecesContainer(List.of(building)));
|
||||
}
|
||||
|
||||
private static NativeStructureStartPlan plan(ChunkPos origin,
|
||||
String placementId,
|
||||
int horizontalPadding) {
|
||||
return plan(origin, placementId, "FORCE_CARVE", horizontalPadding);
|
||||
private static NativeStructureStartPlan plan(ChunkPos origin, int horizontalPadding) {
|
||||
return plan(origin, "FORCE_CARVE", horizontalPadding);
|
||||
}
|
||||
|
||||
/** A start the structure module placed with a terrain fit of {@code terrainMode}, as its memo records it. */
|
||||
private static NativeStructureStartPlan plan(ChunkPos origin,
|
||||
String placementId,
|
||||
String terrainMode,
|
||||
int horizontalPadding) {
|
||||
private static NativeStructureStartPlan plan(ChunkPos origin, String terrainMode, int horizontalPadding) {
|
||||
String terrain = "{\"mode\":\"" + terrainMode + "\",\"horizontalPadding\":" + horizontalPadding + "}";
|
||||
return new NativeStructureStartPlan(
|
||||
"minecraft:monument",
|
||||
@@ -297,15 +279,14 @@ public class NativeStructureOwnershipRecoveryTest {
|
||||
monumentStart(structure(), origin, 1L)).minY(),
|
||||
false,
|
||||
false,
|
||||
StructurePlacementGrid.placementIdentity(placementWithId(placementId)),
|
||||
null,
|
||||
new NativeStartMemo(terrain, "null")
|
||||
new NativeStartMemo("{\"terrain\":" + terrain + "}")
|
||||
);
|
||||
}
|
||||
|
||||
/** The reach the structure module gives the plan's terrain fit: VACUUM its 12-block falloff, else the padding. */
|
||||
private static List<NativeStructureReach> reaches(NativeStructureStartPlan plan) {
|
||||
String terrain = plan.memo().terrain();
|
||||
String terrain = plan.memo().text();
|
||||
int padding = Integer.parseInt(terrain.replaceAll(".*\"horizontalPadding\":(\\d+).*", "$1"));
|
||||
return List.of(new NativeStructureReach(false, terrain.contains("VACUUM") ? 12 : padding));
|
||||
}
|
||||
@@ -324,11 +305,4 @@ public class NativeStructureOwnershipRecoveryTest {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** A structure placement as a pack writing only its {@code placementId} has it. */
|
||||
private static StructurePlacement placementWithId(String placementId) {
|
||||
JsonObject json = new JsonObject();
|
||||
json.addProperty("placementId", placementId);
|
||||
return new Gson().fromJson(json, StructurePlacement.class);
|
||||
}
|
||||
}
|
||||
-1
@@ -58,7 +58,6 @@ public final class NativeStructureOwnershipFingerprint {
|
||||
structureKey,
|
||||
origin.x(),
|
||||
origin.z(),
|
||||
resolvedPlan.placementIdentity(),
|
||||
resolvedPlan.baseY(),
|
||||
content.minX(),
|
||||
content.minY(),
|
||||
|
||||
+1
-1
@@ -57,7 +57,7 @@ public class NativeStructureVacuumParityTest {
|
||||
|
||||
NativeStructureFitting.builtInModules().beforePieces(NativeStructureFitBridge.chunk(world(blocks), area,
|
||||
List.of(new NativeStructureFitBridge.FitTarget("test:vacuum", start,
|
||||
new NativeStartMemo("{\"mode\":\"VACUUM\"}", "null"))), (x, z) -> SURFACE_Y));
|
||||
new NativeStartMemo("{\"terrain\":{\"mode\":\"VACUUM\"}}"))), (x, z) -> SURFACE_Y));
|
||||
|
||||
assertEquals(original, blocks);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import com.google.gson.TypeAdapter;
|
||||
import com.google.gson.TypeAdapterFactory;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonToken;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* IrisApi's decoding contract (IrisApi DESIGN.md, "Decoding contract") for the module settings Gson: a member written as
|
||||
* {@code null} counts as left out, so the field keeps its initialiser, and an enum name the enum does not know is an
|
||||
* error naming the known ones. Together the host never writes {@code null} into a field it reads.
|
||||
*/
|
||||
final class DecodingContract {
|
||||
private static final List<String> LIBRARY_PACKAGES = List.of("java.", "javax.", "com.google.gson.");
|
||||
|
||||
private DecodingContract() {
|
||||
}
|
||||
|
||||
/** {@code builder} with the contract; register it before any factory that should see the JSON as written. */
|
||||
static GsonBuilder appliedTo(GsonBuilder builder) {
|
||||
return builder.registerTypeAdapterFactory(new NullMembersLeftOut())
|
||||
.registerTypeAdapterFactory(new KnownEnumNames());
|
||||
}
|
||||
|
||||
private static boolean readsFields(Class<?> type) {
|
||||
if (type.isPrimitive() || type.isArray() || type.isEnum() || type.isInterface()) {
|
||||
return false;
|
||||
}
|
||||
String name = type.getName();
|
||||
return LIBRARY_PACKAGES.stream().noneMatch(name::startsWith);
|
||||
}
|
||||
|
||||
private static final class NullMembersLeftOut implements TypeAdapterFactory {
|
||||
@Override
|
||||
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
|
||||
if (!readsFields(type.getRawType())) {
|
||||
return null;
|
||||
}
|
||||
TypeAdapter<T> delegate = gson.getDelegateAdapter(this, type);
|
||||
TypeAdapter<JsonElement> trees = gson.getAdapter(JsonElement.class);
|
||||
return new TypeAdapter<T>() {
|
||||
@Override
|
||||
public void write(JsonWriter out, T value) throws IOException {
|
||||
delegate.write(out, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T read(JsonReader in) throws IOException {
|
||||
JsonElement json = trees.read(in);
|
||||
if (json.isJsonObject()) {
|
||||
json.getAsJsonObject().entrySet().removeIf(member -> member.getValue().isJsonNull());
|
||||
}
|
||||
return delegate.fromJsonTree(json);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private static final class KnownEnumNames implements TypeAdapterFactory {
|
||||
@Override
|
||||
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
|
||||
Class<? super T> raw = type.getRawType();
|
||||
if (!raw.isEnum()) {
|
||||
return null;
|
||||
}
|
||||
TypeAdapter<T> delegate = gson.getDelegateAdapter(this, type);
|
||||
return new TypeAdapter<T>() {
|
||||
@Override
|
||||
public void write(JsonWriter out, T value) throws IOException {
|
||||
delegate.write(out, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T read(JsonReader in) throws IOException {
|
||||
if (in.peek() == JsonToken.NULL) {
|
||||
in.nextNull();
|
||||
return null;
|
||||
}
|
||||
String name = in.nextString();
|
||||
T value = delegate.fromJsonTree(new JsonPrimitive(name));
|
||||
if (value == null) {
|
||||
throw new JsonParseException("\"" + name + "\" is not one of " + knownNames(raw, delegate));
|
||||
}
|
||||
return value;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static <T> List<String> knownNames(Class<? super T> type, TypeAdapter<T> delegate) {
|
||||
return Arrays.stream(type.getEnumConstants())
|
||||
.map(constant -> delegate.toJsonTree((T) constant).getAsString())
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -110,7 +110,6 @@ public final class IrisValues {
|
||||
iris.setMultiplier(style.multiplier());
|
||||
iris.setFracture(style.fracture().map(fracture -> generatorStyle(fracture, resources)).orElse(null));
|
||||
iris.setExponent(style.exponent());
|
||||
iris.setCacheSize(style.cacheSize());
|
||||
return iris;
|
||||
}
|
||||
|
||||
|
||||
@@ -83,8 +83,7 @@ public final class ModuleObjectPlacement {
|
||||
Engine engine = placer.getEngine();
|
||||
long worldSeed = engine != null ? engine.getSeedManager().getSeed() : rng.nextLong();
|
||||
ResourceId source = ids.of("object", objectKey);
|
||||
PlacementRequest request = new PlacementRequest(ids.of("placement/" + objectKey + "/" + x + "/" + requestedY + "/" + z),
|
||||
geometry, new BlockPosition(x, requestedY, z));
|
||||
PlacementRequest request = new PlacementRequest(geometry, new BlockPosition(x, requestedY, z));
|
||||
long seed = ModuleSeeds.placement(worldSeed, objectKey, x, requestedY, z);
|
||||
StageMetrics metrics = new StageMetrics(engine != null ? engine.getMetrics() : null);
|
||||
try (ToolWorld toolWorld = engine == null ? new ToolWorld(worldSeed, data.getPackResources(), new PackDeclaredSettings(data)) : null) {
|
||||
|
||||
@@ -36,7 +36,6 @@ import com.volmit.service.ObjectsAt;
|
||||
import com.volmit.service.SaplingGrowth;
|
||||
import com.volmit.service.StructureLocator;
|
||||
import com.volmit.service.VanillaFeatures;
|
||||
import com.volmit.service.VanillaStructures;
|
||||
import com.volmit.geometry.BlockPosition;
|
||||
import com.volmit.world.PackWorld;
|
||||
import java.util.ArrayList;
|
||||
@@ -283,7 +282,7 @@ public final class ModuleServices {
|
||||
|
||||
/** The platform structures the world's modules start themselves, as lower-case registry keys. */
|
||||
public static Set<String> startedStructures(Engine engine) {
|
||||
return platformStructures(engine, VanillaStructures::startedStructures);
|
||||
return platformStructures(engine, StructureLocator::startedStructures);
|
||||
}
|
||||
|
||||
/** Whether a module of the world starts the platform structure {@code key} itself. */
|
||||
@@ -293,7 +292,7 @@ public final class ModuleServices {
|
||||
|
||||
/** Whether a module of the world can find the starts it makes of the platform structure {@code key}. */
|
||||
public static boolean canLocateStart(Engine engine, String key) {
|
||||
return key != null && platformStructures(engine, VanillaStructures::locatableStarts).contains(normalized(key));
|
||||
return key != null && platformStructures(engine, StructureLocator::locatableStarts).contains(normalized(key));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -308,7 +307,7 @@ public final class ModuleServices {
|
||||
if (structure.isEmpty()) {
|
||||
return StructureSearch.NOT_FOUND;
|
||||
}
|
||||
for (Provider<VanillaStructures> provider : providers(engine, VanillaStructures.class)) {
|
||||
for (Provider<StructureLocator> provider : providers(engine, StructureLocator.class)) {
|
||||
if (!provider.service().locatableStarts(provider.world()).contains(structure.get())) {
|
||||
continue;
|
||||
}
|
||||
@@ -386,9 +385,9 @@ public final class ModuleServices {
|
||||
}
|
||||
|
||||
/** The platform structures every provider lists with {@code structures}, as lower-case registry keys. */
|
||||
private static Set<String> platformStructures(Engine engine, BiFunction<VanillaStructures, PackWorld, Set<ResourceId>> structures) {
|
||||
private static Set<String> platformStructures(Engine engine, BiFunction<StructureLocator, PackWorld, Set<ResourceId>> structures) {
|
||||
Set<String> keys = new LinkedHashSet<>();
|
||||
for (Provider<VanillaStructures> provider : providers(engine, VanillaStructures.class)) {
|
||||
for (Provider<StructureLocator> provider : providers(engine, StructureLocator.class)) {
|
||||
structures.apply(provider.service(), provider.world()).forEach(id -> keys.add(id.toString()));
|
||||
}
|
||||
return keys;
|
||||
|
||||
@@ -19,18 +19,24 @@
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import com.volmit.IrisFeature;
|
||||
import com.volmit.config.LinkedBiomes;
|
||||
import com.volmit.config.FeatureSettings;
|
||||
import com.volmit.config.Level;
|
||||
import com.volmit.config.PackSettings;
|
||||
import com.volmit.config.SettingsStack;
|
||||
import com.volmit.host.ConfiguredSettings;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.world.LinkedBiomes;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Module settings one dimension, region, biome or object placement declares, at most one value per settings
|
||||
@@ -72,10 +78,24 @@ public final class ModuleSettings {
|
||||
/**
|
||||
* The keys of the biomes these settings use besides ({@link LinkedBiomes#usedBiomes}), in a fixed order.
|
||||
*
|
||||
* @param dimension the settings of the dimension the owner is part of
|
||||
* @param dimension the settings of the dimension the owner is part of
|
||||
* @param dimensionKey that dimension's key
|
||||
*/
|
||||
public Set<String> usedBiomes(IrisPackResources resources, ModuleSettings dimension) {
|
||||
return linkedBiomes(resources, linked -> linked.usedBiomes(resources, dimension.values()));
|
||||
public Set<String> usedBiomes(IrisPackResources resources, ModuleSettings dimension, String dimensionKey) {
|
||||
PackSettings declared = dimension.declaredByDimension(() -> resources.idOf(IrisPackSettings.DIMENSION + "/" + dimensionKey));
|
||||
return linkedBiomes(resources, linked -> linked.usedBiomes(resources, declared));
|
||||
}
|
||||
|
||||
/** These settings as what a dimension declares itself: each type a stack of at most its dimension entry. */
|
||||
private PackSettings declaredByDimension(Supplier<ResourceId> dimension) {
|
||||
return new PackSettings() {
|
||||
@Override
|
||||
public <F extends IrisFeature> SettingsStack<F> declared(Class<F> featureType) {
|
||||
return find(featureType)
|
||||
.map(value -> SettingsStack.of(List.of(new FeatureSettings.Entry<>(Level.DIMENSION, dimension.get(), value))))
|
||||
.orElse(SettingsStack.empty());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private Set<String> linkedBiomes(IrisPackResources resources, Function<LinkedBiomes, Set<ResourceId>> pick) {
|
||||
|
||||
@@ -59,7 +59,8 @@ import java.util.stream.Stream;
|
||||
/**
|
||||
* Reads the module settings a dimension, region or biome declares: each settings feature of the pack at
|
||||
* that target, under the key the feature declares. Settings are created with their no-argument
|
||||
* constructor and the JSON is read into them, so an omitted option keeps its default. A {@link Snippet}
|
||||
* constructor and the JSON is read into them under IrisApi's {@link DecodingContract}, so an omitted or null option
|
||||
* keeps its default. A {@link Snippet}
|
||||
* type may be written as {@code "snippet/<name>"} or, as Iris's own snippets are, {@code "snippet/<snippet folder>/<name>"},
|
||||
* both read from {@code snippet/<snippet folder>/<name>.json}. IrisApi's value types ({@code BlockSpec},
|
||||
* {@code NoiseStyle} and the rest) are read like settings, and an {@code Object} as Gson reads any JSON value.
|
||||
@@ -84,7 +85,7 @@ public final class ModuleSettingsDecoder {
|
||||
this.packFolder = packFolder;
|
||||
this.irisGson = irisGson;
|
||||
PackResourceIds packIds = new PackResourceIds(packFolder.toFile());
|
||||
this.gson = new GsonBuilder()
|
||||
this.gson = DecodingContract.appliedTo(new GsonBuilder())
|
||||
.registerTypeAdapter(BlockState.class, textAdapter(BlockState::parse, BlockState::key))
|
||||
.registerTypeAdapter(ResourceId.class, textAdapter(text -> resourceIdOf(packIds, text), ResourceId::toString))
|
||||
.registerTypeAdapterFactory(new HostTypes())
|
||||
|
||||
@@ -356,7 +356,7 @@ public final class ModuleStructureFitting implements NativeStructureFitting {
|
||||
@Override
|
||||
public Optional<StartMemo> memo() {
|
||||
NativeStartMemo memo = start.memo();
|
||||
return memo == null ? Optional.empty() : Optional.of(new StartMemo(memo.terrain(), memo.foundation()));
|
||||
return memo == null ? Optional.empty() : Optional.of(new StartMemo(memo.text()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -127,7 +127,7 @@ public final class ModuleVanillaStructures {
|
||||
if (structure.isEmpty()) {
|
||||
return List.of(NativeStructureReach.PLATFORM);
|
||||
}
|
||||
Optional<StartMemo> startMemo = Optional.ofNullable(memo).map(note -> new StartMemo(note.terrain(), note.foundation()));
|
||||
Optional<StartMemo> startMemo = Optional.ofNullable(memo).map(note -> new StartMemo(note.text()));
|
||||
List<NativeStructureReach> reaches = new ArrayList<>(structures.providers.size());
|
||||
for (ServiceRegistration registration : structures.providers) {
|
||||
StartReach reach = ask(registration, "reaching around vanilla structure " + structure.get(),
|
||||
@@ -218,9 +218,8 @@ public final class ModuleVanillaStructures {
|
||||
start.y() + minHeight,
|
||||
start.isUnderground(),
|
||||
start.replacesPlatformStart(),
|
||||
start.identity(),
|
||||
start.jigsaw().map(ModuleVanillaStructures::jigsaw).orElse(null),
|
||||
start.memo().map(memo -> new NativeStartMemo(memo.terrain(), memo.foundation())).orElse(null));
|
||||
start.memo().map(memo -> new NativeStartMemo(memo.text())).orElse(null));
|
||||
}
|
||||
|
||||
private static NativeJigsawOverrides jigsaw(JigsawOverrides overrides) {
|
||||
|
||||
@@ -2,13 +2,12 @@ package art.arcane.iris.engine.framework;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* What a module noted about a start it placed, as the host keeps it: two texts in the module's own format, one about
|
||||
* the start's terrain and one about its foundation. The host never reads them.
|
||||
*/
|
||||
public record NativeStartMemo(String terrain, String foundation) {
|
||||
/** The memo a module gave a start it placed, as the host keeps it: one text the host never reads, not empty. */
|
||||
public record NativeStartMemo(String text) {
|
||||
public NativeStartMemo {
|
||||
Objects.requireNonNull(terrain, "terrain");
|
||||
Objects.requireNonNull(foundation, "foundation");
|
||||
Objects.requireNonNull(text, "text");
|
||||
if (text.isEmpty()) {
|
||||
throw new IllegalArgumentException("A start memo's text must not be empty");
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
-27
@@ -13,7 +13,6 @@ public record NativeStructureOwnershipRecord(
|
||||
String structureKey,
|
||||
int originChunkX,
|
||||
int originChunkZ,
|
||||
long placementIdentity,
|
||||
int baseY,
|
||||
int contentMinX,
|
||||
int contentMinY,
|
||||
@@ -29,7 +28,7 @@ public record NativeStructureOwnershipRecord(
|
||||
String contentFingerprint,
|
||||
MemoSnapshot memo
|
||||
) {
|
||||
public static final int CURRENT_SCHEMA = 2;
|
||||
public static final int CURRENT_SCHEMA = 3;
|
||||
public static final int MAX_REFERENCE_DISTANCE_CHUNKS = 8;
|
||||
private static final int MAX_KEY_BYTES = 512;
|
||||
private static final int MAX_FINGERPRINT_BYTES = 128;
|
||||
@@ -70,7 +69,6 @@ public record NativeStructureOwnershipRecord(
|
||||
public static NativeStructureOwnershipRecord create(String structureKey,
|
||||
int originChunkX,
|
||||
int originChunkZ,
|
||||
long placementIdentity,
|
||||
int baseY,
|
||||
int contentMinX,
|
||||
int contentMinY,
|
||||
@@ -90,7 +88,6 @@ public record NativeStructureOwnershipRecord(
|
||||
structureKey,
|
||||
originChunkX,
|
||||
originChunkZ,
|
||||
placementIdentity,
|
||||
baseY,
|
||||
contentMinX,
|
||||
contentMinY,
|
||||
@@ -121,7 +118,6 @@ public record NativeStructureOwnershipRecord(
|
||||
structureKey,
|
||||
originChunkX,
|
||||
originChunkZ,
|
||||
placementIdentity,
|
||||
baseY,
|
||||
contentMinX,
|
||||
contentMinY,
|
||||
@@ -153,7 +149,6 @@ public record NativeStructureOwnershipRecord(
|
||||
writeString(output, structureKey, MAX_KEY_BYTES, "structure key");
|
||||
output.writeInt(originChunkX);
|
||||
output.writeInt(originChunkZ);
|
||||
output.writeLong(placementIdentity);
|
||||
output.writeInt(baseY);
|
||||
output.writeInt(contentMinX);
|
||||
output.writeInt(contentMinY);
|
||||
@@ -181,7 +176,6 @@ public record NativeStructureOwnershipRecord(
|
||||
readString(input, MAX_KEY_BYTES, "structure key"),
|
||||
input.readInt(),
|
||||
input.readInt(),
|
||||
input.readLong(),
|
||||
input.readInt(),
|
||||
input.readInt(),
|
||||
input.readInt(),
|
||||
@@ -247,40 +241,30 @@ public record NativeStructureOwnershipRecord(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The start's memo as the record stores it: the foundation text, then the terrain text. Records written before
|
||||
* memos existed hold the JSON of the start's stilts and terrain fit in these two places, which is what the module
|
||||
* writes as its memo, so they read the same. A start without a memo stores two empty texts.
|
||||
*/
|
||||
public record MemoSnapshot(String foundation, String terrain) {
|
||||
private static final int MAX_MEMO_BYTES = 65_536;
|
||||
private static final MemoSnapshot NONE = new MemoSnapshot("", "");
|
||||
/** The start's memo as the record stores it: the module's text, empty for a start without a memo. */
|
||||
public record MemoSnapshot(String text) {
|
||||
private static final int MAX_MEMO_BYTES = 131_072;
|
||||
private static final MemoSnapshot NONE = new MemoSnapshot("");
|
||||
|
||||
public MemoSnapshot {
|
||||
foundation = Objects.requireNonNull(foundation, "Native structure foundation memo must not be null");
|
||||
terrain = Objects.requireNonNull(terrain, "Native structure terrain memo must not be null");
|
||||
requireUtf8Limit(foundation, MAX_MEMO_BYTES, "foundation memo");
|
||||
requireUtf8Limit(terrain, MAX_MEMO_BYTES, "terrain memo");
|
||||
text = Objects.requireNonNull(text, "Native structure memo must not be null");
|
||||
requireUtf8Limit(text, MAX_MEMO_BYTES, "memo");
|
||||
}
|
||||
|
||||
public static MemoSnapshot of(NativeStartMemo memo) {
|
||||
return memo == null ? NONE : new MemoSnapshot(memo.foundation(), memo.terrain());
|
||||
return memo == null ? NONE : new MemoSnapshot(memo.text());
|
||||
}
|
||||
|
||||
public NativeStartMemo restore() {
|
||||
return equals(NONE) ? null : new NativeStartMemo(terrain, foundation);
|
||||
return equals(NONE) ? null : new NativeStartMemo(text);
|
||||
}
|
||||
|
||||
void write(DataOutputStream output) throws IOException {
|
||||
writeString(output, foundation, MAX_MEMO_BYTES, "foundation memo");
|
||||
writeString(output, terrain, MAX_MEMO_BYTES, "terrain memo");
|
||||
writeString(output, text, MAX_MEMO_BYTES, "memo");
|
||||
}
|
||||
|
||||
static MemoSnapshot read(DataInputStream input) throws IOException {
|
||||
return new MemoSnapshot(
|
||||
readString(input, MAX_MEMO_BYTES, "foundation memo"),
|
||||
readString(input, MAX_MEMO_BYTES, "terrain memo")
|
||||
);
|
||||
return new MemoSnapshot(readString(input, MAX_MEMO_BYTES, "memo"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import java.util.Objects;
|
||||
/**
|
||||
* One start of a platform structure a module places, as the platform code builds it: the structure key, the start
|
||||
* chunk, the world base Y (the structure's lowest block when underground, the planned surface otherwise), whether it
|
||||
* takes the chunk from a platform start of the same structure, the identity of what placed it, the changes to the
|
||||
* takes the chunk from a platform start of the same structure, the changes to the
|
||||
* jigsaw definition it is assembled with (null for none), and the memo the module gave it (null for none), which the
|
||||
* ownership record keeps for every later chunk of the start.
|
||||
*/
|
||||
@@ -16,7 +16,6 @@ public record NativeStructureStartPlan(
|
||||
int baseY,
|
||||
boolean underground,
|
||||
boolean replacesPlatformStart,
|
||||
long placementIdentity,
|
||||
NativeJigsawOverrides jigsaw,
|
||||
NativeStartMemo memo
|
||||
) {
|
||||
|
||||
+32
-2
@@ -37,7 +37,7 @@ import java.util.Set;
|
||||
* the ones the world's placements assemble from jigsaw pools, and their nearest start, searched with
|
||||
* {@link IrisStructureLocator}. The keys it places also name the platform structures its native placements start and
|
||||
* the ones its structures stand in for; it locates those too. The platform's own locate of a natively started
|
||||
* structure goes through {@link StructureVanillaStructures#locateStart} instead.
|
||||
* structure goes through {@link #locateStart}, which searches the native placements' rings.
|
||||
* <p>
|
||||
* Iris's locator names structures by key: a pack structure by its pack key, a platform structure by its
|
||||
* {@code namespace:path}. A key with a namespace is that id; any other is the pack's.
|
||||
@@ -64,7 +64,29 @@ public final class StructureLocating implements StructureLocator {
|
||||
public LocateResult locate(PackWorld world, ResourceId structure, int fromX, int fromZ, int maxRadiusChunks) {
|
||||
Engine engine = engine(world);
|
||||
String key = keyOf(world.resources(), IrisStructureLocator.placedKeysAndAliases(engine), structure);
|
||||
IrisStructureLocator.LocateResult result = IrisStructureLocator.locate(engine, key, fromX, fromZ, maxRadiusChunks);
|
||||
return apiResult(engine, IrisStructureLocator.locate(engine, key, fromX, fromZ, maxRadiusChunks));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<ResourceId> startedStructures(PackWorld world) {
|
||||
return platformIds(IrisStructureLocator.nativeKeys(engine(world)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<ResourceId> locatableStarts(PackWorld world) {
|
||||
return platformIds(IrisStructureLocator.locatableNativeKeys(engine(world)));
|
||||
}
|
||||
|
||||
/** Searches the rings of the placements that start {@code structure} natively, as the platform's own locate does. */
|
||||
@Override
|
||||
public LocateResult locateStart(PackWorld world, ResourceId structure, int fromX, int fromZ, int maxRings,
|
||||
ChunkFilter accepts) {
|
||||
Engine engine = engine(world);
|
||||
return apiResult(engine, IrisStructureLocator.locateInPlacementRings(
|
||||
engine, structure.toString(), fromX, fromZ, maxRings, accepts::accepts));
|
||||
}
|
||||
|
||||
private static LocateResult apiResult(Engine engine, IrisStructureLocator.LocateResult result) {
|
||||
return switch (result.status()) {
|
||||
case FOUND -> LocateResult.found(new BlockPosition(result.originX(), result.baseY() - engine.getMinHeight(), result.originZ()));
|
||||
case NOT_FOUND -> LocateResult.NOT_FOUND;
|
||||
@@ -72,6 +94,14 @@ public final class StructureLocating implements StructureLocator {
|
||||
};
|
||||
}
|
||||
|
||||
private static Set<ResourceId> platformIds(Set<String> keys) {
|
||||
Set<ResourceId> ids = new LinkedHashSet<>();
|
||||
for (String key : keys) {
|
||||
ids.add(ResourceId.parse(key.toLowerCase(Locale.ROOT)));
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
||||
private static Engine engine(PackWorld world) {
|
||||
return world.extension(Engine.class).orElseThrow();
|
||||
}
|
||||
|
||||
+3
-42
@@ -20,13 +20,11 @@ package art.arcane.iris.engine.framework.structure;
|
||||
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.IrisStructureLocator;
|
||||
import art.arcane.iris.engine.framework.StructurePlacementGrid;
|
||||
import art.arcane.iris.engine.framework.structure.fit.StartLayouts;
|
||||
import art.arcane.iris.engine.framework.structure.fit.StructureFitting;
|
||||
import art.arcane.iris.builtin.structure.StructurePlacement;
|
||||
import art.arcane.iris.builtin.structure.NativeStructureSuppression;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.service.LocateResult;
|
||||
import com.volmit.service.VanillaStructures;
|
||||
import com.volmit.vanilla.PlatformStart;
|
||||
import com.volmit.vanilla.StartMemo;
|
||||
@@ -37,22 +35,18 @@ import com.volmit.vanilla.VanillaStructureRule;
|
||||
import com.volmit.vanilla.VanillaStructureSetup;
|
||||
import com.volmit.vanilla.VanillaStructureStart;
|
||||
import com.volmit.vanilla.VanillaStructureStartContext;
|
||||
import com.volmit.geometry.BlockPosition;
|
||||
import com.volmit.world.PackWorld;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* What {@code iris:structure} says about the platform's own structures. The dimension's {@code importedStructures}
|
||||
* settings ({@link ImportedStructures}) disable, move, fit and set them up; the pack's structure placements replace
|
||||
* them ({@code vanillaSource} with native suppression), place them alongside ({@link IrisStructureLocator#isPlaced}),
|
||||
* start them where their {@code nativeStructures} grids say ({@link NativeStartPlanner}) and fit those starts the way
|
||||
* the placement says, which their memo carries to every chunk they reach ({@link StructureFitting}). It names the
|
||||
* structures its native placements start and finds their starts for the platform's own locate.
|
||||
* the placement says, which their memo carries to every chunk they reach ({@link StructureFitting}). Finding those
|
||||
* starts is {@link StructureLocating}'s.
|
||||
*/
|
||||
public final class StructureVanillaStructures implements VanillaStructures {
|
||||
/**
|
||||
@@ -108,49 +102,16 @@ public final class StructureVanillaStructures implements VanillaStructures {
|
||||
return ImportedStructures.of(context.settings()).setup();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<ResourceId> startedStructures(PackWorld world) {
|
||||
return structureIds(IrisStructureLocator.nativeKeys(engine(world)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<ResourceId> locatableStarts(PackWorld world) {
|
||||
return structureIds(IrisStructureLocator.locatableNativeKeys(engine(world)));
|
||||
}
|
||||
|
||||
/** Searches the rings of the placements that start {@code structure} natively, as the platform's own locate does. */
|
||||
@Override
|
||||
public LocateResult locateStart(PackWorld world, ResourceId structure, int fromX, int fromZ, int maxRings,
|
||||
ChunkFilter accepts) {
|
||||
Engine engine = engine(world);
|
||||
IrisStructureLocator.LocateResult result = IrisStructureLocator.locateInPlacementRings(
|
||||
engine, structure.toString(), fromX, fromZ, maxRings, accepts::accepts);
|
||||
return switch (result.status()) {
|
||||
case FOUND -> LocateResult.found(new BlockPosition(result.originX(), result.baseY() - engine.getMinHeight(), result.originZ()));
|
||||
case NOT_FOUND -> LocateResult.NOT_FOUND;
|
||||
case SEARCH_LIMIT_REACHED -> LocateResult.SEARCH_LIMIT_REACHED;
|
||||
};
|
||||
}
|
||||
|
||||
private static Engine engine(PackWorld world) {
|
||||
return world.extension(Engine.class).orElseThrow();
|
||||
}
|
||||
|
||||
private static Set<ResourceId> structureIds(Set<String> keys) {
|
||||
Set<ResourceId> ids = new LinkedHashSet<>();
|
||||
for (String key : keys) {
|
||||
ids.add(ResourceId.parse(key.toLowerCase(Locale.ROOT)));
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
||||
/** {@code plan} as the start the platform generates: heights above the bottom, the placement's identity and fit. */
|
||||
/** {@code plan} as the start the platform generates: heights above the bottom and the placement's fit. */
|
||||
static VanillaStructureStart start(NativeStartPlanner.Plan plan, int minHeight) {
|
||||
StructurePlacement placement = plan.placement();
|
||||
NativeStructureFit fit = new NativeStructureFit(0, null, false, placement.stilt().orElse(null), placement.resolvedTerrain());
|
||||
VanillaStructureStart start = VanillaStructureStart.at(ResourceId.parse(plan.source().structure()),
|
||||
plan.chunkX(), plan.chunkZ(), plan.baseY() - minHeight)
|
||||
.withIdentity(StructurePlacementGrid.placementIdentity(placement))
|
||||
.withMemo(fit.memo());
|
||||
if (placement.underground()) {
|
||||
start = start.underground();
|
||||
|
||||
@@ -347,7 +347,7 @@ public class IrisDimension extends IrisRegistrant {
|
||||
}
|
||||
}
|
||||
|
||||
addReachableBiomeKeys(pending, getModuleSettings().usedBiomes(data.getPackResources(), getModuleSettings()));
|
||||
addReachableBiomeKeys(pending, getModuleSettings().usedBiomes(data.getPackResources(), getModuleSettings(), getLoadKey()));
|
||||
|
||||
Set<String> visited = new HashSet<>();
|
||||
while (!pending.isEmpty()) {
|
||||
@@ -370,7 +370,7 @@ public class IrisDimension extends IrisRegistrant {
|
||||
biomes.put(loadKey, biome);
|
||||
addReachableBiomeKeys(pending, biome.getChildren());
|
||||
addReachableBiomeKeys(pending, biome.getModuleSettings().treeBiomes(data.getPackResources()));
|
||||
addReachableBiomeKeys(pending, biome.getModuleSettings().usedBiomes(data.getPackResources(), getModuleSettings()));
|
||||
addReachableBiomeKeys(pending, biome.getModuleSettings().usedBiomes(data.getPackResources(), getModuleSettings(), getLoadKey()));
|
||||
}
|
||||
|
||||
return biomes.v();
|
||||
|
||||
@@ -188,7 +188,7 @@ public class CarveSettingsDecodingTest {
|
||||
assertEquals("carving/mushroom", settings.find(CarvingBiomeSettings.class).orElseThrow().biome());
|
||||
IrisPackResources resources = PackResourceFixture.empty(packFolder.toFile());
|
||||
assertEquals(Set.of("carving/mushroom"), settings.treeBiomes(resources));
|
||||
assertEquals(Set.of(), settings.usedBiomes(resources, ModuleSettings.NONE));
|
||||
assertEquals(Set.of(), settings.usedBiomes(resources, ModuleSettings.NONE, "overworld"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -121,7 +121,7 @@ public class FloatingSettingsDecodingTest {
|
||||
ModuleSettings dimensionSettings = decoder.decode(Level.DIMENSION, file("dimensions/overworld.json"), "dimension overworld");
|
||||
|
||||
IrisPackResources resources = PackResourceFixture.empty(packFolder.toFile());
|
||||
Set<String> used = biomeSettings.usedBiomes(resources, dimensionSettings);
|
||||
Set<String> used = biomeSettings.usedBiomes(resources, dimensionSettings, "overworld");
|
||||
|
||||
assertEquals(new LinkedHashSet<>(List.of("mushroom/forest", "carving/mushroom", "tropical/wilds", "carving/lush-child")), used);
|
||||
assertEquals(Set.of(), biomeSettings.treeBiomes(resources));
|
||||
@@ -135,9 +135,9 @@ public class FloatingSettingsDecodingTest {
|
||||
ModuleSettings dimensionSettings = BuiltInPack.settings(new CarvingSettings(List.of(band)));
|
||||
|
||||
IrisPackResources resources = PackResourceFixture.empty(packFolder.toFile());
|
||||
assertEquals(new LinkedHashSet<>(List.of("floating/target", "carving/deep")), biomeSettings.usedBiomes(resources, dimensionSettings));
|
||||
assertEquals(new LinkedHashSet<>(List.of("floating/target", "carving/deep")), biomeSettings.usedBiomes(resources, dimensionSettings, "overworld"));
|
||||
assertEquals("without bands the name is taken as a biome key", new LinkedHashSet<>(List.of("floating/target", "deep")),
|
||||
biomeSettings.usedBiomes(resources, ModuleSettings.NONE));
|
||||
biomeSettings.usedBiomes(resources, ModuleSettings.NONE, "overworld"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -47,7 +47,8 @@ import static org.mockito.Mockito.when;
|
||||
/** IrisApi's value types read the JSON of Iris's own classes and resolve, and build noise, exactly as those do. */
|
||||
public class IrisValuesTest {
|
||||
private static final double[][] COLUMNS = {{0, 0}, {17.5, -3}, {-640, 1280}, {12345.25, 678.5}};
|
||||
private static final Map<Class<?>, Set<String>> IRIS_ONLY_FIELDS = Map.of(IrisBlockData.class, Set.of("debug"));
|
||||
private static final Map<Class<?>, Set<String>> IRIS_ONLY_FIELDS = Map.of(IrisBlockData.class, Set.of("debug"),
|
||||
IrisGeneratorStyle.class, Set.of("cacheSize"));
|
||||
|
||||
@After
|
||||
public void unbindPlatform() {
|
||||
|
||||
@@ -39,6 +39,7 @@ import com.volmit.host.LoadedPack;
|
||||
import com.volmit.host.ModuleHost;
|
||||
import com.volmit.noise.NoiseStyle;
|
||||
import com.volmit.noise.StyledRange;
|
||||
import com.volmit.vanilla.JigsawOverrides;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.stage.Stage;
|
||||
import com.volmit.geometry.BlockPosition;
|
||||
@@ -100,6 +101,7 @@ public class ModuleSettingsDecoderTest {
|
||||
private Range light = Range.of(0, 15);
|
||||
private BlockPosition offset = new BlockPosition(0, 0, 0);
|
||||
private Map<String, Object> extra = Map.of();
|
||||
private JigsawOverrides jigsaw = JigsawOverrides.none();
|
||||
}
|
||||
|
||||
public static final class MossModule implements IrisModule {
|
||||
@@ -216,6 +218,36 @@ public class ModuleSettingsDecoderTest {
|
||||
assertEquals(Map.of("list", List.of(1.0, "a", true)), values.extra);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aNullMemberIsLeftOutSoTheFieldKeepsItsInitialiser() {
|
||||
ValuesSettings values = values("""
|
||||
{"mossValues": {
|
||||
"palette": [{"block": null, "data": null, "tileData": null}],
|
||||
"style": null,
|
||||
"height": {"style": null},
|
||||
"jigsaw": {"liquidSettings": null, "startPool": null}
|
||||
}}
|
||||
""");
|
||||
|
||||
assertEquals(BlockSpec.of("air"), values.palette.getFirst());
|
||||
assertEquals(NoiseStyle.of("SIMPLEX"), values.style);
|
||||
assertEquals(NoiseStyle.of("STATIC"), values.height.style());
|
||||
assertEquals(JigsawOverrides.none(), values.jigsaw);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void anUnknownEnumNameIsAnErrorNamingTheKnownOnes() {
|
||||
IllegalArgumentException failure = assertThrows(IllegalArgumentException.class,
|
||||
() -> values("{\"mossValues\": {\"jigsaw\": {\"liquidSettings\": \"WET\"}}}"));
|
||||
|
||||
assertTrue(failure.getMessage(), failure.getMessage().contains(
|
||||
"\"WET\" is not one of [SOURCE, IGNORE_WATERLOGGING, APPLY_WATERLOGGING]"));
|
||||
}
|
||||
|
||||
private ValuesSettings values(String json) {
|
||||
return decoder.decode(Level.BIOME, new JSONObject(json), "biome desert/dunes").find(ValuesSettings.class).orElseThrow();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void badValuesNameTheSettingsKeyAndResource() {
|
||||
IllegalArgumentException failure = assertThrows(IllegalArgumentException.class,
|
||||
|
||||
+22
-36
@@ -28,8 +28,8 @@ public class NativeStructureOwnershipRecordTest {
|
||||
|
||||
@Test
|
||||
public void binaryRoundTripPreservesMultipleVersionedOwnershipRecords() throws Exception {
|
||||
NativeStructureOwnershipRecord tavern = record("nova_structures:tavern_oak", 4, -7, 71L);
|
||||
NativeStructureOwnershipRecord crypt = record("nova_structures:undead_crypt", 4, -7, 72L);
|
||||
NativeStructureOwnershipRecord tavern = record("nova_structures:tavern_oak", 4, -7);
|
||||
NativeStructureOwnershipRecord crypt = record("nova_structures:undead_crypt", 4, -7);
|
||||
NativeStructureOwnershipBundle bundle = NativeStructureOwnershipBundle.empty()
|
||||
.with(tavern)
|
||||
.with(crypt);
|
||||
@@ -43,23 +43,23 @@ public class NativeStructureOwnershipRecordTest {
|
||||
assertEquals(crypt, restored.find("nova_structures:undead_crypt", 4, -7));
|
||||
}
|
||||
|
||||
/** The stilts and terrain fit JSON records written before memos hold, as the old Iris classes wrote them. */
|
||||
@Test
|
||||
public void recordsWrittenBeforeMemosReadAsTheStructureModulesMemo() throws Exception {
|
||||
String stilts = "{\"maxDepth\":91,\"palette\":{\"style\":{\"style\":\"STATIC\",\"cellularFrequency\":0.0,"
|
||||
+ "\"cellularZoom\":1.0,\"zoom\":1.0,\"multiplier\":1.0,\"exponent\":1.0,\"cacheSize\":0},\"zoom\":5.0,"
|
||||
+ "\"palette\":[{\"block\":\"minecraft:stone_bricks\",\"debug\":false,\"weight\":2,"
|
||||
+ "\"data\":{\"waterlogged\":false},\"tileData\":{}}]},\"spacing\":4,\"supportNonOccluding\":true}";
|
||||
public void theStructureModulesMemoRoundTripsUnchanged() throws Exception {
|
||||
String stilts = "{\"maxDepth\":91,\"palette\":{\"style\":{\"style\":\"STATIC\",\"zoom\":1.0},\"zoom\":5.0,"
|
||||
+ "\"palette\":[{\"block\":\"minecraft:stone_bricks\",\"weight\":2,\"data\":{\"waterlogged\":false}}]},"
|
||||
+ "\"spacing\":4,\"supportNonOccluding\":true}";
|
||||
String terrain = "{\"mode\":\"FORCE_CARVE\",\"horizontalPadding\":9,\"ceilingPadding\":3,\"floorPadding\":2,"
|
||||
+ "\"shape\":\"ERODED\",\"erosionStrength\":0.42,\"erosionFrequency\":0.17,\"lobeFrequency\":0.03,"
|
||||
+ "\"lobeStrength\":0.61}";
|
||||
String text = "{\"terrain\":" + terrain + ",\"stilts\":" + stilts + "}";
|
||||
ByteArrayOutputStream encoded = new ByteArrayOutputStream();
|
||||
new NativeStructureOwnershipRecord.MemoSnapshot(stilts, terrain).write(new DataOutputStream(encoded));
|
||||
NativeStructureOwnershipRecord.MemoSnapshot.of(new NativeStartMemo(text)).write(new DataOutputStream(encoded));
|
||||
|
||||
NativeStartMemo memo = NativeStructureOwnershipRecord.MemoSnapshot.read(
|
||||
new DataInputStream(new ByteArrayInputStream(encoded.toByteArray()))).restore();
|
||||
NativeStructureFit fit = NativeStructureFit.of(new StartMemo(memo.terrain(), memo.foundation()));
|
||||
NativeStructureFit fit = NativeStructureFit.of(new StartMemo(memo.text()));
|
||||
|
||||
assertEquals(text, memo.text());
|
||||
assertEquals(StructureTerrainMode.FORCE_CARVE, fit.terrain().resolvedMode());
|
||||
assertEquals(StructureCarveShape.ERODED, fit.terrain().resolvedShape());
|
||||
assertEquals(9, fit.terrain().horizontalPadding());
|
||||
@@ -83,7 +83,7 @@ public class NativeStructureOwnershipRecordTest {
|
||||
|
||||
@Test
|
||||
public void recordCarriesLocateAndReferenceEnvelopeState() {
|
||||
NativeStructureOwnershipRecord record = record("nova_structures:tavern_oak", -3, 9, 83L);
|
||||
NativeStructureOwnershipRecord record = record("nova_structures:tavern_oak", -3, 9);
|
||||
|
||||
assertEquals(47, record.baseY());
|
||||
assertEquals(43, record.contentMinY());
|
||||
@@ -91,20 +91,18 @@ public class NativeStructureOwnershipRecordTest {
|
||||
assertEquals(58, record.locatorY());
|
||||
assertTrue(record.covers(-5, 11));
|
||||
assertFalse(record.covers(-6, 11));
|
||||
assertEquals(83L, record.placementIdentity());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void referenceEnvelopeRefreshPreservesPersistedAuthority() {
|
||||
NativeStructureOwnershipRecord original = record(
|
||||
"nova_structures:tavern_oak", -3, 9, 83L);
|
||||
"nova_structures:tavern_oak", -3, 9);
|
||||
|
||||
NativeStructureOwnershipRecord refreshed = original.withReferenceEnvelope(
|
||||
-6, 0, 6, 12);
|
||||
|
||||
assertEquals(original.schema(), refreshed.schema());
|
||||
assertEquals(original.ownershipKey(), refreshed.ownershipKey());
|
||||
assertEquals(original.placementIdentity(), refreshed.placementIdentity());
|
||||
assertEquals(original.baseY(), refreshed.baseY());
|
||||
assertEquals(original.contentMinX(), refreshed.contentMinX());
|
||||
assertEquals(original.contentMinY(), refreshed.contentMinY());
|
||||
@@ -122,9 +120,9 @@ public class NativeStructureOwnershipRecordTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ownershipRoundTripPreservesExactBoundsAndPriority() throws Exception {
|
||||
public void ownershipRoundTripPreservesExactBounds() throws Exception {
|
||||
NativeStructureOwnershipRecord ownership = record(
|
||||
"nova_structures:tavern_oak", -3, 9, 83L);
|
||||
"nova_structures:tavern_oak", -3, 9);
|
||||
NativeStructureOwnershipBundle bundle = NativeStructureOwnershipBundle.empty().with(ownership);
|
||||
ByteArrayOutputStream encoded = new ByteArrayOutputStream();
|
||||
bundle.write(new DataOutputStream(encoded));
|
||||
@@ -134,13 +132,13 @@ public class NativeStructureOwnershipRecordTest {
|
||||
.find(ownership.structureKey(), ownership.originChunkX(), ownership.originChunkZ());
|
||||
|
||||
assertNotNull(restored);
|
||||
assertEquals(ownership.placementIdentity(), restored.placementIdentity());
|
||||
assertEquals(ownership.contentMinX(), restored.contentMinX());
|
||||
assertEquals(ownership.contentMinY(), restored.contentMinY());
|
||||
assertEquals(ownership.contentMinZ(), restored.contentMinZ());
|
||||
assertEquals(ownership.contentMaxX(), restored.contentMaxX());
|
||||
assertEquals(ownership.contentMaxY(), restored.contentMaxY());
|
||||
assertEquals(ownership.contentMaxZ(), restored.contentMaxZ());
|
||||
assertEquals(ownership.memo(), restored.memo());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -150,7 +148,6 @@ public class NativeStructureOwnershipRecordTest {
|
||||
"nova_structures:tavern_oak",
|
||||
0,
|
||||
0,
|
||||
1L,
|
||||
47,
|
||||
0,
|
||||
43,
|
||||
@@ -170,7 +167,7 @@ public class NativeStructureOwnershipRecordTest {
|
||||
Map<NativeStructureOwnershipRecord.OwnershipKey, NativeStructureOwnershipRecord> records =
|
||||
new LinkedHashMap<>();
|
||||
for (int i = 0; i <= NativeStructureOwnershipBundle.MAX_RECORDS; i++) {
|
||||
NativeStructureOwnershipRecord record = record("test:structure_" + i, 0, 0, i);
|
||||
NativeStructureOwnershipRecord record = record("test:structure_" + i, 0, 0);
|
||||
records.put(record.ownershipKey(), record);
|
||||
}
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
@@ -179,17 +176,13 @@ public class NativeStructureOwnershipRecordTest {
|
||||
Map<NativeStructureOwnershipRecord.OwnershipKey, NativeStructureOwnershipRecord> oversized =
|
||||
new LinkedHashMap<>();
|
||||
NativeStructureOwnershipRecord.MemoSnapshot largeDecision =
|
||||
new NativeStructureOwnershipRecord.MemoSnapshot(
|
||||
"null",
|
||||
"{\"unused\":\"" + "x".repeat(65_000) + "\"}"
|
||||
);
|
||||
new NativeStructureOwnershipRecord.MemoSnapshot("{\"unused\":\"" + "x".repeat(65_000) + "\"}");
|
||||
for (int i = 0; i < 33; i++) {
|
||||
NativeStructureOwnershipRecord record = new NativeStructureOwnershipRecord(
|
||||
NativeStructureOwnershipRecord.CURRENT_SCHEMA,
|
||||
"test:large_" + i,
|
||||
0,
|
||||
0,
|
||||
i,
|
||||
47,
|
||||
0,
|
||||
43,
|
||||
@@ -218,7 +211,6 @@ public class NativeStructureOwnershipRecordTest {
|
||||
"test:overflow",
|
||||
Integer.MAX_VALUE,
|
||||
0,
|
||||
1L,
|
||||
47,
|
||||
0,
|
||||
43,
|
||||
@@ -243,7 +235,6 @@ public class NativeStructureOwnershipRecordTest {
|
||||
"test:outside_envelope",
|
||||
0,
|
||||
0,
|
||||
1L,
|
||||
47,
|
||||
-16,
|
||||
43,
|
||||
@@ -268,7 +259,6 @@ public class NativeStructureOwnershipRecordTest {
|
||||
"test:displaced",
|
||||
0,
|
||||
0,
|
||||
1L,
|
||||
47,
|
||||
80,
|
||||
43,
|
||||
@@ -291,14 +281,14 @@ public class NativeStructureOwnershipRecordTest {
|
||||
|
||||
@Test
|
||||
public void nullableStiltRoundTripsAsNull() {
|
||||
NativeStructureOwnershipRecord record = record("test:no_stilt", 0, 0, 1L);
|
||||
NativeStructureOwnershipRecord record = record("test:no_stilt", 0, 0);
|
||||
NativeStartMemo memo = record.restoredMemo();
|
||||
assertNull(NativeStructureFit.of(new StartMemo(memo.terrain(), memo.foundation())).stilts());
|
||||
assertNull(NativeStructureFit.of(new StartMemo(memo.text())).stilts());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bundlesWrittenUnderAnOlderSchemaRevisionFailClosed() throws Exception {
|
||||
NativeStructureOwnershipRecord record = record("nova_structures:tavern_oak", 4, -7, 71L);
|
||||
NativeStructureOwnershipRecord record = record("nova_structures:tavern_oak", 4, -7);
|
||||
NativeStructureOwnershipBundle bundle = NativeStructureOwnershipBundle.empty().with(record);
|
||||
ByteArrayOutputStream encoded = new ByteArrayOutputStream();
|
||||
bundle.write(new DataOutputStream(encoded));
|
||||
@@ -319,7 +309,6 @@ public class NativeStructureOwnershipRecordTest {
|
||||
NativeStructureOwnershipRecord.writeString(output, " ", 512, "structure key");
|
||||
output.writeInt(0);
|
||||
output.writeInt(0);
|
||||
output.writeLong(1L);
|
||||
output.writeInt(47);
|
||||
output.writeInt(0);
|
||||
output.writeInt(43);
|
||||
@@ -339,14 +328,12 @@ public class NativeStructureOwnershipRecordTest {
|
||||
new DataInputStream(new ByteArrayInputStream(encoded.toByteArray()))));
|
||||
}
|
||||
|
||||
private static NativeStructureOwnershipRecord record(String key, int originX, int originZ,
|
||||
long placementIdentity) {
|
||||
private static NativeStructureOwnershipRecord record(String key, int originX, int originZ) {
|
||||
return new NativeStructureOwnershipRecord(
|
||||
NativeStructureOwnershipRecord.CURRENT_SCHEMA,
|
||||
key,
|
||||
originX,
|
||||
originZ,
|
||||
placementIdentity,
|
||||
47,
|
||||
originX << 4,
|
||||
43,
|
||||
@@ -365,7 +352,6 @@ public class NativeStructureOwnershipRecordTest {
|
||||
}
|
||||
|
||||
private static NativeStructureOwnershipRecord.MemoSnapshot decision() {
|
||||
StartMemo memo = NativeStructureFit.NONE.memo();
|
||||
return NativeStructureOwnershipRecord.MemoSnapshot.of(new NativeStartMemo(memo.terrain(), memo.foundation()));
|
||||
return NativeStructureOwnershipRecord.MemoSnapshot.of(new NativeStartMemo(NativeStructureFit.NONE.memo().text()));
|
||||
}
|
||||
}
|
||||
+12
-11
@@ -60,7 +60,7 @@ public class NativeStructureOwnershipStoreTest {
|
||||
3, 4, current.structureKey(), 2, 3);
|
||||
|
||||
assertEquals(current, resolved);
|
||||
assertEquals(terrain(9), resolved.restoredMemo().terrain());
|
||||
assertEquals(memoText(terrain(9), 11L), resolved.restoredMemo().text());
|
||||
assertEquals(stale.contentFingerprint(), resolved.contentFingerprint());
|
||||
assertEquals(stale, storage.find(target, stale));
|
||||
}
|
||||
@@ -404,19 +404,17 @@ public class NativeStructureOwnershipStoreTest {
|
||||
return engine;
|
||||
}
|
||||
|
||||
private static NativeStructureOwnershipRecord record(String key, int originX, int originZ,
|
||||
long placementIdentity) {
|
||||
return record(key, originX, originZ, placementIdentity, "{}", 8);
|
||||
/** {@code variant} goes into the record's memo, telling apart records that are otherwise alike. */
|
||||
private static NativeStructureOwnershipRecord record(String key, int originX, int originZ, long variant) {
|
||||
return record(key, originX, originZ, variant, "{}", 8);
|
||||
}
|
||||
|
||||
private static NativeStructureOwnershipRecord record(String key, int originX, int originZ,
|
||||
long placementIdentity,
|
||||
private static NativeStructureOwnershipRecord record(String key, int originX, int originZ, long variant,
|
||||
int referenceRadius) {
|
||||
return record(key, originX, originZ, placementIdentity, "{}", referenceRadius);
|
||||
return record(key, originX, originZ, variant, "{}", referenceRadius);
|
||||
}
|
||||
|
||||
private static NativeStructureOwnershipRecord record(String key, int originX, int originZ,
|
||||
long placementIdentity,
|
||||
private static NativeStructureOwnershipRecord record(String key, int originX, int originZ, long variant,
|
||||
String terrain,
|
||||
int referenceRadius) {
|
||||
return new NativeStructureOwnershipRecord(
|
||||
@@ -424,7 +422,6 @@ public class NativeStructureOwnershipStoreTest {
|
||||
key,
|
||||
originX,
|
||||
originZ,
|
||||
placementIdentity,
|
||||
47,
|
||||
originX << 4,
|
||||
43,
|
||||
@@ -438,10 +435,14 @@ public class NativeStructureOwnershipStoreTest {
|
||||
originZ - referenceRadius,
|
||||
originZ + referenceRadius,
|
||||
FINGERPRINT,
|
||||
new NativeStructureOwnershipRecord.MemoSnapshot("null", terrain)
|
||||
new NativeStructureOwnershipRecord.MemoSnapshot(memoText(terrain, variant))
|
||||
);
|
||||
}
|
||||
|
||||
private static String memoText(String terrain, long variant) {
|
||||
return "{\"terrain\":" + terrain + ",\"variant\":" + variant + "}";
|
||||
}
|
||||
|
||||
private static String terrain(int horizontalPadding) {
|
||||
return "{\"horizontalPadding\":" + horizontalPadding + "}";
|
||||
}
|
||||
|
||||
+70
-64
@@ -7,6 +7,7 @@ import art.arcane.iris.builtin.structure.StructureTerrain;
|
||||
import art.arcane.iris.builtin.structure.StructurePlacement;
|
||||
import art.arcane.iris.builtin.structure.StructureDistribution;
|
||||
import art.arcane.iris.builtin.structure.NativeStructureSource;
|
||||
import art.arcane.iris.engine.framework.structure.NativeStartPlanner;
|
||||
import art.arcane.iris.engine.object.TestSettings;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
@@ -35,8 +36,8 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* The starts the pack's nativeStructures placements make, now through iris:structure's vanilla structure hook, are the
|
||||
* ones the core planner made before the move: the same chunks, structures, base heights and placement identities for
|
||||
* a fixed seed (pinned from the planner), and fits whose persisted JSON is unchanged.
|
||||
* ones the core planner made before the move: the same chunks, structures, base heights and placements for a
|
||||
* fixed seed (pinned from the planner), and fits whose persisted terrain and stilts JSON is unchanged.
|
||||
*/
|
||||
public class NativeStructureStartsTest {
|
||||
private static final long SEED = 1337L;
|
||||
@@ -44,60 +45,64 @@ public class NativeStructureStartsTest {
|
||||
private static final int GRID_RADIUS_CHUNKS = 6;
|
||||
private static final Gson GSON = new Gson();
|
||||
|
||||
/** chunkX chunkZ structure baseY placement identity, as NativeStructurePlacementPlanner.plansAt returned them. */
|
||||
/**
|
||||
* chunkX chunkZ structure baseY placement, as NativeStructurePlacementPlanner.plansAt returned them. Batch 6 dropped
|
||||
* the trailing placement identity column (one value per placement: villages -2304053147360248982, cities
|
||||
* 7830921123394837354, outposts 3980124831785354812) when starts stopped carrying it; the other columns are unchanged.
|
||||
*/
|
||||
private static final List<String> PLANNER_STARTS = List.of(
|
||||
"-6 -4 minecraft:village_plains 72 villages -2304053147360248982",
|
||||
"-6 0 minecraft:ancient_city -11 cities 7830921123394837354",
|
||||
"-6 1 minecraft:pillager_outpost 92 outposts 3980124831785354812",
|
||||
"-6 3 minecraft:village_plains 88 villages -2304053147360248982",
|
||||
"-6 3 minecraft:ancient_city -14 cities 7830921123394837354",
|
||||
"-5 -4 minecraft:pillager_outpost 64 outposts 3980124831785354812",
|
||||
"-5 -3 minecraft:ancient_city -40 cities 7830921123394837354",
|
||||
"-5 5 minecraft:pillager_outpost 76 outposts 3980124831785354812",
|
||||
"-4 -5 minecraft:pillager_outpost 88 outposts 3980124831785354812",
|
||||
"-4 -1 minecraft:village_plains 80 villages -2304053147360248982",
|
||||
"-4 -1 minecraft:pillager_outpost 80 outposts 3980124831785354812",
|
||||
"-4 1 minecraft:village_plains 76 villages -2304053147360248982",
|
||||
"-4 1 minecraft:pillager_outpost 76 outposts 3980124831785354812",
|
||||
"-3 -1 minecraft:village_plains 72 villages -2304053147360248982",
|
||||
"-3 1 minecraft:pillager_outpost 68 outposts 3980124831785354812",
|
||||
"-3 6 minecraft:village_plains 88 villages -2304053147360248982",
|
||||
"-2 0 minecraft:village_plains 92 villages -2304053147360248982",
|
||||
"-2 6 minecraft:pillager_outpost 80 outposts 3980124831785354812",
|
||||
"-1 -4 minecraft:village_plains 92 villages -2304053147360248982",
|
||||
"-1 4 minecraft:ancient_city -12 cities 7830921123394837354",
|
||||
"-1 6 minecraft:ancient_city -23 cities 7830921123394837354",
|
||||
"0 -6 minecraft:village_plains 88 villages -2304053147360248982",
|
||||
"0 -2 minecraft:village_plains 80 villages -2304053147360248982",
|
||||
"0 4 minecraft:pillager_outpost 68 outposts 3980124831785354812",
|
||||
"0 6 minecraft:village_plains 64 villages -2304053147360248982",
|
||||
"1 -6 minecraft:ancient_city -32 cities 7830921123394837354",
|
||||
"1 -4 minecraft:pillager_outpost 76 outposts 3980124831785354812",
|
||||
"1 0 minecraft:ancient_city -37 cities 7830921123394837354",
|
||||
"1 2 minecraft:pillager_outpost 64 outposts 3980124831785354812",
|
||||
"1 3 minecraft:ancient_city -38 cities 7830921123394837354",
|
||||
"1 5 minecraft:ancient_city -12 cities 7830921123394837354",
|
||||
"2 -2 minecraft:pillager_outpost 64 villages -2304053147360248982",
|
||||
"2 5 minecraft:village_plains 80 villages -2304053147360248982",
|
||||
"2 5 minecraft:pillager_outpost 80 outposts 3980124831785354812",
|
||||
"3 -5 minecraft:village_plains 92 villages -2304053147360248982",
|
||||
"3 1 minecraft:village_plains 80 villages -2304053147360248982",
|
||||
"3 5 minecraft:pillager_outpost 72 villages -2304053147360248982",
|
||||
"4 1 minecraft:ancient_city -16 cities 7830921123394837354",
|
||||
"4 1 minecraft:pillager_outpost 72 outposts 3980124831785354812",
|
||||
"4 3 minecraft:pillager_outpost 68 outposts 3980124831785354812",
|
||||
"4 5 minecraft:pillager_outpost 64 outposts 3980124831785354812",
|
||||
"4 6 minecraft:ancient_city -18 cities 7830921123394837354",
|
||||
"5 -5 minecraft:village_plains 76 villages -2304053147360248982",
|
||||
"5 -5 minecraft:ancient_city -24 cities 7830921123394837354",
|
||||
"5 1 minecraft:pillager_outpost 64 outposts 3980124831785354812",
|
||||
"5 2 minecraft:ancient_city -33 cities 7830921123394837354",
|
||||
"5 4 minecraft:village_plains 88 villages -2304053147360248982",
|
||||
"5 6 minecraft:village_plains 84 villages -2304053147360248982",
|
||||
"6 -5 minecraft:pillager_outpost 68 outposts 3980124831785354812",
|
||||
"6 -3 minecraft:village_plains 64 villages -2304053147360248982",
|
||||
"6 -2 minecraft:pillager_outpost 92 outposts 3980124831785354812",
|
||||
"6 2 minecraft:ancient_city -18 cities 7830921123394837354");
|
||||
"-6 -4 minecraft:village_plains 72 villages",
|
||||
"-6 0 minecraft:ancient_city -11 cities",
|
||||
"-6 1 minecraft:pillager_outpost 92 outposts",
|
||||
"-6 3 minecraft:village_plains 88 villages",
|
||||
"-6 3 minecraft:ancient_city -14 cities",
|
||||
"-5 -4 minecraft:pillager_outpost 64 outposts",
|
||||
"-5 -3 minecraft:ancient_city -40 cities",
|
||||
"-5 5 minecraft:pillager_outpost 76 outposts",
|
||||
"-4 -5 minecraft:pillager_outpost 88 outposts",
|
||||
"-4 -1 minecraft:village_plains 80 villages",
|
||||
"-4 -1 minecraft:pillager_outpost 80 outposts",
|
||||
"-4 1 minecraft:village_plains 76 villages",
|
||||
"-4 1 minecraft:pillager_outpost 76 outposts",
|
||||
"-3 -1 minecraft:village_plains 72 villages",
|
||||
"-3 1 minecraft:pillager_outpost 68 outposts",
|
||||
"-3 6 minecraft:village_plains 88 villages",
|
||||
"-2 0 minecraft:village_plains 92 villages",
|
||||
"-2 6 minecraft:pillager_outpost 80 outposts",
|
||||
"-1 -4 minecraft:village_plains 92 villages",
|
||||
"-1 4 minecraft:ancient_city -12 cities",
|
||||
"-1 6 minecraft:ancient_city -23 cities",
|
||||
"0 -6 minecraft:village_plains 88 villages",
|
||||
"0 -2 minecraft:village_plains 80 villages",
|
||||
"0 4 minecraft:pillager_outpost 68 outposts",
|
||||
"0 6 minecraft:village_plains 64 villages",
|
||||
"1 -6 minecraft:ancient_city -32 cities",
|
||||
"1 -4 minecraft:pillager_outpost 76 outposts",
|
||||
"1 0 minecraft:ancient_city -37 cities",
|
||||
"1 2 minecraft:pillager_outpost 64 outposts",
|
||||
"1 3 minecraft:ancient_city -38 cities",
|
||||
"1 5 minecraft:ancient_city -12 cities",
|
||||
"2 -2 minecraft:pillager_outpost 64 villages",
|
||||
"2 5 minecraft:village_plains 80 villages",
|
||||
"2 5 minecraft:pillager_outpost 80 outposts",
|
||||
"3 -5 minecraft:village_plains 92 villages",
|
||||
"3 1 minecraft:village_plains 80 villages",
|
||||
"3 5 minecraft:pillager_outpost 72 villages",
|
||||
"4 1 minecraft:ancient_city -16 cities",
|
||||
"4 1 minecraft:pillager_outpost 72 outposts",
|
||||
"4 3 minecraft:pillager_outpost 68 outposts",
|
||||
"4 5 minecraft:pillager_outpost 64 outposts",
|
||||
"4 6 minecraft:ancient_city -18 cities",
|
||||
"5 -5 minecraft:village_plains 76 villages",
|
||||
"5 -5 minecraft:ancient_city -24 cities",
|
||||
"5 1 minecraft:pillager_outpost 64 outposts",
|
||||
"5 2 minecraft:ancient_city -33 cities",
|
||||
"5 4 minecraft:village_plains 88 villages",
|
||||
"5 6 minecraft:village_plains 84 villages",
|
||||
"6 -5 minecraft:pillager_outpost 68 outposts",
|
||||
"6 -3 minecraft:village_plains 64 villages",
|
||||
"6 -2 minecraft:pillager_outpost 92 outposts",
|
||||
"6 2 minecraft:ancient_city -18 cities");
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder folder = new TemporaryFolder();
|
||||
@@ -121,9 +126,15 @@ public class NativeStructureStartsTest {
|
||||
List<String> starts = new ArrayList<>();
|
||||
for (int chunkX = -GRID_RADIUS_CHUNKS; chunkX <= GRID_RADIUS_CHUNKS; chunkX++) {
|
||||
for (int chunkZ = -GRID_RADIUS_CHUNKS; chunkZ <= GRID_RADIUS_CHUNKS; chunkZ++) {
|
||||
for (NativeStructureStartPlan plan : NativeStructureStarts.plansAt(engine, chunkX, chunkZ)) {
|
||||
List<NativeStructureStartPlan> plans = NativeStructureStarts.plansAt(engine, chunkX, chunkZ);
|
||||
List<NativeStartPlanner.Plan> modulePlans = NativeStartPlanner.plansAt(engine, chunkX, chunkZ);
|
||||
assertEquals(modulePlans.size(), plans.size());
|
||||
for (int index = 0; index < plans.size(); index++) {
|
||||
NativeStructureStartPlan plan = plans.get(index);
|
||||
NativeStartPlanner.Plan modulePlan = modulePlans.get(index);
|
||||
assertEquals(modulePlan.source().structure(), plan.structureKey());
|
||||
starts.add(plan.chunkX() + " " + plan.chunkZ() + " " + plan.structureKey() + " " + plan.baseY() + " "
|
||||
+ placementId(placements, plan.placementIdentity()) + " " + plan.placementIdentity());
|
||||
+ modulePlan.placement().placementId());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -148,10 +159,10 @@ public class NativeStructureStartsTest {
|
||||
|
||||
NativeStructureStartPlan plan = NativeStructureStarts.matchingPlan(engine, "MINECRAFT:ANCIENT_CITY", 0, 0);
|
||||
|
||||
assertEquals(new NativeStartMemo(GSON.toJson(terrain), GSON.toJson(stilt)), plan.memo());
|
||||
assertEquals(new NativeStartMemo("{\"terrain\":" + GSON.toJson(terrain) + ",\"stilts\":" + GSON.toJson(stilt) + "}"),
|
||||
plan.memo());
|
||||
assertEquals(new NativeJigsawOverrides("minecraft:village/plains/town_centers", "", 5, null, null, false,
|
||||
"OCEAN_FLOOR_WG", null, null, NativeJigsawOverrides.SOURCE), plan.jigsaw());
|
||||
assertEquals(StructurePlacementGrid.placementIdentity(fitted), plan.placementIdentity());
|
||||
assertNull(NativeStructureStarts.matchingPlan(engine, "minecraft:stronghold", 0, 0));
|
||||
}
|
||||
|
||||
@@ -168,11 +179,6 @@ public class NativeStructureStartsTest {
|
||||
return placement;
|
||||
}
|
||||
|
||||
private static String placementId(KList<StructurePlacement> placements, long identity) {
|
||||
return placements.stream().filter(placement -> StructurePlacementGrid.placementIdentity(placement) == identity)
|
||||
.findFirst().orElseThrow().placementId();
|
||||
}
|
||||
|
||||
/** An engine whose pack serves the built-in modules, with terrain heights that vary per column and a high sea. */
|
||||
private Engine engine(KList<StructurePlacement> placements) throws IOException {
|
||||
IrisData data = mock(IrisData.class);
|
||||
|
||||
-1
@@ -95,7 +95,6 @@ public class NativeStartPlannerTest {
|
||||
assertEquals(34, start.y());
|
||||
assertTrue(start.isUnderground());
|
||||
assertTrue(start.replacesPlatformStart());
|
||||
assertEquals(StructurePlacementGrid.placementIdentity(placement), start.identity());
|
||||
NativeStructureFit fit = NativeStructureFit.of(start.memo().orElseThrow());
|
||||
assertEquals(StructureTerrainMode.FORCE_CARVE, fit.terrain().resolvedMode());
|
||||
assertEquals(24, fit.terrain().horizontalPadding());
|
||||
|
||||
@@ -248,7 +248,7 @@ final class FitFixture {
|
||||
|
||||
static FitStart start(String terrainJson, String stiltsJson, TerrainAdaptation adaptation, DecorationStep step,
|
||||
Piece... pieces) {
|
||||
StartMemo memo = new StartMemo(terrainJson, stiltsJson);
|
||||
StartMemo memo = new StartMemo("{\"terrain\":" + terrainJson + ",\"stilts\":" + stiltsJson + "}");
|
||||
StructureFit.Start start = new StructureFit.Start() {
|
||||
private final StartKey key = StartKey.create();
|
||||
|
||||
|
||||
+1
-1
@@ -185,7 +185,7 @@ public class TerrainIntegrationTest {
|
||||
public void omittedTerrainRetainsSourceSemanticsAndAnExplicitTerrainWins() {
|
||||
assertEquals(StructureTerrainMode.SOURCE, NativeStructureFit.NONE.resolvedTerrain().resolvedMode());
|
||||
assertEquals(StructureTerrainMode.PRESERVE,
|
||||
NativeStructureFit.of(new StartMemo("{\"mode\":\"PRESERVE\"}", "null")).resolvedTerrain().resolvedMode());
|
||||
NativeStructureFit.of(new StartMemo("{\"terrain\":{\"mode\":\"PRESERVE\"}}")).resolvedTerrain().resolvedMode());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+4
@@ -15,6 +15,9 @@ import static org.junit.Assert.assertNull;
|
||||
/** The settings of {@code iris:objects} describe the same JSON an Iris object placement reads, and keep it for Iris to read. */
|
||||
public class ObjectPlacementMirrorTest {
|
||||
private static final Gson GSON = new Gson();
|
||||
private static final String WARP_OPTION = "warp";
|
||||
/** Iris's own cache size knob, which IrisApi's NoiseStyle leaves out; a placement's JSON still carries it to Iris. */
|
||||
private static final String IRIS_ONLY_STYLE_OPTION = "cacheSize";
|
||||
|
||||
@Test
|
||||
public void theSettingsDeclareEveryOptionOfIrisObjectPlacementAndNoOther() {
|
||||
@@ -29,6 +32,7 @@ public class ObjectPlacementMirrorTest {
|
||||
JsonObject host = GSON.toJsonTree(new IrisObjectPlacement()).getAsJsonObject();
|
||||
JsonObject settings = GSON.toJsonTree(TestSettings.of(ObjectPlacement.class, "{}")).getAsJsonObject();
|
||||
|
||||
host.getAsJsonObject(WARP_OPTION).remove(IRIS_ONLY_STYLE_OPTION);
|
||||
for (String option : host.keySet()) {
|
||||
assertEquals("default of " + option, host.get(option), settings.get(option));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user