Document the loot, drop, entity and sapling services and the item and entity values

This commit is contained in:
piexel committed 2026-10-09 22:26:05 +02:00
1 parent 93f1768174
commit 3633c105b4
4 files changed
+92 -2

No files matched your search

+6 -2
View File
@@ -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`) |
| 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()`) |
| Terrain and settings sampling | `TerrainSampler`, `BiomeSample`, `TerrainSample`, `FeatureSettings` |
| Dense chunk output | `Hunk<T>`, `GenerationContext.hunk`, reference `ArrayHunk<T>` |
| Sparse geometry and transforms | `ObjectGenerator`, `GeneratedObject`, `ObjectTransform`, `ObjectTransformer` |
@@ -175,7 +175,11 @@ running Iris is the pack publisher's responsibility.
catalog order until one answers, and use `service(type)` for `ONE`. Call providers from any thread, but long
searches off the server's main thread, and carry out what they return on the thread the platform needs.
- Read a `StructureLocator` position's Y as a height above the dimension's bottom and convert it to the platform's Y
at the boundary, like every other IrisApi height.
at the boundary, like every other IrisApi height; the same goes for the positions of `Loot.Site`, `BlockDrops.Broken`,
`EntitySpawns` and `SaplingGrowth`.
- 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`.
- 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/<name>"` or `"snippet/<folder>/<name>"` string of a `@Snippet` type from
+7
View File
@@ -912,6 +912,13 @@ from a sapling, which drops a block has. A module answers such questions through
have several providers.
- **Threading.** The host may call a provider from any thread, several at once. A provider that searches long
(`StructureLocator.locate`) is called off the server's main thread.
- **Loot, drops, entities, trees.** `Loot` (`ALL`) asks in two steps, which tables a container draws from and what a
table gives, so the host and plugins can change the tables in between. `BlockDrops`, `EntitySpawns` and `SaplingGrowth`
return values the host carries out: `ItemDrop` and `EntitySpec` carry every decision the module made (the module draws
from its streams in the order the feature always did, which is why `ItemRegistry` answers whether an item can be
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).
- **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
+14
View File
@@ -291,6 +291,10 @@ final class RuinsObjects implements ObjectsAt {
| --- | --- | --- |
| `ObjectsAt` | `ALL` | The pack objects a module would place in a chunk, predicted without generating it, and the biomes and regions of the layout that place a given object (`PlacedBy`), so the host can narrow an object search to the areas it can appear in. |
| `StructureLocator` | `FIRST` | Every structure key the module knows (the structure index), the ones a world places (commands complete them), and the nearest start of one, as a `LocateResult`: `Found(position)`, `NotFound` or `SearchLimitReached`. Keys match without regard to case. |
| `SaplingGrowth` | `ALL` | The tree a growing sapling becomes, as a `Growth` of placed blocks (the first module with one wins; none leaves the growth to the platform), and the objects the module places as trees (`TreeObjects`). The host passes `Surroundings` to read the world around the sapling and places the blocks itself. |
| `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. |
```
Service example.Clock is provided by module example:alpha from modules/alpha.jar already, and module example:beta from modules/beta.jar provides it too; a pack has one provider of it (Providers.ONE), so remove one of them
@@ -429,6 +433,16 @@ Class com.example.flora.Shape of settings example:flora (module example:flora fr
Snippet name 'patch' of com.example.flora.Patch of settings example:flora (module example:flora from modules/flora.jar) is not under a module of the pack; snippets of pack modules start with their module's id as a folder path, such as 'example/flora/patch' (folder snippet/example/flora/patch/)
```
## Items and entities
A service describes an item or an entity as a value after making every random choice, and the host creates it on the
platform. `ItemDrop` is one stack: the item key as the pack wrote it, the amount, name, lore, enchantments, attribute
modifiers, damage as a fraction of the item's durability, colours and custom data. `EntitySpec` is one entity: its type
or the other plugin's mob, flags, equipment (`ItemDrop`s), passengers, attribute modifiers, loot table keys, leash
holder, spawn effect and console commands. Modules ask the platform about items through `resources.items()`
(`ItemRegistry.maxDurability(key)`, empty for an item the platform lacks): whether an item can be damaged decides
whether a loot entry draws a damage roll, so a module needs it to keep its random stream.
## Values in settings
Settings describe blocks, noise and ranges with IrisApi's value types, which read the JSON packs already write:
@@ -0,0 +1,65 @@
package com.volmit;
import com.volmit.entity.EntitySpec;
import com.volmit.item.ItemDrop;
import com.volmit.item.ItemEnchantment;
import com.volmit.service.BlockDrops;
import com.volmit.service.EntitySpawns;
import com.volmit.service.SaplingGrowth;
import com.volmit.world.BlockPosition;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.*;
/** The values services hand the host are immutable and refuse what the host could not create. */
class ItemAndEntityValuesTest {
@Test
void anItemDropRefusesNothingToDropAndKeepsItsListsApart() {
assertThrows(IllegalArgumentException.class, () -> ItemDrop.of("stick", 0));
List<ItemEnchantment> enchantments = new ArrayList<>(List.of(new ItemEnchantment("sharpness", 3)));
ItemDrop drop = new ItemDrop("diamond_sword", 1, null, List.of(), enchantments, List.of(), false, List.of(), null,
0.25, null, null, Map.of(), null);
enchantments.clear();
assertEquals(1, drop.enchantments().size());
assertThrows(UnsupportedOperationException.class, () -> drop.enchantments().clear());
assertThrows(IllegalArgumentException.class, () -> new ItemEnchantment("sharpness", 0));
}
@Test
void anEntityKnowsWhetherItIsAnotherPluginsMob() {
EntitySpec zombie = entity("minecraft:zombie", "");
EntitySpec special = entity("", "mythic:dragon");
assertFalse(zombie.isSpecial());
assertTrue(special.isSpecial());
}
@Test
void anAttemptSaysWhetherLightMatters() {
BlockPosition at = new BlockPosition(1, 2, 3);
EntitySpec zombie = entity("minecraft:zombie", "");
assertFalse(new EntitySpawns.Attempt(at, zombie, EntitySpawns.Surface.LAND, 0, 15, true).restrictsLight());
assertTrue(new EntitySpawns.Attempt(at, zombie, EntitySpawns.Surface.LAND, 0, 7, true).restrictsLight());
assertTrue(new EntitySpawns.Attempt(at, zombie, EntitySpawns.Surface.LAND, 8, 15, true).restrictsLight());
}
@Test
void answersWithNothingAreEmpty() {
assertTrue(BlockDrops.Result.NONE.drops().isEmpty());
assertFalse(BlockDrops.Result.NONE.replacesVanillaDrops());
assertTrue(SaplingGrowth.TreeObjects.NONE.objects().isEmpty());
}
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,
null, null, false, List.of());
}
}