mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 00:34:19 +00:00
Merge branch 'wave2/e1' into feat/irisapi-host
This commit is contained in:
commit
83e59706be
49 files changed
+1301
-1078
No files matched your search
+16
-16
@@ -1,8 +1,8 @@
|
||||
package art.arcane.iris.core.nms.v26_2_R1;
|
||||
|
||||
import art.arcane.iris.core.datapack.DatapackStructureScopeIndex;
|
||||
import art.arcane.iris.engine.framework.NativeStructureFrequencies;
|
||||
import art.arcane.iris.engine.framework.NativeStructureFrequencyScale;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.IrisImportedStructureControl;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.HolderOwner;
|
||||
import net.minecraft.core.Vec3i;
|
||||
@@ -32,20 +32,20 @@ final class DatapackStructureStateFilter {
|
||||
DatapackStructureScopeIndex scopeIndex,
|
||||
Set<String> declaredSources
|
||||
) {
|
||||
return filter(structureSets, scopeIndex, declaredSources, new IrisImportedStructureControl());
|
||||
return filter(structureSets, scopeIndex, declaredSources, NativeStructureFrequencies.NONE);
|
||||
}
|
||||
|
||||
static Selection filter(
|
||||
List<Holder<StructureSet>> structureSets,
|
||||
DatapackStructureScopeIndex scopeIndex,
|
||||
Set<String> declaredSources,
|
||||
IrisImportedStructureControl importedStructures
|
||||
NativeStructureFrequencies frequencies
|
||||
) {
|
||||
return filter(
|
||||
structureSets,
|
||||
scopeIndex,
|
||||
declaredSources,
|
||||
importedStructures,
|
||||
frequencies,
|
||||
keyIndex(structureSets));
|
||||
}
|
||||
|
||||
@@ -53,12 +53,12 @@ final class DatapackStructureStateFilter {
|
||||
List<Holder<StructureSet>> structureSets,
|
||||
DatapackStructureScopeIndex scopeIndex,
|
||||
Set<String> declaredSources,
|
||||
IrisImportedStructureControl importedStructures,
|
||||
NativeStructureFrequencies frequencies,
|
||||
StructureSetKeyIndex keyIndex
|
||||
) {
|
||||
if (scopeIndex.isEmpty()) {
|
||||
return new Selection(
|
||||
scaleFrequencyOverrides(structureSets, importedStructures, keyIndex),
|
||||
scaleFrequencyOverrides(structureSets, frequencies, keyIndex),
|
||||
0,
|
||||
0);
|
||||
}
|
||||
@@ -98,7 +98,7 @@ final class DatapackStructureStateFilter {
|
||||
}
|
||||
return new Selection(
|
||||
scaleFrequencyOverrides(
|
||||
List.copyOf(filteredSets), importedStructures, keyIndex),
|
||||
List.copyOf(filteredSets), frequencies, keyIndex),
|
||||
retainedManagedSets,
|
||||
excludedManagedSets);
|
||||
}
|
||||
@@ -244,10 +244,10 @@ final class DatapackStructureStateFilter {
|
||||
|
||||
private static List<Holder<StructureSet>> scaleFrequencyOverrides(
|
||||
List<Holder<StructureSet>> structureSets,
|
||||
IrisImportedStructureControl importedStructures,
|
||||
NativeStructureFrequencies frequencies,
|
||||
StructureSetKeyIndex keyIndex
|
||||
) {
|
||||
if (!importedStructures.hasFrequencyOverrides()) {
|
||||
if (!frequencies.hasOverrides()) {
|
||||
return structureSets;
|
||||
}
|
||||
Map<String, Holder<StructureSet>> holdersByKey = new HashMap<>();
|
||||
@@ -263,7 +263,7 @@ final class DatapackStructureStateFilter {
|
||||
for (Holder<StructureSet> holder : structureSets) {
|
||||
Holder<StructureSet> scaled = scaleFrequencyHolder(
|
||||
holder,
|
||||
importedStructures,
|
||||
frequencies,
|
||||
holdersByKey,
|
||||
scaledByIdentity,
|
||||
keyIndex);
|
||||
@@ -275,7 +275,7 @@ final class DatapackStructureStateFilter {
|
||||
|
||||
private static Holder<StructureSet> scaleFrequencyHolder(
|
||||
Holder<StructureSet> holder,
|
||||
IrisImportedStructureControl importedStructures,
|
||||
NativeStructureFrequencies frequencies,
|
||||
Map<String, Holder<StructureSet>> holdersByKey,
|
||||
Map<Holder<StructureSet>, Holder<StructureSet>> scaledByIdentity,
|
||||
StructureSetKeyIndex keyIndex
|
||||
@@ -284,7 +284,7 @@ final class DatapackStructureStateFilter {
|
||||
return scaledByIdentity.get(holder);
|
||||
}
|
||||
if (!dependsOnFrequencyOverride(
|
||||
holder, importedStructures, holdersByKey, keyIndex)) {
|
||||
holder, frequencies, holdersByKey, keyIndex)) {
|
||||
scaledByIdentity.put(holder, holder);
|
||||
return holder;
|
||||
}
|
||||
@@ -304,7 +304,7 @@ final class DatapackStructureStateFilter {
|
||||
originalZone.get().otherSet(), holdersByKey, keyIndex);
|
||||
Holder<StructureSet> scaledTarget = scaleFrequencyHolder(
|
||||
target,
|
||||
importedStructures,
|
||||
frequencies,
|
||||
holdersByKey,
|
||||
scaledByIdentity,
|
||||
keyIndex);
|
||||
@@ -314,7 +314,7 @@ final class DatapackStructureStateFilter {
|
||||
}
|
||||
}
|
||||
|
||||
double multiplier = importedStructures.frequencyMultiplier(
|
||||
double multiplier = frequencies.multiplier(
|
||||
structureSetKey(holder, keyIndex));
|
||||
StructurePlacement scaledPlacement = multiplier == 1D && scaledZone.equals(originalZone)
|
||||
? originalPlacement
|
||||
@@ -325,14 +325,14 @@ final class DatapackStructureStateFilter {
|
||||
|
||||
private static boolean dependsOnFrequencyOverride(
|
||||
Holder<StructureSet> holder,
|
||||
IrisImportedStructureControl importedStructures,
|
||||
NativeStructureFrequencies frequencies,
|
||||
Map<String, Holder<StructureSet>> holdersByKey,
|
||||
StructureSetKeyIndex keyIndex
|
||||
) {
|
||||
Set<Holder<StructureSet>> visited = Collections.newSetFromMap(new IdentityHashMap<>());
|
||||
Holder<StructureSet> current = holder;
|
||||
while (visited.add(current)) {
|
||||
if (importedStructures.frequencyMultiplier(
|
||||
if (frequencies.multiplier(
|
||||
structureSetKey(current, keyIndex)) != 1D) {
|
||||
return true;
|
||||
}
|
||||
|
||||
+1
-1
@@ -808,7 +808,7 @@ public class IrisChunkGenerator extends CustomChunkGenerator {
|
||||
throw new IllegalStateException("Iris cannot generate native structures in chunk "
|
||||
+ disabledChunk.x() + "," + disabledChunk.z()
|
||||
+ " because structure generation is disabled outside the pack; enable native structure generation "
|
||||
+ "and deny families through importedStructures.disabled or complete keys through importedStructures.disabledExact");
|
||||
+ "and deny families through iris:structure disabled or complete keys through iris:structure disabledExact");
|
||||
}
|
||||
ChunkPos chunkPos = chunk.getPos();
|
||||
SectionPos sectionPos = SectionPos.of(chunkPos, world.getMinSectionY());
|
||||
|
||||
+3
-3
@@ -6,7 +6,7 @@ import ca.spottedleaf.moonrise.patches.chunk_system.scheduling.NewChunkHolder;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import art.arcane.iris.core.datapack.DatapackStructureScopeIndex;
|
||||
import art.arcane.iris.core.nms.DatapackStructureScopeResult;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.IrisImportedStructureControl;
|
||||
import art.arcane.iris.engine.framework.NativeStructureFrequencies;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.core.nms.INMSBinding;
|
||||
import art.arcane.iris.core.nms.MinecraftVersion;
|
||||
@@ -1232,7 +1232,7 @@ public class NMSBinding implements INMSBinding {
|
||||
World world,
|
||||
DatapackStructureScopeIndex scopeIndex,
|
||||
Set<String> declaredSources,
|
||||
IrisImportedStructureControl importedStructures
|
||||
NativeStructureFrequencies frequencies
|
||||
) throws NoSuchFieldException, IllegalAccessException {
|
||||
ServerLevel level = ((CraftWorld) world).getHandle();
|
||||
ChunkMap chunkMap = level.getChunkSource().chunkMap;
|
||||
@@ -1245,7 +1245,7 @@ public class NMSBinding implements INMSBinding {
|
||||
scopedState.possibleStructureSets(),
|
||||
scopeIndex,
|
||||
declaredSources,
|
||||
importedStructures,
|
||||
frequencies,
|
||||
DatapackStructureStateFilter.keyIndex(
|
||||
structureSetRegistry.listElements().toList()));
|
||||
|
||||
|
||||
+9
-35
@@ -1,10 +1,8 @@
|
||||
package art.arcane.iris.core.nms.v26_2_R1;
|
||||
|
||||
import art.arcane.iris.engine.object.structure.vanilla.IrisStructureSetFrequencyOverride;
|
||||
import art.arcane.iris.core.datapack.DatapackIngestService;
|
||||
import art.arcane.iris.core.datapack.DatapackStructureScopeIndex;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.IrisImportedStructureControl;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.iris.engine.framework.NativeStructureFrequencies;
|
||||
import com.mojang.datafixers.util.Either;
|
||||
import net.minecraft.SharedConstants;
|
||||
import net.minecraft.core.Holder;
|
||||
@@ -32,6 +30,7 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
@@ -135,14 +134,14 @@ public class NMSBindingDatapackStructureScopeTest {
|
||||
List.of(spigotDirect),
|
||||
scopeIndex,
|
||||
Set.of(),
|
||||
new IrisImportedStructureControl(),
|
||||
NativeStructureFrequencies.NONE,
|
||||
keyIndex);
|
||||
DatapackStructureStateFilter.Selection retained =
|
||||
DatapackStructureStateFilter.filter(
|
||||
List.of(spigotDirect),
|
||||
scopeIndex,
|
||||
scopeIndex.declaredSources(List.of(SOURCE)),
|
||||
new IrisImportedStructureControl(),
|
||||
NativeStructureFrequencies.NONE,
|
||||
keyIndex);
|
||||
|
||||
assertEquals(0, excluded.structureSets().size());
|
||||
@@ -172,12 +171,7 @@ public class NMSBindingDatapackStructureScopeTest {
|
||||
"minecraft:nether_fossils",
|
||||
new RandomSpreadStructurePlacement(2, 1, RandomSpreadType.LINEAR, 14357921),
|
||||
structureHolder("minecraft:nether_fossil"));
|
||||
KList<IrisStructureSetFrequencyOverride> overrides = new KList<>();
|
||||
overrides.add(new IrisStructureSetFrequencyOverride()
|
||||
.setStructureSet("minecraft:nether_complexes")
|
||||
.setMultiplier(1.1D));
|
||||
IrisImportedStructureControl control = new IrisImportedStructureControl()
|
||||
.setFrequencyOverrides(overrides);
|
||||
NativeStructureFrequencies control = NativeStructureFrequencies.of(Map.of("minecraft:nether_complexes", 1.1D));
|
||||
|
||||
DatapackStructureStateFilter.Selection selection = DatapackStructureStateFilter.filter(
|
||||
List.of(complexes, fossils), index(List.of(), List.of()), Set.of(), control);
|
||||
@@ -202,12 +196,7 @@ public class NMSBindingDatapackStructureScopeTest {
|
||||
new UnsupportedPlacement(Optional.of(
|
||||
new StructurePlacement.ExclusionZone(exclusionTarget, 1))),
|
||||
structureHolder("example:custom"));
|
||||
KList<IrisStructureSetFrequencyOverride> overrides = new KList<>();
|
||||
overrides.add(new IrisStructureSetFrequencyOverride()
|
||||
.setStructureSet("minecraft:nether_complexes")
|
||||
.setMultiplier(1.1D));
|
||||
IrisImportedStructureControl control = new IrisImportedStructureControl()
|
||||
.setFrequencyOverrides(overrides);
|
||||
NativeStructureFrequencies control = NativeStructureFrequencies.of(Map.of("minecraft:nether_complexes", 1.1D));
|
||||
|
||||
DatapackStructureStateFilter.Selection selection = DatapackStructureStateFilter.filter(
|
||||
List.of(custom), index(List.of(), List.of()), Set.of(), control);
|
||||
@@ -234,12 +223,7 @@ public class NMSBindingDatapackStructureScopeTest {
|
||||
"example:dependent",
|
||||
dependentPlacement,
|
||||
structureHolder("example:dependent"));
|
||||
KList<IrisStructureSetFrequencyOverride> overrides = new KList<>();
|
||||
overrides.add(new IrisStructureSetFrequencyOverride()
|
||||
.setStructureSet("example:target")
|
||||
.setMultiplier(1.1D));
|
||||
IrisImportedStructureControl control = new IrisImportedStructureControl()
|
||||
.setFrequencyOverrides(overrides);
|
||||
NativeStructureFrequencies control = NativeStructureFrequencies.of(Map.of("example:target", 1.1D));
|
||||
|
||||
DatapackStructureStateFilter.Selection selection = DatapackStructureStateFilter.filter(
|
||||
List.of(dependent, target), index(List.of(), List.of()), Set.of(), control);
|
||||
@@ -280,12 +264,7 @@ public class NMSBindingDatapackStructureScopeTest {
|
||||
4,
|
||||
RandomSpreadType.LINEAR),
|
||||
"example:second"));
|
||||
KList<IrisStructureSetFrequencyOverride> overrides = new KList<>();
|
||||
overrides.add(new IrisStructureSetFrequencyOverride()
|
||||
.setStructureSet("example:second")
|
||||
.setMultiplier(1.1D));
|
||||
IrisImportedStructureControl control = new IrisImportedStructureControl()
|
||||
.setFrequencyOverrides(overrides);
|
||||
NativeStructureFrequencies control = NativeStructureFrequencies.of(Map.of("example:second", 1.1D));
|
||||
|
||||
DatapackStructureStateFilter.Selection selection = DatapackStructureStateFilter.filter(
|
||||
List.of(first, second), index(List.of(), List.of()), Set.of(), control);
|
||||
@@ -306,12 +285,7 @@ public class NMSBindingDatapackStructureScopeTest {
|
||||
"example:custom",
|
||||
new CustomRandomSpreadPlacement(),
|
||||
structureHolder("example:custom"));
|
||||
KList<IrisStructureSetFrequencyOverride> overrides = new KList<>();
|
||||
overrides.add(new IrisStructureSetFrequencyOverride()
|
||||
.setStructureSet("example:custom")
|
||||
.setMultiplier(1.1D));
|
||||
IrisImportedStructureControl control = new IrisImportedStructureControl()
|
||||
.setFrequencyOverrides(overrides);
|
||||
NativeStructureFrequencies control = NativeStructureFrequencies.of(Map.of("example:custom", 1.1D));
|
||||
|
||||
DatapackStructureStateFilter.Selection selection = DatapackStructureStateFilter.filter(
|
||||
List.of(custom), index(List.of(), List.of()), Set.of(), control);
|
||||
|
||||
+4
-15
@@ -2,11 +2,10 @@ package art.arcane.iris.nativegen;
|
||||
|
||||
import art.arcane.iris.engine.framework.NativeStructureOwnershipRecord;
|
||||
import art.arcane.iris.engine.framework.NativeStructureStartPlan;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.IrisNativeStructure;
|
||||
import art.arcane.iris.engine.framework.StructurePlacementGrid;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructurePlacement;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructureTerrain;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructureTerrainMode;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import net.minecraft.SharedConstants;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
@@ -246,19 +245,9 @@ public class NativeStructureOwnershipFingerprintTest {
|
||||
}
|
||||
|
||||
private static NativeStructureStartPlan plan(ChunkPos origin, int baseY) {
|
||||
IrisNativeStructure source = new IrisNativeStructure()
|
||||
.setStructure("minecraft:monument")
|
||||
.setWeight(1);
|
||||
IrisStructurePlacement placement = new IrisStructurePlacement()
|
||||
.setPlacementId("monument-test")
|
||||
.setNativeStructures(new KList<IrisNativeStructure>().qadd(source));
|
||||
return new NativeStructureStartPlan(
|
||||
placement,
|
||||
source,
|
||||
origin.x(),
|
||||
origin.z(),
|
||||
baseY
|
||||
);
|
||||
return new NativeStructureStartPlan("minecraft:monument", origin.x(), origin.z(), baseY, false, false,
|
||||
StructurePlacementGrid.placementIdentity(new IrisStructurePlacement().setPlacementId("monument-test")),
|
||||
null, null, new IrisStructureTerrain());
|
||||
}
|
||||
|
||||
private static NativeStructureOwnershipRecord ownership(
|
||||
|
||||
+14
-18
@@ -3,11 +3,9 @@ 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.object.structure.vanilla.IrisNativeStructure;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructurePlacement;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructureTerrain;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructureTerrainMode;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import net.minecraft.SharedConstants;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.HolderSet;
|
||||
@@ -66,7 +64,7 @@ public class NativeStructureOwnershipRecoveryTest {
|
||||
plan, expected, false);
|
||||
|
||||
assertNotNull(recovered);
|
||||
assertEquals(StructurePlacementGrid.placementIdentity(plan.placement()),
|
||||
assertEquals(plan.placementIdentity(),
|
||||
recovered.placementIdentity());
|
||||
assertEquals(expectedLocatorY, recovered.locatorY());
|
||||
assertNotEquals(NativeStructureOwnershipFingerprint.locatorY(reloaded),
|
||||
@@ -110,8 +108,8 @@ public class NativeStructureOwnershipRecoveryTest {
|
||||
new ChunkPos(origin.x() + 1, origin.z()), "changed-identity", 0);
|
||||
|
||||
assertNotEquals(
|
||||
StructurePlacementGrid.placementIdentity(originalIdentity.placement()),
|
||||
StructurePlacementGrid.placementIdentity(changedIdentity.placement()));
|
||||
originalIdentity.placementIdentity(),
|
||||
changedIdentity.placementIdentity());
|
||||
assertNull(NativeStructureOwnershipRecovery.proveCandidate(
|
||||
"minecraft:monument", structure, expected,
|
||||
changedIdentity, expected, false));
|
||||
@@ -169,7 +167,7 @@ public class NativeStructureOwnershipRecoveryTest {
|
||||
assertEquals(IrisStructureTerrainMode.VACUUM,
|
||||
refreshed.restoredDecision().terrain().resolvedMode());
|
||||
BoundingBox expected = NativeStructureReferenceEnvelope.referenceBounds(
|
||||
start, structure, plan.placement().resolvedTerrain(), structureKey);
|
||||
start, structure, plan.terrain(), structureKey);
|
||||
assertEquals(expected.minX() >> 4, refreshed.referenceMinChunkX());
|
||||
assertEquals(expected.maxX() >> 4, refreshed.referenceMaxChunkX());
|
||||
assertEquals(expected.minZ() >> 4, refreshed.referenceMinChunkZ());
|
||||
@@ -209,7 +207,7 @@ public class NativeStructureOwnershipRecoveryTest {
|
||||
StructureStart start = monumentStart(structure, origin, seed);
|
||||
NativeStructureStartPlan plan = plan(origin, "current-force-carve", 24);
|
||||
BoundingBox envelope = NativeStructureReferenceEnvelope.referenceBounds(
|
||||
start, structure, plan.placement().resolvedTerrain(), structureKey);
|
||||
start, structure, plan.terrain(), structureKey);
|
||||
NativeStructureOwnershipRecord ownership = NativeStructureOwnershipFingerprint.capture(
|
||||
structureKey, start, plan, envelope);
|
||||
|
||||
@@ -234,7 +232,7 @@ public class NativeStructureOwnershipRecoveryTest {
|
||||
NativeStructureStartPlan plan = plan(
|
||||
origin, "clipped-vacuum", IrisStructureTerrainMode.VACUUM, 0);
|
||||
BoundingBox envelope = NativeStructureReferenceEnvelope.referenceBounds(
|
||||
start, structure, plan.placement().resolvedTerrain(), structureKey);
|
||||
start, structure, plan.terrain(), structureKey);
|
||||
NativeStructureOwnershipRecord ownership = NativeStructureOwnershipFingerprint.capture(
|
||||
structureKey, start, plan, envelope);
|
||||
|
||||
@@ -277,23 +275,21 @@ public class NativeStructureOwnershipRecoveryTest {
|
||||
String placementId,
|
||||
IrisStructureTerrainMode terrainMode,
|
||||
int horizontalPadding) {
|
||||
IrisNativeStructure source = new IrisNativeStructure()
|
||||
.setStructure("minecraft:monument")
|
||||
.setWeight(1);
|
||||
IrisStructureTerrain terrain = new IrisStructureTerrain()
|
||||
.setMode(terrainMode)
|
||||
.setHorizontalPadding(horizontalPadding);
|
||||
IrisStructurePlacement placement = new IrisStructurePlacement()
|
||||
.setPlacementId(placementId)
|
||||
.setTerrain(terrain)
|
||||
.setNativeStructures(new KList<IrisNativeStructure>().qadd(source));
|
||||
return new NativeStructureStartPlan(
|
||||
placement,
|
||||
source,
|
||||
"minecraft:monument",
|
||||
origin.x(),
|
||||
origin.z(),
|
||||
NativeStructureReferenceEnvelope.contentBounds(
|
||||
monumentStart(structure(), origin, 1L)).minY()
|
||||
monumentStart(structure(), origin, 1L)).minY(),
|
||||
false,
|
||||
false,
|
||||
StructurePlacementGrid.placementIdentity(new IrisStructurePlacement().setPlacementId(placementId)),
|
||||
null,
|
||||
null,
|
||||
terrain
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+12
-16
@@ -8,7 +8,7 @@ import art.arcane.iris.core.nms.INMS;
|
||||
import art.arcane.iris.core.tools.IrisToolbelt;
|
||||
import art.arcane.iris.engine.platform.BukkitChunkGenerator;
|
||||
import art.arcane.iris.engine.platform.PlatformChunkGenerator;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.IrisImportedStructureControl;
|
||||
import art.arcane.iris.engine.framework.NativeStructureFrequencies;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.util.common.plugin.IrisService;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -41,9 +41,9 @@ public final class DatapackStructureScopeSVC implements IrisService {
|
||||
}
|
||||
for (World world : Bukkit.getWorlds()) {
|
||||
try {
|
||||
IrisImportedStructureControl importedStructures = importedStructures(world);
|
||||
if (!scopeIndex.isEmpty() || importedStructures != null && importedStructures.hasFrequencyOverrides()) {
|
||||
applyScope(world, importedStructures);
|
||||
NativeStructureFrequencies frequencies = frequencies(world);
|
||||
if (!scopeIndex.isEmpty() || frequencies.hasOverrides()) {
|
||||
applyScope(world, frequencies);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
// Per-world containment: one world's scoping failure must not abort the
|
||||
@@ -67,10 +67,9 @@ public final class DatapackStructureScopeSVC implements IrisService {
|
||||
boolean studioEntryBootstrap = event.getWorld().getGenerator()
|
||||
instanceof BukkitChunkGenerator generator
|
||||
&& generator.isStudioEntryBootstrapActive();
|
||||
IrisImportedStructureControl importedStructures = importedStructures(event.getWorld());
|
||||
if (shouldApplyScope(scopeIndex.isEmpty(), studioEntryBootstrap,
|
||||
importedStructures != null && importedStructures.hasFrequencyOverrides())) {
|
||||
applyScope(event.getWorld(), importedStructures);
|
||||
NativeStructureFrequencies frequencies = frequencies(event.getWorld());
|
||||
if (shouldApplyScope(scopeIndex.isEmpty(), studioEntryBootstrap, frequencies.hasOverrides())) {
|
||||
applyScope(event.getWorld(), frequencies);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,14 +83,11 @@ public final class DatapackStructureScopeSVC implements IrisService {
|
||||
return !scopeIndexEmpty || studioEntryBootstrap || hasFrequencyOverrides;
|
||||
}
|
||||
|
||||
private void applyScope(World world, IrisImportedStructureControl importedStructures) {
|
||||
private void applyScope(World world, NativeStructureFrequencies frequencies) {
|
||||
Set<String> declaredSources = declaredSources(world);
|
||||
IrisImportedStructureControl activeControl = importedStructures == null
|
||||
? new IrisImportedStructureControl()
|
||||
: importedStructures;
|
||||
try {
|
||||
DatapackStructureScopeResult result = INMS.get().scopeDatapackStructures(
|
||||
world, scopeIndex, declaredSources, activeControl);
|
||||
world, scopeIndex, declaredSources, frequencies);
|
||||
IrisLogging.info("Scoped Iris-managed datapack structure sets for world '"
|
||||
+ world.getName() + "': " + result.retainedManagedSets() + " retained, "
|
||||
+ result.excludedManagedSets() + " excluded.");
|
||||
@@ -101,13 +97,13 @@ public final class DatapackStructureScopeSVC implements IrisService {
|
||||
}
|
||||
}
|
||||
|
||||
private IrisImportedStructureControl importedStructures(World world) {
|
||||
private NativeStructureFrequencies frequencies(World world) {
|
||||
PlatformChunkGenerator generator = IrisToolbelt.access(world);
|
||||
if (generator == null || generator.getTarget() == null
|
||||
|| generator.getTarget().getDimension() == null) {
|
||||
return null;
|
||||
return NativeStructureFrequencies.NONE;
|
||||
}
|
||||
return generator.getTarget().getDimension().getImportedStructures();
|
||||
return NativeStructureFrequencies.of(generator.getTarget().getData(), generator.getTarget().getDimension());
|
||||
}
|
||||
|
||||
private Set<String> declaredSources(World world) {
|
||||
|
||||
+2
-2
@@ -118,7 +118,7 @@ public class IrisStructureLocateCommandContractTest {
|
||||
@Test
|
||||
public void unregisteredDiagnosticExplainsEveryRejectedRoute() {
|
||||
assertEquals(
|
||||
"Native structure minecraft:village is disabled by this dimension's importedStructures settings or a module of the pack.",
|
||||
"Native structure minecraft:village is disabled by this dimension's iris:structure settings or a module of the pack.",
|
||||
CommandFind.describeStructureExclusion(
|
||||
CommandFind.StructureLookupRoute.POLICY_DISABLED, "minecraft:village",
|
||||
NativeStructureGenerationStatus.DISABLED_BY_PACK,
|
||||
@@ -214,7 +214,7 @@ public class IrisStructureLocateCommandContractTest {
|
||||
@Test
|
||||
public void findNativePolicyMessagesMatchModdedDiagnostics() {
|
||||
assertEquals(
|
||||
"Native structure minecraft:village_plains is disabled by this dimension's importedStructures settings or a module of the pack.",
|
||||
"Native structure minecraft:village_plains is disabled by this dimension's iris:structure settings or a module of the pack.",
|
||||
NativeStructureGenerationPolicy.generationStatusMessage(
|
||||
"minecraft:village_plains", NativeStructureGenerationStatus.DISABLED_BY_PACK));
|
||||
assertEquals(
|
||||
|
||||
+7
-7
@@ -38,12 +38,12 @@ public final class NativeStructureFactory {
|
||||
NativeStructureStartPlan plan, int references) {
|
||||
Structure source = sourceHolder.value();
|
||||
Structure configured = configure(
|
||||
context.registryAccess(), source, plan.source().getJigsaw(),
|
||||
plan.placement().isUnderground(), plan.baseY());
|
||||
context.registryAccess(), source, plan.jigsaw(),
|
||||
plan.underground(), plan.baseY());
|
||||
Holder<Biome> sourceBiome = source.biomes().stream().findFirst()
|
||||
.or(() -> context.biomeSource().possibleBiomes().stream().findFirst())
|
||||
.orElseThrow(() -> new IllegalStateException("Configured native structure '"
|
||||
+ plan.source().getStructure() + "' has no usable generation biome"));
|
||||
+ plan.structureKey() + "' has no usable generation biome"));
|
||||
ChunkGenerator forcedGenerator = new ForcedStructureChunkGenerator(
|
||||
context.generator(), sourceBiome);
|
||||
StructureStart generated = configured.generate(
|
||||
@@ -64,13 +64,13 @@ public final class NativeStructureFactory {
|
||||
return StructureStart.INVALID_START;
|
||||
}
|
||||
StructureStart positioned;
|
||||
if (plan.placement().isUnderground()) {
|
||||
if (plan.underground()) {
|
||||
positioned = NativeStructureVerticalPlacer.relocateToMinY(
|
||||
generated, source, plan.baseY(), context.heightAccessor());
|
||||
} else {
|
||||
NativeStructureVerticalPlacer.applyVerticalPlacement(
|
||||
generated,
|
||||
plan.source().getStructure(),
|
||||
plan.structureKey(),
|
||||
0,
|
||||
context.seaLevel(),
|
||||
context.heightAccessor().getMinY(),
|
||||
@@ -88,8 +88,8 @@ public final class NativeStructureFactory {
|
||||
positioned,
|
||||
source,
|
||||
references,
|
||||
plan.placement().resolvedTerrain(),
|
||||
plan.source().getStructure()
|
||||
plan.terrain(),
|
||||
plan.structureKey()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+3
-4
@@ -1,9 +1,8 @@
|
||||
package art.arcane.iris.nativegen;
|
||||
|
||||
import art.arcane.iris.engine.framework.NativeStructureOwnershipRecord;
|
||||
import art.arcane.iris.engine.framework.NativeStructurePlacementPlanner;
|
||||
import art.arcane.iris.engine.framework.NativeStructureStarts;
|
||||
import art.arcane.iris.engine.framework.NativeStructureStartPlan;
|
||||
import art.arcane.iris.engine.framework.StructurePlacementGrid;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.resources.Identifier;
|
||||
@@ -59,7 +58,7 @@ public final class NativeStructureOwnershipFingerprint {
|
||||
structureKey,
|
||||
origin.x(),
|
||||
origin.z(),
|
||||
StructurePlacementGrid.placementIdentity(resolvedPlan.placement()),
|
||||
resolvedPlan.placementIdentity(),
|
||||
resolvedPlan.baseY(),
|
||||
content.minX(),
|
||||
content.minY(),
|
||||
@@ -73,7 +72,7 @@ public final class NativeStructureOwnershipFingerprint {
|
||||
references.minZ() >> 4,
|
||||
references.maxZ() >> 4,
|
||||
fingerprint(structureKey, resolvedStart),
|
||||
NativeStructurePlacementPlanner.decisionFor(resolvedPlan)
|
||||
resolvedPlan.decision()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+5
-11
@@ -4,13 +4,11 @@ import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.NativeStructureGenerationPolicy;
|
||||
import art.arcane.iris.engine.framework.NativeStructureOwnershipRecord;
|
||||
import art.arcane.iris.engine.framework.NativeStructureOwnershipStore;
|
||||
import art.arcane.iris.engine.framework.NativeStructurePlacementPlanner;
|
||||
import art.arcane.iris.engine.framework.NativeStructureStarts;
|
||||
import art.arcane.iris.engine.framework.NativeStructureStartPlan;
|
||||
import art.arcane.iris.engine.framework.StructurePlacementGrid;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructureTerrain;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructureTerrainMode;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.NativeStructureGenerationStatus;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.NativeStructureSuppression;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
@@ -57,7 +55,7 @@ public final class NativeStructureOwnershipRecovery {
|
||||
NativeStructureOwnershipStore.discard(
|
||||
engine, structureKey, origin.x(), origin.z());
|
||||
}
|
||||
NativeStructureStartPlan plan = NativeStructurePlacementPlanner.matchingPlan(
|
||||
NativeStructureStartPlan plan = NativeStructureStarts.matchingPlan(
|
||||
engine, structureKey, origin.x(), origin.z());
|
||||
if (!matchesPlan(structureKey, origin, plan)) {
|
||||
return null;
|
||||
@@ -124,13 +122,9 @@ public final class NativeStructureOwnershipRecovery {
|
||||
return null;
|
||||
}
|
||||
BoundingBox referenceEnvelope = NativeStructureReferenceEnvelope.referenceBounds(
|
||||
expected, structure, plan.placement().resolvedTerrain(), structureKey);
|
||||
expected, structure, plan.terrain(), structureKey);
|
||||
NativeStructureOwnershipRecord candidate = NativeStructureOwnershipFingerprint.capture(
|
||||
structureKey, expected, plan, referenceEnvelope);
|
||||
if (candidate.placementIdentity()
|
||||
!= StructurePlacementGrid.placementIdentity(plan.placement())) {
|
||||
return null;
|
||||
}
|
||||
return NativeStructureOwnershipFingerprint.matches(candidate, persisted)
|
||||
? candidate : null;
|
||||
}
|
||||
@@ -142,7 +136,7 @@ public final class NativeStructureOwnershipRecovery {
|
||||
}
|
||||
return plan.chunkX() == origin.x()
|
||||
&& plan.chunkZ() == origin.z()
|
||||
&& normalize(structureKey).equals(normalize(plan.source().getStructure()));
|
||||
&& normalize(structureKey).equals(normalize(plan.structureKey()));
|
||||
}
|
||||
|
||||
private static StructureStart generateExpected(
|
||||
@@ -172,7 +166,7 @@ public final class NativeStructureOwnershipRecovery {
|
||||
Engine engine, String structureKey, Structure structure,
|
||||
Holder<Structure> holder, ChunkGeneratorStructureState state,
|
||||
NativeStructureStartPlan plan) {
|
||||
if (plan.placement().getNativeSuppression() == NativeStructureSuppression.REPLACE_SOURCE) {
|
||||
if (plan.replacesPlatformStart()) {
|
||||
return false;
|
||||
}
|
||||
NativeStructureGenerationStatus sourceStatus = NativeStructureGenerationPolicy.resolve(
|
||||
|
||||
+6
-8
@@ -4,10 +4,9 @@ import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.NativeStructureGenerationPolicy;
|
||||
import art.arcane.iris.engine.framework.NativeStructureOwnershipRecord;
|
||||
import art.arcane.iris.engine.framework.NativeStructureOwnershipStore;
|
||||
import art.arcane.iris.engine.framework.NativeStructurePlacementPlanner;
|
||||
import art.arcane.iris.engine.framework.NativeStructureStarts;
|
||||
import art.arcane.iris.engine.framework.NativeStructureStartPlan;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.NativeStructureGenerationStatus;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.NativeStructureSuppression;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.Registry;
|
||||
@@ -45,12 +44,12 @@ public final class NativeStructureStartInjector {
|
||||
Registry<Structure> registry = context.registryAccess().lookupOrThrow(Registries.STRUCTURE);
|
||||
SectionPos section = SectionPos.bottomOf(chunk);
|
||||
Map<Structure, NativeStructureStartPlan> configuredStarts = new LinkedHashMap<>();
|
||||
for (NativeStructureStartPlan plan : NativeStructurePlacementPlanner.plansAt(
|
||||
for (NativeStructureStartPlan plan : NativeStructureStarts.plansAt(
|
||||
context.engine(), chunk.getPos().x(), chunk.getPos().z())) {
|
||||
Identifier identifier = Identifier.tryParse(plan.source().getStructure());
|
||||
Identifier identifier = Identifier.tryParse(plan.structureKey());
|
||||
if (identifier == null) {
|
||||
throw new IllegalStateException("Configured native structure key is invalid: "
|
||||
+ plan.source().getStructure());
|
||||
+ plan.structureKey());
|
||||
}
|
||||
Structure structure = registry.getValue(identifier);
|
||||
if (structure == null) {
|
||||
@@ -66,8 +65,7 @@ public final class NativeStructureStartInjector {
|
||||
}
|
||||
StructureStart existing = context.structureManager().getStartForStructure(
|
||||
section, structure, chunk);
|
||||
boolean replacement = plan.placement().getNativeSuppression()
|
||||
== NativeStructureSuppression.REPLACE_SOURCE;
|
||||
boolean replacement = plan.replacesPlatformStart();
|
||||
if (!replacement && existing != null && existing.isValid()) {
|
||||
NativeStructureGenerationStatus sourceStatus = NativeStructureGenerationPolicy.resolve(
|
||||
context.engine(), identifier.toString(),
|
||||
@@ -106,7 +104,7 @@ public final class NativeStructureStartInjector {
|
||||
continue;
|
||||
}
|
||||
BoundingBox referenceBounds = NativeStructureReferenceEnvelope.referenceBounds(
|
||||
generated, structure, plan.placement().resolvedTerrain(), identifier.toString());
|
||||
generated, structure, plan.terrain(), identifier.toString());
|
||||
NativeStructureOwnershipRecord ownership = NativeStructureOwnershipFingerprint.capture(
|
||||
identifier.toString(), generated, plan, referenceBounds);
|
||||
NativeStructureOwnershipStore.record(context.engine(), ownership);
|
||||
|
||||
+6
-5
@@ -3,7 +3,7 @@ package art.arcane.iris.nativegen;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.NativeStructureGenerationPolicy;
|
||||
import art.arcane.iris.engine.framework.NativeStructureOwnershipRecord;
|
||||
import art.arcane.iris.engine.framework.NativeStructurePlacementPlanner;
|
||||
import art.arcane.iris.engine.framework.NativeStructureStarts;
|
||||
import art.arcane.iris.engine.framework.NativeStructureStartPlan;
|
||||
import art.arcane.iris.engine.framework.NativeStructureVolume;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.IrisNativeStructureDecision;
|
||||
@@ -30,6 +30,7 @@ import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemp
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
@@ -171,9 +172,9 @@ public final class NativeStructureVolumeIndex {
|
||||
private KList<NativeStructureVolume> appendPlannedVolumes(Engine engine, Bindings bindings,
|
||||
Registry<Structure> registry, int chunkX, int chunkZ,
|
||||
KList<NativeStructureVolume> volumes) {
|
||||
KList<NativeStructureStartPlan> plans;
|
||||
List<NativeStructureStartPlan> plans;
|
||||
try {
|
||||
plans = NativeStructurePlacementPlanner.plansAt(engine, chunkX, chunkZ);
|
||||
plans = NativeStructureStarts.plansAt(engine, chunkX, chunkZ);
|
||||
} catch (RuntimeException | Error error) {
|
||||
warnOnce("iris-placements", error);
|
||||
return volumes;
|
||||
@@ -181,11 +182,11 @@ public final class NativeStructureVolumeIndex {
|
||||
|
||||
KList<NativeStructureVolume> target = volumes;
|
||||
for (NativeStructureStartPlan plan : plans) {
|
||||
IrisNativeStructureDecision decision = NativeStructurePlacementPlanner.decisionFor(plan);
|
||||
IrisNativeStructureDecision decision = plan.decision();
|
||||
if (!decision.generate()) {
|
||||
continue;
|
||||
}
|
||||
Identifier identifier = Identifier.tryParse(plan.source().getStructure());
|
||||
Identifier identifier = Identifier.tryParse(plan.structureKey());
|
||||
if (identifier == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
+10
-13
@@ -24,9 +24,9 @@ import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.NativeFeatureGenerationPolicy;
|
||||
import art.arcane.iris.engine.framework.GenerationSessionException;
|
||||
import art.arcane.iris.engine.framework.GenerationSessionLease;
|
||||
import art.arcane.iris.engine.framework.NativeStructureFrequencies;
|
||||
import art.arcane.iris.engine.framework.NativeStructureStartPlan;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.IrisImportedStructureControl;
|
||||
import art.arcane.iris.nativegen.NativeStructureStartInjector;
|
||||
import art.arcane.iris.nativegen.NativeStructureReferenceRepair;
|
||||
import art.arcane.iris.nativegen.NativeStructureVanillaLocator;
|
||||
@@ -285,19 +285,16 @@ public final class IrisModdedChunkGenerator extends ChunkGenerator {
|
||||
public ChunkGeneratorStructureState createState(HolderLookup<StructureSet> structureSets, RandomState randomState, long seed) {
|
||||
ChunkGeneratorStructureState state = ChunkGeneratorStructureState.createForNormal(
|
||||
randomState, seed, structureBiomeSource.forStructureState(structureSets), structureSets);
|
||||
return ModdedStructureSetFrequencyOverrides.apply(state, configuredImportedStructures());
|
||||
return ModdedStructureSetFrequencyOverrides.apply(state, configuredFrequencies());
|
||||
}
|
||||
|
||||
private IrisImportedStructureControl configuredImportedStructures() {
|
||||
private NativeStructureFrequencies configuredFrequencies() {
|
||||
Engine current = engine;
|
||||
if (current != null && !current.isClosed() && !current.isClosing()) {
|
||||
IrisDimension dimension = current.getDimension();
|
||||
if (dimension != null && dimension.getImportedStructures() != null) {
|
||||
return dimension.getImportedStructures();
|
||||
}
|
||||
if (current != null && !current.isClosed() && !current.isClosing() && current.getDimension() != null) {
|
||||
return NativeStructureFrequencies.of(current.getData(), current.getDimension());
|
||||
}
|
||||
IrisImportedStructureControl importedStructures = configuredPack().dimension().getImportedStructures();
|
||||
return importedStructures == null ? new IrisImportedStructureControl() : importedStructures;
|
||||
ModdedDimensionMetadata.ConfiguredPack configured = configuredPack();
|
||||
return NativeStructureFrequencies.of(configured.data(), configured.dimension());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -536,10 +533,10 @@ public final class IrisModdedChunkGenerator extends ChunkGenerator {
|
||||
}
|
||||
String remedy = integratedEnvironment()
|
||||
? "enable 'Generate Structures' for this world; Iris requires it, then deny families through "
|
||||
+ "importedStructures.disabled or complete keys through importedStructures.disabledExact"
|
||||
+ "iris:structure disabled or complete keys through iris:structure disabledExact"
|
||||
: "set generate-structures=true in server.properties, restart the server, "
|
||||
+ "then deny families through importedStructures.disabled or complete keys through "
|
||||
+ "importedStructures.disabledExact";
|
||||
+ "then deny families through iris:structure disabled or complete keys through "
|
||||
+ "iris:structure disabledExact";
|
||||
throw new IllegalStateException("Iris generator '" + dimensionKey
|
||||
+ "' cannot bind while generate-structures=false; " + remedy);
|
||||
}
|
||||
|
||||
+3
-3
@@ -231,7 +231,7 @@ final class ModdedNativeStructureStage {
|
||||
}
|
||||
if (configuredStarts.containsKey(structure)) {
|
||||
recordWorldCheckStructureShift(
|
||||
configuredStarts.get(structure).source().getStructure(), start.getChunkPos(), 0);
|
||||
configuredStarts.get(structure).structureKey(), start.getChunkPos(), 0);
|
||||
continue;
|
||||
}
|
||||
Identifier id = registry.getKey(structure);
|
||||
@@ -290,8 +290,8 @@ final class ModdedNativeStructureStage {
|
||||
+ " because generate-structures=false disables them outside the pack. That flag is fixed when "
|
||||
+ "the world is created (server.properties generate-structures, or the Generate Structures "
|
||||
+ "toggle in singleplayer), so it cannot be changed for this world: create a new world with "
|
||||
+ "structures enabled, then deny families through importedStructures.disabled or complete keys "
|
||||
+ "through importedStructures.disabledExact");
|
||||
+ "structures enabled, then deny families through iris:structure disabled or complete keys "
|
||||
+ "through iris:structure disabledExact");
|
||||
}
|
||||
ChunkPos chunkPos = chunk.getPos();
|
||||
SectionPos sectionPos = SectionPos.of(chunkPos, world.getMinSectionY());
|
||||
|
||||
+12
-12
@@ -18,8 +18,8 @@
|
||||
|
||||
package art.arcane.iris.modded;
|
||||
|
||||
import art.arcane.iris.engine.framework.NativeStructureFrequencies;
|
||||
import art.arcane.iris.engine.framework.NativeStructureFrequencyScale;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.IrisImportedStructureControl;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.HolderOwner;
|
||||
import net.minecraft.core.Vec3i;
|
||||
@@ -47,13 +47,13 @@ final class ModdedStructureSetFrequencyOverrides {
|
||||
|
||||
static ChunkGeneratorStructureState apply(
|
||||
ChunkGeneratorStructureState state,
|
||||
IrisImportedStructureControl importedStructures
|
||||
NativeStructureFrequencies frequencies
|
||||
) {
|
||||
if (!importedStructures.hasFrequencyOverrides()) {
|
||||
if (!frequencies.hasOverrides()) {
|
||||
return state;
|
||||
}
|
||||
List<Holder<StructureSet>> original = state.possibleStructureSets();
|
||||
List<Holder<StructureSet>> scaled = scaleSets(original, importedStructures);
|
||||
List<Holder<StructureSet>> scaled = scaleSets(original, frequencies);
|
||||
if (scaled == original) {
|
||||
return state;
|
||||
}
|
||||
@@ -69,7 +69,7 @@ final class ModdedStructureSetFrequencyOverrides {
|
||||
|
||||
static List<Holder<StructureSet>> scaleSets(
|
||||
List<Holder<StructureSet>> structureSets,
|
||||
IrisImportedStructureControl importedStructures
|
||||
NativeStructureFrequencies frequencies
|
||||
) {
|
||||
Map<String, Holder<StructureSet>> holdersByKey = new HashMap<>();
|
||||
for (Holder<StructureSet> holder : structureSets) {
|
||||
@@ -83,7 +83,7 @@ final class ModdedStructureSetFrequencyOverrides {
|
||||
boolean changed = false;
|
||||
for (Holder<StructureSet> holder : structureSets) {
|
||||
Holder<StructureSet> scaled = scaleHolder(
|
||||
holder, importedStructures, holdersByKey, scaledByIdentity);
|
||||
holder, frequencies, holdersByKey, scaledByIdentity);
|
||||
scaledSets.add(scaled);
|
||||
changed |= scaled != holder;
|
||||
}
|
||||
@@ -92,14 +92,14 @@ final class ModdedStructureSetFrequencyOverrides {
|
||||
|
||||
private static Holder<StructureSet> scaleHolder(
|
||||
Holder<StructureSet> holder,
|
||||
IrisImportedStructureControl importedStructures,
|
||||
NativeStructureFrequencies frequencies,
|
||||
Map<String, Holder<StructureSet>> holdersByKey,
|
||||
Map<Holder<StructureSet>, Holder<StructureSet>> scaledByIdentity
|
||||
) {
|
||||
if (scaledByIdentity.containsKey(holder)) {
|
||||
return scaledByIdentity.get(holder);
|
||||
}
|
||||
if (!dependsOnOverride(holder, importedStructures, holdersByKey)) {
|
||||
if (!dependsOnOverride(holder, frequencies, holdersByKey)) {
|
||||
scaledByIdentity.put(holder, holder);
|
||||
return holder;
|
||||
}
|
||||
@@ -116,13 +116,13 @@ final class ModdedStructureSetFrequencyOverrides {
|
||||
Holder<StructureSet> target = canonicalHolder(
|
||||
originalZone.get().otherSet(), holdersByKey);
|
||||
Holder<StructureSet> scaledTarget = scaleHolder(
|
||||
target, importedStructures, holdersByKey, scaledByIdentity);
|
||||
target, frequencies, holdersByKey, scaledByIdentity);
|
||||
if (scaledTarget != originalZone.get().otherSet()) {
|
||||
scaledZone = Optional.of(new StructurePlacement.ExclusionZone(
|
||||
scaledTarget, originalZone.get().chunkCount()));
|
||||
}
|
||||
}
|
||||
double multiplier = importedStructures.frequencyMultiplier(structureSetKey(holder));
|
||||
double multiplier = frequencies.multiplier(structureSetKey(holder));
|
||||
StructurePlacement scaledPlacement = multiplier == 1D && scaledZone.equals(originalZone)
|
||||
? originalPlacement
|
||||
: scalePlacement(originalPlacement, originalZone, scaledZone, multiplier);
|
||||
@@ -132,13 +132,13 @@ final class ModdedStructureSetFrequencyOverrides {
|
||||
|
||||
private static boolean dependsOnOverride(
|
||||
Holder<StructureSet> holder,
|
||||
IrisImportedStructureControl importedStructures,
|
||||
NativeStructureFrequencies frequencies,
|
||||
Map<String, Holder<StructureSet>> holdersByKey
|
||||
) {
|
||||
Set<Holder<StructureSet>> visited = Collections.newSetFromMap(new IdentityHashMap<>());
|
||||
Holder<StructureSet> current = holder;
|
||||
while (visited.add(current)) {
|
||||
if (importedStructures.frequencyMultiplier(structureSetKey(current)) != 1D) {
|
||||
if (frequencies.multiplier(structureSetKey(current)) != 1D) {
|
||||
return true;
|
||||
}
|
||||
Optional<StructurePlacement.ExclusionZone> zone =
|
||||
|
||||
+7
-33
@@ -1,8 +1,6 @@
|
||||
package art.arcane.iris.modded;
|
||||
|
||||
import art.arcane.iris.engine.object.structure.vanilla.IrisStructureSetFrequencyOverride;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.IrisImportedStructureControl;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.iris.engine.framework.NativeStructureFrequencies;
|
||||
import net.minecraft.SharedConstants;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.HolderOwner;
|
||||
@@ -27,6 +25,7 @@ import org.junit.Test;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -47,12 +46,7 @@ public class ModdedStructureSetFrequencyOverridesTest {
|
||||
Holder<StructureSet> fossils = structureSet(
|
||||
"minecraft:nether_fossils", 2, 1, 14357921);
|
||||
ChunkGeneratorStructureState state = state(List.of(complexes, fossils));
|
||||
KList<IrisStructureSetFrequencyOverride> overrides = new KList<>();
|
||||
overrides.add(new IrisStructureSetFrequencyOverride()
|
||||
.setStructureSet("minecraft:nether_complexes")
|
||||
.setMultiplier(1.1D));
|
||||
IrisImportedStructureControl control = new IrisImportedStructureControl()
|
||||
.setFrequencyOverrides(overrides);
|
||||
NativeStructureFrequencies control = NativeStructureFrequencies.of(Map.of("minecraft:nether_complexes", 1.1D));
|
||||
|
||||
ChunkGeneratorStructureState returned =
|
||||
ModdedStructureSetFrequencyOverrides.apply(state, control);
|
||||
@@ -72,12 +66,7 @@ public class ModdedStructureSetFrequencyOverridesTest {
|
||||
Holder<StructureSet> custom = new BoundStructureSetHolder(
|
||||
"example:custom",
|
||||
new StructureSet(List.of(), new UnsupportedPlacement()));
|
||||
KList<IrisStructureSetFrequencyOverride> overrides = new KList<>();
|
||||
overrides.add(new IrisStructureSetFrequencyOverride()
|
||||
.setStructureSet("minecraft:nether_complexes")
|
||||
.setMultiplier(1.1D));
|
||||
IrisImportedStructureControl control = new IrisImportedStructureControl()
|
||||
.setFrequencyOverrides(overrides);
|
||||
NativeStructureFrequencies control = NativeStructureFrequencies.of(Map.of("minecraft:nether_complexes", 1.1D));
|
||||
|
||||
List<Holder<StructureSet>> scaled =
|
||||
ModdedStructureSetFrequencyOverrides.scaleSets(List.of(custom), control);
|
||||
@@ -91,12 +80,7 @@ public class ModdedStructureSetFrequencyOverridesTest {
|
||||
BoundStructureSetHolder second = new BoundStructureSetHolder("example:second");
|
||||
first.bind(new StructureSet(List.of(), placement(32, 8, 1, second)));
|
||||
second.bind(new StructureSet(List.of(), placement(40, 10, 2, first)));
|
||||
KList<IrisStructureSetFrequencyOverride> overrides = new KList<>();
|
||||
overrides.add(new IrisStructureSetFrequencyOverride()
|
||||
.setStructureSet("minecraft:nether_complexes")
|
||||
.setMultiplier(1.1D));
|
||||
IrisImportedStructureControl control = new IrisImportedStructureControl()
|
||||
.setFrequencyOverrides(overrides);
|
||||
NativeStructureFrequencies control = NativeStructureFrequencies.of(Map.of("minecraft:nether_complexes", 1.1D));
|
||||
|
||||
List<Holder<StructureSet>> scaled = ModdedStructureSetFrequencyOverrides.scaleSets(
|
||||
List.of(first, second), control);
|
||||
@@ -111,12 +95,7 @@ public class ModdedStructureSetFrequencyOverridesTest {
|
||||
BoundStructureSetHolder second = new BoundStructureSetHolder("example:second");
|
||||
first.bind(new StructureSet(List.of(), placement(32, 8, 1, second)));
|
||||
second.bind(new StructureSet(List.of(), placement(40, 10, 2, first)));
|
||||
KList<IrisStructureSetFrequencyOverride> overrides = new KList<>();
|
||||
overrides.add(new IrisStructureSetFrequencyOverride()
|
||||
.setStructureSet("example:first")
|
||||
.setMultiplier(1.1D));
|
||||
IrisImportedStructureControl control = new IrisImportedStructureControl()
|
||||
.setFrequencyOverrides(overrides);
|
||||
NativeStructureFrequencies control = NativeStructureFrequencies.of(Map.of("example:first", 1.1D));
|
||||
|
||||
List<Holder<StructureSet>> scaled = ModdedStructureSetFrequencyOverrides.scaleSets(
|
||||
List.of(first, second), control);
|
||||
@@ -132,12 +111,7 @@ public class ModdedStructureSetFrequencyOverridesTest {
|
||||
Holder<StructureSet> custom = new BoundStructureSetHolder(
|
||||
"example:custom",
|
||||
new StructureSet(List.of(), new CustomRandomSpreadPlacement()));
|
||||
KList<IrisStructureSetFrequencyOverride> overrides = new KList<>();
|
||||
overrides.add(new IrisStructureSetFrequencyOverride()
|
||||
.setStructureSet("example:custom")
|
||||
.setMultiplier(1.1D));
|
||||
IrisImportedStructureControl control = new IrisImportedStructureControl()
|
||||
.setFrequencyOverrides(overrides);
|
||||
NativeStructureFrequencies control = NativeStructureFrequencies.of(Map.of("example:custom", 1.1D));
|
||||
|
||||
assertThrows(IllegalStateException.class, () ->
|
||||
ModdedStructureSetFrequencyOverrides.scaleSets(List.of(custom), control));
|
||||
|
||||
+2
-2
@@ -52,8 +52,8 @@ public class NativeStructureFailureContractTest {
|
||||
|
||||
assertTrue(error.getMessage().contains("overworld:overworld"));
|
||||
assertTrue(error.getMessage().contains("generate-structures=false"));
|
||||
assertTrue(error.getMessage().contains("importedStructures.disabled"));
|
||||
assertTrue(error.getMessage().contains("importedStructures.disabledExact"));
|
||||
assertTrue(error.getMessage().contains("iris:structure disabled"));
|
||||
assertTrue(error.getMessage().contains("iris:structure disabledExact"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+15
-24
@@ -9,13 +9,10 @@ import art.arcane.iris.engine.framework.NativeStructureOwnershipRecord;
|
||||
import art.arcane.iris.engine.framework.NativeStructureOwnershipStore;
|
||||
import art.arcane.iris.engine.framework.NativeStructureStartPlan;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.IrisNativeStructure;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.IrisNativeStructureDecision;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructurePlacement;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructureTerrain;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructureTerrainMode;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.NativeStructureGenerationStatus;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import com.github.benmanes.caffeine.cache.Cache;
|
||||
import net.minecraft.SharedConstants;
|
||||
import net.minecraft.core.Direction;
|
||||
@@ -42,6 +39,7 @@ import net.minecraft.world.level.levelgen.structure.structures.OceanMonumentPiec
|
||||
import net.minecraft.world.level.levelgen.structure.structures.OceanMonumentStructure;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.mockito.MockedStatic;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Constructor;
|
||||
@@ -57,11 +55,17 @@ import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.mockStatic;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class NativeStructureReferenceRepairTest {
|
||||
private static final long MONUMENT_PLACEMENT_IDENTITY = 0x4D4F4E554D454E54L;
|
||||
|
||||
@BeforeClass
|
||||
public static void bootstrapMinecraftRegistries() {
|
||||
SharedConstants.tryDetectVersion();
|
||||
@@ -140,14 +144,10 @@ public class NativeStructureReferenceRepairTest {
|
||||
start,
|
||||
plan(origin, NativeStructureReferenceEnvelope.contentBounds(start).minY()),
|
||||
NativeStructureReferenceEnvelope.referenceBounds(start, structure, terrain));
|
||||
IrisDimension dimension = new IrisDimension();
|
||||
dimension.getImportedStructures().getDisabled().add(structureKey);
|
||||
IrisData data = packWithoutModules();
|
||||
Engine engine = engine(dimension, data);
|
||||
IrisNativeStructureDecision currentDecision = NativeStructureGenerationPolicy.resolve(
|
||||
engine, structureKey, false);
|
||||
Engine engine = engine(new IrisDimension(), packWithoutModules());
|
||||
IrisNativeStructureDecision currentDecision = new IrisNativeStructureDecision(
|
||||
NativeStructureGenerationStatus.DISABLED_BY_PACK, 0, null, false, null, null);
|
||||
|
||||
assertFalse(currentDecision.generate());
|
||||
assertFalse(NativeStructureReferenceRepair.naturalDecisionAllows(currentDecision));
|
||||
|
||||
ProtoChunk originChunk = emptyChunk(origin);
|
||||
@@ -163,7 +163,9 @@ public class NativeStructureReferenceRepairTest {
|
||||
assertNotNull(uncoveredTarget);
|
||||
|
||||
installOwnership(engine, ownership);
|
||||
try {
|
||||
try (MockedStatic<NativeStructureGenerationPolicy> policy = mockStatic(NativeStructureGenerationPolicy.class)) {
|
||||
policy.when(() -> NativeStructureGenerationPolicy.resolve(any(), eq(structureKey), anyBoolean()))
|
||||
.thenReturn(currentDecision);
|
||||
WorldGenLevel level = worldGenLevel(
|
||||
registry, serverLevel, originChunk, emptyScannedChunk);
|
||||
ProtoChunk coveredChunk = emptyChunk(coveredTarget);
|
||||
@@ -207,19 +209,8 @@ public class NativeStructureReferenceRepairTest {
|
||||
}
|
||||
|
||||
private static NativeStructureStartPlan plan(ChunkPos origin, int baseY) {
|
||||
IrisNativeStructure source = new IrisNativeStructure()
|
||||
.setStructure("minecraft:monument")
|
||||
.setWeight(1);
|
||||
IrisStructurePlacement placement = new IrisStructurePlacement()
|
||||
.setPlacementId("monument-reference-test")
|
||||
.setNativeStructures(new KList<IrisNativeStructure>().qadd(source));
|
||||
return new NativeStructureStartPlan(
|
||||
placement,
|
||||
source,
|
||||
origin.x(),
|
||||
origin.z(),
|
||||
baseY
|
||||
);
|
||||
return new NativeStructureStartPlan("minecraft:monument", origin.x(), origin.z(), baseY, false, false,
|
||||
MONUMENT_PLACEMENT_IDENTITY, null, null, new IrisStructureTerrain());
|
||||
}
|
||||
|
||||
private static ChunkPos outsideLiveBounds(NativeStructureOwnershipRecord ownership,
|
||||
|
||||
@@ -35,7 +35,7 @@ import art.arcane.iris.core.structure.authoring.StructureKey;
|
||||
import art.arcane.iris.core.structure.authoring.StructureSource;
|
||||
import art.arcane.iris.core.structure.authoring.StructureTransactionWriter;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.IrisImportedStructureControl;
|
||||
import art.arcane.iris.core.modules.ModuleVanillaStructures;
|
||||
import art.arcane.iris.util.common.format.C;
|
||||
import art.arcane.iris.util.common.plugin.VolmitSender;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
@@ -677,7 +677,7 @@ public final class DatapackIngestService {
|
||||
if (report.changed()) {
|
||||
message(sender, C.YELLOW + "New datapack structures were installed. A server restart is required for them to register and generate.");
|
||||
message(sender, C.GRAY + "After the restart they generate natively only in Iris dimensions that declare their source URL - no import needed. To get editable Iris copies (jigsaw pools, pieces & objects written into the pack) run /iris structure import <dimension>, or set general.autoImportDatapackStructures=true to do it on every ingest. Place any registered key directly with a 'structures' placement using nativeStructures.");
|
||||
message(sender, C.GRAY + "Datapacks replace matching vanilla structure keys by default. Set 'importedStructures.datapackOverrides' to false to keep minecraft-namespaced structure definitions untouched; deny non-minecraft datapack and mod structure families with importedStructures.disabled or complete keys with importedStructures.disabledExact.");
|
||||
message(sender, C.GRAY + "Datapacks replace matching vanilla structure keys by default. Set 'iris:structure datapackOverrides' to false to keep minecraft-namespaced structure definitions untouched; deny non-minecraft datapack and mod structure families with iris:structure disabled or complete keys with iris:structure disabledExact.");
|
||||
if (!restart) {
|
||||
message(sender, C.GRAY + "Run with restart=true to restart now, or restart manually. After restart, run /iris structure list <dimension> to see the new keys.");
|
||||
}
|
||||
@@ -2601,8 +2601,7 @@ public final class DatapackIngestService {
|
||||
if (dimension == null) {
|
||||
continue;
|
||||
}
|
||||
IrisImportedStructureControl control = dimension.getImportedStructures();
|
||||
if (control != null && !control.isDatapackOverrides()) {
|
||||
if (ModuleVanillaStructures.setupFor(data, dimension).protectsVanillaDefinitions()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import com.volmit.IrisFeature;
|
||||
import com.volmit.config.FeatureSettings.Entry;
|
||||
import com.volmit.config.PackSettings;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The settings one dimension of a pack declares, with every region and biome it reaches, read before any world of it
|
||||
* exists: what the platform's structure setup and data pack installs see. The same entries {@link IrisPackSettings}
|
||||
* gives a world of the dimension.
|
||||
*/
|
||||
final class DimensionSettings implements PackSettings {
|
||||
private final IrisData data;
|
||||
private final IrisDimension dimension;
|
||||
private final PackResourceIds ids;
|
||||
|
||||
DimensionSettings(IrisData data, IrisDimension dimension) {
|
||||
this.data = data;
|
||||
this.dimension = dimension;
|
||||
this.ids = new PackResourceIds(data.getDataFolder());
|
||||
}
|
||||
|
||||
@Override
|
||||
public <F extends IrisFeature> List<Entry<F>> declared(Class<F> featureType) {
|
||||
return IrisPackSettings.declaredBy(dimension, () -> data, ids, featureType);
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,7 @@ import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.engine.object.world.region.IrisRegion;
|
||||
import art.arcane.iris.util.common.data.DataProvider;
|
||||
import com.volmit.FeatureAttachment.Target;
|
||||
import com.volmit.IrisFeature;
|
||||
import com.volmit.config.FeatureSettings.Entry;
|
||||
@@ -65,13 +66,18 @@ public final class IrisPackSettings implements PackSettings {
|
||||
|
||||
@Override
|
||||
public <F extends IrisFeature> List<Entry<F>> declared(Class<F> featureType) {
|
||||
IrisDimension dimension = engine.getDimension();
|
||||
return declaredBy(engine.getDimension(), engine, ids, featureType);
|
||||
}
|
||||
|
||||
/** The settings of {@code featureType} that {@code dimension} and every region and biome it reaches declare, in that order. */
|
||||
static <F extends IrisFeature> List<Entry<F>> declaredBy(IrisDimension dimension, DataProvider data, PackResourceIds ids,
|
||||
Class<F> featureType) {
|
||||
List<Entry<F>> entries = new ArrayList<>();
|
||||
addEntry(entries, featureType, Target.DIMENSION, ids.of(DIMENSION, dimension.getLoadKey()), dimension);
|
||||
for (IrisRegion region : dimension.getAllRegions(engine)) {
|
||||
for (IrisRegion region : dimension.getAllRegions(data)) {
|
||||
addEntry(entries, featureType, Target.REGION, ids.of(REGION, region.getLoadKey()), region);
|
||||
}
|
||||
for (IrisBiome biome : dimension.getReachableBiomes(engine)) {
|
||||
for (IrisBiome biome : dimension.getReachableBiomes(data)) {
|
||||
addEntry(entries, featureType, Target.BIOME, ids.of(BIOME, biome.getLoadKey()), biome);
|
||||
}
|
||||
return List.copyOf(entries);
|
||||
|
||||
@@ -23,14 +23,23 @@ import art.arcane.iris.engine.object.material.IrisMaterialPalette;
|
||||
import art.arcane.iris.engine.object.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.engine.object.noise.IrisStyledRange;
|
||||
import art.arcane.iris.engine.object.noise.NoiseStyle;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructureStiltSettings;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructureTerrain;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructureYBand;
|
||||
import art.arcane.iris.engine.object.structure.jigsaw.IrisJigsawConfiguration;
|
||||
import art.arcane.iris.engine.object.value.IrisPosition;
|
||||
import art.arcane.iris.engine.object.value.IrisRange;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.collection.KMap;
|
||||
import com.google.gson.Gson;
|
||||
import com.volmit.block.BlockSpec;
|
||||
import com.volmit.block.PaletteSpec;
|
||||
import com.volmit.config.Range;
|
||||
import com.volmit.noise.StyledRange;
|
||||
import com.volmit.vanilla.JigsawOverrides;
|
||||
import com.volmit.vanilla.StructureStilts;
|
||||
import com.volmit.vanilla.StructureTerrain;
|
||||
import com.volmit.vanilla.YBand;
|
||||
import com.volmit.world.BlockPosition;
|
||||
|
||||
import java.util.Map;
|
||||
@@ -42,13 +51,18 @@ import java.util.Optional;
|
||||
* {@link IrisGeneratorStyle}) and studio describes the value with Iris's own description of that class.
|
||||
*/
|
||||
public final class IrisValues {
|
||||
private static final Map<String, Class<?>> IRIS_CLASSES = Map.of(
|
||||
BlockSpec.class.getName(), IrisBlockData.class,
|
||||
PaletteSpec.class.getName(), IrisMaterialPalette.class,
|
||||
com.volmit.noise.NoiseStyle.class.getName(), IrisGeneratorStyle.class,
|
||||
StyledRange.class.getName(), IrisStyledRange.class,
|
||||
Range.class.getName(), IrisRange.class,
|
||||
BlockPosition.class.getName(), IrisPosition.class);
|
||||
private static final Map<String, Class<?>> IRIS_CLASSES = Map.ofEntries(
|
||||
Map.entry(BlockSpec.class.getName(), IrisBlockData.class),
|
||||
Map.entry(PaletteSpec.class.getName(), IrisMaterialPalette.class),
|
||||
Map.entry(com.volmit.noise.NoiseStyle.class.getName(), IrisGeneratorStyle.class),
|
||||
Map.entry(StyledRange.class.getName(), IrisStyledRange.class),
|
||||
Map.entry(Range.class.getName(), IrisRange.class),
|
||||
Map.entry(BlockPosition.class.getName(), IrisPosition.class),
|
||||
Map.entry(StructureTerrain.class.getName(), IrisStructureTerrain.class),
|
||||
Map.entry(StructureStilts.class.getName(), IrisStructureStiltSettings.class),
|
||||
Map.entry(YBand.class.getName(), IrisStructureYBand.class),
|
||||
Map.entry(JigsawOverrides.class.getName(), IrisJigsawConfiguration.class));
|
||||
private static final Gson SAME_JSON = new Gson();
|
||||
|
||||
private IrisValues() {
|
||||
}
|
||||
@@ -80,6 +94,30 @@ public final class IrisValues {
|
||||
return new IrisMaterialPalette().setStyle(generatorStyle(spec.style())).setZoom(spec.zoom()).setPalette(blocks);
|
||||
}
|
||||
|
||||
/** {@code terrain} as the terrain fitting Iris's native structure placement applies. */
|
||||
public static IrisStructureTerrain structureTerrain(StructureTerrain terrain) {
|
||||
return sameJson(terrain, IrisStructureTerrain.class);
|
||||
}
|
||||
|
||||
/** {@code stilts} as the foundation columns Iris's native structure placement builds. */
|
||||
public static IrisStructureStiltSettings structureStilts(StructureStilts stilts) {
|
||||
return sameJson(stilts, IrisStructureStiltSettings.class);
|
||||
}
|
||||
|
||||
public static IrisStructureYBand yBand(YBand band) {
|
||||
return sameJson(band, IrisStructureYBand.class);
|
||||
}
|
||||
|
||||
/** {@code overrides} as the jigsaw configuration Iris applies to a platform jigsaw definition. */
|
||||
public static IrisJigsawConfiguration jigsawConfiguration(JigsawOverrides overrides) {
|
||||
return sameJson(overrides, IrisJigsawConfiguration.class);
|
||||
}
|
||||
|
||||
/** The structure fit classes are plain values whose JSON is the API type's, so the conversion is a JSON round trip. */
|
||||
private static <T> T sameJson(Object apiValue, Class<T> irisClass) {
|
||||
return SAME_JSON.fromJson(SAME_JSON.toJsonTree(apiValue), irisClass);
|
||||
}
|
||||
|
||||
/** Iris's maps hold no null values; a JSON null in a map reads as absent, as it does for Iris's own fields. */
|
||||
private static KMap<String, Object> irisMap(Map<String, ?> values) {
|
||||
KMap<String, Object> map = new KMap<>();
|
||||
|
||||
@@ -18,37 +18,56 @@
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.NativeStructureStartPlan;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructureTerrain;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import com.volmit.config.PackSettings;
|
||||
import com.volmit.host.DiscoveredModule;
|
||||
import com.volmit.host.VanillaStructureHookRegistration;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.vanilla.VanillaStructureAdjustment;
|
||||
import com.volmit.vanilla.VanillaStructureContext;
|
||||
import com.volmit.vanilla.VanillaStructureHook;
|
||||
import com.volmit.vanilla.VanillaStructureRule;
|
||||
import com.volmit.vanilla.VanillaStructureSetup;
|
||||
import com.volmit.vanilla.VanillaStructureStart;
|
||||
import com.volmit.vanilla.VanillaStructureStartContext;
|
||||
import com.volmit.world.PackWorld;
|
||||
import com.volmit.world.TerrainSampler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* What the pack's modules want for each of the platform's own structures in one engine's world: every vanilla structure
|
||||
* hook of the pack asked once per structure, the rules combined ({@link VanillaStructureRule#and}). Kept per engine and
|
||||
* pack snapshot, so a hotload or a reload of the pack's resources asks the hooks again. The platform side
|
||||
* ({@code NativeStructureGenerationPolicy}) applies the result on Bukkit and the modded platforms alike.
|
||||
* What the pack's modules want for the platform's own structures, asked through their vanilla structure hooks in module
|
||||
* id order: per structure in one engine's world the combined rule ({@link VanillaStructureRule#and}) and adjustment
|
||||
* ({@link VanillaStructureAdjustment#then}), kept per engine and pack snapshot so a hotload or a reload of the pack's
|
||||
* resources asks again; per chunk the starts modules place, converted to the host's plans; and per dimension, before a
|
||||
* world exists, the combined setup ({@link VanillaStructureSetup#and}). The platform side applies the results on Bukkit
|
||||
* and the modded platforms alike.
|
||||
*/
|
||||
public final class ModuleVanillaStructures {
|
||||
private static final Map<Engine, ModuleVanillaStructures> WORLDS = Collections.synchronizedMap(new WeakHashMap<>());
|
||||
private static final int START_TERRAIN_REACH_BLOCKS = 8;
|
||||
|
||||
private final PackResources snapshot;
|
||||
private final List<VanillaStructureHookRegistration> hooks;
|
||||
private final VanillaStructureContext world;
|
||||
private final Map<String, VanillaStructureRule> rules = new ConcurrentHashMap<>();
|
||||
private final Map<AdjustedStructure, VanillaStructureAdjustment> adjustments = new ConcurrentHashMap<>();
|
||||
|
||||
private ModuleVanillaStructures(Engine engine, PackResources snapshot) {
|
||||
this.snapshot = snapshot;
|
||||
this.hooks = engine.getData().getModules().pack().catalog().vanillaStructureHooks();
|
||||
this.hooks = hooksOf(engine.getData());
|
||||
this.world = new World(snapshot, new IrisPackSettings(engine));
|
||||
}
|
||||
|
||||
@@ -57,6 +76,47 @@ public final class ModuleVanillaStructures {
|
||||
return of(engine).rule(structureKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* The combined adjustment of the pack's modules for the platform's own starts of {@code structureKey} in
|
||||
* {@code engine}'s world; {@code underground} is whether the platform generates it in an underground step.
|
||||
*/
|
||||
public static VanillaStructureAdjustment adjustmentFor(Engine engine, String structureKey, boolean underground) {
|
||||
return of(engine).adjustment(structureKey, underground);
|
||||
}
|
||||
|
||||
/**
|
||||
* The starts the pack's modules place in chunk {@code chunkX, chunkZ} of {@code engine}'s world, in module id order,
|
||||
* as the host's plans: world heights, Iris's fit and jigsaw classes.
|
||||
*/
|
||||
public static List<NativeStructureStartPlan> startsAt(Engine engine, int chunkX, int chunkZ) {
|
||||
StartContext context = new StartContext(engine.getGeneration().world(),
|
||||
new IrisTerrainSampler(engine, new PackResourceIds(engine.getData().getDataFolder()),
|
||||
chunkX << 4, chunkZ << 4, START_TERRAIN_REACH_BLOCKS));
|
||||
List<NativeStructureStartPlan> plans = new ArrayList<>();
|
||||
for (VanillaStructureHookRegistration registration : hooksOf(engine.getData())) {
|
||||
for (VanillaStructureStart start : ask(registration, "placing starts in chunk " + chunkX + "," + chunkZ,
|
||||
hook -> hook.starts(chunkX, chunkZ, context))) {
|
||||
plans.add(plan(registration.module(), start, chunkX, chunkZ, engine.getMinHeight()));
|
||||
}
|
||||
}
|
||||
return List.copyOf(plans);
|
||||
}
|
||||
|
||||
/** The combined setup of the pack's modules for {@code dimension} of the pack {@code data} serves, before any world exists. */
|
||||
public static VanillaStructureSetup setupFor(IrisData data, IrisDimension dimension) {
|
||||
VanillaStructureContext context = new World(data.getPackResources(), new DimensionSettings(data, dimension));
|
||||
VanillaStructureSetup combined = VanillaStructureSetup.UNCHANGED;
|
||||
for (VanillaStructureHookRegistration registration : hooksOf(data)) {
|
||||
combined = combined.and(ask(registration, "setting up the vanilla structures of dimension " + dimension.getLoadKey(),
|
||||
hook -> hook.setup(context)));
|
||||
}
|
||||
return combined;
|
||||
}
|
||||
|
||||
private static List<VanillaStructureHookRegistration> hooksOf(IrisData data) {
|
||||
return data.getModules().pack().catalog().vanillaStructureHooks();
|
||||
}
|
||||
|
||||
private static ModuleVanillaStructures of(Engine engine) {
|
||||
PackResources current = engine.getData().getPackResources();
|
||||
ModuleVanillaStructures known = WORLDS.get(engine);
|
||||
@@ -69,39 +129,91 @@ public final class ModuleVanillaStructures {
|
||||
}
|
||||
|
||||
private VanillaStructureRule rule(String structureKey) {
|
||||
return rules.computeIfAbsent(structureKey, this::askHooks);
|
||||
return rules.computeIfAbsent(structureKey, this::askRules);
|
||||
}
|
||||
|
||||
private VanillaStructureAdjustment adjustment(String structureKey, boolean underground) {
|
||||
return adjustments.computeIfAbsent(new AdjustedStructure(structureKey, underground), this::askAdjustments);
|
||||
}
|
||||
|
||||
/** A key that is no resource id names no structure a module could decide over. */
|
||||
private VanillaStructureRule askHooks(String structureKey) {
|
||||
ResourceId structure;
|
||||
try {
|
||||
structure = ResourceId.parse(structureKey);
|
||||
} catch (IllegalArgumentException notAnId) {
|
||||
private VanillaStructureRule askRules(String structureKey) {
|
||||
Optional<ResourceId> structure = structureId(structureKey);
|
||||
if (structure.isEmpty()) {
|
||||
return VanillaStructureRule.GENERATE;
|
||||
}
|
||||
VanillaStructureRule combined = VanillaStructureRule.GENERATE;
|
||||
for (VanillaStructureHookRegistration registration : hooks) {
|
||||
combined = combined.and(ask(registration, structure));
|
||||
VanillaStructureRule rule = ask(registration, "deciding over vanilla structure " + structure.get(),
|
||||
hook -> hook.rule(structure.get(), world));
|
||||
combined = combined.and(rule);
|
||||
}
|
||||
return combined;
|
||||
}
|
||||
|
||||
private VanillaStructureRule ask(VanillaStructureHookRegistration registration, ResourceId structure) {
|
||||
VanillaStructureRule rule;
|
||||
private VanillaStructureAdjustment askAdjustments(AdjustedStructure adjusted) {
|
||||
Optional<ResourceId> structure = structureId(adjusted.key());
|
||||
if (structure.isEmpty()) {
|
||||
return VanillaStructureAdjustment.NONE;
|
||||
}
|
||||
VanillaStructureAdjustment combined = VanillaStructureAdjustment.NONE;
|
||||
for (VanillaStructureHookRegistration registration : hooks) {
|
||||
VanillaStructureAdjustment adjustment = ask(registration, "adjusting vanilla structure " + structure.get(),
|
||||
hook -> hook.adjustment(structure.get(), adjusted.underground(), world));
|
||||
combined = combined.then(adjustment);
|
||||
}
|
||||
return combined;
|
||||
}
|
||||
|
||||
private static Optional<ResourceId> structureId(String structureKey) {
|
||||
try {
|
||||
rule = registration.hook().rule(structure, world);
|
||||
return Optional.of(ResourceId.parse(structureKey));
|
||||
} catch (IllegalArgumentException notAnId) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
/** One hook's answer to {@code question}; a hook that throws or answers nothing fails naming its module. */
|
||||
private static <T> T ask(VanillaStructureHookRegistration registration, String question,
|
||||
Function<VanillaStructureHook, T> answer) {
|
||||
T result;
|
||||
try {
|
||||
result = answer.apply(registration.hook());
|
||||
} catch (RuntimeException failure) {
|
||||
throw new IllegalStateException("Module " + registration.module() + " failed deciding over vanilla structure "
|
||||
+ structure + ": " + failure, failure);
|
||||
throw new IllegalStateException("Module " + registration.module() + " failed " + question + ": " + failure, failure);
|
||||
}
|
||||
if (rule == null) {
|
||||
throw new IllegalStateException("Module " + registration.module() + " gave no rule for vanilla structure " + structure);
|
||||
if (result == null) {
|
||||
throw new IllegalStateException("Module " + registration.module() + " gave no answer " + question);
|
||||
}
|
||||
return rule;
|
||||
return result;
|
||||
}
|
||||
|
||||
private static NativeStructureStartPlan plan(DiscoveredModule module, VanillaStructureStart start, int chunkX, int chunkZ,
|
||||
int minHeight) {
|
||||
if (start.chunkX() != chunkX || start.chunkZ() != chunkZ) {
|
||||
throw new IllegalStateException("Module " + module + " started " + start.structure() + " in chunk "
|
||||
+ start.chunkX() + "," + start.chunkZ() + " when asked for chunk " + chunkX + "," + chunkZ);
|
||||
}
|
||||
return new NativeStructureStartPlan(
|
||||
start.structure().toString(),
|
||||
start.chunkX(),
|
||||
start.chunkZ(),
|
||||
start.y() + minHeight,
|
||||
start.isUnderground(),
|
||||
start.replacesPlatformStart(),
|
||||
start.identity(),
|
||||
start.jigsaw().map(IrisValues::jigsawConfiguration).orElse(null),
|
||||
start.fit().stilts().map(IrisValues::structureStilts).orElse(null),
|
||||
start.fit().terrain().map(IrisValues::structureTerrain).orElseGet(IrisStructureTerrain::new));
|
||||
}
|
||||
|
||||
/** The world the hooks decide for: the engine's pack snapshot and the settings its dimension reaches. */
|
||||
private record World(PackResources resources, PackSettings settings) implements VanillaStructureContext {
|
||||
}
|
||||
|
||||
private record StartContext(PackWorld world, TerrainSampler terrain) implements VanillaStructureStartContext {
|
||||
}
|
||||
|
||||
private record AdjustedStructure(String key, boolean underground) {
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@
|
||||
package art.arcane.iris.core.nms;
|
||||
|
||||
import art.arcane.iris.core.datapack.DatapackStructureScopeIndex;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.IrisImportedStructureControl;
|
||||
import art.arcane.iris.engine.framework.NativeStructureFrequencies;
|
||||
import art.arcane.iris.core.lifecycle.WorldLifecycleCaller;
|
||||
import art.arcane.iris.core.lifecycle.WorldLifecycleRequest;
|
||||
import art.arcane.iris.core.lifecycle.WorldLifecycleService;
|
||||
@@ -234,7 +234,7 @@ public interface INMSBinding {
|
||||
World world,
|
||||
DatapackStructureScopeIndex scopeIndex,
|
||||
Set<String> declaredSources,
|
||||
IrisImportedStructureControl importedStructures
|
||||
NativeStructureFrequencies frequencies
|
||||
) throws NoSuchFieldException, IllegalAccessException;
|
||||
|
||||
CompletableFuture<Void> completeStudioStructureBootstrap(World world) throws NoSuchFieldException, IllegalAccessException;
|
||||
|
||||
@@ -20,7 +20,7 @@ package art.arcane.iris.core.nms.v1X;
|
||||
|
||||
import art.arcane.iris.core.datapack.DatapackStructureScopeIndex;
|
||||
import art.arcane.iris.core.nms.DatapackStructureScopeResult;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.IrisImportedStructureControl;
|
||||
import art.arcane.iris.engine.framework.NativeStructureFrequencies;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.core.nms.INMSBinding;
|
||||
import art.arcane.iris.core.nms.container.BiomeColor;
|
||||
@@ -112,7 +112,7 @@ public class NMSBinding1X implements INMSBinding {
|
||||
World world,
|
||||
DatapackStructureScopeIndex scopeIndex,
|
||||
Set<String> declaredSources,
|
||||
IrisImportedStructureControl importedStructures
|
||||
NativeStructureFrequencies frequencies
|
||||
) {
|
||||
throw new IllegalStateException("Iris-managed datapack structure isolation requires the supported NMS binding");
|
||||
}
|
||||
|
||||
@@ -95,27 +95,30 @@ final class PackDimensionValidator {
|
||||
}
|
||||
}
|
||||
|
||||
/** The dimension's settings of the {@code iris:structure} module, which the platform's own structures follow. */
|
||||
static final String STRUCTURE_SETTINGS = "iris:structure";
|
||||
|
||||
static void validateImportedStructurePolicy(String dimensionKey, JSONObject dimension,
|
||||
List<String> blockingErrors, List<String> warnings) {
|
||||
if (!dimension.has("importedStructures")) {
|
||||
if (!dimension.has(STRUCTURE_SETTINGS)) {
|
||||
return;
|
||||
}
|
||||
if (dimension.isNull("importedStructures")) {
|
||||
blockingErrors.add("Dimension '" + dimensionKey + "' importedStructures must be an object.");
|
||||
if (dimension.isNull(STRUCTURE_SETTINGS)) {
|
||||
blockingErrors.add("Dimension '" + dimensionKey + "' iris:structure must be an object.");
|
||||
return;
|
||||
}
|
||||
JSONObject policy = dimension.optJSONObject("importedStructures");
|
||||
JSONObject policy = dimension.optJSONObject(STRUCTURE_SETTINGS);
|
||||
if (policy == null) {
|
||||
blockingErrors.add("Dimension '" + dimensionKey + "' importedStructures must be an object.");
|
||||
blockingErrors.add("Dimension '" + dimensionKey + "' iris:structure must be an object.");
|
||||
return;
|
||||
}
|
||||
if (policy.has("mode")) {
|
||||
blockingErrors.add("Dimension '" + dimensionKey
|
||||
+ "' importedStructures.mode is not supported. Native structures are enabled by default; deny families in importedStructures.disabled or complete keys in importedStructures.disabledExact.");
|
||||
+ "' iris:structure.mode is not supported. Native structures are enabled by default; deny families in iris:structure disabled or complete keys in iris:structure disabledExact.");
|
||||
}
|
||||
if (policy.has("enabled")) {
|
||||
blockingErrors.add("Dimension '" + dimensionKey
|
||||
+ "' importedStructures.enabled is not supported. Native structures are enabled by default; deny families in importedStructures.disabled or complete keys in importedStructures.disabledExact.");
|
||||
+ "' iris:structure.enabled is not supported. Native structures are enabled by default; deny families in iris:structure disabled or complete keys in iris:structure disabledExact.");
|
||||
}
|
||||
validateStructureKeyList(dimensionKey, policy, "disabled", blockingErrors);
|
||||
validateStructureKeyList(dimensionKey, policy, "disabledExact", blockingErrors);
|
||||
@@ -124,7 +127,7 @@ final class PackDimensionValidator {
|
||||
if (adjustments == null) {
|
||||
if (policy.has("adjustments")) {
|
||||
blockingErrors.add("Dimension '" + dimensionKey
|
||||
+ "' importedStructures.adjustments must be an array.");
|
||||
+ "' iris:structure.adjustments must be an array.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -132,17 +135,17 @@ final class PackDimensionValidator {
|
||||
JSONObject adjustment = adjustments.optJSONObject(index);
|
||||
if (adjustment == null) {
|
||||
blockingErrors.add("Dimension '" + dimensionKey
|
||||
+ "' importedStructures.adjustments has a non-object entry at index " + index + ".");
|
||||
+ "' iris:structure.adjustments has a non-object entry at index " + index + ".");
|
||||
continue;
|
||||
}
|
||||
if (adjustment.has("clearVegetation")) {
|
||||
warnings.add("Dimension '" + dimensionKey + "' importedStructures.adjustments[" + index
|
||||
warnings.add("Dimension '" + dimensionKey + "' iris:structure.adjustments[" + index
|
||||
+ "].clearVegetation was removed and is ignored. Vegetation is always cleared inside structure piece envelopes.");
|
||||
}
|
||||
validateStructureKeyList(dimensionKey, adjustment, "match", blockingErrors);
|
||||
validateAdjustmentYBand(dimensionKey, adjustment, index, blockingErrors);
|
||||
PackStructurePlacementValidator.validateNativeTerrain("Dimension '" + dimensionKey
|
||||
+ "' importedStructures.adjustments[" + index + "]", adjustment, blockingErrors);
|
||||
+ "' iris:structure.adjustments[" + index + "]", adjustment, blockingErrors);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,13 +157,13 @@ final class PackDimensionValidator {
|
||||
JSONArray overrides = policy.optJSONArray("frequencyOverrides");
|
||||
if (overrides == null) {
|
||||
blockingErrors.add("Dimension '" + dimensionKey
|
||||
+ "' importedStructures.frequencyOverrides must be an array.");
|
||||
+ "' iris:structure.frequencyOverrides must be an array.");
|
||||
return;
|
||||
}
|
||||
for (int index = 0; index < overrides.length(); index++) {
|
||||
JSONObject override = overrides.optJSONObject(index);
|
||||
String path = "Dimension '" + dimensionKey
|
||||
+ "' importedStructures.frequencyOverrides[" + index + "]";
|
||||
+ "' iris:structure.frequencyOverrides[" + index + "]";
|
||||
if (override == null) {
|
||||
blockingErrors.add(path + " must be an object.");
|
||||
continue;
|
||||
@@ -182,7 +185,7 @@ final class PackDimensionValidator {
|
||||
return;
|
||||
}
|
||||
String path = "Dimension '" + dimensionKey
|
||||
+ "' importedStructures.adjustments[" + index + "].yBand";
|
||||
+ "' iris:structure.adjustments[" + index + "].yBand";
|
||||
JSONObject band = adjustment.optJSONObject("yBand");
|
||||
if (band == null) {
|
||||
blockingErrors.add(path + " must be an object.");
|
||||
|
||||
@@ -490,7 +490,7 @@ final class PackStructurePlacementValidator {
|
||||
private static void validateImportedStructureAdjustmentEnvelopes(
|
||||
String dimensionKey, JSONObject dimension, RegistrySnapshot registries,
|
||||
List<String> blockingErrors) {
|
||||
JSONObject policy = dimension.optJSONObject("importedStructures");
|
||||
JSONObject policy = dimension.optJSONObject(PackDimensionValidator.STRUCTURE_SETTINGS);
|
||||
if (policy == null) {
|
||||
return;
|
||||
}
|
||||
@@ -511,7 +511,7 @@ final class PackStructurePlacementValidator {
|
||||
continue;
|
||||
}
|
||||
String path = "Dimension '" + dimensionKey
|
||||
+ "' importedStructures.adjustments[" + adjustmentIndex + "]";
|
||||
+ "' iris:structure.adjustments[" + adjustmentIndex + "]";
|
||||
for (String structureKey : orderedStructureKeys) {
|
||||
if (matchesStructure(matches, structureKey)) {
|
||||
effective.put(structureKey, new EffectiveTerrainAdjustment(path, adjustment));
|
||||
@@ -661,7 +661,7 @@ final class PackStructurePlacementValidator {
|
||||
if ("VACUUM".equals(mode) || "ENCASE".equals(mode)) {
|
||||
blockingErrors.add(path + ".terrain.mode " + mode
|
||||
+ " cannot target editable Iris structures; use nativeStructures or "
|
||||
+ "importedStructures.adjustments for native terrain preparation.");
|
||||
+ "iris:structure adjustments for native terrain preparation.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +54,6 @@ import art.arcane.iris.engine.object.annotations.RegistryListResource;
|
||||
import art.arcane.iris.engine.object.annotations.RegistryListSpecialEntity;
|
||||
import art.arcane.iris.engine.object.annotations.RegistryListStructure;
|
||||
import art.arcane.iris.engine.object.annotations.RegistryListVanillaStructure;
|
||||
import art.arcane.iris.engine.object.annotations.RegistryListVanillaStructureSet;
|
||||
import art.arcane.iris.engine.object.annotations.RegistryMapBlockState;
|
||||
import art.arcane.iris.engine.object.annotations.Required;
|
||||
import art.arcane.iris.engine.object.annotations.Snippet;
|
||||
@@ -293,8 +292,8 @@ public class SchemaBuilder {
|
||||
|
||||
/**
|
||||
* A registry enum that ALSO accepts family/namespace prefixes ("minecraft:village",
|
||||
* "nova_structures:") — the runtime prefix-matching contract of importedStructures.disabled and
|
||||
* adjustments[].match. Emitted as anyOf(enum, pattern) so autocomplete still offers registered
|
||||
* "nova_structures:") — the runtime prefix-matching contract of iris:structure disabled and
|
||||
* adjustments[].match ({@code Reference.STRUCTURE_PREFIX}). Emitted as anyOf(enum, pattern) so autocomplete still offers registered
|
||||
* keys while prefix entries validate instead of being rejected.
|
||||
*/
|
||||
private void putRegistryEnumOrPrefixRef(JSONObject target, String definitionKey,
|
||||
@@ -323,14 +322,6 @@ public class SchemaBuilder {
|
||||
target.put("$ref", "#/definitions/" + definitionKey);
|
||||
}
|
||||
|
||||
private void putRegistryEnumOrPrefixItems(JSONObject prop, String definitionKey,
|
||||
String enumDefinitionKey, Supplier<JSONArray> values,
|
||||
String pattern) {
|
||||
JSONObject items = new JSONObject();
|
||||
putRegistryEnumOrPrefixRef(items, definitionKey, enumDefinitionKey, values, pattern);
|
||||
prop.put("items", items);
|
||||
}
|
||||
|
||||
private JSONArray itemTypes() {
|
||||
JSONArray a = new JSONArray();
|
||||
for (String key : IrisPlatforms.get().registries().itemKeys()) {
|
||||
@@ -439,6 +430,9 @@ public class SchemaBuilder {
|
||||
case ENTITY -> putRegistryEnumRef(property, "enum-entity-type", this::entityTypes);
|
||||
case BIOME -> putRegistryEnumRef(property, "enum-biome-type", this::biomeTypes);
|
||||
case STRUCTURE -> putRegistryEnumRef(property, "enum-vanilla-structure", this::vanillaStructures);
|
||||
case STRUCTURE_PREFIX -> putRegistryEnumOrPrefixRef(property, "enum-vanilla-structure-or-prefix",
|
||||
"enum-vanilla-structure", this::vanillaStructures, VANILLA_STRUCTURE_PREFIX_PATTERN);
|
||||
case STRUCTURE_SET -> putRegistryEnumRef(property, "enum-vanilla-structure-set", this::vanillaStructureSets);
|
||||
case POTION_EFFECT -> putRegistryEnumRef(property, "enum-potion-effect-type", this::potionTypes);
|
||||
case ENCHANTMENT -> putRegistryEnumRef(property, "enum-enchantment", this::enchantTypes);
|
||||
case PACK_BIOME -> putPackResourceRef(property, IrisBiome.class);
|
||||
@@ -615,19 +609,8 @@ public class SchemaBuilder {
|
||||
|
||||
} else if (k.isAnnotationPresent(RegistryListVanillaStructure.class)) {
|
||||
fancyType = "Vanilla Structure";
|
||||
if (k.getAnnotation(RegistryListVanillaStructure.class).prefixes()) {
|
||||
putRegistryEnumOrPrefixRef(prop, "enum-vanilla-structure-or-prefix",
|
||||
"enum-vanilla-structure", this::vanillaStructures, VANILLA_STRUCTURE_PREFIX_PATTERN);
|
||||
description.add(SYMBOL_TYPE__N + " Must be a vanilla/datapack structure key or a family/namespace prefix like 'minecraft:village' or 'nova_structures:' (use ctrl+space for auto complete!)");
|
||||
} else {
|
||||
putRegistryEnumRef(prop, "enum-vanilla-structure", this::vanillaStructures);
|
||||
description.add(SYMBOL_TYPE__N + " Must be a valid vanilla/datapack structure key (use ctrl+space for auto complete!)");
|
||||
}
|
||||
|
||||
} else if (k.isAnnotationPresent(RegistryListVanillaStructureSet.class)) {
|
||||
fancyType = "Vanilla Structure Set";
|
||||
putRegistryEnumRef(prop, "enum-vanilla-structure-set", this::vanillaStructureSets);
|
||||
description.add(SYMBOL_TYPE__N + " Must be a valid vanilla/datapack structure SET key (use ctrl+space for auto complete!)");
|
||||
putRegistryEnumRef(prop, "enum-vanilla-structure", this::vanillaStructures);
|
||||
description.add(SYMBOL_TYPE__N + " Must be a valid vanilla/datapack structure key (use ctrl+space for auto complete!)");
|
||||
|
||||
} else if (k.isAnnotationPresent(RegistryListItemType.class)) {
|
||||
fancyType = "Item Type";
|
||||
@@ -812,18 +795,8 @@ public class SchemaBuilder {
|
||||
description.add(SYMBOL_TYPE__N + " Must be a registered vanilla, datapack, or modded template pool key (use ctrl+space for auto complete!)");
|
||||
} else if (k.isAnnotationPresent(RegistryListVanillaStructure.class)) {
|
||||
fancyType = "List<Vanilla Structure>";
|
||||
if (k.getAnnotation(RegistryListVanillaStructure.class).prefixes()) {
|
||||
putRegistryEnumOrPrefixItems(prop, "enum-vanilla-structure-or-prefix",
|
||||
"enum-vanilla-structure", this::vanillaStructures, VANILLA_STRUCTURE_PREFIX_PATTERN);
|
||||
description.add(SYMBOL_TYPE__N + " Must be a vanilla/datapack structure key or a family/namespace prefix like 'minecraft:village' or 'nova_structures:' (use ctrl+space for auto complete!)");
|
||||
} else {
|
||||
putRegistryEnumItems(prop, "enum-vanilla-structure", this::vanillaStructures);
|
||||
description.add(SYMBOL_TYPE__N + " Must be a valid vanilla/datapack structure key (use ctrl+space for auto complete!)");
|
||||
}
|
||||
} else if (k.isAnnotationPresent(RegistryListVanillaStructureSet.class)) {
|
||||
fancyType = "List<Vanilla Structure Set>";
|
||||
putRegistryEnumItems(prop, "enum-vanilla-structure-set", this::vanillaStructureSets);
|
||||
description.add(SYMBOL_TYPE__N + " Must be a valid vanilla/datapack structure set key (use ctrl+space for auto complete!)");
|
||||
putRegistryEnumItems(prop, "enum-vanilla-structure", this::vanillaStructures);
|
||||
description.add(SYMBOL_TYPE__N + " Must be a valid vanilla/datapack structure key (use ctrl+space for auto complete!)");
|
||||
} else if (k.isAnnotationPresent(RegistryListBlockType.class)) {
|
||||
fancyType = "List of Block Types";
|
||||
putRegistryEnumItems(prop, "enum-block-type", this::blockTypes);
|
||||
|
||||
@@ -113,7 +113,7 @@ public final class StructureIndexService {
|
||||
counts.put("irisStructures", iris.size());
|
||||
|
||||
Map<String, Object> root = new LinkedHashMap<>();
|
||||
root.put("note", "Generated index of every structure available at runtime. Toggle vanilla/datapack generation via the dimension importedStructures block (by structure key). Place structures via biome/region/dimension structures lists.");
|
||||
root.put("note", "Generated index of every structure available at runtime. Toggle vanilla/datapack generation via the dimension's iris:structure settings (by structure key). Place structures via biome/region/dimension structures lists.");
|
||||
root.put("counts", counts);
|
||||
root.put("structures", structuresNode);
|
||||
root.put("structureSets", setsNode);
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package art.arcane.iris.engine.framework;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.modules.ModuleVanillaStructures;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* How often the structures of each platform structure set start in a dimension: the multipliers the pack's modules
|
||||
* set up through their vanilla structure hooks, by normalized structure set key. Sets without one start as their
|
||||
* definition says (multiplier 1).
|
||||
*/
|
||||
public final class NativeStructureFrequencies {
|
||||
public static final NativeStructureFrequencies NONE = new NativeStructureFrequencies(Map.of());
|
||||
|
||||
private static final double UNCHANGED = 1D;
|
||||
|
||||
private final Map<String, Double> multipliers;
|
||||
|
||||
private NativeStructureFrequencies(Map<String, Double> multipliers) {
|
||||
this.multipliers = Map.copyOf(multipliers);
|
||||
}
|
||||
|
||||
/** The frequencies the modules of {@code data}'s pack set up for {@code dimension}. */
|
||||
public static NativeStructureFrequencies of(IrisData data, IrisDimension dimension) {
|
||||
return new NativeStructureFrequencies(ModuleVanillaStructures.setupFor(data, dimension).frequencies().entrySet().stream()
|
||||
.collect(Collectors.toMap(entry -> entry.getKey().toString(), Map.Entry::getValue)));
|
||||
}
|
||||
|
||||
/** Test and fixture form: multipliers by structure set key. */
|
||||
public static NativeStructureFrequencies of(Map<String, Double> multipliers) {
|
||||
return new NativeStructureFrequencies(multipliers.entrySet().stream()
|
||||
.collect(Collectors.toMap(entry -> normalize(entry.getKey()), Map.Entry::getValue)));
|
||||
}
|
||||
|
||||
public double multiplier(String structureSetKey) {
|
||||
return multipliers.getOrDefault(normalize(structureSetKey), UNCHANGED);
|
||||
}
|
||||
|
||||
public boolean hasOverrides() {
|
||||
return !multipliers.isEmpty();
|
||||
}
|
||||
|
||||
private static String normalize(String key) {
|
||||
return key == null ? "" : key.trim().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
}
|
||||
+29
-25
@@ -18,20 +18,21 @@
|
||||
|
||||
package art.arcane.iris.engine.framework;
|
||||
|
||||
import art.arcane.iris.core.modules.IrisValues;
|
||||
import art.arcane.iris.core.modules.ModuleVanillaStructures;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.IrisImportedStructureControl;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.IrisNativeStructureDecision;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.NativeStructureGenerationStatus;
|
||||
import com.volmit.vanilla.VanillaStructureAdjustment;
|
||||
import com.volmit.vanilla.VanillaStructureFit;
|
||||
import com.volmit.vanilla.VanillaStructureRule;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Whether the platform generates one of its own structures in an engine's world, the same on every platform: the
|
||||
* dimension's {@code importedStructures} settings first, then the rule the pack's modules give the structure through
|
||||
* their vanilla structure hooks ({@link ModuleVanillaStructures}). A structure a module blocks does not generate; one a
|
||||
* module places itself is reported as replaced, so find, goto and verify locate the module's placement.
|
||||
* Whether the platform generates one of its own structures in an engine's world, and how its starts are adjusted, the
|
||||
* same on every platform: the rule and adjustment the pack's modules give the structure through their vanilla
|
||||
* structure hooks ({@link ModuleVanillaStructures}). A structure a module blocks does not generate; one a module
|
||||
* places itself is reported as replaced, so find, goto and verify locate the module's placement.
|
||||
*/
|
||||
public final class NativeStructureGenerationPolicy {
|
||||
private NativeStructureGenerationPolicy() {
|
||||
@@ -40,27 +41,30 @@ public final class NativeStructureGenerationPolicy {
|
||||
public static IrisNativeStructureDecision resolve(Engine engine, String structureKey,
|
||||
boolean undergroundStep) {
|
||||
Engine activeEngine = Objects.requireNonNull(engine, "Native structure policy requires an engine");
|
||||
IrisDimension dimension = Objects.requireNonNull(activeEngine.getDimension(),
|
||||
"Native structure policy requires a bound dimension");
|
||||
IrisImportedStructureControl control = Objects.requireNonNull(
|
||||
dimension.getImportedStructures(),
|
||||
"Dimension importedStructures must not be null");
|
||||
IrisNativeStructureDecision decision = control.resolve(structureKey, undergroundStep);
|
||||
if (decision.status() == NativeStructureGenerationStatus.INVALID_REGISTRY_KEY) {
|
||||
return decision;
|
||||
if (structureKey == null || structureKey.isBlank()) {
|
||||
return decision(NativeStructureGenerationStatus.INVALID_REGISTRY_KEY, VanillaStructureAdjustment.NONE);
|
||||
}
|
||||
VanillaStructureRule modules = ModuleVanillaStructures.ruleFor(activeEngine, structureKey);
|
||||
if (!decision.generate()) {
|
||||
// A key the dimension disables that a module places is the "blanket-disable, re-place explicitly"
|
||||
// pattern: report REPLACED_BY_IRIS so find/goto/verify locate the module's placement.
|
||||
return modules.placedByModule() ? decision.withStatus(NativeStructureGenerationStatus.REPLACED_BY_IRIS) : decision;
|
||||
VanillaStructureRule rule = ModuleVanillaStructures.ruleFor(activeEngine, structureKey);
|
||||
VanillaStructureAdjustment adjustment = ModuleVanillaStructures.adjustmentFor(activeEngine, structureKey, undergroundStep);
|
||||
return decision(status(rule), adjustment);
|
||||
}
|
||||
|
||||
private static IrisNativeStructureDecision decision(NativeStructureGenerationStatus status,
|
||||
VanillaStructureAdjustment adjustment) {
|
||||
VanillaStructureFit fit = adjustment.fit();
|
||||
return new IrisNativeStructureDecision(status, adjustment.yShift(),
|
||||
adjustment.yBand().map(IrisValues::yBand).orElse(null), adjustment.keepsSourceY(),
|
||||
fit.stilts().map(IrisValues::structureStilts).orElse(null),
|
||||
fit.terrain().map(IrisValues::structureTerrain).orElse(null));
|
||||
}
|
||||
|
||||
private static NativeStructureGenerationStatus status(VanillaStructureRule rule) {
|
||||
if (!rule.blocksPlatform()) {
|
||||
return NativeStructureGenerationStatus.GENERATE_NATIVE;
|
||||
}
|
||||
if (!modules.blocksPlatform()) {
|
||||
return decision;
|
||||
}
|
||||
return decision.withStatus(modules.placedByModule()
|
||||
return rule.placedByModule()
|
||||
? NativeStructureGenerationStatus.REPLACED_BY_IRIS
|
||||
: NativeStructureGenerationStatus.DISABLED_BY_PACK);
|
||||
: NativeStructureGenerationStatus.DISABLED_BY_PACK;
|
||||
}
|
||||
|
||||
public static String generationStatusMessage(String structureKey,
|
||||
@@ -69,7 +73,7 @@ public final class NativeStructureGenerationPolicy {
|
||||
return switch (Objects.requireNonNull(status, "Native structure status must not be null")) {
|
||||
case GENERATE_NATIVE -> "Native structure " + key + " generates natively.";
|
||||
case DISABLED_BY_PACK -> "Native structure " + key
|
||||
+ " is disabled by this dimension's importedStructures settings or a module of the pack.";
|
||||
+ " is disabled by this dimension's iris:structure settings or a module of the pack.";
|
||||
case REPLACED_BY_IRIS -> "Native structure " + key
|
||||
+ " is replaced by an Iris placement in this pack and locates through that explicit replacement.";
|
||||
case INVALID_REGISTRY_KEY -> "Native structure registry key is invalid: " + key;
|
||||
|
||||
-173
@@ -1,173 +0,0 @@
|
||||
package art.arcane.iris.engine.framework;
|
||||
|
||||
import art.arcane.iris.engine.object.structure.vanilla.IrisNativeStructure;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.IrisNativeStructureDecision;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructureAnchorMode;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructurePlacement;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.NativeStructureGenerationStatus;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public final class NativeStructurePlacementPlanner {
|
||||
private static final long NATIVE_SELECTION_DOMAIN = 0x4E41544956454A53L;
|
||||
|
||||
private NativeStructurePlacementPlanner() {
|
||||
}
|
||||
|
||||
public static KList<NativeStructureStartPlan> plansAt(Engine engine, int chunkX, int chunkZ) {
|
||||
Map<String, NativeStructureStartPlan> plansByStructure = new LinkedHashMap<>();
|
||||
for (IrisStructurePlacement placement : StructurePlacementScope.placementsAt(engine, chunkX, chunkZ)) {
|
||||
NativeStructureStartPlan plan = planAt(engine, placement, chunkX, chunkZ);
|
||||
if (plan != null) {
|
||||
String structureKey = normalize(plan.source().getStructure());
|
||||
NativeStructureStartPlan current = plansByStructure.get(structureKey);
|
||||
if (current == null || comparePlacementPriority(plan.placement(), current.placement()) < 0) {
|
||||
plansByStructure.put(structureKey, plan);
|
||||
}
|
||||
}
|
||||
}
|
||||
return new KList<>(plansByStructure.values());
|
||||
}
|
||||
|
||||
public static NativeStructureStartPlan planAt(Engine engine, IrisStructurePlacement placement,
|
||||
int chunkX, int chunkZ) {
|
||||
validateBackend(placement);
|
||||
if (!placement.hasNativeStructures()) {
|
||||
return null;
|
||||
}
|
||||
Engine activeEngine = Objects.requireNonNull(engine, "Native structure planner requires an engine");
|
||||
if (activeEngine.getSeedManager() == null) {
|
||||
throw new IllegalStateException("Native structure planner requires a bound seed manager");
|
||||
}
|
||||
long mantleSeed = activeEngine.getSeedManager().getMantle();
|
||||
if (!StructurePlacementGrid.startsInChunk(placement, chunkX, chunkZ, mantleSeed)) {
|
||||
return null;
|
||||
}
|
||||
RNG placementRng = StructurePlacementGrid.placementRng(
|
||||
placement, chunkX, chunkZ, mantleSeed).nextParallelRNG(NATIVE_SELECTION_DOMAIN);
|
||||
IrisNativeStructure source = selectSource(placement.getNativeStructures(), placementRng);
|
||||
Integer baseY = resolveBaseY(activeEngine, placement, chunkX, chunkZ, placementRng);
|
||||
if (baseY == null) {
|
||||
return null;
|
||||
}
|
||||
return new NativeStructureStartPlan(placement, source, chunkX, chunkZ, baseY);
|
||||
}
|
||||
|
||||
public static NativeStructureStartPlan matchingPlan(Engine engine, String structureKey,
|
||||
int chunkX, int chunkZ) {
|
||||
if (structureKey == null || structureKey.isBlank()) {
|
||||
return null;
|
||||
}
|
||||
String normalizedKey = normalize(structureKey);
|
||||
for (NativeStructureStartPlan plan : plansAt(engine, chunkX, chunkZ)) {
|
||||
if (normalizedKey.equals(normalize(plan.source().getStructure()))) {
|
||||
return plan;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static IrisNativeStructureDecision decisionFor(NativeStructureStartPlan plan) {
|
||||
Objects.requireNonNull(plan, "Native structure start plan must not be null");
|
||||
IrisStructurePlacement placement = plan.placement();
|
||||
return new IrisNativeStructureDecision(
|
||||
NativeStructureGenerationStatus.GENERATE_NATIVE,
|
||||
0,
|
||||
null,
|
||||
false,
|
||||
placement.getStilt(),
|
||||
placement.resolvedTerrain()
|
||||
);
|
||||
}
|
||||
|
||||
public static void validateBackend(IrisStructurePlacement placement) {
|
||||
if (placement == null) {
|
||||
throw new IllegalStateException("Structure placement must not be null");
|
||||
}
|
||||
boolean iris = placement.hasIrisStructures();
|
||||
boolean nativeStructure = placement.hasNativeStructures();
|
||||
if (iris == nativeStructure) {
|
||||
throw new IllegalStateException("Structure placement must declare exactly one backend: "
|
||||
+ "structures or nativeStructures");
|
||||
}
|
||||
if (nativeStructure && placement.getAnchor() != null
|
||||
&& placement.getAnchor() != IrisStructureAnchorMode.LEGACY) {
|
||||
throw new IllegalStateException("Native structure placements do not support the Iris anchor field");
|
||||
}
|
||||
}
|
||||
|
||||
static IrisNativeStructure selectSource(KList<IrisNativeStructure> sources, RNG rng) {
|
||||
Objects.requireNonNull(sources, "Native structure sources must not be null");
|
||||
Objects.requireNonNull(rng, "Native structure selection requires an RNG");
|
||||
long totalWeight = 0L;
|
||||
for (IrisNativeStructure source : sources) {
|
||||
if (source == null || source.getStructure() == null || source.getStructure().isBlank()) {
|
||||
throw new IllegalStateException("Native structure placement contains a blank source");
|
||||
}
|
||||
if (source.getWeight() < 1) {
|
||||
throw new IllegalStateException("Native structure source '" + source.getStructure()
|
||||
+ "' has invalid weight " + source.getWeight());
|
||||
}
|
||||
totalWeight = Math.addExact(totalWeight, source.getWeight());
|
||||
}
|
||||
if (totalWeight > Integer.MAX_VALUE) {
|
||||
throw new IllegalStateException("Native structure source weights exceed " + Integer.MAX_VALUE);
|
||||
}
|
||||
int roll = rng.nextInt((int) totalWeight);
|
||||
for (IrisNativeStructure source : sources) {
|
||||
roll -= source.getWeight();
|
||||
if (roll < 0) {
|
||||
return source;
|
||||
}
|
||||
}
|
||||
throw new IllegalStateException("Native structure source selection produced no result");
|
||||
}
|
||||
|
||||
private static Integer resolveBaseY(Engine engine, IrisStructurePlacement placement,
|
||||
int chunkX, int chunkZ, RNG rng) {
|
||||
int worldMin = engine.getMinHeight() + 1;
|
||||
int worldMax = engine.getMinHeight() + engine.getHeight() - 1;
|
||||
if (worldMin > worldMax) {
|
||||
throw new IllegalStateException("Native structure placement has invalid world height bounds");
|
||||
}
|
||||
int blockX = (chunkX << 4) + 8;
|
||||
int blockZ = (chunkZ << 4) + 8;
|
||||
if (!placement.isUnderwater()
|
||||
&& isSubmerged(engine, blockX, blockZ)) {
|
||||
return null;
|
||||
}
|
||||
if (!placement.isUnderground()) {
|
||||
int surfaceY = engine.getHeight(blockX, blockZ, true) + engine.getMinHeight();
|
||||
if (surfaceY < placement.getMinHeight() || surfaceY > placement.getMaxHeight()) {
|
||||
return null;
|
||||
}
|
||||
return surfaceY;
|
||||
}
|
||||
int bandMin = Math.max(worldMin, Math.min(placement.getMinHeight(), placement.getMaxHeight()));
|
||||
int bandMax = Math.min(worldMax, Math.max(placement.getMinHeight(), placement.getMaxHeight()));
|
||||
if (bandMin > bandMax) {
|
||||
return null;
|
||||
}
|
||||
return bandMin == bandMax ? bandMin : bandMin + rng.nextInt((bandMax - bandMin) + 1);
|
||||
}
|
||||
|
||||
static boolean isSubmerged(Engine engine, int blockX, int blockZ) {
|
||||
return engine.getHeight(blockX, blockZ, true) < engine.getDimension().getFluidHeight();
|
||||
}
|
||||
|
||||
private static int comparePlacementPriority(IrisStructurePlacement left, IrisStructurePlacement right) {
|
||||
long leftIdentity = StructurePlacementGrid.placementIdentity(left);
|
||||
long rightIdentity = StructurePlacementGrid.placementIdentity(right);
|
||||
return Long.compareUnsigned(leftIdentity, rightIdentity);
|
||||
}
|
||||
|
||||
private static String normalize(String structureKey) {
|
||||
return structureKey == null ? "" : structureKey.toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,13 +1,39 @@
|
||||
package art.arcane.iris.engine.framework;
|
||||
|
||||
import art.arcane.iris.engine.object.structure.vanilla.IrisNativeStructure;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructurePlacement;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructureStiltSettings;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructureTerrain;
|
||||
import art.arcane.iris.engine.object.structure.jigsaw.IrisJigsawConfiguration;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.IrisNativeStructureDecision;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.NativeStructureGenerationStatus;
|
||||
|
||||
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, and Iris's jigsaw,
|
||||
* stilt and terrain classes for the module's jigsaw overrides and fit. {@code jigsaw} and {@code stilt} may be null;
|
||||
* {@code terrain} is never null ({@code SOURCE} when the module states none).
|
||||
*/
|
||||
public record NativeStructureStartPlan(
|
||||
IrisStructurePlacement placement,
|
||||
IrisNativeStructure source,
|
||||
String structureKey,
|
||||
int chunkX,
|
||||
int chunkZ,
|
||||
int baseY
|
||||
int baseY,
|
||||
boolean underground,
|
||||
boolean replacesPlatformStart,
|
||||
long placementIdentity,
|
||||
IrisJigsawConfiguration jigsaw,
|
||||
IrisStructureStiltSettings stilt,
|
||||
IrisStructureTerrain terrain
|
||||
) {
|
||||
public NativeStructureStartPlan {
|
||||
Objects.requireNonNull(structureKey, "Native structure start plan requires a structure key");
|
||||
Objects.requireNonNull(terrain, "Native structure start plan requires a terrain fit");
|
||||
}
|
||||
|
||||
/** The platform decision this start is generated under: generated natively with the start's own fit. */
|
||||
public IrisNativeStructureDecision decision() {
|
||||
return new IrisNativeStructureDecision(NativeStructureGenerationStatus.GENERATE_NATIVE, 0, null, false, stilt, terrain);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package art.arcane.iris.engine.framework;
|
||||
|
||||
import art.arcane.iris.core.modules.ModuleVanillaStructures;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* The platform structure starts the pack's modules place in a chunk, on every platform the same: what the vanilla
|
||||
* structure hooks of the engine's pack return, in module id order, as the plans the platform code generates.
|
||||
*/
|
||||
public final class NativeStructureStarts {
|
||||
private NativeStructureStarts() {
|
||||
}
|
||||
|
||||
public static List<NativeStructureStartPlan> plansAt(Engine engine, int chunkX, int chunkZ) {
|
||||
return ModuleVanillaStructures.startsAt(engine, chunkX, chunkZ);
|
||||
}
|
||||
|
||||
/** The first start of {@code structureKey} (ignoring case) the modules place in the chunk, or null when none does. */
|
||||
public static NativeStructureStartPlan matchingPlan(Engine engine, String structureKey, int chunkX, int chunkZ) {
|
||||
if (structureKey == null || structureKey.isBlank()) {
|
||||
return null;
|
||||
}
|
||||
String normalizedKey = normalize(structureKey);
|
||||
for (NativeStructureStartPlan plan : plansAt(engine, chunkX, chunkZ)) {
|
||||
if (normalizedKey.equals(normalize(plan.structureKey()))) {
|
||||
return plan;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String normalize(String structureKey) {
|
||||
return structureKey.toLowerCase(Locale.ROOT);
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ package art.arcane.iris.core.modules;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.SeedManager;
|
||||
import com.volmit.IrisFeature;
|
||||
import com.volmit.IrisModule;
|
||||
import com.volmit.host.LoadedPack;
|
||||
import com.volmit.host.ModuleHost;
|
||||
@@ -28,7 +29,9 @@ import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -74,6 +77,15 @@ public final class BuiltInPack {
|
||||
return pack;
|
||||
}
|
||||
|
||||
/** {@code values} as the module settings a dimension, region or biome declares, as the decoder would have read them. */
|
||||
public static ModuleSettings settings(IrisFeature... values) {
|
||||
Map<Class<? extends IrisFeature>, IrisFeature> byType = new HashMap<>();
|
||||
for (IrisFeature value : values) {
|
||||
byType.put(value.getClass(), value);
|
||||
}
|
||||
return ModuleSettings.of(byType);
|
||||
}
|
||||
|
||||
/** Placements into a world of {@code engine} derive their seeds from its world seed. */
|
||||
public static void seedWorld(Engine engine, long seed) {
|
||||
SeedManager seeds = mock(SeedManager.class);
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.structure.StructureAdjustment;
|
||||
import art.arcane.iris.builtin.structure.StructureSettings;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructureStiltSettings;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructureTerrain;
|
||||
import art.arcane.volmlib.util.json.JSONObject;
|
||||
import com.google.gson.Gson;
|
||||
import com.volmit.FeatureAttachment.Target;
|
||||
import com.volmit.block.BlockSpec;
|
||||
import com.volmit.host.LoadedPack;
|
||||
import com.volmit.host.ModuleHost;
|
||||
import com.volmit.vanilla.StructureTerrain;
|
||||
import com.volmit.vanilla.YBand;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* The dimension's {@code importedStructures} as tools/migrate-pack.py writes it, {@code "iris:structure": {...}}, read into
|
||||
* {@link StructureSettings}, IrisApi types only, with the values Iris's own classes read from the same JSON.
|
||||
*/
|
||||
public class StructureSettingsDecodingTest {
|
||||
/** The overworld test pack's dimensions/overworld.json member after migration, plus the options it leaves out. */
|
||||
private static final String MIGRATED_DIMENSION = """
|
||||
{"iris:structure": {
|
||||
"datapackOverrides": true,
|
||||
"adjustments": [
|
||||
{
|
||||
"match": ["minecraft:stronghold"],
|
||||
"yBand": {"min": -120, "max": -20},
|
||||
"terrain": {
|
||||
"mode": "ENCASE", "horizontalPadding": 4, "ceilingPadding": 4, "floorPadding": 4,
|
||||
"encasePalette": {"zoom": 1, "palette": [
|
||||
{"block": "minecraft:stone_bricks", "weight": 6}, {"block": "minecraft:mossy_stone_bricks", "weight": 2},
|
||||
{"block": "minecraft:cracked_stone_bricks", "weight": 2}, {"block": "minecraft:cobblestone", "weight": 1}
|
||||
]}
|
||||
}
|
||||
},
|
||||
{"match": ["minecraft:trial_chambers"], "yShift": -64},
|
||||
{"match": ["minecraft:mineshaft"], "preserveSourceY": true},
|
||||
{"match": ["minecraft:village"], "stilt": {"maxDepth": 2, "palette": {"palette": [{"block": "minecraft:dirt"}]}}}
|
||||
],
|
||||
"disabled": ["minecraft:village", "nova_structures:"],
|
||||
"disabledExact": ["minecraft:ruined_portal"],
|
||||
"undergroundYShift": -32,
|
||||
"frequencyOverrides": [{"structureSet": "minecraft:nether_complexes", "multiplier": 1.5}]
|
||||
}}
|
||||
""";
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder folder = new TemporaryFolder();
|
||||
|
||||
private LoadedPack pack;
|
||||
private ModuleSettingsDecoder decoder;
|
||||
|
||||
@Before
|
||||
public void loadBuiltIns() throws IOException {
|
||||
Path packFolder = folder.newFolder("pack").toPath();
|
||||
pack = LoadedPack.load(packFolder, ModuleHost.of(IrisModuleHost.builtInModules())
|
||||
.describingHostTypesIn(IrisModuleHost.HOST_TYPE_PACKAGE).copyingJarsTo(folder.newFolder("copies").toPath()));
|
||||
decoder = new ModuleSettingsDecoder(pack.catalog(), packFolder, Gson::new);
|
||||
}
|
||||
|
||||
@After
|
||||
public void closePack() {
|
||||
pack.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theMigratedDimensionReadsEveryOption() {
|
||||
StructureSettings settings = settings(MIGRATED_DIMENSION);
|
||||
|
||||
assertTrue(settings.datapackOverrides());
|
||||
assertEquals(List.of("minecraft:village", "nova_structures:"), settings.disabled());
|
||||
assertEquals(List.of("minecraft:ruined_portal"), settings.disabledExact());
|
||||
assertEquals(-32, settings.undergroundYShift());
|
||||
assertEquals("minecraft:nether_complexes", settings.frequencyOverrides().getFirst().structureSet());
|
||||
assertEquals(1.5, settings.frequencyOverrides().getFirst().multiplier(), 0);
|
||||
List<StructureAdjustment> adjustments = settings.adjustments();
|
||||
assertEquals(4, adjustments.size());
|
||||
StructureAdjustment stronghold = adjustments.getFirst();
|
||||
assertEquals(Optional.of(YBand.of(-120, -20)), stronghold.yBand());
|
||||
StructureTerrain terrain = stronghold.terrain().orElseThrow();
|
||||
assertEquals(StructureTerrain.Mode.ENCASE, terrain.mode());
|
||||
assertEquals(4, terrain.horizontalPadding());
|
||||
assertEquals(BlockSpec.of("minecraft:stone_bricks").withWeight(6), terrain.encasePalette().orElseThrow().palette().getFirst());
|
||||
assertEquals(-64, adjustments.get(1).yShift());
|
||||
assertTrue(adjustments.get(2).preserveSourceY());
|
||||
assertEquals(2, adjustments.get(3).stilt().orElseThrow().maxDepth());
|
||||
assertEquals(List.of(BlockSpec.of("minecraft:dirt")), adjustments.get(3).stilt().orElseThrow().palette().palette());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fitsBecomeTheIrisClassesTheOldDimensionFieldReadFromTheSameJson() {
|
||||
JSONObject json = new JSONObject(MIGRATED_DIMENSION).getJSONObject("iris:structure").getJSONArray("adjustments").getJSONObject(0);
|
||||
JSONObject stiltJson = new JSONObject(MIGRATED_DIMENSION).getJSONObject("iris:structure").getJSONArray("adjustments")
|
||||
.getJSONObject(3).getJSONObject("stilt");
|
||||
List<StructureAdjustment> adjustments = settings(MIGRATED_DIMENSION).adjustments();
|
||||
Gson gson = new Gson();
|
||||
|
||||
assertEquals(gson.toJson(gson.fromJson(json.getJSONObject("terrain").toString(), IrisStructureTerrain.class)),
|
||||
gson.toJson(IrisValues.structureTerrain(adjustments.getFirst().terrain().orElseThrow())));
|
||||
assertEquals(gson.toJson(gson.fromJson(stiltJson.toString(), IrisStructureStiltSettings.class)),
|
||||
gson.toJson(IrisValues.structureStilts(adjustments.get(3).stilt().orElseThrow())));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theOldKeyIsNotSettingsAndEmptySettingsHaveTheDefaults() {
|
||||
JSONObject old = new JSONObject("{\"importedStructures\": {\"disabled\": [\"minecraft:village\"]}}");
|
||||
|
||||
assertSame(ModuleSettings.NONE, decoder.decode(Target.DIMENSION, old, "dimension overworld"));
|
||||
assertFalse(decoder.keys(Target.DIMENSION).contains("importedStructures"));
|
||||
StructureSettings defaults = settings("{\"iris:structure\": {}}");
|
||||
assertTrue(defaults.datapackOverrides());
|
||||
assertEquals(List.of(), defaults.disabled());
|
||||
assertEquals(List.of(), defaults.adjustments());
|
||||
assertEquals(0, defaults.undergroundYShift());
|
||||
}
|
||||
|
||||
private StructureSettings settings(String dimensionJson) {
|
||||
return decoder.decode(Target.DIMENSION, new JSONObject(dimensionJson), "dimension overworld")
|
||||
.find(StructureSettings.class).orElseThrow();
|
||||
}
|
||||
}
|
||||
+6
-6
@@ -116,8 +116,8 @@ public class PackValidatorImportedStructurePolicyTest {
|
||||
List<String> errors = validate(policy);
|
||||
|
||||
assertEquals(2, errors.size());
|
||||
assertTrue(errors.get(0).contains("importedStructures.mode is not supported"));
|
||||
assertTrue(errors.get(1).contains("importedStructures.enabled is not supported"));
|
||||
assertTrue(errors.get(0).contains("iris:structure.mode is not supported"));
|
||||
assertTrue(errors.get(1).contains("iris:structure.enabled is not supported"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -156,8 +156,8 @@ public class PackValidatorImportedStructurePolicyTest {
|
||||
|
||||
List<String> nullErrors = new ArrayList<>();
|
||||
PackDimensionValidator.validateImportedStructurePolicy("overworld",
|
||||
new JSONObject().put("importedStructures", JSONObject.NULL), nullErrors, new ArrayList<>());
|
||||
assertEquals(List.of("Dimension 'overworld' importedStructures must be an object."), nullErrors);
|
||||
new JSONObject().put("iris:structure", JSONObject.NULL), nullErrors, new ArrayList<>());
|
||||
assertEquals(List.of("Dimension 'overworld' iris:structure must be an object."), nullErrors);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -170,7 +170,7 @@ public class PackValidatorImportedStructurePolicyTest {
|
||||
List<String> warnings = new ArrayList<>();
|
||||
|
||||
PackDimensionValidator.validateImportedStructurePolicy("overworld",
|
||||
new JSONObject().put("importedStructures", policy), errors, warnings);
|
||||
new JSONObject().put("iris:structure", policy), errors, warnings);
|
||||
|
||||
assertTrue(errors.toString(), errors.isEmpty());
|
||||
assertEquals(1, warnings.size());
|
||||
@@ -181,7 +181,7 @@ public class PackValidatorImportedStructurePolicyTest {
|
||||
private List<String> validate(JSONObject policy) {
|
||||
List<String> errors = new ArrayList<>();
|
||||
PackDimensionValidator.validateImportedStructurePolicy("overworld",
|
||||
new JSONObject().put("importedStructures", policy), errors, new ArrayList<>());
|
||||
new JSONObject().put("iris:structure", policy), errors, new ArrayList<>());
|
||||
return errors;
|
||||
}
|
||||
}
|
||||
@@ -494,7 +494,7 @@ public class PackValidatorStructureGraphTest {
|
||||
List<String> errors = validateWithJigsawMetadata(pack, 80, 0, 129, 0);
|
||||
|
||||
assertTrue(errors.toString(), errors.stream().anyMatch(message ->
|
||||
message.contains("importedStructures.adjustments[0]")
|
||||
message.contains("iris:structure.adjustments[0]")
|
||||
&& message.contains("129-block maximum start element")
|
||||
&& message.contains("128-block (8-chunk)")));
|
||||
}
|
||||
@@ -502,7 +502,7 @@ public class PackValidatorStructureGraphTest {
|
||||
@Test
|
||||
public void lastMatchingNaturalTerrainAdjustmentControlsEnvelopeValidation() throws Exception {
|
||||
File pack = temporaryFolder.newFolder("natural-adjustment-precedence");
|
||||
write(pack, "dimensions/main.json", "{\"importedStructures\":{\"adjustments\":["
|
||||
write(pack, "dimensions/main.json", "{\"iris:structure\":{\"adjustments\":["
|
||||
+ "{\"match\":[\"test:structure\"],\"terrain\":{\"mode\":\"ENCASE\","
|
||||
+ "\"horizontalPadding\":128}},"
|
||||
+ "{\"match\":[\"test:structure\"],\"terrain\":{\"mode\":\"PRESERVE\"}}]}}}");
|
||||
@@ -823,7 +823,7 @@ public class PackValidatorStructureGraphTest {
|
||||
private File nativeAdjustmentEnvelopePack(String name, String match, String mode,
|
||||
int horizontalPadding) throws Exception {
|
||||
File pack = temporaryFolder.newFolder(name);
|
||||
write(pack, "dimensions/main.json", "{\"importedStructures\":{\"adjustments\":[{"
|
||||
write(pack, "dimensions/main.json", "{\"iris:structure\":{\"adjustments\":[{"
|
||||
+ "\"match\":[\"" + match + "\"],\"terrain\":{\"mode\":\"" + mode
|
||||
+ "\",\"horizontalPadding\":" + horizontalPadding + "}}]}}}");
|
||||
return pack;
|
||||
|
||||
+2
-2
@@ -39,7 +39,7 @@ public class PackValidatorStructureTerrainBackendTest {
|
||||
pack, Set.of("dimension_city", "forest_tower", "plains_farm"), false, errors);
|
||||
|
||||
String suffix = ".terrain.mode " + mode + " cannot target editable Iris structures; "
|
||||
+ "use nativeStructures or importedStructures.adjustments for native terrain preparation.";
|
||||
+ "use nativeStructures or iris:structure adjustments for native terrain preparation.";
|
||||
assertEquals(List.of(
|
||||
"Dimension 'main' structures[0]" + suffix,
|
||||
"Region 'forest' structures[0]" + suffix,
|
||||
@@ -87,7 +87,7 @@ public class PackValidatorStructureTerrainBackendTest {
|
||||
List<String> errors = new ArrayList<>();
|
||||
|
||||
PackDimensionValidator.validateImportedStructurePolicy(
|
||||
"overworld", new JSONObject().put("importedStructures", policy),
|
||||
"overworld", new JSONObject().put("iris:structure", policy),
|
||||
errors, new ArrayList<>());
|
||||
|
||||
assertTrue(mode + ": " + errors, errors.isEmpty());
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package art.arcane.iris.core.project;
|
||||
|
||||
import art.arcane.iris.builtin.structure.StructureSettings;
|
||||
import art.arcane.iris.engine.mantle.components.StructureModule;
|
||||
import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
@@ -28,7 +29,6 @@ import art.arcane.iris.engine.object.noise.expression.IrisExpression;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructure;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructurePlacement;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.IrisVanillaStructureAdjustment;
|
||||
import art.arcane.iris.engine.object.annotations.ArrayType;
|
||||
import art.arcane.iris.engine.object.annotations.Desc;
|
||||
import art.arcane.iris.engine.object.annotations.MaxNumber;
|
||||
@@ -63,6 +63,7 @@ import art.arcane.iris.core.modules.PackModuleSet;
|
||||
import art.arcane.iris.core.modules.ModuleResourceFixture;
|
||||
import com.volmit.FeatureAttachment.Target;
|
||||
import com.volmit.IrisFeature;
|
||||
import com.volmit.FeatureRegistry;
|
||||
import com.volmit.IrisModule;
|
||||
import com.volmit.ModuleInfo;
|
||||
import com.volmit.config.Feature;
|
||||
@@ -79,6 +80,7 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -211,31 +213,66 @@ public class SchemaBuilderParityTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nativeAdjustmentSchemaExposesPlacementOverrides() {
|
||||
JSONObject schema = new SchemaBuilder(
|
||||
IrisVanillaStructureAdjustment.class, structureSchemaData()).construct();
|
||||
public void structureSettingsRenderTheirFitsWithIrisDefinitionsOfTheSameJson() throws IOException {
|
||||
JSONObject schema = new SchemaBuilder(IrisDimension.class, structureSchemaData(structureSettingsSchema())).construct();
|
||||
JSONObject definitions = schema.getJSONObject("definitions");
|
||||
JSONObject properties = schema.getJSONObject("properties");
|
||||
JSONObject band = definitions.getJSONObject(
|
||||
definitionKey(properties.getJSONObject("yBand"))).getJSONObject("properties");
|
||||
JSONObject stiltProperties = definitions.getJSONObject(
|
||||
definitionKey(properties.getJSONObject("stilt"))).getJSONObject("properties");
|
||||
JSONObject terrainProperties = definitions.getJSONObject(
|
||||
definitionKey(properties.getJSONObject("terrain"))).getJSONObject("properties");
|
||||
JSONObject spacing = stiltProperties.getJSONObject("spacing");
|
||||
JSONObject settings = definitions.getJSONObject(definitionKey(rootProperties(schema).getJSONObject("iris:structure")))
|
||||
.getJSONObject("properties");
|
||||
JSONObject adjustment = definitions.getJSONObject(definitionKey(settings.getJSONObject("adjustments").getJSONObject("items")))
|
||||
.getJSONObject("properties");
|
||||
JSONObject band = irisDefinition(definitions, adjustment.getJSONObject("yBand")).getJSONObject("properties");
|
||||
JSONObject stilt = irisDefinition(definitions, adjustment.getJSONObject("stilt")).getJSONObject("properties");
|
||||
JSONObject terrain = irisDefinition(definitions, adjustment.getJSONObject("terrain")).getJSONObject("properties");
|
||||
|
||||
assertEquals("boolean", properties.getJSONObject("preserveSourceY").getString("type"));
|
||||
assertEquals("obj-art-arcane-iris-engine-object-structure-irisstructureyband",
|
||||
definitionKey(definitions.getJSONObject(definitionKey(adjustment.getJSONObject("yBand")))));
|
||||
assertEquals("boolean", adjustment.getJSONObject("preserveSourceY").getString("type"));
|
||||
assertEquals(-4064, band.getJSONObject("min").getInt("minimum"));
|
||||
assertEquals(4064, band.getJSONObject("min").getInt("maximum"));
|
||||
assertEquals(-4064, band.getJSONObject("max").getInt("minimum"));
|
||||
assertEquals(4064, band.getJSONObject("max").getInt("maximum"));
|
||||
assertEquals(1, spacing.getInt("minimum"));
|
||||
assertEquals(64, spacing.getInt("maximum"));
|
||||
assertTrue(terrainProperties.has("mode"));
|
||||
assertTrue(terrainProperties.has("shape"));
|
||||
assertTrue(terrainProperties.has("lobeFrequency"));
|
||||
assertTrue(terrainProperties.has("lobeStrength"));
|
||||
assertTrue(terrainProperties.has("encasePalette"));
|
||||
assertEquals(1, stilt.getJSONObject("spacing").getInt("minimum"));
|
||||
assertEquals(64, stilt.getJSONObject("spacing").getInt("maximum"));
|
||||
assertTrue(terrain.has("mode"));
|
||||
assertTrue(terrain.has("shape"));
|
||||
assertTrue(terrain.has("lobeFrequency"));
|
||||
assertTrue(terrain.has("lobeStrength"));
|
||||
assertTrue(terrain.has("encasePalette"));
|
||||
assertEquals(1, settings.getJSONObject("adjustments").getInt("minItems"));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@code disabled} and {@code adjustments[].match} accept family and namespace prefixes ("minecraft:village",
|
||||
* "nova_structures:"), so studio offers the registered keys and also accepts a key/prefix pattern; exact-key
|
||||
* options keep the strict list, and structure set options list the registered sets.
|
||||
*/
|
||||
@Test
|
||||
public void structureSettingsAcceptPrefixesWhereTheyMatchFamilies() throws IOException {
|
||||
JSONObject schema = new SchemaBuilder(IrisDimension.class, structureSchemaData(structureSettingsSchema())).construct();
|
||||
JSONObject definitions = schema.getJSONObject("definitions");
|
||||
JSONObject settings = definitions.getJSONObject(definitionKey(rootProperties(schema).getJSONObject("iris:structure")))
|
||||
.getJSONObject("properties");
|
||||
JSONObject adjustment = definitions.getJSONObject(definitionKey(settings.getJSONObject("adjustments").getJSONObject("items")))
|
||||
.getJSONObject("properties");
|
||||
JSONObject frequency = definitions.getJSONObject(definitionKey(settings.getJSONObject("frequencyOverrides").getJSONObject("items")))
|
||||
.getJSONObject("properties");
|
||||
|
||||
assertEquals("enum-vanilla-structure-or-prefix", definitionKey(settings.getJSONObject("disabled").getJSONObject("items")));
|
||||
assertEquals("enum-vanilla-structure-or-prefix", definitionKey(adjustment.getJSONObject("match").getJSONObject("items")));
|
||||
assertEquals("enum-vanilla-structure", definitionKey(settings.getJSONObject("disabledExact").getJSONObject("items")));
|
||||
assertEquals("the fake platform lists no structure sets, so the set key is plain text",
|
||||
"string", frequency.getJSONObject("structureSet").getString("type"));
|
||||
JSONArray anyOf = definitions.getJSONObject("enum-vanilla-structure-or-prefix").getJSONArray("anyOf");
|
||||
Pattern prefix = null;
|
||||
for (int index = 0; index < anyOf.length(); index++) {
|
||||
if (anyOf.getJSONObject(index).has("pattern")) {
|
||||
prefix = Pattern.compile(anyOf.getJSONObject(index).getString("pattern"));
|
||||
}
|
||||
}
|
||||
assertTrue("the prefix alternative is a pattern", prefix != null);
|
||||
assertTrue(prefix.matcher("minecraft:village").matches());
|
||||
assertTrue(prefix.matcher("nova_structures:").matches());
|
||||
assertTrue(prefix.matcher("towns_and_towers:exclusives/village_piglin").matches());
|
||||
assertFalse(prefix.matcher("village").matches());
|
||||
assertFalse(prefix.matcher("Nova Structures:tavern").matches());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -383,6 +420,11 @@ public class SchemaBuilderParityTest {
|
||||
throw new IllegalStateException("schema exposes no properties");
|
||||
}
|
||||
|
||||
/** The definition an API value type's reference leads to: the module's, which refers to Iris's own. */
|
||||
private static JSONObject irisDefinition(JSONObject definitions, JSONObject reference) {
|
||||
return definitions.getJSONObject(definitionKey(definitions.getJSONObject(definitionKey(reference))));
|
||||
}
|
||||
|
||||
private static String definitionKey(JSONObject reference) {
|
||||
return reference.getString("$ref").substring("#/definitions/".length());
|
||||
}
|
||||
@@ -669,6 +711,32 @@ public class SchemaBuilderParityTest {
|
||||
}
|
||||
}
|
||||
|
||||
/** The schema of {@code iris:structure}'s settings alone, without the module's stages. */
|
||||
private static PackSchema structureSettingsSchema() throws IOException {
|
||||
Path root = Files.createTempDirectory("structure-pack");
|
||||
try (LoadedPack pack = LoadedPack.load(Files.createDirectory(root.resolve("pack")),
|
||||
ModuleHost.of(List.of(new StructureSettingsModule())).copyingJarsTo(Files.createDirectory(root.resolve("copies"))))) {
|
||||
return pack.schema();
|
||||
}
|
||||
}
|
||||
|
||||
/** A module with {@code iris:structure}'s id whose only part is its settings. */
|
||||
public static final class StructureSettingsModule implements IrisModule {
|
||||
@Override
|
||||
public ModuleInfo info() {
|
||||
return ModuleInfo.of("iris:structure", "Structures", "1");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void install(StageGraph graph) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(FeatureRegistry registry) {
|
||||
registry.registerSettings(StructureSettings.class);
|
||||
}
|
||||
}
|
||||
|
||||
private static PackSchema tintModuleSchema() throws IOException {
|
||||
Path root = Files.createTempDirectory("tint-pack");
|
||||
try (LoadedPack pack = LoadedPack.load(Files.createDirectory(root.resolve("pack")),
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
package art.arcane.iris.core.project;
|
||||
|
||||
import art.arcane.iris.engine.object.structure.vanilla.IrisStructureSetFrequencyOverride;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.IrisImportedStructureControl;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.IrisVanillaStructureAdjustment;
|
||||
import art.arcane.iris.engine.object.annotations.ArrayType;
|
||||
import art.arcane.iris.engine.object.annotations.Desc;
|
||||
import art.arcane.iris.engine.object.annotations.RegistryListVanillaStructure;
|
||||
import art.arcane.iris.engine.object.annotations.RegistryListVanillaStructureSet;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.json.JSONArray;
|
||||
import art.arcane.volmlib.util.json.JSONObject;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* importedStructures.disabled and adjustments[].match accept family/namespace PREFIXES
|
||||
* ("minecraft:village", "nova_structures:") per IrisImportedStructureControl.matchesKey, so the
|
||||
* generated editor schema must not reject them with a strict registered-key enum. Prefix-capable
|
||||
* fields emit an anyOf of the registry enum plus a key/prefix pattern. Exact-key fields, including
|
||||
* importedStructures.disabledExact and nativeStructures[].structure, keep the strict enum.
|
||||
*/
|
||||
public class VanillaStructurePrefixSchemaTest {
|
||||
@Test
|
||||
public void prefixCapableFieldsDeclareThePrefixAnnotation() throws NoSuchFieldException {
|
||||
assertTrue(IrisImportedStructureControl.class.getDeclaredField("disabled")
|
||||
.getAnnotation(RegistryListVanillaStructure.class).prefixes());
|
||||
assertFalse(IrisImportedStructureControl.class.getDeclaredField("disabledExact")
|
||||
.getAnnotation(RegistryListVanillaStructure.class).prefixes());
|
||||
assertTrue(IrisVanillaStructureAdjustment.class.getDeclaredField("match")
|
||||
.getAnnotation(RegistryListVanillaStructure.class).prefixes());
|
||||
assertTrue(IrisStructureSetFrequencyOverride.class.getDeclaredField("structureSet")
|
||||
.isAnnotationPresent(RegistryListVanillaStructureSet.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void prefixListSchemaAcceptsFamilyAndNamespacePrefixes() {
|
||||
JSONObject schema = new SchemaBuilder(PrefixModel.class, null).construct();
|
||||
JSONObject items = schema.getJSONObject("properties").getJSONObject("disabled")
|
||||
.getJSONObject("items");
|
||||
String definitionKey = items.getString("$ref").substring("#/definitions/".length());
|
||||
JSONArray anyOf = schema.getJSONObject("definitions").getJSONObject(definitionKey)
|
||||
.getJSONArray("anyOf");
|
||||
|
||||
String pattern = null;
|
||||
for (int i = 0; i < anyOf.length(); i++) {
|
||||
JSONObject branch = anyOf.getJSONObject(i);
|
||||
if (branch.has("pattern")) {
|
||||
pattern = branch.getString("pattern");
|
||||
}
|
||||
}
|
||||
assertTrue("anyOf must contain a pattern branch for prefixes", pattern != null);
|
||||
|
||||
Pattern compiled = Pattern.compile(pattern);
|
||||
assertTrue(compiled.matcher("minecraft:village").matches());
|
||||
assertTrue(compiled.matcher("minecraft:pillager_outpost").matches());
|
||||
assertTrue(compiled.matcher("nova_structures:").matches());
|
||||
assertTrue(compiled.matcher("towns_and_towers:exclusives/village_piglin").matches());
|
||||
assertFalse(compiled.matcher("village").matches());
|
||||
assertFalse(compiled.matcher("Nova Structures:tavern").matches());
|
||||
}
|
||||
|
||||
@Desc("Schema model for prefix-capable vanilla structure lists.")
|
||||
public static class PrefixModel {
|
||||
@RegistryListVanillaStructure(prefixes = true)
|
||||
@ArrayType(type = String.class, min = 1)
|
||||
@Desc("Prefix-capable deny list.")
|
||||
private KList<String> disabled = new KList<>();
|
||||
}
|
||||
}
|
||||
+59
-17
@@ -1,14 +1,17 @@
|
||||
package art.arcane.iris.engine.framework;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.builtin.structure.StructureAdjustment;
|
||||
import art.arcane.iris.builtin.structure.StructureSettings;
|
||||
import art.arcane.iris.core.modules.BuiltInPack;
|
||||
import art.arcane.iris.core.modules.ModuleSettings;
|
||||
import art.arcane.iris.core.modules.IrisPackResources;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.IrisImportedStructureControl;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.IrisNativeStructure;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.IrisNativeStructureDecision;
|
||||
import art.arcane.iris.engine.object.world.region.IrisRegion;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructurePlacement;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructureTerrainMode;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.NativeStructureGenerationStatus;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.NativeStructureSuppression;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
@@ -17,7 +20,16 @@ import com.volmit.IrisModule;
|
||||
import com.volmit.ModuleInfo;
|
||||
import com.volmit.host.LoadedPack;
|
||||
import com.volmit.stage.StageGraph;
|
||||
import com.volmit.block.BlockSpec;
|
||||
import com.volmit.block.PaletteSpec;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.vanilla.StructureStilts;
|
||||
import com.volmit.vanilla.StructureTerrain;
|
||||
import com.volmit.vanilla.VanillaStructureAdjustment;
|
||||
import com.volmit.vanilla.VanillaStructureContext;
|
||||
import com.volmit.vanilla.VanillaStructureFit;
|
||||
import com.volmit.vanilla.VanillaStructureHook;
|
||||
import com.volmit.vanilla.YBand;
|
||||
import com.volmit.vanilla.VanillaStructureRule;
|
||||
import org.junit.After;
|
||||
import org.junit.Rule;
|
||||
@@ -50,7 +62,7 @@ public class NativeStructureGenerationPolicyTest {
|
||||
@Test
|
||||
public void generationStatusMessagesAreSharedAcrossPlatforms() {
|
||||
assertEquals(
|
||||
"Native structure minecraft:village_plains is disabled by this dimension's importedStructures settings or a module of the pack.",
|
||||
"Native structure minecraft:village_plains is disabled by this dimension's iris:structure settings or a module of the pack.",
|
||||
NativeStructureGenerationPolicy.generationStatusMessage(
|
||||
"minecraft:village_plains", NativeStructureGenerationStatus.DISABLED_BY_PACK));
|
||||
assertEquals(
|
||||
@@ -85,10 +97,9 @@ public class NativeStructureGenerationPolicyTest {
|
||||
|
||||
@Test
|
||||
public void exactDisabledKeyDoesNotDisableSiblingVariant() throws IOException {
|
||||
IrisImportedStructureControl control = new IrisImportedStructureControl();
|
||||
control.getDisabled().clear();
|
||||
control.getDisabledExact().add("minecraft:ruined_portal");
|
||||
Engine engine = engine(control, regionPlacement("nova_structures:tavern_oak"), new KList<>(), List.of());
|
||||
StructureSettings settings = new StructureSettings(List.of(), List.of("minecraft:ruined_portal"), 0, true,
|
||||
List.of(), List.of());
|
||||
Engine engine = engine(settings, regionPlacement("nova_structures:tavern_oak"), new KList<>(), List.of());
|
||||
|
||||
assertEquals(NativeStructureGenerationStatus.DISABLED_BY_PACK,
|
||||
NativeStructureGenerationPolicy.resolve(engine, "minecraft:ruined_portal", false).status());
|
||||
@@ -167,17 +178,47 @@ public class NativeStructureGenerationPolicyTest {
|
||||
"Module test:hook from host classpath failed deciding over vanilla structure minecraft:igloo: "));
|
||||
}
|
||||
|
||||
private Engine engineWithDisabledNamespaceAndRegionPlacement(String placedKey) throws IOException {
|
||||
IrisImportedStructureControl control = new IrisImportedStructureControl();
|
||||
control.getDisabled().add("nova_structures:");
|
||||
return engine(control, regionPlacement(placedKey), new KList<>(), List.of());
|
||||
@Test
|
||||
public void adjustmentsOfTheSettingsAndOfPackModulesReachTheDecisionAsIrisClasses() throws IOException {
|
||||
StructureTerrain bore = StructureTerrain.of(StructureTerrain.Mode.BORE).withPadding(6, 2, 1);
|
||||
StructureSettings settings = new StructureSettings(List.of(), List.of(), -32, true, List.of(), List.of(
|
||||
new StructureAdjustment(List.of("minecraft:stronghold"), 4, YBand.of(-20, -100), false, null, bore)));
|
||||
StructureStilts stilts = StructureStilts.of(PaletteSpec.of(List.of(BlockSpec.of("minecraft:stone_bricks")))).withSpacing(2);
|
||||
Engine engine = engine(settings, new KList<>(), new KList<>(), List.of(new HookModule(new VanillaStructureHook() {
|
||||
@Override
|
||||
public VanillaStructureRule rule(ResourceId structure, VanillaStructureContext context) {
|
||||
return VanillaStructureRule.GENERATE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VanillaStructureAdjustment adjustment(ResourceId structure, boolean underground, VanillaStructureContext context) {
|
||||
return VanillaStructureAdjustment.NONE.shifted(-1).keepingSourceY()
|
||||
.withFit(VanillaStructureFit.SOURCE.withStilts(stilts));
|
||||
}
|
||||
})));
|
||||
|
||||
IrisNativeStructureDecision stronghold = NativeStructureGenerationPolicy.resolve(engine, "minecraft:stronghold", true);
|
||||
|
||||
assertEquals(-29, stronghold.yShift());
|
||||
assertTrue(stronghold.preserveSourceY());
|
||||
assertEquals(-100, stronghold.yBand().resolvedMin());
|
||||
assertEquals(IrisStructureTerrainMode.BORE, stronghold.terrain().resolvedMode());
|
||||
assertEquals(6, stronghold.terrain().getHorizontalPadding());
|
||||
assertEquals(2, stronghold.stilt().getSpacing());
|
||||
assertEquals("minecraft:stone_bricks", stronghold.stilt().getPalette().getPalette().getFirst().getBlock());
|
||||
IrisNativeStructureDecision village = NativeStructureGenerationPolicy.resolve(engine, "minecraft:village_plains", false);
|
||||
assertEquals(-1, village.yShift());
|
||||
assertEquals(null, village.terrain());
|
||||
}
|
||||
|
||||
private static IrisImportedStructureControl allowingEverything() {
|
||||
IrisImportedStructureControl control = new IrisImportedStructureControl();
|
||||
control.getDisabled().clear();
|
||||
control.getDisabledExact().clear();
|
||||
return control;
|
||||
private Engine engineWithDisabledNamespaceAndRegionPlacement(String placedKey) throws IOException {
|
||||
StructureSettings settings = new StructureSettings(List.of("nova_structures:"), List.of(), 0, true,
|
||||
List.of(), List.of());
|
||||
return engine(settings, regionPlacement(placedKey), new KList<>(), List.of());
|
||||
}
|
||||
|
||||
private static StructureSettings allowingEverything() {
|
||||
return new StructureSettings();
|
||||
}
|
||||
|
||||
private static KList<IrisStructurePlacement> regionPlacement(String placedKey) {
|
||||
@@ -189,20 +230,21 @@ public class NativeStructureGenerationPolicyTest {
|
||||
}
|
||||
|
||||
/** An engine whose pack serves Iris's built-in modules and {@code packModules}, with the given structure placements. */
|
||||
private Engine engine(IrisImportedStructureControl control, KList<IrisStructurePlacement> regionPlacements,
|
||||
private Engine engine(StructureSettings settings, KList<IrisStructurePlacement> regionPlacements,
|
||||
KList<IrisStructurePlacement> dimensionPlacements, List<IrisModule> packModules) throws IOException {
|
||||
IrisData data = mock(IrisData.class);
|
||||
Engine engine = mock(Engine.class);
|
||||
IrisDimension dimension = mock(IrisDimension.class);
|
||||
IrisRegion region = mock(IrisRegion.class);
|
||||
when(region.getStructures()).thenReturn(regionPlacements);
|
||||
when(region.getModuleSettings()).thenReturn(ModuleSettings.NONE);
|
||||
KList<IrisRegion> regions = new KList<>();
|
||||
regions.add(region);
|
||||
|
||||
packs.add(BuiltInPack.serveWithResources(data, folder, packModules));
|
||||
when(engine.getData()).thenReturn(data);
|
||||
when(engine.getDimension()).thenReturn(dimension);
|
||||
when(dimension.getImportedStructures()).thenReturn(control);
|
||||
when(dimension.getModuleSettings()).thenReturn(BuiltInPack.settings(settings));
|
||||
when(dimension.getStructures()).thenReturn(dimensionPlacements);
|
||||
when(dimension.getAllRegions(engine)).thenReturn(regions);
|
||||
when(dimension.getReachableBiomes(engine)).thenReturn(new KList<>());
|
||||
|
||||
@@ -0,0 +1,204 @@
|
||||
package art.arcane.iris.engine.framework;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.modules.BuiltInPack;
|
||||
import art.arcane.iris.core.modules.ModuleSettings;
|
||||
import art.arcane.iris.engine.object.material.IrisMaterialPalette;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructureCarveShape;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructurePlacement;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructureStiltSettings;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructureTerrain;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructureTerrainMode;
|
||||
import art.arcane.iris.engine.object.structure.StructureDistribution;
|
||||
import art.arcane.iris.engine.object.structure.jigsaw.IrisJigsawConfiguration;
|
||||
import art.arcane.iris.engine.object.structure.jigsaw.IrisJigsawHeightmap;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.IrisNativeStructure;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import com.google.gson.Gson;
|
||||
import com.volmit.host.LoadedPack;
|
||||
import org.junit.After;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
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.
|
||||
*/
|
||||
public class NativeStructureStartsTest {
|
||||
private static final long SEED = 1337L;
|
||||
private static final int MIN_HEIGHT = -64;
|
||||
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. */
|
||||
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");
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder folder = new TemporaryFolder();
|
||||
|
||||
private final List<LoadedPack> packs = new ArrayList<>();
|
||||
|
||||
@After
|
||||
public void closePacks() {
|
||||
packs.forEach(LoadedPack::close);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startsMatchThePlannersForAFixedSeed() throws IOException {
|
||||
KList<IrisStructurePlacement> placements = new KList<>();
|
||||
placements.add(placement("villages", false, -64, 320, 0.2D, source("minecraft:village_plains", 3),
|
||||
source("minecraft:pillager_outpost", 1)));
|
||||
placements.add(placement("cities", true, -50, -10, 0.15D, source("minecraft:ancient_city", 1)));
|
||||
placements.add(placement("outposts", false, -64, 320, 0.2D, source("minecraft:pillager_outpost", 1)));
|
||||
Engine engine = engine(placements);
|
||||
|
||||
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)) {
|
||||
starts.add(plan.chunkX() + " " + plan.chunkZ() + " " + plan.structureKey() + " " + plan.baseY() + " "
|
||||
+ placementId(placements, plan.placementIdentity()) + " " + plan.placementIdentity());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals(PLANNER_STARTS, starts);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fitsAndJigsawOverridesReachThePlatformWithTheirJsonUnchanged() throws IOException {
|
||||
IrisStructureTerrain terrain = new IrisStructureTerrain().setMode(IrisStructureTerrainMode.FORCE_CARVE)
|
||||
.setShape(IrisStructureCarveShape.ERODED).setHorizontalPadding(12).setErosionStrength(0.4D)
|
||||
.setEncasePalette(new IrisMaterialPalette().qclear().qadd("minecraft:deepslate").qadd("minecraft:tuff"));
|
||||
IrisStructureStiltSettings stilt = new IrisStructureStiltSettings().setMaxDepth(40).setSpacing(2)
|
||||
.setPalette(new IrisMaterialPalette().qclear().qadd("minecraft:stone_bricks"));
|
||||
IrisJigsawConfiguration jigsaw = new IrisJigsawConfiguration().setStartPool("minecraft:village/plains/town_centers")
|
||||
.setMaxDepth(5).setProjectStartToHeightmap(IrisJigsawHeightmap.OCEAN_FLOOR_WG).setUseExpansionHack(false);
|
||||
IrisStructurePlacement fitted = placement("fitted", true, -40, -20, 1D, source("minecraft:ancient_city", 1)
|
||||
.setJigsaw(jigsaw)).setTerrain(terrain).setStilt(stilt);
|
||||
KList<IrisStructurePlacement> placements = new KList<>();
|
||||
placements.add(fitted);
|
||||
Engine engine = engine(placements);
|
||||
|
||||
NativeStructureStartPlan plan = NativeStructureStarts.matchingPlan(engine, "MINECRAFT:ANCIENT_CITY", 0, 0);
|
||||
|
||||
assertEquals(GSON.toJson(terrain), GSON.toJson(plan.terrain()));
|
||||
assertEquals(GSON.toJson(stilt), GSON.toJson(plan.stilt()));
|
||||
assertEquals(GSON.toJson(jigsaw), GSON.toJson(plan.jigsaw()));
|
||||
assertEquals(GSON.toJson(new NativeStructureStartPlan(plan.structureKey(), 0, 0, plan.baseY(), true, false,
|
||||
StructurePlacementGrid.placementIdentity(fitted), jigsaw, stilt, terrain).decision()), GSON.toJson(plan.decision()));
|
||||
assertNull(NativeStructureStarts.matchingPlan(engine, "minecraft:stronghold", 0, 0));
|
||||
}
|
||||
|
||||
private static IrisNativeStructure source(String structure, int weight) {
|
||||
return new IrisNativeStructure().setStructure(structure).setWeight(weight);
|
||||
}
|
||||
|
||||
private static IrisStructurePlacement placement(String id, boolean underground, int minHeight, int maxHeight, double density,
|
||||
IrisNativeStructure... sources) {
|
||||
IrisStructurePlacement placement = new IrisStructurePlacement().setPlacementId(id)
|
||||
.setDistribution(StructureDistribution.DENSITY).setDensity(density)
|
||||
.setUnderground(underground).setMinHeight(minHeight).setMaxHeight(maxHeight);
|
||||
for (IrisNativeStructure source : sources) {
|
||||
placement.getNativeStructures().add(source);
|
||||
}
|
||||
return placement;
|
||||
}
|
||||
|
||||
private static String placementId(KList<IrisStructurePlacement> placements, long identity) {
|
||||
return placements.stream().filter(placement -> StructurePlacementGrid.placementIdentity(placement) == identity)
|
||||
.findFirst().orElseThrow().getPlacementId();
|
||||
}
|
||||
|
||||
/** An engine whose pack serves the built-in modules, with terrain heights that vary per column and a high sea. */
|
||||
private Engine engine(KList<IrisStructurePlacement> placements) throws IOException {
|
||||
IrisData data = mock(IrisData.class);
|
||||
Engine engine = mock(Engine.class);
|
||||
IrisDimension dimension = mock(IrisDimension.class);
|
||||
packs.add(BuiltInPack.serveWithResources(data, folder, List.of()));
|
||||
when(engine.getData()).thenReturn(data);
|
||||
when(engine.getGeneration()).thenReturn(new EngineGeneration(engine));
|
||||
when(engine.getSeedManager()).thenReturn(new SeedManager(SEED));
|
||||
when(engine.getMinHeight()).thenReturn(MIN_HEIGHT);
|
||||
when(engine.getHeight()).thenReturn(384);
|
||||
when(engine.getCacheID()).thenReturn(1);
|
||||
when(engine.getHeight(anyInt(), anyInt(), eq(true))).thenAnswer(call -> {
|
||||
int x = call.getArgument(0);
|
||||
int z = call.getArgument(1);
|
||||
return 100 + Math.floorMod(x * 7 + z * 13, 60);
|
||||
});
|
||||
when(engine.getDimension()).thenReturn(dimension);
|
||||
when(dimension.getFluidHeight()).thenReturn(127);
|
||||
when(dimension.getModuleSettings()).thenReturn(ModuleSettings.NONE);
|
||||
when(dimension.getStructures()).thenReturn(placements);
|
||||
when(dimension.getAllRegions(engine)).thenReturn(new KList<>());
|
||||
when(dimension.getReachableBiomes(engine)).thenReturn(new KList<>());
|
||||
return engine;
|
||||
}
|
||||
}
|
||||
+8
-17
@@ -1,12 +1,10 @@
|
||||
package art.arcane.iris.engine.framework;
|
||||
|
||||
import art.arcane.iris.builtin.structure.StructureSettings;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.modules.BuiltInPack;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.IrisImportedStructureControl;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.IrisNativeStructure;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructurePlacement;
|
||||
import art.arcane.iris.engine.object.structure.StructureDistribution;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructureTerrain;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import com.volmit.host.LoadedPack;
|
||||
import org.junit.After;
|
||||
@@ -57,29 +55,22 @@ public class NativeStructureVolumeSuppressionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void plannedIrisStartsContributeVolumesThroughTheirOwnDecision() {
|
||||
IrisStructurePlacement placement = new IrisStructurePlacement()
|
||||
.setDistribution(StructureDistribution.DENSITY)
|
||||
.setDensity(1D);
|
||||
placement.getNativeStructures().add(new IrisNativeStructure()
|
||||
.setStructure("minecraft:ancient_city")
|
||||
.setWeight(1));
|
||||
NativeStructureStartPlan plan = new NativeStructureStartPlan(
|
||||
placement, placement.getNativeStructures().getFirst(), 3, 5, -30);
|
||||
public void plannedModuleStartsContributeVolumesThroughTheirOwnDecision() {
|
||||
NativeStructureStartPlan plan = new NativeStructureStartPlan("minecraft:ancient_city", 3, 5, -30, true, false, 7L,
|
||||
null, null, new IrisStructureTerrain());
|
||||
|
||||
assertTrue(NativeStructurePlacementPlanner.decisionFor(plan).generate());
|
||||
assertTrue(plan.decision().generate());
|
||||
}
|
||||
|
||||
private Engine engine() throws IOException {
|
||||
IrisImportedStructureControl control = new IrisImportedStructureControl();
|
||||
control.getDisabled().add("minecraft:village");
|
||||
StructureSettings settings = new StructureSettings(List.of("minecraft:village"), List.of(), 0, true, List.of(), List.of());
|
||||
IrisDimension dimension = mock(IrisDimension.class);
|
||||
Engine engine = mock(Engine.class);
|
||||
IrisData data = mock(IrisData.class);
|
||||
packs.add(BuiltInPack.serveWithResources(data, folder, List.of()));
|
||||
when(engine.getData()).thenReturn(data);
|
||||
when(engine.getDimension()).thenReturn(dimension);
|
||||
when(dimension.getImportedStructures()).thenReturn(control);
|
||||
when(dimension.getModuleSettings()).thenReturn(BuiltInPack.settings(settings));
|
||||
when(dimension.getStructures()).thenReturn(new KList<>());
|
||||
when(dimension.getAllRegions(engine)).thenReturn(new KList<>());
|
||||
when(dimension.getReachableBiomes(engine)).thenReturn(new KList<>());
|
||||
|
||||
+166
@@ -0,0 +1,166 @@
|
||||
package art.arcane.iris.engine.framework.structure;
|
||||
|
||||
import art.arcane.iris.builtin.structure.StructureAdjustment;
|
||||
import art.arcane.iris.builtin.structure.StructureSetFrequency;
|
||||
import art.arcane.iris.builtin.structure.StructureSettings;
|
||||
import com.volmit.block.BlockSpec;
|
||||
import com.volmit.block.PaletteSpec;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.vanilla.StructureStilts;
|
||||
import com.volmit.vanilla.StructureTerrain;
|
||||
import com.volmit.vanilla.VanillaStructureAdjustment;
|
||||
import com.volmit.vanilla.YBand;
|
||||
import com.google.gson.Gson;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/** What a dimension's iris:structure settings say about the platform's own structures (was IrisImportedStructureControlTest). */
|
||||
public class ImportedStructuresTest {
|
||||
private static final StructureStilts COBBLE = StructureStilts.of(PaletteSpec.of(List.of(BlockSpec.of("minecraft:cobblestone"))));
|
||||
|
||||
@Test
|
||||
public void defaultSettingsGenerateEveryStructureAndChangeNothing() {
|
||||
ImportedStructures defaults = imported(new StructureSettings());
|
||||
|
||||
assertFalse(defaults.disables("minecraft:village_plains"));
|
||||
assertFalse(defaults.disables("nova_structures:desert_temple"));
|
||||
assertEquals(VanillaStructureAdjustment.NONE, defaults.adjustment("minecraft:stronghold", true));
|
||||
assertEquals(1D, defaults.setup().frequency(ResourceId.parse("minecraft:villages")), 0D);
|
||||
assertFalse(defaults.setup().protectsVanillaDefinitions());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void disabledMatchesFamiliesAtResourceBoundariesAndWholeNamespaces() {
|
||||
ImportedStructures imported = imported(settings(List.of("minecraft:village", "example:", "", " "), List.of(), 0, true,
|
||||
List.of(), List.of()));
|
||||
|
||||
assertTrue(imported.disables("minecraft:village_plains"));
|
||||
assertTrue(imported.disables("minecraft:village_taiga"));
|
||||
assertTrue(imported.disables("example:castle"));
|
||||
assertFalse(imported.disables("minecraft:villager_outpost"));
|
||||
assertFalse(imported.disables("minecraft:stronghold"));
|
||||
assertFalse(imported.disables("other:castle"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void disabledExactComparesNormalizedCompleteKeysOnly() {
|
||||
ImportedStructures imported = imported(settings(List.of(), List.of(" MINECRAFT:RUINED_PORTAL "), 0, true,
|
||||
List.of(), List.of()));
|
||||
|
||||
assertTrue(imported.disables("minecraft:ruined_portal"));
|
||||
assertTrue(imported.disables(" MINECRAFT:RUINED_PORTAL "));
|
||||
assertFalse(imported.disables("minecraft:ruined_portal_nether"));
|
||||
assertFalse(imported.disables(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void datapackOverridesFalseProtectsDefinitionsWithoutDisablingAnyNamespace() {
|
||||
ImportedStructures imported = imported(settings(List.of("aquaculture:treasure_vault"), List.of(), 0, false,
|
||||
List.of(), List.of()));
|
||||
|
||||
assertTrue(imported.setup().protectsVanillaDefinitions());
|
||||
assertFalse(imported.disables("nova_structures:desert_temple"));
|
||||
assertFalse(imported.disables("minecraft:village_plains"));
|
||||
assertTrue(imported.disables("aquaculture:treasure_vault"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void frequencyOverridesUseTheNormalizedSetKeyAndTheLastEntry() {
|
||||
ImportedStructures imported = imported(settings(List.of(), List.of(), 0, true, List.of(
|
||||
new StructureSetFrequency("minecraft:nether_complexes", 1.05D),
|
||||
new StructureSetFrequency(" MINECRAFT:NETHER_COMPLEXES ", 1.1D),
|
||||
new StructureSetFrequency("no namespace", 3D)), List.of()));
|
||||
|
||||
assertEquals(1.1D, imported.setup().frequency(ResourceId.parse("minecraft:nether_complexes")), 0D);
|
||||
assertEquals(1D, imported.setup().frequency(ResourceId.parse("minecraft:nether_fossils")), 0D);
|
||||
assertEquals(1, imported.setup().frequencies().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void undergroundShiftAppliesOnlyToUndergroundStepsAndMatchingShiftsStack() {
|
||||
ImportedStructures imported = imported(settings(List.of(), List.of(), 8, true, List.of(), List.of(
|
||||
adjustment(List.of("minecraft:trial"), -48, null, false, null, null),
|
||||
adjustment(List.of("minecraft:trial_chambers"), -16, null, false, null, null))));
|
||||
|
||||
assertEquals(-56, imported.adjustment("minecraft:trial_chambers", true).yShift());
|
||||
assertEquals(8, imported.adjustment("minecraft:stronghold", true).yShift());
|
||||
assertEquals(0, imported.adjustment("minecraft:village_plains", false).yShift());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theLastMatchingTerrainBandAndStiltWin() {
|
||||
StructureTerrain encase = StructureTerrain.of(StructureTerrain.Mode.ENCASE).withPadding(4, 0, 0);
|
||||
StructureStilts deep = COBBLE.withMaxDepth(96);
|
||||
ImportedStructures imported = imported(settings(List.of(), List.of(), 0, true, List.of(), List.of(
|
||||
adjustment(List.of("minecraft:stronghold"), 0, null, false, COBBLE.withMaxDepth(32),
|
||||
StructureTerrain.of(StructureTerrain.Mode.SOURCE)),
|
||||
adjustment(List.of("minecraft:stronghold"), 0, YBand.of(-120, -20), false, null, encase),
|
||||
adjustment(List.of("minecraft:stronghold"), 0, null, false, deep, null))));
|
||||
|
||||
VanillaStructureAdjustment stronghold = imported.adjustment("minecraft:stronghold", true);
|
||||
assertEquals(Optional.of(encase), stronghold.fit().terrain());
|
||||
assertEquals(Optional.of(deep), stronghold.fit().stilts());
|
||||
assertEquals(Optional.of(YBand.of(-120, -20)), stronghold.yBand());
|
||||
assertEquals(VanillaStructureAdjustment.NONE, imported.adjustment("minecraft:trial_chambers", true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aLaterSpecificAdjustmentOverridesANamespaceTerrain() {
|
||||
ImportedStructures imported = imported(settings(List.of(), List.of(), 0, true, List.of(), List.of(
|
||||
adjustment(List.of("towns_and_towers:"), 0, null, false, null, StructureTerrain.of(StructureTerrain.Mode.VACUUM)),
|
||||
adjustment(List.of("towns_and_towers:village_ocean", "towns_and_towers:mimic_desert"), 0, null, false, null,
|
||||
StructureTerrain.of(StructureTerrain.Mode.PRESERVE)))));
|
||||
|
||||
assertEquals(StructureTerrain.Mode.VACUUM, mode(imported, "towns_and_towers:village_forest"));
|
||||
assertEquals(StructureTerrain.Mode.PRESERVE, mode(imported, "towns_and_towers:village_ocean"));
|
||||
assertEquals(StructureTerrain.Mode.PRESERVE, mode(imported, "towns_and_towers:mimic_desert"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void preserveSourceYMatchesTheFamilyAndKeepsTheShifts() {
|
||||
ImportedStructures imported = imported(settings(List.of(), List.of(), -64, true, List.of(), List.of(
|
||||
adjustment(List.of("minecraft:mineshaft"), 4, null, true, null, null))));
|
||||
|
||||
VanillaStructureAdjustment mesa = imported.adjustment("minecraft:mineshaft_mesa", true);
|
||||
assertTrue(mesa.keepsSourceY());
|
||||
assertEquals(-60, mesa.yShift());
|
||||
assertFalse(imported.adjustment("minecraft:stronghold", true).keepsSourceY());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullListsInThePacksJsonReadAsEmpty() {
|
||||
StructureSettings nulls = new Gson().fromJson(
|
||||
"{\"disabled\": null, \"disabledExact\": null, \"adjustments\": null, \"frequencyOverrides\": null}",
|
||||
StructureSettings.class);
|
||||
ImportedStructures imported = imported(nulls);
|
||||
|
||||
assertFalse(imported.disables("minecraft:monument"));
|
||||
assertEquals(VanillaStructureAdjustment.NONE, imported.adjustment("minecraft:monument", false));
|
||||
assertTrue(imported.setup().frequencies().isEmpty());
|
||||
}
|
||||
|
||||
private static StructureTerrain.Mode mode(ImportedStructures imported, String key) {
|
||||
return imported.adjustment(key, false).fit().terrain().orElseThrow().mode();
|
||||
}
|
||||
|
||||
private static ImportedStructures imported(StructureSettings settings) {
|
||||
return new ImportedStructures(settings);
|
||||
}
|
||||
|
||||
private static StructureSettings settings(List<String> disabled, List<String> disabledExact, int undergroundYShift,
|
||||
boolean datapackOverrides, List<StructureSetFrequency> frequencies,
|
||||
List<StructureAdjustment> adjustments) {
|
||||
return new StructureSettings(disabled, disabledExact, undergroundYShift, datapackOverrides, frequencies, adjustments);
|
||||
}
|
||||
|
||||
private static StructureAdjustment adjustment(List<String> match, int yShift, YBand band, boolean preserveSourceY,
|
||||
StructureStilts stilt, StructureTerrain terrain) {
|
||||
return new StructureAdjustment(match, yShift, band, preserveSourceY, stilt, terrain);
|
||||
}
|
||||
}
|
||||
+51
-26
@@ -1,13 +1,24 @@
|
||||
package art.arcane.iris.engine.framework;
|
||||
package art.arcane.iris.engine.framework.structure;
|
||||
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.SeedManager;
|
||||
import art.arcane.iris.engine.framework.StructurePlacementGrid;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructureStiltSettings;
|
||||
import art.arcane.iris.engine.object.structure.jigsaw.IrisJigsawConfiguration;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.NativeStructureSuppression;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.vanilla.StructureTerrain;
|
||||
import com.volmit.vanilla.VanillaStructureStart;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.OptionalInt;
|
||||
|
||||
import art.arcane.iris.engine.object.structure.vanilla.IrisNativeStructure;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.IrisNativeStructureDecision;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructureAnchorMode;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructurePlacement;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructureTerrain;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructureTerrainMode;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.NativeStructureGenerationStatus;
|
||||
import art.arcane.iris.engine.object.structure.StructureDistribution;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
@@ -22,7 +33,8 @@ import static org.junit.Assert.fail;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class NativeStructurePlacementPlannerTest {
|
||||
/** Where the pack's nativeStructures placements start platform structures (was the core planner's test). */
|
||||
public class NativeStartPlannerTest {
|
||||
@Test
|
||||
public void undergroundPlanIsDeterministicAndUsesConfiguredBand() {
|
||||
Engine engine = engine(982374L, -64, 384, 90);
|
||||
@@ -31,8 +43,8 @@ public class NativeStructurePlacementPlannerTest {
|
||||
.setMinHeight(-45)
|
||||
.setMaxHeight(-20);
|
||||
|
||||
NativeStructureStartPlan first = NativeStructurePlacementPlanner.planAt(engine, placement, 12, -7);
|
||||
NativeStructureStartPlan second = NativeStructurePlacementPlanner.planAt(engine, placement, 12, -7);
|
||||
NativeStartPlanner.Plan first = NativeStartPlanner.planAt(engine, placement, 12, -7);
|
||||
NativeStartPlanner.Plan second = NativeStartPlanner.planAt(engine, placement, 12, -7);
|
||||
|
||||
assertNotNull(first);
|
||||
assertEquals(first, second);
|
||||
@@ -50,7 +62,7 @@ public class NativeStructurePlacementPlannerTest {
|
||||
.setMinHeight(500)
|
||||
.setMaxHeight(600);
|
||||
|
||||
assertNull(NativeStructurePlacementPlanner.planAt(engine, placement, 12, -7));
|
||||
assertNull(NativeStartPlanner.planAt(engine, placement, 12, -7));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -60,30 +72,43 @@ public class NativeStructurePlacementPlannerTest {
|
||||
.setMinHeight(80)
|
||||
.setMaxHeight(90);
|
||||
|
||||
NativeStructureStartPlan plan = NativeStructurePlacementPlanner.planAt(engine, placement, 0, 0);
|
||||
NativeStartPlanner.Plan plan = NativeStartPlanner.planAt(engine, placement, 0, 0);
|
||||
|
||||
assertNotNull(plan);
|
||||
assertEquals(86, plan.baseY());
|
||||
|
||||
placement.setMinHeight(87);
|
||||
assertNull(NativeStructurePlacementPlanner.planAt(engine, placement, 0, 0));
|
||||
assertNull(NativeStartPlanner.planAt(engine, placement, 0, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void configuredDecisionOverridesSuppressedSourceWithoutLosingTerrain() {
|
||||
public void aPlanBecomesAStartWithHeightsAboveTheBottomAndThePlacementsFitAndIdentity() {
|
||||
IrisStructureTerrain terrain = new IrisStructureTerrain()
|
||||
.setMode(IrisStructureTerrainMode.FORCE_CARVE)
|
||||
.setHorizontalPadding(24);
|
||||
IrisStructurePlacement placement = nativePlacement()
|
||||
.setUnderground(true)
|
||||
.setTerrain(terrain);
|
||||
NativeStructureStartPlan plan = new NativeStructureStartPlan(
|
||||
.setNativeSuppression(NativeStructureSuppression.REPLACE_SOURCE)
|
||||
.setTerrain(terrain)
|
||||
.setStilt(new IrisStructureStiltSettings().setSpacing(3));
|
||||
placement.getNativeStructures().getFirst().setJigsaw(new IrisJigsawConfiguration().setMaxDepth(4));
|
||||
NativeStartPlanner.Plan plan = new NativeStartPlanner.Plan(
|
||||
placement, placement.getNativeStructures().getFirst(), 3, 5, -30);
|
||||
|
||||
IrisNativeStructureDecision decision = NativeStructurePlacementPlanner.decisionFor(plan);
|
||||
VanillaStructureStart start = StructureVanillaHook.start(plan, -64);
|
||||
|
||||
assertEquals(NativeStructureGenerationStatus.GENERATE_NATIVE, decision.status());
|
||||
assertSame(terrain, decision.terrain());
|
||||
assertEquals(ResourceId.parse("minecraft:ancient_city"), start.structure());
|
||||
assertEquals(34, start.y());
|
||||
assertTrue(start.isUnderground());
|
||||
assertTrue(start.replacesPlatformStart());
|
||||
assertEquals(StructurePlacementGrid.placementIdentity(placement), start.identity());
|
||||
assertEquals(StructureTerrain.Mode.FORCE_CARVE, start.fit().terrain().orElseThrow().mode());
|
||||
assertEquals(24, start.fit().terrain().orElseThrow().horizontalPadding());
|
||||
assertEquals(3, start.fit().stilts().orElseThrow().spacing());
|
||||
assertEquals(OptionalInt.of(4), start.jigsaw().orElseThrow().maxDepth());
|
||||
assertEquals("a source without jigsaw overrides has none", Optional.empty(),
|
||||
StructureVanillaHook.start(new NativeStartPlanner.Plan(nativePlacement(),
|
||||
nativePlacement().getNativeStructures().getFirst(), 0, 0, 70), -64).jigsaw());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -91,13 +116,13 @@ public class NativeStructurePlacementPlannerTest {
|
||||
Engine engine = engine(77L, -64, 384, 63);
|
||||
IrisStructurePlacement placement = nativePlacement();
|
||||
|
||||
assertNull(NativeStructurePlacementPlanner.planAt(engine, placement, 0, 0));
|
||||
assertNull(NativeStartPlanner.planAt(engine, placement, 0, 0));
|
||||
|
||||
placement.setUnderground(true).setMinHeight(-40).setMaxHeight(-20);
|
||||
assertNull(NativeStructurePlacementPlanner.planAt(engine, placement, 0, 0));
|
||||
assertNull(NativeStartPlanner.planAt(engine, placement, 0, 0));
|
||||
|
||||
placement.setUnderwater(true);
|
||||
assertNotNull(NativeStructurePlacementPlanner.planAt(engine, placement, 0, 0));
|
||||
assertNotNull(NativeStartPlanner.planAt(engine, placement, 0, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -105,11 +130,11 @@ public class NativeStructurePlacementPlannerTest {
|
||||
Engine engine = engine(77L, -64, 384, 64);
|
||||
IrisStructurePlacement placement = nativePlacement();
|
||||
|
||||
assertTrue(!NativeStructurePlacementPlanner.isSubmerged(engine, 8, 8));
|
||||
assertNotNull(NativeStructurePlacementPlanner.planAt(engine, placement, 0, 0));
|
||||
assertTrue(!NativeStartPlanner.isSubmerged(engine, 8, 8));
|
||||
assertNotNull(NativeStartPlanner.planAt(engine, placement, 0, 0));
|
||||
|
||||
placement.setUnderground(true).setMinHeight(-40).setMaxHeight(-20);
|
||||
assertNotNull(NativeStructurePlacementPlanner.planAt(engine, placement, 0, 0));
|
||||
assertNotNull(NativeStartPlanner.planAt(engine, placement, 0, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -119,7 +144,7 @@ public class NativeStructurePlacementPlannerTest {
|
||||
IrisStructurePlacement second = nativePlacement().setPlacementId("second");
|
||||
bindPlacements(engine, first, second);
|
||||
|
||||
KList<NativeStructureStartPlan> plans = NativeStructurePlacementPlanner.plansAt(engine, 0, 0);
|
||||
List<NativeStartPlanner.Plan> plans = NativeStartPlanner.plansAt(engine, 0, 0);
|
||||
|
||||
IrisStructurePlacement expected = Long.compareUnsigned(
|
||||
StructurePlacementGrid.placementIdentity(first),
|
||||
@@ -143,9 +168,9 @@ public class NativeStructurePlacementPlannerTest {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
assertEquals("test:a", NativeStructurePlacementPlanner
|
||||
assertEquals("test:a", NativeStartPlanner
|
||||
.selectSource(first, selectsFirstWeightSlot).getStructure());
|
||||
assertEquals("test:b", NativeStructurePlacementPlanner
|
||||
assertEquals("test:b", NativeStartPlanner
|
||||
.selectSource(reordered, selectsFirstWeightSlot).getStructure());
|
||||
}
|
||||
|
||||
@@ -201,7 +226,7 @@ public class NativeStructurePlacementPlannerTest {
|
||||
|
||||
private void assertInvalid(IrisStructurePlacement placement) {
|
||||
try {
|
||||
NativeStructurePlacementPlanner.validateBackend(placement);
|
||||
NativeStartPlanner.validateBackend(placement);
|
||||
fail("Expected an invalid structure backend");
|
||||
} catch (IllegalStateException expected) {
|
||||
assertTrue(expected.getMessage().contains("exactly one backend"));
|
||||
@@ -210,7 +235,7 @@ public class NativeStructurePlacementPlannerTest {
|
||||
|
||||
private void assertUnsupportedAnchor(IrisStructurePlacement placement) {
|
||||
try {
|
||||
NativeStructurePlacementPlanner.validateBackend(placement);
|
||||
NativeStartPlanner.validateBackend(placement);
|
||||
fail("Expected native structure anchor rejection");
|
||||
} catch (IllegalStateException expected) {
|
||||
assertTrue(expected.getMessage().contains("do not support the Iris anchor field"));
|
||||
-379
@@ -1,379 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.object.structure.vanilla;
|
||||
|
||||
import art.arcane.iris.engine.object.structure.IrisStructureStiltSettings;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructureTerrain;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructureTerrainMode;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructureYBand;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.IrisImportedStructureControl;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.IrisNativeStructureDecision;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.IrisStructureSetFrequencyOverride;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.IrisVanillaStructureAdjustment;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.NativeStructureGenerationStatus;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class IrisImportedStructureControlTest {
|
||||
private static KList<String> keys(String... values) {
|
||||
KList<String> list = new KList<>();
|
||||
for (String value : values) {
|
||||
list.add(value);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultPolicyGeneratesEveryRegisteredStructureKey() {
|
||||
IrisImportedStructureControl control = new IrisImportedStructureControl();
|
||||
assertTrue(control.shouldGenerate("minecraft:village_plains"));
|
||||
assertTrue(control.shouldGenerate("minecraft:stronghold"));
|
||||
assertTrue(control.shouldGenerate("minecraft:monument"));
|
||||
assertEquals(NativeStructureGenerationStatus.GENERATE_NATIVE,
|
||||
control.resolve("minecraft:monument", false).status());
|
||||
assertEquals(1D, control.frequencyMultiplier("minecraft:villages"), 0D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void frequencyOverrideUsesExactNormalizedSetKeyAndLastEntry() {
|
||||
KList<IrisStructureSetFrequencyOverride> overrides = new KList<>();
|
||||
overrides.add(new IrisStructureSetFrequencyOverride()
|
||||
.setStructureSet("minecraft:nether_complexes")
|
||||
.setMultiplier(1.05D));
|
||||
overrides.add(new IrisStructureSetFrequencyOverride()
|
||||
.setStructureSet(" MINECRAFT:NETHER_COMPLEXES ")
|
||||
.setMultiplier(1.1D));
|
||||
IrisImportedStructureControl control = new IrisImportedStructureControl()
|
||||
.setFrequencyOverrides(overrides);
|
||||
|
||||
assertTrue(control.hasFrequencyOverrides());
|
||||
assertEquals(1.1D, control.frequencyMultiplier("minecraft:nether_complexes"), 0D);
|
||||
assertEquals(1D, control.frequencyMultiplier("minecraft:nether_fossils"), 0D);
|
||||
assertEquals(1D, control.frequencyMultiplier("minecraft:nether_complexes_extra"), 0D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultPolicyGeneratesDatapackStructures() {
|
||||
IrisImportedStructureControl control = new IrisImportedStructureControl();
|
||||
assertTrue(control.isDatapackOverrides());
|
||||
assertTrue(control.shouldGenerate("nova_structures:desert_temple"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void disabledBlacklistMatchesExactKey() {
|
||||
IrisImportedStructureControl control = new IrisImportedStructureControl()
|
||||
.setDisabled(keys("minecraft:stronghold"));
|
||||
assertFalse(control.shouldGenerate("minecraft:stronghold"));
|
||||
assertTrue(control.shouldGenerate("minecraft:village_plains"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void disabledBlacklistMatchesNamespacePrefix() {
|
||||
IrisImportedStructureControl control = new IrisImportedStructureControl()
|
||||
.setDisabled(keys("minecraft:village"));
|
||||
assertFalse(control.shouldGenerate("minecraft:village_plains"));
|
||||
assertFalse(control.shouldGenerate("minecraft:village_taiga"));
|
||||
assertFalse(control.shouldGenerate("minecraft:village_snowy"));
|
||||
assertTrue(control.shouldGenerate("minecraft:stronghold"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exactBlacklistDoesNotExpandToStructureFamilies() {
|
||||
IrisImportedStructureControl control = new IrisImportedStructureControl()
|
||||
.setDisabledExact(keys(" MINECRAFT:RUINED_PORTAL "));
|
||||
|
||||
assertFalse(control.shouldGenerate("minecraft:ruined_portal"));
|
||||
assertEquals(NativeStructureGenerationStatus.DISABLED_BY_PACK,
|
||||
control.resolve(" MINECRAFT:RUINED_PORTAL ", false).status());
|
||||
assertTrue(control.shouldGenerate("minecraft:ruined_portal_nether"));
|
||||
assertEquals(NativeStructureGenerationStatus.GENERATE_NATIVE,
|
||||
control.resolve("minecraft:ruined_portal_nether", false).status());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void familyBlacklistRetainsPrefixMatchingBesideExactBlacklist() {
|
||||
IrisImportedStructureControl control = new IrisImportedStructureControl()
|
||||
.setDisabled(keys("minecraft:village"))
|
||||
.setDisabledExact(keys("minecraft:ruined_portal"));
|
||||
|
||||
assertFalse(control.shouldGenerate("minecraft:village_plains"));
|
||||
assertFalse(control.shouldGenerate("minecraft:ruined_portal"));
|
||||
assertTrue(control.shouldGenerate("minecraft:ruined_portal_nether"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void datapackOverridesFalseDoesNotDisableModOrDatapackNamespaces() {
|
||||
IrisImportedStructureControl control = new IrisImportedStructureControl()
|
||||
.setDatapackOverrides(false);
|
||||
assertTrue(control.shouldGenerate("nova_structures:desert_temple"));
|
||||
assertTrue(control.shouldGenerate("aquaculture:treasure_vault"));
|
||||
assertTrue(control.shouldGenerate("minecraft:village_plains"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void disabledListControlsThirdPartyStructuresWhenOverridesAreFalse() {
|
||||
IrisImportedStructureControl control = new IrisImportedStructureControl()
|
||||
.setDisabled(keys("aquaculture:treasure_vault"))
|
||||
.setDatapackOverrides(false);
|
||||
assertTrue(control.shouldGenerate("nova_structures:desert_temple"));
|
||||
assertTrue(control.shouldGenerate("minecraft:village_plains"));
|
||||
assertFalse(control.shouldGenerate("aquaculture:treasure_vault"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void datapackOverridesTrueAllowsDatapackKeysByDefault() {
|
||||
IrisImportedStructureControl control = new IrisImportedStructureControl()
|
||||
.setDatapackOverrides(true);
|
||||
assertTrue(control.shouldGenerate("nova_structures:desert_temple"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void keyWithoutNamespaceIsNotTreatedAsDatapack() {
|
||||
IrisImportedStructureControl control = new IrisImportedStructureControl()
|
||||
.setDatapackOverrides(false);
|
||||
assertTrue(control.shouldGenerate("village_plains"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void minecraftKeyIsNeverTreatedAsDatapack() {
|
||||
IrisImportedStructureControl control = new IrisImportedStructureControl()
|
||||
.setDatapackOverrides(false);
|
||||
assertTrue(control.shouldGenerate("minecraft:ancient_city"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptyOrNullListEntriesNeverMatchEveryKey() {
|
||||
IrisImportedStructureControl control = new IrisImportedStructureControl()
|
||||
.setDisabled(keys("", null));
|
||||
assertTrue(control.shouldGenerate("minecraft:village_plains"));
|
||||
assertTrue(control.shouldGenerate("minecraft:stronghold"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullKeyIsRejectedAsAnInvalidRegistryKey() {
|
||||
IrisImportedStructureControl control = new IrisImportedStructureControl();
|
||||
assertFalse(control.shouldGenerate(null));
|
||||
assertEquals(NativeStructureGenerationStatus.INVALID_REGISTRY_KEY,
|
||||
control.resolve(null, false).status());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verticalShiftDefaultsToZeroAndAppliesUndergroundBaseOnlyUnderground() {
|
||||
IrisImportedStructureControl control = new IrisImportedStructureControl().setUndergroundYShift(-32);
|
||||
|
||||
assertEquals(0, control.resolve("minecraft:village_plains", false).yShift());
|
||||
assertEquals(-32, control.resolve("minecraft:stronghold", true).yShift());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchingVerticalShiftsStackWithoutAffectingOtherStructures() {
|
||||
IrisVanillaStructureAdjustment broad = new IrisVanillaStructureAdjustment()
|
||||
.setMatch(keys("minecraft:trial"))
|
||||
.setYShift(-48);
|
||||
IrisVanillaStructureAdjustment exact = new IrisVanillaStructureAdjustment()
|
||||
.setMatch(keys("minecraft:trial_chambers"))
|
||||
.setYShift(-16);
|
||||
KList<IrisVanillaStructureAdjustment> adjustments = new KList<>();
|
||||
adjustments.add(broad);
|
||||
adjustments.add(exact);
|
||||
IrisImportedStructureControl control = new IrisImportedStructureControl()
|
||||
.setUndergroundYShift(8)
|
||||
.setAdjustments(adjustments);
|
||||
|
||||
assertEquals(-56, control.resolve("minecraft:trial_chambers", true).yShift());
|
||||
assertEquals(8, control.resolve("minecraft:stronghold", true).yShift());
|
||||
assertEquals(0, control.resolve("minecraft:village_plains", false).yShift());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postprocessingDefaultsAreDisabled() {
|
||||
IrisImportedStructureControl control = new IrisImportedStructureControl();
|
||||
assertNull(control.resolve("minecraft:village_plains", false).stilt());
|
||||
assertNull(control.resolve(null, false).stilt());
|
||||
assertFalse(control.resolve("minecraft:mineshaft_mesa", true).preserveSourceY());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unconfiguredTerrainAndBandStayUnsetSoNativeDefaultsCanApply() {
|
||||
IrisImportedStructureControl control = new IrisImportedStructureControl();
|
||||
|
||||
assertNull(control.resolve("minecraft:stronghold", true).terrain());
|
||||
assertNull(control.resolve("minecraft:stronghold", true).yBand());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipleMatchesUseTheLastConfiguredTerrainAndBand() {
|
||||
IrisStructureTerrain broadTerrain = new IrisStructureTerrain()
|
||||
.setMode(IrisStructureTerrainMode.SOURCE);
|
||||
IrisStructureTerrain exactTerrain = new IrisStructureTerrain()
|
||||
.setMode(IrisStructureTerrainMode.ENCASE)
|
||||
.setHorizontalPadding(4);
|
||||
IrisStructureYBand band = new IrisStructureYBand().setMin(-120).setMax(-20);
|
||||
IrisVanillaStructureAdjustment broad = new IrisVanillaStructureAdjustment()
|
||||
.setMatch(keys("minecraft:stronghold"))
|
||||
.setTerrain(broadTerrain);
|
||||
IrisVanillaStructureAdjustment exact = new IrisVanillaStructureAdjustment()
|
||||
.setMatch(keys("minecraft:stronghold"))
|
||||
.setTerrain(exactTerrain)
|
||||
.setYBand(band);
|
||||
KList<IrisVanillaStructureAdjustment> adjustments = new KList<>();
|
||||
adjustments.add(broad);
|
||||
adjustments.add(exact);
|
||||
IrisImportedStructureControl control = new IrisImportedStructureControl()
|
||||
.setAdjustments(adjustments);
|
||||
|
||||
IrisNativeStructureDecision stronghold = control.resolve("minecraft:stronghold", true);
|
||||
assertSame(exactTerrain, stronghold.terrain());
|
||||
assertSame(band, stronghold.yBand());
|
||||
assertNull(control.resolve("minecraft:trial_chambers", true).terrain());
|
||||
assertNull(control.resolve("minecraft:trial_chambers", true).yBand());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void namespaceVacuumCanPreserveSpecificStructuresLater() {
|
||||
IrisVanillaStructureAdjustment namespace = new IrisVanillaStructureAdjustment()
|
||||
.setMatch(keys("towns_and_towers:"))
|
||||
.setTerrain(new IrisStructureTerrain().setMode(IrisStructureTerrainMode.VACUUM));
|
||||
IrisVanillaStructureAdjustment preserveShips = new IrisVanillaStructureAdjustment()
|
||||
.setMatch(keys(
|
||||
"towns_and_towers:mimic_desert",
|
||||
"towns_and_towers:pillager_outpost_ocean",
|
||||
"towns_and_towers:village_ocean",
|
||||
"towns_and_towers:wreckage_ocean"))
|
||||
.setTerrain(new IrisStructureTerrain().setMode(IrisStructureTerrainMode.PRESERVE));
|
||||
KList<IrisVanillaStructureAdjustment> adjustments = new KList<>();
|
||||
adjustments.add(namespace);
|
||||
adjustments.add(preserveShips);
|
||||
IrisImportedStructureControl control = new IrisImportedStructureControl()
|
||||
.setAdjustments(adjustments);
|
||||
|
||||
assertEquals(IrisStructureTerrainMode.VACUUM,
|
||||
control.resolve("towns_and_towers:village_forest", false)
|
||||
.terrain().resolvedMode());
|
||||
assertEquals(IrisStructureTerrainMode.PRESERVE,
|
||||
control.resolve("towns_and_towers:village_ocean", false)
|
||||
.terrain().resolvedMode());
|
||||
assertEquals(IrisStructureTerrainMode.PRESERVE,
|
||||
control.resolve("towns_and_towers:mimic_desert", true)
|
||||
.terrain().resolvedMode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void preserveSourceYMatchesTheStructureFamilyAndKeepsExplicitShifts() {
|
||||
IrisVanillaStructureAdjustment adjustment = new IrisVanillaStructureAdjustment()
|
||||
.setMatch(keys("minecraft:mineshaft"))
|
||||
.setPreserveSourceY(true)
|
||||
.setYShift(4);
|
||||
IrisImportedStructureControl control = new IrisImportedStructureControl()
|
||||
.setUndergroundYShift(-64)
|
||||
.setAdjustments(new KList<IrisVanillaStructureAdjustment>().qadd(adjustment));
|
||||
|
||||
IrisNativeStructureDecision mesa = control.resolve("minecraft:mineshaft_mesa", true);
|
||||
assertTrue(mesa.preserveSourceY());
|
||||
assertEquals(-60, mesa.yShift());
|
||||
assertTrue(control.resolve("minecraft:mineshaft", true).preserveSourceY());
|
||||
assertFalse(control.resolve("minecraft:stronghold", true).preserveSourceY());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postprocessingUsesPrefixMatches() {
|
||||
IrisStructureStiltSettings stilt = new IrisStructureStiltSettings();
|
||||
IrisVanillaStructureAdjustment adjustment = new IrisVanillaStructureAdjustment()
|
||||
.setMatch(keys("minecraft:village"))
|
||||
.setStilt(stilt);
|
||||
IrisImportedStructureControl control = new IrisImportedStructureControl()
|
||||
.setAdjustments(new KList<IrisVanillaStructureAdjustment>().qadd(adjustment));
|
||||
|
||||
assertSame(stilt, control.resolve("minecraft:village_taiga", false).stilt());
|
||||
assertNull(control.resolve("minecraft:woodland_mansion", false).stilt());
|
||||
assertNull(control.resolve("minecraft:stronghold", true).stilt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipleMatchesUseTheLastConfiguredStilt() {
|
||||
IrisStructureStiltSettings broadStilt = new IrisStructureStiltSettings().setMaxDepth(32);
|
||||
IrisStructureStiltSettings specificStilt = new IrisStructureStiltSettings().setMaxDepth(96);
|
||||
IrisVanillaStructureAdjustment broad = new IrisVanillaStructureAdjustment()
|
||||
.setMatch(keys("minecraft:village"))
|
||||
.setStilt(broadStilt);
|
||||
IrisVanillaStructureAdjustment exactWithoutStilt = new IrisVanillaStructureAdjustment()
|
||||
.setMatch(keys("minecraft:village_plains"));
|
||||
IrisVanillaStructureAdjustment exactWithStilt = new IrisVanillaStructureAdjustment()
|
||||
.setMatch(keys("minecraft:village_plains"))
|
||||
.setStilt(specificStilt);
|
||||
KList<IrisVanillaStructureAdjustment> adjustments = new KList<>();
|
||||
adjustments.add(broad);
|
||||
adjustments.add(exactWithoutStilt);
|
||||
adjustments.add(exactWithStilt);
|
||||
IrisImportedStructureControl control = new IrisImportedStructureControl().setAdjustments(adjustments);
|
||||
|
||||
IrisNativeStructureDecision plains = control.resolve("minecraft:village_plains", false);
|
||||
assertSame(specificStilt, plains.stilt());
|
||||
assertEquals(96, plains.stilt().getMaxDepth());
|
||||
assertSame(broadStilt, control.resolve("minecraft:village_desert", false).stilt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void familyPrefixRequiresAResourceBoundary() {
|
||||
IrisImportedStructureControl control = new IrisImportedStructureControl()
|
||||
.setDisabled(keys("minecraft:village"));
|
||||
|
||||
assertFalse(control.shouldGenerate("minecraft:village_plains"));
|
||||
assertTrue(control.shouldGenerate("minecraft:villager_outpost"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void namespacePrefixMatchesEveryKeyInNamespace() {
|
||||
IrisImportedStructureControl control = new IrisImportedStructureControl()
|
||||
.setDisabled(keys("example:"));
|
||||
|
||||
assertFalse(control.shouldGenerate("example:castle"));
|
||||
assertTrue(control.shouldGenerate("other:castle"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void malformedNullPolicyListsFailWithTheirExactField() {
|
||||
IrisImportedStructureControl nullDisabled = new IrisImportedStructureControl().setDisabled(null);
|
||||
IrisImportedStructureControl nullDisabledExact = new IrisImportedStructureControl().setDisabledExact(null);
|
||||
IrisImportedStructureControl nullAdjustments = new IrisImportedStructureControl().setAdjustments(null);
|
||||
IrisImportedStructureControl nullFrequencyOverrides = new IrisImportedStructureControl()
|
||||
.setFrequencyOverrides(null);
|
||||
|
||||
NullPointerException disabled = assertThrows(NullPointerException.class,
|
||||
() -> nullDisabled.shouldGenerate("minecraft:monument"));
|
||||
NullPointerException disabledExact = assertThrows(NullPointerException.class,
|
||||
() -> nullDisabledExact.shouldGenerate("minecraft:monument"));
|
||||
NullPointerException adjustments = assertThrows(NullPointerException.class,
|
||||
() -> nullAdjustments.resolve("minecraft:monument", false));
|
||||
NullPointerException frequencyOverrides = assertThrows(NullPointerException.class,
|
||||
() -> nullFrequencyOverrides.frequencyMultiplier("minecraft:villages"));
|
||||
|
||||
assertTrue(disabled.getMessage().contains("importedStructures.disabled"));
|
||||
assertTrue(disabledExact.getMessage().contains("importedStructures.disabledExact"));
|
||||
assertTrue(adjustments.getMessage().contains("importedStructures.adjustments"));
|
||||
assertTrue(frequencyOverrides.getMessage().contains("importedStructures.frequencyOverrides"));
|
||||
}
|
||||
}
|
||||
+7
-9
@@ -1,5 +1,7 @@
|
||||
package art.arcane.iris.util.common.director.specialhandlers;
|
||||
|
||||
import art.arcane.iris.builtin.structure.StructureSettings;
|
||||
import art.arcane.iris.core.modules.BuiltInPack;
|
||||
import art.arcane.iris.engine.framework.structure.StructureResources;
|
||||
import art.arcane.iris.core.modules.ModuleResourceFixture;
|
||||
import art.arcane.iris.engine.mantle.components.StructureModule;
|
||||
@@ -10,7 +12,6 @@ import art.arcane.iris.engine.framework.IrisStructureLocator;
|
||||
import art.arcane.iris.engine.mantle.components.StructureModule;
|
||||
import art.arcane.iris.engine.framework.StructureReachability;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.IrisImportedStructureControl;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.IrisNativeStructure;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.IrisNativeStructureDecision;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructure;
|
||||
@@ -88,10 +89,8 @@ public class StructureHandlerTest {
|
||||
PlatformWorld platformWorld = mock(PlatformWorld.class);
|
||||
IrisPlatform platform = mock(IrisPlatform.class);
|
||||
PlatformStructureHooks hooks = mock(PlatformStructureHooks.class);
|
||||
IrisImportedStructureControl control = new IrisImportedStructureControl();
|
||||
control.getDisabled().add("pack:disabled");
|
||||
control.getDisabled().add("pack:replacement");
|
||||
control.getDisabled().add("pack:dormant_replacement");
|
||||
StructureSettings settings = new StructureSettings(List.of("pack:disabled", "pack:replacement", "pack:dormant_replacement"),
|
||||
List.of(), 0, true, List.of(), List.of());
|
||||
|
||||
KList<IrisStructurePlacement> placements = new KList<>();
|
||||
placements.add(nativePlacement("pack:replacement", StructureDistribution.RANDOM_SPREAD, 1.0));
|
||||
@@ -118,7 +117,7 @@ public class StructureHandlerTest {
|
||||
when(engine.getMinHeight()).thenReturn(-64);
|
||||
when(engine.getHeight()).thenReturn(384);
|
||||
when(world.platformWorld()).thenReturn(platformWorld);
|
||||
when(dimension.getImportedStructures()).thenReturn(control);
|
||||
when(dimension.getModuleSettings()).thenReturn(BuiltInPack.settings(settings));
|
||||
when(dimension.getStructures()).thenReturn(placements);
|
||||
when(dimension.getAllRegions(engine)).thenReturn(new KList<>());
|
||||
when(dimension.getReachableBiomes(engine)).thenReturn(new KList<>());
|
||||
@@ -168,8 +167,7 @@ public class StructureHandlerTest {
|
||||
PlatformWorld platformWorld = mock(PlatformWorld.class);
|
||||
IrisPlatform platform = mock(IrisPlatform.class);
|
||||
PlatformStructureHooks hooks = mock(PlatformStructureHooks.class);
|
||||
IrisImportedStructureControl control = new IrisImportedStructureControl();
|
||||
control.getDisabled().add("minecraft:replacement");
|
||||
StructureSettings settings = new StructureSettings(List.of("minecraft:replacement"), List.of(), 0, true, List.of(), List.of());
|
||||
|
||||
IrisStructure editable = new IrisStructure();
|
||||
editable.setLoadKey("iris:editable");
|
||||
@@ -192,7 +190,7 @@ public class StructureHandlerTest {
|
||||
when(engine.getMinHeight()).thenReturn(-64);
|
||||
when(engine.getHeight()).thenReturn(384);
|
||||
when(world.platformWorld()).thenReturn(platformWorld);
|
||||
when(dimension.getImportedStructures()).thenReturn(control);
|
||||
when(dimension.getModuleSettings()).thenReturn(BuiltInPack.settings(settings));
|
||||
when(dimension.getStructures()).thenReturn(placements);
|
||||
when(dimension.getAllRegions(engine)).thenReturn(new KList<>());
|
||||
when(dimension.getReachableBiomes(engine)).thenReturn(new KList<>());
|
||||
|
||||
Reference in new issue
Block a user