mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 08:44:50 +00:00
Close the object-placement couplings of the tooling audit
PlacementRun carries the placement's display name and its JSON, from which the host reads the settings other modules declare at the placement level. FeatureRegistry.registerPlacementType lets the module that owns placements declare the type and its JSON names for the placement level. RunningWorld and PlacementTerrain keep a typed PlacementRecord (object id, placement id, optional structure id) instead of a text. Loot gives the seed a container is shuffled with, the ProtectedFloor service says whether the lowest layer belongs to the terrain module, and EntitySpec holds the spawn reason, rising out of the ground, panda genes and applying to a provided mob.
This commit is contained in:
1 parent
0347e106c3
commit
a9e3cbaa93
18 files changed
+355
-50
No files matched your search
@@ -8,6 +8,7 @@ import com.volmit.resource.ResourceKind;
|
||||
import com.volmit.service.Service;
|
||||
import com.volmit.stage.StageGraph;
|
||||
import com.volmit.validation.Validator;
|
||||
import java.util.Set;
|
||||
|
||||
/** Host implementation collects non-stage registrations before loading pack configuration.
|
||||
* Feature IDs must be unique. JSON keys must be unique per {@link com.volmit.config.Level}, including the
|
||||
@@ -41,6 +42,15 @@ public interface FeatureRegistry {
|
||||
*/
|
||||
<T> void registerResourceKind(ResourceKind<T> kind);
|
||||
|
||||
/**
|
||||
* Declares the type packs write their object placements as, the JSON object that holds
|
||||
* {@link com.volmit.config.Level#PLACEMENT}: settings other modules declare on a placement are keys of that same
|
||||
* object, next to the type's own fields. So no settings key at that level may be one of {@code jsonFields}, the
|
||||
* names the type's JSON uses, and studio describes {@code type} with those settings added. A pack has one placement
|
||||
* type; a second declaration, from this module or another, fails the pack load naming both.
|
||||
*/
|
||||
void registerPlacementType(Class<?> type, Set<String> jsonFields);
|
||||
|
||||
/** Adds a check the host runs over the whole pack wherever it validates packs. */
|
||||
void registerValidator(Validator validator);
|
||||
|
||||
|
||||
@@ -21,10 +21,13 @@ import java.util.Optional;
|
||||
* @param company the entities that come with it
|
||||
* @param drops what it drops when it dies
|
||||
* @param arrival what happens where it appears
|
||||
* @param adjustsProvidedMob whether the rest of the spec also applies to a {@link ContentKey.Provided} mob, which is
|
||||
* otherwise left as its provider set it up
|
||||
* @param extensions values for a particular host, which other hosts ignore; see {@link #extension}
|
||||
*/
|
||||
public record EntitySpec(ContentKey type, Appearance appearance, Behaviour behaviour, Equipment equipment,
|
||||
List<ItemAttribute> attributes, Company company, Drops drops, Arrival arrival, List<Object> extensions) {
|
||||
List<ItemAttribute> attributes, Company company, Drops drops, Arrival arrival,
|
||||
boolean adjustsProvidedMob, List<Object> extensions) {
|
||||
public EntitySpec {
|
||||
Objects.requireNonNull(type, "type");
|
||||
Objects.requireNonNull(appearance, "appearance");
|
||||
@@ -45,14 +48,20 @@ public record EntitySpec(ContentKey type, Appearance appearance, Behaviour behav
|
||||
/**
|
||||
* How the entity looks.
|
||||
*
|
||||
* @param customName the name shown above the entity, as authored in the pack with {@code &} colour codes; empty for none
|
||||
* @param nameVisible whether the name shows even when nobody looks at the entity
|
||||
* @param customName the name shown above the entity, as authored in the pack with {@code &} colour codes; empty for none
|
||||
* @param nameVisible whether the name shows even when nobody looks at the entity
|
||||
* @param pandaMainGene for a panda, its main gene by the platform's name for it; empty to leave it to the platform
|
||||
* @param pandaHiddenGene for a panda, its hidden gene by the platform's name for it; empty to leave it to the platform
|
||||
*/
|
||||
public record Appearance(Optional<String> customName, boolean nameVisible, boolean glowing, boolean baby) {
|
||||
public static final Appearance PLAIN = new Appearance(Optional.empty(), false, false, false);
|
||||
public record Appearance(Optional<String> customName, boolean nameVisible, boolean glowing, boolean baby,
|
||||
Optional<String> pandaMainGene, Optional<String> pandaHiddenGene) {
|
||||
public static final Appearance PLAIN = new Appearance(Optional.empty(), false, false, false, Optional.empty(),
|
||||
Optional.empty());
|
||||
|
||||
public Appearance {
|
||||
Objects.requireNonNull(customName, "customName");
|
||||
Objects.requireNonNull(pandaMainGene, "pandaMainGene");
|
||||
Objects.requireNonNull(pandaHiddenGene, "pandaHiddenGene");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,15 +126,20 @@ public record EntitySpec(ContentKey type, Appearance appearance, Behaviour behav
|
||||
/**
|
||||
* What happens where the entity appears.
|
||||
*
|
||||
* @param effect an effect to show; empty for none
|
||||
* @param commands console commands to run
|
||||
* @param effect an effect to show; empty for none
|
||||
* @param commands console commands to run
|
||||
* @param reason why the entity appears, by the platform's name for the reason, such as {@code COMMAND}; empty
|
||||
* for a natural spawn
|
||||
* @param risesFromGround whether the entity slowly climbs out of the ground when players are near
|
||||
*/
|
||||
public record Arrival(Optional<SpawnEffect> effect, List<Command> commands) {
|
||||
public static final Arrival QUIET = new Arrival(Optional.empty(), List.of());
|
||||
public record Arrival(Optional<SpawnEffect> effect, List<Command> commands, Optional<String> reason,
|
||||
boolean risesFromGround) {
|
||||
public static final Arrival QUIET = new Arrival(Optional.empty(), List.of(), Optional.empty(), false);
|
||||
|
||||
public Arrival {
|
||||
Objects.requireNonNull(effect, "effect");
|
||||
commands = List.copyOf(commands);
|
||||
Objects.requireNonNull(reason, "reason");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.volmit.placement;
|
||||
|
||||
import com.volmit.resource.ResourceId;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* What a module recorded beside a block when it placed an object there ({@link PlacementTerrain#recordPlacement}), and
|
||||
* what later placements and services read back ({@link PlacementTerrain#placementAt},
|
||||
* {@link com.volmit.world.RunningWorld#placementAt}): which object stands there, which placement of it that was and, for a
|
||||
* piece of a structure, which structure.
|
||||
*
|
||||
* @param object the pack object, or the name the module gave an object it made itself, as an id
|
||||
* @param placementId the number the placing module gave this placement, which tells it apart from other placements of the
|
||||
* same object; the module picks it, the host keeps it as it is
|
||||
* @param structure the structure the object is a piece of; empty for an object placed on its own
|
||||
*/
|
||||
public record PlacementRecord(ResourceId object, int placementId, Optional<ResourceId> structure) {
|
||||
public PlacementRecord {
|
||||
Objects.requireNonNull(object, "object");
|
||||
Objects.requireNonNull(structure, "structure");
|
||||
}
|
||||
|
||||
/** An object placed on its own. */
|
||||
public static PlacementRecord of(ResourceId object, int placementId) {
|
||||
return new PlacementRecord(object, placementId, Optional.empty());
|
||||
}
|
||||
|
||||
/** A piece of {@code structure}. */
|
||||
public static PlacementRecord ofPiece(ResourceId object, int placementId, ResourceId structure) {
|
||||
return new PlacementRecord(object, placementId, Optional.of(structure));
|
||||
}
|
||||
}
|
||||
@@ -3,22 +3,32 @@ package com.volmit.placement;
|
||||
import com.volmit.geometry.BlockBox;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* One object a module asks the host to place through the pack's placement stages ({@link Placements#place}).
|
||||
*
|
||||
* @param request the object and where it goes
|
||||
* @param area the blocks the object may reach around its anchor in any way it is placed; the host widens it by the
|
||||
* reach the pack's placement stages declare, and the result bounds the placement's {@link PlacementAccess}.
|
||||
* Reaching outside fails the placement
|
||||
* @param terrain the world the placement reads, and where the host writes the blocks when the placement commits
|
||||
* @param input what the placing module hands its own stages, such as its placement settings; stages read it with
|
||||
* {@link PlacementContext#input}, and stages of other modules do not know its type
|
||||
* @param seed the seed the stages' random streams derive from; the same seed, stages and inputs give the same placement
|
||||
* @param request the object and where it goes
|
||||
* @param name the placement's display name, such as the object's key: it labels the placement in the host's logs and
|
||||
* names the source of the settings the pack declares on it
|
||||
* @param settings the placement as the pack wrote it, a JSON object, from which the host reads the settings that pack
|
||||
* modules declare at {@link com.volmit.config.Level#PLACEMENT} so that stages see them like any other
|
||||
* level's; the placement type's own fields ({@link com.volmit.FeatureRegistry#registerPlacementType}) are
|
||||
* not settings and are ignored. Empty for a placement the pack did not write. Equal text is read once
|
||||
* @param area the blocks the object may reach around its anchor in any way it is placed; the host widens it by the
|
||||
* reach the pack's placement stages declare, and the result bounds the placement's {@link PlacementAccess}.
|
||||
* Reaching outside fails the placement
|
||||
* @param terrain the world the placement reads, and where the host writes the blocks when the placement commits
|
||||
* @param input what the placing module hands its own stages, such as its placement settings; stages read it with
|
||||
* {@link PlacementContext#input}, and stages of other modules do not know its type
|
||||
* @param seed the seed the stages' random streams derive from; the same seed, stages and inputs give the same placement
|
||||
*/
|
||||
public record PlacementRun(PlacementRequest request, BlockBox area, PlacementTerrain terrain, Object input, long seed) {
|
||||
public record PlacementRun(PlacementRequest request, String name, Optional<String> settings, BlockBox area,
|
||||
PlacementTerrain terrain, Object input, long seed) {
|
||||
public PlacementRun {
|
||||
Objects.requireNonNull(request, "request");
|
||||
Objects.requireNonNull(name, "name");
|
||||
Objects.requireNonNull(settings, "settings");
|
||||
Objects.requireNonNull(area, "area");
|
||||
Objects.requireNonNull(terrain, "terrain");
|
||||
Objects.requireNonNull(input, "input");
|
||||
|
||||
@@ -43,13 +43,13 @@ public interface PlacementTerrain {
|
||||
boolean preventsDecay();
|
||||
|
||||
/**
|
||||
* Records that the block belongs to {@code placement}, the name the placing module gives one placed object, so a
|
||||
* later placement can tell what is already there ({@link #placementAt}). The host keeps the name as it is.
|
||||
* Records that the block belongs to {@code placement}, one placed object, so a later placement can tell what is
|
||||
* already there ({@link #placementAt}). The host keeps the record beside the block in its generation storage.
|
||||
*/
|
||||
void recordPlacement(int x, int y, int z, String placement);
|
||||
void recordPlacement(int x, int y, int z, PlacementRecord placement);
|
||||
|
||||
/** The placement recorded at the block ({@link #recordPlacement}); empty when none is. */
|
||||
Optional<String> placementAt(int x, int y, int z);
|
||||
Optional<PlacementRecord> placementAt(int x, int y, int z);
|
||||
|
||||
/** The bounds of the platform's structure pieces planned around the columns, for placements that keep out of them. */
|
||||
StructureVolumes structureVolumes(int minX, int minZ, int maxX, int maxZ);
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.volmit.world.PackWorld;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.OptionalLong;
|
||||
|
||||
/**
|
||||
* The loot a module gives containers and mobs. The host asks in two steps so that it, and plugins listening to it, can
|
||||
@@ -27,6 +28,16 @@ public interface Loot {
|
||||
/** 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);
|
||||
|
||||
/**
|
||||
* The seed the host shuffles the slots of the container at {@code site} with after it filled it, so that the same
|
||||
* container always ends up with its items in the same slots. Empty to leave the order to the host's other providers;
|
||||
* the host uses the first seed it gets, in module id order, and keeps the items in the order of the tables when no
|
||||
* provider gives one.
|
||||
*/
|
||||
default OptionalLong shuffleSeed(PackWorld world, Site site) {
|
||||
return OptionalLong.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Where loot is given.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.volmit.service;
|
||||
|
||||
import com.volmit.world.PackWorld;
|
||||
|
||||
/**
|
||||
* Whether the lowest layer of the world, the blocks at height 0, belongs to the module that shapes the terrain, such as
|
||||
* a bedrock floor it writes itself. When it does, the host discards the blocks that placements and other stages write
|
||||
* there, so that nothing replaces the floor. A pack has one provider, since two modules could not both own the floor.
|
||||
* Without a provider the host protects nothing.
|
||||
*/
|
||||
@Service(Providers.ONE)
|
||||
public interface ProtectedFloor {
|
||||
/**
|
||||
* Whether the host discards blocks written at height 0 of {@code world}. The answer depends on the world and its
|
||||
* settings only: the host asks once when it starts the world and keeps it while the world runs.
|
||||
*/
|
||||
boolean protectsFloor(PackWorld world);
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package com.volmit.world;
|
||||
|
||||
import com.volmit.config.FeatureSettings;
|
||||
import com.volmit.geometry.BlockPosition;
|
||||
import com.volmit.placement.PlacementRecord;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@@ -39,7 +40,7 @@ public interface RunningWorld {
|
||||
* ({@link com.volmit.placement.PlacementTerrain#recordPlacement}); empty when none was, or when the block's chunk
|
||||
* keeps no generation data any more. Y is the height above the dimension's bottom.
|
||||
*/
|
||||
Optional<String> placementAt(int worldX, int y, int worldZ);
|
||||
Optional<PlacementRecord> placementAt(int worldX, int y, int worldZ);
|
||||
|
||||
/** The time and weather of the world; empty while the platform has not loaded the world. */
|
||||
Optional<Sky> sky();
|
||||
|
||||
Reference in new issue
Block a user