Merge branch 'wave2/d'

This commit is contained in:
piexel committed 2026-10-09 22:33:28 +02:00
commit de35bbedb6
17 files changed
+653 -10

No files matched your search

@@ -0,0 +1,86 @@
package com.volmit.entity;
import com.volmit.item.ItemAttribute;
import com.volmit.item.ItemDrop;
import java.util.List;
import java.util.Objects;
/**
* An entity a module decided to spawn, with every random choice made: the host creates it on the platform and applies
* what is set. Names are as authored in the pack, with {@code &} colour codes.
*
* @param type the entity type's key, such as {@code minecraft:zombie}; ignored when {@code specialType} is set
* @param specialType a mob of another plugin, written {@code PluginName:MobName}, or empty
* @param reason the platform's spawn reason by name, or null for a natural spawn
* @param customName the name shown above the entity, empty for none
* @param flags the settings that every entity kind understands
* @param equipment what the entity wears and holds
* @param passengers entities that ride this one
* @param attributes attribute modifiers to apply
* @param lootTables keys of loot tables the entity drops, instead of the platform's drops, when it dies
* @param lootShuffleSeed seeds how the drops of {@code lootTables} are shuffled
* @param leashHolder the entity that holds this one on a leash, or null
* @param spawnEffect an effect to show when the entity appears, or null
* @param riseOutOfGround whether the entity slowly climbs out of the ground when players are near
* @param pandaMainGene for pandas the main gene by name, or null
* @param pandaHiddenGene for pandas the hidden gene by name, or null
* @param applySettingsToSpecial whether the settings also apply to a mob of another plugin
* @param commands console commands to run where the entity appears
*/
public record EntitySpec(String type, String specialType, String reason, String customName, Flags flags, Equipment equipment,
List<EntitySpec> passengers, List<ItemAttribute> attributes, List<String> lootTables,
long lootShuffleSeed, EntitySpec leashHolder, SpawnEffect spawnEffect, boolean riseOutOfGround,
String pandaMainGene, String pandaHiddenGene, boolean applySettingsToSpecial,
List<Command> commands) {
public EntitySpec {
Objects.requireNonNull(type, "type");
Objects.requireNonNull(specialType, "specialType");
Objects.requireNonNull(customName, "customName");
Objects.requireNonNull(flags, "flags");
Objects.requireNonNull(equipment, "equipment");
passengers = List.copyOf(passengers);
attributes = List.copyOf(attributes);
lootTables = List.copyOf(lootTables);
commands = List.copyOf(commands);
}
/** Whether the entity is a mob of another plugin. */
public boolean isSpecial() {
return !specialType.isEmpty();
}
/** What an entity can be set to be, whatever its kind; the host applies the ones its kind has. */
public record Flags(boolean customNameVisible, boolean aware, boolean ai, boolean glowing, boolean gravity,
boolean invulnerable, boolean silent, boolean pickupItems, boolean removable,
boolean keepEntity, boolean baby) {
}
/** The items an entity wears and holds; null for an empty slot. */
public record Equipment(ItemDrop helmet, ItemDrop chestplate, ItemDrop leggings, ItemDrop boots, ItemDrop mainHand,
ItemDrop offHand) {
public static final Equipment NONE = new Equipment(null, null, null, null, null, null);
}
/**
* Sound and particles shown around an entity that appears. Offsets and the randomness of the particle motion are
* as in an effect of the pack; the host makes the random choices.
*/
public record SpawnEffect(String sound, int soundDistance, double minPitch, double maxPitch, double volume,
String particle, int particleOffset, int particleCount, double altX, double altY,
double altZ, boolean randomAltX, boolean randomAltY, boolean randomAltZ, double extra) {
}
/**
* Console commands run when an entity appears. {@code {x}}, {@code {y}} and {@code {z}} stand for its block position.
*
* @param commands the commands
* @param delay server ticks to wait before running them
* @param repeat whether to run them again and again until the server stops
* @param repeatDelay server ticks between repeats
*/
public record Command(List<String> commands, long delay, boolean repeat, long repeatDelay) {
public Command {
commands = List.copyOf(commands);
}
}
}
@@ -0,0 +1,18 @@
package com.volmit.item;
import java.util.Objects;
/** An attribute modifier of an {@link ItemDrop} or an entity, with the amount the module decided. The host creates a
* modifier under an id it makes unique from {@code name}, for every equipment slot.
*
* @param attribute the platform attribute's key, such as {@code max_health} or {@code minecraft:armor}
* @param name identifies the modifier among those of one item or entity; not shown to players
* @param operation {@code ADD_NUMBER}, {@code ADD_SCALAR} or {@code MULTIPLY_SCALAR_1}
*/
public record ItemAttribute(String attribute, String name, String operation, double amount) {
public ItemAttribute {
Objects.requireNonNull(attribute, "attribute");
Objects.requireNonNull(name, "name");
Objects.requireNonNull(operation, "operation");
}
}
@@ -0,0 +1,57 @@
package com.volmit.item;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/**
* One stack of items a module decided to give: what a loot entry, a block's drops or an entity's equipment turned into
* after the module made every random choice. The host creates the stack on the platform. Names and lore are as authored
* in the pack, with {@code &} colour codes; the host translates and wraps them.
*
* @param item the item's key as the pack wrote it, see {@link ItemRegistry}
* @param amount how many, at least 1
* @param displayName the item's name, or null to keep the platform's
* @param lore lines of text under the name
* @param enchantments applied in order
* @param attributes attribute modifiers applied in order
* @param unbreakable whether the item never breaks
* @param flags platform item flags to set, by name; names the platform lacks are ignored
* @param customModel custom model number, or null
* @param damage the fraction of the item's durability already used, 0 to 1, or null to leave it undamaged
* @param leatherColor colour of leather armour as {@code #rrggbb}, or null
* @param dyeColor dye colour name, or null
* @param customNbt custom data the platform stores on the item, or empty
* @param source where the item came from, set only when the host asked for it to be shown (debug loot)
*/
public record ItemDrop(String item, int amount, String displayName, List<String> lore, List<ItemEnchantment> enchantments,
List<ItemAttribute> attributes, boolean unbreakable, List<String> flags, Integer customModel,
Double damage, String leatherColor, String dyeColor, Map<String, Object> customNbt, Source source) {
public ItemDrop {
Objects.requireNonNull(item, "item");
if (amount < 1) throw new IllegalArgumentException("Item amount must be at least 1: " + amount);
lore = List.copyOf(lore);
enchantments = List.copyOf(enchantments);
attributes = List.copyOf(attributes);
flags = List.copyOf(flags);
customNbt = customNbt == null ? Map.of() : Collections.unmodifiableMap(new LinkedHashMap<>(customNbt));
}
/** {@code amount} items of kind {@code item} and nothing else. */
public static ItemDrop of(String item, int amount) {
return new ItemDrop(item, amount, null, List.of(), List.of(), List.of(), false, List.of(), null, null, null, null,
Map.of(), null);
}
/**
* Where a shown item came from: the loot table, when it came from one, and the 1-in-N chances it passed.
*
* @param table the table's name, or null for an item that came from no table
* @param tableRarity the table's rarity, 1 in this many
* @param entryRarity the entry's rarity within the table
*/
public record Source(String table, int tableRarity, int entryRarity) {
}
}
@@ -0,0 +1,13 @@
package com.volmit.item;
import java.util.Objects;
/** An enchantment of an {@link ItemDrop}, named by the key the platform's registry knows ({@code sharpness},
* {@code mymod:vorpal}) with the level the module decided.
*/
public record ItemEnchantment(String key, int level) {
public ItemEnchantment {
Objects.requireNonNull(key, "key");
if (level < 1) throw new IllegalArgumentException("Enchantment level must be at least 1: " + level);
}
}
@@ -0,0 +1,15 @@
package com.volmit.item;
import java.util.OptionalInt;
/** What a module may ask the platform about items, so that its decisions follow the item they concern. Item keys are
* written as in packs: {@code diamond_sword}, {@code minecraft:diamond_sword}, or a custom item of a provider such as
* {@code itemsadder:ruby}. Safe for concurrent use.
*/
public interface ItemRegistry {
/**
* The most damage an item of this kind takes before it breaks, 0 for an item that cannot be damaged; empty when no
* item is known by {@code key}.
*/
OptionalInt maxDurability(String key);
}
@@ -1,6 +1,7 @@
package com.volmit.resource;
import com.volmit.block.BlockRegistry;
import com.volmit.item.ItemRegistry;
import com.volmit.noise.NoiseFactory;
import java.util.List;
import java.util.NoSuchElementException;
@@ -21,6 +22,9 @@ public interface PackResources {
UUID snapshotId();
BlockRegistry blocks();
/** Asks the platform about items, such as how much damage one takes. */
ItemRegistry items();
/** Builds the noise of the {@link com.volmit.noise.NoiseStyle}s the pack's settings describe. */
NoiseFactory noise();
@@ -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,126 @@
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 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 entity of the pack named {@code key} as this module would spawn it, for tools that spawn one on request; empty for an unknown key. */
Optional<EntitySpec> entity(PackWorld world, String key);
/** 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 key of the 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, String 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 keys of the 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<String> spawners, boolean emptyAbove, boolean removeOnChange) {
public MarkerRule {
spawners = List.copyOf(spawners);
}
}
/**
* Entities to spawn, tried one after the other.
*
* @param spawner the key of the 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(String 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,64 @@
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;
/**
* 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 table {@code key} gives at {@code site}; empty for a table this module does not know. */
List<ItemDrop> items(PackWorld world, Site site, String key);
/**
* 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, null 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, BlockState container, boolean nativeLootDefined, boolean debug) {
public Site {
Objects.requireNonNull(position, "position");
}
}
/** Where a container's items come from. */
sealed interface Source permits Table, PlatformTable {
}
/** A loot table of the pack, named by its key as packs write it ({@code dungeon/chest}). */
record Table(String key) implements Source {
public Table {
Objects.requireNonNull(key, "key");
}
}
/**
* 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");
}
}
}
@@ -1,10 +1,11 @@
package com.volmit.service;
import com.volmit.world.PackWorld;
import java.util.Objects;
import java.util.Set;
/** Which pack objects a module places in a chunk, predicted without generating it. The host's object search and its
* studio tools ask every provider and use all the keys together.
/** 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 {
@@ -15,4 +16,26 @@ public interface ObjectsAt {
* there.
*/
Set<String> 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 objectKey}. 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, String objectKey);
/** Layout entries that place an object, named by the keys packs write ({@code land/plains}, {@code temperate}). */
record PlacedBy(Set<String> biomes, Set<String> 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,80 @@
package com.volmit.service;
import com.volmit.block.BlockState;
import com.volmit.placement.PlacedBlock;
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 pack object key the tree comes from, in the form packs write it
* @param blocks the blocks to place, in order, later ones over earlier ones
*/
record Growth(String object, List<PlacedBlock> blocks) {
public Growth {
Objects.requireNonNull(object, "object");
blocks = List.copyOf(blocks);
}
}
/**
* Object keys a module places as trees.
*
* @param objects pack objects its placements mark as trees
* @param procedural the keys of the objects its procedural trees generate, one per variant
*/
record TreeObjects(Set<String> objects, Set<String> procedural) {
public static final TreeObjects NONE = new TreeObjects(Set.of(), Set.of());
public TreeObjects {
objects = Set.copyOf(objects);
procedural = Set.copyOf(procedural);
}
}
}