From 284213e9b8b16ce200b5c42c644746f4c6324c97 Mon Sep 17 00:00:00 2001 From: piexel Date: Sat, 10 Oct 2026 08:46:32 +0200 Subject: [PATCH 1/3] 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 a2bee86c1f47d82c10b93409747df719a6347987 Mon Sep 17 00:00:00 2001 From: piexel Date: Sat, 10 Oct 2026 13:01:15 +0200 Subject: [PATCH 2/3] 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 3/3] 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,