mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-30 17:54:56 +00:00
Place and locate structures through the api instead of the engine
Structure placement, its locator, the cave anchor resolver and the native start planner now take the pack world and its running world, and StructurePlacing writes through the mantle stage context and the placement graph. Terrain carving draws its noise from the pack's noise factory. The api gains clearBlock/clearAttached on PlacementTerrain, RunningWorld.carvedAt and VanillaStructureContext.world; modules get the host's seed purposes through their world view.
This commit is contained in:
1 parent
5ab99210b2
commit
3d209b393c
47 files changed
+1957
-1127
No files matched your search
@@ -175,6 +175,10 @@ final class CarvedVoids implements MantleLayer<CarvedVoid> {
|
||||
}
|
||||
|
||||
private CarvedVoid toApi(MatterCavern cavern) {
|
||||
return toApi(cavern, ids);
|
||||
}
|
||||
|
||||
static CarvedVoid toApi(MatterCavern cavern, PackResourceIds ids) {
|
||||
CarvedVoid plain = switch (cavern.getLiquid()) {
|
||||
case LIQUID_FLUID -> CarvedVoid.FLUID;
|
||||
case LIQUID_LAVA -> CarvedVoid.LAVA;
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import com.volmit.ModuleLog;
|
||||
import com.volmit.block.BlockRegistry;
|
||||
import com.volmit.config.PackSettings;
|
||||
import com.volmit.host.ModuleLogs;
|
||||
import com.volmit.item.ItemRegistry;
|
||||
import com.volmit.noise.NoiseFactory;
|
||||
import com.volmit.object.PackObjects;
|
||||
import com.volmit.placement.Placements;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.resource.ResourceKind;
|
||||
import com.volmit.world.PackWorld;
|
||||
import com.volmit.world.RunningWorld;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* The world a fit has outside any world: a start fitted with its memo needs nothing of a world but the noise its
|
||||
* terrain carving draws on, which comes from plain styles. Everything else a fit could ask of a world fails, saying why.
|
||||
*/
|
||||
final class FitlessWorld implements PackWorld, PackResources {
|
||||
private static final String OUTSIDE_A_WORLD = "The built-in modules fit outside a world here: a start needs its memo"
|
||||
+ " and a fit without palettes";
|
||||
private static final ResourceId PACK = ResourceId.parse("iris:fitless");
|
||||
|
||||
private final UUID snapshot = UUID.randomUUID();
|
||||
private final NoiseFactory noise = IrisNoiseFactory.standalone();
|
||||
|
||||
@Override
|
||||
public long seed() {
|
||||
throw outsideAWorld();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackResources resources() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackSettings settings() {
|
||||
throw outsideAWorld();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int minWorldY() {
|
||||
throw outsideAWorld();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<RunningWorld> running() {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T state(Class<T> type, Function<? super PackWorld, ? extends T> create) {
|
||||
throw outsideAWorld();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Placements placements() {
|
||||
throw outsideAWorld();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModuleLog log() {
|
||||
return ModuleLogs.discarding();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <S> List<S> services(Class<S> service) {
|
||||
throw outsideAWorld();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceId packId() {
|
||||
return PACK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID snapshotId() {
|
||||
return snapshot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockRegistry blocks() {
|
||||
throw outsideAWorld();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemRegistry items() {
|
||||
throw outsideAWorld();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NoiseFactory noise() {
|
||||
return noise;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackObjects objects() {
|
||||
throw outsideAWorld();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Optional<T> find(ResourceKind<T> kind, ResourceId id) {
|
||||
throw outsideAWorld();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ResourceId> ids(ResourceKind<?> kind) {
|
||||
throw outsideAWorld();
|
||||
}
|
||||
|
||||
private static IllegalStateException outsideAWorld() {
|
||||
return new IllegalStateException(OUTSIDE_A_WORLD);
|
||||
}
|
||||
}
|
||||
@@ -49,6 +49,11 @@ final class IrisNoiseFactory implements NoiseFactory {
|
||||
this.resources = resources;
|
||||
}
|
||||
|
||||
/** Noise with no pack behind it: the plain styles, but no expressions and no image maps. */
|
||||
static IrisNoiseFactory standalone() {
|
||||
return new IrisNoiseFactory(null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NoiseSampler sampler(NoiseStyle style, long seed) {
|
||||
IrisGeneratorStyle iris = styles.computeIfAbsent(style, unbuilt -> IrisValues.generatorStyle(unbuilt, resources));
|
||||
|
||||
@@ -19,11 +19,13 @@
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.structure.StructureHost;
|
||||
import art.arcane.iris.builtin.structure.StructureSeeds;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import com.volmit.ModuleLog;
|
||||
import com.volmit.config.PackSettings;
|
||||
import com.volmit.host.WorldStates;
|
||||
import com.volmit.placement.Placements;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.world.PackWorld;
|
||||
import com.volmit.world.RunningWorld;
|
||||
import java.util.List;
|
||||
@@ -70,6 +72,14 @@ public final class IrisPackWorld implements PackWorld {
|
||||
return engine.getSeedManager().getSeed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long seed(ResourceId purpose) {
|
||||
if (StructureSeeds.PLACEMENT.equals(purpose)) {
|
||||
return engine.getSeedManager().getMantle();
|
||||
}
|
||||
return PackWorld.super.seed(purpose);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IrisPackResources resources() {
|
||||
@@ -78,7 +88,7 @@ public final class IrisPackWorld implements PackWorld {
|
||||
|
||||
@Override
|
||||
public int minWorldY() {
|
||||
return engine.getWorld().minHeight();
|
||||
return engine.getMinHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -24,11 +24,13 @@ import art.arcane.iris.spi.PlatformWorld;
|
||||
import art.arcane.iris.util.common.scheduling.J;
|
||||
import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
|
||||
import art.arcane.volmlib.util.matter.Matter;
|
||||
import art.arcane.volmlib.util.matter.MatterCavern;
|
||||
import art.arcane.volmlib.util.matter.slices.MarkerMatter;
|
||||
import com.volmit.ModuleLog;
|
||||
import com.volmit.config.FeatureSettings;
|
||||
import com.volmit.data.SavedKey;
|
||||
import com.volmit.geometry.BlockPosition;
|
||||
import com.volmit.mantle.CarvedVoid;
|
||||
import com.volmit.placement.PlacementRecord;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.world.RunningWorld;
|
||||
@@ -139,6 +141,12 @@ final class IrisRunningWorld implements RunningWorld {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<CarvedVoid> carvedAt(int worldX, int y, int worldZ) {
|
||||
MatterCavern cavern = engine.getMantle().getMantle().get(worldX, y, worldZ, MatterCavern.class);
|
||||
return Optional.ofNullable(cavern).map(carved -> CarvedVoids.toApi(carved, packIds()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean debug() {
|
||||
return engine.isStudio();
|
||||
|
||||
@@ -24,8 +24,8 @@ import art.arcane.iris.engine.framework.structure.StructureResources;
|
||||
import art.arcane.iris.engine.mantle.components.StructurePlacing;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructure;
|
||||
import com.volmit.ModuleLog;
|
||||
import com.volmit.generation.InvocationContext;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.stage.MantleStageContext;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@@ -41,9 +41,8 @@ final class IrisStructureHost implements StructureHost {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void placeChunk(InvocationContext context) {
|
||||
IrisMantleChunk chunk = context.extension(IrisMantleChunk.class).orElseThrow();
|
||||
placing().place(chunk.writer(), chunk.chunkX(), chunk.chunkZ(), chunk.context());
|
||||
public void placeChunk(MantleStageContext context) {
|
||||
placing().place(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -65,6 +64,6 @@ final class IrisStructureHost implements StructureHost {
|
||||
}
|
||||
|
||||
private StructurePlacing placing() {
|
||||
return engine.getGeneration().state(StructurePlacing.class, generating -> new StructurePlacing(generating, log));
|
||||
return engine.getGeneration().world().state(StructurePlacing.class, generating -> new StructurePlacing(generating, log));
|
||||
}
|
||||
}
|
||||
@@ -96,10 +96,8 @@ public final class ModuleStructureFitting implements NativeStructureFitting {
|
||||
public static NativeStructureFitting builtInModules() {
|
||||
ModuleRegistry registry = new ModuleRegistry();
|
||||
IrisModuleHost.builtInModules().forEach(module -> ModuleSetups.run(DiscoveredModule.builtIn(module), new StageGraphBuilder(), registry));
|
||||
return new ModuleStructureFitting(registry.freeze().registrations(VanillaStructures.class), () -> {
|
||||
throw new IllegalStateException("The built-in modules fit outside a world here: a start needs its memo"
|
||||
+ " and a fit without palettes");
|
||||
});
|
||||
FitlessWorld fitless = new FitlessWorld();
|
||||
return new ModuleStructureFitting(registry.freeze().registrations(VanillaStructures.class), () -> fitless);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -54,6 +54,7 @@ import java.util.OptionalInt;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* What the pack's modules want for the platform's own structures, asked through their {@link VanillaStructures}
|
||||
@@ -77,7 +78,8 @@ public final class ModuleVanillaStructures {
|
||||
private ModuleVanillaStructures(Engine engine, PackResources snapshot) {
|
||||
this.snapshot = snapshot;
|
||||
this.providers = providersOf(engine.getData());
|
||||
this.world = new World(snapshot, new IrisPackSettings(engine));
|
||||
this.world = new World(snapshot, new IrisPackSettings(engine),
|
||||
() -> Optional.of(engine.getGeneration().world()));
|
||||
}
|
||||
|
||||
/** The combined rule of the pack's modules for the platform structure {@code structureKey} in {@code engine}'s world. */
|
||||
@@ -139,7 +141,7 @@ public final class ModuleVanillaStructures {
|
||||
|
||||
/** 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));
|
||||
VanillaStructureContext context = new World(data.getPackResources(), new DimensionSettings(data, dimension), Optional::empty);
|
||||
VanillaStructureSetup combined = VanillaStructureSetup.UNCHANGED;
|
||||
for (ServiceRegistration registration : providersOf(data)) {
|
||||
combined = combined.and(ask(registration, "setting up the vanilla structures of dimension " + dimension.getLoadKey(),
|
||||
@@ -241,7 +243,12 @@ public final class ModuleVanillaStructures {
|
||||
}
|
||||
|
||||
/** The world the providers decide for: the engine's pack snapshot and the settings its dimension reaches. */
|
||||
private record World(PackResources resources, PackSettings settings) implements VanillaStructureContext {
|
||||
private record World(PackResources resources, PackSettings settings, Supplier<Optional<PackWorld>> worldSource)
|
||||
implements VanillaStructureContext {
|
||||
@Override
|
||||
public Optional<PackWorld> world() {
|
||||
return worldSource.get();
|
||||
}
|
||||
}
|
||||
|
||||
private record StartContext(PackWorld world, TerrainSampler terrain) implements VanillaStructureStartContext {
|
||||
|
||||
@@ -120,6 +120,19 @@ final class PlacerTerrain implements PlacementTerrain {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearBlock(int x, int y, int z) {
|
||||
placer.clearBlock(x, y, z);
|
||||
if (written != null) {
|
||||
written.remove(new BlockPosition(x, y, z));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearAttached(int x, int y, int z) {
|
||||
placer.clearAttached(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCarved(int x, int y, int z) {
|
||||
return placer.isCarved(x, y, z);
|
||||
|
||||
@@ -21,26 +21,28 @@ package art.arcane.iris.engine.framework;
|
||||
import art.arcane.iris.builtin.anchor.PlaceTrait;
|
||||
import art.arcane.iris.engine.framework.structure.ColumnHeights;
|
||||
import art.arcane.iris.engine.framework.structure.NativeStartPlanner;
|
||||
import art.arcane.iris.engine.framework.structure.StructureWorld;
|
||||
import art.arcane.iris.engine.framework.structure.assembly.AssembledPiece;
|
||||
import art.arcane.iris.engine.framework.structure.assembly.Assembly;
|
||||
import art.arcane.iris.engine.framework.structure.assembly.StructureAssembly;
|
||||
import art.arcane.iris.engine.framework.structure.assembly.StructureStamp;
|
||||
import art.arcane.iris.engine.framework.structure.assembly.Viability;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.builtin.structure.NativeStructureSource;
|
||||
import art.arcane.iris.engine.object.world.region.IrisRegion;
|
||||
import art.arcane.iris.builtin.structure.StructureAnchorMode;
|
||||
import art.arcane.iris.builtin.structure.StructureCarveShape;
|
||||
import art.arcane.iris.builtin.structure.StructurePlacement;
|
||||
import art.arcane.iris.builtin.structure.StructurePlacementSettings;
|
||||
import art.arcane.iris.builtin.structure.StructureTerrain;
|
||||
import art.arcane.iris.builtin.structure.StructureTerrainMode;
|
||||
import art.arcane.iris.builtin.structure.NativeStructureSuppression;
|
||||
import art.arcane.iris.builtin.structure.StructureDistribution;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.config.Level;
|
||||
import com.volmit.geometry.BlockPosition;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.world.PackWorld;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -86,139 +88,139 @@ public final class IrisStructureLocator {
|
||||
}
|
||||
|
||||
/** Structure keys referenced by any Iris assembly or native jigsaw placement. */
|
||||
public static Set<String> placedKeys(Engine engine) {
|
||||
if (engine == null) {
|
||||
public static Set<String> placedKeys(PackWorld world) {
|
||||
if (world == null) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
return index(engine).loadKeys;
|
||||
return index(world).loadKeys;
|
||||
}
|
||||
|
||||
/**
|
||||
* Every key under which a structure the engine's placements place can be found: the placed keys and the platform
|
||||
* structures Iris structures stand in for ({@code vanillaSource}), the latter in lower case.
|
||||
*/
|
||||
public static Set<String> placedKeysAndAliases(Engine engine) {
|
||||
if (engine == null) {
|
||||
public static Set<String> placedKeysAndAliases(PackWorld world) {
|
||||
if (world == null) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
PlacementIndex placementIndex = index(engine);
|
||||
PlacementIndex placementIndex = index(world);
|
||||
Set<String> keys = new LinkedHashSet<>(placementIndex.loadKeys);
|
||||
keys.addAll(placementIndex.vanillaAliases);
|
||||
return Collections.unmodifiableSet(keys);
|
||||
}
|
||||
|
||||
/** The platform structures the engine's placements start natively ({@code nativeStructures}), in lower case. */
|
||||
public static Set<String> nativeKeys(Engine engine) {
|
||||
if (engine == null) {
|
||||
public static Set<String> nativeKeys(PackWorld world) {
|
||||
if (world == null) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
return index(engine).nativeKeys;
|
||||
return index(world).nativeKeys;
|
||||
}
|
||||
|
||||
public static boolean isPlaced(Engine engine, String key) {
|
||||
if (engine == null || key == null || key.isEmpty()) {
|
||||
public static boolean isPlaced(PackWorld world, String key) {
|
||||
if (world == null || key == null || key.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
PlacementIndex placementIndex = index(engine);
|
||||
PlacementIndex placementIndex = index(world);
|
||||
String normalizedKey = normalize(key);
|
||||
return placementIndex.normalizedLoadKeys.contains(normalizedKey)
|
||||
|| placementIndex.vanillaAliases.contains(normalizedKey);
|
||||
}
|
||||
|
||||
public static boolean hasLocatablePlacement(Engine engine, String key) {
|
||||
if (engine == null || key == null || key.isBlank()) {
|
||||
public static boolean hasLocatablePlacement(PackWorld world, String key) {
|
||||
if (world == null || key == null || key.isBlank()) {
|
||||
return false;
|
||||
}
|
||||
return locatableIndex(engine).normalizedKeys().contains(normalize(key));
|
||||
return locatableIndex(world).normalizedKeys().contains(normalize(key));
|
||||
}
|
||||
|
||||
public static boolean hasLocatableEditablePlacement(Engine engine, String key) {
|
||||
if (engine == null || key == null || key.isBlank()) {
|
||||
public static boolean hasLocatableEditablePlacement(PackWorld world, String key) {
|
||||
if (world == null || key == null || key.isBlank()) {
|
||||
return false;
|
||||
}
|
||||
return locatableIndex(engine).normalizedEditableKeys().contains(normalize(key));
|
||||
return locatableIndex(world).normalizedEditableKeys().contains(normalize(key));
|
||||
}
|
||||
|
||||
public static boolean hasLocatableNativePlacement(Engine engine, String key) {
|
||||
if (engine == null || key == null || key.isBlank()) {
|
||||
public static boolean hasLocatableNativePlacement(PackWorld world, String key) {
|
||||
if (world == null || key == null || key.isBlank()) {
|
||||
return false;
|
||||
}
|
||||
return locatableIndex(engine).normalizedNativeKeys().contains(normalize(key));
|
||||
return locatableIndex(world).normalizedNativeKeys().contains(normalize(key));
|
||||
}
|
||||
|
||||
public static Set<String> locatableKeys(Engine engine) {
|
||||
return locatableIndex(engine).keys();
|
||||
public static Set<String> locatableKeys(PackWorld world) {
|
||||
return locatableIndex(world).keys();
|
||||
}
|
||||
|
||||
public static Set<String> locatableEditableKeys(Engine engine) {
|
||||
return locatableIndex(engine).editableKeys();
|
||||
public static Set<String> locatableEditableKeys(PackWorld world) {
|
||||
return locatableIndex(world).editableKeys();
|
||||
}
|
||||
|
||||
public static Set<String> locatableNativeKeys(Engine engine) {
|
||||
return locatableIndex(engine).nativeKeys();
|
||||
public static Set<String> locatableNativeKeys(PackWorld world) {
|
||||
return locatableIndex(world).nativeKeys();
|
||||
}
|
||||
|
||||
public static boolean hasNativePlacement(Engine engine, String key) {
|
||||
if (engine == null || key == null || key.isBlank()) {
|
||||
public static boolean hasNativePlacement(PackWorld world, String key) {
|
||||
if (world == null || key == null || key.isBlank()) {
|
||||
return false;
|
||||
}
|
||||
return index(engine).nativeKeys.contains(normalize(key));
|
||||
return index(world).nativeKeys.contains(normalize(key));
|
||||
}
|
||||
|
||||
public static boolean hasEditablePlacement(Engine engine, String key) {
|
||||
if (engine == null || key == null || key.isBlank()) {
|
||||
public static boolean hasEditablePlacement(PackWorld world, String key) {
|
||||
if (world == null || key == null || key.isBlank()) {
|
||||
return false;
|
||||
}
|
||||
for (StructurePlacement placement : index(engine).placements) {
|
||||
if (placement.hasIrisStructures() && matches(placement, key, engine)) {
|
||||
for (StructurePlacement placement : index(world).placements) {
|
||||
if (placement.hasIrisStructures() && matches(placement, key, world)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean suppressesVanilla(Engine engine, String vanillaKey) {
|
||||
if (engine == null || vanillaKey == null || vanillaKey.isEmpty()) {
|
||||
public static boolean suppressesVanilla(PackWorld world, String vanillaKey) {
|
||||
if (world == null || vanillaKey == null || vanillaKey.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
return index(engine).suppressedVanillaSources.contains(normalize(vanillaKey));
|
||||
return index(world).suppressedVanillaSources.contains(normalize(vanillaKey));
|
||||
}
|
||||
|
||||
public static boolean startsInChunk(Engine engine, String key, int cx, int cz) {
|
||||
if (!isPlaced(engine, key)) {
|
||||
public static boolean startsInChunk(PackWorld world, String key, int cx, int cz) {
|
||||
if (!isPlaced(world, key)) {
|
||||
return false;
|
||||
}
|
||||
return resolveInChunk(engine, key, cx, cz) != null;
|
||||
return resolveInChunk(world, key, cx, cz) != null;
|
||||
}
|
||||
|
||||
public static LocateResult locate(Engine engine, String key, int fromBlockX, int fromBlockZ, int maxRadiusChunks) {
|
||||
return locate(engine, key, fromBlockX, fromBlockZ, maxRadiusChunks, (chunkX, chunkZ) -> true);
|
||||
public static LocateResult locate(PackWorld world, String key, int fromBlockX, int fromBlockZ, int maxRadiusChunks) {
|
||||
return locate(world, key, fromBlockX, fromBlockZ, maxRadiusChunks, (chunkX, chunkZ) -> true);
|
||||
}
|
||||
|
||||
public static LocateResult locate(Engine engine, String key, int fromBlockX, int fromBlockZ,
|
||||
public static LocateResult locate(PackWorld world, String key, int fromBlockX, int fromBlockZ,
|
||||
int maxRadiusChunks, CandidateFilter candidateFilter) {
|
||||
try {
|
||||
return locateFiltered(engine, key, fromBlockX, fromBlockZ, maxRadiusChunks, candidateFilter);
|
||||
return locateFiltered(world, key, fromBlockX, fromBlockZ, maxRadiusChunks, candidateFilter);
|
||||
} catch (CandidateSearchLimitException ignored) {
|
||||
return SEARCH_LIMIT_RESULT;
|
||||
}
|
||||
}
|
||||
|
||||
public static LocateResult locateInPlacementRings(
|
||||
Engine engine, String key, int fromBlockX, int fromBlockZ,
|
||||
PackWorld world, String key, int fromBlockX, int fromBlockZ,
|
||||
int maxSearchRadius, CandidateFilter candidateFilter) {
|
||||
try {
|
||||
return locateInPlacementRingsFiltered(
|
||||
engine, key, fromBlockX, fromBlockZ, maxSearchRadius, candidateFilter);
|
||||
world, key, fromBlockX, fromBlockZ, maxSearchRadius, candidateFilter);
|
||||
} catch (CandidateSearchLimitException ignored) {
|
||||
return SEARCH_LIMIT_RESULT;
|
||||
}
|
||||
}
|
||||
|
||||
private static LocateResult locateInPlacementRingsFiltered(
|
||||
Engine engine, String key, int fromBlockX, int fromBlockZ,
|
||||
PackWorld world, String key, int fromBlockX, int fromBlockZ,
|
||||
int maxSearchRadius, CandidateFilter candidateFilter) {
|
||||
if (!isPlaced(engine, key)) {
|
||||
if (!isPlaced(world, key)) {
|
||||
return NOT_FOUND_RESULT;
|
||||
}
|
||||
CandidateFilter activeFilter = Objects.requireNonNull(
|
||||
@@ -226,26 +228,21 @@ public final class IrisStructureLocator {
|
||||
int maximumRing = Math.max(0, Math.min(maxSearchRadius, 2048));
|
||||
int centerChunkX = fromBlockX >> 4;
|
||||
int centerChunkZ = fromBlockZ >> 4;
|
||||
PlacementCatalog catalog = collectPlacementCatalog(engine, key);
|
||||
PlacementCatalog catalog = collectPlacementCatalog(world, key);
|
||||
if (catalog.randomSpread().isEmpty()
|
||||
&& catalog.concentricRings().isEmpty() && !catalog.hasDensity()) {
|
||||
return NOT_FOUND_RESULT;
|
||||
}
|
||||
SeedManager seedManager = engine.getSeedManager();
|
||||
if (seedManager == null) {
|
||||
throw new IllegalStateException(
|
||||
"Iris structure locate requires a bound seed manager for '" + key + "'");
|
||||
}
|
||||
long seed = seedManager.getMantle();
|
||||
long seed = StructureWorld.placementSeed(world);
|
||||
CandidateBudget candidateBudget = new CandidateBudget();
|
||||
LocatedCandidate best = nearestConcentricCandidate(
|
||||
engine, key, fromBlockX, fromBlockZ, seed, catalog, activeFilter, candidateBudget);
|
||||
world, key, fromBlockX, fromBlockZ, seed, catalog, activeFilter, candidateBudget);
|
||||
|
||||
for (int ring = 0; ring <= maximumRing; ring++) {
|
||||
boolean foundInRing = false;
|
||||
for (RandomSpreadParameters parameters : catalog.randomSpread()) {
|
||||
LocatedCandidate candidate = firstRandomSpreadCandidateInRing(
|
||||
engine, key, fromBlockX, fromBlockZ,
|
||||
world, key, fromBlockX, fromBlockZ,
|
||||
centerChunkX, centerChunkZ, ring, seed,
|
||||
parameters, activeFilter, candidateBudget);
|
||||
if (candidate == null) {
|
||||
@@ -258,7 +255,7 @@ public final class IrisStructureLocator {
|
||||
}
|
||||
if (catalog.hasDensity()) {
|
||||
LocatedCandidate candidate = firstDensityCandidateInRing(
|
||||
engine, key, fromBlockX, fromBlockZ,
|
||||
world, key, fromBlockX, fromBlockZ,
|
||||
centerChunkX, centerChunkZ, ring,
|
||||
activeFilter, candidateBudget);
|
||||
if (candidate != null) {
|
||||
@@ -276,7 +273,7 @@ public final class IrisStructureLocator {
|
||||
}
|
||||
|
||||
private static LocatedCandidate nearestConcentricCandidate(
|
||||
Engine engine, String key, int fromBlockX, int fromBlockZ,
|
||||
PackWorld world, String key, int fromBlockX, int fromBlockZ,
|
||||
long seed, PlacementCatalog catalog, CandidateFilter candidateFilter,
|
||||
CandidateBudget candidateBudget) {
|
||||
LocatedCandidate best = null;
|
||||
@@ -290,7 +287,7 @@ public final class IrisStructureLocator {
|
||||
if (candidate == null || !checkedChunks.add(chunkKey(candidate[0], candidate[1]))) {
|
||||
continue;
|
||||
}
|
||||
ResolvedStart resolved = resolveInChunk(engine, key, candidate[0], candidate[1]);
|
||||
ResolvedStart resolved = resolveInChunk(world, key, candidate[0], candidate[1]);
|
||||
if (resolved == null || !candidateFilter.accept(candidate[0], candidate[1])) {
|
||||
continue;
|
||||
}
|
||||
@@ -305,7 +302,7 @@ public final class IrisStructureLocator {
|
||||
}
|
||||
|
||||
private static LocatedCandidate firstRandomSpreadCandidateInRing(
|
||||
Engine engine, String key, int fromBlockX, int fromBlockZ,
|
||||
PackWorld world, String key, int fromBlockX, int fromBlockZ,
|
||||
int centerChunkX, int centerChunkZ, int ring, long seed,
|
||||
RandomSpreadParameters parameters, CandidateFilter candidateFilter,
|
||||
CandidateBudget candidateBudget) {
|
||||
@@ -323,7 +320,7 @@ public final class IrisStructureLocator {
|
||||
int[] candidate = StructurePlacementGrid.randomSpreadCellChunk(
|
||||
centerCellX + offsetX, centerCellZ + offsetZ,
|
||||
spacing, parameters.separation(), parameters.salt(), seed);
|
||||
ResolvedStart resolved = resolveInChunk(engine, key, candidate[0], candidate[1]);
|
||||
ResolvedStart resolved = resolveInChunk(world, key, candidate[0], candidate[1]);
|
||||
if (resolved != null && candidateFilter.accept(candidate[0], candidate[1])) {
|
||||
return new LocatedCandidate(
|
||||
resolved, blockDistanceSquared(resolved, fromBlockX, fromBlockZ));
|
||||
@@ -334,7 +331,7 @@ public final class IrisStructureLocator {
|
||||
}
|
||||
|
||||
private static LocatedCandidate firstDensityCandidateInRing(
|
||||
Engine engine, String key, int fromBlockX, int fromBlockZ,
|
||||
PackWorld world, String key, int fromBlockX, int fromBlockZ,
|
||||
int centerChunkX, int centerChunkZ, int ring,
|
||||
CandidateFilter candidateFilter, CandidateBudget candidateBudget) {
|
||||
for (int offsetX = -ring; offsetX <= ring; offsetX++) {
|
||||
@@ -347,7 +344,7 @@ public final class IrisStructureLocator {
|
||||
int chunkX = centerChunkX + offsetX;
|
||||
int chunkZ = centerChunkZ + offsetZ;
|
||||
candidateBudget.claim();
|
||||
ResolvedStart resolved = resolveInChunk(engine, key, chunkX, chunkZ);
|
||||
ResolvedStart resolved = resolveInChunk(world, key, chunkX, chunkZ);
|
||||
if (resolved != null && candidateFilter.accept(chunkX, chunkZ)) {
|
||||
return new LocatedCandidate(
|
||||
resolved, blockDistanceSquared(resolved, fromBlockX, fromBlockZ));
|
||||
@@ -357,9 +354,9 @@ public final class IrisStructureLocator {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static LocateResult locateFiltered(Engine engine, String key, int fromBlockX, int fromBlockZ,
|
||||
private static LocateResult locateFiltered(PackWorld world, String key, int fromBlockX, int fromBlockZ,
|
||||
int maxRadiusChunks, CandidateFilter candidateFilter) {
|
||||
if (!isPlaced(engine, key)) {
|
||||
if (!isPlaced(world, key)) {
|
||||
return NOT_FOUND_RESULT;
|
||||
}
|
||||
CandidateFilter activeFilter = Objects.requireNonNull(candidateFilter, "Structure locate filter must not be null");
|
||||
@@ -367,15 +364,11 @@ public final class IrisStructureLocator {
|
||||
int pcx = fromBlockX >> 4;
|
||||
int pcz = fromBlockZ >> 4;
|
||||
LocatedCandidate best = null;
|
||||
PlacementCatalog catalog = collectPlacementCatalog(engine, key);
|
||||
PlacementCatalog catalog = collectPlacementCatalog(world, key);
|
||||
if (catalog.randomSpread().isEmpty() && catalog.concentricRings().isEmpty() && !catalog.hasDensity()) {
|
||||
return NOT_FOUND_RESULT;
|
||||
}
|
||||
SeedManager seedManager = engine.getSeedManager();
|
||||
if (seedManager == null) {
|
||||
throw new IllegalStateException("Iris structure locate requires a bound seed manager for '" + key + "'");
|
||||
}
|
||||
long seed = seedManager.getMantle();
|
||||
long seed = StructureWorld.placementSeed(world);
|
||||
CandidateBudget candidateBudget = new CandidateBudget();
|
||||
|
||||
for (RandomSpreadParameters parameters : catalog.randomSpread) {
|
||||
@@ -406,7 +399,7 @@ public final class IrisStructureLocator {
|
||||
cx, cz, fromBlockX, fromBlockZ) >= best.distanceSquared()) {
|
||||
continue;
|
||||
}
|
||||
ResolvedStart resolved = resolveInChunk(engine, key, cx, cz);
|
||||
ResolvedStart resolved = resolveInChunk(world, key, cx, cz);
|
||||
if (resolved != null && activeFilter.accept(cx, cz)) {
|
||||
long distanceSquared = blockDistanceSquared(
|
||||
resolved, fromBlockX, fromBlockZ);
|
||||
@@ -433,7 +426,7 @@ public final class IrisStructureLocator {
|
||||
candidate[0], candidate[1], fromBlockX, fromBlockZ) >= best.distanceSquared()) {
|
||||
continue;
|
||||
}
|
||||
ResolvedStart resolved = resolveInChunk(engine, key, candidate[0], candidate[1]);
|
||||
ResolvedStart resolved = resolveInChunk(world, key, candidate[0], candidate[1]);
|
||||
if (resolved != null && activeFilter.accept(candidate[0], candidate[1])) {
|
||||
long distanceSquared = blockDistanceSquared(
|
||||
resolved, fromBlockX, fromBlockZ);
|
||||
@@ -462,7 +455,7 @@ public final class IrisStructureLocator {
|
||||
continue;
|
||||
}
|
||||
candidateBudget.claim();
|
||||
ResolvedStart resolved = resolveInChunk(engine, key, cx, cz);
|
||||
ResolvedStart resolved = resolveInChunk(world, key, cx, cz);
|
||||
if (resolved != null && activeFilter.accept(cx, cz)) {
|
||||
long distanceSquared = blockDistanceSquared(
|
||||
resolved, fromBlockX, fromBlockZ);
|
||||
@@ -487,15 +480,15 @@ public final class IrisStructureLocator {
|
||||
&& Math.abs((long) chunkZ - centerChunkZ) <= radius;
|
||||
}
|
||||
|
||||
public static ResolvedPlacement resolvePlacement(Engine engine, StructurePlacement placement, int cx, int cz) {
|
||||
if (engine == null || engine.getData() == null || engine.getSeedManager() == null) {
|
||||
throw new IllegalStateException("Iris structure placement requires a fully bound engine");
|
||||
public static ResolvedPlacement resolvePlacement(PackWorld world, StructurePlacement placement, int cx, int cz) {
|
||||
if (world == null) {
|
||||
throw new IllegalStateException("Iris structure placement requires a world");
|
||||
}
|
||||
NativeStartPlanner.validateBackend(placement);
|
||||
if (!placement.hasIrisStructures()) {
|
||||
throw new IllegalStateException("Iris structure placement is missing its structure list");
|
||||
}
|
||||
long seed = engine.getSeedManager().getMantle();
|
||||
long seed = StructureWorld.placementSeed(world);
|
||||
if (!StructurePlacementGrid.startsInChunk(placement, cx, cz, seed)) {
|
||||
return null;
|
||||
}
|
||||
@@ -503,7 +496,7 @@ public final class IrisStructureLocator {
|
||||
RNG rng = StructurePlacementGrid.placementRng(placement, cx, cz, seed);
|
||||
int originX = (cx << 4) + rng.nextInt(16);
|
||||
int originZ = (cz << 4) + rng.nextInt(16);
|
||||
PlacementAnchor anchor = resolveAnchor(engine, placement, cx, cz, originX, originZ, rng);
|
||||
PlacementAnchor anchor = resolveAnchor(world, placement, cx, cz, originX, originZ, rng);
|
||||
if (anchor == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -515,9 +508,9 @@ public final class IrisStructureLocator {
|
||||
if (selectedKey == null || selectedKey.isBlank()) {
|
||||
throw new IllegalStateException("Iris structure placement selected a blank structure key");
|
||||
}
|
||||
PackResources pack = engine.getData().getPackResources();
|
||||
PackResources pack = world.resources();
|
||||
ResourceId structureId = pack.idOf(selectedKey);
|
||||
StructureAssembly provider = providerOf(engine, structureId);
|
||||
StructureAssembly provider = providerOf(world, structureId);
|
||||
if (provider == null) {
|
||||
throw new IllegalStateException("Iris structure placement references missing structure '"
|
||||
+ selectedKey + "'");
|
||||
@@ -543,8 +536,8 @@ public final class IrisStructureLocator {
|
||||
}
|
||||
boolean exactY = hasExactY(placement, stamp, pieces);
|
||||
|
||||
int worldMin = engine.getMinHeight() + 1;
|
||||
int worldMax = engine.getMinHeight() + engine.getHeight() - 1;
|
||||
int worldMin = world.minWorldY() + 1;
|
||||
int worldMax = world.minWorldY() + StructureWorld.height(world) - 1;
|
||||
if (exactY) {
|
||||
Integer verticalShift = resolveVerticalShift(pieces, placement, baseY, worldMin, worldMax);
|
||||
if (!requirePlacementOutput(placement, selectedKey, cx, cz, verticalShift != null,
|
||||
@@ -558,7 +551,7 @@ public final class IrisStructureLocator {
|
||||
}
|
||||
if (placement.isAnchoredUnderground() && !placement.resolvedAnchor().isCave()) {
|
||||
Integer burialShift = resolveUndergroundBurialShift(
|
||||
engine, pieces, placement, baseY, worldMin, worldMax);
|
||||
world, pieces, placement, baseY, worldMin, worldMax);
|
||||
if (!requirePlacementOutput(placement, selectedKey, cx, cz, burialShift != null,
|
||||
"assembled pieces and carving envelope cannot remain fully buried beneath terrain")) {
|
||||
return null;
|
||||
@@ -584,9 +577,9 @@ public final class IrisStructureLocator {
|
||||
* The first provider of {@link StructureAssembly} among the modules of the engine's pack that knows {@code structure};
|
||||
* null when none does.
|
||||
*/
|
||||
public static StructureAssembly providerOf(Engine engine, ResourceId structure) {
|
||||
PackResources pack = engine.getData().getPackResources();
|
||||
for (StructureAssembly provider : engine.getGeneration().world().services(StructureAssembly.class)) {
|
||||
public static StructureAssembly providerOf(PackWorld world, ResourceId structure) {
|
||||
PackResources pack = world.resources();
|
||||
for (StructureAssembly provider : world.services(StructureAssembly.class)) {
|
||||
if (provider.knows(pack, structure)) {
|
||||
return provider;
|
||||
}
|
||||
@@ -595,10 +588,10 @@ public final class IrisStructureLocator {
|
||||
}
|
||||
|
||||
/** How the pieces of the pack structure {@code key} are stamped; null when no module knows the structure. */
|
||||
public static StructureStamp stampOf(Engine engine, String key) {
|
||||
PackResources pack = engine.getData().getPackResources();
|
||||
public static StructureStamp stampOf(PackWorld world, String key) {
|
||||
PackResources pack = world.resources();
|
||||
ResourceId structure = pack.idOf(key);
|
||||
StructureAssembly provider = providerOf(engine, structure);
|
||||
StructureAssembly provider = providerOf(world, structure);
|
||||
return provider == null ? null : provider.stamp(pack, structure).orElse(null);
|
||||
}
|
||||
|
||||
@@ -631,24 +624,24 @@ public final class IrisStructureLocator {
|
||||
&& fitsHorizontalBounds(bounds, originX, originZ, structureRadius);
|
||||
}
|
||||
|
||||
private static ResolvedStart resolveInChunk(Engine engine, String key, int cx, int cz) {
|
||||
private static ResolvedStart resolveInChunk(PackWorld world, String key, int cx, int cz) {
|
||||
String normalizedKey = normalize(key);
|
||||
if (hasNativePlacement(engine, key)) {
|
||||
for (NativeStartPlanner.Plan plan : NativeStartPlanner.plansAt(engine, cx, cz)) {
|
||||
if (hasNativePlacement(world, key)) {
|
||||
for (NativeStartPlanner.Plan plan : NativeStartPlanner.plansAt(world, cx, cz)) {
|
||||
if (normalize(plan.source().structure()).equals(normalizedKey)) {
|
||||
return new ResolvedStart(cx << 4, plan.baseY(), cz << 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
KList<StructurePlacement> placements = StructurePlacementScope.placementsAt(engine, cx, cz);
|
||||
List<StructurePlacement> placements = StructurePlacementScope.placementsAt(world, cx, cz);
|
||||
for (StructurePlacement placement : placements) {
|
||||
if (!matches(placement, key, engine)) {
|
||||
if (!matches(placement, key, world)) {
|
||||
continue;
|
||||
}
|
||||
if (placement.hasNativeStructures()) {
|
||||
continue;
|
||||
}
|
||||
ResolvedPlacement resolved = resolvePlacement(engine, placement, cx, cz);
|
||||
ResolvedPlacement resolved = resolvePlacement(world, placement, cx, cz);
|
||||
if (resolved != null && matchesResolved(resolved, key)) {
|
||||
return new ResolvedStart(
|
||||
resolved.originX(), resolved.baseY(), resolved.originZ());
|
||||
@@ -658,7 +651,7 @@ public final class IrisStructureLocator {
|
||||
}
|
||||
|
||||
private static PlacementAnchor resolveAnchor(
|
||||
Engine engine,
|
||||
PackWorld world,
|
||||
StructurePlacement placement,
|
||||
int chunkX,
|
||||
int chunkZ,
|
||||
@@ -668,25 +661,25 @@ public final class IrisStructureLocator {
|
||||
) {
|
||||
if (placement.resolvedAnchor().isCave()) {
|
||||
StructureCaveAnchorResolver.Anchor caveAnchor = StructureCaveAnchorResolver.resolve(
|
||||
engine, placement, chunkX, chunkZ, rng.nextParallelRNG(CAVE_ANCHOR_DOMAIN));
|
||||
world, placement, chunkX, chunkZ, rng.nextParallelRNG(CAVE_ANCHOR_DOMAIN));
|
||||
return caveAnchor == null ? null : new PlacementAnchor(caveAnchor.x(), caveAnchor.y(), caveAnchor.z());
|
||||
}
|
||||
Integer baseY = resolveBaseY(engine, placement, originX, originZ, rng);
|
||||
Integer baseY = resolveBaseY(world, placement, originX, originZ, rng);
|
||||
return baseY == null ? null : new PlacementAnchor(originX, baseY, originZ);
|
||||
}
|
||||
|
||||
private static Integer resolveBaseY(Engine engine, StructurePlacement placement, int originX, int originZ, RNG rng) {
|
||||
int worldMin = engine.getMinHeight() + 1;
|
||||
int worldMax = engine.getMinHeight() + engine.getHeight() - 1;
|
||||
private static Integer resolveBaseY(PackWorld world, StructurePlacement placement, int originX, int originZ, RNG rng) {
|
||||
int worldMin = world.minWorldY() + 1;
|
||||
int worldMax = world.minWorldY() + StructureWorld.height(world) - 1;
|
||||
if (worldMin > worldMax) {
|
||||
return null;
|
||||
}
|
||||
if (!placement.underwater()
|
||||
&& NativeStartPlanner.isSubmerged(engine, originX, originZ)) {
|
||||
&& NativeStartPlanner.isSubmerged(world, originX, originZ)) {
|
||||
return null;
|
||||
}
|
||||
if (placement.resolvedAnchor() == StructureAnchorMode.SURFACE) {
|
||||
int surfaceY = engine.getHeight(originX, originZ, true) + engine.getMinHeight();
|
||||
int surfaceY = StructureWorld.highest(world, originX, originZ);
|
||||
return surfaceY < placement.minHeight() || surfaceY > placement.maxHeight() ? null : surfaceY;
|
||||
}
|
||||
int bandMin = Math.max(worldMin, Math.min(placement.minHeight(), placement.maxHeight()));
|
||||
@@ -722,11 +715,11 @@ public final class IrisStructureLocator {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static Integer resolveUndergroundBurialShift(Engine engine, KList<AssembledPiece> pieces,
|
||||
static Integer resolveUndergroundBurialShift(PackWorld world, KList<AssembledPiece> pieces,
|
||||
StructurePlacement placement, int baseY,
|
||||
int worldMin, int worldMax) {
|
||||
int[] bounds = computeBounds(pieces);
|
||||
if (engine == null || bounds == null || placement == null || !placement.isAnchoredUnderground()
|
||||
if (world == null || bounds == null || placement == null || !placement.isAnchoredUnderground()
|
||||
|| placement.resolvedAnchor().isCave()) {
|
||||
return null;
|
||||
}
|
||||
@@ -753,7 +746,7 @@ public final class IrisStructureLocator {
|
||||
ColumnHeights surfaceHeights = new ColumnHeights(Integer.MIN_VALUE);
|
||||
if (bore || forceCarve && carveShape == StructureCarveShape.BOX) {
|
||||
maximumShift = resolveBurialEnvelopeShift(
|
||||
engine,
|
||||
world,
|
||||
bounds[0] - sideExtension,
|
||||
bounds[3] + sideExtension,
|
||||
bounds[2] - sideExtension,
|
||||
@@ -768,7 +761,7 @@ public final class IrisStructureLocator {
|
||||
} else {
|
||||
for (AssembledPiece piece : pieces) {
|
||||
maximumShift = resolveBurialEnvelopeShift(
|
||||
engine,
|
||||
world,
|
||||
piece.minX() - sideExtension,
|
||||
piece.maxX() + sideExtension,
|
||||
piece.minZ() - sideExtension,
|
||||
@@ -785,7 +778,7 @@ public final class IrisStructureLocator {
|
||||
return minimumShift > maximumShift ? null : maximumShift;
|
||||
}
|
||||
|
||||
private static int resolveBurialEnvelopeShift(Engine engine, int minX, int maxX, int minZ, int maxZ,
|
||||
private static int resolveBurialEnvelopeShift(PackWorld world, int minX, int maxX, int minZ, int maxZ,
|
||||
int envelopeTopY, int maximumShift,
|
||||
ColumnHeights surfaceHeights) {
|
||||
for (int x = minX; x <= maxX; x++) {
|
||||
@@ -796,7 +789,7 @@ public final class IrisStructureLocator {
|
||||
if (surfaceHeights.size() >= MAX_BURIAL_COLUMNS) {
|
||||
return Integer.MIN_VALUE;
|
||||
}
|
||||
surfaceY = engine.getHeight(x, z, true) + engine.getMinHeight();
|
||||
surfaceY = StructureWorld.highest(world, x, z);
|
||||
surfaceHeights.put(columnKey, surfaceY);
|
||||
}
|
||||
int allowedTopY = surfaceY - UNDERGROUND_SURFACE_CLEARANCE;
|
||||
@@ -908,13 +901,13 @@ public final class IrisStructureLocator {
|
||||
return minimum + rng.nextInt((maximum - minimum) + 1);
|
||||
}
|
||||
|
||||
private static PlacementCatalog collectPlacementCatalog(Engine engine, String key) {
|
||||
private static PlacementCatalog collectPlacementCatalog(PackWorld world, String key) {
|
||||
Set<RandomSpreadParameters> randomSpread = new LinkedHashSet<>();
|
||||
List<StructurePlacement> concentricRings = new ArrayList<>();
|
||||
boolean hasDensity = false;
|
||||
for (StructurePlacement placement : index(engine).placements) {
|
||||
if (!isSearchablePlacement(engine, placement)
|
||||
|| !matches(placement, key, engine)) {
|
||||
for (StructurePlacement placement : index(world).placements) {
|
||||
if (!isSearchablePlacement(world, placement)
|
||||
|| !matches(placement, key, world)) {
|
||||
continue;
|
||||
}
|
||||
if (placement.distribution() == StructureDistribution.RANDOM_SPREAD) {
|
||||
@@ -930,22 +923,22 @@ public final class IrisStructureLocator {
|
||||
return new PlacementCatalog(List.copyOf(randomSpread), List.copyOf(concentricRings), hasDensity);
|
||||
}
|
||||
|
||||
static boolean isSearchableDensityPlacement(Engine engine, StructurePlacement placement) {
|
||||
static boolean isSearchableDensityPlacement(PackWorld world, StructurePlacement placement) {
|
||||
return placement != null
|
||||
&& placement.distribution() == StructureDistribution.DENSITY
|
||||
&& isSearchablePlacement(engine, placement);
|
||||
&& isSearchablePlacement(world, placement);
|
||||
}
|
||||
|
||||
static boolean isSearchablePlacement(Engine engine, StructurePlacement placement) {
|
||||
if (engine == null || placement == null || engine.getHeight() <= 0) {
|
||||
static boolean isSearchablePlacement(PackWorld world, StructurePlacement placement) {
|
||||
if (world == null || placement == null || StructureWorld.height(world) <= 0) {
|
||||
return false;
|
||||
}
|
||||
if (placement.distribution() == StructureDistribution.DENSITY
|
||||
&& !(placement.density() > 0.0)) {
|
||||
return false;
|
||||
}
|
||||
long worldMin = (long) engine.getMinHeight() + (placement.isAnchoredUnderground() ? 1L : 0L);
|
||||
long worldMax = (long) engine.getMinHeight() + engine.getHeight()
|
||||
long worldMin = (long) world.minWorldY() + (placement.isAnchoredUnderground() ? 1L : 0L);
|
||||
long worldMax = (long) world.minWorldY() + StructureWorld.height(world)
|
||||
- (placement.resolvedAnchor().isCave() ? 2L : 1L);
|
||||
if (worldMin > worldMax) {
|
||||
return false;
|
||||
@@ -1033,8 +1026,8 @@ public final class IrisStructureLocator {
|
||||
private record PlacementAnchor(int x, int y, int z) {
|
||||
}
|
||||
|
||||
private static boolean matches(StructurePlacement placement, String key, Engine engine) {
|
||||
if (placement == null || key == null || engine == null || engine.getData() == null) {
|
||||
private static boolean matches(StructurePlacement placement, String key, PackWorld world) {
|
||||
if (placement == null || key == null || world == null) {
|
||||
return false;
|
||||
}
|
||||
String normalizedKey = normalize(key);
|
||||
@@ -1047,7 +1040,7 @@ public final class IrisStructureLocator {
|
||||
if (structureKey == null || structureKey.isBlank()) {
|
||||
continue;
|
||||
}
|
||||
StructureStamp stamp = stampOf(engine, structureKey);
|
||||
StructureStamp stamp = stampOf(world, structureKey);
|
||||
if (stamp == null) {
|
||||
continue;
|
||||
}
|
||||
@@ -1069,32 +1062,29 @@ public final class IrisStructureLocator {
|
||||
return key == null ? "" : key.toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
private static PlacementIndex index(Engine engine) {
|
||||
if (engine == null) {
|
||||
private static PlacementIndex index(PackWorld world) {
|
||||
if (world == null) {
|
||||
return EMPTY_INDEX;
|
||||
}
|
||||
if (engine.getData() == null || engine.getDimension() == null) {
|
||||
throw new IllegalStateException("Iris structure index requires a fully bound engine and dimension");
|
||||
}
|
||||
return engine.getGeneration().state(PlacementIndex.class, IrisStructureLocator::build);
|
||||
return world.state(PlacementIndex.class, IrisStructureLocator::build);
|
||||
}
|
||||
|
||||
private static LocatableIndex locatableIndex(Engine engine) {
|
||||
if (engine == null) {
|
||||
private static LocatableIndex locatableIndex(PackWorld world) {
|
||||
if (world == null) {
|
||||
return EMPTY_LOCATABLE_INDEX;
|
||||
}
|
||||
return engine.getGeneration().state(LocatableIndex.class, IrisStructureLocator::buildLocatableIndex);
|
||||
return world.state(LocatableIndex.class, IrisStructureLocator::buildLocatableIndex);
|
||||
}
|
||||
|
||||
private static LocatableIndex buildLocatableIndex(Engine engine) {
|
||||
private static LocatableIndex buildLocatableIndex(PackWorld world) {
|
||||
Set<String> keys = new LinkedHashSet<>();
|
||||
Set<String> normalizedKeys = new LinkedHashSet<>();
|
||||
Set<String> editableKeys = new LinkedHashSet<>();
|
||||
Set<String> normalizedEditableKeys = new LinkedHashSet<>();
|
||||
Set<String> nativeKeys = new LinkedHashSet<>();
|
||||
Set<String> normalizedNativeKeys = new LinkedHashSet<>();
|
||||
for (StructurePlacement placement : index(engine).placements) {
|
||||
if (!isSearchablePlacement(engine, placement)) {
|
||||
for (StructurePlacement placement : index(world).placements) {
|
||||
if (!isSearchablePlacement(world, placement)) {
|
||||
continue;
|
||||
}
|
||||
if (placement.hasNativeStructures()) {
|
||||
@@ -1105,7 +1095,7 @@ public final class IrisStructureLocator {
|
||||
continue;
|
||||
}
|
||||
for (String structureKey : placement.structures()) {
|
||||
StructureStamp stamp = stampOf(engine, structureKey);
|
||||
StructureStamp stamp = stampOf(world, structureKey);
|
||||
if (stamp == null) {
|
||||
throw new IllegalStateException(
|
||||
"Iris structure placement references missing structure '" + structureKey + "'");
|
||||
@@ -1134,29 +1124,15 @@ public final class IrisStructureLocator {
|
||||
normalizedKeys.add(normalize(trimmedKey));
|
||||
}
|
||||
|
||||
private static PlacementIndex build(Engine engine) {
|
||||
private static PlacementIndex build(PackWorld world) {
|
||||
Set<String> loadKeys = new LinkedHashSet<>();
|
||||
Set<String> normalizedLoadKeys = new LinkedHashSet<>();
|
||||
Set<String> vanillaAliases = new LinkedHashSet<>();
|
||||
Set<String> suppressedVanillaSources = new LinkedHashSet<>();
|
||||
List<StructurePlacement> placements = new ArrayList<>();
|
||||
collect(StructurePlacementScope.placementsOf(engine.getDimension()), engine, loadKeys, normalizedLoadKeys, vanillaAliases,
|
||||
suppressedVanillaSources, placements, true);
|
||||
KList<IrisRegion> regions = engine.getDimension().getAllRegions(engine);
|
||||
if (regions != null) {
|
||||
for (IrisRegion region : regions) {
|
||||
collect(StructurePlacementScope.placementsOf(region), engine,
|
||||
loadKeys, normalizedLoadKeys, vanillaAliases,
|
||||
suppressedVanillaSources, placements, false);
|
||||
}
|
||||
}
|
||||
KList<IrisBiome> biomes = engine.getDimension().getReachableBiomes(engine);
|
||||
if (biomes != null) {
|
||||
for (IrisBiome biome : biomes) {
|
||||
collect(StructurePlacementScope.placementsOf(biome), engine,
|
||||
loadKeys, normalizedLoadKeys, vanillaAliases,
|
||||
suppressedVanillaSources, placements, false);
|
||||
}
|
||||
for (var declared : world.settings().declared(StructurePlacementSettings.class)) {
|
||||
collect(declared.value().placements(), world, loadKeys, normalizedLoadKeys, vanillaAliases,
|
||||
suppressedVanillaSources, placements, declared.level() == Level.DIMENSION);
|
||||
}
|
||||
return new PlacementIndex(
|
||||
Collections.unmodifiableSet(loadKeys),
|
||||
@@ -1182,7 +1158,7 @@ public final class IrisStructureLocator {
|
||||
return Collections.unmodifiableSet(nativeKeys);
|
||||
}
|
||||
|
||||
private static void collect(List<StructurePlacement> source, Engine engine, Set<String> loadKeys,
|
||||
private static void collect(List<StructurePlacement> source, PackWorld world, Set<String> loadKeys,
|
||||
Set<String> normalizedLoadKeys, Set<String> vanillaAliases,
|
||||
Set<String> suppressedVanillaSources,
|
||||
List<StructurePlacement> placements, boolean allowNativeSuppression) {
|
||||
@@ -1219,7 +1195,7 @@ public final class IrisStructureLocator {
|
||||
? "REPLACE_SOURCE contains a blank Iris structure reference"
|
||||
: "Iris structure placement contains a blank structure reference");
|
||||
}
|
||||
StructureStamp stamp = stampOf(engine, structureKey);
|
||||
StructureStamp stamp = stampOf(world, structureKey);
|
||||
if (stamp == null) {
|
||||
throw new IllegalStateException((replacesNative
|
||||
? "REPLACE_SOURCE references missing Iris structure '"
|
||||
@@ -1237,9 +1213,9 @@ public final class IrisStructureLocator {
|
||||
throw new IllegalStateException("REPLACE_SOURCE structure '" + structureKey
|
||||
+ "' must declare a valid namespaced vanillaSource");
|
||||
}
|
||||
PackResources pack = engine.getData().getPackResources();
|
||||
PackResources pack = world.resources();
|
||||
ResourceId structureId = pack.idOf(structureKey);
|
||||
if (providerOf(engine, structureId).viability(pack, structureId) != Viability.GUARANTEED) {
|
||||
if (providerOf(world, structureId).viability(pack, structureId) != Viability.GUARANTEED) {
|
||||
throw new IllegalStateException("REPLACE_SOURCE structure '" + structureKey
|
||||
+ "' is not runtime-viable; native generation will not be used as a fallback");
|
||||
}
|
||||
|
||||
+57
-46
@@ -1,16 +1,19 @@
|
||||
package art.arcane.iris.engine.framework;
|
||||
|
||||
import art.arcane.iris.builtin.carve.CaveLavaHeightSettings;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.builtin.structure.StructureAnchorMode;
|
||||
import art.arcane.iris.builtin.structure.StructurePlacement;
|
||||
import art.arcane.iris.engine.framework.structure.StructureWorld;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import art.arcane.volmlib.util.matter.MatterCavern;
|
||||
import com.volmit.mantle.CarvedVoid;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.world.PackWorld;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.function.IntPredicate;
|
||||
|
||||
public final class StructureCaveAnchorResolver {
|
||||
@@ -19,22 +22,21 @@ public final class StructureCaveAnchorResolver {
|
||||
private static final int MAX_SCAN_STEP = 16;
|
||||
private static final int MAX_CLEARANCE = 64;
|
||||
private static final int MAX_GENERIC_CENTER_SEARCH = 4096;
|
||||
private static final byte LIQUID_FORCED_AIR = 3;
|
||||
|
||||
private StructureCaveAnchorResolver() {
|
||||
}
|
||||
|
||||
public static Anchor resolve(Engine engine, StructurePlacement placement, int chunkX, int chunkZ, RNG rng) {
|
||||
Objects.requireNonNull(engine, "Cave structure anchor requires an engine");
|
||||
public static Anchor resolve(PackWorld world, StructurePlacement placement, int chunkX, int chunkZ, RNG rng) {
|
||||
Objects.requireNonNull(world, "Cave structure anchor requires a world");
|
||||
Objects.requireNonNull(placement, "Cave structure anchor requires a placement");
|
||||
Objects.requireNonNull(rng, "Cave structure anchor requires a random source");
|
||||
StructureAnchorMode mode = placement.resolvedAnchor();
|
||||
if (!mode.isCave() || engine.getMantle() == null || engine.getMantle().getMantle() == null) {
|
||||
if (!mode.isCave() || world.running().isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int worldMin = engine.getMinHeight() + 1;
|
||||
int worldMax = engine.getMinHeight() + engine.getHeight() - 2;
|
||||
int worldMin = world.minWorldY() + 1;
|
||||
int worldMax = world.minWorldY() + StructureWorld.height(world) - 2;
|
||||
int minimumY = Math.max(worldMin, Math.min(placement.minHeight(), placement.maxHeight()));
|
||||
int maximumY = Math.min(worldMax, Math.max(placement.minHeight(), placement.maxHeight()));
|
||||
if (minimumY > maximumY) {
|
||||
@@ -51,7 +53,7 @@ public final class StructureCaveAnchorResolver {
|
||||
int blockX = chunkMinX + (candidateColumn & 15);
|
||||
int blockZ = chunkMinZ + (candidateColumn >>> 4);
|
||||
List<Integer> anchors = anchorsInColumn(
|
||||
engine, placement, mode, blockX, blockZ,
|
||||
world, placement, mode, blockX, blockZ,
|
||||
minimumY, maximumY, scanStep, clearance);
|
||||
if (!anchors.isEmpty()) {
|
||||
return new Anchor(blockX, anchors.get(rng.nextInt(anchors.size())), blockZ);
|
||||
@@ -73,7 +75,7 @@ public final class StructureCaveAnchorResolver {
|
||||
}
|
||||
|
||||
static List<Integer> anchorsInColumn(
|
||||
Engine engine,
|
||||
PackWorld world,
|
||||
StructurePlacement placement,
|
||||
StructureAnchorMode mode,
|
||||
int blockX,
|
||||
@@ -85,20 +87,20 @@ public final class StructureCaveAnchorResolver {
|
||||
) {
|
||||
if (mode == StructureAnchorMode.CAVE_CENTER) {
|
||||
return centerAnchorsInColumn(
|
||||
engine, placement, blockX, blockZ,
|
||||
world, placement, blockX, blockZ,
|
||||
minimumY, maximumY, scanStep, clearance);
|
||||
}
|
||||
List<Integer> anchors = new ArrayList<>();
|
||||
int step = Math.max(1, scanStep);
|
||||
for (int worldY = minimumY; worldY <= maximumY; worldY += step) {
|
||||
int mantleY = toMantleY(worldY, engine.getMinHeight());
|
||||
if (!matchesGeometry(engine, mode, blockX, mantleY, blockZ, clearance)) {
|
||||
int mantleY = toMantleY(worldY, world.minWorldY());
|
||||
if (!matchesGeometry(world, mode, blockX, mantleY, blockZ, clearance)) {
|
||||
continue;
|
||||
}
|
||||
if (!matchesAnchorFluid(engine, placement, blockX, mantleY, blockZ)) {
|
||||
if (!matchesAnchorFluid(world, placement, blockX, mantleY, blockZ)) {
|
||||
continue;
|
||||
}
|
||||
if (!matchesBiome(engine, placement, blockX, mantleY, blockZ)) {
|
||||
if (!matchesBiome(world, placement, blockX, mantleY, blockZ)) {
|
||||
continue;
|
||||
}
|
||||
anchors.add(worldY);
|
||||
@@ -107,7 +109,7 @@ public final class StructureCaveAnchorResolver {
|
||||
}
|
||||
|
||||
private static List<Integer> centerAnchorsInColumn(
|
||||
Engine engine,
|
||||
PackWorld world,
|
||||
StructurePlacement placement,
|
||||
int blockX,
|
||||
int blockZ,
|
||||
@@ -118,11 +120,11 @@ public final class StructureCaveAnchorResolver {
|
||||
) {
|
||||
List<Integer> anchors = new ArrayList<>();
|
||||
int step = Math.max(1, scanStep);
|
||||
int worldOffset = engine.getMinHeight();
|
||||
int worldOffset = world.minWorldY();
|
||||
int minimumMantleY = 0;
|
||||
int maximumMantleY = engine.getHeight() - 1;
|
||||
int maximumMantleY = StructureWorld.height(world) - 1;
|
||||
int processedThroughWorldY = Integer.MIN_VALUE;
|
||||
IntPredicate carved = y -> isCarved(engine, blockX, y, blockZ);
|
||||
IntPredicate carved = y -> isCarved(world, blockX, y, blockZ);
|
||||
for (int worldY = minimumY; worldY <= maximumY; worldY += step) {
|
||||
if (worldY <= processedThroughWorldY) {
|
||||
continue;
|
||||
@@ -139,12 +141,12 @@ public final class StructureCaveAnchorResolver {
|
||||
}
|
||||
int lowerCenterWorldY = lower + Math.floorDiv(upper - lower, 2) + worldOffset;
|
||||
addCenterAnchor(
|
||||
anchors, engine, placement, blockX, blockZ,
|
||||
anchors, world, placement, blockX, blockZ,
|
||||
lowerCenterWorldY, minimumY, maximumY);
|
||||
int upperCenterWorldY = lower + Math.ceilDiv(upper - lower, 2) + worldOffset;
|
||||
if (upperCenterWorldY != lowerCenterWorldY) {
|
||||
addCenterAnchor(
|
||||
anchors, engine, placement, blockX, blockZ,
|
||||
anchors, world, placement, blockX, blockZ,
|
||||
upperCenterWorldY, minimumY, maximumY);
|
||||
}
|
||||
}
|
||||
@@ -153,7 +155,7 @@ public final class StructureCaveAnchorResolver {
|
||||
|
||||
private static void addCenterAnchor(
|
||||
List<Integer> anchors,
|
||||
Engine engine,
|
||||
PackWorld world,
|
||||
StructurePlacement placement,
|
||||
int blockX,
|
||||
int blockZ,
|
||||
@@ -164,25 +166,25 @@ public final class StructureCaveAnchorResolver {
|
||||
if (worldY < minimumY || worldY > maximumY) {
|
||||
return;
|
||||
}
|
||||
int mantleY = toMantleY(worldY, engine.getMinHeight());
|
||||
if (matchesAnchorFluid(engine, placement, blockX, mantleY, blockZ)
|
||||
&& matchesBiome(engine, placement, blockX, mantleY, blockZ)) {
|
||||
int mantleY = toMantleY(worldY, world.minWorldY());
|
||||
if (matchesAnchorFluid(world, placement, blockX, mantleY, blockZ)
|
||||
&& matchesBiome(world, placement, blockX, mantleY, blockZ)) {
|
||||
anchors.add(worldY);
|
||||
}
|
||||
}
|
||||
|
||||
static boolean matchesGeometry(
|
||||
Engine engine,
|
||||
PackWorld world,
|
||||
StructureAnchorMode mode,
|
||||
int blockX,
|
||||
int mantleY,
|
||||
int blockZ,
|
||||
int clearance
|
||||
) {
|
||||
IntPredicate carved = y -> isCarved(engine, blockX, y, blockZ);
|
||||
IntPredicate carved = y -> isCarved(world, blockX, y, blockZ);
|
||||
if (mode == StructureAnchorMode.CAVE_CENTER) {
|
||||
return matchesCenterGeometry(
|
||||
carved, mantleY, Math.max(1, clearance), 0, engine.getHeight() - 1);
|
||||
carved, mantleY, Math.max(1, clearance), 0, StructureWorld.height(world) - 1);
|
||||
}
|
||||
return matchesGeometry(carved, mode, mantleY, clearance);
|
||||
}
|
||||
@@ -272,49 +274,49 @@ public final class StructureCaveAnchorResolver {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean isCarved(Engine engine, int blockX, int mantleY, int blockZ) {
|
||||
if (mantleY < 0 || mantleY >= engine.getHeight()) {
|
||||
private static boolean isCarved(PackWorld world, int blockX, int mantleY, int blockZ) {
|
||||
if (mantleY < 0 || mantleY >= StructureWorld.height(world)) {
|
||||
return false;
|
||||
}
|
||||
MatterCavern cavern = cavernAt(engine, blockX, mantleY, blockZ);
|
||||
return cavern != null && cavern.isCavern();
|
||||
return carvedAt(world, blockX, mantleY, blockZ).isPresent();
|
||||
}
|
||||
|
||||
private static boolean matchesAnchorFluid(
|
||||
Engine engine,
|
||||
PackWorld world,
|
||||
StructurePlacement placement,
|
||||
int blockX,
|
||||
int mantleY,
|
||||
int blockZ
|
||||
) {
|
||||
MatterCavern cavern = cavernAt(engine, blockX, mantleY, blockZ);
|
||||
int lavaHeight = StructureWorld.running(world).settings().at(CaveLavaHeightSettings.class, blockX, blockZ)
|
||||
.dimension().map(CaveLavaHeightSettings::height).orElse(CaveLavaHeightSettings.DEFAULT_HEIGHT);
|
||||
return acceptsAnchorFluid(
|
||||
placement.underwater(),
|
||||
cavern,
|
||||
carvedAt(world, blockX, mantleY, blockZ).orElse(null),
|
||||
mantleY,
|
||||
engine.getDimension().getModuleSettings().find(CaveLavaHeightSettings.class).map(CaveLavaHeightSettings::height).orElse(CaveLavaHeightSettings.DEFAULT_HEIGHT));
|
||||
lavaHeight);
|
||||
}
|
||||
|
||||
static boolean acceptsAnchorFluid(
|
||||
boolean underwater,
|
||||
MatterCavern cavern,
|
||||
CarvedVoid carved,
|
||||
int mantleY,
|
||||
int defaultLavaHeight
|
||||
) {
|
||||
if (cavern == null || !cavern.isCavern()) {
|
||||
if (carved == null) {
|
||||
return false;
|
||||
}
|
||||
if (underwater) {
|
||||
return true;
|
||||
}
|
||||
if (cavern.getLiquid() == LIQUID_FORCED_AIR) {
|
||||
if (carved.fill() == CarvedVoid.Fill.AIR) {
|
||||
return true;
|
||||
}
|
||||
return cavern.isAir() && mantleY > defaultLavaHeight;
|
||||
return carved.fill() == CarvedVoid.Fill.OPEN && mantleY > defaultLavaHeight;
|
||||
}
|
||||
|
||||
private static MatterCavern cavernAt(Engine engine, int blockX, int mantleY, int blockZ) {
|
||||
return engine.getMantle().getMantle().get(blockX, mantleY, blockZ, MatterCavern.class);
|
||||
private static Optional<CarvedVoid> carvedAt(PackWorld world, int blockX, int mantleY, int blockZ) {
|
||||
return StructureWorld.running(world).carvedAt(blockX, mantleY, blockZ);
|
||||
}
|
||||
|
||||
static int toMantleY(int worldY, int worldMinHeight) {
|
||||
@@ -322,7 +324,7 @@ public final class StructureCaveAnchorResolver {
|
||||
}
|
||||
|
||||
private static boolean matchesBiome(
|
||||
Engine engine,
|
||||
PackWorld world,
|
||||
StructurePlacement placement,
|
||||
int blockX,
|
||||
int mantleY,
|
||||
@@ -331,11 +333,11 @@ public final class StructureCaveAnchorResolver {
|
||||
if (placement.caveBiomes().isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
IrisBiome biome = engine.getCaveOrMantleBiome(blockX, mantleY, blockZ);
|
||||
if (biome == null || biome.getLoadKey() == null) {
|
||||
Optional<ResourceId> biome = caveOrCarvedBiome(world, blockX, mantleY, blockZ);
|
||||
if (biome.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
String actual = biome.getLoadKey().toLowerCase(Locale.ROOT);
|
||||
String actual = StructureWorld.keyOf(world, biome.get()).toLowerCase(Locale.ROOT);
|
||||
for (String allowed : placement.caveBiomes()) {
|
||||
if (matchesBiomeKey(actual, allowed)) {
|
||||
return true;
|
||||
@@ -344,6 +346,15 @@ public final class StructureCaveAnchorResolver {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** The biome the carver gave the void at the block, else the cave biome of the column at that height. */
|
||||
private static Optional<ResourceId> caveOrCarvedBiome(PackWorld world, int blockX, int mantleY, int blockZ) {
|
||||
Optional<ResourceId> carvedBiome = carvedAt(world, blockX, mantleY, blockZ).flatMap(CarvedVoid::biome);
|
||||
if (carvedBiome.isPresent()) {
|
||||
return carvedBiome;
|
||||
}
|
||||
return StructureWorld.running(world).layout().caveBiome(blockX, mantleY, blockZ);
|
||||
}
|
||||
|
||||
static boolean matchesBiomeKey(String actual, String allowed) {
|
||||
if (actual == null || actual.isBlank() || allowed == null || allowed.isBlank()) {
|
||||
return false;
|
||||
|
||||
@@ -2,16 +2,20 @@ package art.arcane.iris.engine.framework;
|
||||
|
||||
import art.arcane.iris.builtin.structure.StructurePlacement;
|
||||
import art.arcane.iris.builtin.structure.StructurePlacementSettings;
|
||||
import art.arcane.iris.core.loader.IrisRegistrant;
|
||||
import art.arcane.iris.engine.IrisComplex;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.world.region.IrisRegion;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.iris.engine.framework.structure.StructureWorld;
|
||||
import com.volmit.config.FeatureSettings;
|
||||
import com.volmit.config.Level;
|
||||
import com.volmit.config.SettingsStack;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.world.PackWorld;
|
||||
import com.volmit.world.RunningWorld;
|
||||
import com.volmit.world.TerrainSampler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@@ -20,79 +24,78 @@ import java.util.Set;
|
||||
* region lookups a pack never needs.
|
||||
*/
|
||||
public final class StructurePlacementScope {
|
||||
private static final int CHUNK_CENTER_OFFSET_BLOCKS = 8;
|
||||
|
||||
private StructurePlacementScope() {
|
||||
}
|
||||
|
||||
/** The placements {@code owner} declares in its {@code "structures"} settings; empty for none. */
|
||||
public static List<StructurePlacement> placementsOf(IrisRegistrant owner) {
|
||||
if (owner == null) {
|
||||
return List.of();
|
||||
}
|
||||
return owner.getModuleSettings().find(StructurePlacementSettings.class)
|
||||
.map(StructurePlacementSettings::placements)
|
||||
.orElse(List.of());
|
||||
/** The placements {@code settings} declare; empty for none. */
|
||||
public static List<StructurePlacement> placementsOf(Optional<StructurePlacementSettings> settings) {
|
||||
return settings.map(StructurePlacementSettings::placements).orElse(List.of());
|
||||
}
|
||||
|
||||
public static KList<StructurePlacement> placementsAt(Engine engine, int chunkX, int chunkZ) {
|
||||
Engine activeEngine = Objects.requireNonNull(engine, "Structure placement scope requires an engine");
|
||||
IrisComplex complex = activeEngine.getComplex();
|
||||
int blockX = (chunkX << 4) + 8;
|
||||
int blockZ = (chunkZ << 4) + 8;
|
||||
KList<StructurePlacement> placements = new KList<>();
|
||||
public static List<StructurePlacement> placementsAt(PackWorld world, int chunkX, int chunkZ) {
|
||||
RunningWorld running = StructureWorld.running(world);
|
||||
int blockX = (chunkX << 4) + CHUNK_CENTER_OFFSET_BLOCKS;
|
||||
int blockZ = (chunkZ << 4) + CHUNK_CENTER_OFFSET_BLOCKS;
|
||||
List<StructurePlacement> placements = new ArrayList<>();
|
||||
Set<StructurePlacement> seen = Collections.newSetFromMap(new IdentityHashMap<>());
|
||||
ScopeIndex index = scopeIndex(activeEngine);
|
||||
if (complex != null) {
|
||||
if (index.biome()) {
|
||||
IrisBiome biome = complex.getTrueBiomeStream().get(blockX, blockZ);
|
||||
addUnique(placements, seen, placementsOf(biome));
|
||||
}
|
||||
if (index.caveBiome()) {
|
||||
IrisBiome caveBiome = complex.getCaveBiomeStream().get(blockX, blockZ);
|
||||
addCaveUnique(placements, seen, placementsOf(caveBiome));
|
||||
}
|
||||
if (index.region()) {
|
||||
IrisRegion region = complex.getRegionStream().get(blockX, blockZ);
|
||||
addUnique(placements, seen, placementsOf(region));
|
||||
}
|
||||
}
|
||||
if (index.dimension()) {
|
||||
addUnique(placements, seen, placementsOf(activeEngine.getDimension()));
|
||||
ScopeIndex index = world.state(ScopeIndex.class, StructurePlacementScope::buildScopeIndex);
|
||||
if (index.declaresBelowDimension()) {
|
||||
addColumnPlacements(placements, seen, running, index, blockX, blockZ);
|
||||
}
|
||||
addUnique(placements, seen, index.dimensionPlacements());
|
||||
return placements;
|
||||
}
|
||||
|
||||
private static ScopeIndex scopeIndex(Engine engine) {
|
||||
return engine.getGeneration().state(ScopeIndex.class, StructurePlacementScope::buildScopeIndex);
|
||||
private static void addColumnPlacements(List<StructurePlacement> placements, Set<StructurePlacement> seen,
|
||||
RunningWorld running, ScopeIndex index, int blockX, int blockZ) {
|
||||
SettingsStack<StructurePlacementSettings> declared = running.settings().at(StructurePlacementSettings.class, blockX, blockZ);
|
||||
if (index.biome()) {
|
||||
addUnique(placements, seen, placementsOf(declared.level(Level.BIOME)));
|
||||
}
|
||||
if (index.caveBiome()) {
|
||||
addCaveUnique(placements, seen, placementsOf(caveBiomeSettings(running, blockX, blockZ)));
|
||||
}
|
||||
if (index.region()) {
|
||||
addUnique(placements, seen, placementsOf(declared.level(Level.REGION)));
|
||||
}
|
||||
}
|
||||
|
||||
private static ScopeIndex buildScopeIndex(Engine engine) {
|
||||
private static Optional<StructurePlacementSettings> caveBiomeSettings(RunningWorld running, int blockX, int blockZ) {
|
||||
TerrainSampler layout = running.layout();
|
||||
ResourceId surfaceBiome = layout.surfaceBiome(blockX, blockZ);
|
||||
Optional<ResourceId> caveBiome = layout.caveBiome(blockX, layout.bounds().minY(), blockZ)
|
||||
.filter(cave -> !cave.equals(surfaceBiome));
|
||||
FeatureSettings settings = running.settings();
|
||||
return caveBiome.flatMap(cave -> settings.declaredBy(cave, StructurePlacementSettings.class));
|
||||
}
|
||||
|
||||
private static ScopeIndex buildScopeIndex(PackWorld world) {
|
||||
boolean biome = false;
|
||||
boolean caveBiome = false;
|
||||
KList<IrisBiome> allBiomes = engine.getAllBiomes();
|
||||
if (allBiomes == null) {
|
||||
biome = true;
|
||||
caveBiome = true;
|
||||
} else {
|
||||
for (IrisBiome candidate : allBiomes) {
|
||||
List<StructurePlacement> structures = placementsOf(candidate);
|
||||
if (structures.isEmpty()) {
|
||||
continue;
|
||||
boolean region = false;
|
||||
List<StructurePlacement> dimensionPlacements = List.of();
|
||||
for (var entry : world.settings().declared(StructurePlacementSettings.class)) {
|
||||
List<StructurePlacement> placements = entry.value().placements();
|
||||
if (placements.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
switch (entry.level()) {
|
||||
case BIOME -> {
|
||||
biome = true;
|
||||
caveBiome |= placements.stream().anyMatch(placement -> placement.resolvedAnchor().isCave());
|
||||
}
|
||||
case REGION -> region = true;
|
||||
case DIMENSION -> dimensionPlacements = placements;
|
||||
default -> {
|
||||
}
|
||||
biome = true;
|
||||
caveBiome |= structures.stream().anyMatch(placement -> placement.resolvedAnchor().isCave());
|
||||
}
|
||||
}
|
||||
boolean region = false;
|
||||
if (engine.getDimension() != null) {
|
||||
KList<IrisRegion> allRegions = engine.getDimension().getAllRegions(engine);
|
||||
region = allRegions == null
|
||||
|| allRegions.stream().anyMatch(candidate -> !placementsOf(candidate).isEmpty());
|
||||
}
|
||||
boolean dimension = !placementsOf(engine.getDimension()).isEmpty();
|
||||
return new ScopeIndex(biome, caveBiome, region, dimension);
|
||||
return new ScopeIndex(biome, caveBiome, region, dimensionPlacements);
|
||||
}
|
||||
|
||||
private static void addUnique(KList<StructurePlacement> destination, Set<StructurePlacement> seen,
|
||||
private static void addUnique(List<StructurePlacement> destination, Set<StructurePlacement> seen,
|
||||
List<StructurePlacement> source) {
|
||||
for (StructurePlacement placement : source) {
|
||||
if (placement != null && seen.add(placement)) {
|
||||
@@ -101,7 +104,7 @@ public final class StructurePlacementScope {
|
||||
}
|
||||
}
|
||||
|
||||
private static void addCaveUnique(KList<StructurePlacement> destination, Set<StructurePlacement> seen,
|
||||
private static void addCaveUnique(List<StructurePlacement> destination, Set<StructurePlacement> seen,
|
||||
List<StructurePlacement> source) {
|
||||
for (StructurePlacement placement : source) {
|
||||
if (placement != null && placement.resolvedAnchor().isCave() && seen.add(placement)) {
|
||||
@@ -110,6 +113,9 @@ public final class StructurePlacementScope {
|
||||
}
|
||||
}
|
||||
|
||||
private record ScopeIndex(boolean biome, boolean caveBiome, boolean region, boolean dimension) {
|
||||
record ScopeIndex(boolean biome, boolean caveBiome, boolean region, List<StructurePlacement> dimensionPlacements) {
|
||||
boolean declaresBelowDimension() {
|
||||
return biome || caveBiome || region;
|
||||
}
|
||||
}
|
||||
}
|
||||
+15
-18
@@ -18,9 +18,9 @@
|
||||
|
||||
package art.arcane.iris.engine.framework.structure;
|
||||
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.StructurePlacementGrid;
|
||||
import art.arcane.iris.engine.framework.StructurePlacementScope;
|
||||
import com.volmit.world.PackWorld;
|
||||
import art.arcane.iris.builtin.structure.StructureAnchorMode;
|
||||
import art.arcane.iris.builtin.structure.StructurePlacement;
|
||||
import art.arcane.iris.builtin.structure.NativeStructureSource;
|
||||
@@ -48,10 +48,10 @@ public final class NativeStartPlanner {
|
||||
public record Plan(StructurePlacement placement, NativeStructureSource source, int chunkX, int chunkZ, int baseY) {
|
||||
}
|
||||
|
||||
public static List<Plan> plansAt(Engine engine, int chunkX, int chunkZ) {
|
||||
public static List<Plan> plansAt(PackWorld world, int chunkX, int chunkZ) {
|
||||
Map<String, Plan> plansByStructure = new LinkedHashMap<>();
|
||||
for (StructurePlacement placement : StructurePlacementScope.placementsAt(engine, chunkX, chunkZ)) {
|
||||
Plan plan = planAt(engine, placement, chunkX, chunkZ);
|
||||
for (StructurePlacement placement : StructurePlacementScope.placementsAt(world, chunkX, chunkZ)) {
|
||||
Plan plan = planAt(world, placement, chunkX, chunkZ);
|
||||
if (plan == null) {
|
||||
continue;
|
||||
}
|
||||
@@ -64,23 +64,20 @@ public final class NativeStartPlanner {
|
||||
return List.copyOf(plansByStructure.values());
|
||||
}
|
||||
|
||||
public static Plan planAt(Engine engine, StructurePlacement placement, int chunkX, int chunkZ) {
|
||||
public static Plan planAt(PackWorld world, StructurePlacement 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();
|
||||
Objects.requireNonNull(world, "Native structure planner requires a world");
|
||||
long mantleSeed = StructureWorld.placementSeed(world);
|
||||
if (!StructurePlacementGrid.startsInChunk(placement, chunkX, chunkZ, mantleSeed)) {
|
||||
return null;
|
||||
}
|
||||
RNG placementRng = StructurePlacementGrid.placementRng(
|
||||
placement, chunkX, chunkZ, mantleSeed).nextParallelRNG(NATIVE_SELECTION_DOMAIN);
|
||||
NativeStructureSource source = selectSource(placement.nativeStructures(), placementRng);
|
||||
Integer baseY = resolveBaseY(activeEngine, placement, chunkX, chunkZ, placementRng);
|
||||
Integer baseY = resolveBaseY(world, placement, chunkX, chunkZ, placementRng);
|
||||
if (baseY == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -102,8 +99,8 @@ public final class NativeStartPlanner {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isSubmerged(Engine engine, int blockX, int blockZ) {
|
||||
return engine.getHeight(blockX, blockZ, true) < engine.getDimension().getFluidHeight();
|
||||
public static boolean isSubmerged(PackWorld world, int blockX, int blockZ) {
|
||||
return StructureWorld.highestAboveBottom(world, blockX, blockZ) < StructureWorld.fluidHeightAboveBottom(world);
|
||||
}
|
||||
|
||||
static NativeStructureSource selectSource(List<NativeStructureSource> sources, RNG rng) {
|
||||
@@ -133,20 +130,20 @@ public final class NativeStartPlanner {
|
||||
throw new IllegalStateException("Native structure source selection produced no result");
|
||||
}
|
||||
|
||||
private static Integer resolveBaseY(Engine engine, StructurePlacement placement,
|
||||
private static Integer resolveBaseY(PackWorld world, StructurePlacement placement,
|
||||
int chunkX, int chunkZ, RNG rng) {
|
||||
int worldMin = engine.getMinHeight() + 1;
|
||||
int worldMax = engine.getMinHeight() + engine.getHeight() - 1;
|
||||
int worldMin = world.minWorldY() + 1;
|
||||
int worldMax = world.minWorldY() + StructureWorld.height(world) - 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.underwater() && isSubmerged(engine, blockX, blockZ)) {
|
||||
if (!placement.underwater() && isSubmerged(world, blockX, blockZ)) {
|
||||
return null;
|
||||
}
|
||||
if (!placement.underground()) {
|
||||
int surfaceY = engine.getHeight(blockX, blockZ, true) + engine.getMinHeight();
|
||||
int surfaceY = StructureWorld.highest(world, blockX, blockZ);
|
||||
if (surfaceY < placement.minHeight() || surfaceY > placement.maxHeight()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
+10
-17
@@ -18,7 +18,6 @@
|
||||
|
||||
package art.arcane.iris.engine.framework.structure;
|
||||
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.IrisStructureLocator;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
@@ -52,43 +51,41 @@ public final class StructureLocating implements StructureLocator {
|
||||
|
||||
@Override
|
||||
public Set<ResourceId> locatable(PackWorld world) {
|
||||
return idsOf(world.resources(), IrisStructureLocator.locatableEditableKeys(engine(world)));
|
||||
return idsOf(world.resources(), IrisStructureLocator.locatableEditableKeys(world));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<ResourceId> placed(PackWorld world) {
|
||||
return idsOf(world.resources(), IrisStructureLocator.placedKeysAndAliases(engine(world)));
|
||||
return idsOf(world.resources(), IrisStructureLocator.placedKeysAndAliases(world));
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocateResult locate(PackWorld world, ResourceId structure, int fromX, int fromZ, int maxRadiusChunks) {
|
||||
Engine engine = engine(world);
|
||||
String key = keyOf(world.resources(), IrisStructureLocator.placedKeysAndAliases(engine), structure);
|
||||
return apiResult(engine, IrisStructureLocator.locate(engine, key, fromX, fromZ, maxRadiusChunks));
|
||||
String key = keyOf(world.resources(), IrisStructureLocator.placedKeysAndAliases(world), structure);
|
||||
return apiResult(world, IrisStructureLocator.locate(world, key, fromX, fromZ, maxRadiusChunks));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<ResourceId> startedStructures(PackWorld world) {
|
||||
return platformIds(IrisStructureLocator.nativeKeys(engine(world)));
|
||||
return platformIds(IrisStructureLocator.nativeKeys(world));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<ResourceId> locatableStarts(PackWorld world) {
|
||||
return platformIds(IrisStructureLocator.locatableNativeKeys(engine(world)));
|
||||
return platformIds(IrisStructureLocator.locatableNativeKeys(world));
|
||||
}
|
||||
|
||||
/** Searches the rings of the placements that start {@code structure} natively, as the platform's own locate does. */
|
||||
@Override
|
||||
public LocateResult locateStart(PackWorld world, ResourceId structure, int fromX, int fromZ, int maxRings,
|
||||
ChunkFilter accepts) {
|
||||
Engine engine = engine(world);
|
||||
return apiResult(engine, IrisStructureLocator.locateInPlacementRings(
|
||||
engine, structure.toString(), fromX, fromZ, maxRings, accepts::accepts));
|
||||
return apiResult(world, IrisStructureLocator.locateInPlacementRings(
|
||||
world, structure.toString(), fromX, fromZ, maxRings, accepts::accepts));
|
||||
}
|
||||
|
||||
private static LocateResult apiResult(Engine engine, IrisStructureLocator.LocateResult result) {
|
||||
private static LocateResult apiResult(PackWorld world, IrisStructureLocator.LocateResult result) {
|
||||
return switch (result.status()) {
|
||||
case FOUND -> LocateResult.found(new BlockPosition(result.originX(), result.baseY() - engine.getMinHeight(), result.originZ()));
|
||||
case FOUND -> LocateResult.found(new BlockPosition(result.originX(), result.baseY() - world.minWorldY(), result.originZ()));
|
||||
case NOT_FOUND -> LocateResult.NOT_FOUND;
|
||||
case SEARCH_LIMIT_REACHED -> LocateResult.SEARCH_LIMIT_REACHED;
|
||||
};
|
||||
@@ -102,10 +99,6 @@ public final class StructureLocating implements StructureLocator {
|
||||
return ids;
|
||||
}
|
||||
|
||||
private static Engine engine(PackWorld world) {
|
||||
return world.extension(Engine.class).orElseThrow();
|
||||
}
|
||||
|
||||
private static Set<ResourceId> idsOf(PackResources pack, Collection<String> keys) {
|
||||
Set<ResourceId> ids = new LinkedHashSet<>();
|
||||
for (String key : keys) {
|
||||
|
||||
+6
-11
@@ -18,7 +18,6 @@
|
||||
|
||||
package art.arcane.iris.engine.framework.structure;
|
||||
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.IrisStructureLocator;
|
||||
import art.arcane.iris.engine.framework.structure.fit.StartLayouts;
|
||||
import art.arcane.iris.engine.framework.structure.fit.StructureFitting;
|
||||
@@ -56,20 +55,20 @@ public final class StructureVanillaStructures implements VanillaStructures {
|
||||
*/
|
||||
@Override
|
||||
public VanillaStructureRule rule(ResourceId structure, VanillaStructureContext context) {
|
||||
Engine engine = context.settings().extension(Engine.class).orElseThrow();
|
||||
PackWorld world = context.world().orElseThrow();
|
||||
String key = structure.toString();
|
||||
boolean replaced = IrisStructureLocator.suppressesVanilla(engine, key);
|
||||
boolean replaced = IrisStructureLocator.suppressesVanilla(world, key);
|
||||
boolean blocked = replaced || ImportedStructures.of(context.settings()).disables(key);
|
||||
boolean placed = replaced || IrisStructureLocator.isPlaced(engine, key);
|
||||
boolean placed = replaced || IrisStructureLocator.isPlaced(world, key);
|
||||
VanillaStructureRule rule = blocked ? VanillaStructureRule.BLOCK : VanillaStructureRule.GENERATE;
|
||||
return placed ? rule.and(VanillaStructureRule.ALSO_PLACE) : rule;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<VanillaStructureStart> starts(int chunkX, int chunkZ, VanillaStructureStartContext context) {
|
||||
Engine engine = engine(context.world());
|
||||
return NativeStartPlanner.plansAt(engine, chunkX, chunkZ).stream()
|
||||
.map(plan -> start(plan, engine.getMinHeight()))
|
||||
PackWorld world = context.world();
|
||||
return NativeStartPlanner.plansAt(world, chunkX, chunkZ).stream()
|
||||
.map(plan -> start(plan, world.minWorldY()))
|
||||
.toList();
|
||||
}
|
||||
|
||||
@@ -102,10 +101,6 @@ public final class StructureVanillaStructures implements VanillaStructures {
|
||||
return ImportedStructures.of(context.settings()).setup();
|
||||
}
|
||||
|
||||
private static Engine engine(PackWorld world) {
|
||||
return world.extension(Engine.class).orElseThrow();
|
||||
}
|
||||
|
||||
/** {@code plan} as the start the platform generates: heights above the bottom and the placement's fit. */
|
||||
static VanillaStructureStart start(NativeStartPlanner.Plan plan, int minHeight) {
|
||||
StructurePlacement placement = plan.placement();
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package art.arcane.iris.engine.framework.structure;
|
||||
|
||||
import art.arcane.iris.builtin.structure.StructureSeeds;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.world.PackWorld;
|
||||
import com.volmit.world.RunningWorld;
|
||||
|
||||
/**
|
||||
* What structure placement asks a world about its size, its seed and its terrain. Heights here are the world's own
|
||||
* (absolute) Y unless a method says it is above the dimension's bottom.
|
||||
*/
|
||||
public final class StructureWorld {
|
||||
private StructureWorld() {
|
||||
}
|
||||
|
||||
public static RunningWorld running(PackWorld world) {
|
||||
return world.running().orElseThrow(() -> new IllegalStateException("Structure placement requires a running world"));
|
||||
}
|
||||
|
||||
/** The key the pack's files name {@code id} by: its path in the pack's own namespace, the whole id in another. */
|
||||
public static String keyOf(PackWorld world, ResourceId id) {
|
||||
return id.namespace().equals(world.resources().packId().namespace()) ? id.path() : id.toString();
|
||||
}
|
||||
|
||||
/** The seed placements start from. */
|
||||
public static long placementSeed(PackWorld world) {
|
||||
return world.seed(StructureSeeds.PLACEMENT);
|
||||
}
|
||||
|
||||
/** How many blocks high the world is. */
|
||||
public static int height(PackWorld world) {
|
||||
var bounds = running(world).layout().bounds();
|
||||
return bounds.maxY() - bounds.minY();
|
||||
}
|
||||
|
||||
/** The highest block of the column, with what objects and structures added, above the dimension's bottom. */
|
||||
public static int highestAboveBottom(PackWorld world, int blockX, int blockZ) {
|
||||
return running(world).highest(blockX, blockZ, true);
|
||||
}
|
||||
|
||||
/** The highest block of the column in world Y. */
|
||||
public static int highest(PackWorld world, int blockX, int blockZ) {
|
||||
return highestAboveBottom(world, blockX, blockZ) + world.minWorldY();
|
||||
}
|
||||
|
||||
/** The height up to which the dimension is filled with fluid, above the dimension's bottom. */
|
||||
public static int fluidHeightAboveBottom(PackWorld world) {
|
||||
return running(world).layout().fluidHeight();
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -91,7 +91,8 @@ public final class StructureFitting {
|
||||
private void prepare() {
|
||||
vacuumFoundations = SurfaceFitting.prepareSurfaceStructures(blocks, area, starts, surfaceHeight,
|
||||
SurfaceFitting.MAX_SURFACE_TEMPLATE_CELLS, fit.log());
|
||||
TerrainIntegration.prepareTerrain(blocks, area, starts, fit.seed(), this::naturalBlock, this::paletteBlock);
|
||||
TerrainIntegration.prepareTerrain(blocks, area, starts, fit.seed(), fit.world().resources().noise(),
|
||||
this::naturalBlock, this::paletteBlock);
|
||||
RigidSupport.bridgeRigidPieceSupport(blocks, area, starts);
|
||||
}
|
||||
|
||||
|
||||
+26
-23
@@ -23,10 +23,11 @@ import art.arcane.iris.builtin.structure.StructureTerrain;
|
||||
import art.arcane.iris.builtin.structure.StructureTerrainMode;
|
||||
import art.arcane.iris.engine.mantle.components.StructureCarveEnvelope;
|
||||
import art.arcane.iris.engine.mantle.components.StructureCarvingFootprint;
|
||||
import art.arcane.iris.util.project.noise.CNG;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.block.PaletteSpec;
|
||||
import com.volmit.noise.NoiseFactory;
|
||||
import com.volmit.noise.NoiseSampler;
|
||||
import com.volmit.noise.NoiseStyle;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.vanilla.TerrainAdaptation;
|
||||
import com.volmit.geometry.BlockPosition;
|
||||
@@ -49,6 +50,9 @@ final class TerrainIntegration {
|
||||
private static final long CARVE_CEILING_ROLL_SIGNATURE = 0x2A17L;
|
||||
private static final long CARVE_FLOOR_ROLL_SIGNATURE = 0x5B3DL;
|
||||
private static final long CARVE_LOBE_SIGNATURE = 0x7C41L;
|
||||
private static final NoiseStyle SIGNATURE_NOISE = NoiseStyle.of("IRIS");
|
||||
/** The lobes want a plain single octave channel: the fractured signature noise has no usable low frequency band. */
|
||||
private static final NoiseStyle SINGLE_OCTAVE_NOISE = NoiseStyle.of("SIMPLEX");
|
||||
private static final long CARVE_IDENTITY_X = 341873128712L;
|
||||
private static final long CARVE_IDENTITY_Z = 132897987541L;
|
||||
private static final int SOURCE_BURY_HORIZONTAL_RADIUS = 6;
|
||||
@@ -83,14 +87,14 @@ final class TerrainIntegration {
|
||||
* Integrates the terrain of every start, then clears the legacy template air of those that replay their own
|
||||
* adaptation or are encased. The natural material SOURCE fills with is read once for all starts, before any fill.
|
||||
*/
|
||||
static void prepareTerrain(FitBlocks blocks, Box area, List<FitStart> starts, long seed,
|
||||
static void prepareTerrain(FitBlocks blocks, Box area, List<FitStart> starts, long seed, NoiseFactory noise,
|
||||
IntFunction<BlockState> naturalBlock, FitPalettes palettes) {
|
||||
if (starts.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
SourceTerrainSnapshot sourceTerrain = captureSourceTerrain(blocks, area, starts);
|
||||
for (FitStart start : starts) {
|
||||
integrateTerrain(blocks, area, start, seed, naturalBlock, palettes, sourceTerrain);
|
||||
integrateTerrain(blocks, area, start, seed, noise, naturalBlock, palettes, sourceTerrain);
|
||||
}
|
||||
for (FitStart start : starts) {
|
||||
if (clearsLegacyTemplateAir(start)) {
|
||||
@@ -99,7 +103,7 @@ final class TerrainIntegration {
|
||||
}
|
||||
}
|
||||
|
||||
static void integrateTerrain(FitBlocks blocks, Box area, FitStart start, long seed,
|
||||
static void integrateTerrain(FitBlocks blocks, Box area, FitStart start, long seed, NoiseFactory noise,
|
||||
IntFunction<BlockState> naturalBlock, FitPalettes palettes,
|
||||
SourceTerrainSnapshot sourceTerrain) {
|
||||
StructureTerrain terrain = start.terrain();
|
||||
@@ -109,11 +113,12 @@ final class TerrainIntegration {
|
||||
case PRESERVE, VACUUM -> {
|
||||
}
|
||||
case ENCASE -> encasePieces(blocks, area, start, terrain, seed, naturalBlock, palettes);
|
||||
case BORE, FORCE_CARVE -> carve(blocks, area, start, terrain, seed);
|
||||
case BORE, FORCE_CARVE -> carve(blocks, area, start, terrain, seed, noise);
|
||||
}
|
||||
}
|
||||
|
||||
private static void carve(FitBlocks blocks, Box area, FitStart start, StructureTerrain terrain, long seed) {
|
||||
private static void carve(FitBlocks blocks, Box area, FitStart start, StructureTerrain terrain, long seed,
|
||||
NoiseFactory noise) {
|
||||
StructureCarveShape shape = terrain.resolvedMode() == StructureTerrainMode.BORE
|
||||
? StructureCarveShape.BOX : terrain.resolvedShape();
|
||||
if (shape == StructureCarveShape.BOX) {
|
||||
@@ -122,7 +127,7 @@ final class TerrainIntegration {
|
||||
}
|
||||
carveOrganicColumns(blocks, area, organicCarve(
|
||||
CarveFootprints.of(start, Math.max(0, terrain.horizontalPadding())),
|
||||
terrain, shape, carveNoiseIdentity(seed, start)));
|
||||
terrain, shape, carveNoiseIdentity(seed, start), noise));
|
||||
}
|
||||
|
||||
static SourceTerrainSnapshot captureSourceTerrain(FitBlocks blocks, Box area, List<FitStart> starts) {
|
||||
@@ -404,22 +409,20 @@ final class TerrainIntegration {
|
||||
}
|
||||
|
||||
static OrganicCarve organicCarve(StructureCarvingFootprint footprint, StructureTerrain terrain,
|
||||
StructureCarveShape shape, long identity) {
|
||||
StructureCarveShape shape, long identity, NoiseFactory noise) {
|
||||
double strength = terrain.resolvedErosionStrength();
|
||||
double lobeStrength = terrain.resolvedLobeStrength();
|
||||
RNG noiseRng = new RNG(identity);
|
||||
CNG blob = null;
|
||||
CNG ceilingRoll = null;
|
||||
CNG floorRoll = null;
|
||||
CNG lobe = null;
|
||||
NoiseSampler blob = null;
|
||||
NoiseSampler ceilingRoll = null;
|
||||
NoiseSampler floorRoll = null;
|
||||
NoiseSampler lobe = null;
|
||||
if (shape == StructureCarveShape.ERODED && strength > 0D) {
|
||||
blob = CNG.signature(noiseRng);
|
||||
ceilingRoll = CNG.signature(noiseRng.nextParallelRNG(CARVE_CEILING_ROLL_SIGNATURE));
|
||||
floorRoll = CNG.signature(noiseRng.nextParallelRNG(CARVE_FLOOR_ROLL_SIGNATURE));
|
||||
blob = noise.sampler(SIGNATURE_NOISE, identity);
|
||||
ceilingRoll = noise.sampler(SIGNATURE_NOISE, identity + CARVE_CEILING_ROLL_SIGNATURE);
|
||||
floorRoll = noise.sampler(SIGNATURE_NOISE, identity + CARVE_FLOOR_ROLL_SIGNATURE);
|
||||
}
|
||||
if (shape == StructureCarveShape.ERODED && lobeStrength > 0D) {
|
||||
// A plain single octave channel: the fractured signature noise has no usable low frequency band.
|
||||
lobe = new CNG(noiseRng.nextParallelRNG(CARVE_LOBE_SIGNATURE), 1D, 1);
|
||||
lobe = noise.sampler(SINGLE_OCTAVE_NOISE, identity + CARVE_LOBE_SIGNATURE);
|
||||
}
|
||||
return new OrganicCarve(footprint, shape,
|
||||
Math.max(0, terrain.horizontalPadding()),
|
||||
@@ -474,10 +477,10 @@ final class TerrainIntegration {
|
||||
continue;
|
||||
}
|
||||
if (distanceSquared > 0D && eroded) {
|
||||
double noise = carve.blob().fitDouble(0D, 1D,
|
||||
double blobSample = carve.blob().sample(
|
||||
x * carve.frequency(), y * carve.frequency(), z * carve.frequency());
|
||||
if (!StructureCarveEnvelope.shouldCarveOverboreCell(
|
||||
carve.shape(), distanceSquared, noise, carve.strength())) {
|
||||
carve.shape(), distanceSquared, blobSample, carve.strength())) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -627,7 +630,7 @@ final class TerrainIntegration {
|
||||
|
||||
record OrganicCarve(StructureCarvingFootprint footprint, StructureCarveShape shape,
|
||||
int horizontalPadding, int ceilingPadding, int floorPadding,
|
||||
double strength, double frequency, CNG blob, CNG ceilingRoll, CNG floorRoll,
|
||||
CNG lobe, double lobeFrequency, double lobeStrength) {
|
||||
double strength, double frequency, NoiseSampler blob,
|
||||
NoiseSampler ceilingRoll, NoiseSampler floorRoll, NoiseSampler lobe, double lobeFrequency, double lobeStrength) {
|
||||
}
|
||||
}
|
||||
@@ -41,6 +41,8 @@ import art.arcane.volmlib.util.math.RNG;
|
||||
import art.arcane.volmlib.util.matter.Matter;
|
||||
import art.arcane.volmlib.util.matter.MatterCavern;
|
||||
import art.arcane.volmlib.util.matter.MatterSlice;
|
||||
import art.arcane.volmlib.util.matter.MatterStructurePOI;
|
||||
import art.arcane.iris.engine.framework.TreeBlockMaterial;
|
||||
import art.arcane.iris.util.project.noise.CNG;
|
||||
import art.arcane.iris.util.common.scheduling.J;
|
||||
import lombok.AccessLevel;
|
||||
@@ -373,6 +375,14 @@ public class MantleWriter implements IObjectPlacer, AutoCloseable {
|
||||
matter.getSlice(type).set(x & 15, y & 15, z & 15, null);
|
||||
}
|
||||
|
||||
/** Takes back the placement marker, tree material, block entity and point of interest kept beside the block. */
|
||||
public void clearAttached(int x, int y, int z) {
|
||||
clearData(x, y, z, String.class);
|
||||
clearData(x, y, z, TreeBlockMaterial.class);
|
||||
clearData(x, y, z, TileWrapper.class);
|
||||
clearData(x, y, z, MatterStructurePOI.class);
|
||||
}
|
||||
|
||||
private static void clearDeferredPlacement(Matter matter, int x, int y, int z) {
|
||||
if (matter.hasSlice(Identifier.class)) {
|
||||
matter.<Identifier>getSlice(Identifier.class).set(x & 15, y & 15, z & 15, null);
|
||||
|
||||
+10
-11
@@ -19,7 +19,7 @@
|
||||
package art.arcane.iris.engine.mantle.components;
|
||||
|
||||
import art.arcane.iris.builtin.structure.StructureCarveShape;
|
||||
import art.arcane.iris.util.project.noise.CNG;
|
||||
import com.volmit.noise.NoiseSampler;
|
||||
|
||||
/**
|
||||
* Carve envelope math shared by the Iris-assembled structure path and the native (vanilla template)
|
||||
@@ -44,7 +44,7 @@ public final class StructureCarveEnvelope {
|
||||
* stays inside the footprint bounds the carve was sized against and never falls below
|
||||
* {@code horizontalPadding * (1 - lobeStrength)}.
|
||||
*/
|
||||
public static double lobedSideReach(CNG lobe, double lobeFrequency, double lobeStrength,
|
||||
public static double lobedSideReach(NoiseSampler lobe, double lobeFrequency, double lobeStrength,
|
||||
int x, int z, int horizontalPadding) {
|
||||
if (horizontalPadding <= 0) {
|
||||
return 0D;
|
||||
@@ -56,7 +56,7 @@ public final class StructureCarveEnvelope {
|
||||
* Ceiling counterpart of {@link #lobedSideReach}, deliberately half as strong so the roof swells
|
||||
* with the same lobes without collapsing onto the pieces.
|
||||
*/
|
||||
public static double lobedUpReach(CNG lobe, double lobeFrequency, double lobeStrength,
|
||||
public static double lobedUpReach(NoiseSampler lobe, double lobeFrequency, double lobeStrength,
|
||||
int x, int z, double upReach) {
|
||||
if (upReach <= 0D) {
|
||||
return upReach;
|
||||
@@ -65,19 +65,18 @@ public final class StructureCarveEnvelope {
|
||||
* lobeFactor(lobe, lobeFrequency, lobeStrength * CEILING_LOBE_RATIO, x, z));
|
||||
}
|
||||
|
||||
private static double lobeFactor(CNG lobe, double lobeFrequency, double lobeStrength,
|
||||
private static double lobeFactor(NoiseSampler lobe, double lobeFrequency, double lobeStrength,
|
||||
int x, int z) {
|
||||
double clampedStrength = Math.max(0D, Math.min(1D, lobeStrength));
|
||||
if (lobe == null || clampedStrength <= 0D) {
|
||||
return 1D;
|
||||
}
|
||||
double scaledFrequency = lobeFrequency * LOBE_FREQUENCY_SCALE;
|
||||
double sample = Math.max(0D, Math.min(1D, lobe.fitDouble(
|
||||
0D, 1D, x * scaledFrequency, z * scaledFrequency)));
|
||||
double sample = Math.max(0D, Math.min(1D, lobe.sample(x * scaledFrequency, z * scaledFrequency)));
|
||||
return 1D - clampedStrength * (1D - sample);
|
||||
}
|
||||
|
||||
public static double erodedUpReach(CNG roll, double frequency, double strength, int x, int z, int head) {
|
||||
public static double erodedUpReach(NoiseSampler roll, double frequency, double strength, int x, int z, int head) {
|
||||
if (head <= 0) {
|
||||
return 0D;
|
||||
}
|
||||
@@ -86,8 +85,8 @@ public final class StructureCarveEnvelope {
|
||||
return Math.max(1D, head);
|
||||
}
|
||||
double rollFrequency = frequency * CEILING_ROLL_FREQUENCY_RATIO;
|
||||
double sample = roll.fitDouble(0D, 1D, x * rollFrequency, z * rollFrequency) * 0.7D
|
||||
+ roll.fitDouble(0D, 1D, x * rollFrequency * 3D, z * rollFrequency * 3D) * 0.3D;
|
||||
double sample = roll.sample(x * rollFrequency, z * rollFrequency) * 0.7D
|
||||
+ roll.sample(x * rollFrequency * 3D, z * rollFrequency * 3D) * 0.3D;
|
||||
double contrast = Math.max(0D, Math.min(1D, (sample - 0.5D) * 2.6D + 0.5D));
|
||||
double roundedReach = Math.max(1D, head);
|
||||
double erodedReach = Math.max(1D, head * (0.4D + 1.4D * contrast));
|
||||
@@ -99,7 +98,7 @@ public final class StructureCarveEnvelope {
|
||||
* never exceeds the configured floor padding, so a padding of zero leaves every column standing on
|
||||
* its own supporting block instead of undermining the structure.
|
||||
*/
|
||||
public static double erodedDownReach(CNG roll, double frequency, double strength, int x, int z, int floorCut) {
|
||||
public static double erodedDownReach(NoiseSampler roll, double frequency, double strength, int x, int z, int floorCut) {
|
||||
if (floorCut <= 0) {
|
||||
return 0D;
|
||||
}
|
||||
@@ -108,7 +107,7 @@ public final class StructureCarveEnvelope {
|
||||
return floorCut;
|
||||
}
|
||||
double rollFrequency = frequency * FLOOR_ROLL_FREQUENCY_RATIO;
|
||||
double sample = roll.fitDouble(0D, 1D, x * rollFrequency, z * rollFrequency);
|
||||
double sample = roll.sample(x * rollFrequency, z * rollFrequency);
|
||||
return floorCut * (1D - clampedStrength * FLOOR_ROLL_AMPLITUDE * (1D - sample));
|
||||
}
|
||||
|
||||
|
||||
+10
-7
@@ -1,7 +1,9 @@
|
||||
package art.arcane.iris.engine.mantle.components;
|
||||
|
||||
import art.arcane.iris.engine.framework.structure.ColumnHeights;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import com.volmit.block.BlockRegistry;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.block.BlockTrait;
|
||||
|
||||
import java.util.function.IntConsumer;
|
||||
import java.util.function.IntPredicate;
|
||||
@@ -13,9 +15,9 @@ final class StructureFoundationPlanner {
|
||||
}
|
||||
|
||||
static void recordBaseCell(ColumnHeights columns, int x, int y, int z,
|
||||
PlatformBlockState state, boolean supportNonOccluding) {
|
||||
BlockState state, BlockRegistry blocks, boolean supportNonOccluding) {
|
||||
if (columns == null || state == null
|
||||
|| !(supportNonOccluding ? state.isSolid() : state.isOccluding())) {
|
||||
|| !blocks.hasTrait(state, supportNonOccluding ? BlockTrait.SOLID : BlockTrait.OCCLUDING)) {
|
||||
return;
|
||||
}
|
||||
long columnKey = pack(x, z);
|
||||
@@ -38,19 +40,20 @@ final class StructureFoundationPlanner {
|
||||
return NO_GROUND;
|
||||
}
|
||||
|
||||
static boolean isGroundSolid(PlatformBlockState overlay, boolean carved, int mantleY, int terrainHeight) {
|
||||
static boolean isGroundSolid(BlockState overlay, BlockRegistry blocks, boolean carved, int mantleY,
|
||||
int terrainHeight) {
|
||||
if (mantleY <= 0) {
|
||||
return true;
|
||||
}
|
||||
if (overlay != null) {
|
||||
return overlay.isSolid();
|
||||
return blocks.hasTrait(overlay, BlockTrait.SOLID);
|
||||
}
|
||||
return !carved && mantleY <= terrainHeight;
|
||||
}
|
||||
|
||||
static boolean isSurfaceSupportBoundary(PlatformBlockState overlay, boolean carved,
|
||||
static boolean isSurfaceSupportBoundary(BlockState overlay, BlockRegistry blocks, boolean carved,
|
||||
int mantleY, int terrainHeight) {
|
||||
return carved || isGroundSolid(overlay, false, mantleY, terrainHeight);
|
||||
return carved || isGroundSolid(overlay, blocks, false, mantleY, terrainHeight);
|
||||
}
|
||||
|
||||
static int fillSupportColumn(int foundationY, int groundY, IntConsumer supportAtY) {
|
||||
|
||||
+203
-202
@@ -18,94 +18,100 @@
|
||||
|
||||
package art.arcane.iris.engine.mantle.components;
|
||||
|
||||
import art.arcane.iris.builtin.anchor.PlaceTrait;
|
||||
import art.arcane.iris.builtin.anchor.ObjectPlaceMode;
|
||||
import art.arcane.iris.builtin.anchor.PlaceTrait;
|
||||
import art.arcane.iris.builtin.loot.ObjectLoot;
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.builtin.objects.ObjectRun;
|
||||
import art.arcane.iris.builtin.prepare.ObjectRotation;
|
||||
import art.arcane.iris.builtin.structure.StructureCarveShape;
|
||||
import art.arcane.iris.builtin.structure.StructurePlacement;
|
||||
import art.arcane.iris.builtin.structure.StructurePlacementSettings;
|
||||
import art.arcane.iris.builtin.structure.StructureStilts;
|
||||
import art.arcane.iris.builtin.structure.StructureTerrain;
|
||||
import art.arcane.iris.builtin.structure.StructureTerrainMode;
|
||||
import art.arcane.iris.engine.framework.IrisStructureLocator;
|
||||
import art.arcane.iris.engine.framework.StructurePlacementScope;
|
||||
import art.arcane.iris.engine.framework.structure.ColumnHeights;
|
||||
import art.arcane.iris.engine.framework.structure.StructureWorld;
|
||||
import art.arcane.iris.engine.framework.structure.assembly.AssembledPiece;
|
||||
import art.arcane.iris.engine.framework.structure.assembly.PieceTurn;
|
||||
import art.arcane.iris.engine.framework.structure.assembly.StructureAssembly;
|
||||
import art.arcane.iris.engine.framework.structure.assembly.StructureStamp;
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.builtin.prepare.ObjectRotation;
|
||||
import art.arcane.iris.core.IrisSettings;
|
||||
import art.arcane.iris.core.modules.ModuleObjectPlacement;
|
||||
import art.arcane.volmlib.util.cache.CacheKey;
|
||||
import art.arcane.iris.engine.framework.IrisStructureLocator;
|
||||
import art.arcane.iris.engine.framework.StructurePlacementScope;
|
||||
import art.arcane.iris.core.modules.PlacementMarkers;
|
||||
import art.arcane.iris.engine.framework.TreeBlockMaterial;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.builtin.loot.ObjectLoot;
|
||||
import art.arcane.iris.engine.mantle.MantleWriter;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObject;
|
||||
import art.arcane.iris.engine.object.world.region.IrisRegion;
|
||||
import art.arcane.iris.builtin.structure.StructureCarveShape;
|
||||
import art.arcane.iris.builtin.structure.StructurePlacement;
|
||||
import art.arcane.iris.builtin.structure.StructureStilts;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.documentation.ChunkCoordinates;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.ModuleLog;
|
||||
import com.volmit.block.BlockRegistry;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.block.BlockTrait;
|
||||
import com.volmit.block.PaletteSampler;
|
||||
import com.volmit.block.PaletteSpec;
|
||||
import art.arcane.iris.builtin.structure.StructureTerrain;
|
||||
import art.arcane.iris.builtin.structure.StructureTerrainMode;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.util.common.data.B;
|
||||
import art.arcane.volmlib.util.math.IrisBlockVector;
|
||||
import art.arcane.iris.util.project.matter.TileWrapper;
|
||||
import art.arcane.iris.util.project.noise.CNG;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.iris.util.project.context.ChunkContext;
|
||||
import art.arcane.volmlib.util.documentation.ChunkCoordinates;
|
||||
import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
|
||||
import art.arcane.volmlib.util.matter.Matter;
|
||||
import art.arcane.volmlib.util.matter.MatterCavern;
|
||||
import art.arcane.volmlib.util.matter.MatterStructurePOI;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.geometry.BlockBox;
|
||||
import com.volmit.geometry.BlockPosition;
|
||||
import com.volmit.mantle.CarvedVoid;
|
||||
import com.volmit.mantle.Mantle;
|
||||
import com.volmit.noise.NoiseSampler;
|
||||
import com.volmit.noise.NoiseStyle;
|
||||
import com.volmit.object.ObjectBlock;
|
||||
import com.volmit.object.PlaceableObject;
|
||||
import com.volmit.placement.PlacementOutcome;
|
||||
import com.volmit.placement.PlacementRecord;
|
||||
import com.volmit.placement.PlacementTerrain;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.stage.MantleStageContext;
|
||||
import com.volmit.world.PackWorld;
|
||||
import com.volmit.world.RunningWorld;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Places the Iris structures of the dimension, its regions and biomes into the mantle for
|
||||
* {@link StructureModule}: their pieces, foundations, bores and carves, clearing object trees they
|
||||
* intersect. One per engine runtime. Its reach is the largest structure any placement can produce.
|
||||
* intersect. One per world. Its reach is the largest structure any placement can produce.
|
||||
*/
|
||||
public class StructurePlacing {
|
||||
private static final MatterCavern CARVE_CAVERN = new MatterCavern(true, "", (byte) 3);
|
||||
private static final CarvedVoid CARVE_VOID = CarvedVoid.AIR;
|
||||
private static final NoiseStyle CARVE_NOISE = NoiseStyle.of("IRIS");
|
||||
private static final long CARVE_ROLL_SIGNATURE = 0x2A17L;
|
||||
private static final int REJECTED_PIECE = -1;
|
||||
private static final int SAMPLED_HEIGHT = -1;
|
||||
|
||||
private final Engine engine;
|
||||
private final PackWorld world;
|
||||
private final ModuleLog log;
|
||||
|
||||
public StructurePlacing(Engine engine, ModuleLog log) {
|
||||
this.engine = engine;
|
||||
public StructurePlacing(PackWorld world, ModuleLog log) {
|
||||
this.world = world;
|
||||
this.log = log;
|
||||
}
|
||||
|
||||
/** Places what originates in the chunk at chunk coordinates {@code x}, {@code z} into {@code writer}. */
|
||||
/** Places what originates in the chunk {@code context} generates into its mantle. */
|
||||
@ChunkCoordinates
|
||||
public void place(MantleWriter writer, int x, int z, ChunkContext context) {
|
||||
for (StructurePlacement placement : StructurePlacementScope.placementsAt(
|
||||
engine, x, z)) {
|
||||
public void place(MantleStageContext context) {
|
||||
int x = context.chunkX();
|
||||
int z = context.chunkZ();
|
||||
for (StructurePlacement placement : StructurePlacementScope.placementsAt(world, x, z)) {
|
||||
if (!placement.hasIrisStructures()) {
|
||||
continue;
|
||||
}
|
||||
placeFromPlacement(writer, placement, x, z);
|
||||
placeFromPlacement(context, placement, x, z);
|
||||
}
|
||||
}
|
||||
|
||||
@ChunkCoordinates
|
||||
private void placeFromPlacement(MantleWriter writer, StructurePlacement placement, int cx, int cz) {
|
||||
private void placeFromPlacement(MantleStageContext context, StructurePlacement placement, int cx, int cz) {
|
||||
IrisStructureLocator.ResolvedPlacement resolved = IrisStructureLocator.resolvePlacement(
|
||||
engine, placement, cx, cz);
|
||||
world, placement, cx, cz);
|
||||
if (resolved == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean trace = IrisSettings.get().getGeneral().isDebug();
|
||||
boolean trace = log.debugging();
|
||||
if (trace) {
|
||||
log.debug("[StructTrace] ORIGIN chunk=" + cx + "," + cz + " structures=" + placement.structures()
|
||||
+ " anchor=" + placement.resolvedAnchor() + " band=" + placement.minHeight() + ".." + placement.maxHeight());
|
||||
@@ -124,21 +130,20 @@ public class StructurePlacing {
|
||||
}
|
||||
|
||||
if (!placement.isAnchoredUnderground()) {
|
||||
clearIntersectingObjectTrees(writer, resolved);
|
||||
clearIntersectingObjectTrees(context, resolved);
|
||||
}
|
||||
|
||||
StructureTerrain terrain = placement.resolvedTerrain();
|
||||
StructureTerrainMode terrainMode = terrain.resolvedMode();
|
||||
if (terrainMode == StructureTerrainMode.FORCE_CARVE) {
|
||||
forceCarveStructure(writer, pieces, terrain);
|
||||
forceCarveStructure(context, pieces, terrain);
|
||||
} else if (terrainMode == StructureTerrainMode.BORE) {
|
||||
boreStructure(writer, pieces, terrain);
|
||||
boreStructure(context, pieces, terrain);
|
||||
} else if (terrainMode != StructureTerrainMode.PRESERVE
|
||||
&& terrainMode != StructureTerrainMode.SOURCE) {
|
||||
throw new IllegalStateException("Iris assembly terrain mode " + terrainMode
|
||||
+ " is not implemented for structure '" + key + "'");
|
||||
}
|
||||
|
||||
ObjectPlaceMode mode = stamp.placeMode();
|
||||
int failedPieces = 0;
|
||||
StructureStilts stilt = placement.stilt().orElse(null);
|
||||
@@ -149,87 +154,88 @@ public class StructurePlacing {
|
||||
ObjectPlaceMode undergroundMode = mode.placeMode().has(PlaceTrait.CAVE_ANCHORED)
|
||||
? mode : ObjectPlaceMode.STRUCTURE_PIECE;
|
||||
for (AssembledPiece p : pieces) {
|
||||
if (placeObject(writer, key, stamp, p, undergroundMode, p.y(), rng,
|
||||
foundationColumns, supportNonOccluding) == -1) {
|
||||
if (placeObject(context, key, stamp, p, undergroundMode, p.y(),
|
||||
foundationColumns, supportNonOccluding) == REJECTED_PIECE) {
|
||||
failedPieces++;
|
||||
}
|
||||
}
|
||||
} else if (mode.placeMode().has(PlaceTrait.FREE_HEIGHT)) {
|
||||
for (AssembledPiece p : pieces) {
|
||||
if (placeObject(writer, key, stamp, p, ObjectPlaceMode.STRUCTURE_PIECE, p.y(), rng,
|
||||
foundationColumns, supportNonOccluding) == -1) {
|
||||
if (placeObject(context, key, stamp, p, ObjectPlaceMode.STRUCTURE_PIECE, p.y(),
|
||||
foundationColumns, supportNonOccluding) == REJECTED_PIECE) {
|
||||
failedPieces++;
|
||||
}
|
||||
}
|
||||
} else if (pieces.size() == 1) {
|
||||
if (placeObject(writer, key, stamp, pieces.getFirst(), mode, -1, rng,
|
||||
foundationColumns, supportNonOccluding) == -1) {
|
||||
if (placeObject(context, key, stamp, pieces.getFirst(), mode, SAMPLED_HEIGHT,
|
||||
foundationColumns, supportNonOccluding) == REJECTED_PIECE) {
|
||||
failedPieces++;
|
||||
}
|
||||
} else {
|
||||
for (AssembledPiece p : pieces) {
|
||||
if (placeObject(writer, key, stamp, p, ObjectPlaceMode.STRUCTURE_PIECE, p.y(), rng,
|
||||
foundationColumns, supportNonOccluding) == -1) {
|
||||
if (placeObject(context, key, stamp, p, ObjectPlaceMode.STRUCTURE_PIECE, p.y(),
|
||||
foundationColumns, supportNonOccluding) == REJECTED_PIECE) {
|
||||
failedPieces++;
|
||||
}
|
||||
}
|
||||
}
|
||||
requireAppliedPieces(resolved, cx, cz, failedPieces);
|
||||
if (failedPieces == 0 && stilt != null) {
|
||||
placeFoundation(writer, foundationColumns, stilt, rng, !placement.isAnchoredUnderground());
|
||||
placeFoundation(context, foundationColumns, stilt, rng, !placement.isAnchoredUnderground());
|
||||
}
|
||||
}
|
||||
|
||||
private void placeFoundation(MantleWriter writer, ColumnHeights columns,
|
||||
private void placeFoundation(MantleStageContext context, ColumnHeights columns,
|
||||
StructureStilts settings, RNG rng,
|
||||
boolean surfaceStructure) {
|
||||
PaletteSpec palette = settings.palette().orElseThrow(
|
||||
() -> new NullPointerException("Structure stilt palette must not be null"));
|
||||
PaletteSampler picker = engine.getData().getPackResources().blocks().palette(palette, rng.getSeed());
|
||||
int mantleOffset = engine.getMinHeight();
|
||||
BlockRegistry blocks = world.resources().blocks();
|
||||
PaletteSampler picker = blocks.palette(palette, rng.getSeed());
|
||||
Mantle mantle = context.mantle();
|
||||
PlacementTerrain terrain = context.placementTerrain();
|
||||
RunningWorld running = StructureWorld.running(world);
|
||||
int mantleOffset = world.minWorldY();
|
||||
int maxDepth = Math.max(1, settings.maxDepth());
|
||||
columns.forEach((column, foundationY) -> {
|
||||
int worldX = StructureFoundationPlanner.unpackX(column);
|
||||
int worldZ = StructureFoundationPlanner.unpackZ(column);
|
||||
PlatformBlockState foundationState = writer.getDataIfPresent(
|
||||
worldX, foundationY, worldZ, PlatformBlockState.class);
|
||||
if (foundationState == null || !foundationState.isSolid()) {
|
||||
BlockState foundationState = mantle.blocks().get(worldX, foundationY, worldZ);
|
||||
if (foundationState == null || !blocks.hasTrait(foundationState, BlockTrait.SOLID)) {
|
||||
return;
|
||||
}
|
||||
int terrainHeight = engine.getMantle().trueHeight(worldX, worldZ);
|
||||
int terrainHeight = running.layout().surfaceHeight(worldX, worldZ);
|
||||
int groundY = StructureFoundationPlanner.findGroundY(
|
||||
foundationY, maxDepth, 0,
|
||||
y -> {
|
||||
PlatformBlockState overlay = writer.getDataIfPresent(
|
||||
worldX, y, worldZ, PlatformBlockState.class);
|
||||
boolean carved = writer.getDataIfPresent(
|
||||
worldX, y, worldZ, MatterCavern.class) != null;
|
||||
BlockState overlay = mantle.blocks().get(worldX, y, worldZ);
|
||||
boolean carved = mantle.carved().get(worldX, y, worldZ) != null;
|
||||
return surfaceStructure
|
||||
? StructureFoundationPlanner.isSurfaceSupportBoundary(
|
||||
overlay, carved, y, terrainHeight)
|
||||
overlay, blocks, carved, y, terrainHeight)
|
||||
: StructureFoundationPlanner.isGroundSolid(
|
||||
overlay, carved, y, terrainHeight);
|
||||
overlay, blocks, carved, y, terrainHeight);
|
||||
});
|
||||
if (groundY == StructureFoundationPlanner.NO_GROUND) {
|
||||
return;
|
||||
}
|
||||
StructureFoundationPlanner.fillSupportColumn(foundationY, groundY, y -> {
|
||||
writeFoundationSupport(writer, picker, worldX, y, worldZ, mantleOffset);
|
||||
writeFoundationSupport(terrain, mantle, picker, worldX, y, worldZ, mantleOffset);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/** Writes the stilt palette's block at the column's mantle height, clearing any carve there. */
|
||||
static void writeFoundationSupport(MantleWriter writer, PaletteSampler picker, int worldX, int mantleY, int worldZ,
|
||||
int mantleOffset) {
|
||||
static void writeFoundationSupport(PlacementTerrain terrain, Mantle mantle, PaletteSampler picker, int worldX,
|
||||
int mantleY, int worldZ, int mantleOffset) {
|
||||
int worldY = mantleY + mantleOffset;
|
||||
PlatformBlockState support = B.getState(picker.at(worldX, worldY, worldZ).key());
|
||||
BlockState support = picker.at(worldX, worldY, worldZ);
|
||||
if (support == null) {
|
||||
throw new IllegalStateException("Structure stilt palette resolved no block at "
|
||||
+ worldX + "," + worldY + "," + worldZ);
|
||||
}
|
||||
writer.clearData(worldX, mantleY, worldZ, MatterCavern.class);
|
||||
writer.set(worldX, mantleY, worldZ, support);
|
||||
mantle.carved().remove(worldX, mantleY, worldZ);
|
||||
terrain.set(worldX, mantleY, worldZ, support);
|
||||
}
|
||||
|
||||
static KList<AssembledPiece> resolvedPiecesOrNull(
|
||||
@@ -257,7 +263,7 @@ public class StructurePlacing {
|
||||
+ " assembled piece(s)");
|
||||
}
|
||||
|
||||
private void boreStructure(MantleWriter writer, KList<AssembledPiece> pieces,
|
||||
private void boreStructure(MantleStageContext context, KList<AssembledPiece> pieces,
|
||||
StructureTerrain terrain) {
|
||||
int[] bounds = computePieceBounds(pieces);
|
||||
if (bounds == null) {
|
||||
@@ -270,24 +276,24 @@ public class StructurePlacing {
|
||||
int maxX = bounds[3] + pad;
|
||||
int maxY = bounds[4] + Math.max(0, terrain.ceilingPadding());
|
||||
int maxZ = bounds[5] + pad;
|
||||
int worldMin = engine.getMinHeight() + 1;
|
||||
int worldMax = engine.getMinHeight() + engine.getHeight() - 1;
|
||||
int worldMin = world.minWorldY() + 1;
|
||||
int worldMax = world.minWorldY() + StructureWorld.height(world) - 1;
|
||||
minY = Math.max(minY, worldMin);
|
||||
maxY = Math.min(maxY, worldMax);
|
||||
if (maxX < minX || maxY < minY || maxZ < minZ) {
|
||||
return;
|
||||
}
|
||||
int mantleOffset = engine.getMinHeight();
|
||||
int mantleOffset = world.minWorldY();
|
||||
for (int bx = minX; bx <= maxX; bx++) {
|
||||
for (int by = minY; by <= maxY; by++) {
|
||||
for (int bz = minZ; bz <= maxZ; bz++) {
|
||||
writer.setForcedCarve(bx, by - mantleOffset, bz, CARVE_CAVERN);
|
||||
carve(context, bx, by - mantleOffset, bz);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void forceCarveStructure(MantleWriter writer, KList<AssembledPiece> pieces,
|
||||
private void forceCarveStructure(MantleStageContext context, KList<AssembledPiece> pieces,
|
||||
StructureTerrain terrain) {
|
||||
int[] bounds = computePieceBounds(pieces);
|
||||
if (bounds == null) {
|
||||
@@ -298,13 +304,13 @@ public class StructurePlacing {
|
||||
int head = Math.max(0, terrain.ceilingPadding());
|
||||
int floorCut = Math.max(0, terrain.floorPadding());
|
||||
double strength = terrain.resolvedErosionStrength();
|
||||
int mantleOffset = engine.getMinHeight();
|
||||
int worldMin = engine.getMinHeight() + 1;
|
||||
int worldMax = engine.getMinHeight() + engine.getHeight() - 1;
|
||||
int mantleOffset = world.minWorldY();
|
||||
int worldMin = world.minWorldY() + 1;
|
||||
int worldMax = world.minWorldY() + StructureWorld.height(world) - 1;
|
||||
int upExtension = shape.maximumCeilingExtension(head, strength);
|
||||
|
||||
if (shape == StructureCarveShape.BOX) {
|
||||
carveOverboreBox(writer, bounds, margin, head, floorCut, mantleOffset, worldMin, worldMax);
|
||||
carveOverboreBox(context, bounds, margin, head, floorCut, mantleOffset, worldMin, worldMax);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -317,15 +323,15 @@ public class StructurePlacing {
|
||||
|
||||
double frequency = terrain.resolvedErosionFrequency();
|
||||
boolean eroded = shape == StructureCarveShape.ERODED && strength > 0D;
|
||||
CNG blob = null;
|
||||
CNG roll = null;
|
||||
NoiseSampler blob = null;
|
||||
NoiseSampler roll = null;
|
||||
if (eroded) {
|
||||
RNG noiseRng = new RNG(engine.getSeedManager().getMantle() + CacheKey.key(bounds[0], bounds[2]));
|
||||
blob = CNG.signature(noiseRng);
|
||||
roll = CNG.signature(noiseRng.nextParallelRNG(0x2A17));
|
||||
long noiseSeed = StructureWorld.placementSeed(world) + CacheKey.key(bounds[0], bounds[2]);
|
||||
blob = world.resources().noise().sampler(CARVE_NOISE, noiseSeed);
|
||||
roll = world.resources().noise().sampler(CARVE_NOISE, noiseSeed + CARVE_ROLL_SIGNATURE);
|
||||
}
|
||||
|
||||
if (IrisSettings.get().getGeneral().isDebug()) {
|
||||
if (log.debugging()) {
|
||||
log.info("Overbore carving structure cavern: shape=" + shape + " pieces=" + pieces.size()
|
||||
+ " footprint=" + footprint.width() + "x" + footprint.depth()
|
||||
+ " margin=" + margin + " head=" + head + " floorCut=" + floorCut + " work=" + work);
|
||||
@@ -357,28 +363,27 @@ public class StructurePlacing {
|
||||
double distanceSquared = normalizedHorizontalDistanceSquared
|
||||
+ normalizedY * normalizedY;
|
||||
if (distanceSquared <= 0D) {
|
||||
writer.setForcedCarve(bx, by - mantleOffset, bz, CARVE_CAVERN);
|
||||
carve(context, bx, by - mantleOffset, bz);
|
||||
continue;
|
||||
}
|
||||
if (distanceSquared > 1D) {
|
||||
continue;
|
||||
}
|
||||
if (!eroded) {
|
||||
writer.setForcedCarve(bx, by - mantleOffset, bz, CARVE_CAVERN);
|
||||
carve(context, bx, by - mantleOffset, bz);
|
||||
continue;
|
||||
}
|
||||
double noise = blob.fitDouble(
|
||||
0D, 1D, bx * frequency, by * frequency, bz * frequency);
|
||||
double noise = blob.sample(bx * frequency, by * frequency, bz * frequency);
|
||||
if (StructureCarveEnvelope.shouldCarveOverboreCell(
|
||||
shape, distanceSquared, noise, strength)) {
|
||||
writer.setForcedCarve(bx, by - mantleOffset, bz, CARVE_CAVERN);
|
||||
carve(context, bx, by - mantleOffset, bz);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void carveOverboreBox(MantleWriter writer, int[] bounds, int margin, int head, int floorCut,
|
||||
private void carveOverboreBox(MantleStageContext context, int[] bounds, int margin, int head, int floorCut,
|
||||
int mantleOffset, int worldMin, int worldMax) {
|
||||
int minX = bounds[0] - margin;
|
||||
int minY = Math.max(worldMin, bounds[1] - floorCut);
|
||||
@@ -389,12 +394,18 @@ public class StructurePlacing {
|
||||
for (int bx = minX; bx <= maxX; bx++) {
|
||||
for (int by = minY; by <= maxY; by++) {
|
||||
for (int bz = minZ; bz <= maxZ; bz++) {
|
||||
writer.setForcedCarve(bx, by - mantleOffset, bz, CARVE_CAVERN);
|
||||
carve(context, bx, by - mantleOffset, bz);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Carves the block open for good: the void is planned and any block a placement wrote there is taken back. */
|
||||
private static void carve(MantleStageContext context, int x, int mantleY, int z) {
|
||||
context.placementTerrain().clearBlock(x, mantleY, z);
|
||||
context.mantle().carved().set(x, mantleY, z, CARVE_VOID);
|
||||
}
|
||||
|
||||
private static long overboreCandidateVolume(int[] bounds, int margin, int upExtension,
|
||||
int floorCut) {
|
||||
return inclusiveVolume(
|
||||
@@ -414,96 +425,82 @@ public class StructurePlacing {
|
||||
return width * height * depth;
|
||||
}
|
||||
|
||||
private void clearIntersectingObjectTrees(MantleWriter writer, IrisStructureLocator.ResolvedPlacement resolved) {
|
||||
int mantleOffset = engine.getMinHeight();
|
||||
int worldHeight = engine.getHeight();
|
||||
Map<String, ObjectMarkerBounds> intersectingObjects = new HashMap<>();
|
||||
private void clearIntersectingObjectTrees(MantleStageContext context, IrisStructureLocator.ResolvedPlacement resolved) {
|
||||
BlockRegistry blocks = world.resources().blocks();
|
||||
int mantleOffset = world.minWorldY();
|
||||
int worldHeight = StructureWorld.height(world);
|
||||
Map<PlacementRecord, ObjectMarkerBounds> intersectingObjects = new HashMap<>();
|
||||
for (AssembledPiece piece : resolved.pieces()) {
|
||||
IrisObject object = objectOf(piece);
|
||||
for (IrisBlockVector local : object.getBlocks().keys()) {
|
||||
PlatformBlockState structureState = object.getBlocks().get(local);
|
||||
if (!isOccupiedStructureState(structureState)) {
|
||||
for (ObjectBlock block : objectOf(piece).geometry().blocks()) {
|
||||
if (!isOccupiedStructureState(block.state(), blocks)) {
|
||||
continue;
|
||||
}
|
||||
BlockPosition rotated = piece.turn().rotate(
|
||||
new BlockPosition(local.getBlockX(), local.getBlockY(), local.getBlockZ()));
|
||||
BlockPosition rotated = piece.turn().rotate(block.position());
|
||||
int y = piece.y() - mantleOffset + rotated.y();
|
||||
if (y >= 0 && y < worldHeight) {
|
||||
collectIntersectingObjectTreeMarker(
|
||||
writer, piece.x() + rotated.x(), y,
|
||||
collectIntersectingObjectTree(
|
||||
context, piece.x() + rotated.x(), y,
|
||||
piece.z() + rotated.z(), intersectingObjects);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Map.Entry<String, ObjectMarkerBounds> entry : intersectingObjects.entrySet()) {
|
||||
clearMarkerOwnedObject(writer, entry.getKey(), entry.getValue(), worldHeight);
|
||||
for (Map.Entry<PlacementRecord, ObjectMarkerBounds> entry : intersectingObjects.entrySet()) {
|
||||
clearRecordOwnedObject(context, entry.getKey(), entry.getValue(), worldHeight);
|
||||
}
|
||||
}
|
||||
|
||||
static boolean isOccupiedStructureState(PlatformBlockState state) {
|
||||
return !B.isAir(state);
|
||||
static boolean isOccupiedStructureState(BlockState state, BlockRegistry blocks) {
|
||||
return state != null && !blocks.hasTrait(state, BlockTrait.AIR);
|
||||
}
|
||||
|
||||
private void collectIntersectingObjectTreeMarker(MantleWriter writer, int x, int y, int z,
|
||||
Map<String, ObjectMarkerBounds> intersectingObjects) {
|
||||
PlatformBlockState state = writer.getDataIfPresent(x, y, z, PlatformBlockState.class);
|
||||
if (state == null || !state.isTreeBlock()) {
|
||||
private void collectIntersectingObjectTree(MantleStageContext context, int x, int y, int z,
|
||||
Map<PlacementRecord, ObjectMarkerBounds> intersectingObjects) {
|
||||
BlockState state = context.mantle().blocks().get(x, y, z);
|
||||
if (state == null || !isTreeBlock(state)) {
|
||||
return;
|
||||
}
|
||||
String marker = writer.getDataIfPresent(x, y, z, String.class);
|
||||
if (isOrdinaryObjectMarker(marker)) {
|
||||
intersectingObjects.computeIfAbsent(marker, ignored -> new ObjectMarkerBounds())
|
||||
Optional<PlacementRecord> record = StructureWorld.running(world).placementAt(x, y, z);
|
||||
if (isOrdinaryObjectRecord(record)) {
|
||||
intersectingObjects.computeIfAbsent(record.get(), ignored -> new ObjectMarkerBounds())
|
||||
.include(x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
private void clearMarkerOwnedObject(MantleWriter writer, String marker,
|
||||
private boolean isTreeBlock(BlockState state) {
|
||||
BlockRegistry blocks = world.resources().blocks();
|
||||
return blocks.hasTrait(state, BlockTrait.LOG) || blocks.hasTrait(state, BlockTrait.LEAVES);
|
||||
}
|
||||
|
||||
private void clearRecordOwnedObject(MantleStageContext context, PlacementRecord record,
|
||||
ObjectMarkerBounds intersections, int worldHeight) {
|
||||
PlacementMarkers.Decoded decoded = PlacementMarkers.decode(marker);
|
||||
if (decoded == null) {
|
||||
Optional<PlaceableObject> object = world.resources().objects().object(record.object());
|
||||
if (object.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
IrisObject object = engine.getData().load(IrisObject.class, decoded.objectKey(), false);
|
||||
if (object == null) {
|
||||
return;
|
||||
}
|
||||
int horizontalSpan = Math.max(1, Math.max(object.getW(), object.getD()));
|
||||
int verticalSpan = Math.max(1, object.getH());
|
||||
int horizontalSpan = Math.max(1, Math.max(object.get().width(), object.get().depth()));
|
||||
int verticalSpan = Math.max(1, object.get().height());
|
||||
ObjectMarkerBounds search = intersections.expand(horizontalSpan - 1, verticalSpan - 1, worldHeight);
|
||||
KList<ObjectBlockPosition> positions = new KList<>();
|
||||
int minChunkX = Math.floorDiv(search.minX, 16);
|
||||
int maxChunkX = Math.floorDiv(search.maxX, 16);
|
||||
int minChunkZ = Math.floorDiv(search.minZ, 16);
|
||||
int maxChunkZ = Math.floorDiv(search.maxZ, 16);
|
||||
for (int chunkX = minChunkX; chunkX <= maxChunkX; chunkX++) {
|
||||
for (int chunkZ = minChunkZ; chunkZ <= maxChunkZ; chunkZ++) {
|
||||
MantleChunk<Matter> chunk = writer.acquireChunk(chunkX, chunkZ);
|
||||
if (chunk == null) {
|
||||
continue;
|
||||
}
|
||||
int blockX = chunkX << 4;
|
||||
int blockZ = chunkZ << 4;
|
||||
chunk.iterate(String.class, (localX, y, localZ, value) -> {
|
||||
int x = blockX + localX;
|
||||
int z = blockZ + localZ;
|
||||
if (marker.equals(value) && search.contains(x, y, z)) {
|
||||
BlockBox prepared = context.mantle().bounds();
|
||||
RunningWorld running = StructureWorld.running(world);
|
||||
PlacementTerrain terrain = context.placementTerrain();
|
||||
List<ObjectBlockPosition> positions = new ArrayList<>();
|
||||
for (int x = search.minX; x <= search.maxX; x++) {
|
||||
for (int y = search.minY; y <= search.maxY; y++) {
|
||||
for (int z = search.minZ; z <= search.maxZ; z++) {
|
||||
if (prepared.contains(x, y, z) && running.placementAt(x, y, z).filter(record::equals).isPresent()) {
|
||||
positions.add(new ObjectBlockPosition(x, y, z));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
for (ObjectBlockPosition position : positions) {
|
||||
writer.clearBlock(position.x(), position.y(), position.z());
|
||||
writer.clearData(position.x(), position.y(), position.z(), String.class);
|
||||
writer.clearData(position.x(), position.y(), position.z(), TreeBlockMaterial.class);
|
||||
writer.clearData(position.x(), position.y(), position.z(), TileWrapper.class);
|
||||
writer.clearData(position.x(), position.y(), position.z(), MatterStructurePOI.class);
|
||||
terrain.clearBlock(position.x(), position.y(), position.z());
|
||||
terrain.clearAttached(position.x(), position.y(), position.z());
|
||||
}
|
||||
}
|
||||
|
||||
static boolean isOrdinaryObjectMarker(String marker) {
|
||||
PlacementMarkers.Decoded decoded = PlacementMarkers.decode(marker);
|
||||
return decoded != null && !decoded.structureAware();
|
||||
static boolean isOrdinaryObjectRecord(Optional<PlacementRecord> record) {
|
||||
return record.isPresent() && record.get().structure().isEmpty();
|
||||
}
|
||||
|
||||
static ObjectMarkerBounds markerSearchBounds(int minX, int minY, int minZ,
|
||||
@@ -522,25 +519,19 @@ public class StructurePlacing {
|
||||
}
|
||||
|
||||
private List<StructurePieceColumns.PieceBlock> blocksOf(AssembledPiece piece) {
|
||||
IrisObject object = objectOf(piece);
|
||||
if (object == null || object.getBlocks() == null) {
|
||||
return null;
|
||||
BlockRegistry blocks = world.resources().blocks();
|
||||
List<StructurePieceColumns.PieceBlock> pieceBlocks = new ArrayList<>();
|
||||
for (ObjectBlock block : objectOf(piece).geometry().blocks()) {
|
||||
pieceBlocks.add(new StructurePieceColumns.PieceBlock(
|
||||
block.position(), blocks.hasTrait(block.state(), BlockTrait.AIR)));
|
||||
}
|
||||
List<StructurePieceColumns.PieceBlock> blocks = new ArrayList<>();
|
||||
for (IrisBlockVector local : object.getBlocks().keys()) {
|
||||
if (local != null) {
|
||||
blocks.add(new StructurePieceColumns.PieceBlock(
|
||||
new BlockPosition(local.getBlockX(), local.getBlockY(), local.getBlockZ()),
|
||||
B.isAir(object.getBlocks().get(local))));
|
||||
}
|
||||
}
|
||||
return blocks;
|
||||
return pieceBlocks;
|
||||
}
|
||||
|
||||
/** The object of {@code piece}, loaded from the engine's pack. */
|
||||
private IrisObject objectOf(AssembledPiece piece) {
|
||||
String key = engine.getData().getPackResources().keyOf(piece.object());
|
||||
return engine.getData().load(IrisObject.class, key, false);
|
||||
/** The object of {@code piece}, loaded from the world's pack. */
|
||||
private PlaceableObject objectOf(AssembledPiece piece) {
|
||||
return world.resources().objects().object(piece.object())
|
||||
.orElseThrow(() -> new IllegalStateException("Structure piece object " + piece.object() + " is missing"));
|
||||
}
|
||||
|
||||
private int[] computePieceBounds(KList<AssembledPiece> pieces) {
|
||||
@@ -583,11 +574,11 @@ public class StructurePlacing {
|
||||
return placement.loot(loot);
|
||||
}
|
||||
|
||||
private int placeObject(MantleWriter writer, String structureKey, StructureStamp stamp, AssembledPiece p,
|
||||
ObjectPlaceMode mode, int y, RNG rng, ColumnHeights foundationColumns,
|
||||
private int placeObject(MantleStageContext context, String structureKey, StructureStamp stamp, AssembledPiece p,
|
||||
ObjectPlaceMode mode, int y, ColumnHeights foundationColumns,
|
||||
boolean supportNonOccluding) {
|
||||
IrisObject object = objectOf(p);
|
||||
String objectKey = object.getLoadKey();
|
||||
PlaceableObject object = objectOf(p);
|
||||
String objectKey = object.name();
|
||||
ObjectPlacement.Builder builder = lootPlacementBuilder(stamp, objectKey).mode(mode).rotation(moduleRotation(p.turn()));
|
||||
if (!stamp.edits().isEmpty()) {
|
||||
builder.edit(new KList<>(stamp.edits()));
|
||||
@@ -596,16 +587,32 @@ public class StructurePlacing {
|
||||
builder.forcePlace(true);
|
||||
}
|
||||
ObjectPlacement config = builder.build();
|
||||
int placeY = (y == -1) ? -1 : y - engine.getMinHeight();
|
||||
String marker = structurePlacementMarker(structureKey, p, objectKey);
|
||||
return ModuleObjectPlacement.place(object, p.x(), placeY, p.z(), writer, config, rng, (position, state) -> {
|
||||
int placeY = (y == SAMPLED_HEIGHT) ? SAMPLED_HEIGHT : y - world.minWorldY();
|
||||
PlacementTerrain terrain = context.placementTerrain();
|
||||
ObjectRun run = ObjectRun.of(object, config, p.x(), placeY, p.z());
|
||||
PlacementOutcome outcome = run.placeIn(world, terrain);
|
||||
if (!outcome.isPlaced()) {
|
||||
return REJECTED_PIECE;
|
||||
}
|
||||
recordPieceBlocks(terrain, run, structureKey, p, objectKey, foundationColumns, supportNonOccluding);
|
||||
return run.anchorY().orElseThrow(() -> new IllegalStateException(
|
||||
"The placement graph placed " + objectKey + " without anchoring it"));
|
||||
}
|
||||
|
||||
/** Notes each block the piece wrote as a base cell of the foundation, and marks its storage blocks as the structure's. */
|
||||
private void recordPieceBlocks(PlacementTerrain terrain, ObjectRun run, String structureKey, AssembledPiece piece,
|
||||
String objectKey, ColumnHeights foundationColumns, boolean supportNonOccluding) {
|
||||
BlockRegistry blocks = world.resources().blocks();
|
||||
PlacementRecord record = structurePlacementRecord(structureKey, piece, objectKey);
|
||||
for (BlockPosition position : run.objectBlocks()) {
|
||||
BlockState state = terrain.get(position.x(), position.y(), position.z());
|
||||
StructureFoundationPlanner.recordBaseCell(
|
||||
foundationColumns, position.getX(), position.getY(), position.getZ(), state,
|
||||
foundationColumns, position.x(), position.y(), position.z(), state, blocks,
|
||||
supportNonOccluding);
|
||||
if (marker != null && shouldWriteStructureMarker(state)) {
|
||||
writer.setData(position.getX(), position.getY(), position.getZ(), marker);
|
||||
if (record != null && shouldWriteStructureMarker(state, blocks)) {
|
||||
terrain.recordPlacement(position.x(), position.y(), position.z(), record);
|
||||
}
|
||||
}, null, engine.getData()).heightOrRejected();
|
||||
}
|
||||
}
|
||||
|
||||
/** The placement rotation that turns a placed piece the way {@code turn} does. */
|
||||
@@ -613,8 +620,8 @@ public class StructurePlacing {
|
||||
return ObjectRotation.of(0, turn.yDegrees(), 0);
|
||||
}
|
||||
|
||||
static boolean shouldWriteStructureMarker(PlatformBlockState state) {
|
||||
return state != null && state.isStorageChest();
|
||||
static boolean shouldWriteStructureMarker(BlockState state, BlockRegistry blocks) {
|
||||
return state != null && blocks.hasTrait(state, BlockTrait.STORAGE);
|
||||
}
|
||||
|
||||
static int structurePlacementId(String structureKey, String objectKey, int x, int y, int z) {
|
||||
@@ -627,27 +634,21 @@ public class StructurePlacing {
|
||||
return hash & Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
private static String structurePlacementMarker(String structureKey, AssembledPiece piece, String objectKey) {
|
||||
private PlacementRecord structurePlacementRecord(String structureKey, AssembledPiece piece, String objectKey) {
|
||||
if (structureKey == null || structureKey.isBlank() || objectKey == null || objectKey.isBlank()) {
|
||||
return null;
|
||||
}
|
||||
PackResources pack = world.resources();
|
||||
int placementId = structurePlacementId(structureKey, objectKey, piece.x(), piece.y(), piece.z());
|
||||
return PlacementMarkers.encodeStructure(objectKey, placementId, structureKey);
|
||||
return PlacementRecord.ofPiece(pack.idOf(objectKey), placementId, pack.idOf(structureKey));
|
||||
}
|
||||
|
||||
/** How far, in blocks along X and Z, placements may write beyond their chunk. */
|
||||
public int reach() {
|
||||
IrisDimension dimension = engine.getDimension();
|
||||
int maxBlocks = 0;
|
||||
|
||||
for (IrisRegion region : dimension.getAllRegions(engine)) {
|
||||
maxBlocks = Math.max(maxBlocks, maxBlocksFrom(StructurePlacementScope.placementsOf(region)));
|
||||
for (var declared : world.settings().declared(StructurePlacementSettings.class)) {
|
||||
maxBlocks = Math.max(maxBlocks, maxBlocksFrom(declared.value().placements()));
|
||||
}
|
||||
for (IrisBiome biome : dimension.getReachableBiomes(engine)) {
|
||||
maxBlocks = Math.max(maxBlocks, maxBlocksFrom(StructurePlacementScope.placementsOf(biome)));
|
||||
}
|
||||
maxBlocks = Math.max(maxBlocks, maxBlocksFrom(StructurePlacementScope.placementsOf(dimension)));
|
||||
|
||||
return maxBlocks;
|
||||
}
|
||||
|
||||
@@ -662,9 +663,9 @@ public class StructurePlacing {
|
||||
|| terrain.resolvedMode() == StructureTerrainMode.BORE
|
||||
? Math.max(0, terrain.horizontalPadding()) : 0;
|
||||
for (String key : placement.structures()) {
|
||||
var pack = engine.getData().getPackResources();
|
||||
PackResources pack = world.resources();
|
||||
var structure = pack.idOf(key);
|
||||
StructureAssembly provider = IrisStructureLocator.providerOf(engine, structure);
|
||||
StructureAssembly provider = IrisStructureLocator.providerOf(world, structure);
|
||||
if (provider != null) {
|
||||
max = Math.max(max, Math.max(1, provider.reachChunks(pack, structure).orElse(1)) * 16 + carvePadding);
|
||||
}
|
||||
|
||||
@@ -58,4 +58,12 @@ public interface IObjectPlacer {
|
||||
<T> @Nullable T getData(int xx, int yy, int zz, Class<T> t);
|
||||
|
||||
Engine getEngine();
|
||||
|
||||
default void clearBlock(int x, int y, int z) {
|
||||
throw new UnsupportedOperationException("This placer cannot take blocks back");
|
||||
}
|
||||
|
||||
default void clearAttached(int x, int y, int z) {
|
||||
throw new UnsupportedOperationException("This placer cannot take what is kept beside a block back");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user