mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 00:04:42 +00:00
Batch 6 part 3: structure locating, decoding contract, minor cuts
Finding 45: StructureLocator is the one locating service (startedStructures, locatableStarts, locateStart, ChunkFilter moved from VanillaStructures). StartMemo is one opaque non-empty text. VanillaStructureStart.identity is deleted; the host only stored it. useExpansionHack and legacyAir stay: both mirror platform structure behaviour any structure module needs. Finding 46: DESIGN.md documents one decoding contract (fields read by name, absent or null members keep the initialiser, unknown enum names are errors, the host never writes null). Value type getters stop null-guarding. NoiseStyle.cacheSize is deleted. @Desc texts rewritten. multiplier stays on NoiseStyle: it is also an object placement's warp strength. Finding 47: LinkedBiomes moves to world and takes the dimension's settings as PackSettings. Optional packages move from ModuleInfo to the jar manifest (Iris-Optional-Packages); PackageName moves into the host. PlacementRequest.id is dropped (nothing read it).
This commit is contained in:
1 parent
6b24e6f150
commit
1bc91df048
30 files changed
+308
-314
No files matched your search
@@ -1,8 +1,6 @@
|
||||
package com.volmit;
|
||||
|
||||
import com.volmit.resource.ResourceId;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/** Module identity. Every stage a module defines has an id that starts with the module id and
|
||||
@@ -13,12 +11,10 @@ import java.util.Objects;
|
||||
* people, for example in load logs; the id is what the host and other modules match on. Name and
|
||||
* version must fit on one log line, so they reject control characters such as line breaks.
|
||||
*
|
||||
* <p>Optional packages are packages, with their subpackages, whose classes the module's jar uses
|
||||
* but expects may be absent at runtime, typically optional integrations of a library it bundles.
|
||||
* The pack load does not warn about missing classes in them. They never excuse a class that Iris
|
||||
* hides from modules or one missing from a package Iris exposes; those still fail the load.
|
||||
* <p>What the module's jar needs at load, such as packages it expects may be missing, is the jar's, declared in its
|
||||
* manifest (see README, "Optional packages"), not the module's identity.
|
||||
*/
|
||||
public record ModuleInfo(ResourceId id, String name, String version, List<PackageName> optionalPackages) {
|
||||
public record ModuleInfo(ResourceId id, String name, String version) {
|
||||
private static final String STAGE_SEPARATOR = "/";
|
||||
|
||||
public ModuleInfo {
|
||||
@@ -28,26 +24,10 @@ public record ModuleInfo(ResourceId id, String name, String version, List<Packag
|
||||
requireSingleSegment(id);
|
||||
requireOneLineText(id, "name", name);
|
||||
requireOneLineText(id, "version", version);
|
||||
optionalPackages = List.copyOf(optionalPackages);
|
||||
}
|
||||
|
||||
public static ModuleInfo of(String id, String name, String version) {
|
||||
return new ModuleInfo(ResourceId.parse(id), name, version, List.of());
|
||||
}
|
||||
|
||||
/** This identity with {@code packages} as its optional packages, replacing any declared before.
|
||||
* A trailing dot is accepted; anything that is not a package name, such as a wildcard, is rejected.
|
||||
*/
|
||||
public ModuleInfo withOptionalPackages(String... packages) {
|
||||
var parsed = Arrays.stream(packages).map(this::requireOptionalPackage).toList();
|
||||
return new ModuleInfo(id, name, version, parsed);
|
||||
}
|
||||
|
||||
private PackageName requireOptionalPackage(String packageName) {
|
||||
Objects.requireNonNull(packageName, "optional package");
|
||||
return PackageName.tryParse(packageName).orElseThrow(() -> new IllegalArgumentException("Optional package '"
|
||||
+ packageName + "' of module " + id + " is not a package name; name a package such as org.slf4j,"
|
||||
+ " which covers that package and its subpackages"));
|
||||
return new ModuleInfo(ResourceId.parse(id), name, version);
|
||||
}
|
||||
|
||||
/** Whether {@code stageId} may name a stage of this module: it starts with this module's id and '/'. */
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
package com.volmit;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
/** A Java package name that stands for the package and all its subpackages. Only whole package
|
||||
* names match: {@code com.volmit} contains {@code com.volmit.stage.Stage} but not
|
||||
* {@code com.volmitx.Fake}.
|
||||
*/
|
||||
public record PackageName(String name) implements Comparable<PackageName> {
|
||||
private static final char SEPARATOR = '.';
|
||||
private static final String SEPARATOR_PATTERN = "\\.";
|
||||
|
||||
public PackageName {
|
||||
Objects.requireNonNull(name, "name");
|
||||
if (!isPackageName(name)) throw new IllegalArgumentException("'" + name + "' is not a package name");
|
||||
}
|
||||
|
||||
/** The package {@code name} denotes, if it is a package name. A trailing dot is accepted; blank
|
||||
* names, wildcards and anything else that is not a package name give an empty result.
|
||||
*/
|
||||
public static Optional<PackageName> tryParse(String name) {
|
||||
Objects.requireNonNull(name, "name");
|
||||
var withoutTrailingDot = name.endsWith(String.valueOf(SEPARATOR)) ? name.substring(0, name.length() - 1) : name;
|
||||
return isPackageName(withoutTrailingDot) ? Optional.of(new PackageName(withoutTrailingDot)) : Optional.empty();
|
||||
}
|
||||
|
||||
/** Whether the class with this binary name is in this package or one of its subpackages. */
|
||||
public boolean contains(String binaryName) {
|
||||
return binaryName.startsWith(name)
|
||||
&& binaryName.length() > name.length()
|
||||
&& binaryName.charAt(name.length()) == SEPARATOR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() { return name; }
|
||||
|
||||
@Override
|
||||
public int compareTo(PackageName other) { return name.compareTo(other.name); }
|
||||
|
||||
private static boolean isPackageName(String name) {
|
||||
return Arrays.stream(name.split(SEPARATOR_PATTERN, -1)).allMatch(PackageName::isIdentifier);
|
||||
}
|
||||
|
||||
private static boolean isIdentifier(String segment) {
|
||||
return !segment.isEmpty()
|
||||
&& Character.isJavaIdentifierStart(segment.codePointAt(0))
|
||||
&& segment.codePoints().skip(1).allMatch(Character::isJavaIdentifierPart);
|
||||
}
|
||||
}
|
||||
@@ -18,8 +18,8 @@ import java.util.Optional;
|
||||
* the pack's {@code blocks} folder, or a block that only some versions or mods have.
|
||||
*
|
||||
* <p>The host resolves it with {@link BlockRegistry#resolve(BlockSpec)} and its block entity with
|
||||
* {@link BlockRegistry#blockEntity(BlockSpec)}. A spec is a value: the host creates it with the no-argument
|
||||
* constructor and reads the JSON into it, and nothing changes it afterwards. Property values are text however the
|
||||
* {@link BlockRegistry#blockEntity(BlockSpec)}. A spec is a value the host decodes as every settings class (see
|
||||
* DESIGN.md, "Decoding contract"), and nothing changes it afterwards. Property values are text however the
|
||||
* pack writes them, so {@code "waterlogged": true} reads as {@code "true"}.
|
||||
*/
|
||||
@Desc("A block, with optional properties, block entity data and a backup for platforms without it")
|
||||
@@ -31,7 +31,7 @@ public final class BlockSpec {
|
||||
@Desc("The block to use. A key without a namespace is a Minecraft block or a block of the pack's blocks folder.")
|
||||
private String block = AIR;
|
||||
|
||||
@Desc("Optional properties for this block, such as 'waterlogged': true")
|
||||
@Desc("The block's properties, such as \"waterlogged\": true.")
|
||||
private Map<String, String> data = Map.of();
|
||||
|
||||
@MinNumber(1)
|
||||
@@ -39,10 +39,10 @@ public final class BlockSpec {
|
||||
@Desc("The weight of this block in a list it is picked from. A weight of two is as if the block were in the list twice.")
|
||||
private int weight = 1;
|
||||
|
||||
@Desc("If the block cannot be created on this platform, this block is used instead.")
|
||||
@Desc("The block used instead on a platform that does not have this one.")
|
||||
private BlockSpec backup;
|
||||
|
||||
@Desc("Optional block entity data for this block, such as a spawner's SpawnData")
|
||||
@Desc("The block entity data, such as a spawner's SpawnData.")
|
||||
private Map<String, Object> tileData = Map.of();
|
||||
|
||||
private BlockSpec() {
|
||||
@@ -82,12 +82,12 @@ public final class BlockSpec {
|
||||
|
||||
/** The block key as the pack wrote it. */
|
||||
public String block() {
|
||||
return block == null ? AIR : block;
|
||||
return block;
|
||||
}
|
||||
|
||||
/** The properties as the pack wrote them, as text. */
|
||||
public Map<String, String> data() {
|
||||
return data == null ? Map.of() : Collections.unmodifiableMap(data);
|
||||
return Collections.unmodifiableMap(data);
|
||||
}
|
||||
|
||||
public int weight() {
|
||||
@@ -100,7 +100,7 @@ public final class BlockSpec {
|
||||
|
||||
/** The block entity data as the pack wrote it: JSON objects as maps, arrays as lists, numbers as {@code Double}. */
|
||||
public Map<String, Object> tileData() {
|
||||
return tileData == null ? Map.of() : Collections.unmodifiableMap(tileData);
|
||||
return Collections.unmodifiableMap(tileData);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,26 +16,26 @@ import java.util.Objects;
|
||||
* at the position over {@code zoom} selects, each block counting {@link BlockSpec#weight() weight} times.
|
||||
*
|
||||
* <p>A palette is a description, not a picker: the host builds the picker
|
||||
* ({@link BlockRegistry#palette(PaletteSpec, long)}). It is a value the host creates with the no-argument
|
||||
* constructor and reads the JSON into; nothing changes it afterwards.
|
||||
* ({@link BlockRegistry#palette(PaletteSpec, long)}). It is a value the host decodes as every settings class (see
|
||||
* DESIGN.md, "Decoding contract"); nothing changes it afterwards.
|
||||
*/
|
||||
@Snippet("palette")
|
||||
@Desc("A palette of materials")
|
||||
@Desc("Blocks picked by noise, each as often as its weight")
|
||||
public final class PaletteSpec {
|
||||
private static final String DEFAULT_STYLE = "STATIC";
|
||||
private static final double DEFAULT_ZOOM = 5;
|
||||
private static final String DEFAULT_BLOCK = "stone";
|
||||
|
||||
@Desc("The style of noise")
|
||||
@Desc("The noise that picks the block at each position.")
|
||||
private NoiseStyle style = NoiseStyle.of(DEFAULT_STYLE);
|
||||
|
||||
@MinNumber(0.0001)
|
||||
@Desc("The terrain zoom mostly for zooming in on a wispy palette")
|
||||
@Desc("How far the picking noise is stretched: above 1 gives larger patches of one block.")
|
||||
private double zoom = DEFAULT_ZOOM;
|
||||
|
||||
@Required
|
||||
@MinItems(1)
|
||||
@Desc("The palette of blocks to be used in this layer")
|
||||
@Desc("The blocks to pick from.")
|
||||
private List<BlockSpec> palette = List.of(BlockSpec.of(DEFAULT_BLOCK));
|
||||
|
||||
private PaletteSpec() {
|
||||
@@ -63,7 +63,7 @@ public final class PaletteSpec {
|
||||
|
||||
/** The noise that picks the blocks; the default {@code STATIC} style where the pack wrote none. */
|
||||
public NoiseStyle style() {
|
||||
return style == null ? NoiseStyle.of(DEFAULT_STYLE) : style;
|
||||
return style;
|
||||
}
|
||||
|
||||
/** The factor the position is divided by before it is looked up in the noise. */
|
||||
@@ -73,7 +73,7 @@ public final class PaletteSpec {
|
||||
|
||||
/** The blocks to pick from, as the pack wrote them. */
|
||||
public List<BlockSpec> palette() {
|
||||
return palette == null ? List.of() : Collections.unmodifiableList(palette);
|
||||
return Collections.unmodifiableList(palette);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -5,15 +5,15 @@ import java.util.Objects;
|
||||
|
||||
/** A span of numbers from {@code min} to {@code max}, both included, as packs write it: {@code {"min": 0, "max": 15}},
|
||||
* or a snippet under {@code snippet/range/}. An omitted bound keeps its default, so give a settings field its own
|
||||
* default with {@link #of}. A value the host creates with the no-argument constructor and reads the JSON into.
|
||||
* default with {@link #of}. A value the host decodes as every settings class (see DESIGN.md, "Decoding contract").
|
||||
*/
|
||||
@Snippet("range")
|
||||
@Desc("Represents a range")
|
||||
@Desc("A span of numbers from min to max, both included")
|
||||
public final class Range {
|
||||
@Desc("The minimum value")
|
||||
@Desc("The lowest value.")
|
||||
private double min = 16;
|
||||
|
||||
@Desc("The maximum value")
|
||||
@Desc("The highest value.")
|
||||
private double max = 32;
|
||||
|
||||
private Range() {
|
||||
|
||||
@@ -14,10 +14,10 @@ import java.util.Optional;
|
||||
/** How noise is shaped, as packs write it: {@code {"style": "SIMPLEX", "zoom": 4}}, or a snippet under
|
||||
* {@code snippet/style/}. The style names one of the host's noise generators ({@link Reference#NOISE_STYLE}); an
|
||||
* expression or image map of the pack replaces it. A zoom stretches the noise, an exponent bends it, a fracture
|
||||
* style distorts its coordinates and a cellular frequency turns it into cells.
|
||||
* distorts its coordinates and a cellular frequency turns it into cells.
|
||||
*
|
||||
* <p>A style is a description, not noise: the host builds the noise ({@link NoiseFactory#sampler}). It is a value
|
||||
* the host creates with the no-argument constructor and reads the JSON into; nothing changes it afterwards.
|
||||
* the host decodes as every settings class (see DESIGN.md, "Decoding contract"); nothing changes it afterwards.
|
||||
*/
|
||||
@Snippet("style")
|
||||
@Desc("A noise style: one of the host's noise generators, or an expression or image map of the pack, shaped by zoom, exponent, fracture and cells")
|
||||
@@ -26,44 +26,39 @@ public final class NoiseStyle {
|
||||
public static final String FLAT = "FLAT";
|
||||
|
||||
@Ref(Reference.NOISE_STYLE)
|
||||
@Desc("The base noise style. Used when neither expression nor imageMap is set; a failed expression also falls back to this style.")
|
||||
@Desc("The noise generator. Used when neither expression nor imageMap is set, and when an expression fails.")
|
||||
private String style = FLAT;
|
||||
|
||||
@Desc("If set above 0, this style will be cellularized")
|
||||
@Desc("Above 0, the noise is turned into cells of this frequency.")
|
||||
private double cellularFrequency = 0;
|
||||
|
||||
@Desc("Cell zooms")
|
||||
@Desc("How far the cells are stretched.")
|
||||
private double cellularZoom = 1;
|
||||
|
||||
@MinNumber(0.00001)
|
||||
@Desc("The zoom of this style")
|
||||
@Desc("How far the noise is stretched: above 1 wider, below 1 tighter.")
|
||||
private double zoom = 1;
|
||||
|
||||
@Ref(kind = PackExpression.class)
|
||||
@Desc("Instead of using the style property, use a custom expression to represent this style.")
|
||||
@Desc("An expression of the pack that gives the noise instead of the style.")
|
||||
private ResourceId expression;
|
||||
|
||||
@Ref(kind = PackImageMap.class)
|
||||
@Desc("Use an Image map instead of a generated value")
|
||||
@Desc("An image map of the pack that gives the noise instead of the style, when there is no expression.")
|
||||
private ResourceId imageMap;
|
||||
|
||||
@MinNumber(0.00001)
|
||||
@Desc("The Output multiplier. Only used if parent is fracture.")
|
||||
@Desc("When this style moves coordinates, as another style's fracture or as a warp: up to half this many blocks either way.")
|
||||
private double multiplier = 1;
|
||||
|
||||
@Desc("Apply a generator to the coordinate field fed into this parent generator. I.e. Distort your generator with another generator.")
|
||||
@Desc("A style whose noise moves the coordinates this style is sampled at, distorting it.")
|
||||
private NoiseStyle fracture;
|
||||
|
||||
@MinNumber(0.01562)
|
||||
@MaxNumber(64)
|
||||
@Desc("The exponent")
|
||||
@Desc("The power the noise is raised to: above 1 favours low values, below 1 high ones.")
|
||||
private double exponent = 1;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(8192)
|
||||
@Desc("If the cache size is set above 0, this generator will be cached")
|
||||
private int cacheSize = 0;
|
||||
|
||||
private NoiseStyle() {
|
||||
}
|
||||
|
||||
@@ -77,7 +72,6 @@ public final class NoiseStyle {
|
||||
multiplier = copy.multiplier;
|
||||
fracture = copy.fracture;
|
||||
exponent = copy.exponent;
|
||||
cacheSize = copy.cacheSize;
|
||||
}
|
||||
|
||||
/** The host's noise style {@code style}, such as {@code SIMPLEX}, with every other option at its default. */
|
||||
@@ -96,7 +90,7 @@ public final class NoiseStyle {
|
||||
|
||||
/** The base style's name; {@link #FLAT} where the pack wrote none. */
|
||||
public String style() {
|
||||
return style == null ? FLAT : style;
|
||||
return style;
|
||||
}
|
||||
|
||||
public double cellularFrequency() {
|
||||
@@ -121,10 +115,14 @@ public final class NoiseStyle {
|
||||
return Optional.ofNullable(imageMap);
|
||||
}
|
||||
|
||||
/** How far this style moves coordinates when it moves them, as another style's {@link #fracture} or as a warp: up
|
||||
* to half this many blocks either way.
|
||||
*/
|
||||
public double multiplier() {
|
||||
return multiplier;
|
||||
}
|
||||
|
||||
/** The style whose noise moves the coordinates this style is sampled at, by its own {@link #multiplier}. */
|
||||
public Optional<NoiseStyle> fracture() {
|
||||
return Optional.ofNullable(fracture);
|
||||
}
|
||||
@@ -133,34 +131,29 @@ public final class NoiseStyle {
|
||||
return exponent;
|
||||
}
|
||||
|
||||
public int cacheSize() {
|
||||
return cacheSize;
|
||||
}
|
||||
|
||||
/** Whether the style gives no noise: the {@link #FLAT} base style without an expression or image map. */
|
||||
public boolean isFlat() {
|
||||
return FLAT.equals(style()) && expression == null && imageMap == null;
|
||||
return FLAT.equals(style) && expression == null && imageMap == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
return other instanceof NoiseStyle that && style().equals(that.style())
|
||||
return other instanceof NoiseStyle that && style.equals(that.style)
|
||||
&& Double.compare(cellularFrequency, that.cellularFrequency) == 0
|
||||
&& Double.compare(cellularZoom, that.cellularZoom) == 0 && Double.compare(zoom, that.zoom) == 0
|
||||
&& Objects.equals(expression, that.expression) && Objects.equals(imageMap, that.imageMap)
|
||||
&& Double.compare(multiplier, that.multiplier) == 0 && Objects.equals(fracture, that.fracture)
|
||||
&& Double.compare(exponent, that.exponent) == 0 && cacheSize == that.cacheSize;
|
||||
&& Double.compare(exponent, that.exponent) == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(style(), cellularFrequency, cellularZoom, zoom, expression, imageMap, multiplier, fracture,
|
||||
exponent, cacheSize);
|
||||
return Objects.hash(style, cellularFrequency, cellularZoom, zoom, expression, imageMap, multiplier, fracture, exponent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "NoiseStyle[" + style() + expression().map(key -> ", expression " + key).orElse("")
|
||||
return "NoiseStyle[" + style + expression().map(key -> ", expression " + key).orElse("")
|
||||
+ imageMap().map(key -> ", image map " + key).orElse("") + ", zoom " + zoom + "]";
|
||||
}
|
||||
}
|
||||
@@ -6,20 +6,20 @@ import java.util.Objects;
|
||||
|
||||
/** A number between {@code min} and {@code max} that a noise style picks per column, as packs write it:
|
||||
* {@code {"min": 4, "max": 12, "style": {"style": "SIMPLEX"}}}, or a snippet under {@code snippet/style-range/}.
|
||||
* A value the host creates with the no-argument constructor and reads the JSON into.
|
||||
* A value the host decodes as every settings class (see DESIGN.md, "Decoding contract").
|
||||
*/
|
||||
@Snippet("style-range")
|
||||
@Desc("Represents a range styled with a custom generator")
|
||||
@Desc("A number between min and max that noise picks per column")
|
||||
public final class StyledRange {
|
||||
private static final String DEFAULT_STYLE = "STATIC";
|
||||
|
||||
@Desc("The minimum value")
|
||||
@Desc("The lowest value.")
|
||||
private double min = 16;
|
||||
|
||||
@Desc("The maximum value")
|
||||
@Desc("The highest value.")
|
||||
private double max = 32;
|
||||
|
||||
@Desc("The style to pick the range")
|
||||
@Desc("The noise that picks the value in each column.")
|
||||
private NoiseStyle style = NoiseStyle.of(DEFAULT_STYLE);
|
||||
|
||||
private StyledRange() {
|
||||
@@ -43,14 +43,14 @@ public final class StyledRange {
|
||||
return max;
|
||||
}
|
||||
|
||||
/** The style; {@link NoiseStyle#FLAT} where the pack wrote {@code null}. */
|
||||
/** The style; {@code STATIC} where the pack wrote none. */
|
||||
public NoiseStyle style() {
|
||||
return style == null ? NoiseStyle.of(NoiseStyle.FLAT) : style;
|
||||
return style;
|
||||
}
|
||||
|
||||
/** Whether every column gets the same value: the bounds are equal or the style is flat. */
|
||||
public boolean isFlat() {
|
||||
return min == max || style().isFlat();
|
||||
return min == max || style.isFlat();
|
||||
}
|
||||
|
||||
/** The value at column {@code worldX}, {@code worldZ}: {@code min} when the bounds are equal, halfway between
|
||||
@@ -61,25 +61,25 @@ public final class StyledRange {
|
||||
if (min == max) {
|
||||
return min;
|
||||
}
|
||||
if (style().isFlat()) {
|
||||
if (style.isFlat()) {
|
||||
return (min + max) / 2;
|
||||
}
|
||||
return min + (max - min) * noise.sampler(style(), seed).sample(worldX, worldZ);
|
||||
return min + (max - min) * noise.sampler(style, seed).sample(worldX, worldZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
return other instanceof StyledRange that && Double.compare(min, that.min) == 0
|
||||
&& Double.compare(max, that.max) == 0 && style().equals(that.style());
|
||||
&& Double.compare(max, that.max) == 0 && style.equals(that.style);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(min, max, style());
|
||||
return Objects.hash(min, max, style);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "StyledRange[" + min + ".." + max + ", " + style() + "]";
|
||||
return "StyledRange[" + min + ".." + max + ", " + style + "]";
|
||||
}
|
||||
}
|
||||
@@ -3,17 +3,14 @@ package com.volmit.placement;
|
||||
import com.volmit.geometry.BlockBox;
|
||||
import com.volmit.geometry.BlockPosition;
|
||||
import com.volmit.object.GeneratedObject;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import java.util.Objects;
|
||||
|
||||
/** One placement attempt. Geometry is already transformed; anchor is a world block position (world X and Z, Y as the height
|
||||
* above the dimension's bottom).
|
||||
* World position = local position - object anchor + request anchor. Arithmetic never wraps.
|
||||
* id identifies this attempt within the host's generation plan.
|
||||
*/
|
||||
public record PlacementRequest(ResourceId id, GeneratedObject object, BlockPosition anchor) {
|
||||
public record PlacementRequest(GeneratedObject object, BlockPosition anchor) {
|
||||
public PlacementRequest {
|
||||
Objects.requireNonNull(id, "id");
|
||||
Objects.requireNonNull(object, "object");
|
||||
Objects.requireNonNull(anchor, "anchor");
|
||||
}
|
||||
|
||||
@@ -5,10 +5,11 @@ 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}),
|
||||
/** Finds the structures a module places, for the host's structure commands, index and locate. 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}).
|
||||
* sends an id to the first that places it in the world: {@link #placed} for the structures the module places itself,
|
||||
* {@link #locatableStarts} for the platform structures it starts ({@link VanillaStructures#starts}).
|
||||
*/
|
||||
@Service(Providers.FIRST)
|
||||
public interface StructureLocator {
|
||||
@@ -37,4 +38,37 @@ public interface StructureLocator {
|
||||
* host calls it off the server's main thread.
|
||||
*/
|
||||
LocateResult locate(PackWorld world, ResourceId structure, int fromX, int fromZ, int maxRadiusChunks);
|
||||
|
||||
/** The platform structures this module starts itself in {@code world} ({@link VanillaStructures#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);
|
||||
}
|
||||
}
|
||||
@@ -10,10 +10,8 @@ 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:
|
||||
@@ -32,7 +30,8 @@ import java.util.Set;
|
||||
* 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.
|
||||
* one chunk's {@link StructureFit} is used on one thread. Finding the starts a module makes is
|
||||
* {@link StructureLocator}'s, the one service that locates structures.
|
||||
*/
|
||||
@Service(Providers.ALL)
|
||||
public interface VanillaStructures {
|
||||
@@ -93,37 +92,4 @@ 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);
|
||||
}
|
||||
}
|
||||
@@ -12,18 +12,18 @@ import java.util.OptionalInt;
|
||||
|
||||
/** Changes to a platform jigsaw structure's definition before the platform assembles one start of it, as packs write
|
||||
* them: {@code {"startPool": "minecraft:village/plains/town_centers", "maxDepth": 4}}. Every option left out keeps
|
||||
* what the registered definition says. A value the host creates with the no-argument constructor and reads the JSON
|
||||
* into.
|
||||
* what the registered definition says. A value the host decodes as every settings class (see DESIGN.md, "Decoding
|
||||
* contract").
|
||||
*/
|
||||
@Desc("Optional overrides applied to a live vanilla, datapack, or modded jigsaw definition before Minecraft assembles it. Omitted values preserve the registered source definition.")
|
||||
@Desc("Changes to a platform jigsaw structure's definition before a start of it is assembled. An option left out keeps the definition's value.")
|
||||
public final class JigsawOverrides {
|
||||
/** What packs write as the start connector to remove the definition's constraint. */
|
||||
private static final String NO_START_JIGSAW = "NONE";
|
||||
|
||||
/** Whether the start piece follows one of the platform's heightmaps. */
|
||||
@Desc("Controls whether a configured native jigsaw projects its start onto a Minecraft heightmap.")
|
||||
@Desc("Which heightmap the start piece is placed on.")
|
||||
public enum Heightmap {
|
||||
@Desc("Keeps the registered structure's own heightmap projection.")
|
||||
@Desc("The definition's own heightmap.")
|
||||
SOURCE,
|
||||
@Desc("Removes heightmap projection: the start piece lands at the structure's literal start height.")
|
||||
NONE,
|
||||
@@ -42,9 +42,9 @@ public final class JigsawOverrides {
|
||||
}
|
||||
|
||||
/** Whether placed pieces take on the water they are placed into. */
|
||||
@Desc("Controls waterlogging behavior for a configured native jigsaw.")
|
||||
@Desc("Whether placed pieces take on the water they replace.")
|
||||
public enum Liquids {
|
||||
@Desc("Keeps the registered structure's own liquid setting.")
|
||||
@Desc("The definition's own liquid setting.")
|
||||
SOURCE,
|
||||
@Desc("Places pieces dry.")
|
||||
IGNORE_WATERLOGGING,
|
||||
@@ -52,45 +52,45 @@ public final class JigsawOverrides {
|
||||
APPLY_WATERLOGGING
|
||||
}
|
||||
|
||||
@Desc("Optional registered template-pool key used instead of the source jigsaw's start pool. Empty preserves the source pool.")
|
||||
@Desc("The template pool the start piece comes from. Left out, the definition's pool.")
|
||||
@Ref(Reference.TEMPLATE_POOL)
|
||||
private String startPool = "";
|
||||
|
||||
@Desc("Optional start connector name. Empty preserves the source value; the literal NONE removes the source constraint.")
|
||||
@Desc("The start piece's connector. Left out, the definition's; NONE removes the definition's constraint.")
|
||||
private String startJigsawName = "";
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(20)
|
||||
@Desc("Maximum jigsaw recursion depth. Null preserves the source value.")
|
||||
@Desc("How many pieces deep the structure grows. Left out, the definition's depth.")
|
||||
private Integer maxDepth = null;
|
||||
|
||||
@MinNumber(1)
|
||||
@MaxNumber(128)
|
||||
@Desc("Exact horizontal block distance allowed from the start. Null preserves the source value.")
|
||||
@Desc("How many blocks sideways pieces may reach from the start. Left out, the definition's distance.")
|
||||
private Integer maxDistanceHorizontal = null;
|
||||
|
||||
@MinNumber(1)
|
||||
@MaxNumber(4064)
|
||||
@Desc("Exact vertical block distance allowed from the start. Null preserves the source value.")
|
||||
@Desc("How many blocks up or down pieces may reach from the start. Left out, the definition's distance.")
|
||||
private Integer maxDistanceVertical = null;
|
||||
|
||||
@Desc("Expansion-hack override. Null preserves the source value.")
|
||||
@Desc("Whether the platform's expansion hack applies. Left out, the definition's setting.")
|
||||
private Boolean useExpansionHack = null;
|
||||
|
||||
@Desc("Heightmap projection override. SOURCE preserves the registered value and NONE removes projection.")
|
||||
@Desc("The heightmap the start piece is placed on.")
|
||||
private Heightmap projectStartToHeightmap = Heightmap.SOURCE;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(Integer.MAX_VALUE)
|
||||
@Desc("Minimum distance retained above the dimension floor. Null preserves the source value.")
|
||||
@Desc("How many blocks pieces stay above the dimension's bottom. Left out, the definition's padding.")
|
||||
private Integer dimensionPaddingBottom = null;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(Integer.MAX_VALUE)
|
||||
@Desc("Minimum distance retained below the dimension ceiling. Null preserves the source value.")
|
||||
@Desc("How many blocks pieces stay below the dimension's top. Left out, the definition's padding.")
|
||||
private Integer dimensionPaddingTop = null;
|
||||
|
||||
@Desc("Waterlogging override. SOURCE preserves the registered value.")
|
||||
@Desc("Whether placed pieces take on the water they replace.")
|
||||
private Liquids liquidSettings = Liquids.SOURCE;
|
||||
|
||||
private JigsawOverrides() {
|
||||
@@ -187,11 +187,11 @@ public final class JigsawOverrides {
|
||||
|
||||
/** Whether the start connector constraint is removed, which packs write as {@code NONE}. */
|
||||
public boolean removesStartJigsaw() {
|
||||
return startJigsawName != null && NO_START_JIGSAW.equalsIgnoreCase(startJigsawName.trim());
|
||||
return NO_START_JIGSAW.equalsIgnoreCase(startJigsawName.trim());
|
||||
}
|
||||
|
||||
private static Optional<ResourceId> platformKey(String key) {
|
||||
return key == null || key.isBlank() ? Optional.empty() : Optional.of(ResourceId.ofPlatformKey(key));
|
||||
return key.isBlank() ? Optional.empty() : Optional.of(ResourceId.ofPlatformKey(key));
|
||||
}
|
||||
|
||||
public OptionalInt maxDepth() {
|
||||
@@ -210,9 +210,9 @@ public final class JigsawOverrides {
|
||||
return Optional.ofNullable(useExpansionHack);
|
||||
}
|
||||
|
||||
/** The heightmap projection; {@link Heightmap#SOURCE} where the pack wrote none or one the host does not know. */
|
||||
/** The heightmap projection; {@link Heightmap#SOURCE} where the pack wrote none. */
|
||||
public Heightmap projectStartToHeightmap() {
|
||||
return projectStartToHeightmap == null ? Heightmap.SOURCE : projectStartToHeightmap;
|
||||
return projectStartToHeightmap;
|
||||
}
|
||||
|
||||
public OptionalInt dimensionPaddingBottom() {
|
||||
@@ -223,9 +223,9 @@ public final class JigsawOverrides {
|
||||
return optional(dimensionPaddingTop);
|
||||
}
|
||||
|
||||
/** The waterlogging; {@link Liquids#SOURCE} where the pack wrote none or one the host does not know. */
|
||||
/** The waterlogging; {@link Liquids#SOURCE} where the pack wrote none. */
|
||||
public Liquids liquidSettings() {
|
||||
return liquidSettings == null ? Liquids.SOURCE : liquidSettings;
|
||||
return liquidSettings;
|
||||
}
|
||||
|
||||
private static OptionalInt optional(Integer value) {
|
||||
@@ -256,8 +256,8 @@ public final class JigsawOverrides {
|
||||
return "JigsawOverrides[pool '" + written(startPool) + "', depth " + maxDepth + ", " + projectStartToHeightmap() + "]";
|
||||
}
|
||||
|
||||
/** A key as the pack wrote it, without surrounding blanks; empty when it wrote none. */
|
||||
/** A key as the pack wrote it, without surrounding blanks. */
|
||||
private static String written(String key) {
|
||||
return key == null ? "" : key.trim();
|
||||
return key.trim();
|
||||
}
|
||||
}
|
||||
@@ -2,15 +2,17 @@ package com.volmit.vanilla;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/** What a module noted about a start it placed, for itself: two texts in the module's own format, one about how the
|
||||
* start meets the terrain and one about its foundation. The host keeps the memo with the start for as long as the world
|
||||
* does and hands it back whenever it asks the module about the start again ({@link StructureFit.Start#memo()},
|
||||
* {@link com.volmit.service.VanillaStructures#reach}), so a start that spans many chunks is finished the way it was
|
||||
* begun, even after the pack changed. The host never reads the texts.
|
||||
/** What a module noted about a start it placed, for itself: one text in the module's own format. The host keeps the memo
|
||||
* with the start for as long as the world does and hands it back whenever it asks the module about the start again
|
||||
* ({@link StructureFit.Start#memo()}, {@link com.volmit.service.VanillaStructures#reach}), so a start that spans many
|
||||
* chunks is finished the way it was begun, even after the pack changed. The host never reads the text, which is not
|
||||
* empty: a start the module noted nothing about has no memo.
|
||||
*/
|
||||
public record StartMemo(String terrain, String foundation) {
|
||||
public record StartMemo(String text) {
|
||||
public StartMemo {
|
||||
Objects.requireNonNull(terrain, "terrain");
|
||||
Objects.requireNonNull(foundation, "foundation");
|
||||
Objects.requireNonNull(text, "text");
|
||||
if (text.isEmpty()) {
|
||||
throw new IllegalArgumentException("A start memo's text must not be empty; give the start no memo instead");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,10 +13,9 @@ import java.util.Optional;
|
||||
* the chunk win unless the start {@link #replacesPlatformStart() replaces} them or the structure is
|
||||
* {@link VanillaStructureRule#REPLACE replaced} by a module.
|
||||
*
|
||||
* <p>{@link #identity()} names what placed the start, stable for one pack: the host records it with every start it
|
||||
* publishes, so a start found in the world later can be traced back to its placement. The {@link #memo() memo} is kept
|
||||
* with that record and handed back whenever the host asks the module about the start again, so a start that spans many
|
||||
* chunks keeps what the module decided for it when it was placed, even after the pack changed.
|
||||
* <p>The {@link #memo() memo} is kept with the start and handed back whenever the host asks the module about the start
|
||||
* again, so a start that spans many chunks keeps what the module decided for it when it was placed, even after the pack
|
||||
* changed.
|
||||
*/
|
||||
public final class VanillaStructureStart {
|
||||
private final ResourceId structure;
|
||||
@@ -25,56 +24,49 @@ public final class VanillaStructureStart {
|
||||
private final int y;
|
||||
private final boolean underground;
|
||||
private final boolean replacesPlatformStart;
|
||||
private final long identity;
|
||||
private final JigsawOverrides jigsaw;
|
||||
private final StartMemo memo;
|
||||
|
||||
private VanillaStructureStart(ResourceId structure, int chunkX, int chunkZ, int y, boolean underground,
|
||||
boolean replacesPlatformStart, long identity, JigsawOverrides jigsaw,
|
||||
StartMemo memo) {
|
||||
boolean replacesPlatformStart, JigsawOverrides jigsaw, StartMemo memo) {
|
||||
this.structure = Objects.requireNonNull(structure, "structure");
|
||||
this.chunkX = chunkX;
|
||||
this.chunkZ = chunkZ;
|
||||
this.y = y;
|
||||
this.underground = underground;
|
||||
this.replacesPlatformStart = replacesPlatformStart;
|
||||
this.identity = identity;
|
||||
this.jigsaw = jigsaw;
|
||||
this.memo = memo;
|
||||
}
|
||||
|
||||
/** A surface start of {@code structure} in chunk {@code chunkX, chunkZ}, planned at height {@code y}, with its
|
||||
* registered definition, identity 0 and no memo.
|
||||
* registered definition and no memo.
|
||||
*/
|
||||
public static VanillaStructureStart at(ResourceId structure, int chunkX, int chunkZ, int y) {
|
||||
return new VanillaStructureStart(structure, chunkX, chunkZ, y, false, false, 0L, null, null);
|
||||
return new VanillaStructureStart(structure, chunkX, chunkZ, y, false, false, null, null);
|
||||
}
|
||||
|
||||
/** This start with the structure's lowest block at {@link #y()} instead of on the surface. */
|
||||
public VanillaStructureStart underground() {
|
||||
return new VanillaStructureStart(structure, chunkX, chunkZ, y, true, replacesPlatformStart, identity, jigsaw, memo);
|
||||
return new VanillaStructureStart(structure, chunkX, chunkZ, y, true, replacesPlatformStart, jigsaw, memo);
|
||||
}
|
||||
|
||||
/** This start, taking the chunk even where the platform already started the structure there. */
|
||||
public VanillaStructureStart replacingPlatformStart() {
|
||||
return new VanillaStructureStart(structure, chunkX, chunkZ, y, underground, true, identity, jigsaw, memo);
|
||||
}
|
||||
|
||||
public VanillaStructureStart withIdentity(long identity) {
|
||||
return new VanillaStructureStart(structure, chunkX, chunkZ, y, underground, replacesPlatformStart, identity, jigsaw, memo);
|
||||
return new VanillaStructureStart(structure, chunkX, chunkZ, y, underground, true, jigsaw, memo);
|
||||
}
|
||||
|
||||
/** This start, assembled with {@code overrides} applied to a jigsaw structure's definition. Only jigsaw structures
|
||||
* take overrides: the host fails the start of any other structure that has some.
|
||||
*/
|
||||
public VanillaStructureStart withJigsaw(JigsawOverrides overrides) {
|
||||
return new VanillaStructureStart(structure, chunkX, chunkZ, y, underground, replacesPlatformStart, identity,
|
||||
return new VanillaStructureStart(structure, chunkX, chunkZ, y, underground, replacesPlatformStart,
|
||||
Objects.requireNonNull(overrides, "overrides"), memo);
|
||||
}
|
||||
|
||||
/** This start with {@code memo}, which the host keeps with it and hands back in every later question about it. */
|
||||
public VanillaStructureStart withMemo(StartMemo memo) {
|
||||
return new VanillaStructureStart(structure, chunkX, chunkZ, y, underground, replacesPlatformStart, identity, jigsaw,
|
||||
return new VanillaStructureStart(structure, chunkX, chunkZ, y, underground, replacesPlatformStart, jigsaw,
|
||||
Objects.requireNonNull(memo, "memo"));
|
||||
}
|
||||
|
||||
@@ -103,10 +95,6 @@ public final class VanillaStructureStart {
|
||||
return replacesPlatformStart;
|
||||
}
|
||||
|
||||
public long identity() {
|
||||
return identity;
|
||||
}
|
||||
|
||||
/** Changes to the jigsaw definition; empty assembles the registered definition as it is. */
|
||||
public Optional<JigsawOverrides> jigsaw() {
|
||||
return Optional.ofNullable(jigsaw);
|
||||
@@ -121,13 +109,13 @@ public final class VanillaStructureStart {
|
||||
public boolean equals(Object other) {
|
||||
return other instanceof VanillaStructureStart that && structure.equals(that.structure) && chunkX == that.chunkX
|
||||
&& chunkZ == that.chunkZ && y == that.y && underground == that.underground
|
||||
&& replacesPlatformStart == that.replacesPlatformStart && identity == that.identity
|
||||
&& replacesPlatformStart == that.replacesPlatformStart
|
||||
&& Objects.equals(jigsaw, that.jigsaw) && Objects.equals(memo, that.memo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(structure, chunkX, chunkZ, y, underground, replacesPlatformStart, identity, jigsaw, memo);
|
||||
return Objects.hash(structure, chunkX, chunkZ, y, underground, replacesPlatformStart, jigsaw, memo);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+6
-6
@@ -1,10 +1,9 @@
|
||||
package com.volmit.config;
|
||||
package com.volmit.world;
|
||||
|
||||
import com.volmit.IrisFeature;
|
||||
import com.volmit.config.PackSettings;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@@ -30,10 +29,11 @@ public interface LinkedBiomes {
|
||||
* generation) without joining the region's biome tree.
|
||||
*
|
||||
* @param pack the pack the settings belong to, which turns their keys into ids
|
||||
* @param dimension the settings the owner's dimension declares, for settings that name something the dimension
|
||||
* declares, such as a band of its caves
|
||||
* @param dimension what the owner's dimension itself declares, each type as a stack of at most its dimension entry,
|
||||
* for settings that name something the dimension declares, such as a band of its caves. The
|
||||
* dimension's regions and biomes are not in it: they are what the host is working out.
|
||||
*/
|
||||
default Set<ResourceId> usedBiomes(PackResources pack, Collection<IrisFeature> dimension) {
|
||||
default Set<ResourceId> usedBiomes(PackResources pack, PackSettings dimension) {
|
||||
return Set.of();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user