Batch 4 of the API review: api and host artifacts, ModuleLoadException

- Split into Gradle subprojects api (com.volmit:iris-api) and host
  (com.volmit:iris-host). ExposedPackages never exposes com.volmit.host.
- One unchecked ModuleLoadException(moduleId, origin, message, cause)
  for every load error; messages unchanged.
- PlacementAccess.set(x, y, z, state) next to set(PlacedBlock).
- BlockState: precompiled patterns, withProperty copies once.
- Mantle and layer views are made once per invocation.
- Hunk getters are width(), height(), depth().
- Held types and host types are deprecated for removal at the cut-over.
- Docs: artifacts, one-or-more modules per jar, no option shorthand.
This commit is contained in:
piexel committed 2026-10-24 04:19:39 +02:00
1 parent 3a307b5b8e
commit b6c2992752
309 files changed
+547 -178

No files matched your search

@@ -0,0 +1,100 @@
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;
import java.util.Optional;
/**
* 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<Effect> 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; empty for none
* @param particles particles to show; empty for none
* @param commands console commands to run, none when the effect has no commands that may run now
* @param potion a potion effect to give; empty for none
*/
record Effect(Optional<Sound> sound, Optional<Particles> particles, List<Command> commands, Optional<Potion> potion) {
public Effect {
Objects.requireNonNull(sound, "sound");
Objects.requireNonNull(particles, "particles");
commands = List.copyOf(commands);
Objects.requireNonNull(potion, "potion");
}
}
/**
* 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");
}
}
}
@@ -0,0 +1,44 @@
package com.volmit.service;
import com.volmit.block.BlockState;
import com.volmit.item.ItemDrop;
import com.volmit.world.BlockPosition;
import com.volmit.world.PackWorld;
import java.util.List;
import java.util.Objects;
/**
* Items a module drops when a block breaks, in addition to or instead of the platform's. The host asks every provider
* when a player breaks a block in a world generated with the pack, drops the items of all answers where the block was
* and keeps the platform's own drops unless an answer replaces them.
*/
@Service(Providers.ALL)
public interface BlockDrops {
/** What this module drops for the block {@code broken}; {@link Result#NONE} when it does nothing for that block. */
Result drops(PackWorld world, Broken broken);
/**
* The block that was broken.
*
* @param position world X and Z, Y the height above the dimension's bottom
* @param block the block as it was
*/
record Broken(BlockPosition position, BlockState block) {
public Broken {
Objects.requireNonNull(position, "position");
Objects.requireNonNull(block, "block");
}
}
/**
* @param drops the items to drop
* @param replacesVanillaDrops whether the platform's own drops of the block are not dropped
*/
record Result(List<ItemDrop> drops, boolean replacesVanillaDrops) {
public static final Result NONE = new Result(List.of(), false);
public Result {
drops = List.copyOf(drops);
}
}
}
@@ -0,0 +1,29 @@
package com.volmit.service;
import com.volmit.resource.ResourceId;
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's pack id
*/
Optional<ResourceId> overriddenBiome(PackWorld world, int x, int y, int z);
/**
* How many blocks below the surface a position must lie for the pack biome {@code biome} to be the cave biome there;
* nearer the surface the surface's biome is. 0 for a biome that has no such limit. The answer depends on the world and the
* biome only: the host asks once per biome and keeps it while the world runs.
*/
int minDepthBelowSurface(PackWorld world, ResourceId biome);
}
@@ -0,0 +1,127 @@
package com.volmit.service;
import com.volmit.entity.EntitySpec;
import com.volmit.resource.ResourceId;
import com.volmit.world.BlockPosition;
import com.volmit.world.PackWorld;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
/**
* The entities a module spawns in the world over time: spawners the dimension, region and biomes list, and the spawners
* markers in the world name. The host decides when and where to look, asks the providers, and spawns what the first
* answer plans, after checking the conditions of the platform that come with it (light, the surface below, free space).
* It tells the module how many entities appeared so that the module can keep its limits on how often a spawner fires.
*/
@Service(Providers.ALL)
public interface EntitySpawns {
/** What the module plans to spawn in the chunk or at the marker, or empty to spawn nothing. */
Optional<Plan> plan(PackWorld world, Site site);
/** Called with the number of entities of {@code plan} that appeared, so the spawner's rate limits count them. */
void spawned(PackWorld world, Plan plan, int count);
/** The pack's entity {@code entity} as this module would spawn it, for tools that spawn one on request; empty for an unknown one. */
Optional<EntitySpec> entity(PackWorld world, ResourceId entity);
/** What a marker in the world means for spawning; empty for a marker this module does not know. */
Optional<MarkerRule> marker(PackWorld world, String tag);
/** Where entities may spawn. */
sealed interface Site permits Chunk, Marker {
}
/**
* An ambient spawn in a chunk.
*
* @param chunkX chunk coordinates
* @param livingEntities how many living entities the chunk already holds
* @param initial whether this is the spawn of a chunk that was just generated
*/
record Chunk(int chunkX, int chunkZ, int livingEntities, boolean initial) implements Site {
}
/**
* A spawn at a marker.
*
* @param position the marker's block: world X and Z, Y the height above the dimension's bottom
* @param marker the marker's tag
* @param spawner the pack's spawner chosen among the marker's
* @param initial whether the spawner's initial spawns are used rather than its ordinary ones
*/
record Marker(BlockPosition position, String marker, ResourceId spawner, boolean initial) implements Site {
public Marker {
Objects.requireNonNull(position, "position");
Objects.requireNonNull(marker, "marker");
Objects.requireNonNull(spawner, "spawner");
}
}
/**
* What a marker does.
*
* @param spawners the pack's spawners at the marker
* @param emptyAbove whether it only counts with free space above it
* @param removeOnChange whether it goes away when its block changes
*/
record MarkerRule(List<ResourceId> spawners, boolean emptyAbove, boolean removeOnChange) {
public MarkerRule {
spawners = List.copyOf(spawners);
}
}
/**
* Entities to spawn, tried one after the other.
*
* @param spawner the pack's spawner that planned them
* @param chunkX the chunk they spawn in, where the spawner's per-chunk limit counts them
* @param exhaustsMarker whether the marker that led here is used up and should be removed
* @param attempts the spawns to try
*/
record Plan(ResourceId spawner, int chunkX, int chunkZ, boolean exhaustsMarker, List<Attempt> attempts) {
public Plan {
Objects.requireNonNull(spawner, "spawner");
attempts = List.copyOf(attempts);
}
}
/**
* One entity to spawn at a block. The host spawns it only if the block's light level lies in the range (when the
* range is restricted) and, when {@code checkSurface}, the block below suits the entity's {@code surface} and the
* space the entity needs is free.
*
* @param at world X and Z, Y the height above the dimension's bottom
* @param entity what to spawn
* @param surface the kind of ground or fluid the entity needs below it
* @param minLight lowest light level allowed, 0 for any
* @param maxLight highest light level allowed, 15 for any
* @param checkSurface whether to check the surface and the free space
*/
record Attempt(BlockPosition at, EntitySpec entity, Surface surface, int minLight, int maxLight, boolean checkSurface) {
public Attempt {
Objects.requireNonNull(at, "at");
Objects.requireNonNull(entity, "entity");
Objects.requireNonNull(surface, "surface");
}
/** Whether the light level matters. */
public boolean restrictsLight() {
return minLight > 0 || maxLight < 15;
}
}
/** The ground or fluid an entity spawns on. */
enum Surface {
/** Solid ground. */
LAND,
/** Ground animals spawn on, such as grass, dirt and podzol. */
ANIMAL,
/** Within water. */
WATER,
/** Solid ground or water. */
OVERWORLD,
/** Within lava. */
LAVA
}
}
@@ -0,0 +1,29 @@
package com.volmit.service;
import com.volmit.world.BlockPosition;
import java.util.Objects;
/** How a search for something in a world ended: found at a position, not there, or given up before covering the whole
* area asked for.
*/
public sealed interface LocateResult {
LocateResult NOT_FOUND = new NotFound();
LocateResult SEARCH_LIMIT_REACHED = new SearchLimitReached();
static LocateResult found(BlockPosition position) {
return new Found(position);
}
/** Found at {@code position}: world X and Z, and Y the height above the dimension's bottom. */
record Found(BlockPosition position) implements LocateResult {
public Found {
Objects.requireNonNull(position, "position");
}
}
/** The whole area was searched and holds none. */
record NotFound() implements LocateResult {}
/** The search stopped before covering the area, such as after checking as many candidates as it allows itself. */
record SearchLimitReached() implements LocateResult {}
}
@@ -0,0 +1,67 @@
package com.volmit.service;
import com.volmit.block.BlockState;
import com.volmit.item.ItemDrop;
import com.volmit.resource.ResourceId;
import com.volmit.world.BlockPosition;
import com.volmit.world.PackWorld;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
/**
* The loot a module gives containers and mobs. The host asks in two steps so that it, and plugins listening to it, can
* see and change which tables are used: {@link #tables} names the tables a container draws from, {@link #items} turns
* one table into items. The host asks every provider and puts the answers together; a provider answers {@link #items}
* only for the tables it knows. A container is filled with items the host creates on the platform, in the order of the
* tables.
*/
@Service(Providers.ALL)
public interface Loot {
/**
* The tables the container at {@code site} draws from, in the order their items are added. Empty when the module
* gives that container nothing.
*/
List<Source> tables(PackWorld world, Site site);
/** The items the pack's table {@code table} gives at {@code site}; empty for a table this module does not know. */
List<ItemDrop> items(PackWorld world, Site site, ResourceId table);
/**
* Where loot is given.
*
* @param position the container, or the mob's spawn spot: world X and Z, Y the height above the dimension's
* bottom
* @param container the container's block when it is a storage chest the module may give the loot of the object
* placed there; empty for any other spot
* @param nativeLootDefined whether the platform already gave the container a loot table of its own
* @param debug whether items should say where they came from ({@link ItemDrop#source()})
*/
record Site(BlockPosition position, Optional<BlockState> container, boolean nativeLootDefined, boolean debug) {
public Site {
Objects.requireNonNull(position, "position");
Objects.requireNonNull(container, "container");
}
}
/** Where a container's items come from. */
sealed interface Source permits Table, PlatformTable {
}
/** A loot table of the pack, by the id {@link com.volmit.resource.PackResources#idOf} gives its key. */
record Table(ResourceId id) implements Source {
public Table {
Objects.requireNonNull(id, "id");
}
}
/**
* A loot table of the platform, such as {@code minecraft:chests/simple_dungeon}. The host draws it with {@code seed}
* so that the same container always gets the same items.
*/
record PlatformTable(String key, long seed) implements Source {
public PlatformTable {
Objects.requireNonNull(key, "key");
}
}
}
@@ -0,0 +1,42 @@
package com.volmit.service;
import com.volmit.resource.ResourceId;
import com.volmit.world.PackWorld;
import java.util.Objects;
import java.util.Set;
/** Which pack objects a module places, predicted without generating anything. The host's object search and its
* studio tools ask every provider and use all the answers together.
*/
@Service(Providers.ALL)
public interface ObjectsAt {
/**
* The ids of the pack objects this module would place in the chunk at {@code chunkX}, {@code chunkZ} (chunk
* coordinates, world X and Z divided by 16), as {@link com.volmit.resource.PackResources#idOf} gives them. It is a
* prediction: it may name an object whose placement the chunk's generation later rejects. Empty when the module
* places nothing there.
*/
Set<ResourceId> objectsAt(PackWorld world, int chunkX, int chunkZ);
/**
* The biomes and regions of {@code world}'s layout whose own settings make this module place the object
* {@code object}. The host finds the areas where the object can appear from these: a biome counts for the areas
* it generates in and, through its children, for the areas of the biomes inside it, so a provider names only the
* layout entries that place the object themselves. Only biomes and regions the dimension can reach are named.
*/
PlacedBy placedBy(PackWorld world, ResourceId object);
/** Layout entries that place an object, by their pack ids. */
record PlacedBy(Set<ResourceId> biomes, Set<ResourceId> regions) {
public static final PlacedBy NOTHING = new PlacedBy(Set.of(), Set.of());
public PlacedBy {
biomes = Set.copyOf(Objects.requireNonNull(biomes, "biomes"));
regions = Set.copyOf(Objects.requireNonNull(regions, "regions"));
}
public boolean isEmpty() {
return biomes.isEmpty() && regions.isEmpty();
}
}
}
@@ -0,0 +1,16 @@
package com.volmit.service;
/** How the host combines the providers of one {@link Service}. A service chooses one; its javadoc says how the host
* uses the answers. Providers are always in module id order, each module's in the order it registered them, so the
* outcome never depends on how modules were discovered.
*/
public enum Providers {
/** The host asks every provider and combines their answers, such as the objects each module places in a chunk. */
ALL,
/** The host asks the providers in order until one answers, such as the module that knows a structure key. A provider
* that has no answer says so in the service's own terms (an empty result) and the next one is asked.
*/
FIRST,
/** A pack has at most one provider. A second module registering one fails the pack load, naming both modules. */
ONE
}
@@ -0,0 +1,82 @@
package com.volmit.service;
import com.volmit.block.BlockState;
import com.volmit.placement.PlacedBlock;
import com.volmit.resource.ResourceId;
import com.volmit.world.BlockPosition;
import com.volmit.world.PackWorld;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
/**
* Trees a module grows when a sapling or mushroom grows in a world generated with the pack, and which objects it
* counts as trees. The host asks every provider in order when something grows and uses the first {@link Growth}; no
* answer leaves the growth to the platform. The module decides what grows and the blocks it consists of; the host
* clears the sapling, places the blocks on the right thread and tells listeners.
*/
@Service(Providers.ALL)
public interface SaplingGrowth {
/**
* The tree that replaces the growth at {@code sapling}, or empty to leave it to the platform. Reads the world around
* the sapling through {@code surroundings}, which is only valid during the call and sees the saplings that are
* growing as air.
*/
Optional<Growth> grow(PackWorld world, Sapling sapling, Surroundings surroundings);
/** The objects of the pack this module places as trees, for tools that tell trees from other objects. */
TreeObjects treeObjects(PackWorld world);
/**
* What grows.
*
* @param at where the growth happened: world X and Z, Y the height above the dimension's bottom
* @param center the middle of the plane of saplings that grow together, the same way
* @param species the platform's name for the kind of tree that would grow, such as {@code TREE} or {@code JUNGLE}
*/
record Sapling(BlockPosition at, BlockPosition center, String species) {
public Sapling {
Objects.requireNonNull(at, "at");
Objects.requireNonNull(center, "center");
Objects.requireNonNull(species, "species");
}
}
/** The world around a growing sapling, read where the tree is placed. X and Z are world coordinates, Y the height above the dimension's bottom. */
interface Surroundings {
/** The height of the topmost block at the column, ignoring fluids when {@code ignoreFluid}. */
int highest(int x, int z, boolean ignoreFluid);
BlockState blockAt(int x, int y, int z);
}
/**
* The tree to place.
*
* @param object the id of the object the tree comes from, as {@link com.volmit.resource.PackResources#idOf} gives it
* for the object's key
* @param blocks the blocks to place, in order, later ones over earlier ones
*/
record Growth(ResourceId object, List<PlacedBlock> blocks) {
public Growth {
Objects.requireNonNull(object, "object");
blocks = List.copyOf(blocks);
}
}
/**
* Objects a module places as trees, by the ids {@link com.volmit.resource.PackResources#idOf} gives their keys.
*
* @param objects pack objects its placements mark as trees
* @param procedural the objects its procedural trees generate, one per variant
*/
record TreeObjects(Set<ResourceId> objects, Set<ResourceId> procedural) {
public static final TreeObjects NONE = new TreeObjects(Set.of(), Set.of());
public TreeObjects {
objects = Set.copyOf(objects);
procedural = Set.copyOf(procedural);
}
}
}
@@ -0,0 +1,25 @@
package com.volmit.service;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/** Marks an interface as a service: a capability modules provide and the host looks up, such as finding a module's
* structures, instead of knowing the feature behind it. Modules register providers with
* {@link com.volmit.FeatureRegistry#registerService}; the host gets them from the pack's catalog.
*
* <p>Providers hold no state of their own: a provider is shared by every world, and the host may call it from any
* thread, also from several at once. A provider keeps what it needs in the world's state store
* ({@link com.volmit.world.PackWorld#state}), which is why service methods take the world. Services compute answers;
* they never act on the platform themselves: what should happen in the world comes back as a value the host carries out
* on the right thread.
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Service {
/** How the host treats several modules providing this service. */
Providers value();
}
@@ -0,0 +1,40 @@
package com.volmit.service;
import com.volmit.resource.PackResources;
import com.volmit.resource.ResourceId;
import com.volmit.world.PackWorld;
import java.util.Set;
/** Finds the structures a module places, for the host's structure commands and index. Structures are named by their
* ids: a pack's own structure by the id {@link PackResources#idOf} gives its key ({@code overworld:villages/plains}),
* a platform structure by the platform's id ({@code minecraft:ancient_city}). The host asks the providers in order and
* sends an id to the first that places it in the world ({@link #placed}).
*/
@Service(Providers.FIRST)
public interface StructureLocator {
/** Every structure of the pack this module knows, placed in a world or not, such as one per structure file. The
* host lists them in its index of the structures a pack has.
*/
Set<ResourceId> structures(PackResources pack);
/** The structures this module places in {@code world} and can find with {@link #locate}: commands offer them and
* send a search for one of them here. A structure no placement of the world uses is not among them.
*/
Set<ResourceId> locatable(PackWorld world);
/** The structures {@link #locate} finds among those 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. Commands
* report them and send a search for one of them here. By default the {@link #locatable} ones.
*/
default Set<ResourceId> placed(PackWorld world) {
return locatable(world);
}
/**
* The start of {@code structure} 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 an id from {@link #placed}. May take long; the
* host calls it off the server's main thread.
*/
LocateResult locate(PackWorld world, ResourceId structure, int fromX, int fromZ, int maxRadiusChunks);
}
@@ -0,0 +1,38 @@
package com.volmit.service;
import com.volmit.resource.ResourceId;
import com.volmit.vanilla.DecorationStep;
import com.volmit.world.PackWorld;
import java.util.Optional;
/**
* A module's say over the platform's own placed features in the pack's worlds: the ores, trees, plants, springs and other
* decorations Minecraft, data packs and mods declare for a biome. By default the platform runs none of them over the pack's
* terrain. The host asks every provider, in module id order: it runs the platform's feature pass in a world when any
* provider turns it on with {@link #generates}, and then skips a decoration step or a feature that any provider refuses.
*
* <p>Every answer is decided from the world alone (its settings and resources), never from a position: the host asks once
* per world, and once per world and step or feature, and keeps the answer while the world runs. Every method may be
* called from any thread, concurrently.
*/
@Service(Providers.ALL)
public interface VanillaFeatures {
/** Whether the platform runs its placed features over the terrain of {@code world}. False when the module has no part in it. */
default boolean generates(PackWorld world) {
return false;
}
/**
* Whether the platform places the features of decoration step {@code step} in {@code world}: empty for a step of a newer
* platform the API does not know yet. True when the module has no part in it.
*/
default boolean generatesStep(PackWorld world, Optional<DecorationStep> step) {
return true;
}
/** Whether the platform places the feature {@code feature}, such as {@code minecraft:ore_diamond}, in {@code world}. True when the module has no part in it. */
default boolean generatesFeature(PackWorld world, ResourceId feature) {
return true;
}
}
@@ -0,0 +1,129 @@
package com.volmit.service;
import com.volmit.resource.ResourceId;
import com.volmit.vanilla.PlatformStart;
import com.volmit.vanilla.StartMemo;
import com.volmit.vanilla.StartReach;
import com.volmit.vanilla.StructureFit;
import com.volmit.vanilla.VanillaStructureContext;
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:
*
* <ul>
* <li>{@link #rule} before the platform starts one of its structures, and when it locates one;</li>
* <li>{@link #starts} for every chunk, for the starts modules place where the platform would not;</li>
* <li>{@link #shift} before it publishes a start the platform made itself, and {@link #reach} before it publishes any
* start;</li>
* <li>{@link #beforePieces} and {@link #afterPieces} around the platform placing the starts' pieces in a chunk;</li>
* <li>{@link #setup} before a world of the dimension exists, when the platform sets up its structures and when the
* host installs data packs.</li>
* </ul>
*
* <p>The host asks {@link #rule} once per world, structure and pack snapshot and keeps the answer, so a rule is decided
* from the pack (its settings and resources) and never from where a start would be. Rules combine with
* {@link VanillaStructureRule#and}: any module may block the platform's starts. Shifts add up; reaches are all covered;
* setups combine with {@link VanillaStructureSetup#and}. Every method may be called from any thread, concurrently, but
* one chunk's {@link StructureFit} is used on one thread.
*/
@Service(Providers.ALL)
public interface VanillaStructures {
/** What this module wants for the platform structure {@code structure}, such as {@code minecraft:village_plains},
* in the world {@code context} describes. {@link VanillaStructureRule#GENERATE} when the module has no part in it.
*/
default VanillaStructureRule rule(ResourceId structure, VanillaStructureContext context) {
return VanillaStructureRule.GENERATE;
}
/** The platform structures this module starts in chunk {@code chunkX, chunkZ}: starts the platform generates from
* that chunk, wherever its own placement rules would put them. At most one start per structure and chunk counts;
* the host keeps the first, in module id order. Decided from the world and the chunk only, so the same chunk always
* gets the same starts: the host asks again when it locates structures and when it checks a start it finds in
* the world.
*/
default List<VanillaStructureStart> starts(int chunkX, int chunkZ, VanillaStructureStartContext context) {
return List.of();
}
/** How many blocks the platform's own start {@code start} moves up (negative: down) before the host publishes it.
* Decided from the start's place and the terrain only, so asking again for the same start gives the same answer:
* the host asks again when it predicts where the platform's starts end up. The host keeps the start inside the
* world, moving it less when it would leave it. 0 when the module has no part in it.
*/
default int shift(PlatformStart start, VanillaStructureContext context) {
return 0;
}
/** How far around its pieces this module changes the terrain for a start of {@code structure}: a start the module
* placed itself, with the {@code memo} it gave it, or one of the platform's own starts (no memo; {@code underground}
* says whether the platform generates the structure in one of its underground steps). The platform hands the start to
* every chunk the reach covers, so {@link #beforePieces} sees it there. {@link StartReach#PLATFORM} when the module
* changes no more than the platform's own terrain adaptation would.
*/
default StartReach reach(ResourceId structure, boolean underground, Optional<StartMemo> memo,
VanillaStructureContext context) {
return StartReach.PLATFORM;
}
/** Called once per chunk before the platform places any piece of {@code fit}'s starts there: the module fits the
* terrain to the starts it cares about, writing only inside {@link StructureFit#area()}.
*/
default void beforePieces(StructureFit fit) {
}
/** Called after the platform placed the pieces of {@code placed}, one of {@code fit}'s starts, in the chunk, before
* it places the next start's; the last call of a chunk is for the last of {@link StructureFit#starts()}.
*/
default void afterPieces(StructureFit fit, StructureFit.Start placed) {
}
/** What this module changes about how the platform sets up its structures for the dimension {@code context}
* describes. Protecting the platform's definitions in one dimension protects them in every data pack the host
* installs, since those are shared by every world. {@link VanillaStructureSetup#UNCHANGED} when the module has no
* part in it.
*/
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);
}
}