mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 00:34:19 +00:00
Batch 3 of the API review: built-ins reach Iris through extensions
- Every facade is asked through IrisApi's extension point: world.extension(...) for IrisSeeds, LiveWorld, ObjectHost, FloatingHost and StructureHost, context.extension(...) for ObjectPlacement and MatterMantle, settings.extension(...) for reaches. The X.of(...) casts, the *.Source interfaces, ObjectPlacement.current() and PlacementBinding are gone; IrisSeed is an enum and IrisSeeds gives the seeds. - Facades that worked from a thread binding take the invocation context instead (ObjectHost.chunk, StructureHost.placeChunk, FloatingHost's placements). - Resources are looked up by kind and id; services, loot, spawns, structures, objects, cave bands and LinkedBiomes use ResourceId. - Value records are built with Optionals, starts are keyed by StartKey, and deposits ask Mantle.isCarved. - README describes the extension point and the chunk stage's matter.
This commit is contained in:
1 parent
b15a41094d
commit
00e1fc1e27
63 files changed
+337
-355
No files matched your search
@@ -24,21 +24,8 @@ import com.volmit.world.PackWorld;
|
||||
* The seeds Iris derives from a world's seed for its own features. Iris derives them one after another from a shared
|
||||
* random, so they cannot be worked out from the world seed alone. Built-in modules seed their randoms and noise with
|
||||
* them, so worlds generated before the features were modules generate the same; a pack module derives its own seeds
|
||||
* from {@link PackWorld#seed()}.
|
||||
* from {@link PackWorld#seed()}. A world Iris generates answers for them through its {@link IrisSeeds} extension.
|
||||
*/
|
||||
public enum IrisSeed {
|
||||
BIOME, CARVE, COMPLEX, COMPONENT, DECORATOR, DEPOSIT, ENTITY, LOOT, MANTLE, POST, TERRAIN;
|
||||
|
||||
/** This seed of {@code world}, which must be a world Iris generates. */
|
||||
public long of(PackWorld world) {
|
||||
if (world instanceof Source source) {
|
||||
return source.seed(this);
|
||||
}
|
||||
throw new IllegalArgumentException("Built-in modules generate Iris's own worlds, not " + world);
|
||||
}
|
||||
|
||||
/** Iris's worlds answer for their seeds. */
|
||||
public interface Source {
|
||||
long seed(IrisSeed seed);
|
||||
}
|
||||
BIOME, CARVE, COMPLEX, COMPONENT, DECORATOR, DEPOSIT, ENTITY, LOOT, MANTLE, POST, TERRAIN
|
||||
}
|
||||
+7
-20
@@ -16,25 +16,12 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.builtin.placement;
|
||||
package art.arcane.iris.builtin;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/** The placement bound to the placing thread. */
|
||||
final class PlacementBinding {
|
||||
private static final ScopedValue<ObjectPlacement> CURRENT = ScopedValue.newInstance();
|
||||
|
||||
private PlacementBinding() {
|
||||
}
|
||||
|
||||
static ObjectPlacement current() {
|
||||
if (!CURRENT.isBound()) {
|
||||
throw new IllegalStateException("No Iris object placement is running on this thread");
|
||||
}
|
||||
return CURRENT.get();
|
||||
}
|
||||
|
||||
static <T> T run(ObjectPlacement placement, Supplier<T> body) {
|
||||
return ScopedValue.where(CURRENT, placement).call(body::get);
|
||||
}
|
||||
/**
|
||||
* The {@link IrisSeed}s of a world Iris generates, which it offers as an extension of the world:
|
||||
* {@code world.extension(IrisSeeds.class).orElseThrow().seed(IrisSeed.CARVE)}.
|
||||
*/
|
||||
public interface IrisSeeds {
|
||||
long seed(IrisSeed seed);
|
||||
}
|
||||
@@ -24,7 +24,6 @@ import art.arcane.iris.builtin.spawn.SpawnCooldowns;
|
||||
import com.volmit.IrisFeature;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.world.BlockPosition;
|
||||
import com.volmit.world.PackWorld;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@@ -36,22 +35,9 @@ import java.util.Set;
|
||||
* the layout through its {@link com.volmit.world.TerrainSampler}; a service has no chunk, so it asks here.
|
||||
*
|
||||
* <p>X and Z are world coordinates; Y is the height above the dimension's bottom, as everywhere in IrisApi.
|
||||
* Safe to use from any thread. Reached through {@link #of(PackWorld)}.
|
||||
* Safe to use from any thread. Iris offers it as an extension of its worlds: {@code world.extension(LiveWorld.class)}.
|
||||
*/
|
||||
public interface LiveWorld {
|
||||
/** The live view of {@code world}, which must be a world Iris generates. */
|
||||
static LiveWorld of(PackWorld world) {
|
||||
if (world instanceof Source source) {
|
||||
return source.liveWorld();
|
||||
}
|
||||
throw new IllegalArgumentException("Built-in modules work in worlds Iris generates, not " + world);
|
||||
}
|
||||
|
||||
/** Iris's worlds answer for their live view. */
|
||||
interface Source {
|
||||
LiveWorld liveWorld();
|
||||
}
|
||||
|
||||
/** The platform's block Y of height 0, the dimension's bottom: a position's height plus this is its Y in the platform. */
|
||||
int bottomY();
|
||||
|
||||
|
||||
@@ -20,34 +20,20 @@ package art.arcane.iris.builtin;
|
||||
|
||||
import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
|
||||
import art.arcane.volmlib.util.matter.Matter;
|
||||
import com.volmit.host.ReadOnlyMantle;
|
||||
import com.volmit.mantle.Mantle;
|
||||
|
||||
/**
|
||||
* Iris's mantle as the matter slices it stores, for the built-ins whose data the platform and the rest of Iris read as
|
||||
* slices rather than through a {@link com.volmit.mantle.MantleLayer}: caves ({@code MatterCavern}) and markers. The
|
||||
* slices are VolmLib's own types, which a pack module may use as well; Iris's worlds implement this next to
|
||||
* {@link Mantle}, and {@link #of(Mantle)} reaches it from an invocation's mantle.
|
||||
* slices are VolmLib's own types, which a pack module may use as well. Iris offers it as an extension of its mantle and
|
||||
* chunk invocations: {@code context.extension(MatterMantle.class)}.
|
||||
*
|
||||
* <p>A chunk invocation's matter mantle holds its own chunk only, which the stage may write, as a chunk stage writes the
|
||||
* mantle of its own chunk; it reads its neighbours through {@link #loadedChunk} alone.
|
||||
*
|
||||
* <p>Heights are as the mantle stores them: above the dimension's bottom. A chunk the invocation reaches is pinned for
|
||||
* as long as the invocation runs; callers neither release it nor keep it afterwards.
|
||||
*/
|
||||
public interface MatterMantle {
|
||||
/**
|
||||
* The matter side of {@code mantle}, which must be a mantle Iris hands to its stages. A chunk stage's mantle is read-only
|
||||
* to the stage; the matter behind it is not, and a built-in chunk stage that writes markers into it (the caves' floors and
|
||||
* ceilings) is why this reaches through.
|
||||
*/
|
||||
static MatterMantle of(Mantle mantle) {
|
||||
if (mantle instanceof ReadOnlyMantle readOnly) {
|
||||
return of(readOnly.host());
|
||||
}
|
||||
if (mantle instanceof MatterMantle matter) {
|
||||
return matter;
|
||||
}
|
||||
throw new IllegalArgumentException("Built-in modules write Iris's own mantle, not " + mantle);
|
||||
}
|
||||
|
||||
/** The mantle chunk at chunk coordinates {@code chunkX}, {@code chunkZ}, or null outside what the invocation reaches. */
|
||||
MantleChunk<Matter> chunk(int chunkX, int chunkZ);
|
||||
|
||||
|
||||
@@ -25,6 +25,8 @@ import com.volmit.config.Feature;
|
||||
import com.volmit.config.LinkedBiomes;
|
||||
import com.volmit.config.Ref;
|
||||
import com.volmit.config.Reference;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@@ -48,7 +50,7 @@ public final class CarvingBiomeSettings implements IrisFeature, LinkedBiomes {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> treeBiomes() {
|
||||
return Set.of(biome());
|
||||
public Set<ResourceId> treeBiomes(PackResources pack) {
|
||||
return biome().isBlank() ? Set.of() : Set.of(pack.idOf(biome()));
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,8 @@ import com.volmit.config.Desc;
|
||||
import com.volmit.config.Feature;
|
||||
import com.volmit.config.LinkedBiomes;
|
||||
import com.volmit.config.MinItems;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -68,11 +70,11 @@ public final class CarvingSettings implements IrisFeature, LinkedBiomes {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> usedBiomes(Collection<IrisFeature> dimension) {
|
||||
Set<String> biomes = new LinkedHashSet<>();
|
||||
public Set<ResourceId> usedBiomes(PackResources pack, Collection<IrisFeature> dimension) {
|
||||
Set<ResourceId> biomes = new LinkedHashSet<>();
|
||||
for (CarvingEntry entry : entries()) {
|
||||
if (entry != null && entry.enabled()) {
|
||||
biomes.add(entry.biome());
|
||||
if (entry != null && entry.enabled() && entry.biome() != null && !entry.biome().isBlank()) {
|
||||
biomes.add(pack.idOf(entry.biome()));
|
||||
}
|
||||
}
|
||||
return biomes;
|
||||
|
||||
@@ -25,6 +25,8 @@ import com.volmit.config.Desc;
|
||||
import com.volmit.config.Feature;
|
||||
import com.volmit.config.LinkedBiomes;
|
||||
import com.volmit.config.MinItems;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -56,15 +58,21 @@ public final class FloatingChildSettings implements IrisFeature, LinkedBiomes {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> usedBiomes(Collection<IrisFeature> dimension) {
|
||||
public Set<ResourceId> usedBiomes(PackResources pack, Collection<IrisFeature> dimension) {
|
||||
CarvingSettings carving = dimension.stream().filter(CarvingSettings.class::isInstance).map(CarvingSettings.class::cast).findFirst().orElse(null);
|
||||
Set<String> biomes = new LinkedHashSet<>();
|
||||
Set<ResourceId> biomes = new LinkedHashSet<>();
|
||||
for (FloatingChildBiome child : children()) {
|
||||
if (child != null) {
|
||||
biomes.add(child.biome());
|
||||
biomes.add(carving == null ? child.carving() : carving.biomeOf(child.carving()));
|
||||
addBiome(pack, biomes, child.biome());
|
||||
addBiome(pack, biomes, carving == null ? child.carving() : carving.biomeOf(child.carving()));
|
||||
}
|
||||
}
|
||||
return biomes;
|
||||
}
|
||||
|
||||
private static void addBiome(PackResources pack, Set<ResourceId> biomes, String key) {
|
||||
if (key != null && !key.isBlank()) {
|
||||
biomes.add(pack.idOf(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,34 +21,17 @@ package art.arcane.iris.builtin.floating;
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.builtin.objects.PlaceableObject;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.config.PackSettings;
|
||||
import com.volmit.generation.InvocationContext;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.world.PackWorld;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* What {@code iris:floating} asks of Iris beyond the API: the biome of any column, a biome's own terrain height, the sky
|
||||
* biome an island paints, and placing Iris objects against an island. Iris's worlds implement it; a module reaches it
|
||||
* with {@link #of}.
|
||||
* biome an island paints, and placing Iris objects against an island. Iris offers it as an extension of its worlds and
|
||||
* of the settings of the pack it loads: {@code world.extension(FloatingHost.class)}.
|
||||
*/
|
||||
public interface FloatingHost {
|
||||
/** The host of the world {@code settings} are the pack's of, which must be a world Iris generates. */
|
||||
static FloatingHost of(PackSettings settings) {
|
||||
if (settings instanceof Source source) {
|
||||
return source.floating();
|
||||
}
|
||||
throw new IllegalArgumentException("Built-in modules generate Iris's own worlds, not " + settings);
|
||||
}
|
||||
|
||||
/** The host of {@code world}, which must be a world Iris generates. */
|
||||
static FloatingHost of(PackWorld world) {
|
||||
if (world instanceof Source source) {
|
||||
return source.floating();
|
||||
}
|
||||
throw new IllegalArgumentException("Built-in modules generate Iris's own worlds, not " + world);
|
||||
}
|
||||
|
||||
/** The biome of the column's surface, the biome an island grows from; any column, not only the chunk's. */
|
||||
ResourceId surfaceBiome(int worldX, int worldZ);
|
||||
|
||||
@@ -70,24 +53,21 @@ public interface FloatingHost {
|
||||
/** {@code object} shrunk by {@code factor} (below 1), the variant picked with {@code random}. */
|
||||
Optional<PlaceableObject> shrink(PlaceableObject object, double factor, RNG random);
|
||||
|
||||
/** Places {@code object} floating free at the column, into the chunk the mantle is generating. */
|
||||
void placeFloating(PlaceableObject object, int worldX, int worldZ, ObjectPlacement placement, RNG random);
|
||||
/** Places {@code object} floating free at the column, into the chunk the mantle invocation {@code context} generates. */
|
||||
void placeFloating(InvocationContext context, PlaceableObject object, int worldX, int worldZ, ObjectPlacement placement,
|
||||
RNG random);
|
||||
|
||||
/**
|
||||
* Places {@code object} on an island's top, its lowest block at {@code y}, into the chunk the mantle is generating; nothing
|
||||
* is written unless every block it writes is one {@code anchor} lets it write.
|
||||
* Places {@code object} on an island's top, its lowest block at {@code y}, into the chunk the mantle invocation
|
||||
* {@code context} generates; nothing is written unless every block it writes is one {@code anchor} lets it write.
|
||||
*/
|
||||
void placeOnTop(PlaceableObject object, int worldX, int y, int worldZ, ObjectPlacement placement, IslandAnchor anchor, RNG random);
|
||||
void placeOnTop(InvocationContext context, PlaceableObject object, int worldX, int y, int worldZ,
|
||||
ObjectPlacement placement, IslandAnchor anchor, RNG random);
|
||||
|
||||
/**
|
||||
* Places {@code object} upside down under an island, turned {@code yRotation} degrees about Y, as {@link #placeOnTop} does
|
||||
* on top.
|
||||
*/
|
||||
void placeUnder(PlaceableObject object, int worldX, int y, int worldZ, int yRotation, ObjectPlacement placement,
|
||||
IslandAnchor anchor, RNG random);
|
||||
|
||||
/** A world that hands out its {@link FloatingHost}. */
|
||||
interface Source {
|
||||
FloatingHost floating();
|
||||
}
|
||||
void placeUnder(InvocationContext context, PlaceableObject object, int worldX, int y, int worldZ, int yRotation,
|
||||
ObjectPlacement placement, IslandAnchor anchor, RNG random);
|
||||
}
|
||||
@@ -22,9 +22,8 @@ import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.config.Level;
|
||||
import com.volmit.IrisFeature;
|
||||
import com.volmit.config.FeatureSettings;
|
||||
import com.volmit.config.PackSettings;
|
||||
import com.volmit.generation.InvocationContext;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.world.PackWorld;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@@ -32,25 +31,11 @@ import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* What {@code iris:objects} asks of Iris: the objects of the pack, how Iris scales and places them, and the layout around
|
||||
* a world position. Iris's worlds implement it; a module reaches it with {@link #of}. Nothing here hands out the engine.
|
||||
* a world position. Iris offers it as an extension of its worlds and of the settings of the pack it loads:
|
||||
* {@code world.extension(ObjectHost.class)}, {@code settings.extension(ObjectHost.class)}. Nothing here hands out the
|
||||
* engine.
|
||||
*/
|
||||
public interface ObjectHost {
|
||||
/** The host of the world {@code settings} are the pack's of, which must be a world Iris generates. */
|
||||
static ObjectHost of(PackSettings settings) {
|
||||
if (settings instanceof Source source) {
|
||||
return source.objects();
|
||||
}
|
||||
throw new IllegalArgumentException("Built-in modules generate Iris's own worlds, not " + settings);
|
||||
}
|
||||
|
||||
/** The host of {@code world}, which must be a world Iris generates. */
|
||||
static ObjectHost of(PackWorld world) {
|
||||
if (world instanceof Source source) {
|
||||
return source.objects();
|
||||
}
|
||||
throw new IllegalArgumentException("Built-in modules generate Iris's own worlds, not " + world);
|
||||
}
|
||||
|
||||
/** Whether Iris's debug setting is on. */
|
||||
boolean debugging();
|
||||
|
||||
@@ -66,8 +51,8 @@ public interface ObjectHost {
|
||||
/** The random a chunk's objects are placed with: the same for the same chunk of the same world. */
|
||||
RNG chunkRandom(int chunkX, int chunkZ);
|
||||
|
||||
/** The chunk whose objects are being placed on this thread. */
|
||||
ObjectChunk chunk();
|
||||
/** The chunk whose objects the mantle invocation {@code context} places. */
|
||||
ObjectChunk chunk(InvocationContext context);
|
||||
|
||||
/** The object of the pack that {@code key} names. */
|
||||
Optional<PlaceableObject> object(String key);
|
||||
@@ -119,11 +104,6 @@ public interface ObjectHost {
|
||||
record UpperObjects(ObjectSettings biome, ObjectSettings region, String biomeKey, String regionKey) {
|
||||
}
|
||||
|
||||
/** Iris's worlds answer for their objects. */
|
||||
interface Source {
|
||||
ObjectHost objects();
|
||||
}
|
||||
|
||||
/** One region's or biome's declaration of settings. */
|
||||
record Declaration<F extends IrisFeature>(Level level, String key, F settings) {
|
||||
}
|
||||
|
||||
@@ -26,28 +26,17 @@ import com.volmit.resource.PackResources;
|
||||
import com.volmit.world.BlockPosition;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* The object placement being run, as Iris's built-in placement stages see it: what is placed and with which settings, the
|
||||
* terrain it is placed on, and the few block operations that only the platform can do. Iris implements it for each
|
||||
* placement and binds it to the placing thread while the placement graph runs; the stages read it through {@link #current()}.
|
||||
* placement and offers it as an extension of the placement invocation: {@code context.extension(ObjectPlacement.class)}.
|
||||
* Heights are in the coordinates of the placement stages: above the dimension's bottom.
|
||||
* <p>
|
||||
* It never hands out an engine, pack data or a platform type; everything it answers is an IrisApi, VolmLib or
|
||||
* {@code art.arcane.iris.builtin} value.
|
||||
*/
|
||||
public interface ObjectPlacement {
|
||||
/** The placement running on this thread. */
|
||||
static ObjectPlacement current() {
|
||||
return PlacementBinding.current();
|
||||
}
|
||||
|
||||
/** Runs {@code placement} with {@code inputs} as {@link #current()} on this thread. */
|
||||
static <T> T runBound(ObjectPlacement inputs, Supplier<T> placement) {
|
||||
return PlacementBinding.run(inputs, placement);
|
||||
}
|
||||
|
||||
ObjectShape object();
|
||||
|
||||
/** The settings as the caller passed them; the stages derive what they change (the rotation) themselves. */
|
||||
|
||||
@@ -17,40 +17,18 @@
|
||||
*/
|
||||
package art.arcane.iris.builtin.structure;
|
||||
|
||||
import com.volmit.config.PackSettings;
|
||||
import com.volmit.world.PackWorld;
|
||||
import com.volmit.generation.InvocationContext;
|
||||
|
||||
/**
|
||||
* What {@code iris:structure} asks of Iris: Iris places its jigsaw structures itself. The structure model (structures,
|
||||
* pools, pieces), the assembler that builds a structure from them and the locator that spreads them over the world are
|
||||
* Iris's, shared with the jigsaw studio and the structure importers and exporters. Iris's worlds implement it; a module
|
||||
* reaches it with {@link #of}.
|
||||
* Iris's, shared with the jigsaw studio and the structure importers and exporters. Iris offers it as an extension of its
|
||||
* worlds and of the settings of the pack it loads: {@code world.extension(StructureHost.class)}.
|
||||
*/
|
||||
public interface StructureHost {
|
||||
/** The host of the world {@code settings} are the pack's of, which must be a world Iris generates. */
|
||||
static StructureHost of(PackSettings settings) {
|
||||
if (settings instanceof Source source) {
|
||||
return source.structures();
|
||||
}
|
||||
throw new IllegalArgumentException("Built-in modules generate Iris's own worlds, not " + settings);
|
||||
}
|
||||
|
||||
/** The host of {@code world}, which must be a world Iris generates. */
|
||||
static StructureHost of(PackWorld world) {
|
||||
if (world instanceof Source source) {
|
||||
return source.structures();
|
||||
}
|
||||
throw new IllegalArgumentException("Built-in modules generate Iris's own worlds, not " + world);
|
||||
}
|
||||
|
||||
/** Places the structures that start in the chunk whose mantle this thread is generating. */
|
||||
void placeChunk();
|
||||
/** Places the structures that start in the chunk whose mantle the mantle invocation {@code context} generates. */
|
||||
void placeChunk(InvocationContext context);
|
||||
|
||||
/** How far, in blocks along X and Z, a structure may write beyond the chunk it starts in. */
|
||||
int reach();
|
||||
|
||||
/** Iris's worlds answer for their structures. */
|
||||
interface Source {
|
||||
StructureHost structures();
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@
|
||||
package art.arcane.iris.builtin.terrain;
|
||||
|
||||
import art.arcane.iris.builtin.IrisSeed;
|
||||
import art.arcane.iris.builtin.IrisSeeds;
|
||||
import art.arcane.volmlib.util.cache.AtomicCache;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.block.BlockState;
|
||||
@@ -61,7 +62,7 @@ public final class TerrainPalettes {
|
||||
|
||||
TerrainPalettes(PackWorld world) {
|
||||
this.world = world;
|
||||
this.complexSeed = IrisSeed.COMPLEX.of(world);
|
||||
this.complexSeed = world.extension(IrisSeeds.class).orElseThrow().seed(IrisSeed.COMPLEX);
|
||||
}
|
||||
|
||||
/** The palettes of {@code world}. */
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
package art.arcane.iris.engine.actuator;
|
||||
|
||||
import art.arcane.iris.builtin.IrisSeed;
|
||||
import art.arcane.iris.builtin.IrisSeeds;
|
||||
import art.arcane.iris.builtin.terrain.OreSettings;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.config.FeatureSettings.Entry;
|
||||
@@ -49,7 +50,7 @@ final class OreWarmUp {
|
||||
OreWarmUp(PackWorld world, TerrainOres ores) {
|
||||
this.world = world;
|
||||
this.ores = ores;
|
||||
this.root = new RNG(IrisSeed.COMPONENT.of(world) + ROOT_SEED_SALT);
|
||||
this.root = new RNG(world.extension(IrisSeeds.class).orElseThrow().seed(IrisSeed.COMPONENT) + ROOT_SEED_SALT);
|
||||
}
|
||||
|
||||
void warm() {
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
package art.arcane.iris.engine.actuator;
|
||||
|
||||
import art.arcane.iris.builtin.IrisSeed;
|
||||
import art.arcane.iris.builtin.IrisSeeds;
|
||||
import art.arcane.iris.builtin.terrain.OreSettings;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.world.PackWorld;
|
||||
@@ -36,7 +37,7 @@ final class TerrainOres {
|
||||
|
||||
TerrainOres(PackWorld world) {
|
||||
this.resources = world.resources();
|
||||
this.terrainSeed = IrisSeed.TERRAIN.of(world);
|
||||
this.terrainSeed = world.extension(IrisSeeds.class).orElseThrow().seed(IrisSeed.TERRAIN);
|
||||
}
|
||||
|
||||
/** The ores of {@code world}. */
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
package art.arcane.iris.engine.actuator;
|
||||
|
||||
import art.arcane.iris.builtin.IrisSeed;
|
||||
import art.arcane.iris.builtin.IrisSeeds;
|
||||
import art.arcane.iris.builtin.terrain.BedrockSettings;
|
||||
import art.arcane.iris.builtin.terrain.HideOresSettings;
|
||||
import art.arcane.iris.builtin.terrain.OreSettings;
|
||||
@@ -66,7 +67,7 @@ final class TerrainShaper {
|
||||
this.palettes = palettes;
|
||||
this.layers = layers;
|
||||
this.ores = ores;
|
||||
this.rng = new RNG(IrisSeed.TERRAIN.of(world));
|
||||
this.rng = new RNG(world.extension(IrisSeeds.class).orElseThrow().seed(IrisSeed.TERRAIN));
|
||||
this.levelsBelowTheDimensionDeclareOres = world.settings().declared(OreSettings.class).entries().stream()
|
||||
.anyMatch(entry -> entry.level() != Level.DIMENSION);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
package art.arcane.iris.engine.decorator;
|
||||
|
||||
import art.arcane.iris.builtin.IrisSeed;
|
||||
import art.arcane.iris.builtin.IrisSeeds;
|
||||
import art.arcane.iris.builtin.decorant.DecorantSettings;
|
||||
import art.arcane.iris.builtin.decorant.DecorationPart;
|
||||
import art.arcane.iris.builtin.decorant.Decorator;
|
||||
@@ -59,7 +60,7 @@ public final class BiomeDecorators {
|
||||
this.world = world;
|
||||
this.resources = world.resources();
|
||||
this.log = world.log();
|
||||
this.decoratorSeed = IrisSeed.DECORATOR.of(world);
|
||||
this.decoratorSeed = world.extension(IrisSeeds.class).orElseThrow().seed(IrisSeed.DECORATOR);
|
||||
}
|
||||
|
||||
/** The world's decorators, kept in its state store. */
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
package art.arcane.iris.engine.decorator;
|
||||
|
||||
import art.arcane.iris.builtin.IrisSeed;
|
||||
import art.arcane.iris.builtin.IrisSeeds;
|
||||
import com.volmit.ModuleLog;
|
||||
import com.volmit.block.BlockRegistry;
|
||||
import com.volmit.block.BlockState;
|
||||
@@ -52,7 +53,7 @@ public final class DecorationScene {
|
||||
public static DecorationScene of(ChunkStageContext context) {
|
||||
Mantle mantle = context.mantle();
|
||||
return new DecorationScene(context.hunk(BlockState.class), context.world().resources().blocks(), context.terrain(),
|
||||
mantle == null ? null : mantle.blocks(), BiomeDecorators.of(context.world()), IrisSeed.COMPONENT.of(context.world()),
|
||||
mantle == null ? null : mantle.blocks(), BiomeDecorators.of(context.world()), context.world().extension(IrisSeeds.class).orElseThrow().seed(IrisSeed.COMPONENT),
|
||||
context.log());
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -77,7 +77,7 @@ public final class StructureGraphValidation {
|
||||
Set<String> replacementOutputStructures = new LinkedHashSet<>();
|
||||
Map<String, List<SampledVerticalEnvelope>> sampledVerticalEnvelopes = new LinkedHashMap<>();
|
||||
PackStructureResolver resolver = new PackStructureResolver(data);
|
||||
for (ResourceId id : data.getPackResources().ids(IrisStructure.class)) {
|
||||
for (ResourceId id : data.getPackResources().ids(StructureResources.STRUCTURES)) {
|
||||
String structureKey = id.path();
|
||||
if (structureKey.equals(LEGACY_INDEX_KEY) || (activeStructureKeys != null && !activeStructureKeys.contains(structureKey))) {
|
||||
continue;
|
||||
|
||||
@@ -18,15 +18,18 @@
|
||||
|
||||
package art.arcane.iris.engine.framework.structure;
|
||||
|
||||
import art.arcane.iris.core.modules.IrisPackWorld;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.IrisStructureLocator;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.service.LocateResult;
|
||||
import com.volmit.service.StructureLocator;
|
||||
import com.volmit.world.BlockPosition;
|
||||
import com.volmit.world.PackWorld;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@@ -35,26 +38,32 @@ import java.util.Set;
|
||||
* {@link IrisStructureLocator}. The keys it places also name the platform structures its native placements start and
|
||||
* the ones its structures stand in for; it locates those too. The platform's own locate of a natively started
|
||||
* structure goes through {@link StructureVanillaStructures#locateStart} instead.
|
||||
* <p>
|
||||
* Iris's locator names structures by key: a pack structure by its pack key, a platform structure by its
|
||||
* {@code namespace:path}. A key with a namespace is that id; any other is the pack's.
|
||||
*/
|
||||
public final class StructureLocating implements StructureLocator {
|
||||
private static final char NAMESPACE_SEPARATOR = ':';
|
||||
|
||||
@Override
|
||||
public Set<String> structures(PackResources pack) {
|
||||
return new LinkedHashSet<>(StructureResources.structureKeysOf(pack));
|
||||
public Set<ResourceId> structures(PackResources pack) {
|
||||
return idsOf(pack, StructureResources.structureKeysOf(pack));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> locatable(PackWorld world) {
|
||||
return IrisStructureLocator.locatableEditableKeys(engine(world));
|
||||
public Set<ResourceId> locatable(PackWorld world) {
|
||||
return idsOf(world.resources(), IrisStructureLocator.locatableEditableKeys(engine(world)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> placed(PackWorld world) {
|
||||
return IrisStructureLocator.placedKeysAndAliases(engine(world));
|
||||
public Set<ResourceId> placed(PackWorld world) {
|
||||
return idsOf(world.resources(), IrisStructureLocator.placedKeysAndAliases(engine(world)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocateResult locate(PackWorld world, String key, int fromX, int fromZ, int maxRadiusChunks) {
|
||||
public LocateResult locate(PackWorld world, ResourceId structure, int fromX, int fromZ, int maxRadiusChunks) {
|
||||
Engine engine = engine(world);
|
||||
String key = keyOf(world.resources(), IrisStructureLocator.placedKeysAndAliases(engine), structure);
|
||||
IrisStructureLocator.LocateResult result = IrisStructureLocator.locate(engine, key, fromX, fromZ, maxRadiusChunks);
|
||||
return switch (result.status()) {
|
||||
case FOUND -> LocateResult.found(new BlockPosition(result.originX(), result.baseY() - engine.getMinHeight(), result.originZ()));
|
||||
@@ -64,6 +73,28 @@ public final class StructureLocating implements StructureLocator {
|
||||
}
|
||||
|
||||
private static Engine engine(PackWorld world) {
|
||||
return IrisPackWorld.of(world).engine();
|
||||
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) {
|
||||
ids.add(idOf(pack, key));
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
||||
private static ResourceId idOf(PackResources pack, String key) {
|
||||
return key.indexOf(NAMESPACE_SEPARATOR) >= 0 ? ResourceId.parse(key.toLowerCase(Locale.ROOT)) : pack.idOf(key);
|
||||
}
|
||||
|
||||
/** The locator's key of {@code structure}: the placed key with that id, else the id as written. */
|
||||
private static String keyOf(PackResources pack, Collection<String> placedKeys, ResourceId structure) {
|
||||
for (String key : placedKeys) {
|
||||
if (idOf(pack, key).equals(structure)) {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
return structure.toString();
|
||||
}
|
||||
}
|
||||
@@ -87,7 +87,7 @@ public final class StructureResources {
|
||||
}
|
||||
IrisPackResources resources = data.getPackResources();
|
||||
try {
|
||||
return resources.find(kind.key(resources.idOf(key))).orElse(null);
|
||||
return resources.find(kind, resources.idOf(key)).orElse(null);
|
||||
} catch (IllegalStateException failedToLoad) {
|
||||
return null;
|
||||
}
|
||||
@@ -99,6 +99,6 @@ public final class StructureResources {
|
||||
}
|
||||
|
||||
private static List<String> keys(PackResources pack, ResourceKind<?> kind) {
|
||||
return pack.ids(kind.type()).stream().map(ResourceId::path).toList();
|
||||
return pack.ids(kind).stream().map(ResourceId::path).toList();
|
||||
}
|
||||
}
|
||||
+2
-4
@@ -18,8 +18,6 @@
|
||||
|
||||
package art.arcane.iris.engine.framework.structure;
|
||||
|
||||
import art.arcane.iris.core.modules.IrisPackSettings;
|
||||
import art.arcane.iris.core.modules.IrisPackWorld;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.IrisStructureLocator;
|
||||
import art.arcane.iris.engine.framework.StructurePlacementGrid;
|
||||
@@ -64,7 +62,7 @@ public final class StructureVanillaStructures implements VanillaStructures {
|
||||
*/
|
||||
@Override
|
||||
public VanillaStructureRule rule(ResourceId structure, VanillaStructureContext context) {
|
||||
Engine engine = IrisPackSettings.of(context.settings()).engine();
|
||||
Engine engine = context.settings().extension(Engine.class).orElseThrow();
|
||||
String key = structure.toString();
|
||||
boolean replaced = IrisStructureLocator.suppressesVanilla(engine, key);
|
||||
boolean blocked = replaced || ImportedStructures.of(context.settings()).disables(key);
|
||||
@@ -135,7 +133,7 @@ public final class StructureVanillaStructures implements VanillaStructures {
|
||||
}
|
||||
|
||||
private static Engine engine(PackWorld world) {
|
||||
return IrisPackWorld.of(world).engine();
|
||||
return world.extension(Engine.class).orElseThrow();
|
||||
}
|
||||
|
||||
private static Set<ResourceId> structureIds(Set<String> keys) {
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
package art.arcane.iris.engine.framework.structure.fit;
|
||||
|
||||
import art.arcane.iris.engine.mantle.components.StructureCarvingFootprint;
|
||||
import com.volmit.vanilla.StartKey;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -163,8 +164,8 @@ final class CarveFootprints {
|
||||
}
|
||||
}
|
||||
|
||||
/** The platform's start has no value equality, so the key pins the exact start a chunk carves against. */
|
||||
private record CarveFootprintKey(Object start, int padding) {
|
||||
/** A start's key is equal only to itself, so the key pins the exact start a chunk carves against. */
|
||||
private record CarveFootprintKey(StartKey start, int padding) {
|
||||
}
|
||||
|
||||
private record CachedCarveFootprint(StructureCarvingFootprint footprint, int cells) {
|
||||
|
||||
@@ -21,6 +21,7 @@ package art.arcane.iris.engine.framework.structure.fit;
|
||||
import art.arcane.iris.builtin.structure.StructureTerrain;
|
||||
import art.arcane.iris.engine.framework.structure.NativeStructureFit;
|
||||
import com.volmit.vanilla.DecorationStep;
|
||||
import com.volmit.vanilla.StartKey;
|
||||
import com.volmit.vanilla.StructureFit;
|
||||
import com.volmit.vanilla.TerrainAdaptation;
|
||||
|
||||
@@ -88,7 +89,7 @@ final class FitStart {
|
||||
return bounds;
|
||||
}
|
||||
|
||||
Object key() {
|
||||
StartKey key() {
|
||||
return start.key();
|
||||
}
|
||||
}
|
||||
@@ -19,14 +19,13 @@
|
||||
package art.arcane.iris.engine.framework.structure.fit;
|
||||
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.vanilla.StartKey;
|
||||
import com.volmit.vanilla.TemplateCells;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -52,7 +51,7 @@ final class RigidSupport {
|
||||
try {
|
||||
BatchCellBudget budget = new BatchCellBudget();
|
||||
List<SupportRequest> requests = new ArrayList<>();
|
||||
Set<Object> seenStarts = Collections.newSetFromMap(new IdentityHashMap<>());
|
||||
Set<StartKey> seenStarts = new HashSet<>();
|
||||
for (FitStart start : starts) {
|
||||
if (!SurfaceFitting.requiresSurfaceTerrain(start) || !seenStarts.add(start.key())) {
|
||||
continue;
|
||||
|
||||
@@ -22,15 +22,14 @@ import art.arcane.iris.builtin.structure.StructureTerrainMode;
|
||||
import com.volmit.ModuleLog;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.vanilla.DecorationStep;
|
||||
import com.volmit.vanilla.StartKey;
|
||||
import com.volmit.vanilla.TemplateCells;
|
||||
import com.volmit.vanilla.TerrainAdaptation;
|
||||
import com.volmit.world.BlockPosition;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
@@ -222,7 +221,7 @@ final class SurfaceFitting {
|
||||
int maximumTemplateCells, ModuleLog log) {
|
||||
Box influenceArea = area.widened(SURFACE_TERRAIN_RADIUS);
|
||||
List<SurfaceAnchor> anchors = new ArrayList<>();
|
||||
Set<Object> seenStarts = Collections.newSetFromMap(new IdentityHashMap<>());
|
||||
Set<StartKey> seenStarts = new HashSet<>();
|
||||
for (FitStart start : starts) {
|
||||
if (!requiresSourceSurfaceTerrain(start) || !seenStarts.add(start.key())) {
|
||||
continue;
|
||||
@@ -288,7 +287,7 @@ final class SurfaceFitting {
|
||||
Map<Long, Integer> columnCaps = new HashMap<>();
|
||||
Set<Long> foundationBases = new HashSet<>();
|
||||
Set<Long> occupiedCells = new HashSet<>();
|
||||
Set<Object> seenStarts = Collections.newSetFromMap(new IdentityHashMap<>());
|
||||
Set<StartKey> seenStarts = new HashSet<>();
|
||||
for (FitStart start : starts) {
|
||||
if (start.terrain().resolvedMode() != StructureTerrainMode.VACUUM || !seenStarts.add(start.key())) {
|
||||
continue;
|
||||
|
||||
@@ -41,7 +41,7 @@ import java.util.concurrent.ConcurrentMap;
|
||||
public final class BlockDropping implements BlockDrops {
|
||||
@Override
|
||||
public Result drops(PackWorld world, Broken broken) {
|
||||
LiveWorld live = LiveWorld.of(world);
|
||||
LiveWorld live = world.extension(LiveWorld.class).orElseThrow();
|
||||
int x = broken.position().x();
|
||||
int y = broken.position().y();
|
||||
int z = broken.position().z();
|
||||
|
||||
@@ -19,12 +19,14 @@
|
||||
package art.arcane.iris.engine.loot;
|
||||
|
||||
import art.arcane.iris.builtin.IrisSeed;
|
||||
import art.arcane.iris.builtin.IrisSeeds;
|
||||
import art.arcane.iris.builtin.LiveWorld;
|
||||
import art.arcane.iris.builtin.LiveWorld.ObjectLoots;
|
||||
import art.arcane.iris.builtin.loot.LootResolver;
|
||||
import art.arcane.iris.builtin.loot.LootTable;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.item.ItemDrop;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.service.Loot;
|
||||
import com.volmit.world.PackWorld;
|
||||
|
||||
@@ -40,7 +42,7 @@ import java.util.Optional;
|
||||
public final class LootGiving implements Loot {
|
||||
@Override
|
||||
public List<Source> tables(PackWorld world, Site site) {
|
||||
LiveWorld live = LiveWorld.of(world);
|
||||
LiveWorld live = world.extension(LiveWorld.class).orElseThrow();
|
||||
int x = site.position().x();
|
||||
int z = site.position().z();
|
||||
int relativeY = site.position().y();
|
||||
@@ -49,11 +51,11 @@ public final class LootGiving implements Loot {
|
||||
|
||||
List<Source> sources = new ArrayList<>();
|
||||
boolean objectLootDefined = site.nativeLootDefined();
|
||||
Optional<ObjectLoots> objectLoots = site.container() == null ? Optional.empty() : live.objectLoots(x, relativeY, z);
|
||||
Optional<ObjectLoots> objectLoots = site.container().isEmpty() ? Optional.empty() : live.objectLoots(x, relativeY, z);
|
||||
if (objectLoots.isPresent()) {
|
||||
objectLootDefined = objectLootDefined || objectLoots.get().defined();
|
||||
Source picked = placementLoot(world, live).pick(objectLoots.get().platformTables(), objectLoots.get().packTables(),
|
||||
site.container(), rng, x, worldY, z);
|
||||
site.container().get(), rng, x, worldY, z);
|
||||
if (picked != null) {
|
||||
sources.add(picked);
|
||||
if (objectLoots.get().overridesGlobalLoot()) {
|
||||
@@ -62,19 +64,20 @@ public final class LootGiving implements Loot {
|
||||
}
|
||||
}
|
||||
|
||||
LootTables.resolveEnvironmentSources(sources, world, rng, x, relativeY, z, objectLootDefined, Table::new);
|
||||
LootTables.resolveEnvironmentSources(sources, world, rng, x, relativeY, z, objectLootDefined,
|
||||
key -> new Table(world.resources().idOf(key)));
|
||||
return sources;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemDrop> items(PackWorld world, Site site, String key) {
|
||||
LootTable table = LootResources.table(world.resources(), key);
|
||||
public List<ItemDrop> items(PackWorld world, Site site, ResourceId tableId) {
|
||||
LootTable table = LootResources.table(world.resources(), tableId);
|
||||
if (table == null) {
|
||||
return List.of();
|
||||
}
|
||||
int worldY = site.position().y() + LiveWorld.of(world).bottomY();
|
||||
int worldY = site.position().y() + world.extension(LiveWorld.class).orElseThrow().bottomY();
|
||||
return new LootItems(world.resources().items(), site.debug())
|
||||
.draw(key, table, lootSeed(world), site.position().x(), worldY, site.position().z());
|
||||
.draw(tableId.path(), table, lootSeed(world), site.position().x(), worldY, site.position().z());
|
||||
}
|
||||
|
||||
private static PlacementLoot placementLoot(PackWorld world, LiveWorld live) {
|
||||
@@ -82,6 +85,6 @@ public final class LootGiving implements Loot {
|
||||
}
|
||||
|
||||
private static long lootSeed(PackWorld world) {
|
||||
return IrisSeed.LOOT.of(world);
|
||||
return world.extension(IrisSeeds.class).orElseThrow().seed(IrisSeed.LOOT);
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,10 @@ import com.volmit.item.ItemRegistry;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.OptionalDouble;
|
||||
import java.util.OptionalInt;
|
||||
|
||||
/**
|
||||
@@ -106,10 +110,18 @@ public final class LootItems {
|
||||
int amount = Math.max(MIN_AMOUNT, LootResolver.inclusive(rng, entry.minAmount(), entry.maxAmount()));
|
||||
List<ItemEnchantment> enchantments = drawEnchantments(entry, rng);
|
||||
List<ItemAttribute> attributes = drawAttributes(entry, rng);
|
||||
Double damage = maxDurability.getAsInt() > 0 ? 1D - rng.d(entry.minDurability(), entry.maxDurability()) : null;
|
||||
return new ItemDrop(type, amount, entry.displayName(), entry.lore(), enchantments, attributes,
|
||||
entry.unbreakable(), entry.itemFlags(), entry.customModel(), damage, entry.leatherColor(),
|
||||
entry.dyeColor(), entry.customNbt(), debug ? sourceOf(entry, table) : null);
|
||||
OptionalDouble damage = maxDurability.getAsInt() > 0
|
||||
? OptionalDouble.of(1D - rng.d(entry.minDurability(), entry.maxDurability()))
|
||||
: OptionalDouble.empty();
|
||||
return new ItemDrop(type, amount, Optional.ofNullable(entry.displayName()), entry.lore(), enchantments, attributes,
|
||||
entry.unbreakable(), entry.itemFlags(), customModelOf(entry), damage, Optional.ofNullable(entry.leatherColor()),
|
||||
Optional.ofNullable(entry.dyeColor()), Objects.requireNonNullElse(entry.customNbt(), Map.of()),
|
||||
debug ? Optional.of(sourceOf(entry, table)) : Optional.empty());
|
||||
}
|
||||
|
||||
private static OptionalInt customModelOf(LootEntry entry) {
|
||||
Integer customModel = entry.customModel();
|
||||
return customModel == null ? OptionalInt.empty() : OptionalInt.of(customModel);
|
||||
}
|
||||
|
||||
private static List<ItemEnchantment> drawEnchantments(LootEntry entry, RNG rng) {
|
||||
@@ -142,9 +154,9 @@ public final class LootItems {
|
||||
|
||||
private static ItemDrop.Source sourceOf(LootEntry entry, LootTable table) {
|
||||
if (table == null) {
|
||||
return new ItemDrop.Source(null, 0, entry.rarity());
|
||||
return new ItemDrop.Source(Optional.empty(), 0, entry.rarity());
|
||||
}
|
||||
return new ItemDrop.Source(table.name(), table.rarity(), entry.rarity());
|
||||
return new ItemDrop.Source(Optional.ofNullable(table.name()), table.rarity(), entry.rarity());
|
||||
}
|
||||
|
||||
private static boolean isAir(String type) {
|
||||
|
||||
@@ -49,8 +49,12 @@ public final class LootResources {
|
||||
if (key == null || key.isBlank()) {
|
||||
return null;
|
||||
}
|
||||
return table(resources, resources.idOf(key));
|
||||
}
|
||||
|
||||
public static LootTable table(PackResources resources, ResourceId id) {
|
||||
try {
|
||||
return resources.find(TABLES.key(resources.idOf(key))).orElse(null);
|
||||
return resources.find(TABLES, id).orElse(null);
|
||||
} catch (IllegalStateException failedToLoad) {
|
||||
return null;
|
||||
}
|
||||
@@ -58,6 +62,6 @@ public final class LootResources {
|
||||
|
||||
/** The key of every loot table of the pack, in key order. */
|
||||
public static List<String> tableKeys(PackResources resources) {
|
||||
return resources.ids(TABLES.type()).stream().map(ResourceId::path).toList();
|
||||
return resources.ids(TABLES).stream().map(ResourceId::path).toList();
|
||||
}
|
||||
}
|
||||
@@ -83,7 +83,7 @@ public final class LootTables {
|
||||
boolean objectLootDefined,
|
||||
Function<String, T> mapper
|
||||
) {
|
||||
LiveWorld live = LiveWorld.of(world);
|
||||
LiveWorld live = world.extension(LiveWorld.class).orElseThrow();
|
||||
boolean belowSurface = relativeY < live.terrainHeight(x, z);
|
||||
boolean distinctContextualBiome = belowSurface && !live.caveBiome(x, relativeY, z).equals(live.surfaceBiome(x, z));
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ public final class LootValidator implements Validator {
|
||||
|
||||
private static List<Problem> checkTables(PackResources resources) {
|
||||
List<Problem> problems = new ArrayList<>();
|
||||
for (ResourceId id : resources.ids(LootTable.class)) {
|
||||
for (ResourceId id : resources.ids(LootResources.TABLES)) {
|
||||
String lootKey = id.path();
|
||||
List<String> errors = new ArrayList<>();
|
||||
LootTable table = readTable(resources, id, lootKey, errors);
|
||||
@@ -68,7 +68,7 @@ public final class LootValidator implements Validator {
|
||||
}
|
||||
|
||||
private static List<Problem> checkReferences(ValidationContext pack) {
|
||||
Set<ResourceId> lootIds = Set.copyOf(pack.resources().ids(LootTable.class));
|
||||
Set<ResourceId> lootIds = Set.copyOf(pack.resources().ids(LootResources.TABLES));
|
||||
List<Problem> problems = new ArrayList<>();
|
||||
List<Entry<LootSettings>> declared = new ArrayList<>(pack.settings().declared(LootSettings.class).entries());
|
||||
declared.sort(Comparator.comparing(Entry<LootSettings>::level).thenComparing(Entry::source));
|
||||
@@ -93,7 +93,7 @@ public final class LootValidator implements Validator {
|
||||
|
||||
private static LootTable readTable(PackResources resources, ResourceId id, String key, List<String> errors) {
|
||||
try {
|
||||
return resources.find(LootResources.TABLES.key(id)).orElse(null);
|
||||
return resources.find(LootResources.TABLES, id).orElse(null);
|
||||
} catch (IllegalStateException failedToLoad) {
|
||||
errors.add("Loot table '" + key + "' cannot be read: " + failedToLoad.getMessage());
|
||||
return null;
|
||||
|
||||
@@ -86,7 +86,7 @@ final class PlacementLoot {
|
||||
}
|
||||
|
||||
private Loot.Source packSource(String key) {
|
||||
return LootResources.table(resources, key) == null ? null : new Loot.Table(key);
|
||||
return LootResources.table(resources, key) == null ? null : new Loot.Table(resources.idOf(key));
|
||||
}
|
||||
|
||||
private Loot.Source platformSource(String name, int x, int worldY, int z) {
|
||||
|
||||
@@ -89,7 +89,7 @@ final class ChunkObjectPlacing {
|
||||
this.host = host;
|
||||
this.log = log;
|
||||
this.context = context;
|
||||
this.chunk = host.chunk();
|
||||
this.chunk = host.chunk(context);
|
||||
this.terrain = context.terrain();
|
||||
this.chunkX = context.chunkX();
|
||||
this.chunkZ = context.chunkZ();
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
package art.arcane.iris.engine.mantle.components;
|
||||
|
||||
import art.arcane.iris.builtin.IrisSeed;
|
||||
import art.arcane.iris.builtin.IrisSeeds;
|
||||
import art.arcane.iris.builtin.floating.FloatingChildBiome;
|
||||
import art.arcane.iris.builtin.floating.FloatingChildSettings;
|
||||
import art.arcane.iris.builtin.floating.FloatingHost;
|
||||
@@ -87,7 +88,8 @@ public final class FloatingObjectPlacing {
|
||||
/** The floating object placing of {@code world}. */
|
||||
public static FloatingObjectPlacing of(PackWorld world, ModuleLog log) {
|
||||
return world.state(FloatingObjectPlacing.class,
|
||||
generating -> new FloatingObjectPlacing(FloatingWorld.of(generating), IrisSeed.MANTLE.of(generating), log));
|
||||
generating -> new FloatingObjectPlacing(FloatingWorld.of(generating),
|
||||
generating.extension(IrisSeeds.class).orElseThrow().seed(IrisSeed.MANTLE), log));
|
||||
}
|
||||
|
||||
/** Places what originates in the chunk of {@code context} into the mantle. */
|
||||
@@ -101,7 +103,7 @@ public final class FloatingObjectPlacing {
|
||||
new FloatingIslandBoundarySampler(host::surfaceBiome), log);
|
||||
|
||||
FloatingIslandSample.clearChunkMemo();
|
||||
Chunk chunk = new Chunk(minX, minZ, worldHeight, chunkRng, samples, sampleColumns(samples, minX, minZ));
|
||||
Chunk chunk = new Chunk(context, minX, minZ,worldHeight, chunkRng, samples, sampleColumns(samples, minX, minZ));
|
||||
|
||||
// The maps are lookup indices only. Iteration MUST follow the encounter order of the deterministic 0..255 column
|
||||
// scan: identity-hash order changes per JVM run, and the shared chunk random makes placement output depend on order.
|
||||
@@ -204,7 +206,7 @@ public final class FloatingObjectPlacing {
|
||||
continue;
|
||||
}
|
||||
int key = columns.get(rng.i(columns.size()));
|
||||
host.placeFloating(picked.get(), chunk.minX + (key & 15), chunk.minZ + (key >> 4), placement, rng);
|
||||
host.placeFloating(chunk.context, picked.get(),chunk.minX + (key & 15), chunk.minZ + (key >> 4), placement, rng);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -239,7 +241,7 @@ public final class FloatingObjectPlacing {
|
||||
int x = pickedX - footprint.tallestX();
|
||||
int z = pickedZ - footprint.tallestZ();
|
||||
int y = pickTopY + 1 - footprint.lowestSolidY();
|
||||
host.placeOnTop(object, x, y, z, placement, IslandFace.top(chunk.resolver, entry, pickTopY, chunk.worldHeight), rng);
|
||||
host.placeOnTop(chunk.context, object,x, y, z, placement, IslandFace.top(chunk.resolver, entry, pickTopY, chunk.worldHeight), rng);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -266,7 +268,7 @@ public final class FloatingObjectPlacing {
|
||||
int x = invertedBaseX(chunk.minX, pickedXf, footprint, turn);
|
||||
int z = invertedBaseZ(chunk.minZ, pickedZf, footprint, turn);
|
||||
int y = invertedBaseY(pickBottomY, footprint, turn);
|
||||
host.placeUnder(object, x, y, z, turn.yRotation(), placement,
|
||||
host.placeUnder(chunk.context, object,x, y, z, turn.yRotation(), placement,
|
||||
IslandFace.bottom(chunk.resolver, entry, pickBottomY, chunk.worldHeight), rng);
|
||||
}
|
||||
}
|
||||
@@ -386,7 +388,8 @@ public final class FloatingObjectPlacing {
|
||||
|
||||
/** How far, in blocks along X and Z, the floating objects of the pack {@code settings} describe may write beyond their chunk. */
|
||||
public static int reach(PackSettings settings, ModuleLog log) {
|
||||
Reach reach = new Reach(FloatingHost.of(settings), ObjectHost.of(settings), log);
|
||||
Reach reach = new Reach(settings.extension(FloatingHost.class).orElseThrow(),
|
||||
settings.extension(ObjectHost.class).orElseThrow(), log);
|
||||
int maxObjectExtent = MIN_REACH_BLOCKS;
|
||||
try {
|
||||
for (Entry<FloatingChildSettings> declared : settings.declared(FloatingChildSettings.class)) {
|
||||
@@ -476,7 +479,7 @@ public final class FloatingObjectPlacing {
|
||||
}
|
||||
|
||||
/** What one chunk's placements share: where it is, its random, and its columns' island samples. */
|
||||
private record Chunk(int minX, int minZ, int worldHeight, RNG rng, FloatingIslandSampleResolver resolver,
|
||||
FloatingIslandSample[] samples) {
|
||||
private record Chunk(MantleStageContext context, int minX, int minZ, int worldHeight, RNG rng,
|
||||
FloatingIslandSampleResolver resolver, FloatingIslandSample[] samples) {
|
||||
}
|
||||
}
|
||||
@@ -23,12 +23,15 @@ import art.arcane.iris.builtin.objects.ObjectHost.Declaration;
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.builtin.objects.ObjectSettings;
|
||||
import com.volmit.config.Level;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.service.ObjectsAt;
|
||||
import com.volmit.world.PackWorld;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* How {@code iris:objects} tells Iris where its objects are: the objects the biome and region of a chunk would place,
|
||||
@@ -36,29 +39,36 @@ import java.util.Set;
|
||||
*/
|
||||
public final class ObjectLocating implements ObjectsAt {
|
||||
@Override
|
||||
public Set<String> objectsAt(PackWorld world, int chunkX, int chunkZ) {
|
||||
return ObjectPlacing.of(world).guess(chunkX, chunkZ);
|
||||
public Set<ResourceId> objectsAt(PackWorld world, int chunkX, int chunkZ) {
|
||||
return ObjectPlacing.of(world).guess(chunkX, chunkZ).stream()
|
||||
.map(world.resources()::idOf)
|
||||
.collect(Collectors.toCollection(LinkedHashSet::new));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlacedBy placedBy(PackWorld world, String objectKey) {
|
||||
Set<String> biomes = new LinkedHashSet<>();
|
||||
Set<String> regions = new LinkedHashSet<>();
|
||||
for (Declaration<ObjectSettings> declaration : ObjectHost.of(world).declarations(ObjectSettings.class)) {
|
||||
if (!placesObject(declaration.settings().objects(), objectKey)) {
|
||||
public PlacedBy placedBy(PackWorld world, ResourceId object) {
|
||||
PackResources resources = world.resources();
|
||||
Set<ResourceId> biomes = new LinkedHashSet<>();
|
||||
Set<ResourceId> regions = new LinkedHashSet<>();
|
||||
for (Declaration<ObjectSettings> declaration : world.extension(ObjectHost.class).orElseThrow().declarations(ObjectSettings.class)) {
|
||||
if (!placesObject(declaration.settings().objects(), resources, object)) {
|
||||
continue;
|
||||
}
|
||||
(declaration.level() == Level.BIOME ? biomes : regions).add(declaration.key());
|
||||
(declaration.level() == Level.BIOME ? biomes : regions).add(resources.idOf(declaration.key()));
|
||||
}
|
||||
return new PlacedBy(biomes, regions);
|
||||
}
|
||||
|
||||
private static boolean placesObject(List<ObjectPlacement> placements, String objectKey) {
|
||||
private static boolean placesObject(List<ObjectPlacement> placements, PackResources resources, ResourceId object) {
|
||||
for (ObjectPlacement placement : placements) {
|
||||
if (placement != null && placement.carvingSupport().supportsSurface() && placement.place().contains(objectKey)) {
|
||||
if (placement != null && placement.carvingSupport().supportsSurface() && names(placement, resources, object)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean names(ObjectPlacement placement, PackResources resources, ResourceId object) {
|
||||
return placement.place().stream().anyMatch(key -> key != null && resources.idOf(key).equals(object));
|
||||
}
|
||||
}
|
||||
@@ -79,6 +79,6 @@ public final class ObjectModule implements IrisModule, ModuleLifecycle {
|
||||
}
|
||||
|
||||
private static int reach(PackSettings settings, ModuleLog log) {
|
||||
return new PlacementReach(ObjectHost.of(settings), log).ofPack(settings);
|
||||
return new PlacementReach(settings.extension(ObjectHost.class).orElseThrow(), log).ofPack(settings);
|
||||
}
|
||||
}
|
||||
@@ -56,7 +56,7 @@ public final class ObjectPlacing {
|
||||
|
||||
/** The object placing of {@code world}. */
|
||||
public static ObjectPlacing of(PackWorld world) {
|
||||
return world.state(ObjectPlacing.class, generating -> new ObjectPlacing(ObjectHost.of(generating), generating.log()));
|
||||
return world.state(ObjectPlacing.class, generating -> new ObjectPlacing(generating.extension(ObjectHost.class).orElseThrow(), generating.log()));
|
||||
}
|
||||
|
||||
/** Places what originates in the chunk {@code context} generates. */
|
||||
|
||||
@@ -25,6 +25,7 @@ import art.arcane.iris.builtin.objects.ObjectSettings;
|
||||
import art.arcane.iris.builtin.objects.ProceduralObjectSettings;
|
||||
import art.arcane.iris.builtin.objects.ProceduralPlacement;
|
||||
import art.arcane.iris.builtin.IrisSeed;
|
||||
import art.arcane.iris.builtin.IrisSeeds;
|
||||
import art.arcane.iris.engine.object.procedural.ResolvedProceduralObjects;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.config.Level;
|
||||
@@ -48,8 +49,8 @@ final class ObjectWarmUp {
|
||||
private int warmed;
|
||||
|
||||
ObjectWarmUp(PackWorld world) {
|
||||
this.host = ObjectHost.of(world);
|
||||
this.root = new RNG(IrisSeed.COMPONENT.of(world) + ROOT_SEED_SALT);
|
||||
this.host = world.extension(ObjectHost.class).orElseThrow();
|
||||
this.root = new RNG(world.extension(IrisSeeds.class).orElseThrow().seed(IrisSeed.COMPONENT) + ROOT_SEED_SALT);
|
||||
}
|
||||
|
||||
void warm() {
|
||||
|
||||
@@ -51,10 +51,10 @@ public final class StructureModule implements IrisModule {
|
||||
}
|
||||
|
||||
private static void place(MantleStageContext context) {
|
||||
StructureHost.of(context.world()).placeChunk();
|
||||
context.world().extension(StructureHost.class).orElseThrow().placeChunk(context);
|
||||
}
|
||||
|
||||
private static int reach(PackSettings settings) {
|
||||
return StructureHost.of(settings).reach();
|
||||
return settings.extension(StructureHost.class).orElseThrow().reach();
|
||||
}
|
||||
}
|
||||
@@ -41,6 +41,7 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* How {@code iris:objects} grows trees: when a sapling grows, the tree comes from the tree placements of the biome and
|
||||
@@ -53,7 +54,7 @@ public final class TreeGrowing implements SaplingGrowth {
|
||||
|
||||
@Override
|
||||
public Optional<Growth> grow(PackWorld world, Sapling sapling, Surroundings surroundings) {
|
||||
ObjectHost host = ObjectHost.of(world);
|
||||
ObjectHost host = world.extension(ObjectHost.class).orElseThrow();
|
||||
BlockPosition at = sapling.at();
|
||||
TreeGrowthSettings growth = treeGrowth(host, at);
|
||||
if (!growth.enabled()) {
|
||||
@@ -72,12 +73,12 @@ public final class TreeGrowing implements SaplingGrowth {
|
||||
GrowthSink sink = new GrowthSink(surroundings, host);
|
||||
BlockPosition center = sapling.center();
|
||||
host.placeInto(object, center.x(), center.y() + object.height() / 2, center.z(), placement.get(), sink, RNG.r);
|
||||
return Optional.of(new Growth(object.key(), sink.placed()));
|
||||
return Optional.of(new Growth(world.resources().idOf(object.key()), sink.placed()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public TreeObjects treeObjects(PackWorld world) {
|
||||
ObjectHost host = ObjectHost.of(world);
|
||||
ObjectHost host = world.extension(ObjectHost.class).orElseThrow();
|
||||
Set<String> objects = new HashSet<>();
|
||||
Set<String> procedural = new HashSet<>();
|
||||
for (Declaration<ObjectSettings> declaration : host.declarations(ObjectSettings.class)) {
|
||||
@@ -86,7 +87,11 @@ public final class TreeGrowing implements SaplingGrowth {
|
||||
for (Declaration<ProceduralObjectSettings> declaration : host.declarations(ProceduralObjectSettings.class)) {
|
||||
collectProceduralTrees(declaration.settings().trees(), procedural);
|
||||
}
|
||||
return new TreeObjects(objects, procedural);
|
||||
return new TreeObjects(idsOf(world, objects), idsOf(world, procedural));
|
||||
}
|
||||
|
||||
private static Set<ResourceId> idsOf(PackWorld world, Set<String> keys) {
|
||||
return keys.stream().map(world.resources()::idOf).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
private static TreeGrowthSettings treeGrowth(ObjectHost host, BlockPosition at) {
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
package art.arcane.iris.engine.modifier;
|
||||
|
||||
import art.arcane.iris.builtin.IrisSeed;
|
||||
import art.arcane.iris.builtin.IrisSeeds;
|
||||
import art.arcane.iris.builtin.IrisStages;
|
||||
import art.arcane.iris.builtin.MatterMantle;
|
||||
import art.arcane.iris.builtin.carve.CarvingBiomeSettings;
|
||||
@@ -81,12 +82,12 @@ public final class CarveModule implements IrisModule {
|
||||
if (!carves(context)) {
|
||||
return;
|
||||
}
|
||||
MatterMantle mantle = MatterMantle.of(context.mantle());
|
||||
MatterMantle mantle = context.extension(MatterMantle.class).orElseThrow();
|
||||
caveCarving(context).carve(mantle, context.terrain(), context.chunkX(), context.chunkZ());
|
||||
}
|
||||
|
||||
private static void applyCaves(ChunkStageContext context) {
|
||||
MatterMantle mantle = MatterMantle.of(context.mantle());
|
||||
MatterMantle mantle = context.extension(MatterMantle.class).orElseThrow();
|
||||
Hunk<BlockState> blocks = context.hunk(BlockState.class);
|
||||
caveApplying(context).apply(mantle, context.terrain(), context.chunkX(), context.chunkZ(), blocks, CaveDressing.of(context));
|
||||
}
|
||||
@@ -114,7 +115,8 @@ public final class CarveModule implements IrisModule {
|
||||
/** What the carvers need of the world, from the dimension's settings and the first terrain they see (constant for the world). */
|
||||
private static CarveWorld carveWorld(PackWorld world, TerrainSampler terrain) {
|
||||
int lavaHeight = dimensionSetting(world, CaveLavaHeightSettings.class, CaveLavaHeightSettings::height, CaveLavaHeightSettings.DEFAULT_HEIGHT);
|
||||
return new CarveWorld(world.resources().noise(), IrisSeed.CARVE.of(world), terrain.bounds().maxY(), terrain.fluidHeight(), lavaHeight,
|
||||
return new CarveWorld(world.resources().noise(), world.extension(IrisSeeds.class).orElseThrow().seed(IrisSeed.CARVE),
|
||||
terrain.bounds().maxY(), terrain.fluidHeight(), lavaHeight,
|
||||
world.minHeight());
|
||||
}
|
||||
|
||||
|
||||
@@ -34,8 +34,6 @@ import com.volmit.block.BlockState;
|
||||
import com.volmit.hunk.Hunk;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.resource.ResourceKey;
|
||||
import com.volmit.world.PackBiome;
|
||||
import com.volmit.world.PackWorld;
|
||||
import com.volmit.world.TerrainSampler;
|
||||
import lombok.Data;
|
||||
@@ -666,7 +664,7 @@ public class CaveApplying {
|
||||
private ResourceId existingBiomeId(String key) {
|
||||
ResourceId id = resources.idOf(key);
|
||||
try {
|
||||
return resources.find(new ResourceKey<>(id, PackBiome.class)).isPresent() ? id : null;
|
||||
return resources.find(PackResources.BIOMES, id).isPresent() ? id : null;
|
||||
} catch (IllegalStateException unreadable) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ import java.util.Optional;
|
||||
*/
|
||||
public final class CaveBiomeBands implements CaveBiomes {
|
||||
@Override
|
||||
public Optional<String> overriddenBiome(PackWorld world, int x, int y, int z) {
|
||||
public Optional<ResourceId> overriddenBiome(PackWorld world, int x, int y, int z) {
|
||||
CarvingResolver resolver = CarvingResolver.of(world);
|
||||
ResolvedCarvingEntry rootEntry = resolver.rootEntryAt(y);
|
||||
if (rootEntry == null) {
|
||||
@@ -44,12 +44,12 @@ public final class CaveBiomeBands implements CaveBiomes {
|
||||
if (resolver.entryBiome(entry) == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(entry.biomeKey().trim());
|
||||
return Optional.of(world.resources().idOf(entry.biomeKey().trim()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int minDepthBelowSurface(PackWorld world, String biomeKey) {
|
||||
return Depths.of(world).minDepthBelowSurface(world.resources().idOf(biomeKey));
|
||||
public int minDepthBelowSurface(PackWorld world, ResourceId biome) {
|
||||
return Depths.of(world).minDepthBelowSurface(biome);
|
||||
}
|
||||
|
||||
/** The minimum depths the world's biomes declare ({@code caveMinDepthBelowSurface}), found by biome id. */
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
package art.arcane.iris.engine.modifier;
|
||||
|
||||
import art.arcane.iris.builtin.IrisSeed;
|
||||
import art.arcane.iris.builtin.IrisSeeds;
|
||||
import art.arcane.iris.builtin.deposit.DepositGenerator;
|
||||
import art.arcane.iris.builtin.deposit.DepositHeightDistribution;
|
||||
import art.arcane.iris.builtin.deposit.DepositPlacementScope;
|
||||
@@ -36,13 +37,11 @@ import com.volmit.config.FeatureSettings;
|
||||
import com.volmit.config.Level;
|
||||
import com.volmit.config.SettingsStack;
|
||||
import com.volmit.hunk.Hunk;
|
||||
import com.volmit.mantle.MantleLayer;
|
||||
import com.volmit.mantle.Mantle;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.resource.ResourceKey;
|
||||
import com.volmit.stage.ChunkStageContext;
|
||||
import com.volmit.world.BiomeSample;
|
||||
import com.volmit.world.PackBiome;
|
||||
import com.volmit.world.PackWorld;
|
||||
import com.volmit.world.TerrainSampler;
|
||||
|
||||
@@ -78,7 +77,7 @@ final class DepositPlacer {
|
||||
private final Map<ResourceId, Optional<BiomeIdentity>> biomeIdentities = new ConcurrentHashMap<>();
|
||||
|
||||
DepositPlacer(PackWorld world) {
|
||||
this.rng = new RNG(IrisSeed.DEPOSIT.of(world));
|
||||
this.rng = new RNG(world.extension(IrisSeeds.class).orElseThrow().seed(IrisSeed.DEPOSIT));
|
||||
this.resources = world.resources();
|
||||
this.registry = resources.blocks();
|
||||
this.log = world.log();
|
||||
@@ -112,7 +111,7 @@ final class DepositPlacer {
|
||||
}
|
||||
|
||||
private Optional<BiomeIdentity> identityOf(ResourceId biome) {
|
||||
return biomeIdentities.computeIfAbsent(biome, id -> resources.find(new ResourceKey<>(id, PackBiome.class))
|
||||
return biomeIdentities.computeIfAbsent(biome, id -> resources.find(PackResources.BIOMES, id)
|
||||
.map(found -> new BiomeIdentity(id.path(), found.platformBiome().toString(), found.vanillaBiome().toString())));
|
||||
}
|
||||
|
||||
@@ -121,7 +120,7 @@ final class DepositPlacer {
|
||||
private final Hunk<BlockState> blocks;
|
||||
private final TerrainSampler terrain;
|
||||
private final FeatureSettings settings;
|
||||
private final MantleLayer<Boolean> caverns;
|
||||
private final Mantle mantle;
|
||||
private final int originX;
|
||||
private final int originZ;
|
||||
private final int worldHeight;
|
||||
@@ -136,7 +135,7 @@ final class DepositPlacer {
|
||||
this.blocks = context.hunk(BlockState.class);
|
||||
this.terrain = context.terrain();
|
||||
this.settings = context.settings();
|
||||
this.caverns = context.mantle().caverns();
|
||||
this.mantle = context.mantle();
|
||||
this.originX = context.originX();
|
||||
this.originZ = context.originZ();
|
||||
this.worldHeight = blocks.getHeight();
|
||||
@@ -250,7 +249,7 @@ final class DepositPlacer {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (caverns.get(originX + nx, ny, originZ + nz) == null) {
|
||||
if (!mantle.isCarved(originX + nx, ny, originZ + nz)) {
|
||||
BlockState ore = clump.blocks().get(j);
|
||||
BlockState remapped = remapped(nx, ny, nz, ore);
|
||||
BlockState finalBlock = remapped != null
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
package art.arcane.iris.engine.modifier;
|
||||
|
||||
import art.arcane.iris.builtin.IrisSeed;
|
||||
import art.arcane.iris.builtin.IrisSeeds;
|
||||
import art.arcane.iris.builtin.decorant.DecorantSettings;
|
||||
import art.arcane.iris.builtin.decorant.DecorationPart;
|
||||
import art.arcane.iris.builtin.floating.FloatingBottomPaletteMode;
|
||||
@@ -81,7 +82,7 @@ final class FloatingIslands {
|
||||
|
||||
FloatingIslands(PackWorld world, ModuleLog log) {
|
||||
this.world = FloatingWorld.of(world);
|
||||
this.rng = new RNG(IrisSeed.TERRAIN.of(world) ^ ISLAND_RANDOM_SALT);
|
||||
this.rng = new RNG(world.extension(IrisSeeds.class).orElseThrow().seed(IrisSeed.TERRAIN) ^ ISLAND_RANDOM_SALT);
|
||||
this.biomeLayers = BiomeLayers.of(world);
|
||||
this.log = log;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
package art.arcane.iris.engine.modifier;
|
||||
|
||||
import art.arcane.iris.builtin.IrisSeed;
|
||||
import art.arcane.iris.builtin.IrisSeeds;
|
||||
import art.arcane.iris.builtin.post.PostProcessingSlabsSettings;
|
||||
import art.arcane.iris.builtin.post.PostProcessingWallsSettings;
|
||||
import art.arcane.iris.builtin.terrain.LayerBlocks;
|
||||
@@ -81,7 +82,7 @@ final class SurfaceSmoothing {
|
||||
this.terrain = context.terrain();
|
||||
this.settings = context.settings();
|
||||
this.layerBlocks = LayerBlocks.of(context.world());
|
||||
this.postRandom = new RNG(IrisSeed.POST.of(context.world()));
|
||||
this.postRandom = new RNG(context.world().extension(IrisSeeds.class).orElseThrow().seed(IrisSeed.POST));
|
||||
this.originX = context.originX();
|
||||
this.originZ = context.originZ();
|
||||
this.planeWidth = blocks.getWidth() + 2;
|
||||
|
||||
@@ -62,7 +62,7 @@ public final class AnchorModule implements IrisModule {
|
||||
}
|
||||
|
||||
private static AnchorHeight height(PlacementStageContext context) {
|
||||
ObjectPlacement placement = ObjectPlacement.current();
|
||||
ObjectPlacement placement = context.extension(ObjectPlacement.class).orElseThrow();
|
||||
PreparedPlacement prepared = context.output(IrisStages.Prepare.TRANSFORMS);
|
||||
PlacementSettings settings = prepared.settings();
|
||||
boolean structurePiece = prepared.mode().has(PlaceTrait.RAW_STAMP);
|
||||
@@ -89,7 +89,7 @@ public final class AnchorModule implements IrisModule {
|
||||
|
||||
private static AnchorHeight finalHeight(PlacementStageContext context) {
|
||||
int y = context.output(IrisStages.Anchor.HEIGHT).y() + context.output(IrisStages.Prepare.TRANSFORMS).randomY();
|
||||
ObjectPlacement.current().anchoredAt(y);
|
||||
context.extension(ObjectPlacement.class).orElseThrow().anchoredAt(y);
|
||||
return new AnchorHeight(y);
|
||||
}
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ public final class BlocksModule implements IrisModule {
|
||||
}
|
||||
|
||||
private static void write(BlockStageContext context, WrittenBlocks written) {
|
||||
ObjectPlacement placement = ObjectPlacement.current();
|
||||
ObjectPlacement placement = context.extension(ObjectPlacement.class).orElseThrow();
|
||||
PreparedPlacement prepared = context.output(IrisStages.Prepare.TRANSFORMS);
|
||||
PlacementSettings settings = prepared.settings();
|
||||
PlacementWorld world = new PlacementWorld(context.access(), prepared.traits());
|
||||
@@ -198,7 +198,7 @@ public final class BlocksModule implements IrisModule {
|
||||
* where the marker either allows anything above or finds two blocks of air.
|
||||
*/
|
||||
private static void placeMarkers(PlacementStageContext context) {
|
||||
ObjectPlacement placement = ObjectPlacement.current();
|
||||
ObjectPlacement placement = context.extension(ObjectPlacement.class).orElseThrow();
|
||||
PreparedPlacement prepared = context.output(IrisStages.Prepare.TRANSFORMS);
|
||||
PlacementSettings settings = prepared.settings();
|
||||
if (settings.markers().isEmpty() || !prepared.terrain().hasWorld()) {
|
||||
|
||||
@@ -50,7 +50,7 @@ public final class BoreModule implements IrisModule {
|
||||
if (!settings.bore()) {
|
||||
return;
|
||||
}
|
||||
ObjectPlacement placement = ObjectPlacement.current();
|
||||
ObjectPlacement placement = context.extension(ObjectPlacement.class).orElseThrow();
|
||||
WorldVolume volume = WorldVolume.of(placement, prepared, context.output(IrisStages.Anchor.FINAL).y());
|
||||
PlacementWorld world = new PlacementWorld(context.access(), prepared.traits());
|
||||
for (int x = volume.minX(); x <= volume.maxX(); x++) {
|
||||
|
||||
@@ -72,7 +72,7 @@ public final class PrepareModule implements IrisModule {
|
||||
}
|
||||
|
||||
private static ObjectRotation slope(PlacementStageContext context) {
|
||||
ObjectPlacement placement = ObjectPlacement.current();
|
||||
ObjectPlacement placement = context.extension(ObjectPlacement.class).orElseThrow();
|
||||
PlacementSettings settings = placement.settings();
|
||||
ObjectRotation requested = settings.rotation();
|
||||
boolean checksSlope = !settings.forcePlace() && !settings.slopeCondition().isDefault();
|
||||
@@ -112,7 +112,7 @@ public final class PrepareModule implements IrisModule {
|
||||
}
|
||||
|
||||
private static PreparedPlacement transforms(PlacementStageContext context) {
|
||||
ObjectPlacement placement = ObjectPlacement.current();
|
||||
ObjectPlacement placement = context.extension(ObjectPlacement.class).orElseThrow();
|
||||
PlacementSettings settings = placement.settings();
|
||||
ObjectRotation rotation = context.output(IrisStages.Prepare.SLOPE);
|
||||
ObjectShape object = placement.object();
|
||||
|
||||
@@ -133,7 +133,7 @@ public final class StiltModule implements IrisModule {
|
||||
private final ErodeShape erode;
|
||||
|
||||
private StiltColumns(PlacementStageContext context, PreparedPlacement prepared, StiltLayers layers) {
|
||||
this.placement = ObjectPlacement.current();
|
||||
this.placement = context.extension(ObjectPlacement.class).orElseThrow();
|
||||
this.prepared = prepared;
|
||||
this.context = context;
|
||||
this.config = prepared.settings();
|
||||
|
||||
@@ -91,7 +91,7 @@ public final class VacuumModule implements IrisModule {
|
||||
|
||||
private Bend(PlacementStageContext context, PreparedPlacement prepared) {
|
||||
VacuumProfile vacuum = prepared.mode().vacuum();
|
||||
this.placement = ObjectPlacement.current();
|
||||
this.placement = context.extension(ObjectPlacement.class).orElseThrow();
|
||||
this.prepared = prepared;
|
||||
this.terrain = prepared.terrain();
|
||||
this.world = new PlacementWorld(context.access(), prepared.traits());
|
||||
|
||||
@@ -76,7 +76,7 @@ public final class ValidateModule implements IrisModule {
|
||||
}
|
||||
|
||||
private static void checkSurface(PlacementStageContext context) {
|
||||
ObjectPlacement placement = ObjectPlacement.current();
|
||||
ObjectPlacement placement = context.extension(ObjectPlacement.class).orElseThrow();
|
||||
PreparedPlacement prepared = context.output(IrisStages.Prepare.TRANSFORMS);
|
||||
PlacementSettings settings = prepared.settings();
|
||||
if (settings.forcePlace() || settings.fromBottom() || prepared.mode().has(PlaceTrait.FREE_HEIGHT)) {
|
||||
@@ -110,7 +110,7 @@ public final class ValidateModule implements IrisModule {
|
||||
}
|
||||
|
||||
private static void checkLimits(PlacementStageContext context) {
|
||||
ObjectPlacement placement = ObjectPlacement.current();
|
||||
ObjectPlacement placement = context.extension(ObjectPlacement.class).orElseThrow();
|
||||
PreparedPlacement prepared = context.output(IrisStages.Prepare.TRANSFORMS);
|
||||
PlacementSettings settings = prepared.settings();
|
||||
if (settings.forcePlace() || prepared.mode().has(PlaceTrait.RAW_STAMP)) {
|
||||
@@ -139,7 +139,7 @@ public final class ValidateModule implements IrisModule {
|
||||
return;
|
||||
}
|
||||
int y = context.output(IrisStages.Anchor.HEIGHT).y() + prepared.randomY();
|
||||
if (meetsNativeStructure(context, ObjectPlacement.current(), prepared, y)) {
|
||||
if (meetsNativeStructure(context, context.extension(ObjectPlacement.class).orElseThrow(), prepared, y)) {
|
||||
context.reject("native-structure");
|
||||
}
|
||||
}
|
||||
@@ -198,7 +198,7 @@ public final class ValidateModule implements IrisModule {
|
||||
}
|
||||
|
||||
private static void checkCollisions(PlacementStageContext context) {
|
||||
ObjectPlacement placement = ObjectPlacement.current();
|
||||
ObjectPlacement placement = context.extension(ObjectPlacement.class).orElseThrow();
|
||||
PreparedPlacement prepared = context.output(IrisStages.Prepare.TRANSFORMS);
|
||||
PlacementSettings settings = prepared.settings();
|
||||
if (settings.forcePlace() || prepared.mode().has(PlaceTrait.RAW_STAMP)
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
package art.arcane.iris.engine.object.terrain.carving;
|
||||
|
||||
import art.arcane.iris.builtin.IrisSeed;
|
||||
import art.arcane.iris.builtin.IrisSeeds;
|
||||
import art.arcane.iris.builtin.carve.CarvingEntry;
|
||||
import art.arcane.iris.builtin.carve.CarvingSettings;
|
||||
import com.volmit.ModuleLog;
|
||||
@@ -59,7 +60,7 @@ public final class CarvingResolver {
|
||||
this.resources = world.resources();
|
||||
this.log = world.log();
|
||||
this.minHeight = world.minHeight();
|
||||
this.childSeed = IrisSeed.CARVE.of(world) ^ CHILD_SEED_SALT;
|
||||
this.childSeed = world.extension(IrisSeeds.class).orElseThrow().seed(IrisSeed.CARVE) ^ CHILD_SEED_SALT;
|
||||
this.entries = declared.stream().filter(Objects::nonNull).map(ResolvedCarvingEntry::new).toList();
|
||||
this.index = indexById(entries);
|
||||
}
|
||||
|
||||
+1
-2
@@ -24,7 +24,6 @@ import com.volmit.ModuleLog;
|
||||
import com.volmit.config.Range;
|
||||
import com.volmit.noise.NoiseSampler;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceKey;
|
||||
import com.volmit.world.PackBiome;
|
||||
|
||||
import java.util.List;
|
||||
@@ -82,7 +81,7 @@ public final class ResolvedCarvingEntry {
|
||||
}
|
||||
|
||||
try {
|
||||
return resources.find(new ResourceKey<>(resources.idOf(biomeKey.trim()), PackBiome.class)).orElse(null);
|
||||
return resources.find(PackResources.BIOMES, resources.idOf(biomeKey.trim())).orElse(null);
|
||||
} catch (IllegalStateException unreadable) {
|
||||
log.warnOnce("carving-biome:" + biomeKey, "The biome " + biomeKey + " of a carving entry cannot be loaded: " + unreadable.getMessage());
|
||||
return null;
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
package art.arcane.iris.engine.object.terrain.floating;
|
||||
|
||||
import art.arcane.iris.builtin.IrisSeed;
|
||||
import art.arcane.iris.builtin.IrisSeeds;
|
||||
import art.arcane.iris.builtin.carve.CarvingEntry;
|
||||
import art.arcane.iris.builtin.carve.CarvingSettings;
|
||||
import art.arcane.iris.builtin.carve.CaveProfile;
|
||||
@@ -71,8 +72,10 @@ public final class FloatingWorld {
|
||||
}
|
||||
|
||||
private static FloatingWorld create(PackWorld world) {
|
||||
return new FloatingWorld(FloatingHost.of(world), ObjectHost.of(world), world.resources().noise(), IrisSeed.TERRAIN.of(world),
|
||||
IrisSeed.CARVE.of(world), world.minHeight(), dimensionCarvingOf(world));
|
||||
IrisSeeds seeds = world.extension(IrisSeeds.class).orElseThrow();
|
||||
return new FloatingWorld(world.extension(FloatingHost.class).orElseThrow(), world.extension(ObjectHost.class).orElseThrow(),
|
||||
world.resources().noise(), seeds.seed(IrisSeed.TERRAIN), seeds.seed(IrisSeed.CARVE), world.minHeight(),
|
||||
dimensionCarvingOf(world));
|
||||
}
|
||||
|
||||
private static List<CarvingEntry> dimensionCarvingOf(PackWorld world) {
|
||||
|
||||
@@ -347,7 +347,7 @@ public class IrisDimension extends IrisRegistrant {
|
||||
}
|
||||
}
|
||||
|
||||
addReachableBiomeKeys(pending, getModuleSettings().usedBiomes(getModuleSettings()));
|
||||
addReachableBiomeKeys(pending, getModuleSettings().usedBiomes(data.getPackResources(), getModuleSettings()));
|
||||
|
||||
Set<String> visited = new HashSet<>();
|
||||
while (!pending.isEmpty()) {
|
||||
@@ -369,8 +369,8 @@ public class IrisDimension extends IrisRegistrant {
|
||||
visited.add(loadKey);
|
||||
biomes.put(loadKey, biome);
|
||||
addReachableBiomeKeys(pending, biome.getChildren());
|
||||
addReachableBiomeKeys(pending, biome.getModuleSettings().treeBiomes());
|
||||
addReachableBiomeKeys(pending, biome.getModuleSettings().usedBiomes(getModuleSettings()));
|
||||
addReachableBiomeKeys(pending, biome.getModuleSettings().treeBiomes(data.getPackResources()));
|
||||
addReachableBiomeKeys(pending, biome.getModuleSettings().usedBiomes(data.getPackResources(), getModuleSettings()));
|
||||
}
|
||||
|
||||
return biomes.v();
|
||||
|
||||
@@ -153,7 +153,7 @@ public class IrisRegion extends IrisRegistrant implements IRare {
|
||||
continue;
|
||||
}
|
||||
|
||||
names.addAll(biome.getModuleSettings().treeBiomes());
|
||||
names.addAll(biome.getModuleSettings().treeBiomes(g.getData().getPackResources()));
|
||||
b.put(biome.getLoadKey(), biome);
|
||||
names.addAll(biome.getChildren());
|
||||
}
|
||||
@@ -250,7 +250,7 @@ public class IrisRegion extends IrisRegistrant implements IRare {
|
||||
continue;
|
||||
}
|
||||
|
||||
names.addAll(biome.getModuleSettings().treeBiomes());
|
||||
names.addAll(biome.getModuleSettings().treeBiomes(biome.getLoader().getPackResources()));
|
||||
b.put(biome.getLoadKey(), biome);
|
||||
names.addAll(biome.getChildren());
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ import java.util.Optional;
|
||||
public final class AmbientEffecting implements AmbientEffects {
|
||||
@Override
|
||||
public List<Effect> due(PackWorld world, BlockPosition at) {
|
||||
LiveWorld live = LiveWorld.of(world);
|
||||
LiveWorld live = world.extension(LiveWorld.class).orElseThrow();
|
||||
EffectTimers timers = world.state(EffectTimers.class, ignored -> new EffectTimers());
|
||||
Optional<Sky> sky = live.sky();
|
||||
|
||||
@@ -65,8 +65,8 @@ public final class AmbientEffecting implements AmbientEffects {
|
||||
}
|
||||
|
||||
private static Effect play(AmbientEffect effect, Optional<Sky> sky) {
|
||||
Sound sound = effect.sound() == null ? null : soundOf(effect);
|
||||
Particles particles = effect.particleEffect() == null ? null : particlesOf(effect);
|
||||
Optional<Sound> sound = effect.sound() == null ? Optional.empty() : Optional.of(soundOf(effect));
|
||||
Optional<Particles> particles = effect.particleEffect() == null ? Optional.empty() : Optional.of(particlesOf(effect));
|
||||
return new Effect(sound, particles, commandsOf(effect.commandRegistry(), sky), potionOf(effect));
|
||||
}
|
||||
|
||||
@@ -115,14 +115,14 @@ public final class AmbientEffecting implements AmbientEffects {
|
||||
return commands;
|
||||
}
|
||||
|
||||
private static Potion potionOf(AmbientEffect effect) {
|
||||
private static Optional<Potion> potionOf(AmbientEffect effect) {
|
||||
if (effect.potionStrength() <= -1) {
|
||||
return null;
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
int shortest = Math.min(effect.potionTicksMax(), effect.potionTicksMin());
|
||||
int longest = Math.max(effect.potionTicksMax(), effect.potionTicksMin());
|
||||
return new Potion(effect.potionEffect(), effect.potionStrength(), RNG.r.i(shortest, longest));
|
||||
return Optional.of(new Potion(effect.potionEffect(), effect.potionStrength(), RNG.r.i(shortest, longest)));
|
||||
}
|
||||
|
||||
private static double commandOffset(double offset, boolean random) {
|
||||
|
||||
@@ -30,6 +30,8 @@ import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.entity.EntitySpec;
|
||||
import com.volmit.item.ItemAttribute;
|
||||
import com.volmit.item.ItemDrop;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -43,12 +45,17 @@ final class EntityResolution {
|
||||
private static final long PASSENGER_STREAM_BASE = 234858L;
|
||||
private static final long LEASH_HOLDER_STREAM = 234548L;
|
||||
|
||||
private final PackResources resources;
|
||||
private final LootItems items;
|
||||
private final Optional<Sky> sky;
|
||||
private final EffectTimers timers;
|
||||
|
||||
/** @param sky the sky of the world the entity appears in, whose time and weather decide which of its commands run; none while the world has no platform world */
|
||||
EntityResolution(LootItems items, Optional<Sky> sky, EffectTimers timers) {
|
||||
/**
|
||||
* @param resources names the entity's loot tables by id
|
||||
* @param sky the sky of the world the entity appears in, whose time and weather decide which of its commands run; none while the world has no platform world
|
||||
*/
|
||||
EntityResolution(PackResources resources, LootItems items, Optional<Sky> sky, EffectTimers timers) {
|
||||
this.resources = resources;
|
||||
this.items = items;
|
||||
this.sky = sky;
|
||||
this.timers = timers;
|
||||
@@ -62,21 +69,24 @@ final class EntityResolution {
|
||||
}
|
||||
|
||||
List<ItemAttribute> attributes = drawAttributes(entity, rng);
|
||||
List<String> lootTables = List.copyOf(entity.loot().tables());
|
||||
List<ResourceId> lootTables = entity.loot().tables().stream().map(resources::idOf).toList();
|
||||
long lootShuffleSeed = lootTables.isEmpty() ? 0L : rng.nextLong();
|
||||
EntitySpec leashHolder = entity.leashHolder() == null ? null : resolve(entity.leashHolder(), rng.nextParallelRNG(LEASH_HOLDER_STREAM));
|
||||
Optional<EntitySpec> leashHolder = entity.leashHolder() == null
|
||||
? Optional.empty()
|
||||
: Optional.of(resolve(entity.leashHolder(), rng.nextParallelRNG(LEASH_HOLDER_STREAM)));
|
||||
EntitySpec.Equipment equipment = new EntitySpec.Equipment(
|
||||
equip(entity.helmet(), rng), equip(entity.chestplate(), rng), equip(entity.leggings(), rng),
|
||||
equip(entity.boots(), rng), equip(entity.mainHand(), rng), equip(entity.offHand(), rng));
|
||||
|
||||
return new EntitySpec(
|
||||
entity.type() == null ? "" : entity.type(),
|
||||
entity.specialType() == null ? "" : entity.specialType(),
|
||||
entity.reason(),
|
||||
entity.customName() == null ? "" : entity.customName(),
|
||||
flagsOf(entity), equipment, passengers, attributes, lootTables, lootShuffleSeed, leashHolder,
|
||||
spawnEffectOf(entity), entity.spawnEffectRiseOutOfGround(), entity.pandaMainGene(),
|
||||
entity.pandaHiddenGene(), entity.applySettingsToCustomMobAnyways(), commandsOf(entity));
|
||||
return new EntitySpec(textOf(entity.type()), textOf(entity.specialType()), textOf(entity.reason()),
|
||||
textOf(entity.customName()), flagsOf(entity), equipment, passengers, attributes, lootTables, lootShuffleSeed,
|
||||
leashHolder, spawnEffectOf(entity), entity.spawnEffectRiseOutOfGround(), textOf(entity.pandaMainGene()),
|
||||
textOf(entity.pandaHiddenGene()), entity.applySettingsToCustomMobAnyways(), commandsOf(entity));
|
||||
}
|
||||
|
||||
/** A text the pack may leave out or blank, as absent then. */
|
||||
private static Optional<String> textOf(String text) {
|
||||
return text == null || text.isBlank() ? Optional.empty() : Optional.of(text);
|
||||
}
|
||||
|
||||
private static EntitySpec.Flags flagsOf(EntityDefinition entity) {
|
||||
@@ -100,23 +110,23 @@ final class EntityResolution {
|
||||
return attributes;
|
||||
}
|
||||
|
||||
private ItemDrop equip(LootEntry piece, RNG rng) {
|
||||
private Optional<ItemDrop> equip(LootEntry piece, RNG rng) {
|
||||
if (piece == null || !LootResolver.oneIn(rng, piece.rarity())) {
|
||||
return null;
|
||||
return Optional.empty();
|
||||
}
|
||||
return items.give(piece, rng);
|
||||
return Optional.ofNullable(items.give(piece, rng));
|
||||
}
|
||||
|
||||
/** The entity's spawn effect when it shows this time: an effect only shows now and then, as its interval and chance say. */
|
||||
private EntitySpec.SpawnEffect spawnEffectOf(EntityDefinition entity) {
|
||||
private Optional<EntitySpec.SpawnEffect> spawnEffectOf(EntityDefinition entity) {
|
||||
AmbientEffect effect = entity.spawnEffect();
|
||||
if (effect == null || !timers.shouldPlayNow(effect)) {
|
||||
return null;
|
||||
return Optional.empty();
|
||||
}
|
||||
return new EntitySpec.SpawnEffect(effect.sound(), effect.soundDistance(), effect.minPitch(),
|
||||
effect.maxPitch(), effect.volume(), effect.particleEffect(), effect.particleOffset(),
|
||||
return Optional.of(new EntitySpec.SpawnEffect(textOf(effect.sound()), effect.soundDistance(), effect.minPitch(),
|
||||
effect.maxPitch(), effect.volume(), textOf(effect.particleEffect()), effect.particleOffset(),
|
||||
effect.particleCount(), effect.particleAltX(), effect.particleAltY(), effect.particleAltZ(),
|
||||
effect.randomAltX(), effect.randomAltY(), effect.randomAltZ(), effect.extra());
|
||||
effect.randomAltX(), effect.randomAltY(), effect.randomAltZ(), effect.extra()));
|
||||
}
|
||||
|
||||
private List<EntitySpec.Command> commandsOf(EntityDefinition entity) {
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
package art.arcane.iris.engine.spawn;
|
||||
|
||||
import art.arcane.iris.builtin.IrisSeed;
|
||||
import art.arcane.iris.builtin.IrisSeeds;
|
||||
import art.arcane.iris.builtin.LiveWorld;
|
||||
import art.arcane.iris.builtin.LiveWorld.Level;
|
||||
import art.arcane.iris.builtin.loot.LootResolver;
|
||||
@@ -37,6 +38,7 @@ import art.arcane.volmlib.util.scheduling.ChronoLatch;
|
||||
import com.volmit.config.Range;
|
||||
import com.volmit.entity.EntitySpec;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.service.EntitySpawns;
|
||||
import com.volmit.world.BlockPosition;
|
||||
import com.volmit.world.PackWorld;
|
||||
@@ -76,15 +78,16 @@ public final class EntitySpawning implements EntitySpawns {
|
||||
if (count <= 0) {
|
||||
return;
|
||||
}
|
||||
Spawner spawner = SpawnResources.spawner(world.resources(), plan.spawner());
|
||||
String spawnerKey = plan.spawner().path();
|
||||
Spawner spawner = SpawnResources.spawner(world.resources(), spawnerKey);
|
||||
if (spawner != null) {
|
||||
SpawnerGate.spawned(plan.spawner(), spawner, LiveWorld.of(world), plan.chunkX(), plan.chunkZ());
|
||||
SpawnerGate.spawned(spawnerKey, spawner, world.extension(LiveWorld.class).orElseThrow(), plan.chunkX(), plan.chunkZ());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<EntitySpec> entity(PackWorld world, String key) {
|
||||
EntityDefinition entity = SpawnResources.entity(world.resources(), key);
|
||||
public Optional<EntitySpec> entity(PackWorld world, ResourceId id) {
|
||||
EntityDefinition entity = SpawnResources.entity(world.resources(), id.path());
|
||||
if (entity == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
@@ -101,13 +104,13 @@ public final class EntitySpawning implements EntitySpawns {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
List<String> spawners = new ArrayList<>();
|
||||
List<ResourceId> spawners = new ArrayList<>();
|
||||
for (String key : marker.spawners()) {
|
||||
if (SpawnResources.spawner(world.resources(), key) == null) {
|
||||
world.log().error("Cannot load spawner: " + key + " for marker " + tag, null);
|
||||
continue;
|
||||
}
|
||||
spawners.add(key);
|
||||
spawners.add(world.resources().idOf(key));
|
||||
}
|
||||
return Optional.of(new MarkerRule(spawners, marker.emptyAbove(), marker.removeOnChange()));
|
||||
}
|
||||
@@ -119,14 +122,14 @@ public final class EntitySpawning implements EntitySpawns {
|
||||
return;
|
||||
}
|
||||
PackResources resources = world.resources();
|
||||
LiveWorld.of(world).spawnCooldowns().forgetExpired(key -> {
|
||||
world.extension(LiveWorld.class).orElseThrow().spawnCooldowns().forgetExpired(key -> {
|
||||
Spawner spawner = SpawnResources.spawner(resources, key);
|
||||
return spawner == null ? -1L : spawner.maximumRate().interval();
|
||||
});
|
||||
}
|
||||
|
||||
private Optional<Plan> planChunk(PackWorld world, Chunk chunk) {
|
||||
LiveWorld live = LiveWorld.of(world);
|
||||
LiveWorld live = world.extension(LiveWorld.class).orElseThrow();
|
||||
Predicate<KeyedSpawner> canSpawn = keyed -> SpawnerGate.canSpawn(keyed.key(), keyed.spawner(), live, chunk.chunkX(), chunk.chunkZ());
|
||||
int blockX = PowerOfTwoCoordinates.chunkToBlock(chunk.chunkX());
|
||||
int blockZ = PowerOfTwoCoordinates.chunkToBlock(chunk.chunkZ());
|
||||
@@ -161,7 +164,7 @@ public final class EntitySpawning implements EntitySpawns {
|
||||
addAttempt(attempts, world, chosen, at, true);
|
||||
}
|
||||
}
|
||||
return attempts.isEmpty() ? Optional.empty() : Optional.of(new Plan(chosen.key(), chunk.chunkX(), chunk.chunkZ(), false, attempts));
|
||||
return attempts.isEmpty() ? Optional.empty() : Optional.of(new Plan(world.resources().idOf(chosen.key()), chunk.chunkX(), chunk.chunkZ(), false, attempts));
|
||||
}
|
||||
|
||||
/** Where a spawner of its group puts an entity at the column; null when it has no place for one. */
|
||||
@@ -182,7 +185,8 @@ public final class EntitySpawning implements EntitySpawns {
|
||||
}
|
||||
|
||||
private Optional<Plan> planMarker(PackWorld world, Marker marker) {
|
||||
Spawner spawner = SpawnResources.spawner(world.resources(), marker.spawner());
|
||||
String spawnerKey = marker.spawner().path();
|
||||
Spawner spawner = SpawnResources.spawner(world.resources(), spawnerKey);
|
||||
SpawnMarker spawnMarker = SpawnResources.marker(world.resources(), marker.marker());
|
||||
if (spawner == null) {
|
||||
return Optional.empty();
|
||||
@@ -197,8 +201,8 @@ public final class EntitySpawning implements EntitySpawns {
|
||||
BlockPosition position = marker.position();
|
||||
int chunkX = PowerOfTwoCoordinates.blockToChunkFloor(position.x());
|
||||
int chunkZ = PowerOfTwoCoordinates.blockToChunkFloor(position.z());
|
||||
LiveWorld live = LiveWorld.of(world);
|
||||
if (!SpawnerGate.canSpawn(marker.spawner(), spawner, live, chunkX, chunkZ)) {
|
||||
LiveWorld live = world.extension(LiveWorld.class).orElseThrow();
|
||||
if (!SpawnerGate.canSpawn(spawnerKey, spawner, live, chunkX, chunkZ)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@@ -210,7 +214,7 @@ public final class EntitySpawning implements EntitySpawns {
|
||||
List<Attempt> attempts = new ArrayList<>();
|
||||
BlockPosition above = new BlockPosition(position.x(), position.y() + AIR_ABOVE_MARKER, position.z());
|
||||
for (int i = 0; i < count; i++) {
|
||||
addAttempt(attempts, world, new Candidate(marker.spawner(), spawner, spawn), above, false);
|
||||
addAttempt(attempts, world, new Candidate(spawnerKey, spawner, spawn), above, false);
|
||||
}
|
||||
return attempts.isEmpty() ? Optional.empty() : Optional.of(new Plan(marker.spawner(), chunkX, chunkZ, exhaustsMarker, attempts));
|
||||
}
|
||||
@@ -233,9 +237,9 @@ public final class EntitySpawning implements EntitySpawns {
|
||||
}
|
||||
|
||||
private static EntityResolution resolution(PackWorld world) {
|
||||
LiveWorld live = LiveWorld.of(world);
|
||||
LiveWorld live = world.extension(LiveWorld.class).orElseThrow();
|
||||
LootItems items = new LootItems(world.resources().items(), live.studio());
|
||||
return new EntityResolution(items, live.sky(), world.state(EffectTimers.class, ignored -> new EffectTimers()));
|
||||
return new EntityResolution(world.resources(), items, live.sky(),world.state(EffectTimers.class, ignored -> new EffectTimers()));
|
||||
}
|
||||
|
||||
private static EntityRandom entityRandom(PackWorld world) {
|
||||
@@ -270,7 +274,7 @@ public final class EntitySpawning implements EntitySpawns {
|
||||
private final RNG rng;
|
||||
|
||||
private EntityRandom(PackWorld world) {
|
||||
this.rng = new RNG(IrisSeed.ENTITY.of(world));
|
||||
this.rng = new RNG(world.extension(IrisSeeds.class).orElseThrow().seed(IrisSeed.ENTITY));
|
||||
}
|
||||
|
||||
private RNG rng() {
|
||||
|
||||
@@ -100,7 +100,7 @@ public final class SpawnResources {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return resources.find(kind.key(resources.idOf(key))).orElse(null);
|
||||
return resources.find(kind, resources.idOf(key)).orElse(null);
|
||||
} catch (IllegalStateException failedToLoad) {
|
||||
return null;
|
||||
}
|
||||
@@ -108,6 +108,6 @@ public final class SpawnResources {
|
||||
|
||||
/** A key's id has the key as its path, so the path names the resource again wherever a key is expected. */
|
||||
private static List<String> keys(PackResources resources, ResourceKind<?> kind) {
|
||||
return resources.ids(kind.type()).stream().map(ResourceId::path).toList();
|
||||
return resources.ids(kind).stream().map(ResourceId::path).toList();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user