mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 16:54:04 +00:00
Core asks for native structure starts and locates through the structure services
ModuleServices gains placedStructures, placesStructure, startedStructures, startsStructure, canLocateStart and locateStart (a SEARCH_LIMIT_REACHED outcome instead of an exception); StructureHandler, the Bukkit and modded locate commands and suggestions, the native structure stages, NMS IrisChunkGenerator and NativeStructureLocatePersistence use them instead of IrisStructureLocator. StructureReachability keeps its keys per world; the hotloader no longer invalidates locator caches. StructureCaveAnchorResolverTest binds a platform itself (it relied on test order).
This commit is contained in:
1 parent
0cfcada4f2
commit
7d9fd3faa6
24 files changed
+385
-126
No files matched your search
@@ -24,6 +24,7 @@ import com.volmit.host.FeatureCatalog;
|
||||
import com.volmit.host.ServiceRegistration;
|
||||
import com.volmit.entity.EntitySpec;
|
||||
import com.volmit.item.ItemDrop;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.service.AmbientEffects;
|
||||
import com.volmit.service.BlockDrops;
|
||||
import com.volmit.service.CaveBiomes;
|
||||
@@ -34,6 +35,7 @@ import com.volmit.service.ObjectsAt;
|
||||
import com.volmit.service.SaplingGrowth;
|
||||
import com.volmit.service.StructureLocator;
|
||||
import com.volmit.service.VanillaFeatures;
|
||||
import com.volmit.service.VanillaStructures;
|
||||
import com.volmit.world.BlockPosition;
|
||||
import com.volmit.world.PackWorld;
|
||||
import java.util.ArrayList;
|
||||
@@ -42,6 +44,7 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
/**
|
||||
* What Iris core asks the pack's modules through their services ({@link com.volmit.service.Service}) instead of reading
|
||||
@@ -236,26 +239,90 @@ public final class ModuleServices {
|
||||
|
||||
/** Whether a module of the world can locate structure {@code key}, matched without regard to case. */
|
||||
public static boolean canLocateStructure(Engine engine, String key) {
|
||||
return structureLocatorOf(engine, key).isPresent();
|
||||
return structureLocatorOf(engine, key, StructureLocator::locatable).isPresent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Every key under which the world's modules find what they place, locatable or not: their own structures and the
|
||||
* platform structures they start or stand in for.
|
||||
*/
|
||||
public static Set<String> placedStructures(Engine engine) {
|
||||
Set<String> keys = new LinkedHashSet<>();
|
||||
for (Provider<StructureLocator> provider : providers(engine, StructureLocator.class)) {
|
||||
keys.addAll(provider.service().placed(provider.world()));
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
/** Whether a module of the world places structure {@code key}, located or not, matched without regard to case. */
|
||||
public static boolean placesStructure(Engine engine, String key) {
|
||||
return structureLocatorOf(engine, key, StructureLocator::placed).isPresent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches for the start of structure {@code key} nearest to {@code fromX}, {@code fromZ} with the first module that
|
||||
* can locate it, in the world's own coordinates; not found when none can.
|
||||
* places it, in the world's own coordinates; not found when none does.
|
||||
*/
|
||||
public static StructureSearch locateStructure(Engine engine, String key, int fromX, int fromZ, int maxRadiusChunks) {
|
||||
LocateResult result = structureLocatorOf(engine, key)
|
||||
LocateResult result = structureLocatorOf(engine, key, StructureLocator::placed)
|
||||
.map(provider -> provider.service().locate(provider.world(), key, fromX, fromZ, maxRadiusChunks))
|
||||
.orElse(LocateResult.NOT_FOUND);
|
||||
return StructureSearch.of(result, engine);
|
||||
}
|
||||
|
||||
/** The platform structures the world's modules start themselves, as lower-case registry keys. */
|
||||
public static Set<String> startedStructures(Engine engine) {
|
||||
return platformStructures(engine, VanillaStructures::startedStructures);
|
||||
}
|
||||
|
||||
/** Whether a module of the world starts the platform structure {@code key} itself. */
|
||||
public static boolean startsStructure(Engine engine, String key) {
|
||||
return key != null && startedStructures(engine).contains(normalized(key));
|
||||
}
|
||||
|
||||
/** Whether a module of the world can find the starts it makes of the platform structure {@code key}. */
|
||||
public static boolean canLocateStart(Engine engine, String key) {
|
||||
return key != null && platformStructures(engine, VanillaStructures::locatableStarts).contains(normalized(key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches ring by ring, up to {@code maxRings} rings, for the start the first module that can find them makes of the
|
||||
* platform structure {@code key} nearest to {@code fromX}, {@code fromZ}, trying only chunks {@code candidates}
|
||||
* accepts, in the world's own coordinates. A {@link StructureSearchLimitException} from {@code candidates} ends the
|
||||
* search as {@link StructureSearch.Outcome#SEARCH_LIMIT_REACHED}.
|
||||
*/
|
||||
public static StructureSearch locateStart(Engine engine, String key, int fromX, int fromZ, int maxRings,
|
||||
CandidateChunks candidates) {
|
||||
Optional<ResourceId> structure = registryId(key);
|
||||
if (structure.isEmpty()) {
|
||||
return StructureSearch.NOT_FOUND;
|
||||
}
|
||||
for (Provider<VanillaStructures> provider : providers(engine, VanillaStructures.class)) {
|
||||
if (!provider.service().locatableStarts(provider.world()).contains(structure.get())) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
return StructureSearch.of(provider.service().locateStart(provider.world(), structure.get(), fromX, fromZ,
|
||||
maxRings, candidates::accepts), engine);
|
||||
} catch (StructureSearchLimitException limit) {
|
||||
return StructureSearch.SEARCH_LIMIT_REACHED;
|
||||
}
|
||||
}
|
||||
return StructureSearch.NOT_FOUND;
|
||||
}
|
||||
|
||||
/** The chunks a search for a module's start of a platform structure may answer with. */
|
||||
@FunctionalInterface
|
||||
public interface CandidateChunks {
|
||||
boolean accepts(int chunkX, int chunkZ);
|
||||
}
|
||||
|
||||
/** How a structure search ended. A found start is at {@code x}, {@code y}, {@code z}: world coordinates, Y the world's own. */
|
||||
public record StructureSearch(Outcome outcome, int x, int y, int z) {
|
||||
public enum Outcome { FOUND, NOT_FOUND, SEARCH_LIMIT_REACHED }
|
||||
|
||||
private static final StructureSearch NOT_FOUND = new StructureSearch(Outcome.NOT_FOUND, 0, 0, 0);
|
||||
private static final StructureSearch SEARCH_LIMIT_REACHED = new StructureSearch(Outcome.SEARCH_LIMIT_REACHED, 0, 0, 0);
|
||||
public static final StructureSearch NOT_FOUND = new StructureSearch(Outcome.NOT_FOUND, 0, 0, 0);
|
||||
public static final StructureSearch SEARCH_LIMIT_REACHED = new StructureSearch(Outcome.SEARCH_LIMIT_REACHED, 0, 0, 0);
|
||||
|
||||
public boolean found() {
|
||||
return outcome == Outcome.FOUND;
|
||||
@@ -272,20 +339,41 @@ public final class ModuleServices {
|
||||
}
|
||||
}
|
||||
|
||||
/** The first provider, in the catalog's order, whose locatable structures hold {@code key}. */
|
||||
private static Optional<Provider<StructureLocator>> structureLocatorOf(Engine engine, String key) {
|
||||
/** The first provider, in the catalog's order, whose structures of the kind {@code keys} lists hold {@code key}. */
|
||||
private static Optional<Provider<StructureLocator>> structureLocatorOf(Engine engine, String key,
|
||||
BiFunction<StructureLocator, PackWorld, Set<String>> keys) {
|
||||
if (key == null || key.isBlank()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
String wanted = normalized(key);
|
||||
for (Provider<StructureLocator> provider : providers(engine, StructureLocator.class)) {
|
||||
if (provider.service().locatable(provider.world()).stream().map(ModuleServices::normalized).anyMatch(wanted::equals)) {
|
||||
if (keys.apply(provider.service(), provider.world()).stream().map(ModuleServices::normalized).anyMatch(wanted::equals)) {
|
||||
return Optional.of(provider);
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/** The platform structures every provider lists with {@code structures}, as lower-case registry keys. */
|
||||
private static Set<String> platformStructures(Engine engine, BiFunction<VanillaStructures, PackWorld, Set<ResourceId>> structures) {
|
||||
Set<String> keys = new LinkedHashSet<>();
|
||||
for (Provider<VanillaStructures> provider : providers(engine, VanillaStructures.class)) {
|
||||
structures.apply(provider.service(), provider.world()).forEach(id -> keys.add(id.toString()));
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
private static Optional<ResourceId> registryId(String key) {
|
||||
if (key == null || key.isBlank()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
try {
|
||||
return Optional.of(ResourceId.parse(normalized(key.trim())));
|
||||
} catch (IllegalArgumentException notAnId) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
private static String normalized(String key) {
|
||||
return key.toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Thrown by a host's {@link ModuleServices.CandidateChunks} to end a search for a module's start of a platform structure
|
||||
* when the host's own checks ran out of budget; {@link ModuleServices#locateStart} reports it as a reached search limit.
|
||||
*/
|
||||
public final class StructureSearchLimitException extends RuntimeException {
|
||||
public StructureSearchLimitException() {
|
||||
super(null, null, false, false);
|
||||
}
|
||||
}
|
||||
@@ -24,8 +24,6 @@ import art.arcane.iris.engine.EngineRuntime.BiomeMaxes;
|
||||
import art.arcane.iris.engine.EngineRuntimeBuilder.RuntimeAssembly;
|
||||
import art.arcane.iris.engine.IrisEngine.LifecycleState;
|
||||
import art.arcane.iris.engine.framework.EngineTarget;
|
||||
import art.arcane.iris.engine.framework.IrisStructureLocator;
|
||||
import art.arcane.iris.engine.framework.StructureReachability;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.spi.IrisServices;
|
||||
@@ -117,8 +115,6 @@ final class EngineHotloader {
|
||||
}
|
||||
engine.getPlatformHooks().validateDimensionHotload(engine, replacement);
|
||||
replacementData.registerEngine(engine);
|
||||
IrisStructureLocator.invalidate(engine);
|
||||
StructureReachability.invalidate(engine);
|
||||
EngineTarget replacementTarget = new EngineTarget(engine.getWorld(), replacement, replacementData);
|
||||
EngineRuntime nextRuntime = engine.runtimeBuilder.buildRuntime(replacementTarget);
|
||||
engine.runtimeBuilder.publishRuntime(nextRuntime, previousRuntime);
|
||||
@@ -151,8 +147,6 @@ final class EngineHotloader {
|
||||
e.addSuppressed(replacementDataFailure);
|
||||
}
|
||||
}
|
||||
IrisStructureLocator.invalidate(engine);
|
||||
StructureReachability.invalidate(engine);
|
||||
if (engine.lifecycleState != LifecycleState.FAILED) {
|
||||
Throwable rollbackFailure = runCleanup(null, engine.getMantle()::hotload);
|
||||
if (rollbackFailure == null) {
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* 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.framework;
|
||||
|
||||
import art.arcane.iris.engine.object.world.IrisWorld;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Determines which vanilla/datapack structures can ever generate in a world, using the same biome
|
||||
* gate vanilla applies: a structure is reachable when its biome filter intersects the set of vanilla
|
||||
* biomes the pack actually produces (its {@code possibleBiomes}). Structures whose required biomes are
|
||||
* never produced cannot generate and must not be scanned for by {@code /locate} or {@code /iris find}
|
||||
* (an unbounded scan for an absent biome is what stalls the server).
|
||||
*
|
||||
* <p>The reachable set is fixed per world: it is kept in the world's state, so a hotload's new world builds it again.
|
||||
* It is the platform's answer, so Iris core asks it, not a module.
|
||||
*/
|
||||
public final class StructureReachability {
|
||||
private StructureReachability() {
|
||||
}
|
||||
|
||||
public static Set<String> reachableKeys(Engine engine) {
|
||||
Engine activeEngine = Objects.requireNonNull(engine, "Structure reachability requires an engine");
|
||||
if (activeEngine.getData() == null) {
|
||||
throw new IllegalStateException("Structure reachability requires a bound pack data loader");
|
||||
}
|
||||
return activeEngine.getGeneration().state(ReachableKeys.class, ReachableKeys::of).keys();
|
||||
}
|
||||
|
||||
public static boolean isReachable(Engine engine, String structureKey) {
|
||||
String normalizedStructureKey = normalizeStructureKey(structureKey);
|
||||
return reachableKeys(engine).contains(normalizedStructureKey);
|
||||
}
|
||||
|
||||
private static Set<String> build(Engine engine) {
|
||||
IrisWorld world = engine.getWorld();
|
||||
if (world == null) {
|
||||
throw new IllegalStateException("Structure reachability requires a bound Iris world");
|
||||
}
|
||||
if (world.platformWorld() == null) {
|
||||
throw new IllegalStateException("Structure reachability requires a bound platform world");
|
||||
}
|
||||
Set<String> reachable = new LinkedHashSet<>();
|
||||
for (String key : IrisPlatforms.get().structureHooks().reachableStructureKeys(world.platformWorld())) {
|
||||
if (key == null || key.isBlank()) {
|
||||
throw new IllegalStateException("Platform structure reachability returned a blank registry key");
|
||||
}
|
||||
reachable.add(key.toLowerCase(Locale.ROOT));
|
||||
}
|
||||
return Collections.unmodifiableSet(reachable);
|
||||
}
|
||||
|
||||
/**
|
||||
* The vanilla biome keys (e.g. {@code minecraft:taiga}) from a structure's filter that the pack
|
||||
* does not produce. An empty list means the structure is reachable. Used by the structure verify
|
||||
* diagnostic to explain why a structure cannot generate.
|
||||
*/
|
||||
public static KList<String> missingBiomeKeys(Engine engine, String structureKey) {
|
||||
KList<String> missing = new KList<>();
|
||||
Engine activeEngine = Objects.requireNonNull(engine, "Structure biome diagnostics require an engine");
|
||||
String normalizedStructureKey = normalizeStructureKey(structureKey);
|
||||
IrisWorld world = activeEngine.getWorld();
|
||||
if (world == null) {
|
||||
throw new IllegalStateException("Structure biome diagnostics require a bound Iris world");
|
||||
}
|
||||
if (world.platformWorld() == null) {
|
||||
throw new IllegalStateException("Structure biome diagnostics require a bound platform world");
|
||||
}
|
||||
Set<String> possible = new LinkedHashSet<>();
|
||||
for (String key : IrisPlatforms.get().structureHooks().possibleBiomeKeys(world.platformWorld())) {
|
||||
if (key == null || key.isBlank()) {
|
||||
throw new IllegalStateException("Platform structure biome query returned a blank possible-biome key");
|
||||
}
|
||||
possible.add(key.toLowerCase(Locale.ROOT));
|
||||
}
|
||||
for (String biomeKey : IrisPlatforms.get().structureHooks().structureBiomeKeys(normalizedStructureKey)) {
|
||||
if (biomeKey == null || biomeKey.isBlank()) {
|
||||
throw new IllegalStateException("Platform structure biome query returned a blank required-biome key for "
|
||||
+ normalizedStructureKey);
|
||||
}
|
||||
if (!possible.contains(biomeKey.toLowerCase(Locale.ROOT))) {
|
||||
missing.add(biomeKey);
|
||||
}
|
||||
}
|
||||
return missing;
|
||||
}
|
||||
|
||||
/** The world's reachable structure keys, in lower case. */
|
||||
private record ReachableKeys(Set<String> keys) {
|
||||
static ReachableKeys of(Engine engine) {
|
||||
return new ReachableKeys(build(engine));
|
||||
}
|
||||
}
|
||||
|
||||
private static String normalizeStructureKey(String structureKey) {
|
||||
if (structureKey == null || structureKey.isBlank()) {
|
||||
throw new IllegalArgumentException("Registered structure key must not be blank");
|
||||
}
|
||||
return structureKey.trim().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
}
|
||||
+3
-4
@@ -20,7 +20,6 @@ package art.arcane.iris.util.common.director.specialhandlers;
|
||||
|
||||
import art.arcane.iris.core.modules.ModuleServices;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.IrisStructureLocator;
|
||||
import art.arcane.iris.engine.framework.NativeStructureGenerationPolicy;
|
||||
import art.arcane.iris.engine.framework.StructureReachability;
|
||||
import art.arcane.iris.engine.framework.NativeStructureGenerationStatus;
|
||||
@@ -62,7 +61,7 @@ public class StructureHandler implements DirectorParameterHandler<String> {
|
||||
String normalizedKey = normalizeKey(key);
|
||||
if (!normalizedKey.isEmpty()
|
||||
&& !registeredKeys.containsKey(normalizedKey)
|
||||
&& !IrisStructureLocator.hasNativePlacement(activeEngine, key)) {
|
||||
&& !ModuleServices.startsStructure(activeEngine, key)) {
|
||||
suggestions.putIfAbsent(normalizedKey, key.trim());
|
||||
}
|
||||
}
|
||||
@@ -116,9 +115,9 @@ public class StructureHandler implements DirectorParameterHandler<String> {
|
||||
private static boolean isEligibleRegisteredKey(Engine engine, String key, String normalizedKey,
|
||||
Set<String> reachableKeys, boolean nativeGenerationEnabled) {
|
||||
NativeStructureGenerationStatus status = NativeStructureGenerationPolicy.resolve(engine, key);
|
||||
boolean nativePlacement = IrisStructureLocator.hasNativePlacement(engine, key);
|
||||
boolean nativePlacement = ModuleServices.startsStructure(engine, key);
|
||||
boolean locatableNativePlacement = nativePlacement
|
||||
&& IrisStructureLocator.hasLocatableNativePlacement(engine, key);
|
||||
&& ModuleServices.canLocateStart(engine, key);
|
||||
boolean locatableEditableReplacement = !nativePlacement
|
||||
&& status == NativeStructureGenerationStatus.REPLACED_BY_IRIS
|
||||
&& ModuleServices.canLocateStructure(engine, key);
|
||||
|
||||
Reference in new issue
Block a user