diff --git a/README.md b/README.md
index 3c3ad9e5f..01abf7153 100644
--- a/README.md
+++ b/README.md
@@ -137,10 +137,12 @@ naming the class and what it uses. A VolmLib class that Iris's Bukkit jar strips
`core/volmlib-left-out-of-bukkit-jar.txt`, which its shadowJar reads too) is on that classpath but missing on a
server, so the check treats it as missing and fails the task naming it. `check` runs the task.
-The jar holds `iris:post`, `iris:perfection` and `iris:matter`. They are written against IrisApi and
+The jar holds `iris:post`, `iris:perfection`, `iris:matter`, `iris:loot` and `iris:spawn`. They are written against IrisApi and
`art.arcane.iris.builtin` alone: the chunk's `BlockState` hunk, the block registry's traits and `canPlaceOn`, the terrain
-sampler (heights around the chunk, slope, fluid height, where the upper dimension begins) and the mantle's planned blocks.
-Iris no longer compiles them in (`IrisModuleHost.generationModules()`), so a pack gets them by putting
+sampler (heights around the chunk, slope, fluid height, where the upper dimension begins) and the mantle's planned blocks;
+the loot and spawn services, which have no chunk to ask, ask `LiveWorld` (below). Without the jar a pack's world has no
+loot, block drops, entity spawns or ambient effects, and its biomes' `loot`, `blockDrops`, `entitySpawners` and `effects` are
+not read. Iris no longer compiles them in (`IrisModuleHost.generationModules()`), so a pack gets them by putting
`iris-builtins.jar` into its `modules` folder; the built-ins that order after their stages (`iris:floating`,
`iris:decorant`, `iris:custom`) only order, so a pack without the jar still loads. Iris warns once per pack folder
when a pack loads none of the jar's modules (`IrisModuleHost.JAR_MODULE_IDS`, which a test keeps equal to
@@ -149,5 +151,10 @@ when a pack loads none of the jar's modules (`IrisModuleHost.JAR_MODULE_IDS`, wh
`art.arcane.iris.builtin` also holds what the compiled-in built-ins and the jar must share, because each sees its own copy of
every other class: `IrisSeed` (Iris's per-feature world seeds, a facade Iris's worlds implement, so existing worlds generate the
same) and `terrain.LayerBlocks` (the world's picks from the biomes' palette layers: terrain, caves and post pick from the same
-layers, and a layer's noise is built once per world by whichever asks first). `iris:post` reads its switches
+layers, and a layer's noise is built once per world by whichever asks first), `LiveWorld` (what the loot and spawn services ask a
+running world, outside any chunk stage: the layout and settings at a block, the platform's weather and loot tables, the
+objects' loot and the spawner cooldowns Iris saves with the world; values only, implemented by Iris's worlds like `IrisSeed`),
+`loot.LootResolver` (the random streams loot is drawn from, shared with the hosts that fill containers) and the loot and
+marker lists of an object placement (`loot.ObjectLoot`, `loot.ObjectVanillaLoot`, `spawn.PlacementMarker`, which the modules
+register as held types, because Iris's `IrisObjectPlacement` holds them). `iris:post` reads its switches
(`postProcessingWalls`, `postProcessingSlabs`) and the biome's `wall` and `slab` as module settings through its context.
\ No newline at end of file
diff --git a/builtin-modules.txt b/builtin-modules.txt
index 824782905..d72e0bd5a 100644
--- a/builtin-modules.txt
+++ b/builtin-modules.txt
@@ -18,3 +18,7 @@ module art.arcane.iris.engine.modifier.PostModule
include art/arcane/iris/engine/modifier/SurfaceSmoothing*.class
module art.arcane.iris.engine.modifier.PerfectionModule
module art.arcane.iris.engine.modifier.MatterModule
+module art.arcane.iris.engine.loot.LootModule
+include art/arcane/iris/engine/loot/**
+module art.arcane.iris.engine.spawn.SpawnModule
+include art/arcane/iris/engine/spawn/**
diff --git a/src/main/java/art/arcane/iris/builtin/LiveWorld.java b/src/main/java/art/arcane/iris/builtin/LiveWorld.java
new file mode 100644
index 000000000..d52bc1d0f
--- /dev/null
+++ b/src/main/java/art/arcane/iris/builtin/LiveWorld.java
@@ -0,0 +1,136 @@
+/*
+ * Iris is a World Generator for Minecraft Servers
+ * Copyright (c) 2026 Arcane Arts (Volmit Software)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package art.arcane.iris.builtin;
+
+import art.arcane.iris.builtin.loot.ObjectLoot;
+import art.arcane.iris.builtin.loot.ObjectVanillaLoot;
+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;
+import java.util.Set;
+
+/**
+ * What Iris's own services ask a world that is running, outside any chunk stage: the layout and the objects at a block
+ * as they are now, the platform's weather and loot tables, and the data Iris keeps with the world. A chunk stage reads
+ * the layout through its {@link com.volmit.world.TerrainSampler}; a service has no chunk, so it asks here.
+ *
+ *
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)}.
+ */
+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();
+
+ /** The pack biome at the column's surface. */
+ ResourceId surfaceBiome(int x, int z);
+
+ /** The pack biome at the block when it lies in a cave biome, else the surface biome. */
+ ResourceId caveBiome(int x, int y, int z);
+
+ /** What the surface biome of the column is for: land, sea, shore or cave. */
+ BiomeKind surfaceKind(int x, int z);
+
+ /** The terrain's height at the column, before anything was placed on it. */
+ double terrainHeight(int x, int z);
+
+ /** The height of the highest block placed in the column, with the terrain and what objects and structures added. */
+ int highestBlock(int x, int z, boolean ignoreFluid);
+
+ /**
+ * The settings of {@code type} that the dimension, the region or a biome declares for the block, as they are
+ * decoded for generation; empty when that level declares none.
+ */
+ Optional settings(Class type, Level level, int x, int y, int z);
+
+ /** The time and weather of the world, or empty when the world has no platform world yet. */
+ Optional sky();
+
+ /** Whether the world is a studio world. */
+ boolean studio();
+
+ /** The keys of the loot tables the platform has, such as {@code minecraft:chests/simple_dungeon}. They do not change while the world runs. */
+ Set platformLootTables();
+
+ /** The floors of the caves marked in the chunk, none on a platform that cannot read them. */
+ List caveFloors(int chunkX, int chunkZ);
+
+ /** The loot the object placed at the block defines, or empty when no object placement covers the block. */
+ Optional objectLoots(int x, int y, int z);
+
+ /** The cooldowns of the world's spawners. */
+ SpawnCooldowns spawnCooldowns();
+
+ /** Where the layout is asked: the dimension, the region of the column, or one of its biomes. */
+ enum Level {
+ DIMENSION,
+ REGION,
+ /** The biome at the column's surface. */
+ SURFACE_BIOME,
+ /** The biome at the block: a cave biome below the surface, the surface biome above. */
+ BIOME,
+ /** The cave biome at the block, the surface biome when it has none. */
+ CAVE_BIOME
+ }
+
+ /** What a biome is for, which decides the spawners that fit it. */
+ enum BiomeKind {
+ LAND, SEA, SHORE, CAVE
+ }
+
+ /** The world's time of day in ticks, whether it is storming and whether it thunders. */
+ record Sky(long time, boolean storming, boolean thundering) {
+ }
+
+ /**
+ * The loot an object placement gives its containers.
+ *
+ * @param packTables tables of the pack
+ * @param platformTables tables of the platform
+ * @param overridesGlobalLoot whether the placement's tables replace those of the dimension, region and biomes
+ */
+ record ObjectLoots(List packTables, List platformTables, boolean overridesGlobalLoot) {
+ public ObjectLoots {
+ packTables = List.copyOf(packTables);
+ platformTables = List.copyOf(platformTables);
+ }
+
+ /** Whether the placement names any table. */
+ public boolean defined() {
+ return !packTables.isEmpty() || !platformTables.isEmpty();
+ }
+ }
+}
diff --git a/src/main/java/art/arcane/iris/builtin/loot/LootResolver.java b/src/main/java/art/arcane/iris/builtin/loot/LootResolver.java
new file mode 100644
index 000000000..71eb99106
--- /dev/null
+++ b/src/main/java/art/arcane/iris/builtin/loot/LootResolver.java
@@ -0,0 +1,200 @@
+/*
+ * Iris is a World Generator for Minecraft Bukkit Servers
+ * Copyright (c) 2026 Arcane Arts (Volmit Software)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package art.arcane.iris.builtin.loot;
+
+import art.arcane.volmlib.util.math.RNG;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.function.ToIntFunction;
+
+/**
+ * The random streams loot is drawn from and the picks made on them, shared by the loot module and the hosts that fill
+ * containers, so a container always holds the same loot. Changing a seed, a salt or a draw changes the loot of existing worlds.
+ */
+public final class LootResolver {
+ private static final int MAX_SCALED_SOURCE_COUNT = 256;
+ private static final long CONTAINER_SALT = 0x632BE59BD9B4E019L;
+ private static final long TABLE_SALT = 0x94D049BB133111EBL;
+ private static final long ENTRY_SALT = 0x9E3779B97F4A7C15L;
+
+ private LootResolver() {
+ }
+
+ public static RNG containerRng(long lootSeed, int x, int y, int z) {
+ return new RNG(containerSeed(lootSeed, x, y, z));
+ }
+
+ public static long containerSeed(long lootSeed, int x, int y, int z) {
+ long seed = mix(lootSeed ^ CONTAINER_SALT);
+ seed = mix(seed ^ ((long) x * 0xD6E8FEB86659FD93L));
+ seed = mix(seed ^ ((long) y * 0xA5A3564E27F886A7L));
+ return mix(seed ^ ((long) z * 0x8CB92BA72F3D8DD7L));
+ }
+
+ /** The random stream of one loot table at one position; {@code tableIdentity} names the table (its key, else its name). */
+ public static RNG tableRng(long lootSeed, String tableIdentity, int x, int y, int z) {
+ return new RNG(tableSeed(lootSeed, tableIdentity, x, y, z));
+ }
+
+ public static long tableSeed(long lootSeed, String tableIdentity, int x, int y, int z) {
+ return mix(containerSeed(lootSeed, x, y, z) ^ stableHash(tableIdentity) ^ TABLE_SALT);
+ }
+
+ public static boolean spatialOneIn(
+ long lootSeed,
+ String tableIdentity,
+ int entryIndex,
+ int x,
+ int y,
+ int z,
+ long rarity
+ ) {
+ if (rarity <= 1L) {
+ return true;
+ }
+ long roll = mix(tableSeed(lootSeed, tableIdentity, x, y, z) ^ ((long) entryIndex * ENTRY_SALT));
+ return new RNG(roll).nextLong(rarity) == 0L;
+ }
+
+ public static long combinedRarity(int tableRarity, int entryRarity) {
+ long table = Math.max(1, tableRarity);
+ long entry = Math.max(1, entryRarity);
+ if (table > Long.MAX_VALUE / entry) {
+ return Long.MAX_VALUE;
+ }
+ return table * entry;
+ }
+
+ public static boolean oneIn(RNG rng, int rarity) {
+ int bound = Math.max(1, rarity);
+ return bound == 1 || rng.nextInt(bound) == 0;
+ }
+
+ public static int inclusive(RNG rng, int first, int second) {
+ int lower = Math.min(first, second);
+ int upper = Math.max(first, second);
+ if (lower == upper) {
+ return lower;
+ }
+ long span = (long) upper - lower + 1L;
+ return (int) (lower + rng.nextLong(span));
+ }
+
+ public static T pickWeighted(List choices, ToIntFunction weight, RNG rng) {
+ long total = 0L;
+ for (T choice : choices) {
+ int value = Math.max(0, weight.applyAsInt(choice));
+ total = Long.MAX_VALUE - total < value ? Long.MAX_VALUE : total + value;
+ }
+ if (total <= 0L) {
+ return null;
+ }
+ long pull = rng.nextLong(total);
+ for (T choice : choices) {
+ pull -= Math.max(0, weight.applyAsInt(choice));
+ if (pull < 0L) {
+ return choice;
+ }
+ }
+ return null;
+ }
+
+ public static void scaleSources(List sources, double multiplier, RNG rng) {
+ if (!Double.isFinite(multiplier) || multiplier < 0D) {
+ throw new IllegalArgumentException("Effective loot source multiplier must be finite and non-negative, got "
+ + multiplier + ".");
+ }
+ if (sources.isEmpty()) {
+ return;
+ }
+ if (sources.size() > MAX_SCALED_SOURCE_COUNT) {
+ throw new IllegalArgumentException("Loot source scaling starts above the maximum of "
+ + MAX_SCALED_SOURCE_COUNT + " sources: " + sources.size() + ".");
+ }
+ double scaledSize = sources.size() * multiplier;
+ if (!Double.isFinite(scaledSize) || scaledSize > MAX_SCALED_SOURCE_COUNT) {
+ throw new IllegalArgumentException("Loot source scaling exceeds the maximum of "
+ + MAX_SCALED_SOURCE_COUNT + " sources: " + sources.size() + " * " + multiplier + ".");
+ }
+ int target = (int) Math.round(scaledSize);
+ if (target == sources.size()) {
+ return;
+ }
+ List original = new ArrayList<>(sources);
+ int[] order = new int[original.size()];
+ if (target < original.size()) {
+ shrinkSources(sources, original, order, target, rng);
+ return;
+ }
+ expandSources(sources, original, order, target, rng);
+ }
+
+ private static void shrinkSources(List sources, List original, int[] order, int target, RNG rng) {
+ shuffleOrder(order, rng);
+ boolean[] selected = new boolean[original.size()];
+ for (int index = 0; index < target; index++) {
+ selected[order[index]] = true;
+ }
+ sources.clear();
+ for (int index = 0; index < original.size(); index++) {
+ if (selected[index]) {
+ sources.add(original.get(index));
+ }
+ }
+ }
+
+ private static void expandSources(List sources, List original, int[] order, int target, RNG rng) {
+ while (sources.size() < target) {
+ shuffleOrder(order, rng);
+ int additions = Math.min(target - sources.size(), original.size());
+ for (int index = 0; index < additions; index++) {
+ sources.add(original.get(order[index]));
+ }
+ }
+ }
+
+ private static void shuffleOrder(int[] order, RNG rng) {
+ for (int index = 0; index < order.length; index++) {
+ order[index] = index;
+ }
+ for (int index = 0; index < order.length - 1; index++) {
+ int selected = index + rng.nextInt(order.length - index);
+ int previous = order[index];
+ order[index] = order[selected];
+ order[selected] = previous;
+ }
+ }
+
+ private static long stableHash(String value) {
+ long hash = 0xCBF29CE484222325L;
+ for (int i = 0; i < value.length(); i++) {
+ hash ^= value.charAt(i);
+ hash *= 0x100000001B3L;
+ }
+ return mix(hash);
+ }
+
+ private static long mix(long value) {
+ long mixed = value;
+ mixed = (mixed ^ (mixed >>> 30)) * 0xBF58476D1CE4E5B9L;
+ mixed = (mixed ^ (mixed >>> 27)) * 0x94D049BB133111EBL;
+ return mixed ^ (mixed >>> 31);
+ }
+}
diff --git a/src/main/java/art/arcane/iris/builtin/loot/ObjectLoot.java b/src/main/java/art/arcane/iris/builtin/loot/ObjectLoot.java
new file mode 100644
index 000000000..95ca8dae0
--- /dev/null
+++ b/src/main/java/art/arcane/iris/builtin/loot/ObjectLoot.java
@@ -0,0 +1,76 @@
+/*
+ * Iris is a World Generator for Minecraft Servers
+ * Copyright (c) 2026 Arcane Arts (Volmit Software)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package art.arcane.iris.builtin.loot;
+
+import com.volmit.block.BlockSpec;
+import com.volmit.config.Desc;
+import com.volmit.config.MinItems;
+import com.volmit.config.MinNumber;
+import com.volmit.config.Required;
+import com.volmit.config.ResourceRef;
+import com.volmit.config.Snippet;
+
+import java.util.Collections;
+import java.util.List;
+
+@Snippet("object-loot")
+@Desc("Represents loot within this object")
+public final class ObjectLoot implements ObjectLootEntry {
+ @MinItems(1)
+ @Desc("The list of blocks this loot table should apply to")
+ private List filter = List.of();
+ @Desc("Exactly match the block data or not")
+ private boolean exact = false;
+ @Desc("The loot table name")
+ @Required
+ @ResourceRef(LootTable.class)
+ private String name;
+ @Desc("The weight of this loot table being chosen")
+ @MinNumber(1)
+ private int weight = 1;
+
+ public ObjectLoot() {
+ }
+
+ /** A table for every container of the placement. */
+ public ObjectLoot(String name, int weight) {
+ this.name = name;
+ this.weight = weight;
+ }
+
+ @Override
+ public String name() {
+ return name;
+ }
+
+ @Override
+ public int weight() {
+ return weight;
+ }
+
+ @Override
+ public boolean exact() {
+ return exact;
+ }
+
+ @Override
+ public List filter() {
+ return filter == null ? List.of() : Collections.unmodifiableList(filter);
+ }
+}
diff --git a/src/main/java/art/arcane/iris/builtin/loot/ObjectLootEntry.java b/src/main/java/art/arcane/iris/builtin/loot/ObjectLootEntry.java
new file mode 100644
index 000000000..92a2a5d77
--- /dev/null
+++ b/src/main/java/art/arcane/iris/builtin/loot/ObjectLootEntry.java
@@ -0,0 +1,41 @@
+/*
+ * Iris is a World Generator for Minecraft Servers
+ * Copyright (c) 2026 Arcane Arts (Volmit Software)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package art.arcane.iris.builtin.loot;
+
+import com.volmit.block.BlockSpec;
+
+import java.util.List;
+
+/**
+ * One loot table an object placement gives its containers: which table, how often it is picked among the placement's
+ * tables, and which of the object's containers it is for.
+ */
+public interface ObjectLootEntry {
+ /** The table: a key of the pack's loot tables, or a key of the platform's. */
+ String name();
+
+ /** How often the table is picked among equals; a table with no weight is never picked. */
+ int weight();
+
+ /** Whether the table applies to the exact state of the blocks in {@link #filter}, not to every state of their kind of block. */
+ boolean exact();
+
+ /** The blocks the table is for; none means every container the placement holds. */
+ List filter();
+}
diff --git a/src/main/java/art/arcane/iris/builtin/loot/ObjectVanillaLoot.java b/src/main/java/art/arcane/iris/builtin/loot/ObjectVanillaLoot.java
new file mode 100644
index 000000000..45351c4d1
--- /dev/null
+++ b/src/main/java/art/arcane/iris/builtin/loot/ObjectVanillaLoot.java
@@ -0,0 +1,71 @@
+/*
+ * Iris is a World Generator for Minecraft Servers
+ * Copyright (c) 2026 Arcane Arts (Volmit Software)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package art.arcane.iris.builtin.loot;
+
+import com.volmit.block.BlockSpec;
+import com.volmit.config.Desc;
+import com.volmit.config.MinItems;
+import com.volmit.config.MinNumber;
+import com.volmit.config.Ref;
+import com.volmit.config.Reference;
+import com.volmit.config.Required;
+import com.volmit.config.Snippet;
+
+import java.util.Collections;
+import java.util.List;
+
+@Snippet("object-vanilla-loot")
+@Desc("Represents vanilla loot within this object")
+public final class ObjectVanillaLoot implements ObjectLootEntry {
+ @MinItems(1)
+ @Desc("The list of blocks this loot table should apply to")
+ private List filter = List.of();
+ @Desc("Exactly match the block data or not")
+ private boolean exact = false;
+ @Desc("The vanilla loot table key")
+ @Required
+ @Ref(Reference.LOOT_TABLE)
+ private String name;
+ @Desc("The weight of this loot table being chosen")
+ @MinNumber(1)
+ private int weight = 1;
+
+ public ObjectVanillaLoot() {
+ }
+
+ @Override
+ public String name() {
+ return name;
+ }
+
+ @Override
+ public int weight() {
+ return weight;
+ }
+
+ @Override
+ public boolean exact() {
+ return exact;
+ }
+
+ @Override
+ public List filter() {
+ return filter == null ? List.of() : Collections.unmodifiableList(filter);
+ }
+}
diff --git a/src/main/java/art/arcane/iris/builtin/package-info.java b/src/main/java/art/arcane/iris/builtin/package-info.java
index 4e62e77b1..d05b405cd 100644
--- a/src/main/java/art/arcane/iris/builtin/package-info.java
+++ b/src/main/java/art/arcane/iris/builtin/package-info.java
@@ -29,7 +29,7 @@
*
* Besides those, it holds what the compiled-in built-ins and the built-ins jar must share, since each sees its own copy
* of every other class: narrow facades only Iris's own built-ins use, interfaces Iris's worlds implement
- * ({@link art.arcane.iris.builtin.IrisSeed}), and per-world state several of them use
+ * ({@link art.arcane.iris.builtin.IrisSeed}, {@link art.arcane.iris.builtin.LiveWorld}), and per-world state several of them use
* ({@link art.arcane.iris.builtin.terrain.LayerBlocks}). Keep them few: each is a promise.
*
* Some built-in stages produce Iris's own types, such as the placement settings of {@code iris:prepare}. A
diff --git a/src/main/java/art/arcane/iris/builtin/spawn/PlacementMarker.java b/src/main/java/art/arcane/iris/builtin/spawn/PlacementMarker.java
new file mode 100644
index 000000000..435cc4af5
--- /dev/null
+++ b/src/main/java/art/arcane/iris/builtin/spawn/PlacementMarker.java
@@ -0,0 +1,72 @@
+/*
+ * Iris is a World Generator for Minecraft Servers
+ * Copyright (c) 2026 Arcane Arts (Volmit Software)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package art.arcane.iris.builtin.spawn;
+
+import com.volmit.block.BlockSpec;
+import com.volmit.config.Desc;
+import com.volmit.config.MaxNumber;
+import com.volmit.config.MinItems;
+import com.volmit.config.MinNumber;
+import com.volmit.config.Required;
+import com.volmit.config.ResourceRef;
+import com.volmit.config.Snippet;
+
+import java.util.Collections;
+import java.util.List;
+
+/** Blocks of an object placement that get a {@link SpawnMarker}, an entry of the placement's {@code markers}. */
+@Snippet("object-marker")
+@Desc("Find blocks to mark")
+public final class PlacementMarker {
+ @MinItems(1)
+ @Required
+ @Desc("Find block types to mark")
+ private List mark = List.of();
+ @MinNumber(1)
+ @MaxNumber(16)
+ @Desc("The maximum amount of markers to place. Use these sparingly!")
+ private int maximumMarkers = 8;
+ @Desc("If true, markers will only be placed if the block matches the mark list perfectly.")
+ private boolean exact = false;
+ @Required
+ @ResourceRef(SpawnMarker.class)
+ @Desc("The marker to add")
+ private String marker;
+
+ public PlacementMarker() {
+ }
+
+ /** The blocks that get a marker. */
+ public List mark() {
+ return mark == null ? List.of() : Collections.unmodifiableList(mark);
+ }
+
+ public int maximumMarkers() {
+ return maximumMarkers;
+ }
+
+ public boolean exact() {
+ return exact;
+ }
+
+ /** The key of the {@link SpawnMarker} to place. */
+ public String marker() {
+ return marker;
+ }
+}
diff --git a/src/main/java/art/arcane/iris/builtin/spawn/SpawnCooldowns.java b/src/main/java/art/arcane/iris/builtin/spawn/SpawnCooldowns.java
new file mode 100644
index 000000000..ca17005ee
--- /dev/null
+++ b/src/main/java/art/arcane/iris/builtin/spawn/SpawnCooldowns.java
@@ -0,0 +1,47 @@
+/*
+ * Iris is a World Generator for Minecraft Servers
+ * Copyright (c) 2026 Arcane Arts (Volmit Software)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package art.arcane.iris.builtin.spawn;
+
+import java.util.function.ToLongFunction;
+
+/**
+ * When spawners last fired, which Iris keeps with the world's data so that a spawner's rates hold across restarts. Rates
+ * count per spawner, by the key the pack names it by, in the world and in each chunk. Reached through
+ * {@link art.arcane.iris.builtin.LiveWorld#spawnCooldowns()}.
+ */
+public interface SpawnCooldowns {
+ /** Whether the spawner may fire in the world again, {@code intervalMilliseconds} after it last did. */
+ boolean canSpawn(String spawner, long intervalMilliseconds);
+
+ /** Notes that the spawner fired in the world now. */
+ void spawned(String spawner);
+
+ /** Whether the spawner may fire in the chunk again, {@code intervalMilliseconds} after it last did there. */
+ boolean canSpawnInChunk(int chunkX, int chunkZ, String spawner, long intervalMilliseconds);
+
+ /** Notes that the spawner fired in the chunk now. */
+ void spawnedInChunk(int chunkX, int chunkZ, String spawner);
+
+ /**
+ * Forgets the cooldowns that ran out and those of spawners the pack no longer has, so the world's data does not grow.
+ *
+ * @param intervalMilliseconds the interval of the world rate of a spawner by its key, or a negative number for a spawner the pack lacks
+ */
+ void forgetExpired(ToLongFunction intervalMilliseconds);
+}
diff --git a/src/main/java/art/arcane/iris/engine/loot/BlockDropping.java b/src/main/java/art/arcane/iris/engine/loot/BlockDropping.java
index 55b501500..d0c477bde 100644
--- a/src/main/java/art/arcane/iris/engine/loot/BlockDropping.java
+++ b/src/main/java/art/arcane/iris/engine/loot/BlockDropping.java
@@ -18,16 +18,12 @@
package art.arcane.iris.engine.loot;
+import art.arcane.iris.builtin.LiveWorld;
+import art.arcane.iris.builtin.LiveWorld.Level;
import art.arcane.iris.builtin.loot.BlockDrop;
import art.arcane.iris.builtin.loot.BlockDropSettings;
import art.arcane.iris.builtin.loot.LootEntry;
-import art.arcane.iris.core.loader.IrisRegistrant;
-import art.arcane.iris.core.modules.IrisPackWorld;
-import art.arcane.iris.engine.framework.Engine;
-import art.arcane.iris.engine.framework.LootResolver;
-import art.arcane.iris.engine.object.world.biome.IrisBiome;
-import art.arcane.iris.engine.object.world.region.IrisRegion;
-import art.arcane.iris.spi.IrisPlatforms;
+import art.arcane.iris.builtin.loot.LootResolver;
import art.arcane.volmlib.util.math.RNG;
import com.volmit.item.ItemDrop;
import com.volmit.service.BlockDrops;
@@ -45,19 +41,17 @@ import java.util.concurrent.ConcurrentMap;
public final class BlockDropping implements BlockDrops {
@Override
public Result drops(PackWorld world, Broken broken) {
- Engine engine = IrisPackWorld.of(world).engine();
+ LiveWorld live = LiveWorld.of(world);
int x = broken.position().x();
int y = broken.position().y();
int z = broken.position().z();
- String brokenKey = IrisPlatforms.get().registries().block(broken.block().key()).key();
+ String brokenKey = world.resources().blocks().resolve(broken.block()).key();
ResolvedDrops resolved = world.state(ResolvedDrops.class, ignored -> new ResolvedDrops());
- IrisBiome biome = engine.getBiome(x, y, z);
- List providers = dropsFor(biome, brokenKey, resolved, world);
+ List providers = dropsFor(live, Level.BIOME, x, y, z, brokenKey, resolved, world);
if (providers.stream().noneMatch(provider -> provider.drop().skipParents())) {
- IrisRegion region = engine.getRegion(x, z);
- providers.addAll(dropsFor(region, brokenKey, resolved, world));
- providers.addAll(dropsFor(engine.getDimension(), brokenKey, resolved, world));
+ providers.addAll(dropsFor(live, Level.REGION, x, y, z, brokenKey, resolved, world));
+ providers.addAll(dropsFor(live, Level.DIMENSION, x, y, z, brokenKey, resolved, world));
}
LootItems items = new LootItems(world.resources().items(), false);
@@ -79,9 +73,10 @@ public final class BlockDropping implements BlockDrops {
}
}
- private static List dropsFor(IrisRegistrant owner, String brokenKey, ResolvedDrops resolved, PackWorld world) {
+ private static List dropsFor(LiveWorld live, Level level, int x, int y, int z, String brokenKey,
+ ResolvedDrops resolved, PackWorld world) {
List matching = new ArrayList<>();
- for (BlockDrop drop : owner.getModuleSettings().find(BlockDropSettings.class).map(BlockDropSettings::drops).orElse(List.of())) {
+ for (BlockDrop drop : live.settings(BlockDropSettings.class, level, x, y, z).map(BlockDropSettings::drops).orElse(List.of())) {
ResolvedBlockDrop candidate = resolved.of(drop, world);
if (candidate.dropsFor(brokenKey)) {
matching.add(candidate);
diff --git a/src/main/java/art/arcane/iris/engine/loot/LootGiving.java b/src/main/java/art/arcane/iris/engine/loot/LootGiving.java
index 1dde569ca..3f245d70a 100644
--- a/src/main/java/art/arcane/iris/engine/loot/LootGiving.java
+++ b/src/main/java/art/arcane/iris/engine/loot/LootGiving.java
@@ -18,14 +18,11 @@
package art.arcane.iris.engine.loot;
+import art.arcane.iris.builtin.IrisSeed;
+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.iris.core.modules.IrisPackWorld;
-import art.arcane.iris.engine.framework.Engine;
-import art.arcane.iris.engine.framework.LootResolver;
-import art.arcane.iris.engine.framework.PlacedObject;
-import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
-import art.arcane.iris.spi.IrisPlatforms;
-import art.arcane.iris.spi.PlatformBlockState;
import art.arcane.volmlib.util.math.RNG;
import com.volmit.item.ItemDrop;
import com.volmit.service.Loot;
@@ -33,7 +30,7 @@ import com.volmit.world.PackWorld;
import java.util.ArrayList;
import java.util.List;
-import java.util.Set;
+import java.util.Optional;
/**
* How {@code iris:loot} fills containers: the tables of the object placed around a container, then those of the
@@ -43,76 +40,48 @@ import java.util.Set;
public final class LootGiving implements Loot {
@Override
public List tables(PackWorld world, Site site) {
- Engine engine = engine(world);
+ LiveWorld live = LiveWorld.of(world);
int x = site.position().x();
int z = site.position().z();
int relativeY = site.position().y();
- int worldY = relativeY + engine.getMinHeight();
- RNG rng = LootResolver.containerRng(lootSeed(engine), x, worldY, z);
+ int worldY = relativeY + live.bottomY();
+ RNG rng = LootResolver.containerRng(lootSeed(world), x, worldY, z);
List sources = new ArrayList<>();
boolean objectLootDefined = site.nativeLootDefined();
- IrisObjectPlacement placement = site.container() == null ? null : placementAt(engine, x, relativeY, z);
- if (placement != null) {
- objectLootDefined = objectLootDefined || placement.getLoot().isNotEmpty() || placement.getVanillaLoot().isNotEmpty();
- Source picked = placementLoot(world, engine).pick(placement.getVanillaLoot(), placement.getLoot(), platformState(site), rng, x, worldY, z);
+ Optional objectLoots = site.container() == null ? 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);
if (picked != null) {
sources.add(picked);
- if (placement.isOverrideGlobalLoot()) {
+ if (objectLoots.get().overridesGlobalLoot()) {
return sources;
}
}
}
- LootTables.resolveEnvironmentSources(sources, engine, rng, x, relativeY, z, objectLootDefined, Table::new);
+ LootTables.resolveEnvironmentSources(sources, world, rng, x, relativeY, z, objectLootDefined, Table::new);
return sources;
}
@Override
public List items(PackWorld world, Site site, String key) {
- Engine engine = engine(world);
- LootTable table = LootResources.table(engine.getData(), key);
+ LootTable table = LootResources.table(world.resources(), key);
if (table == null) {
return List.of();
}
- int worldY = site.position().y() + engine.getMinHeight();
+ int worldY = site.position().y() + LiveWorld.of(world).bottomY();
return new LootItems(world.resources().items(), site.debug())
- .draw(key, table, lootSeed(engine), site.position().x(), worldY, site.position().z());
+ .draw(key, table, lootSeed(world), site.position().x(), worldY, site.position().z());
}
- private static PlacementLoot placementLoot(PackWorld world, Engine engine) {
- PlatformLootTables platformTables = world.state(PlatformLootTables.class, ignored -> new PlatformLootTables());
- return new PlacementLoot(engine.getData(), platformTables::keys, lootSeed(engine), world.log());
+ private static PlacementLoot placementLoot(PackWorld world, LiveWorld live) {
+ return new PlacementLoot(world.resources(), live::platformLootTables, lootSeed(world), world.log());
}
- private static IrisObjectPlacement placementAt(Engine engine, int x, int relativeY, int z) {
- PlacedObject placed = engine.getObjectPlacement(x, relativeY, z);
- return placed == null ? null : placed.getPlacement();
- }
-
- private static PlatformBlockState platformState(Site site) {
- return IrisPlatforms.get().registries().block(site.container().key());
- }
-
- private static long lootSeed(Engine engine) {
- return engine.getSeedManager().getLoot();
- }
-
- private static Engine engine(PackWorld world) {
- return IrisPackWorld.of(world).engine();
- }
-
- /** The loot table keys of the platform, which do not change while a world runs. */
- private static final class PlatformLootTables {
- private volatile Set keys;
-
- private Set keys() {
- Set known = keys;
- if (known == null) {
- known = PlacementLoot.platformTableKeys();
- keys = known;
- }
- return known;
- }
+ private static long lootSeed(PackWorld world) {
+ return IrisSeed.LOOT.of(world);
}
}
diff --git a/src/main/java/art/arcane/iris/engine/loot/LootItems.java b/src/main/java/art/arcane/iris/engine/loot/LootItems.java
index 1c2300261..3d825273f 100644
--- a/src/main/java/art/arcane/iris/engine/loot/LootItems.java
+++ b/src/main/java/art/arcane/iris/engine/loot/LootItems.java
@@ -23,7 +23,7 @@ import art.arcane.iris.builtin.loot.LootEnchantment;
import art.arcane.iris.builtin.loot.LootEntry;
import art.arcane.iris.builtin.loot.LootSlot;
import art.arcane.iris.builtin.loot.LootTable;
-import art.arcane.iris.engine.framework.LootResolver;
+import art.arcane.iris.builtin.loot.LootResolver;
import art.arcane.volmlib.util.math.RNG;
import com.volmit.item.ItemAttribute;
import com.volmit.item.ItemDrop;
diff --git a/src/main/java/art/arcane/iris/engine/loot/LootModule.java b/src/main/java/art/arcane/iris/engine/loot/LootModule.java
index aa2041db9..d3e2696e3 100644
--- a/src/main/java/art/arcane/iris/engine/loot/LootModule.java
+++ b/src/main/java/art/arcane/iris/engine/loot/LootModule.java
@@ -20,6 +20,8 @@ package art.arcane.iris.engine.loot;
import art.arcane.iris.builtin.loot.BlockDropSettings;
import art.arcane.iris.builtin.loot.LootSettings;
+import art.arcane.iris.builtin.loot.ObjectLoot;
+import art.arcane.iris.builtin.loot.ObjectVanillaLoot;
import com.volmit.FeatureRegistry;
import com.volmit.IrisModule;
import com.volmit.ModuleInfo;
@@ -49,6 +51,8 @@ public final class LootModule implements IrisModule {
public void register(FeatureRegistry registry) {
registry.registerSettings(LootSettings.class);
registry.registerSettings(BlockDropSettings.class);
+ registry.registerHeldType(ObjectLoot.class);
+ registry.registerHeldType(ObjectVanillaLoot.class);
LootResources.kinds().forEach(registry::registerResourceKind);
registry.registerValidator(new LootValidator());
registry.registerService(Loot.class, new LootGiving());
diff --git a/src/main/java/art/arcane/iris/engine/loot/LootResources.java b/src/main/java/art/arcane/iris/engine/loot/LootResources.java
index b21985205..d0085a58f 100644
--- a/src/main/java/art/arcane/iris/engine/loot/LootResources.java
+++ b/src/main/java/art/arcane/iris/engine/loot/LootResources.java
@@ -19,8 +19,7 @@
package art.arcane.iris.engine.loot;
import art.arcane.iris.builtin.loot.LootTable;
-import art.arcane.iris.core.loader.IrisData;
-import art.arcane.iris.core.modules.IrisPackResources;
+import com.volmit.resource.PackResources;
import com.volmit.resource.ResourceId;
import com.volmit.resource.ResourceKind;
@@ -46,11 +45,10 @@ public final class LootResources {
return List.of(TABLES);
}
- public static LootTable table(IrisData data, String key) {
+ public static LootTable table(PackResources resources, String key) {
if (key == null || key.isBlank()) {
return null;
}
- IrisPackResources resources = data.getPackResources();
try {
return resources.find(TABLES.key(resources.idOf(key))).orElse(null);
} catch (IllegalStateException failedToLoad) {
@@ -59,7 +57,7 @@ public final class LootResources {
}
/** The key of every loot table of the pack, in key order. */
- public static List tableKeys(IrisData data) {
- return data.getPackResources().ids(TABLES.type()).stream().map(ResourceId::path).toList();
+ public static List tableKeys(PackResources resources) {
+ return resources.ids(TABLES.type()).stream().map(ResourceId::path).toList();
}
}
diff --git a/src/main/java/art/arcane/iris/engine/loot/LootTables.java b/src/main/java/art/arcane/iris/engine/loot/LootTables.java
index c1d0cb067..d40014994 100644
--- a/src/main/java/art/arcane/iris/engine/loot/LootTables.java
+++ b/src/main/java/art/arcane/iris/engine/loot/LootTables.java
@@ -18,14 +18,13 @@
package art.arcane.iris.engine.loot;
+import art.arcane.iris.builtin.LiveWorld;
+import art.arcane.iris.builtin.LiveWorld.Level;
import art.arcane.iris.builtin.loot.LootMode;
+import art.arcane.iris.builtin.loot.LootResolver;
import art.arcane.iris.builtin.loot.LootSettings;
-import art.arcane.iris.core.loader.IrisRegistrant;
-import art.arcane.iris.engine.framework.Engine;
-import art.arcane.iris.engine.framework.LootResolver;
-import art.arcane.iris.engine.object.world.biome.IrisBiome;
-import art.arcane.iris.engine.object.world.region.IrisRegion;
import art.arcane.volmlib.util.math.RNG;
+import com.volmit.world.PackWorld;
import java.util.List;
import java.util.Objects;
@@ -64,9 +63,9 @@ public final class LootTables {
return LootResolver.spatialOneIn(lootSeed, identity, entryIndex, x, y, z, rarity);
}
- /** The loot settings a dimension, region or biome declares; the defaults, which add nothing, when it declares none. */
- public static LootSettings settingsOf(IrisRegistrant owner) {
- return owner.getModuleSettings().find(LootSettings.class).orElseGet(LootSettings::new);
+ /** The loot settings the level declares at the block; the defaults, which add nothing, when it declares none. */
+ private static LootSettings settingsAt(LiveWorld live, Level level, int x, int relativeY, int z) {
+ return live.settings(LootSettings.class, level, x, relativeY, z).orElseGet(LootSettings::new);
}
/**
@@ -76,7 +75,7 @@ public final class LootTables {
*/
public static void resolveEnvironmentSources(
List sources,
- Engine engine,
+ PackWorld world,
RNG rng,
int x,
int relativeY,
@@ -84,31 +83,25 @@ public final class LootTables {
boolean objectLootDefined,
Function mapper
) {
- IrisRegion region = engine.getComplex().getRegionStream().get(x, z);
- IrisBiome surfaceBiome = engine.getComplex().getTrueBiomeStream().get(x, z);
- double terrainHeight = engine.getComplex().getHeightStream().get(x, z);
- IrisBiome contextualBiome = relativeY < terrainHeight
- ? engine.getCaveBiome(x, relativeY, z)
- : surfaceBiome;
- if (contextualBiome == null) {
- contextualBiome = surfaceBiome;
- }
+ LiveWorld live = LiveWorld.of(world);
+ boolean belowSurface = relativeY < live.terrainHeight(x, z);
+ boolean distinctContextualBiome = belowSurface && !live.caveBiome(x, relativeY, z).equals(live.surfaceBiome(x, z));
- LootSettings dimensionLoot = settingsOf(engine.getDimension());
- LootSettings regionLoot = settingsOf(region);
- LootSettings surfaceLoot = settingsOf(surfaceBiome);
- boolean distinctContextualBiome = !sameBiome(surfaceBiome, contextualBiome);
+ LootSettings dimensionLoot = settingsAt(live, Level.DIMENSION, x, relativeY, z);
+ LootSettings regionLoot = settingsAt(live, Level.REGION, x, relativeY, z);
+ LootSettings surfaceLoot = settingsAt(live, Level.SURFACE_BIOME, x, relativeY, z);
double multiplier = dimensionLoot.multiplier() * regionLoot.multiplier() * surfaceLoot.multiplier();
- if (distinctContextualBiome) {
- multiplier *= settingsOf(contextualBiome).multiplier();
+ LootSettings contextualLoot = distinctContextualBiome ? settingsAt(live, Level.CAVE_BIOME, x, relativeY, z) : null;
+ if (contextualLoot != null) {
+ multiplier *= contextualLoot.multiplier();
}
boolean fallback = !objectLootDefined;
- injectReference(sources, dimensionLoot, engine, mapper, fallback);
- injectReference(sources, regionLoot, engine, mapper, fallback);
- injectReference(sources, surfaceLoot, engine, mapper, fallback);
- if (distinctContextualBiome) {
- injectReference(sources, settingsOf(contextualBiome), engine, mapper, fallback);
+ injectReference(sources, dimensionLoot, world, mapper, fallback);
+ injectReference(sources, regionLoot, world, mapper, fallback);
+ injectReference(sources, surfaceLoot, world, mapper, fallback);
+ if (contextualLoot != null) {
+ injectReference(sources, contextualLoot, world, mapper, fallback);
}
LootResolver.scaleSources(sources, multiplier, rng);
}
@@ -133,25 +126,15 @@ public final class LootTables {
sources.addAll(additions);
}
- static boolean sameBiome(IrisBiome first, IrisBiome second) {
- if (first == second) {
- return true;
- }
- if (first == null || second == null) {
- return false;
- }
- return Objects.equals(first.getLoadKey(), second.getLoadKey());
- }
-
private static void injectReference(
List sources,
LootSettings loot,
- Engine engine,
+ PackWorld world,
Function mapper,
boolean fallback
) {
List additions = loot.tables().stream()
- .filter(key -> LootResources.table(engine.getData(), key) != null)
+ .filter(key -> LootResources.table(world.resources(), key) != null)
.map(mapper)
.filter(Objects::nonNull)
.toList();
diff --git a/src/main/java/art/arcane/iris/engine/loot/LootValidator.java b/src/main/java/art/arcane/iris/engine/loot/LootValidator.java
index cb4fef3d0..bebef35dd 100644
--- a/src/main/java/art/arcane/iris/engine/loot/LootValidator.java
+++ b/src/main/java/art/arcane/iris/engine/loot/LootValidator.java
@@ -18,269 +18,210 @@
package art.arcane.iris.engine.loot;
-import art.arcane.iris.core.modules.IrisValidationContext;
-import art.arcane.iris.core.pack.PackIntegerChecks;
-import art.arcane.iris.core.pack.PackValidationIo;
+import art.arcane.iris.builtin.loot.LootEnchantment;
import art.arcane.iris.builtin.loot.LootEntry;
+import art.arcane.iris.builtin.loot.LootMode;
import art.arcane.iris.builtin.loot.LootSettings;
import art.arcane.iris.builtin.loot.LootTable;
-import art.arcane.volmlib.util.json.JSONArray;
-import art.arcane.volmlib.util.json.JSONObject;
+import com.volmit.FeatureAttachment.Target;
+import com.volmit.config.FeatureSettings.Entry;
+import com.volmit.resource.PackResources;
+import com.volmit.resource.ResourceId;
import com.volmit.validation.Problem;
import com.volmit.validation.Subject;
import com.volmit.validation.ValidationContext;
import com.volmit.validation.Validator;
-import java.io.File;
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Comparator;
-import java.util.HashSet;
import java.util.List;
import java.util.Set;
+import java.util.function.BiFunction;
/**
* Module {@code iris:loot}'s check of a pack: every loot table has sane picks, tries and entries, and every loot
- * reference of a dimension, region or biome names a table the pack has. The files are read as written, like the pack
- * validator's other file checks, so a malformed table is reported rather than failing the load.
+ * reference of a dimension, region or biome names a table the pack has. It checks the tables and settings as they
+ * decoded; a file that is not valid JSON, or holds a value of the wrong type, is reported by the load that reads it.
*/
public final class LootValidator implements Validator {
- private static final List LOOT_HOST_FOLDERS = List.of("dimensions", "regions", "biomes");
private static final String JSON_EXTENSION = ".json";
+ private static final String LEVEL_FOLDER_SEPARATOR = "/";
@Override
public void validate(ValidationContext pack) {
- check(IrisValidationContext.of(pack).data().getDataFolder()).forEach(pack::report);
+ checkTables(pack.resources()).forEach(pack::report);
+ checkReferences(pack).forEach(pack::report);
}
- /** What is wrong with the loot tables and loot references of the pack in {@code packFolder}. */
- public static List check(File packFolder) {
+ private static List checkTables(PackResources resources) {
List problems = new ArrayList<>();
- if (packFolder == null || !packFolder.isDirectory()) {
- return problems;
- }
-
- File lootFolder = new File(packFolder, LootResources.TABLES.folder());
- Set lootKeys = keysOf(lootFolder);
- checkTables(lootFolder, problems);
- for (String folderName : LOOT_HOST_FOLDERS) {
- checkReferences(new File(packFolder, folderName), folderName, lootKeys, problems);
- }
- return problems;
- }
-
- private static void checkTables(File lootFolder, List problems) {
- if (!lootFolder.isDirectory()) {
- return;
- }
- List lootFiles = PackValidationIo.listJsonRecursive(lootFolder);
- lootFiles.sort(Comparator.comparing(File::getPath));
- for (File lootFile : lootFiles) {
- String lootKey = PackValidationIo.deriveKey(lootFolder, lootFile);
+ for (ResourceId id : resources.ids(LootTable.class)) {
+ String lootKey = id.path();
List errors = new ArrayList<>();
- JSONObject table = readTable(lootFile, lootKey, errors);
+ LootTable table = readTable(resources, id, lootKey, errors);
if (table != null) {
validateLootTable(lootKey, table, errors);
}
report(problems, Problem::error, Subject.file(LootResources.TABLES.folder() + "/" + lootKey + JSON_EXTENSION), errors);
}
+ return problems;
}
- private static void checkReferences(File resourceFolder, String folderName, Set lootKeys, List problems) {
- if (!resourceFolder.isDirectory()) {
- return;
- }
- List resourceFiles = PackValidationIo.listJsonRecursive(resourceFolder);
- resourceFiles.sort(Comparator.comparing(File::getPath));
- for (File resourceFile : resourceFiles) {
- JSONObject resource = PackValidationIo.readJson(resourceFile);
- if (resource == null || !resource.has("loot")) {
- continue;
- }
- String resourceKey = PackValidationIo.deriveKey(resourceFolder, resourceFile);
+ private static List checkReferences(ValidationContext pack) {
+ Set lootIds = Set.copyOf(pack.resources().ids(LootTable.class));
+ List problems = new ArrayList<>();
+ List> declared = new ArrayList<>(pack.settings().declared(LootSettings.class));
+ declared.sort(Comparator.comparing(Entry::level).thenComparing(Entry::source));
+ for (Entry entry : declared) {
+ String resourceKey = keyOf(entry);
List errors = new ArrayList<>();
List warnings = new ArrayList<>();
- validateLootReference(hostType(folderName), resourceKey, resource.opt("loot"), lootKeys, errors, warnings);
- Subject subject = Subject.file(folderName + "/" + resourceKey + JSON_EXTENSION);
+ validateLootReference(pack.resources(), hostType(entry.level()), resourceKey, entry.value(), lootIds, errors, warnings);
+ Subject subject = Subject.file(folderOf(entry.level()) + "/" + resourceKey + JSON_EXTENSION);
report(problems, Problem::error, subject, errors);
report(problems, Problem::warning, subject, warnings);
}
+ return problems;
}
- private static void report(List problems, java.util.function.BiFunction severity,
+ private static void report(List problems, BiFunction severity,
Subject subject, List messages) {
for (String message : messages) {
problems.add(severity.apply(subject, message));
}
}
- private static Set keysOf(File folder) {
- Set keys = new HashSet<>();
- if (!folder.isDirectory()) {
- return keys;
- }
- for (File file : PackValidationIo.listJsonRecursive(folder)) {
- String key = PackValidationIo.deriveKey(folder, file);
- if (key != null && !key.isBlank()) {
- keys.add(key);
- }
- }
- return keys;
- }
-
- private static JSONObject readTable(File file, String key, List errors) {
+ private static LootTable readTable(PackResources resources, ResourceId id, String key, List errors) {
try {
- return new JSONObject(Files.readString(file.toPath(), StandardCharsets.UTF_8));
- } catch (IOException | RuntimeException e) {
- String reason = e.getMessage();
- if (reason == null || reason.isBlank()) {
- reason = e.getClass().getSimpleName();
- }
- errors.add("Loot table '" + key + "' has invalid JSON: " + reason);
+ return resources.find(LootResources.TABLES.key(id)).orElse(null);
+ } catch (IllegalStateException failedToLoad) {
+ errors.add("Loot table '" + key + "' cannot be read; the log says what is wrong with the file.");
return null;
}
}
- private static String hostType(String folderName) {
- return switch (folderName) {
- case "dimensions" -> "Dimension";
- case "regions" -> "Region";
- case "biomes" -> "Biome";
- default -> "Resource";
+ /** The key of the dimension, region or biome that declared {@code entry}: its source id is {@code :/}. */
+ private static String keyOf(Entry entry) {
+ String path = entry.source().path();
+ return path.substring(path.indexOf(LEVEL_FOLDER_SEPARATOR) + 1);
+ }
+
+ private static String hostType(Target level) {
+ return switch (level) {
+ case DIMENSION -> "Dimension";
+ case REGION -> "Region";
+ case BIOME -> "Biome";
+ case OBJECT_PLACEMENT -> "Resource";
};
}
- private static void validateLootTable(String lootKey, JSONObject table, List blockingErrors) {
- String path = "Loot table '" + lootKey + "'";
- Integer rarity = PackIntegerChecks.integerField(table, "rarity", 1, path, blockingErrors);
- Integer minimumPicked = PackIntegerChecks.integerField(table, "minPicked", 1, path, blockingErrors);
- Integer maximumPicked = PackIntegerChecks.integerField(table, "maxPicked", 5, path, blockingErrors);
- Integer maximumTries = PackIntegerChecks.integerField(table, "maxTries", 10, path, blockingErrors);
- PackIntegerChecks.requireMinimum(path + ".rarity", rarity, 1, blockingErrors);
- PackIntegerChecks.requireMinimum(path + ".minPicked", minimumPicked, 0, blockingErrors);
- PackIntegerChecks.requireMinimum(path + ".maxPicked", maximumPicked, 1, blockingErrors);
- PackIntegerChecks.requireMinimum(path + ".maxTries", maximumTries, 1, blockingErrors);
- PackIntegerChecks.requireMaximum(path + ".minPicked", minimumPicked, LootTable.MAX_PICKED, blockingErrors);
- PackIntegerChecks.requireMaximum(path + ".maxPicked", maximumPicked, LootTable.MAX_PICKED, blockingErrors);
- PackIntegerChecks.requireMaximum(path + ".maxTries", maximumTries, LootTable.MAX_TRIES, blockingErrors);
- PackIntegerChecks.requireOrdered(path + ".minPicked", minimumPicked, path + ".maxPicked", maximumPicked, blockingErrors);
+ private static String folderOf(Target level) {
+ return switch (level) {
+ case DIMENSION -> "dimensions";
+ case REGION -> "regions";
+ case BIOME -> "biomes";
+ case OBJECT_PLACEMENT -> "placements";
+ };
+ }
- JSONArray entries = table.optJSONArray("loot");
- if (entries == null || entries.length() == 0) {
+ private static void validateLootTable(String lootKey, LootTable table, List blockingErrors) {
+ String path = "Loot table '" + lootKey + "'";
+ requireMinimum(path + ".rarity", table.rarity(), 1, blockingErrors);
+ requireMinimum(path + ".minPicked", table.minPicked(), 0, blockingErrors);
+ requireMinimum(path + ".maxPicked", table.maxPicked(), 1, blockingErrors);
+ requireMinimum(path + ".maxTries", table.maxTries(), 1, blockingErrors);
+ requireMaximum(path + ".minPicked", table.minPicked(), LootTable.MAX_PICKED, blockingErrors);
+ requireMaximum(path + ".maxPicked", table.maxPicked(), LootTable.MAX_PICKED, blockingErrors);
+ requireMaximum(path + ".maxTries", table.maxTries(), LootTable.MAX_TRIES, blockingErrors);
+ requireOrdered(path + ".minPicked", table.minPicked(), path + ".maxPicked", table.maxPicked(), blockingErrors);
+
+ List entries = table.loot();
+ if (entries.isEmpty()) {
blockingErrors.add(path + ".loot must be a non-empty array.");
return;
}
- for (int entryIndex = 0; entryIndex < entries.length(); entryIndex++) {
- JSONObject entry = entries.optJSONObject(entryIndex);
- String entryPath = path + ".loot[" + entryIndex + "]";
- if (entry == null) {
- blockingErrors.add(entryPath + " must be an object.");
- continue;
- }
- String type = entry.optString("type", "").trim();
- if (type.isEmpty()) {
- blockingErrors.add(entryPath + ".type must not be blank.");
- }
- Integer entryRarity = PackIntegerChecks.integerField(entry, "rarity", 1, entryPath, blockingErrors);
- Integer minimumAmount = PackIntegerChecks.integerField(entry, "minAmount", 1, entryPath, blockingErrors);
- Integer maximumAmount = PackIntegerChecks.integerField(entry, "maxAmount", 1, entryPath, blockingErrors);
- PackIntegerChecks.requireMinimum(entryPath + ".rarity", entryRarity, 1, blockingErrors);
- PackIntegerChecks.requireMinimum(entryPath + ".minAmount", minimumAmount, 1, blockingErrors);
- PackIntegerChecks.requireMinimum(entryPath + ".maxAmount", maximumAmount, 1, blockingErrors);
- PackIntegerChecks.requireMaximum(entryPath + ".minAmount", minimumAmount, LootEntry.MAX_AMOUNT, blockingErrors);
- PackIntegerChecks.requireMaximum(entryPath + ".maxAmount", maximumAmount, LootEntry.MAX_AMOUNT, blockingErrors);
- PackIntegerChecks.requireOrdered(entryPath + ".minAmount", minimumAmount,
- entryPath + ".maxAmount", maximumAmount, blockingErrors);
- validateLootEnchantments(entryPath, entry.opt("enchantments"), blockingErrors);
+ for (int entryIndex = 0; entryIndex < entries.size(); entryIndex++) {
+ validateLootEntry(path + ".loot[" + entryIndex + "]", entries.get(entryIndex), blockingErrors);
}
}
- private static void validateLootEnchantments(String entryPath, Object rawEnchantments,
- List blockingErrors) {
- if (rawEnchantments == null || rawEnchantments == JSONObject.NULL) {
+ private static void validateLootEntry(String entryPath, LootEntry entry, List blockingErrors) {
+ if (entry == null) {
+ blockingErrors.add(entryPath + " must be an object.");
return;
}
- if (!(rawEnchantments instanceof JSONArray enchantments)) {
- blockingErrors.add(entryPath + ".enchantments must be an array.");
- return;
+ if (entry.type().trim().isEmpty()) {
+ blockingErrors.add(entryPath + ".type must not be blank.");
}
- for (int enchantmentIndex = 0; enchantmentIndex < enchantments.length(); enchantmentIndex++) {
- JSONObject enchantment = enchantments.optJSONObject(enchantmentIndex);
- String enchantmentPath = entryPath + ".enchantments[" + enchantmentIndex + "]";
- if (enchantment == null) {
- blockingErrors.add(enchantmentPath + " must be an object.");
- continue;
- }
- if (enchantment.optString("enchantment", "").isBlank()) {
- blockingErrors.add(enchantmentPath + ".enchantment must not be blank.");
- }
- Integer minimumLevel = PackIntegerChecks.integerField(enchantment, "minLevel", 1, enchantmentPath, blockingErrors);
- Integer maximumLevel = PackIntegerChecks.integerField(enchantment, "maxLevel", 1, enchantmentPath, blockingErrors);
- PackIntegerChecks.requireMinimum(enchantmentPath + ".minLevel", minimumLevel, 1, blockingErrors);
- PackIntegerChecks.requireMinimum(enchantmentPath + ".maxLevel", maximumLevel, 1, blockingErrors);
- PackIntegerChecks.requireOrdered(enchantmentPath + ".minLevel", minimumLevel,
- enchantmentPath + ".maxLevel", maximumLevel, blockingErrors);
- if (enchantment.has("chance")) {
- Object rawChance = enchantment.opt("chance");
- if (!(rawChance instanceof Number number)
- || !Double.isFinite(number.doubleValue())
- || number.doubleValue() < 0D
- || number.doubleValue() > 1D) {
- blockingErrors.add(enchantmentPath + ".chance must be a finite number from 0 to 1.");
- }
- }
+ requireMinimum(entryPath + ".rarity", entry.rarity(), 1, blockingErrors);
+ requireMinimum(entryPath + ".minAmount", entry.minAmount(), 1, blockingErrors);
+ requireMinimum(entryPath + ".maxAmount", entry.maxAmount(), 1, blockingErrors);
+ requireMaximum(entryPath + ".minAmount", entry.minAmount(), LootEntry.MAX_AMOUNT, blockingErrors);
+ requireMaximum(entryPath + ".maxAmount", entry.maxAmount(), LootEntry.MAX_AMOUNT, blockingErrors);
+ requireOrdered(entryPath + ".minAmount", entry.minAmount(), entryPath + ".maxAmount", entry.maxAmount(), blockingErrors);
+
+ List enchantments = entry.enchantments();
+ for (int enchantmentIndex = 0; enchantmentIndex < enchantments.size(); enchantmentIndex++) {
+ validateEnchantment(entryPath + ".enchantments[" + enchantmentIndex + "]", enchantments.get(enchantmentIndex), blockingErrors);
}
}
- private static void validateLootReference(String resourceType, String resourceKey, Object rawLoot,
- Set lootKeys, List blockingErrors, List warnings) {
+ private static void validateEnchantment(String enchantmentPath, LootEnchantment enchantment, List blockingErrors) {
+ if (enchantment == null) {
+ blockingErrors.add(enchantmentPath + " must be an object.");
+ return;
+ }
+ String name = enchantment.enchantment();
+ if (name == null || name.isBlank()) {
+ blockingErrors.add(enchantmentPath + ".enchantment must not be blank.");
+ }
+ requireMinimum(enchantmentPath + ".minLevel", enchantment.minLevel(), 1, blockingErrors);
+ requireMinimum(enchantmentPath + ".maxLevel", enchantment.maxLevel(), 1, blockingErrors);
+ requireOrdered(enchantmentPath + ".minLevel", enchantment.minLevel(),
+ enchantmentPath + ".maxLevel", enchantment.maxLevel(), blockingErrors);
+ double chance = enchantment.chance();
+ if (!Double.isFinite(chance) || chance < 0D || chance > 1D) {
+ blockingErrors.add(enchantmentPath + ".chance must be a finite number from 0 to 1.");
+ }
+ }
+
+ private static void validateLootReference(PackResources resources, String resourceType, String resourceKey, LootSettings reference,
+ Set lootIds, List blockingErrors, List warnings) {
String path = resourceType + " '" + resourceKey + "'.loot";
- if (!(rawLoot instanceof JSONObject reference)) {
- blockingErrors.add(path + " must be an object.");
- return;
+ double multiplier = reference.multiplier();
+ if (!Double.isFinite(multiplier) || multiplier < 0D || multiplier > LootSettings.MAX_MULTIPLIER) {
+ blockingErrors.add(path + ".multiplier must be a finite number from 0 to " + (int) LootSettings.MAX_MULTIPLIER + ".");
}
- boolean clearMode = false;
- if (reference.has("mode")) {
- Object rawMode = reference.opt("mode");
- if (!(rawMode instanceof String mode)
- || !Set.of("ADD", "CLEAR", "REPLACE", "FALLBACK").contains(mode)) {
- blockingErrors.add(path + ".mode must be ADD, CLEAR, REPLACE, or FALLBACK.");
- } else {
- clearMode = "CLEAR".equals(mode);
- }
- }
- if (reference.has("multiplier")) {
- Object rawMultiplier = reference.opt("multiplier");
- if (!(rawMultiplier instanceof Number multiplier)
- || !Double.isFinite(multiplier.doubleValue())
- || multiplier.doubleValue() < 0D
- || multiplier.doubleValue() > LootSettings.MAX_MULTIPLIER) {
- blockingErrors.add(path + ".multiplier must be a finite number from 0 to "
- + (int) LootSettings.MAX_MULTIPLIER + ".");
- }
- }
- if (!reference.has("tables")) {
- return;
- }
- JSONArray tables = reference.optJSONArray("tables");
- if (tables == null) {
- blockingErrors.add(path + ".tables must be an array.");
- return;
- }
- if (clearMode && tables.length() > 0) {
- warnings.add(path + " uses mode CLEAR and lists " + tables.length()
+ List tables = reference.tables();
+ if (reference.mode() == LootMode.CLEAR && !tables.isEmpty()) {
+ warnings.add(path + " uses mode CLEAR and lists " + tables.size()
+ " table(s); CLEAR clears parent tables and contributes no tables of its own, so these entries are dead. Use REPLACE to substitute them.");
}
- for (int tableIndex = 0; tableIndex < tables.length(); tableIndex++) {
- Object rawTableKey = tables.opt(tableIndex);
- if (!(rawTableKey instanceof String tableKey) || tableKey.isBlank()) {
+ for (int tableIndex = 0; tableIndex < tables.size(); tableIndex++) {
+ String tableKey = tables.get(tableIndex);
+ if (tableKey == null || tableKey.isBlank()) {
blockingErrors.add(path + ".tables[" + tableIndex + "] must name a loot table.");
- } else if (!lootKeys.contains(tableKey)) {
- blockingErrors.add(path + ".tables[" + tableIndex
- + "] references missing loot table '" + tableKey + "'.");
+ } else if (!lootIds.contains(resources.idOf(tableKey))) {
+ blockingErrors.add(path + ".tables[" + tableIndex + "] references missing loot table '" + tableKey + "'.");
}
}
}
+
+ private static void requireMinimum(String fieldPath, int value, int minimum, List blockingErrors) {
+ if (value < minimum) {
+ blockingErrors.add(fieldPath + " must be at least " + minimum + ".");
+ }
+ }
+
+ private static void requireMaximum(String fieldPath, int value, int maximum, List blockingErrors) {
+ if (value > maximum) {
+ blockingErrors.add(fieldPath + " must be at most " + maximum + ".");
+ }
+ }
+
+ private static void requireOrdered(String minimumPath, int minimum, String maximumPath, int maximum, List blockingErrors) {
+ if (minimum > maximum) {
+ blockingErrors.add(minimumPath + " must not exceed " + maximumPath + ".");
+ }
+ }
}
diff --git a/src/main/java/art/arcane/iris/engine/loot/PlacementLoot.java b/src/main/java/art/arcane/iris/engine/loot/PlacementLoot.java
index 29db05407..0e91f6e0f 100644
--- a/src/main/java/art/arcane/iris/engine/loot/PlacementLoot.java
+++ b/src/main/java/art/arcane/iris/engine/loot/PlacementLoot.java
@@ -18,13 +18,13 @@
package art.arcane.iris.engine.loot;
-import art.arcane.iris.core.loader.IrisData;
-import art.arcane.iris.engine.framework.LootResolver;
-import art.arcane.iris.engine.object.loot.IObjectLoot;
-import art.arcane.iris.spi.IrisPlatforms;
-import art.arcane.iris.spi.PlatformBlockState;
+import art.arcane.iris.builtin.loot.LootResolver;
+import art.arcane.iris.builtin.loot.ObjectLootEntry;
import art.arcane.volmlib.util.math.RNG;
import com.volmit.ModuleLog;
+import com.volmit.block.BlockSpec;
+import com.volmit.block.BlockState;
+import com.volmit.resource.PackResources;
import com.volmit.service.Loot;
import java.util.ArrayList;
@@ -43,32 +43,27 @@ final class PlacementLoot {
private static final char NAMESPACE_SEPARATOR = ':';
private static final char PROPERTIES_START = '[';
- private final IrisData data;
+ private final PackResources resources;
private final Supplier> platformTables;
private final long lootSeed;
private final ModuleLog log;
/** @param platformTables the keys of the loot tables the platform has, asked for only when a placement names one */
- PlacementLoot(IrisData data, Supplier> platformTables, long lootSeed, ModuleLog log) {
- this.data = data;
+ PlacementLoot(PackResources resources, Supplier> platformTables, long lootSeed, ModuleLog log) {
+ this.resources = resources;
this.platformTables = platformTables;
this.lootSeed = lootSeed;
this.log = log;
}
- /** The platform's loot table keys, which a placement may name, in the form a placement names them. */
- static Set platformTableKeys() {
- return Set.copyOf(IrisPlatforms.get().registries().lootTableKeys());
- }
-
/**
* The table a placement, whose platform tables are {@code platformLoot} and whose pack tables are {@code packLoot},
* gives {@code container}, a storage chest, at the spot {@code x}, {@code worldY}, {@code z}; null when it gives
* it none.
*/
- Loot.Source pick(List extends IObjectLoot> platformLoot, List extends IObjectLoot> packLoot, PlatformBlockState container,
+ Loot.Source pick(List extends ObjectLootEntry> platformLoot, List extends ObjectLootEntry> packLoot, BlockState container,
RNG rng, int x, int worldY, int z) {
- Candidates candidates = new Candidates(container);
+ Candidates candidates = new Candidates(resources.blocks().resolve(container));
add(candidates, platformLoot, name -> platformSource(name, x, worldY, z));
add(candidates, packLoot, this::packSource);
List pool = candidates.pool();
@@ -76,22 +71,22 @@ final class PlacementLoot {
return picked == null ? null : picked.source();
}
- private void add(Candidates candidates, List extends IObjectLoot> entries, Function sourceOf) {
- for (IObjectLoot entry : entries) {
- if (entry == null || entry.getWeight() <= 0) {
+ private void add(Candidates candidates, List extends ObjectLootEntry> entries, Function sourceOf) {
+ for (ObjectLootEntry entry : entries) {
+ if (entry == null || entry.weight() <= 0) {
continue;
}
- Loot.Source source = sourceOf.apply(entry.getName());
+ Loot.Source source = sourceOf.apply(entry.name());
if (source == null) {
- log.warn("Couldn't find loot table " + entry.getName());
+ log.warn("Couldn't find loot table " + entry.name());
continue;
}
- candidates.add(entry, data, new Candidate(source, entry.getWeight()));
+ candidates.add(entry, resources, new Candidate(source, entry.weight()));
}
}
private Loot.Source packSource(String key) {
- return LootResources.table(data, key) == null ? null : new Loot.Table(key);
+ return LootResources.table(resources, key) == null ? null : new Loot.Table(key);
}
private Loot.Source platformSource(String name, int x, int worldY, int z) {
@@ -121,21 +116,22 @@ final class PlacementLoot {
private final List basic = new ArrayList<>();
private final List global = new ArrayList<>();
- private Candidates(PlatformBlockState container) {
+ private Candidates(BlockState container) {
this.containerKey = container.key();
this.containerMaterial = materialOf(containerKey);
}
- void add(IObjectLoot entry, IrisData data, Candidate candidate) {
- List filter = entry.getFilter(data);
+ void add(ObjectLootEntry entry, PackResources resources, Candidate candidate) {
+ List filter = entry.filter();
if (filter.isEmpty()) {
global.add(candidate);
return;
}
- for (PlatformBlockState filterState : filter) {
- if (entry.isExact() && filterState.key().equals(containerKey)) {
+ for (BlockSpec filterSpec : filter) {
+ String filterKey = resources.blocks().resolve(filterSpec).key();
+ if (entry.exact() && filterKey.equals(containerKey)) {
exact.add(candidate);
- } else if (!entry.isExact() && materialOf(filterState.key()).equals(containerMaterial)) {
+ } else if (!entry.exact() && materialOf(filterKey).equals(containerMaterial)) {
basic.add(candidate);
}
}
diff --git a/src/main/java/art/arcane/iris/engine/loot/ResolvedBlockDrop.java b/src/main/java/art/arcane/iris/engine/loot/ResolvedBlockDrop.java
index d42367c31..a33b046b6 100644
--- a/src/main/java/art/arcane/iris/engine/loot/ResolvedBlockDrop.java
+++ b/src/main/java/art/arcane/iris/engine/loot/ResolvedBlockDrop.java
@@ -19,8 +19,6 @@
package art.arcane.iris.engine.loot;
import art.arcane.iris.builtin.loot.BlockDrop;
-import art.arcane.iris.spi.IrisPlatforms;
-import art.arcane.iris.spi.PlatformBlockState;
import com.volmit.block.BlockRegistry;
import com.volmit.block.BlockSpec;
@@ -45,10 +43,7 @@ final class ResolvedBlockDrop {
static ResolvedBlockDrop of(BlockDrop drop, BlockRegistry blocks) {
Set keys = new LinkedHashSet<>();
for (BlockSpec spec : drop.blocks()) {
- PlatformBlockState state = IrisPlatforms.get().registries().block(blocks.resolve(spec).key());
- if (state != null) {
- keys.add(comparable(state.key(), drop.exactBlocks()));
- }
+ keys.add(comparable(blocks.resolve(spec).key(), drop.exactBlocks()));
}
return new ResolvedBlockDrop(drop, keys);
}
diff --git a/src/main/java/art/arcane/iris/engine/object/entity/spawn/IrisSpawnerCooldowns.java b/src/main/java/art/arcane/iris/engine/object/entity/spawn/IrisSpawnerCooldowns.java
index 7b12a24b6..1f0965cec 100644
--- a/src/main/java/art/arcane/iris/engine/object/entity/spawn/IrisSpawnerCooldowns.java
+++ b/src/main/java/art/arcane/iris/engine/object/entity/spawn/IrisSpawnerCooldowns.java
@@ -1,12 +1,11 @@
package art.arcane.iris.engine.object.entity.spawn;
-import art.arcane.iris.builtin.spawn.Spawner;
-import art.arcane.iris.engine.spawn.SpawnResources;
-import art.arcane.iris.engine.framework.Engine;
import art.arcane.volmlib.util.collection.KMap;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
+import java.util.function.ToLongFunction;
+
@EqualsAndHashCode
public class IrisSpawnerCooldowns {
private final KMap cooldowns = new KMap<>();
@@ -19,10 +18,11 @@ public class IrisSpawnerCooldowns {
});
}
- public void cleanup(Engine engine) {
+ /** Forgets the cooldowns that ran out and those of spawners {@code intervalMilliseconds} does not know (a negative interval). */
+ public void cleanup(ToLongFunction intervalMilliseconds) {
cooldowns.values().removeIf(cd -> {
- Spawner spawner = SpawnResources.spawner(engine.getData(), cd.getSpawner());
- return spawner == null || cd.canSpawn(spawner.maximumRate().interval());
+ long interval = intervalMilliseconds.applyAsLong(cd.getSpawner());
+ return interval < 0 || cd.canSpawn(interval);
});
}
diff --git a/src/main/java/art/arcane/iris/engine/object/loot/IObjectLoot.java b/src/main/java/art/arcane/iris/engine/object/loot/IObjectLoot.java
deleted file mode 100644
index 07d0f6859..000000000
--- a/src/main/java/art/arcane/iris/engine/object/loot/IObjectLoot.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package art.arcane.iris.engine.object.loot;
-
-import art.arcane.iris.engine.object.material.IrisBlockData;
-import art.arcane.iris.core.loader.IrisData;
-import art.arcane.iris.spi.PlatformBlockState;
-import art.arcane.volmlib.util.collection.KList;
-
-public interface IObjectLoot {
- KList getFilter();
- KList getFilter(IrisData manager);
- boolean isExact();
- String getName();
- int getWeight();
-}
diff --git a/src/main/java/art/arcane/iris/engine/object/loot/IrisObjectLoot.java b/src/main/java/art/arcane/iris/engine/object/loot/IrisObjectLoot.java
deleted file mode 100644
index ce6ff7c59..000000000
--- a/src/main/java/art/arcane/iris/engine/object/loot/IrisObjectLoot.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Iris is a World Generator for Minecraft Bukkit Servers
- * Copyright (c) 2022 Arcane Arts (Volmit Software)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-package art.arcane.iris.engine.object.loot;
-
-import art.arcane.iris.builtin.loot.LootTable;
-import art.arcane.iris.engine.object.material.IrisBlockData;
-import art.arcane.iris.core.loader.IrisData;
-import art.arcane.volmlib.util.cache.AtomicCache;
-import art.arcane.iris.engine.object.annotations.ArrayType;
-import art.arcane.iris.engine.object.annotations.Desc;
-import art.arcane.iris.engine.object.annotations.MinNumber;
-import art.arcane.iris.engine.object.annotations.RegistryListResource;
-import art.arcane.iris.engine.object.annotations.Required;
-import art.arcane.iris.engine.object.annotations.Snippet;
-import art.arcane.iris.util.common.data.B;
-import art.arcane.volmlib.util.collection.KList;
-import lombok.AllArgsConstructor;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-import art.arcane.iris.spi.PlatformBlockState;
-import lombok.experimental.Accessors;
-
-@Snippet("object-loot")
-@Accessors(chain = true)
-@NoArgsConstructor
-@AllArgsConstructor
-@Desc("Represents loot within this object")
-@Data
-public class IrisObjectLoot implements IObjectLoot {
- private final transient AtomicCache> filterCache = new AtomicCache<>();
- @ArrayType(min = 1, type = IrisBlockData.class)
- @Desc("The list of blocks this loot table should apply to")
- private KList filter = new KList<>();
- @Desc("Exactly match the block data or not")
- private boolean exact = false;
- @Desc("The loot table name")
- @Required
- @RegistryListResource(LootTable.class)
- private String name;
- @Desc("The weight of this loot table being chosen")
- @MinNumber(1)
- private int weight = 1;
-
- public KList getFilter(IrisData rdata) {
- return filterCache.aquire(() ->
- {
- KList b = new KList<>();
-
- for (IrisBlockData i : filter) {
- PlatformBlockState bx = i.getBlockData(rdata);
-
- if (bx != null) {
- b.add(bx);
- }
- }
-
- return b;
- });
- }
-
- public boolean matchesFilter(IrisData manager, PlatformBlockState data) {
- for (PlatformBlockState filterState : getFilter(manager)) {
- if (B.matches(filterState, data)) return true;
- }
- return false;
- }
-}
diff --git a/src/main/java/art/arcane/iris/engine/object/loot/IrisObjectVanillaLoot.java b/src/main/java/art/arcane/iris/engine/object/loot/IrisObjectVanillaLoot.java
deleted file mode 100644
index 4ad466e2f..000000000
--- a/src/main/java/art/arcane/iris/engine/object/loot/IrisObjectVanillaLoot.java
+++ /dev/null
@@ -1,57 +0,0 @@
-package art.arcane.iris.engine.object.loot;
-
-import art.arcane.iris.engine.object.material.IrisBlockData;
-import art.arcane.iris.core.loader.IrisData;
-import art.arcane.volmlib.util.cache.AtomicCache;
-import art.arcane.iris.engine.object.annotations.ArrayType;
-import art.arcane.iris.engine.object.annotations.Desc;
-import art.arcane.iris.engine.object.annotations.MinNumber;
-import art.arcane.iris.engine.object.annotations.RegistryListFunction;
-import art.arcane.iris.engine.object.annotations.Required;
-import art.arcane.iris.engine.object.annotations.Snippet;
-import art.arcane.iris.engine.object.annotations.functions.LootTableKeyFunction;
-import art.arcane.volmlib.util.collection.KList;
-import lombok.AllArgsConstructor;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-import art.arcane.iris.spi.PlatformBlockState;
-import lombok.experimental.Accessors;
-
-@Snippet("object-vanilla-loot")
-@Accessors(chain = true)
-@NoArgsConstructor
-@AllArgsConstructor
-@Desc("Represents vanilla loot within this object")
-@Data
-public class IrisObjectVanillaLoot implements IObjectLoot {
- private final transient AtomicCache> filterCache = new AtomicCache<>();
- @ArrayType(min = 1, type = IrisBlockData.class)
- @Desc("The list of blocks this loot table should apply to")
- private KList filter = new KList<>();
- @Desc("Exactly match the block data or not")
- private boolean exact = false;
- @Desc("The vanilla loot table key")
- @Required
- @RegistryListFunction(LootTableKeyFunction.class)
- private String name;
- @Desc("The weight of this loot table being chosen")
- @MinNumber(1)
- private int weight = 1;
-
- public KList getFilter(IrisData rdata) {
- return filterCache.aquire(() ->
- {
- KList b = new KList<>();
-
- for (IrisBlockData i : filter) {
- PlatformBlockState bx = i.getBlockData(rdata);
-
- if (bx != null) {
- b.add(bx);
- }
- }
-
- return b;
- });
- }
-}
diff --git a/src/main/java/art/arcane/iris/engine/object/marker/IrisObjectMarker.java b/src/main/java/art/arcane/iris/engine/object/marker/IrisObjectMarker.java
deleted file mode 100644
index 4c3ffe0bb..000000000
--- a/src/main/java/art/arcane/iris/engine/object/marker/IrisObjectMarker.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Iris is a World Generator for Minecraft Bukkit Servers
- * Copyright (c) 2022 Arcane Arts (Volmit Software)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-package art.arcane.iris.engine.object.marker;
-
-import art.arcane.iris.builtin.spawn.SpawnMarker;
-import art.arcane.iris.engine.object.material.IrisBlockData;
-import art.arcane.iris.core.loader.IrisData;
-import art.arcane.volmlib.util.cache.AtomicCache;
-import art.arcane.iris.engine.object.annotations.ArrayType;
-import art.arcane.iris.engine.object.annotations.Desc;
-import art.arcane.iris.engine.object.annotations.MaxNumber;
-import art.arcane.iris.engine.object.annotations.MinNumber;
-import art.arcane.iris.engine.object.annotations.RegistryListResource;
-import art.arcane.iris.engine.object.annotations.Required;
-import art.arcane.iris.engine.object.annotations.Snippet;
-import art.arcane.volmlib.util.collection.KList;
-import lombok.AllArgsConstructor;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-import art.arcane.iris.spi.PlatformBlockState;
-import lombok.experimental.Accessors;
-
-@Snippet("object-marker")
-@Accessors(chain = true)
-@NoArgsConstructor
-@AllArgsConstructor
-@Desc("Find blocks to mark")
-@Data
-public class IrisObjectMarker {
- private final transient AtomicCache> findData = new AtomicCache<>();
- @ArrayType(min = 1, type = IrisBlockData.class)
- @Required
- @Desc("Find block types to mark")
- private KList mark = new KList<>();
- @MinNumber(1)
- @MaxNumber(16)
- @Desc("The maximum amount of markers to place. Use these sparingly!")
- private int maximumMarkers = 8;
- @Desc("If true, markers will only be placed if the block matches the mark list perfectly.")
- private boolean exact = false;
- @Required
- @RegistryListResource(SpawnMarker.class)
- @Desc("The marker to add")
- private String marker;
-
- public KList getMark(IrisData rdata) {
- return findData.aquire(() ->
- {
- KList b = new KList<>();
-
- for (IrisBlockData i : mark) {
- PlatformBlockState bx = i.getBlockData(rdata);
-
- if (bx != null) {
- b.add(bx);
- }
- }
-
- return b;
- });
- }
-}
diff --git a/src/main/java/art/arcane/iris/engine/object/placement/BlocksModule.java b/src/main/java/art/arcane/iris/engine/object/placement/BlocksModule.java
index d04debcb6..437bb3b55 100644
--- a/src/main/java/art/arcane/iris/engine/object/placement/BlocksModule.java
+++ b/src/main/java/art/arcane/iris/engine/object/placement/BlocksModule.java
@@ -28,8 +28,8 @@ import art.arcane.iris.builtin.blocks.ObjectMarkers;
import art.arcane.iris.builtin.blocks.WrittenBlocks;
import art.arcane.iris.core.modules.BlockEntities;
import art.arcane.iris.core.modules.IrisPlacement;
+import art.arcane.iris.builtin.spawn.PlacementMarker;
import art.arcane.iris.builtin.spawn.SpawnMarker;
-import art.arcane.iris.engine.object.marker.IrisObjectMarker;
import art.arcane.iris.engine.object.prefab.IrisObject;
import art.arcane.iris.engine.object.prefab.IrisObjectShaping;
import art.arcane.iris.engine.object.prefab.TileData;
@@ -39,6 +39,8 @@ import art.arcane.iris.util.common.data.B;
import art.arcane.volmlib.util.collection.KList;
import art.arcane.volmlib.util.math.RNG;
import com.volmit.IrisModule;
+import com.volmit.block.BlockSpec;
+import com.volmit.block.BlockState;
import com.volmit.ModuleInfo;
import com.volmit.object.ObjectBlock;
import com.volmit.placement.PlacedBlock;
@@ -204,27 +206,36 @@ public final class BlocksModule implements IrisModule {
PlacementWorld world = new PlacementWorld(context.access(), placement.states());
RNG markerRandom = new RNG(context.random().nextLong());
int salt = 0;
- for (IrisObjectMarker markerConfig : config.getMarkers()) {
- SpawnMarker marker = SpawnResources.marker(placement.object().getLoader(), markerConfig.getMarker());
+ for (PlacementMarker markerConfig : config.getMarkers()) {
+ SpawnMarker marker = SpawnResources.marker(placement.data().getPackResources(), markerConfig.marker());
int markerSalt = salt++;
if (marker == null) {
continue;
}
- KList candidates = candidates(written, markerConfig, markerConfig.getMark(placement.data()), placement);
- int remaining = markerConfig.getMaximumMarkers();
+ KList candidates = candidates(written, markerConfig, markTargets(markerConfig, placement), placement);
+ int remaining = markerConfig.maximumMarkers();
for (BlockPosition position : candidates.shuffleCopy(markerRandom.nextParallelRNG(markerSalt))) {
if (remaining <= 0) {
break;
}
if (!marker.emptyAbove() || hasAirAbove(world, position)) {
- context.access().marker(ObjectMarkers.of(position, markerConfig.getMarker()));
+ context.access().marker(ObjectMarkers.of(position, markerConfig.marker()));
remaining--;
}
}
}
}
- private static KList candidates(WrittenBlocks written, IrisObjectMarker markerConfig,
+ private static KList markTargets(PlacementMarker markerConfig, IrisPlacement placement) {
+ KList targets = new KList<>();
+ for (BlockSpec spec : markerConfig.mark()) {
+ BlockState state = placement.data().getPackResources().blocks().resolve(spec);
+ targets.add(placement.states().toPlatform(state));
+ }
+ return targets;
+ }
+
+ private static KList candidates(WrittenBlocks written, PlacementMarker markerConfig,
KList targets, IrisPlacement placement) {
KList candidates = new KList<>();
for (PlacedBlock block : written.blocks()) {
@@ -236,8 +247,8 @@ public final class BlocksModule implements IrisModule {
return candidates;
}
- private static boolean marks(IrisObjectMarker markerConfig, PlatformBlockState target, PlatformBlockState state) {
- return markerConfig.isExact()
+ private static boolean marks(PlacementMarker markerConfig, PlatformBlockState target, PlatformBlockState state) {
+ return markerConfig.exact()
? target.matches(state)
: IrisObjectShaping.materialKey(target).equals(IrisObjectShaping.materialKey(state));
}
diff --git a/src/main/java/art/arcane/iris/engine/object/placement/IrisObjectPlacement.java b/src/main/java/art/arcane/iris/engine/object/placement/IrisObjectPlacement.java
index 2a7c4583c..7af65552d 100644
--- a/src/main/java/art/arcane/iris/engine/object/placement/IrisObjectPlacement.java
+++ b/src/main/java/art/arcane/iris/engine/object/placement/IrisObjectPlacement.java
@@ -27,9 +27,9 @@ import art.arcane.iris.builtin.prepare.SlopeClip;
import art.arcane.iris.builtin.vacuum.VacuumSettings;
import art.arcane.iris.builtin.validate.ObjectLimit;
import art.arcane.iris.core.modules.ModuleSettings;
-import art.arcane.iris.engine.object.loot.IrisObjectLoot;
-import art.arcane.iris.engine.object.loot.IrisObjectVanillaLoot;
-import art.arcane.iris.engine.object.marker.IrisObjectMarker;
+import art.arcane.iris.builtin.loot.ObjectLoot;
+import art.arcane.iris.builtin.loot.ObjectVanillaLoot;
+import art.arcane.iris.builtin.spawn.PlacementMarker;
import art.arcane.iris.engine.object.noise.IrisGeneratorStyle;
import art.arcane.iris.engine.object.noise.IrisNoiseGenerator;
import art.arcane.iris.engine.object.noise.IrisStyledRange;
@@ -117,9 +117,9 @@ public class IrisObjectPlacement {
@MinNumber(0)
@Desc("When bore is enabled, expand max-y of the cuboid it removes")
private int boreExtendMaxY = 0;
- @ArrayType(min = 1, type = IrisObjectMarker.class)
+ @ArrayType(min = 1, type = PlacementMarker.class)
@Desc("Add markers to blocks in this object")
- private KList markers = new KList<>();
+ private KList markers = new KList<>();
@MaxNumber(64)
@MinNumber(-1)
@Desc("When bore is enabled, lower min-y of the cuboid it removes")
@@ -167,12 +167,12 @@ public class IrisObjectPlacement {
private IrisObjectTranslate translate = new IrisObjectTranslate();
@Desc("Scale Objects")
private IrisObjectScale scale = new IrisObjectScale();
- @ArrayType(min = 1, type = IrisObjectLoot.class)
+ @ArrayType(min = 1, type = ObjectLoot.class)
@Desc("The loot tables to apply to these objects")
- private KList loot = new KList<>();
- @ArrayType(min = 1, type = IrisObjectVanillaLoot.class)
+ private KList loot = new KList<>();
+ @ArrayType(min = 1, type = ObjectVanillaLoot.class)
@Desc("The vanilla loot tables to apply to these objects")
- private KList vanillaLoot = new KList<>();
+ private KList vanillaLoot = new KList<>();
@Desc("Whether the given loot tables override any and all other loot tables available in the dimension, region or biome.")
private boolean overrideGlobalLoot = false;
@Desc("This object / these objects override the following trees when they grow...")
diff --git a/src/main/java/art/arcane/iris/engine/object/runtime/IrisEngineData.java b/src/main/java/art/arcane/iris/engine/object/runtime/IrisEngineData.java
index 0fa145932..2db085788 100644
--- a/src/main/java/art/arcane/iris/engine/object/runtime/IrisEngineData.java
+++ b/src/main/java/art/arcane/iris/engine/object/runtime/IrisEngineData.java
@@ -20,11 +20,12 @@ package art.arcane.iris.engine.object.runtime;
import art.arcane.iris.engine.object.entity.spawn.IrisSpawnerCooldowns;
import art.arcane.volmlib.util.cache.CacheKey;
-import art.arcane.iris.engine.framework.Engine;
import art.arcane.volmlib.util.collection.KMap;
import lombok.Data;
import lombok.EqualsAndHashCode;
+import java.util.function.ToLongFunction;
+
@Data
@EqualsAndHashCode(callSuper = true)
public class IrisEngineData extends IrisSpawnerCooldowns {
@@ -40,11 +41,12 @@ public class IrisEngineData extends IrisSpawnerCooldowns {
return chunks.computeIfAbsent(CacheKey.key(x, z), k -> new IrisSpawnerCooldowns());
}
- public void cleanup(Engine engine) {
- super.cleanup(engine);
+ @Override
+ public void cleanup(ToLongFunction intervalMilliseconds) {
+ super.cleanup(intervalMilliseconds);
chunks.values().removeIf(chunk -> {
- chunk.cleanup(engine);
+ chunk.cleanup(intervalMilliseconds);
return chunk.isEmpty();
});
}
diff --git a/src/main/java/art/arcane/iris/engine/object/structure/IrisStructure.java b/src/main/java/art/arcane/iris/engine/object/structure/IrisStructure.java
index 77865a878..9c14ab28b 100644
--- a/src/main/java/art/arcane/iris/engine/object/structure/IrisStructure.java
+++ b/src/main/java/art/arcane/iris/engine/object/structure/IrisStructure.java
@@ -22,7 +22,7 @@ import art.arcane.iris.builtin.anchor.PlaceTrait;
import art.arcane.iris.builtin.anchor.ObjectPlaceMode;
import art.arcane.iris.builtin.blocks.ObjectReplace;
import art.arcane.iris.builtin.loot.LootTable;
-import art.arcane.iris.engine.object.loot.IrisObjectLoot;
+import art.arcane.iris.builtin.loot.ObjectLoot;
import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
import art.arcane.iris.engine.object.structure.jigsaw.IrisJigsawBranchFailurePolicy;
import art.arcane.iris.engine.object.structure.jigsaw.IrisJigsawCompatibility;
@@ -138,7 +138,7 @@ public class IrisStructure extends IrisRegistrant {
}
for (String lootTable : loot) {
if (lootTable != null && !lootTable.isBlank()) {
- placement.getLoot().add(new IrisObjectLoot().setName(lootTable).setWeight(1));
+ placement.getLoot().add(new ObjectLoot(lootTable, 1));
}
}
return placement;
diff --git a/src/main/java/art/arcane/iris/engine/object/value/IRare.java b/src/main/java/art/arcane/iris/engine/object/value/IRare.java
index 04f8a27ba..09cfcb19d 100644
--- a/src/main/java/art/arcane/iris/engine/object/value/IRare.java
+++ b/src/main/java/art/arcane/iris/engine/object/value/IRare.java
@@ -93,23 +93,5 @@ public interface IRare {
return v instanceof IRare ? Math.max(1, ((IRare) v).getRarity()) : 1;
}
- /**
- * Expands a candidate list into a rarity-weighted list: each entry appears totalRarity/rarity
- * times, so picking uniformly from the result applies rarity exactly once. Both the Bukkit and
- * modded entity spawners select through this expansion; rarity must never be applied a second
- * time per spawn position.
- */
- static KList expandWeighted(List possibilities) {
- KList rarityTypes = new KList<>();
- int totalRarity = 0;
- for (T i : possibilities) {
- totalRarity += get(i);
- }
- for (T i : possibilities) {
- rarityTypes.addMultiple(i, totalRarity / get(i));
- }
- return rarityTypes;
- }
-
int getRarity();
}
diff --git a/src/main/java/art/arcane/iris/engine/spawn/AmbientEffecting.java b/src/main/java/art/arcane/iris/engine/spawn/AmbientEffecting.java
index f1af6b1c4..370847e79 100644
--- a/src/main/java/art/arcane/iris/engine/spawn/AmbientEffecting.java
+++ b/src/main/java/art/arcane/iris/engine/spawn/AmbientEffecting.java
@@ -18,14 +18,13 @@
package art.arcane.iris.engine.spawn;
+import art.arcane.iris.builtin.LiveWorld;
+import art.arcane.iris.builtin.LiveWorld.Level;
+import art.arcane.iris.builtin.LiveWorld.Sky;
import art.arcane.iris.builtin.spawn.AmbientEffect;
import art.arcane.iris.builtin.spawn.EffectCommands;
import art.arcane.iris.builtin.spawn.EffectSettings;
import art.arcane.iris.builtin.spawn.SpawnCommand;
-import art.arcane.iris.core.loader.IrisRegistrant;
-import art.arcane.iris.core.modules.IrisPackWorld;
-import art.arcane.iris.engine.framework.Engine;
-import art.arcane.iris.spi.PlatformWorld;
import art.arcane.volmlib.util.math.RNG;
import com.volmit.entity.EntitySpec;
import com.volmit.service.AmbientEffects;
@@ -34,6 +33,7 @@ import com.volmit.world.PackWorld;
import java.util.ArrayList;
import java.util.List;
+import java.util.Optional;
/**
* How {@code iris:spawn} plays the ambient effects of regions and biomes: the region's effects, then the biome's, each
@@ -42,32 +42,32 @@ import java.util.List;
public final class AmbientEffecting implements AmbientEffects {
@Override
public List due(PackWorld world, BlockPosition at) {
- Engine engine = IrisPackWorld.of(world).engine();
+ LiveWorld live = LiveWorld.of(world);
EffectTimers timers = world.state(EffectTimers.class, ignored -> new EffectTimers());
- PlatformWorld platformWorld = engine.getWorld().platformWorld();
+ Optional sky = live.sky();
List due = new ArrayList<>();
- addDue(due, effectsOf(engine.getRegion(at.x(), at.z())), timers, platformWorld);
- addDue(due, effectsOf(engine.getBiome(at.x(), at.y(), at.z())), timers, platformWorld);
+ addDue(due, effectsOf(live, Level.REGION, at), timers, sky);
+ addDue(due, effectsOf(live, Level.BIOME, at), timers, sky);
return due;
}
- private static List effectsOf(IrisRegistrant owner) {
- return owner.getModuleSettings().find(EffectSettings.class).map(EffectSettings::effects).orElse(List.of());
+ private static List effectsOf(LiveWorld live, Level level, BlockPosition at) {
+ return live.settings(EffectSettings.class, level, at.x(), at.y(), at.z()).map(EffectSettings::effects).orElse(List.of());
}
- private static void addDue(List due, List effects, EffectTimers timers, PlatformWorld world) {
+ private static void addDue(List due, List effects, EffectTimers timers, Optional sky) {
for (AmbientEffect effect : effects) {
if (timers.shouldPlayNow(effect)) {
- due.add(play(effect, world));
+ due.add(play(effect, sky));
}
}
}
- private static Effect play(AmbientEffect effect, PlatformWorld world) {
+ private static Effect play(AmbientEffect effect, Optional sky) {
Sound sound = effect.sound() == null ? null : soundOf(effect);
Particles particles = effect.particleEffect() == null ? null : particlesOf(effect);
- return new Effect(sound, particles, commandsOf(effect.commandRegistry(), world), potionOf(effect));
+ return new Effect(sound, particles, commandsOf(effect.commandRegistry(), sky), potionOf(effect));
}
private static Sound soundOf(AmbientEffect effect) {
@@ -92,7 +92,7 @@ public final class AmbientEffecting implements AmbientEffects {
altX, altY, altZ, effect.extra());
}
- private static List commandsOf(EffectCommands registry, PlatformWorld world) {
+ private static List commandsOf(EffectCommands registry, Optional sky) {
List commands = new ArrayList<>();
if (registry == null) {
return commands;
@@ -102,7 +102,7 @@ public final class AmbientEffecting implements AmbientEffects {
double offsetY = commandOffset(registry.commandOffsetY(), registry.commandRandomAltY());
double offsetZ = commandOffset(registry.commandOffsetZ(), registry.commandRandomAltZ());
for (SpawnCommand command : registry.rawCommands()) {
- if (SpawnConditions.allow(command.timeBlock(), command.weather(), world)) {
+ if (sky.isPresent() && SpawnConditions.allow(command.timeBlock(), command.weather(), sky.get())) {
commands.add(new Command(new EntitySpec.Command(command.commands(), command.delay(), command.repeat(),
command.repeatDelay()), offsetX, offsetY, offsetZ));
}
diff --git a/src/main/java/art/arcane/iris/engine/spawn/EntityResolution.java b/src/main/java/art/arcane/iris/engine/spawn/EntityResolution.java
index f0b72ae42..e934f61c3 100644
--- a/src/main/java/art/arcane/iris/engine/spawn/EntityResolution.java
+++ b/src/main/java/art/arcane/iris/engine/spawn/EntityResolution.java
@@ -18,14 +18,14 @@
package art.arcane.iris.engine.spawn;
+import art.arcane.iris.builtin.LiveWorld.Sky;
import art.arcane.iris.builtin.loot.ItemAttributeModifier;
import art.arcane.iris.builtin.loot.LootEntry;
import art.arcane.iris.builtin.spawn.AmbientEffect;
import art.arcane.iris.builtin.spawn.EntityDefinition;
import art.arcane.iris.builtin.spawn.SpawnCommand;
-import art.arcane.iris.engine.framework.LootResolver;
+import art.arcane.iris.builtin.loot.LootResolver;
import art.arcane.iris.engine.loot.LootItems;
-import art.arcane.iris.spi.PlatformWorld;
import art.arcane.volmlib.util.math.RNG;
import com.volmit.entity.EntitySpec;
import com.volmit.item.ItemAttribute;
@@ -33,6 +33,7 @@ import com.volmit.item.ItemDrop;
import java.util.ArrayList;
import java.util.List;
+import java.util.Optional;
/**
* Turns an entity of the pack into the {@link EntitySpec} the host spawns, making every random choice in the order Iris
@@ -43,13 +44,13 @@ final class EntityResolution {
private static final long LEASH_HOLDER_STREAM = 234548L;
private final LootItems items;
- private final PlatformWorld world;
+ private final Optional sky;
private final EffectTimers timers;
- /** @param world the world the entity appears in, whose time and weather decide which of its commands run */
- EntityResolution(LootItems items, PlatformWorld world, 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, EffectTimers timers) {
this.items = items;
- this.world = world;
+ this.sky = sky;
this.timers = timers;
}
@@ -121,7 +122,7 @@ final class EntityResolution {
private List commandsOf(EntityDefinition entity) {
List commands = new ArrayList<>();
for (SpawnCommand command : entity.rawCommands()) {
- if (SpawnConditions.allow(command.timeBlock(), command.weather(), world)) {
+ if (sky.isPresent() && SpawnConditions.allow(command.timeBlock(), command.weather(), sky.get())) {
commands.add(new EntitySpec.Command(command.commands(), command.delay(), command.repeat(), command.repeatDelay()));
}
}
diff --git a/src/main/java/art/arcane/iris/engine/spawn/EntitySpawning.java b/src/main/java/art/arcane/iris/engine/spawn/EntitySpawning.java
index d55ad48ca..f5ba8f655 100644
--- a/src/main/java/art/arcane/iris/engine/spawn/EntitySpawning.java
+++ b/src/main/java/art/arcane/iris/engine/spawn/EntitySpawning.java
@@ -18,29 +18,25 @@
package art.arcane.iris.engine.spawn;
+import art.arcane.iris.builtin.IrisSeed;
+import art.arcane.iris.builtin.LiveWorld;
+import art.arcane.iris.builtin.LiveWorld.Level;
+import art.arcane.iris.builtin.loot.LootResolver;
import art.arcane.iris.builtin.spawn.EntityDefinition;
import art.arcane.iris.builtin.spawn.EntitySpawn;
import art.arcane.iris.builtin.spawn.SpawnMarker;
import art.arcane.iris.builtin.spawn.SpawnSurface;
import art.arcane.iris.builtin.spawn.Spawner;
import art.arcane.iris.builtin.spawn.SpawnerSettings;
-import art.arcane.iris.core.loader.IrisRegistrant;
-import art.arcane.iris.core.modules.IrisPackWorld;
-import art.arcane.iris.engine.framework.Engine;
-import art.arcane.iris.engine.framework.LootResolver;
import art.arcane.iris.engine.loot.LootItems;
-import art.arcane.iris.engine.object.value.IRare;
-import art.arcane.iris.engine.object.value.IrisPosition;
-import art.arcane.iris.engine.object.world.biome.IrisBiome;
-import art.arcane.iris.engine.object.world.region.IrisRegion;
import art.arcane.iris.engine.spawn.SpawnResources.KeyedSpawner;
-import art.arcane.iris.util.common.scheduling.J;
import art.arcane.volmlib.util.collection.KList;
import art.arcane.volmlib.util.math.PowerOfTwoCoordinates;
import art.arcane.volmlib.util.math.RNG;
-import art.arcane.volmlib.util.matter.slices.MarkerMatter;
+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.service.EntitySpawns;
import com.volmit.world.BlockPosition;
import com.volmit.world.PackWorld;
@@ -63,13 +59,15 @@ public final class EntitySpawning implements EntitySpawns {
private static final String CAVE_FLOOR_MARKER = "cave_floor";
private static final String CAVE_CEILING_MARKER = "cave_ceiling";
private static final int AIR_ABOVE_MARKER = 1;
+ private static final long COOLDOWN_CLEANUP_INTERVAL_MILLISECONDS = 60_000L;
+ private static final int LAYOUT_QUESTION_HEIGHT = 0;
@Override
public Optional plan(PackWorld world, Site site) {
- Engine engine = engine(world);
+ forgetExpiredCooldowns(world);
return switch (site) {
- case Chunk chunk -> planChunk(world, engine, chunk);
- case Marker marker -> planMarker(world, engine, marker);
+ case Chunk chunk -> planChunk(world, chunk);
+ case Marker marker -> planMarker(world, marker);
};
}
@@ -78,19 +76,19 @@ public final class EntitySpawning implements EntitySpawns {
if (count <= 0) {
return;
}
- Spawner spawner = SpawnResources.spawner(engine(world).getData(), plan.spawner());
+ Spawner spawner = SpawnResources.spawner(world.resources(), plan.spawner());
if (spawner != null) {
- SpawnerGate.spawned(plan.spawner(), spawner, engine(world), plan.chunkX(), plan.chunkZ());
+ SpawnerGate.spawned(plan.spawner(), spawner, LiveWorld.of(world), plan.chunkX(), plan.chunkZ());
}
}
@Override
public Optional entity(PackWorld world, String key) {
- EntityDefinition entity = SpawnResources.entity(engine(world).getData(), key);
+ EntityDefinition entity = SpawnResources.entity(world.resources(), key);
if (entity == null) {
return Optional.empty();
}
- return Optional.of(resolution(world, engine(world)).resolve(entity, entityRandom(world).rng()));
+ return Optional.of(resolution(world).resolve(entity, entityRandom(world).rng()));
}
@Override
@@ -98,15 +96,14 @@ public final class EntitySpawning implements EntitySpawns {
if (tag.equals(CAVE_FLOOR_MARKER) || tag.equals(CAVE_CEILING_MARKER)) {
return Optional.empty();
}
- Engine engine = engine(world);
- SpawnMarker marker = SpawnResources.marker(engine.getData(), tag);
+ SpawnMarker marker = SpawnResources.marker(world.resources(), tag);
if (marker == null) {
return Optional.empty();
}
List spawners = new ArrayList<>();
for (String key : marker.spawners()) {
- if (SpawnResources.spawner(engine.getData(), key) == null) {
+ if (SpawnResources.spawner(world.resources(), key) == null) {
world.log().error("Cannot load spawner: " + key + " for marker " + tag, null);
continue;
}
@@ -115,69 +112,78 @@ public final class EntitySpawning implements EntitySpawns {
return Optional.of(new MarkerRule(spawners, marker.emptyAbove(), marker.removeOnChange()));
}
- private Optional planChunk(PackWorld world, Engine engine, Chunk chunk) {
- Predicate canSpawn = keyed -> SpawnerGate.canSpawn(keyed.key(), keyed.spawner(), engine, chunk.chunkX(), chunk.chunkZ());
+ /** Drops the cooldowns that ran out, now and then: the world's data keeps them across restarts. */
+ private static void forgetExpiredCooldowns(PackWorld world) {
+ CooldownCleanup cleanup = world.state(CooldownCleanup.class, ignored -> new CooldownCleanup());
+ if (!cleanup.due()) {
+ return;
+ }
+ PackResources resources = world.resources();
+ LiveWorld.of(world).spawnCooldowns().forgetExpired(key -> {
+ Spawner spawner = SpawnResources.spawner(resources, key);
+ return spawner == null ? -1L : spawner.maximumRate().interval();
+ });
+ }
+
+ private Optional planChunk(PackWorld world, Chunk chunk) {
+ LiveWorld live = LiveWorld.of(world);
+ Predicate 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());
- IrisBiome centreBiome = engine.getSurfaceBiome(blockX + BLOCKS_TO_CHUNK_CENTRE, blockZ + BLOCKS_TO_CHUNK_CENTRE);
- IrisRegion region = engine.getRegion(blockX, blockZ);
- IrisBiome biome = engine.getSurfaceBiome(blockX, blockZ);
+ LiveWorld.BiomeKind centreKind = live.surfaceKind(blockX + BLOCKS_TO_CHUNK_CENTRE, blockZ + BLOCKS_TO_CHUNK_CENTRE);
List candidates = Stream.concat(
- shuffled(engine, engine.getDimension()).stream()
- .filter(canSpawn).filter(keyed -> SpawnerGate.suits(keyed.spawner(), centreBiome)),
+ shuffled(world, live, Level.DIMENSION, blockX, blockZ).stream()
+ .filter(canSpawn).filter(keyed -> SpawnerGate.suits(keyed.spawner(), centreKind)),
Stream.concat(
- shuffled(engine, region).stream().filter(canSpawn),
- shuffled(engine, biome).stream().filter(canSpawn)))
+ shuffled(world, live, Level.REGION, blockX, blockZ).stream().filter(canSpawn),
+ shuffled(world, live, Level.SURFACE_BIOME, blockX, blockZ).stream().filter(canSpawn)))
.filter(keyed -> chunk.livingEntities() < keyed.spawner().maxEntitiesPerChunk())
.toList();
List spawns = candidates.stream().flatMap(keyed -> spawnsOf(keyed, chunk.initial())).collect(Collectors.toList());
- Candidate chosen = IRare.expandWeighted(spawns).getRandom();
+ Candidate chosen = RarityWeighting.expand(spawns, Candidate::rarity).getRandom();
if (chosen == null) {
return Optional.empty();
}
- return planChunkSpawn(world, engine, chunk, chosen);
+ return planChunkSpawn(world, live, chunk, chosen);
}
- private Optional planChunkSpawn(PackWorld world, Engine engine, Chunk chunk, Candidate chosen) {
+ private Optional planChunkSpawn(PackWorld world, LiveWorld live, Chunk chunk, Candidate chosen) {
EntitySpawn spawn = chosen.spawn();
int count = LootResolver.inclusive(RNG.r, spawn.minSpawns(), spawn.maxSpawns());
List attempts = new ArrayList<>();
for (int i = 0; i < count; i++) {
int x = (chunk.chunkX() * CHUNK_SIZE) + RNG.r.i(CHUNK_SIZE);
int z = (chunk.chunkZ() * CHUNK_SIZE) + RNG.r.i(CHUNK_SIZE);
- BlockPosition at = spawnPosition(engine, chosen.spawner(), chunk.chunkX(), chunk.chunkZ(), x, z);
+ BlockPosition at = spawnPosition(live, chosen.spawner(), chunk.chunkX(), chunk.chunkZ(), x, z);
if (at != null) {
- addAttempt(attempts, world, engine, chosen, at, true);
+ addAttempt(attempts, world, chosen, at, true);
}
}
return attempts.isEmpty() ? Optional.empty() : Optional.of(new Plan(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. */
- private static BlockPosition spawnPosition(Engine engine, Spawner spawner, int chunkX, int chunkZ, int x, int z) {
- int height = engine.getHeight(x, z, true);
- int heightWithFluid = engine.getHeight(x, z, false);
+ private static BlockPosition spawnPosition(LiveWorld live, Spawner spawner, int chunkX, int chunkZ, int x, int z) {
+ int height = live.highestBlock(x, z, true);
+ int heightWithFluid = live.highestBlock(x, z, false);
return switch (spawner.group()) {
case NORMAL -> new BlockPosition(x, heightWithFluid + 1, z);
- case CAVE -> caveSpawnPosition(engine, chunkX, chunkZ);
+ case CAVE -> caveSpawnPosition(live, chunkX, chunkZ);
case UNDERWATER, BEACH -> new BlockPosition(x, RNG.r.i(height + 1, heightWithFluid), z);
};
}
- static BlockPosition caveSpawnPosition(Engine engine, int chunkX, int chunkZ) {
- if (J.isFolia()) {
- return null;
- }
- KList floors = engine.getMantle().findMarkers(chunkX, chunkZ, MarkerMatter.CAVE_FLOOR);
- IrisPosition floor = floors.getRandom(RNG.r);
- return floor == null ? null : new BlockPosition(floor.getX(), floor.getY() - engine.getMinHeight() + AIR_ABOVE_MARKER, floor.getZ());
+ static BlockPosition caveSpawnPosition(LiveWorld live, int chunkX, int chunkZ) {
+ KList floors = new KList<>(live.caveFloors(chunkX, chunkZ));
+ BlockPosition floor = floors.getRandom(RNG.r);
+ return floor == null ? null : new BlockPosition(floor.x(), floor.y() + AIR_ABOVE_MARKER, floor.z());
}
- private Optional planMarker(PackWorld world, Engine engine, Marker marker) {
- Spawner spawner = SpawnResources.spawner(engine.getData(), marker.spawner());
- SpawnMarker spawnMarker = SpawnResources.marker(engine.getData(), marker.marker());
+ private Optional planMarker(PackWorld world, Marker marker) {
+ Spawner spawner = SpawnResources.spawner(world.resources(), marker.spawner());
+ SpawnMarker spawnMarker = SpawnResources.marker(world.resources(), marker.marker());
if (spawner == null) {
return Optional.empty();
}
@@ -186,12 +192,13 @@ public final class EntitySpawning implements EntitySpawns {
if (candidates.isEmpty()) {
return Optional.empty();
}
- EntitySpawn spawn = IRare.expandWeighted(candidates.stream().map(RareSpawn::new).toList()).getRandom().spawn();
+ EntitySpawn spawn = RarityWeighting.expand(candidates, EntitySpawn::rarity).getRandom();
BlockPosition position = marker.position();
int chunkX = PowerOfTwoCoordinates.blockToChunkFloor(position.x());
int chunkZ = PowerOfTwoCoordinates.blockToChunkFloor(position.z());
- if (!SpawnerGate.canSpawn(marker.spawner(), spawner, engine, chunkX, chunkZ)) {
+ LiveWorld live = LiveWorld.of(world);
+ if (!SpawnerGate.canSpawn(marker.spawner(), spawner, live, chunkX, chunkZ)) {
return Optional.empty();
}
@@ -203,7 +210,7 @@ public final class EntitySpawning implements EntitySpawns {
List 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, engine, new Candidate(marker.spawner(), spawner, spawn), above, false);
+ addAttempt(attempts, world, new Candidate(marker.spawner(), spawner, spawn), above, false);
}
return attempts.isEmpty() ? Optional.empty() : Optional.of(new Plan(marker.spawner(), chunkX, chunkZ, exhaustsMarker, attempts));
}
@@ -212,22 +219,23 @@ public final class EntitySpawning implements EntitySpawns {
return marker.exhaustionChance() > RNG.r.nextDouble();
}
- private void addAttempt(List attempts, PackWorld world, Engine engine, Candidate candidate, BlockPosition at, boolean checkSurface) {
- EntityDefinition entity = SpawnResources.entity(engine.getData(), candidate.spawn().entity());
+ private void addAttempt(List attempts, PackWorld world, Candidate candidate, BlockPosition at, boolean checkSurface) {
+ EntityDefinition entity = SpawnResources.entity(world.resources(), candidate.spawn().entity());
if (entity == null) {
world.log().debug(" You are trying to spawn an entity that does not exist!");
return;
}
Range light = candidate.spawner().allowedLightLevels();
- EntitySpec spec = resolution(world, engine).resolve(entity, entityRandom(world).rng());
+ EntitySpec spec = resolution(world).resolve(entity, entityRandom(world).rng());
attempts.add(new Attempt(at, spec, surfaceOf(entity.surface()),
(int) Math.ceil(light.min()), (int) Math.floor(light.max()), checkSurface));
}
- private static EntityResolution resolution(PackWorld world, Engine engine) {
- LootItems items = new LootItems(world.resources().items(), engine.isStudio());
- return new EntityResolution(items, engine.getWorld().platformWorld(), world.state(EffectTimers.class, ignored -> new EffectTimers()));
+ private static EntityResolution resolution(PackWorld world) {
+ LiveWorld live = LiveWorld.of(world);
+ LootItems items = new LootItems(world.resources().items(), live.studio());
+ return new EntityResolution(items, live.sky(), world.state(EffectTimers.class, ignored -> new EffectTimers()));
}
private static EntityRandom entityRandom(PackWorld world) {
@@ -238,10 +246,11 @@ public final class EntitySpawning implements EntitySpawns {
return Surface.valueOf(surface.name());
}
- /** The spawners an area lists, in a random order. */
- private static List shuffled(Engine engine, IrisRegistrant owner) {
- List keys = owner.getModuleSettings().find(SpawnerSettings.class).map(SpawnerSettings::spawners).orElse(List.of());
- return new KList<>(SpawnResources.spawners(engine.getData(), keys)).shuffleCopy(RNG.r);
+ /** The spawners the dimension, region or surface biome at the column lists, in a random order. */
+ private static List shuffled(PackWorld world, LiveWorld live, Level level, int x, int z) {
+ List keys = live.settings(SpawnerSettings.class, level, x, LAYOUT_QUESTION_HEIGHT, z)
+ .map(SpawnerSettings::spawners).orElse(List.of());
+ return new KList<>(SpawnResources.spawners(world.resources(), keys)).shuffleCopy(RNG.r);
}
private static Stream spawnsOf(KeyedSpawner keyed, boolean initial) {
@@ -250,35 +259,31 @@ public final class EntitySpawning implements EntitySpawns {
}
/** A spawn of a spawner, which picks as often as the spawn's rarity says. */
- private record Candidate(String key, Spawner spawner, EntitySpawn spawn) implements IRare {
- @Override
- public int getRarity() {
+ private record Candidate(String key, Spawner spawner, EntitySpawn spawn) {
+ int rarity() {
return spawn.rarity();
}
}
- /** A spawn that picks as often as its rarity says. */
- private record RareSpawn(EntitySpawn spawn) implements IRare {
- @Override
- public int getRarity() {
- return spawn.rarity();
- }
- }
-
- private static Engine engine(PackWorld world) {
- return IrisPackWorld.of(world).engine();
- }
-
/** The random stream entities are made from, seeded from the world like Iris always seeded it; one per world. */
private static final class EntityRandom {
private final RNG rng;
private EntityRandom(PackWorld world) {
- this.rng = new RNG(IrisPackWorld.of(world).engine().getSeedManager().getEntity());
+ this.rng = new RNG(IrisSeed.ENTITY.of(world));
}
private RNG rng() {
return rng;
}
}
+
+ /** When the world's spawner cooldowns were last tidied. */
+ private static final class CooldownCleanup {
+ private final ChronoLatch latch = new ChronoLatch(COOLDOWN_CLEANUP_INTERVAL_MILLISECONDS);
+
+ private boolean due() {
+ return latch.flip();
+ }
+ }
}
diff --git a/src/main/java/art/arcane/iris/engine/spawn/RarityWeighting.java b/src/main/java/art/arcane/iris/engine/spawn/RarityWeighting.java
new file mode 100644
index 000000000..6e700e3cf
--- /dev/null
+++ b/src/main/java/art/arcane/iris/engine/spawn/RarityWeighting.java
@@ -0,0 +1,53 @@
+/*
+ * Iris is a World Generator for Minecraft Servers
+ * Copyright (c) 2026 Arcane Arts (Volmit Software)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package art.arcane.iris.engine.spawn;
+
+import art.arcane.volmlib.util.collection.KList;
+
+import java.util.List;
+import java.util.function.ToIntFunction;
+
+/**
+ * Applies rarity to a pick: each possibility appears in the expansion as often as its rarity says, so picking one at
+ * random from the expansion picks the rarer ones less often. Spawner choices go through this once; rarity must never be
+ * applied a second time per spawn position.
+ */
+final class RarityWeighting {
+ private static final int MINIMUM_RARITY = 1;
+
+ private RarityWeighting() {
+ }
+
+ /** Each of {@code possibilities} repeated total/rarity times, where a rarity below 1 counts as 1. */
+ static KList expand(List possibilities, ToIntFunction rarity) {
+ KList expanded = new KList<>();
+ int totalRarity = 0;
+ for (T possibility : possibilities) {
+ totalRarity += rarityOf(possibility, rarity);
+ }
+ for (T possibility : possibilities) {
+ expanded.addMultiple(possibility, totalRarity / rarityOf(possibility, rarity));
+ }
+ return expanded;
+ }
+
+ private static int rarityOf(T possibility, ToIntFunction rarity) {
+ return Math.max(MINIMUM_RARITY, rarity.applyAsInt(possibility));
+ }
+}
diff --git a/src/main/java/art/arcane/iris/engine/spawn/SpawnConditions.java b/src/main/java/art/arcane/iris/engine/spawn/SpawnConditions.java
index f7616adef..a7c565c79 100644
--- a/src/main/java/art/arcane/iris/engine/spawn/SpawnConditions.java
+++ b/src/main/java/art/arcane/iris/engine/spawn/SpawnConditions.java
@@ -18,11 +18,11 @@
package art.arcane.iris.engine.spawn;
+import art.arcane.iris.builtin.LiveWorld.Sky;
import art.arcane.iris.builtin.spawn.SpawnTimeBlock;
import art.arcane.iris.builtin.spawn.SpawnWeather;
-import art.arcane.iris.spi.PlatformWorld;
-/** The time of day and the weather a command or spawner of the pack asks for, checked against a world. */
+/** The time of day and the weather a command or spawner of the pack asks for, checked against a world's sky. */
final class SpawnConditions {
private static final double TICKS_PER_HOUR = 1000D;
private static final double HOURS_AT_TIME_ZERO = 6;
@@ -31,12 +31,12 @@ final class SpawnConditions {
private SpawnConditions() {
}
- static boolean allow(SpawnTimeBlock time, SpawnWeather weather, PlatformWorld world) {
- return time.contains(hourOf(world)) && weather.matches(world.isStorming(), world.isThundering());
+ static boolean allow(SpawnTimeBlock time, SpawnWeather weather, Sky sky) {
+ return time.contains(hourOf(sky)) && weather.matches(sky.storming(), sky.thundering());
}
/** The world's time of day as a clock hour: tick 0 is 6 in the morning. */
- static double hourOf(PlatformWorld world) {
- return ((world.getTime() / TICKS_PER_HOUR) + HOURS_AT_TIME_ZERO) % HOURS_PER_DAY;
+ static double hourOf(Sky sky) {
+ return ((sky.time() / TICKS_PER_HOUR) + HOURS_AT_TIME_ZERO) % HOURS_PER_DAY;
}
}
diff --git a/src/main/java/art/arcane/iris/engine/spawn/SpawnModule.java b/src/main/java/art/arcane/iris/engine/spawn/SpawnModule.java
index e219c7b2f..96e08b52f 100644
--- a/src/main/java/art/arcane/iris/engine/spawn/SpawnModule.java
+++ b/src/main/java/art/arcane/iris/engine/spawn/SpawnModule.java
@@ -19,6 +19,7 @@
package art.arcane.iris.engine.spawn;
import art.arcane.iris.builtin.spawn.EffectSettings;
+import art.arcane.iris.builtin.spawn.PlacementMarker;
import art.arcane.iris.builtin.spawn.SpawnerSettings;
import com.volmit.FeatureRegistry;
import com.volmit.IrisModule;
@@ -50,6 +51,7 @@ public final class SpawnModule implements IrisModule {
public void register(FeatureRegistry registry) {
registry.registerSettings(SpawnerSettings.class);
registry.registerSettings(EffectSettings.class);
+ registry.registerHeldType(PlacementMarker.class);
SpawnResources.kinds().forEach(registry::registerResourceKind);
registry.registerService(EntitySpawns.class, new EntitySpawning());
registry.registerService(AmbientEffects.class, new AmbientEffecting());
diff --git a/src/main/java/art/arcane/iris/engine/spawn/SpawnResources.java b/src/main/java/art/arcane/iris/engine/spawn/SpawnResources.java
index fa12eefd2..b90cd5232 100644
--- a/src/main/java/art/arcane/iris/engine/spawn/SpawnResources.java
+++ b/src/main/java/art/arcane/iris/engine/spawn/SpawnResources.java
@@ -21,8 +21,7 @@ package art.arcane.iris.engine.spawn;
import art.arcane.iris.builtin.spawn.EntityDefinition;
import art.arcane.iris.builtin.spawn.SpawnMarker;
import art.arcane.iris.builtin.spawn.Spawner;
-import art.arcane.iris.core.loader.IrisData;
-import art.arcane.iris.core.modules.IrisPackResources;
+import com.volmit.resource.PackResources;
import com.volmit.resource.ResourceId;
import com.volmit.resource.ResourceKind;
@@ -57,23 +56,23 @@ public final class SpawnResources {
return List.of(SPAWNERS, ENTITIES, MARKERS);
}
- public static Spawner spawner(IrisData data, String key) {
- return find(data, SPAWNERS, key);
+ public static Spawner spawner(PackResources resources, String key) {
+ return find(resources, SPAWNERS, key);
}
- public static EntityDefinition entity(IrisData data, String key) {
- return find(data, ENTITIES, key);
+ public static EntityDefinition entity(PackResources resources, String key) {
+ return find(resources, ENTITIES, key);
}
- public static SpawnMarker marker(IrisData data, String key) {
- return find(data, MARKERS, key);
+ public static SpawnMarker marker(PackResources resources, String key) {
+ return find(resources, MARKERS, key);
}
/** The spawners of the pack named by {@code keys}, in order, without the ones the pack lacks. */
- public static List spawners(IrisData data, List keys) {
+ public static List spawners(PackResources resources, List keys) {
List spawners = new ArrayList<>();
for (String key : keys) {
- Spawner spawner = spawner(data, key);
+ Spawner spawner = spawner(resources, key);
if (spawner != null) {
spawners.add(new KeyedSpawner(key, spawner));
}
@@ -82,25 +81,24 @@ public final class SpawnResources {
}
/** The key of every entity of the pack, in key order. */
- public static List entityKeys(IrisData data) {
- return keys(data, ENTITIES);
+ public static List entityKeys(PackResources resources) {
+ return keys(resources, ENTITIES);
}
/** The key of every spawner of the pack, in key order. */
- public static List spawnerKeys(IrisData data) {
- return keys(data, SPAWNERS);
+ public static List spawnerKeys(PackResources resources) {
+ return keys(resources, SPAWNERS);
}
/** The key of every marker of the pack, in key order. */
- public static List markerKeys(IrisData data) {
- return keys(data, MARKERS);
+ public static List markerKeys(PackResources resources) {
+ return keys(resources, MARKERS);
}
- private static T find(IrisData data, ResourceKind kind, String key) {
+ private static T find(PackResources resources, ResourceKind kind, String key) {
if (key == null || key.isBlank()) {
return null;
}
- IrisPackResources resources = data.getPackResources();
try {
return resources.find(kind.key(resources.idOf(key))).orElse(null);
} catch (IllegalStateException failedToLoad) {
@@ -109,7 +107,7 @@ 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 keys(IrisData data, ResourceKind> kind) {
- return data.getPackResources().ids(kind.type()).stream().map(ResourceId::path).toList();
+ private static List keys(PackResources resources, ResourceKind> kind) {
+ return resources.ids(kind.type()).stream().map(ResourceId::path).toList();
}
}
diff --git a/src/main/java/art/arcane/iris/engine/spawn/SpawnerGate.java b/src/main/java/art/arcane/iris/engine/spawn/SpawnerGate.java
index 74bbfb95b..1327251af 100644
--- a/src/main/java/art/arcane/iris/engine/spawn/SpawnerGate.java
+++ b/src/main/java/art/arcane/iris/engine/spawn/SpawnerGate.java
@@ -18,34 +18,36 @@
package art.arcane.iris.engine.spawn;
+import art.arcane.iris.builtin.LiveWorld;
+import art.arcane.iris.builtin.LiveWorld.BiomeKind;
+import art.arcane.iris.builtin.LiveWorld.Sky;
import art.arcane.iris.builtin.spawn.SpawnRate;
+import art.arcane.iris.builtin.spawn.SpawnCooldowns;
import art.arcane.iris.builtin.spawn.Spawner;
-import art.arcane.iris.engine.framework.Engine;
-import art.arcane.iris.engine.object.world.biome.IrisBiome;
-import art.arcane.iris.spi.PlatformWorld;
+
+import java.util.Optional;
/**
* Whether a spawner may fire: in a biome of the kind its group wants, in the time and weather it asks for, and not
- * more often than its rates allow. The rates count in the engine's persisted data, by the key the pack names the
- * spawner by.
+ * more often than its rates allow. The rates count in the world's data, by the key the pack names the spawner by.
*/
final class SpawnerGate {
private SpawnerGate() {
}
- /** Whether a spawner of this group fires in {@code biome}. */
- static boolean suits(Spawner spawner, IrisBiome biome) {
+ /** Whether a spawner of this group fires in a biome of {@code kind}. */
+ static boolean suits(Spawner spawner, BiomeKind kind) {
return switch (spawner.group()) {
- case NORMAL -> switch (biome.getInferredType()) {
+ case NORMAL -> switch (kind) {
case SHORE, SEA, CAVE -> false;
case LAND -> true;
};
case CAVE -> true;
- case UNDERWATER -> switch (biome.getInferredType()) {
+ case UNDERWATER -> switch (kind) {
case SHORE, LAND, CAVE -> false;
case SEA -> true;
};
- case BEACH -> switch (biome.getInferredType()) {
+ case BEACH -> switch (kind) {
case SHORE -> true;
case LAND, CAVE, SEA -> false;
};
@@ -53,45 +55,45 @@ final class SpawnerGate {
}
/** Whether the world is in the time and weather the spawner asks for. */
- static boolean suits(Spawner spawner, PlatformWorld world) {
- return SpawnConditions.allow(spawner.timeBlock(), spawner.weather(), world);
+ static boolean suits(Spawner spawner, Sky sky) {
+ return SpawnConditions.allow(spawner.timeBlock(), spawner.weather(), sky);
}
/** Whether the spawner may fire in the chunk now. */
- static boolean canSpawn(String key, Spawner spawner, Engine engine, int chunkX, int chunkZ) {
- if (!canSpawn(key, spawner, engine)) {
+ static boolean canSpawn(String key, Spawner spawner, LiveWorld live, int chunkX, int chunkZ) {
+ if (!canSpawn(key, spawner, live)) {
return false;
}
SpawnRate rate = spawner.maximumRatePerChunk();
- return rate.isInfinite() || engine.getEngineData().getChunk(chunkX, chunkZ).getCooldown(key).canSpawn(rate.interval());
+ return rate.isInfinite() || live.spawnCooldowns().canSpawnInChunk(chunkX, chunkZ, key, rate.interval());
}
/** Counts a spawn of the spawner in the chunk against its rates. */
- static void spawned(String key, Spawner spawner, Engine engine, int chunkX, int chunkZ) {
- spawned(key, spawner, engine);
+ static void spawned(String key, Spawner spawner, LiveWorld live, int chunkX, int chunkZ) {
+ spawned(key, spawner, live);
if (spawner.maximumRatePerChunk().isInfinite()) {
return;
}
- engine.getEngineData().getChunk(chunkX, chunkZ).getCooldown(key).spawn();
+ live.spawnCooldowns().spawnedInChunk(chunkX, chunkZ, key);
}
- private static boolean canSpawn(String key, Spawner spawner, Engine engine) {
- PlatformWorld world = engine.getWorld().platformWorld();
- if (world == null || !suits(spawner, world)) {
+ private static boolean canSpawn(String key, Spawner spawner, LiveWorld live) {
+ Optional sky = live.sky();
+ if (sky.isEmpty() || !suits(spawner, sky.get())) {
return false;
}
SpawnRate rate = spawner.maximumRate();
- return rate.isInfinite() || engine.getEngineData().getCooldown(key).canSpawn(rate.interval());
+ return rate.isInfinite() || live.spawnCooldowns().canSpawn(key, rate.interval());
}
- private static void spawned(String key, Spawner spawner, Engine engine) {
+ private static void spawned(String key, Spawner spawner, LiveWorld live) {
if (spawner.maximumRate().isInfinite()) {
return;
}
- engine.getEngineData().getCooldown(key).spawn();
+ live.spawnCooldowns().spawned(key);
}
}