Type the loot source's table as an id and leave jigsaw overrides out explicitly

ItemDrop.Source names its pack table by ResourceId. JigsawOverrides drops the
SOURCE constants of Heightmap and Liquids and the blank-text defaults: an option
the pack left out is null inside and empty in its getter.
This commit is contained in:
piexel committed 2026-10-28 04:13:22 +01:00
1 parent a9e3cbaa93
commit 56bd2badab
4 files changed
+36 -32

No files matched your search

+2 -1
View File
@@ -765,7 +765,8 @@ public List<VanillaStructureStart> starts(int chunkX, int chunkZ, VanillaStructu
How a start meets the terrain is the module's: the API has no fit values. A `StartMemo` is one opaque, non-empty
text the module gives a start it places; the host persists it with the start and hands it back in `reach` and in every chunk's
`StructureFit`, so every chunk the start reaches fits it the same way, also after a restart. `JigsawOverrides` is a
value type like `PaletteSpec`: settings may hold it, and packs write it as Iris always read it.
value type like `PaletteSpec`: settings may hold it, and packs write it as Iris always read it. An option a pack leaves
out is empty in its getter (`Optional`, `OptionalInt`); no constant stands for "the definition's own".
## Host side
@@ -1,6 +1,7 @@
package com.volmit.item;
import com.volmit.resource.ContentKey;
import com.volmit.resource.ResourceId;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
@@ -97,11 +98,11 @@ public record ItemDrop(ContentKey item, int amount, Look look, List<ItemEnchantm
/**
* 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; empty for an item that came from no table
* @param table the pack table's id; empty 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(Optional<String> table, int tableRarity, int entryRarity) {
public record Source(Optional<ResourceId> table, int tableRarity, int entryRarity) {
public Source {
Objects.requireNonNull(table, "table");
}
@@ -12,8 +12,8 @@ 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 decodes as every settings class (see DESIGN.md, "Decoding
* contract").
* what the registered definition says, and its getter returns an empty value then; there is no constant that stands for
* "the definition's own". A value the host decodes as every settings class (see DESIGN.md, "Decoding contract").
*/
@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 {
@@ -23,8 +23,6 @@ public final class JigsawOverrides {
/** Whether the start piece follows one of the platform's heightmaps. */
@Desc("Which heightmap the start piece is placed on.")
public enum Heightmap {
@Desc("The definition's own heightmap.")
SOURCE,
@Desc("Removes heightmap projection: the start piece lands at the structure's literal start height.")
NONE,
@Desc("The terrain top counting water as solid.")
@@ -44,8 +42,6 @@ public final class JigsawOverrides {
/** Whether placed pieces take on the water they are placed into. */
@Desc("Whether placed pieces take on the water they replace.")
public enum Liquids {
@Desc("The definition's own liquid setting.")
SOURCE,
@Desc("Places pieces dry.")
IGNORE_WATERLOGGING,
@Desc("Waterlogs placed pieces from the water they replace.")
@@ -54,10 +50,10 @@ public final class JigsawOverrides {
@Desc("The template pool the start piece comes from. Left out, the definition's pool.")
@Ref(Reference.TEMPLATE_POOL)
private String startPool = "";
private String startPool = null;
@Desc("The start piece's connector. Left out, the definition's; NONE removes the definition's constraint.")
private String startJigsawName = "";
private String startJigsawName = null;
@MinNumber(0)
@MaxNumber(20)
@@ -77,8 +73,8 @@ public final class JigsawOverrides {
@Desc("Whether the platform's expansion hack applies. Left out, the definition's setting.")
private Boolean useExpansionHack = null;
@Desc("The heightmap the start piece is placed on.")
private Heightmap projectStartToHeightmap = Heightmap.SOURCE;
@Desc("The heightmap the start piece is placed on. Left out, the definition's heightmap.")
private Heightmap projectStartToHeightmap = null;
@MinNumber(0)
@MaxNumber(Integer.MAX_VALUE)
@@ -90,8 +86,8 @@ public final class JigsawOverrides {
@Desc("How many blocks pieces stay below the dimension's top. Left out, the definition's padding.")
private Integer dimensionPaddingTop = null;
@Desc("Whether placed pieces take on the water they replace.")
private Liquids liquidSettings = Liquids.SOURCE;
@Desc("Whether placed pieces take on the water they replace. Left out, the definition's setting.")
private Liquids liquidSettings = null;
private JigsawOverrides() {
}
@@ -103,10 +99,10 @@ public final class JigsawOverrides {
maxDistanceHorizontal = source.maxDistanceHorizontal;
maxDistanceVertical = source.maxDistanceVertical;
useExpansionHack = source.useExpansionHack;
projectStartToHeightmap = source.projectStartToHeightmap();
projectStartToHeightmap = source.projectStartToHeightmap;
dimensionPaddingBottom = source.dimensionPaddingBottom;
dimensionPaddingTop = source.dimensionPaddingTop;
liquidSettings = source.liquidSettings();
liquidSettings = source.liquidSettings;
}
/** Overrides that change nothing: the registered definition as it is. */
@@ -187,11 +183,11 @@ public final class JigsawOverrides {
/** Whether the start connector constraint is removed, which packs write as {@code NONE}. */
public boolean removesStartJigsaw() {
return NO_START_JIGSAW.equalsIgnoreCase(startJigsawName.trim());
return startJigsawName != null && NO_START_JIGSAW.equalsIgnoreCase(written(startJigsawName));
}
private static Optional<ResourceId> platformKey(String key) {
return key.isBlank() ? Optional.empty() : Optional.of(ResourceId.ofPlatformKey(key));
return key == null || key.isBlank() ? Optional.empty() : Optional.of(ResourceId.ofPlatformKey(key));
}
public OptionalInt maxDepth() {
@@ -210,9 +206,9 @@ public final class JigsawOverrides {
return Optional.ofNullable(useExpansionHack);
}
/** The heightmap projection; {@link Heightmap#SOURCE} where the pack wrote none. */
public Heightmap projectStartToHeightmap() {
return projectStartToHeightmap;
/** The heightmap projection; empty keeps the definition's. */
public Optional<Heightmap> projectStartToHeightmap() {
return Optional.ofNullable(projectStartToHeightmap);
}
public OptionalInt dimensionPaddingBottom() {
@@ -223,9 +219,9 @@ public final class JigsawOverrides {
return optional(dimensionPaddingTop);
}
/** The waterlogging; {@link Liquids#SOURCE} where the pack wrote none. */
public Liquids liquidSettings() {
return liquidSettings;
/** The waterlogging; empty keeps the definition's. */
public Optional<Liquids> liquidSettings() {
return Optional.ofNullable(liquidSettings);
}
private static OptionalInt optional(Integer value) {
@@ -239,25 +235,25 @@ public final class JigsawOverrides {
&& Objects.equals(maxDistanceHorizontal, that.maxDistanceHorizontal)
&& Objects.equals(maxDistanceVertical, that.maxDistanceVertical)
&& Objects.equals(useExpansionHack, that.useExpansionHack)
&& projectStartToHeightmap() == that.projectStartToHeightmap()
&& projectStartToHeightmap == that.projectStartToHeightmap
&& Objects.equals(dimensionPaddingBottom, that.dimensionPaddingBottom)
&& Objects.equals(dimensionPaddingTop, that.dimensionPaddingTop)
&& liquidSettings() == that.liquidSettings();
&& liquidSettings == that.liquidSettings;
}
@Override
public int hashCode() {
return Objects.hash(written(startPool), written(startJigsawName), maxDepth, maxDistanceHorizontal, maxDistanceVertical,
useExpansionHack, projectStartToHeightmap(), dimensionPaddingBottom, dimensionPaddingTop, liquidSettings());
useExpansionHack, projectStartToHeightmap, dimensionPaddingBottom, dimensionPaddingTop, liquidSettings);
}
@Override
public String toString() {
return "JigsawOverrides[pool '" + written(startPool) + "', depth " + maxDepth + ", " + projectStartToHeightmap() + "]";
return "JigsawOverrides[pool '" + written(startPool) + "', depth " + maxDepth + ", " + projectStartToHeightmap + "]";
}
/** A key as the pack wrote it, without surrounding blanks. */
/** A key as the pack wrote it, without surrounding blanks; blank for a key left out, so that left out and blank are equal. */
private static String written(String key) {
return key.trim();
return key == null ? "" : key.trim();
}
}
@@ -38,7 +38,13 @@ class VanillaStructureValuesTest {
"useExpansionHack", "projectStartToHeightmap", "dimensionPaddingBottom", "dimensionPaddingTop",
"liquidSettings"), names(JigsawOverrides.class));
assertEquals(OptionalInt.empty(), JigsawOverrides.none().maxDepth());
assertEquals(JigsawOverrides.Heightmap.SOURCE, JigsawOverrides.none().projectStartToHeightmap());
assertEquals(Optional.empty(), JigsawOverrides.none().projectStartToHeightmap());
assertEquals(Optional.empty(), JigsawOverrides.none().liquidSettings());
assertEquals(Optional.empty(), JigsawOverrides.none().startPool());
assertEquals(Optional.empty(), JigsawOverrides.none().startJigsawName());
assertFalse(JigsawOverrides.none().removesStartJigsaw());
assertEquals(Optional.of(JigsawOverrides.Liquids.IGNORE_WATERLOGGING),
JigsawOverrides.none().withLiquids(JigsawOverrides.Liquids.IGNORE_WATERLOGGING).liquidSettings());
var pool = com.volmit.resource.ResourceId.parse("minecraft:village/plains/town_centers");
var overrides = JigsawOverrides.none().withStartPool(pool).withMaxDepth(4)
.withMaxDistance(80, 120).withHeightmap(JigsawOverrides.Heightmap.NONE);