mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-30 01:34:04 +00:00
Host side of the vanilla structure hook's starts, adjustments and setup; the planner is gone
ModuleVanillaStructures asks every hook for rules and adjustments (per engine, structure and snapshot), starts per chunk (converted to NativeStructureStartPlan, refused outside the chunk asked for) and setup per dimension before a world exists (DimensionSettings: the dimension's settings without an engine). NativeStructureStartPlan carries the module's start as host types (structure key, chunk, world base Y, underground, replacesPlatformStart, identity, IrisJigsawConfiguration, stilt, terrain) and decision(); NativeStructureStarts replaces plansAt/matchingPlan. NativeStructureGenerationPolicy builds its decision from rule and adjustment only. NativeStructureFrequencies (host) replaces IrisImportedStructureControl in INMSBinding, Bukkit NMS, DatapackStructureScopeSVC and modded frequency overrides; DatapackIngestService asks setup for protecting vanilla definitions. IrisValues converts the fit value types to Iris's classes (same JSON). Studio: Reference.STRUCTURE_PREFIX/STRUCTURE_SET complete like Iris's prefix and structure set lists; the annotation branches they replace are gone. Validators read the iris:structure key. Messages name iris:structure instead of importedStructures. Tests: NativeStructureStartsTest pins the planner's starts for seed 1337 (52 starts) and the fit JSON; NativeStartPlannerTest (moved), ImportedStructuresTest (was IrisImportedStructureControlTest), StructureSettingsDecodingTest (migrated overworld JSON), policy, schema, validator, handler, Bukkit NMS and modded tests ported.
This commit is contained in:
1 parent
49b82f7c16
commit
23e07c3a5f
49 files changed
+1301
-1078
No files matched your search
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user