From 284213e9b8b16ce200b5c42c644746f4c6324c97 Mon Sep 17 00:00:00 2001 From: piexel Date: Sat, 10 Oct 2026 08:46:32 +0200 Subject: [PATCH 1/4] AmbientEffects service: the effects due around a player, decided by the module; Reference.SPECIAL_ENTITY --- .../java/com/volmit/config/Reference.java | 2 + .../com/volmit/service/AmbientEffects.java | 96 +++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 src/main/java/com/volmit/service/AmbientEffects.java diff --git a/src/main/java/com/volmit/config/Reference.java b/src/main/java/com/volmit/config/Reference.java index a98134652..c6badee63 100644 --- a/src/main/java/com/volmit/config/Reference.java +++ b/src/main/java/com/volmit/config/Reference.java @@ -27,6 +27,8 @@ public enum Reference { POTION_EFFECT, /** An enchantment, such as {@code minecraft:sharpness}. */ ENCHANTMENT, + /** A mob of another plugin or content provider, such as {@code mythicmobs:skeleton_king}. */ + SPECIAL_ENTITY, /** A biome of the pack. */ PACK_BIOME, /** A region of the pack. */ diff --git a/src/main/java/com/volmit/service/AmbientEffects.java b/src/main/java/com/volmit/service/AmbientEffects.java new file mode 100644 index 000000000..a3c896a8b --- /dev/null +++ b/src/main/java/com/volmit/service/AmbientEffects.java @@ -0,0 +1,96 @@ +package com.volmit.service; + +import com.volmit.entity.EntitySpec; +import com.volmit.world.BlockPosition; +import com.volmit.world.PackWorld; +import java.util.List; +import java.util.Objects; + +/** + * The ambient effects of an area: sounds, particles, potion effects and commands that play around the players who stay + * in it. The host asks, now and then, for the players it keeps; the module says which effects of the area are due, and + * every random choice that goes with them (where the sound seems to come from, how the particles scatter, how long the + * potion lasts), so that the host only has to carry them out. An effect is due only now and then, as its interval and + * chance say, so most answers are empty. The host asks every provider and carries out all answers. + */ +@Service(Providers.ALL) +public interface AmbientEffects { + /** + * The effects due for a player standing at {@code at}. + * + * @param at world X and Z, Y the height above the dimension's bottom + */ + List due(PackWorld world, BlockPosition at); + + /** + * One effect that plays now. The host carries out the parts it has, in the order sound, particles, commands, potion. + * A part the platform lacks, such as an unknown sound, is skipped. + * + * @param sound a sound to play, or null + * @param particles particles to show, or null + * @param commands console commands to run, none when the effect has no commands that may run now + * @param potion a potion effect to give, or null + */ + record Effect(Sound sound, Particles particles, List commands, Potion potion) { + public Effect { + commands = List.copyOf(commands); + } + } + + /** + * A sound played to the player. + * + * @param key the platform's sound key + * @param offsetX blocks from the player where the sound seems to come from, as the other offsets + * @param volume the sound's volume + * @param pitch the sound's pitch + */ + record Sound(String key, int offsetX, int offsetY, int offsetZ, float volume, float pitch) { + public Sound { + Objects.requireNonNull(key, "key"); + } + } + + /** + * Particles shown to the player. They appear {@code forward} blocks ahead of the player, {@code sideways} blocks to + * the right (negative for the left) and on the surface at that spot, one block up, moved by {@code jitterX} and + * {@code jitterZ} and by {@code lift} blocks up. + * + * @param key the platform's particle key + * @param count how many particles; none makes {@code altX}, {@code altY} and {@code altZ} their motion + * @param altX the particles' offset or motion, as the other two + * @param extra an extra value some particles take; 0 for none + */ + record Particles(String key, double forward, double sideways, double jitterX, double jitterZ, int lift, int count, + double altX, double altY, double altZ, double extra) { + public Particles { + Objects.requireNonNull(key, "key"); + } + } + + /** + * A command to run where the effect plays. + * + * @param command the commands, their delay and repeats; {@code {x}}, {@code {y}} and {@code {z}} stand for the block + * position + * @param offsetX blocks from the player where the command runs, as the other two + */ + record Command(EntitySpec.Command command, double offsetX, double offsetY, double offsetZ) { + public Command { + Objects.requireNonNull(command, "command"); + } + } + + /** + * A potion effect for the player. A player who has the same potion effect with a stronger amplifier keeps it. + * + * @param key the platform's potion effect key + * @param strength the amplifier + * @param ticks how long it lasts, in server ticks + */ + record Potion(String key, int strength, int ticks) { + public Potion { + Objects.requireNonNull(key, "key"); + } + } +} From 25f9ea2f37343978caa0b2122220032922ce034b Mon Sep 17 00:00:00 2001 From: piexel Date: Sat, 10 Oct 2026 08:51:28 +0200 Subject: [PATCH 2/4] LinkedBiomes: settings name the pack biomes they bring into the layout; CaveBiomes service: the cave biome a module puts at a position and a biome's minimum cave depth --- CONTRACTS.md | 4 +-- DESIGN.md | 10 ++++++ README.md | 7 ++++ .../java/com/volmit/config/LinkedBiomes.java | 34 +++++++++++++++++++ .../java/com/volmit/service/CaveBiomes.java | 27 +++++++++++++++ 5 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/volmit/config/LinkedBiomes.java create mode 100644 src/main/java/com/volmit/service/CaveBiomes.java diff --git a/CONTRACTS.md b/CONTRACTS.md index 1b62cbd24..0d0b256b5 100644 --- a/CONTRACTS.md +++ b/CONTRACTS.md @@ -21,7 +21,7 @@ types that carry them and lists what the Iris adapter still owes. | Pack-load validation and diagnostics | host `StageGraphBuilder`, `ResolvedGraph`, `LoadedModules` | | Reference execution | host `PlacementRunner`, `ChunkRunner`, `MantleRunner` | | Work across chunks and mantle writes | `Stage.mantle`, `MantleStage`, `MantleStageContext`, `MantleGenerationContext`; chunk stages read the mantle only | -| Annotated settings | `IrisFeature`, `@Feature` (id, short JSON `key`, optional `root`), config annotations, `OptionsMetadata` | +| Annotated settings | `IrisFeature`, `@Feature` (id, short JSON `key`, optional `root`), config annotations, `OptionsMetadata`, `LinkedBiomes` (`treeBiomes`, `usedBiomes`: pack biomes the settings bring into the layout) | | Area a stage writes | `reach(blocks)`, `reach(PackReach)`, `writesMantle(...)` on stage definitions, `PackSettings`, host `StageReach`, `ResolvedStage.reachBlocks`, `PipelineReach` | | Settings described for studio | `@Desc`, `@Required`, `@MinNumber`, `@MaxNumber`, `@MinItems`, `@Snippet`, `@Ref`/`Reference`, `FeatureRegistry.registerSettings`, `FeatureRegistry.registerHeldType`, host `FeatureCatalog.heldTypes()`, host `LoadedPack.schema()` (`PackSchema`, `FeatureSchema`, `ObjectType`, `SchemaOption`, `ValueKind` with `HostKind`), `ModuleHost.describingHostTypesIn` | | Geometry and mantle registration | `FeatureRegistry`, host `ModuleRegistry`, `FeatureCatalog` | @@ -34,7 +34,7 @@ types that carry them and lists what the Iris adapter still owes. | Module-owned pack checks | `Validator`, `ValidationContext`, `Problem`, `Severity`, `Subject`, `FeatureRegistry.registerValidator`, host `FeatureCatalog.validators()` | | Per-world module state | `PackWorld` (`state`), `InvocationContext.world()`, host `WorldStates` | | Module lifecycle across loads, hotloads and reloads | `ModuleLifecycle`, `FeatureRegistry.registerLifecycle`, host `FeatureCatalog.lifecycles()`, `LifecycleRunner` | -| Host questions answered by modules | `@Service`, `Providers`, `FeatureRegistry.registerService`, host `FeatureCatalog.services(type)` / `service(type)`; services `ObjectsAt`, `StructureLocator` (`LocateResult`), `SaplingGrowth`, `Loot`, `BlockDrops`, `EntitySpawns`; values `ItemDrop`, `EntitySpec`, `ItemRegistry` (`PackResources.items()`) | +| Host questions answered by modules | `@Service`, `Providers`, `FeatureRegistry.registerService`, host `FeatureCatalog.services(type)` / `service(type)`; services `ObjectsAt`, `StructureLocator` (`LocateResult`), `SaplingGrowth`, `Loot`, `BlockDrops`, `EntitySpawns`, `CaveBiomes`; values `ItemDrop`, `EntitySpec`, `ItemRegistry` (`PackResources.items()`) | | Terrain and settings sampling | `TerrainSampler`, `BiomeSample`, `TerrainSample`, `FeatureSettings` | | Dense chunk output | `Hunk`, `GenerationContext.hunk`, reference `ArrayHunk` | | Sparse geometry and transforms | `ObjectGenerator`, `GeneratedObject`, `ObjectTransform`, `ObjectTransformer` | diff --git a/DESIGN.md b/DESIGN.md index 771798940..ad7ed2488 100644 --- a/DESIGN.md +++ b/DESIGN.md @@ -974,6 +974,16 @@ from a sapling, which drops a block has. A module answers such questions through host builds its search area from them through the biome tree it owns). `StructureLocator` (`FIRST`): every structure key a module knows, the ones a world places, and the nearest start of one as a `LocateResult` (`Found`, `NotFound`, `SearchLimitReached`; a sealed interface, so callers switch over every outcome). Keys are pack keys as packs write them and match without regard to case. + `CaveBiomes` (`ONE`): the pack biome a module puts at a position whatever the regions say (a band of the deep dark, + `overriddenBiome`, the height counted above the dimension's bottom) and how deep below the surface a biome's caves begin + (`minDepthBelowSurface`). The host owns the 3D biome of a position (its regions, terrain height and the cave biome stream) + and asks this only where a module decides; one provider, since two modules could not both decide the biome of one cave. +- **Settings that name biomes.** The host owns the biome tree (a region's biomes and their children) and the set of + biomes a dimension reaches, and both must include biomes that module settings name: a cave band's biome, the target of a + floating island. Settings say so by implementing `LinkedBiomes` (`treeBiomes`, which join a region's tree and so its terrain + generators, and `usedBiomes`, which the dimension reaches without joining), instead of the host reading any module's + settings class. `usedBiomes` receives the dimension's own settings, since a name may stand for something the dimension + declares (a floating island's `carving` is a band id or a biome key). - **Why not per-world provider instances.** A factory per world (`world -> provider`) would let a provider hold its world, but every service method would then hide which world it answers for, and a host could not ask a pack-level question without a world. Passing the world keeps providers stateless like stage bodies and puts all per-world data diff --git a/README.md b/README.md index 68a0bd7e3..94af61f6d 100644 --- a/README.md +++ b/README.md @@ -295,6 +295,7 @@ final class RuinsObjects implements ObjectsAt { | `Loot` | `ALL` | The loot tables a container draws from at a `Site` (`Table` of the pack, `PlatformTable` with the seed to draw it with), in the order their items are added, and the `ItemDrop`s one table gives there. The host puts them together, tells listeners, creates the stacks and shuffles the container. | | `BlockDrops` | `ALL` | What a module drops for a broken block: `ItemDrop`s, and whether the platform's own drops of the block are replaced. | | `EntitySpawns` | `ALL` | A `Plan` of entities to spawn in a chunk or at a marker, each `Attempt` an `EntitySpec` with the block, light range and surface it needs; how many appeared (`spawned`); what a marker means (`MarkerRule`); one entity of the pack on request. The host checks light, surface and free space, spawns, and applies the spec. | +| `CaveBiomes` | `ONE` | The pack biome a module puts at a position whatever the regions say (a band of the deep dark), and how far below the surface a biome's caves begin. The host places the cave biome of a position itself and asks this where a module overrides it. | | `VanillaStructures` | `ALL` | Rules, starts, shifts and reaches for the platform's own structures, and fitting the terrain to the starts in one chunk through the `BlockAccess` the host hands over (see Vanilla structures). | ``` @@ -429,6 +430,12 @@ public final class FloraSettings implements IrisFeature { (nothing could set another), or the load fails. There is no second form: the studio schema renders one shape and a wrong shape fails with a message naming the key and the file. - Options keep the order the class declares them in, a superclass's first. +- Settings that bring other pack biomes into the pack's layout implement `LinkedBiomes`: `treeBiomes()` are biomes that join the + biome tree of every region the owner is in (the host registers their terrain generators with the region, as it does an + owner's children), and `usedBiomes(dimension)` are biomes the settings use besides, which the dimension reaches so their + objects, decorators and settings take part in generation. `dimension` is the settings the owner's dimension declares, for + settings that name something the dimension declares, such as a band of its caves. The host asks every dimension and biome + it reaches and ignores blank keys and keys naming no biome. - Built-in settings may hold classes the host describes itself, such as Iris's palettes, which the host names with `ModuleHost.describingHostTypesIn(...)`. They appear as `HostKind` and pack modules cannot use them. diff --git a/src/main/java/com/volmit/config/LinkedBiomes.java b/src/main/java/com/volmit/config/LinkedBiomes.java new file mode 100644 index 000000000..5a08f7a09 --- /dev/null +++ b/src/main/java/com/volmit/config/LinkedBiomes.java @@ -0,0 +1,34 @@ +package com.volmit.config; + +import com.volmit.IrisFeature; + +import java.util.Collection; +import java.util.Set; + +/** + * Implemented by settings that make pack biomes part of a pack's layout besides the ones its regions list: the biome + * that a cave band puts underground, or the target of a floating island. The host asks the settings of every dimension + * and biome it reaches, without knowing the module behind them, so such a biome is loaded, registered and given its own + * settings like any other. Keys are pack biome keys as packs write them; blank keys and keys naming no biome are + * ignored. + */ +public interface LinkedBiomes { + /** + * Biomes that join the biome tree of every region the owner is part of, like the owner's children: the host registers + * them with the region, so their terrain generators take part in the region's terrain. + */ + default Set treeBiomes() { + return Set.of(); + } + + /** + * Biomes the settings use besides, which a dimension reaches (their objects, decorators and settings take part in + * generation) without joining the region's biome tree. + * + * @param dimension the settings the owner's dimension declares, for settings that name something the dimension + * declares, such as a band of its caves + */ + default Set usedBiomes(Collection dimension) { + return Set.of(); + } +} diff --git a/src/main/java/com/volmit/service/CaveBiomes.java b/src/main/java/com/volmit/service/CaveBiomes.java new file mode 100644 index 000000000..f108d2a9a --- /dev/null +++ b/src/main/java/com/volmit/service/CaveBiomes.java @@ -0,0 +1,27 @@ +package com.volmit.service; + +import com.volmit.world.PackWorld; +import java.util.Optional; + +/** + * Which biome a module puts underground. The host places the cave biome of a position itself, from the biome its regions give + * the column and its terrain; this service tells it where a module overrides that and where a cave biome gives way to the + * surface's. A pack has one provider, since two modules deciding the biome of the same cave could not both be right. + */ +@Service(Providers.ONE) +public interface CaveBiomes { + /** + * The pack biome the module puts at the position whatever the regions say, such as a band of the deep dark. Empty where it + * overrides nothing. + * + * @param y the height above the dimension's bottom + * @return the biome key as packs write it + */ + Optional overriddenBiome(PackWorld world, int x, int y, int z); + + /** + * How many blocks below the surface a position must lie for the pack biome {@code biomeKey} to be the cave biome there; + * nearer the surface the surface's biome is. 0 for a biome that has no such limit. + */ + int minDepthBelowSurface(PackWorld world, String biomeKey); +} From a2bee86c1f47d82c10b93409747df719a6347987 Mon Sep 17 00:00:00 2001 From: piexel Date: Sat, 10 Oct 2026 13:01:15 +0200 Subject: [PATCH 3/4] Docs: AmbientEffects, Reference.SPECIAL_ENTITY --- CONTRACTS.md | 5 ++++- DESIGN.md | 2 ++ README.md | 3 ++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CONTRACTS.md b/CONTRACTS.md index 1b62cbd24..910a441f1 100644 --- a/CONTRACTS.md +++ b/CONTRACTS.md @@ -34,7 +34,7 @@ types that carry them and lists what the Iris adapter still owes. | Module-owned pack checks | `Validator`, `ValidationContext`, `Problem`, `Severity`, `Subject`, `FeatureRegistry.registerValidator`, host `FeatureCatalog.validators()` | | Per-world module state | `PackWorld` (`state`), `InvocationContext.world()`, host `WorldStates` | | Module lifecycle across loads, hotloads and reloads | `ModuleLifecycle`, `FeatureRegistry.registerLifecycle`, host `FeatureCatalog.lifecycles()`, `LifecycleRunner` | -| Host questions answered by modules | `@Service`, `Providers`, `FeatureRegistry.registerService`, host `FeatureCatalog.services(type)` / `service(type)`; services `ObjectsAt`, `StructureLocator` (`LocateResult`), `SaplingGrowth`, `Loot`, `BlockDrops`, `EntitySpawns`; values `ItemDrop`, `EntitySpec`, `ItemRegistry` (`PackResources.items()`) | +| Host questions answered by modules | `@Service`, `Providers`, `FeatureRegistry.registerService`, host `FeatureCatalog.services(type)` / `service(type)`; services `ObjectsAt`, `StructureLocator` (`LocateResult`), `SaplingGrowth`, `Loot`, `BlockDrops`, `EntitySpawns`, `AmbientEffects`; values `ItemDrop`, `EntitySpec`, `ItemRegistry` (`PackResources.items()`) | | Terrain and settings sampling | `TerrainSampler`, `BiomeSample`, `TerrainSample`, `FeatureSettings` | | Dense chunk output | `Hunk`, `GenerationContext.hunk`, reference `ArrayHunk` | | Sparse geometry and transforms | `ObjectGenerator`, `GeneratedObject`, `ObjectTransform`, `ObjectTransformer` | @@ -184,6 +184,9 @@ running Iris is the pack publisher's responsibility. - Create what `ItemDrop` and `EntitySpec` describe on the platform, skip what the platform lacks (an unknown enchantment, attribute or item flag) with a warning, and run the checks that come with an `EntitySpawns.Attempt` (light, surface, free space) before spawning. Report how many entities appeared with `EntitySpawns.spawned`. +- `AmbientEffects.due`: ask for the player's last sampled position (not every tick's), carry out an `Effect` in the order + sound, particles, commands, potion, skip a part the platform lacks, and give no potion to a player who already has the + same one with a higher amplifier. - Decode IrisApi's value types like settings: `BlockSpec`, `PaletteSpec`, `NoiseStyle`, `StyledRange`, `Range` and `BlockPosition` from the JSON shapes in their docs, `Object` as maps, lists, `Double`s, strings and booleans. Read a `"snippet/"` or `"snippet//"` string of a `@Snippet` type from diff --git a/DESIGN.md b/DESIGN.md index 771798940..9df789813 100644 --- a/DESIGN.md +++ b/DESIGN.md @@ -969,6 +969,8 @@ from a sapling, which drops a block has. A module answers such questions through damaged), and the host reads what only the platform knows (light, the surface below, free space, the blocks around a sapling) through the attempt's conditions or a `Surroundings` view. A service that must hear how its plan went has a second method for it (`EntitySpawns.spawned`, which keeps a spawner's rate limits). + `AmbientEffects` follows the same rule: the module decides which effects are due (interval and chance, kept in the world's + state) and every random value they carry, the host only plays them. - **Services now.** `ObjectsAt` (`ALL`): pack object keys a module would place in a chunk, predicted without generating it, and the biomes and regions whose settings place a given object (`PlacedBy`, named by pack keys; the host builds its search area from them through the biome tree it owns). `StructureLocator` (`FIRST`): every structure key a module knows, the ones a world places, and the diff --git a/README.md b/README.md index 68a0bd7e3..581b8435a 100644 --- a/README.md +++ b/README.md @@ -295,6 +295,7 @@ final class RuinsObjects implements ObjectsAt { | `Loot` | `ALL` | The loot tables a container draws from at a `Site` (`Table` of the pack, `PlatformTable` with the seed to draw it with), in the order their items are added, and the `ItemDrop`s one table gives there. The host puts them together, tells listeners, creates the stacks and shuffles the container. | | `BlockDrops` | `ALL` | What a module drops for a broken block: `ItemDrop`s, and whether the platform's own drops of the block are replaced. | | `EntitySpawns` | `ALL` | A `Plan` of entities to spawn in a chunk or at a marker, each `Attempt` an `EntitySpec` with the block, light range and surface it needs; how many appeared (`spawned`); what a marker means (`MarkerRule`); one entity of the pack on request. The host checks light, surface and free space, spawns, and applies the spec. | +| `AmbientEffects` | `ALL` | The effects due for a player standing at a position: a `Sound`, `Particles`, `Command`s and a `Potion` per `Effect`, every random choice already made (offsets, scatter, duration). The host asks now and then, carries out the parts the platform has, and keeps a stronger potion effect the player already has. | | `VanillaStructures` | `ALL` | Rules, starts, shifts and reaches for the platform's own structures, and fitting the terrain to the starts in one chunk through the `BlockAccess` the host hands over (see Vanilla structures). | ``` @@ -408,7 +409,7 @@ public final class FloraSettings implements IrisFeature { - `@Ref(Reference.X)` says what a `String` or `ResourceId` names, also on lists, sets and arrays of them, so studio offers the right list: `BLOCK`, `ITEM`, `ENTITY`, `BIOME`, `STRUCTURE`, `STRUCTURE_PREFIX` (a structure or a family prefix such as `minecraft:village`), `STRUCTURE_SET`, `TEMPLATE_POOL` (a jigsaw template pool), - `POTION_EFFECT` or `ENCHANTMENT` from the server's registries, `NOISE_STYLE` from the host's noise + `POTION_EFFECT`, `ENCHANTMENT` or `SPECIAL_ENTITY` (a mob of another plugin) from the server's registries, `NOISE_STYLE` from the host's noise styles, or `PACK_BIOME`, `PACK_REGION`, `PACK_OBJECT`, `PACK_EXPRESSION` or `PACK_IMAGE_MAP` of the pack. The pack kinds fit `String` only, in the form packs use (`desert/dunes`), never `ResourceId`. `BlockState` fields name blocks without it. `@Ref` on any other field fails the load. From 07cb9a57eb618705e2319ea30fa1e4217d74700b Mon Sep 17 00:00:00 2001 From: piexel Date: Sat, 10 Oct 2026 13:01:33 +0200 Subject: [PATCH 4/4] Test the AmbientEffects values --- .../java/com/volmit/ItemAndEntityValuesTest.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/test/java/com/volmit/ItemAndEntityValuesTest.java b/src/test/java/com/volmit/ItemAndEntityValuesTest.java index d930ae66f..bde3e4b5c 100644 --- a/src/test/java/com/volmit/ItemAndEntityValuesTest.java +++ b/src/test/java/com/volmit/ItemAndEntityValuesTest.java @@ -3,6 +3,7 @@ package com.volmit; import com.volmit.entity.EntitySpec; import com.volmit.item.ItemDrop; import com.volmit.item.ItemEnchantment; +import com.volmit.service.AmbientEffects; import com.volmit.service.BlockDrops; import com.volmit.service.EntitySpawns; import com.volmit.service.SaplingGrowth; @@ -57,6 +58,19 @@ class ItemAndEntityValuesTest { assertTrue(SaplingGrowth.TreeObjects.NONE.objects().isEmpty()); } + @Test + void anAmbientEffectKeepsItsCommandsApartAndRefusesPartsWithoutKeys() { + List commands = new ArrayList<>(List.of( + new AmbientEffects.Command(new EntitySpec.Command(List.of("say hi"), 0, false, 100), 1, 0, -1))); + AmbientEffects.Effect effect = new AmbientEffects.Effect(null, null, commands, new AmbientEffects.Potion("luck", 0, 100)); + commands.clear(); + + assertEquals(1, effect.commands().size()); + assertThrows(UnsupportedOperationException.class, () -> effect.commands().clear()); + assertThrows(NullPointerException.class, () -> new AmbientEffects.Sound(null, 0, 0, 0, 1, 1)); + assertThrows(NullPointerException.class, () -> new AmbientEffects.Command(null, 0, 0, 0)); + } + private static EntitySpec entity(String type, String specialType) { return new EntitySpec(type, specialType, null, "", new EntitySpec.Flags(false, true, true, false, true, false, false, false, false, false, false), EntitySpec.Equipment.NONE, List.of(), List.of(), List.of(), 0L, null, null, false,