mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 00:04:42 +00:00
Structure services answer what Iris core still asked its locator directly: placed keys and the starts a module makes of platform structures
StructureLocator.placed(world) (default: locatable): every key under which locate finds what the module places, its own structures and the platform structures it starts or stands in for; the host routes locate by it. VanillaStructures.startedStructures(world), locatableStarts(world) and locateStart(world, structure, fromX, fromZ, maxRings, ChunkFilter): the platform structures a module starts itself, the ones it can find, and the nearest start of one, ring by ring through the module's grids, trying only the chunks the host's filter accepts (the platform's /locate checks each start in the world and asks again without a refused chunk). README, DESIGN, CONTRACTS; test.
This commit is contained in:
1 parent
030cbbb8fc
commit
750e0691a6
6 files changed
+90
-6
No files matched your search
+5
-1
@@ -28,7 +28,7 @@ types that carry them and lists what the Iris adapter still owes.
|
||||
| Block states and palettes | `BlockState`, `BlockRegistry`, `BlockPalette`, `BlockSpec` (`BlockRegistry.resolve(BlockSpec)`, `blockEntity`), `PaletteSpec` and `PaletteSampler` (`BlockRegistry.palette`) |
|
||||
| Noise from pack-described styles | `NoiseStyle`, `StyledRange`, `PackResources.noise()`, `NoiseFactory`, `NoiseSampler` |
|
||||
| Values in settings | `BlockSpec`, `PaletteSpec`, `NoiseStyle`, `StyledRange`, `Range`, `BlockPosition`, `JigsawOverrides`, `Object` as `ValueKind.AnyKind` |
|
||||
| Decisions over and fit of the platform's own structures | service `VanillaStructures` (`rule`, `starts`, `shift`, `reach`, `beforePieces`, `afterPieces`, `setup`), `VanillaStructureRule`, `VanillaStructureContext`, `VanillaStructureStart`, `VanillaStructureStartContext`, `VanillaStructureSetup`, `PlatformStart`, `StartMemo`, `StartReach`, `StructureFit` (`Start`, `Piece`, `ColumnVisitor`), `DecorationStep`, `TerrainAdaptation`, `PieceKind`, `TemplateCells`, `world.BlockAccess`, host `FeatureCatalog.registrations(service)` |
|
||||
| Decisions over and fit of the platform's own structures | service `VanillaStructures` (`rule`, `starts`, `shift`, `reach`, `beforePieces`, `afterPieces`, `setup`, `startedStructures`, `locatableStarts`, `locateStart`, `ChunkFilter`), `VanillaStructureRule`, `VanillaStructureContext`, `VanillaStructureStart`, `VanillaStructureStartContext`, `VanillaStructureSetup`, `PlatformStart`, `StartMemo`, `StartReach`, `StructureFit` (`Start`, `Piece`, `ColumnVisitor`), `DecorationStep`, `TerrainAdaptation`, `PieceKind`, `TemplateCells`, `world.BlockAccess`, host `FeatureCatalog.registrations(service)` |
|
||||
| Pack-scoped resolution | `ResourceId`, `ResourceKey<T>`, `PackResources` (`find`, `ids`), `PackBiome`, `PackRegion` |
|
||||
| Module-owned pack resources | `ResourceKind`, `FeatureRegistry.registerResourceKind`, `@ResourceRef`, host `ModuleHost.reservingFolders`, `FeatureCatalog.resourceKinds()`, `ResourceKindSchema`, `ValueKind.ResourceReferenceKind` |
|
||||
| Module-owned pack checks | `Validator`, `ValidationContext`, `Problem`, `Severity`, `Subject`, `FeatureRegistry.registerValidator`, host `FeatureCatalog.validators()` |
|
||||
@@ -233,6 +233,10 @@ running Iris is the pack publisher's responsibility.
|
||||
structure, let a start take the chunk from a platform start only when it says so or the structure is `REPLACE`d,
|
||||
apply its jigsaw overrides, keep its memo, record its identity with every start the host publishes, and ask again (same
|
||||
answer) when locating or verifying a start found in the world.
|
||||
- Send the platform's locate of a structure some provider lists in `startedStructures` to that provider's
|
||||
`locateStart` (module id order, the first that lists it in `locatableStarts`), convert the start's Y to the platform's,
|
||||
check the start the platform made there before reporting it, and search again refusing that chunk when the check fails.
|
||||
Route the host's own structure commands by `startedStructures` the same way.
|
||||
- Ask `setup` per dimension before its worlds build their structure state and when installing data packs; multiply
|
||||
frequencies per structure set (0.01 to 16), protect the platform's definitions in every installed data pack once
|
||||
any dimension of any loaded pack asks for it.
|
||||
|
||||
@@ -1020,7 +1020,8 @@ from a sapling, which drops a block has. A module answers such questions through
|
||||
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
|
||||
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 (`locatable`; `placed` adds the
|
||||
platform structures the module starts or stands in for, and keys it places but cannot search for), 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,
|
||||
|
||||
@@ -329,14 +329,14 @@ final class RuinsObjects implements ObjectsAt {
|
||||
| Service | Providers | What the host asks |
|
||||
| --- | --- | --- |
|
||||
| `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. |
|
||||
| `StructureLocator` | `FIRST` | Every structure key the module knows (the structure index), the ones a world places and can locate (commands complete them), every key under which it finds what a world places (`placed`: its own structures and the platform structures it starts or stands in for), 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. |
|
||||
| `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. |
|
||||
| `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). |
|
||||
| `VanillaStructures` | `ALL` | Rules, starts, shifts and reaches for the platform's own structures, fitting the terrain to the starts in one chunk through the `BlockAccess` the host hands over, and finding the starts a module makes of them (see Vanilla structures). |
|
||||
| `VanillaFeatures` | `ALL` | Whether the platform runs its own placed features (ores, trees, plants, springs) over a world's terrain, and which decoration steps (`DecorationStep`) and features it skips there. Off unless a module turns it on; any module may refuse a step or a feature. Asked once per world, step and feature. |
|
||||
|
||||
```
|
||||
@@ -605,6 +605,11 @@ Every method has a default that changes nothing, so a provider implements only w
|
||||
- `setup(context)`: before any world of the dimension exists, how often each structure set starts (`withFrequency`,
|
||||
multipliers of several modules multiply) and whether the data packs the host installs must leave the platform's own
|
||||
structure definitions alone (`protectingVanillaDefinitions`, for every pack once any dimension asks for it).
|
||||
- `startedStructures(world)`, `locatableStarts(world)` and `locateStart(world, structure, fromX, fromZ, maxRings,
|
||||
accepts)`: the platform structures the module starts itself, the ones of them it can find, and the nearest start of one,
|
||||
searched ring by ring through the module's own placement grids. The host sends the platform's `/locate` and its own
|
||||
structure commands for those structures here, then checks the start it got in the world; `accepts` lets it skip chunks
|
||||
it already refused.
|
||||
|
||||
```java
|
||||
@Override
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.util.Set;
|
||||
|
||||
/** Finds the structures a module places, for the host's structure commands and index. Structures are named by their
|
||||
* keys, in the form packs write them ({@code castle}, {@code villages/plains}). The host asks the providers in order and
|
||||
* sends a key to the first that can locate it in the world.
|
||||
* sends a key to the first that places it in the world ({@link #placed}).
|
||||
*/
|
||||
@Service(Providers.FIRST)
|
||||
public interface StructureLocator {
|
||||
@@ -20,10 +20,19 @@ public interface StructureLocator {
|
||||
*/
|
||||
Set<String> locatable(PackWorld world);
|
||||
|
||||
/** The keys under which {@link #locate} finds the structures this module places in {@code world}, locatable or not: its
|
||||
* own structures, the platform structures it starts itself and the platform structures its own stand in for (namespaced,
|
||||
* such as {@code minecraft:ancient_city}). Commands report them and send a search for one of them here. By default the
|
||||
* {@link #locatable} ones.
|
||||
*/
|
||||
default Set<String> placed(PackWorld world) {
|
||||
return locatable(world);
|
||||
}
|
||||
|
||||
/**
|
||||
* The start of structure {@code key} nearest to the column {@code fromX}, {@code fromZ} (world coordinates), searched
|
||||
* up to {@code maxRadiusChunks} chunks away from it. The position is the structure's origin: world X and Z, and Y the
|
||||
* height above the dimension's bottom of its base. Called with a key from {@link #locatable}. May take long; the
|
||||
* height above the dimension's bottom of its base. Called with a key from {@link #placed}. May take long; the
|
||||
* host calls it off the server's main thread.
|
||||
*/
|
||||
LocateResult locate(PackWorld world, String key, int fromX, int fromZ, int maxRadiusChunks);
|
||||
|
||||
@@ -10,8 +10,10 @@ import com.volmit.vanilla.VanillaStructureRule;
|
||||
import com.volmit.vanilla.VanillaStructureSetup;
|
||||
import com.volmit.vanilla.VanillaStructureStart;
|
||||
import com.volmit.vanilla.VanillaStructureStartContext;
|
||||
import com.volmit.world.PackWorld;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
/** A module's say over the platform's own structures, the ones Minecraft, data packs and mods register, in the pack's
|
||||
* worlds. The host asks every provider, in module id order:
|
||||
@@ -91,4 +93,37 @@ public interface VanillaStructures {
|
||||
default VanillaStructureSetup setup(VanillaStructureContext context) {
|
||||
return VanillaStructureSetup.UNCHANGED;
|
||||
}
|
||||
|
||||
/** The platform structures this module starts itself in {@code world} ({@link #starts}), wherever its own placements put
|
||||
* them. The host's locate and structure commands send them to {@link #locateStart}.
|
||||
*/
|
||||
default Set<ResourceId> startedStructures(PackWorld world) {
|
||||
return Set.of();
|
||||
}
|
||||
|
||||
/** Those of {@link #startedStructures} whose starts {@link #locateStart} can find in {@code world}: a start whose
|
||||
* placement can never start in the world's height, for one, cannot be searched for.
|
||||
*/
|
||||
default Set<ResourceId> locatableStarts(PackWorld world) {
|
||||
return Set.of();
|
||||
}
|
||||
|
||||
/**
|
||||
* The start of the platform structure {@code structure} this module makes nearest to the column {@code fromX},
|
||||
* {@code fromZ} (world coordinates), searched ring by ring outward through its placements' grids up to {@code maxRings}
|
||||
* rings: the nearest start of the first ring that has one. The position is the start's origin: world X and Z, and Y the
|
||||
* height above the dimension's bottom of its base. Only chunks {@code accepts} allows count; the host checks the start
|
||||
* the platform made there and searches again without a chunk it refuses. An exception {@code accepts} throws ends the
|
||||
* search and reaches the caller. Called with a structure from {@link #locatableStarts}, off the server's main thread.
|
||||
*/
|
||||
default LocateResult locateStart(PackWorld world, ResourceId structure, int fromX, int fromZ, int maxRings,
|
||||
ChunkFilter accepts) {
|
||||
return LocateResult.NOT_FOUND;
|
||||
}
|
||||
|
||||
/** Which chunks a {@link #locateStart} search may answer with. */
|
||||
@FunctionalInterface
|
||||
interface ChunkFilter {
|
||||
boolean accepts(int chunkX, int chunkZ);
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,10 @@ package com.volmit;
|
||||
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.config.OptionsMetadata;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.service.LocateResult;
|
||||
import com.volmit.service.StructureLocator;
|
||||
import com.volmit.service.VanillaFeatures;
|
||||
import com.volmit.service.VanillaStructures;
|
||||
import com.volmit.vanilla.DecorationStep;
|
||||
@@ -14,11 +17,13 @@ import com.volmit.vanilla.VanillaStructureContext;
|
||||
import com.volmit.vanilla.VanillaStructureRule;
|
||||
import com.volmit.vanilla.VanillaStructureSetup;
|
||||
import com.volmit.vanilla.VanillaStructureStart;
|
||||
import com.volmit.world.PackWorld;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.OptionalInt;
|
||||
import java.util.Set;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/** The values a vanilla structures provider answers with and how the host combines several modules' answers. */
|
||||
@@ -123,6 +128,31 @@ class VanillaStructureValuesTest {
|
||||
assertEquals(StartReach.PLATFORM, provider.reach(CITY, true, Optional.empty(), null));
|
||||
assertEquals(VanillaStructureSetup.UNCHANGED, provider.setup(null));
|
||||
assertEquals(VanillaStructureRule.GENERATE, new VanillaStructures() { }.rule(CITY, null));
|
||||
assertEquals(Set.of(), provider.startedStructures(null));
|
||||
assertEquals(Set.of(), provider.locatableStarts(null));
|
||||
assertEquals(LocateResult.NOT_FOUND, provider.locateStart(null, CITY, 0, 0, 8, (chunkX, chunkZ) -> true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aLocatorPlacesWhatItCanLocateUnlessItSaysMore() {
|
||||
StructureLocator locator = new StructureLocator() {
|
||||
@Override
|
||||
public Set<String> structures(PackResources pack) {
|
||||
return Set.of("castle", "tower");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> locatable(PackWorld world) {
|
||||
return Set.of("castle");
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocateResult locate(PackWorld world, String key, int fromX, int fromZ, int maxRadiusChunks) {
|
||||
return LocateResult.NOT_FOUND;
|
||||
}
|
||||
};
|
||||
|
||||
assertEquals(Set.of("castle"), locator.placed(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in new issue
Block a user