mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 08:44:50 +00:00
Pick regions, biomes and children by weight
Rarity gave every list entry a share of 1 / rarity and children rounded slots; a weight on the list entry says what a pack author means. Dimension regions, region biome lists, biome children and carving children are now entries with a weight (1 to 1000), picked along the list in the order written, region and biome lists giving the edge to the earlier entry and children to the later. A biome keeps itself among its children only where it lists itself. PackBiome and PackRegion carry the weighted lists, and the carving module picks with the API's Weighted.pick. Rarity is gone from biomes and regions, and the three fixture packs are rewritten to the entry format. No pin or golden moved: the changed generator seed only touches biomes of rarity other than 1, and no pinned world reads one. The fixture packs now have weights where their regions had rarities: pack-before-the-port forests 15, magnetics 1; pack-before-loot-and-spawn hot 10, terralost 6, mushroom 2, swamp 15, the rest 1. v3: 0fbce6ba2 a598b4323 96beb86e0
This commit is contained in:
1 parent
d705dee379
commit
3d55236f97
90 files changed
+1022
-1183
No files matched your search
+20
-124
@@ -19,14 +19,15 @@
|
||||
package art.arcane.iris.engine.object.terrain.carving;
|
||||
|
||||
import art.arcane.iris.builtin.IrisSeedPurposes;
|
||||
import art.arcane.iris.modules.carve.CarvingChild;
|
||||
import art.arcane.iris.modules.carve.CarvingEntry;
|
||||
import art.arcane.iris.modules.carve.CarvingSettings;
|
||||
import com.volmit.ModuleLog;
|
||||
import com.volmit.config.Range;
|
||||
import com.volmit.noise.NoiseSampler;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.world.PackBiome;
|
||||
import com.volmit.world.PackWorld;
|
||||
import com.volmit.world.Weighted;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -43,6 +44,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
* one a noise pattern selects at a column.
|
||||
*/
|
||||
public final class CarvingResolver {
|
||||
private static final Weighted.Edge CHILD_EDGE = Weighted.Edge.LATER;
|
||||
private static final int MAX_CHILD_DEPTH = 32;
|
||||
private static final long CHILD_SEED_SALT = 0x9E3779B97F4A7C15L;
|
||||
|
||||
@@ -53,7 +55,7 @@ public final class CarvingResolver {
|
||||
private final List<ResolvedCarvingEntry> entries;
|
||||
private final Map<String, ResolvedCarvingEntry> index;
|
||||
private final Map<Integer, Optional<ResolvedCarvingEntry>> rootEntriesByWorldY = new ConcurrentHashMap<>();
|
||||
private final Map<ResolvedCarvingEntry, ParentSelectionPlan> selectionPlans = new ConcurrentHashMap<>();
|
||||
private final Map<ResolvedCarvingEntry, List<Weighted<ResolvedCarvingEntry>>> childOptions = new ConcurrentHashMap<>();
|
||||
|
||||
CarvingResolver(PackWorld world, List<CarvingEntry> declared) {
|
||||
this.resources = world.resources();
|
||||
@@ -88,7 +90,7 @@ public final class CarvingResolver {
|
||||
return rootEntryAtWorldY(y + minHeight);
|
||||
}
|
||||
|
||||
/** The root entry for a world Y as packs write them; null where no enabled entry with a biome holds it. */
|
||||
/** The root entry for a world Y as packs write it; null where no enabled entry with a biome holds it. */
|
||||
public ResolvedCarvingEntry rootEntryAtWorldY(int worldY) {
|
||||
return rootEntriesByWorldY.computeIfAbsent(worldY, this::pickRootEntry).orElse(null);
|
||||
}
|
||||
@@ -156,97 +158,32 @@ public final class CarvingResolver {
|
||||
}
|
||||
|
||||
private ResolvedCarvingEntry selectChild(ResolvedCarvingEntry parent, int worldX, int worldZ) {
|
||||
List<String> children = parent.children();
|
||||
if (children.isEmpty()) {
|
||||
List<Weighted<ResolvedCarvingEntry>> options = childOptions.computeIfAbsent(parent, this::buildChildOptions);
|
||||
if (options.isEmpty()) {
|
||||
return parent;
|
||||
}
|
||||
|
||||
PackBiome parentBiome = entryBiome(parent);
|
||||
if (parentBiome == null) {
|
||||
return parent;
|
||||
}
|
||||
|
||||
ParentSelectionPlan selectionPlan = selectionPlans.computeIfAbsent(parent, key -> buildSelectionPlan(key, parentBiome));
|
||||
if (selectionPlan.parentOnly) {
|
||||
return parent;
|
||||
}
|
||||
|
||||
NoiseSampler childGenerator = parent.childrenGenerator(childSeed, resources);
|
||||
double sample = childGenerator.sample(worldX, worldZ);
|
||||
int selectedIndex = (int) Math.round(sample * selectionPlan.maxIndex);
|
||||
CarvingChoice selected = selectionPlan.get(selectedIndex);
|
||||
if (selected == null || selected.entry == null) {
|
||||
return parent;
|
||||
}
|
||||
|
||||
return selected.entry;
|
||||
double sample = parent.childrenGenerator(childSeed, resources).sample(worldX, worldZ);
|
||||
return Weighted.pick(options, sample, CHILD_EDGE);
|
||||
}
|
||||
|
||||
private ParentSelectionPlan buildSelectionPlan(ResolvedCarvingEntry parent, PackBiome parentBiome) {
|
||||
List<CarvingChoice> options = new ArrayList<>();
|
||||
for (String childId : parent.children()) {
|
||||
if (childId == null || childId.isBlank()) {
|
||||
continue;
|
||||
private List<Weighted<ResolvedCarvingEntry>> buildChildOptions(ResolvedCarvingEntry parent) {
|
||||
List<Weighted<ResolvedCarvingEntry>> options = new ArrayList<>();
|
||||
for (CarvingChild listed : parent.children()) {
|
||||
ResolvedCarvingEntry child = listedEntry(parent, listed.id().trim());
|
||||
if (child != null && child.enabled() && entryBiome(child) != null) {
|
||||
options.add(new Weighted<>(child, listed.weight()));
|
||||
}
|
||||
|
||||
ResolvedCarvingEntry child = index.get(childId.trim());
|
||||
if (child == null || !child.enabled()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
PackBiome childBiome = entryBiome(child);
|
||||
if (childBiome == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
options.add(new CarvingChoice(child, rarity(childBiome)));
|
||||
}
|
||||
|
||||
options.add(new CarvingChoice(parent, rarity(parentBiome)));
|
||||
if (options.size() <= 1) {
|
||||
return ParentSelectionPlan.parentOnly();
|
||||
}
|
||||
|
||||
CarvingChoice[] mappedChoices = buildRarityMappedChoices(options);
|
||||
if (mappedChoices.length == 0) {
|
||||
return ParentSelectionPlan.parentOnly();
|
||||
}
|
||||
|
||||
return new ParentSelectionPlan(mappedChoices);
|
||||
return List.copyOf(options);
|
||||
}
|
||||
|
||||
private static CarvingChoice[] buildRarityMappedChoices(List<CarvingChoice> choices) {
|
||||
int max = 1;
|
||||
for (CarvingChoice choice : choices) {
|
||||
if (choice.rarity > max) {
|
||||
max = choice.rarity;
|
||||
}
|
||||
private ResolvedCarvingEntry listedEntry(ResolvedCarvingEntry parent, String id) {
|
||||
if (id.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
max++;
|
||||
List<CarvingChoice> mapped = new ArrayList<>();
|
||||
boolean flip = false;
|
||||
for (CarvingChoice choice : choices) {
|
||||
int count = max - choice.rarity;
|
||||
for (int index = 0; index < count; index++) {
|
||||
flip = !flip;
|
||||
if (flip) {
|
||||
mapped.add(choice);
|
||||
} else {
|
||||
mapped.add(0, choice);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return mapped.toArray(new CarvingChoice[0]);
|
||||
}
|
||||
|
||||
private static int rarity(PackBiome biome) {
|
||||
if (biome == null) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return Math.max(biome.rarity(), 1);
|
||||
return id.equals(parent.id().trim()) ? parent : index.get(id);
|
||||
}
|
||||
|
||||
private static int clampDepth(int depth) {
|
||||
@@ -266,45 +203,4 @@ public final class CarvingResolver {
|
||||
}
|
||||
return Map.copyOf(index);
|
||||
}
|
||||
|
||||
private static final class ParentSelectionPlan {
|
||||
private final CarvingChoice[] mappedChoices;
|
||||
private final int maxIndex;
|
||||
private final boolean parentOnly;
|
||||
|
||||
private ParentSelectionPlan(CarvingChoice[] mappedChoices) {
|
||||
this.mappedChoices = mappedChoices;
|
||||
this.maxIndex = mappedChoices.length - 1;
|
||||
this.parentOnly = false;
|
||||
}
|
||||
|
||||
private ParentSelectionPlan() {
|
||||
this.mappedChoices = null;
|
||||
this.maxIndex = -1;
|
||||
this.parentOnly = true;
|
||||
}
|
||||
|
||||
private static ParentSelectionPlan parentOnly() {
|
||||
return new ParentSelectionPlan();
|
||||
}
|
||||
|
||||
private CarvingChoice get(int index) {
|
||||
if (mappedChoices == null || mappedChoices.length == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (index < 0) {
|
||||
return mappedChoices[0];
|
||||
}
|
||||
|
||||
if (index >= mappedChoices.length) {
|
||||
return mappedChoices[mappedChoices.length - 1];
|
||||
}
|
||||
|
||||
return mappedChoices[index];
|
||||
}
|
||||
}
|
||||
|
||||
private record CarvingChoice(ResolvedCarvingEntry entry, int rarity) {
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -18,6 +18,7 @@
|
||||
|
||||
package art.arcane.iris.engine.object.terrain.carving;
|
||||
|
||||
import art.arcane.iris.modules.carve.CarvingChild;
|
||||
import art.arcane.iris.modules.carve.CarvingEntry;
|
||||
import art.arcane.volmlib.util.cache.AtomicCache;
|
||||
import com.volmit.ModuleLog;
|
||||
@@ -64,7 +65,7 @@ public final class ResolvedCarvingEntry {
|
||||
return settings.worldYRange();
|
||||
}
|
||||
|
||||
public List<String> children() {
|
||||
public List<CarvingChild> children() {
|
||||
return settings.children();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.modules.carve;
|
||||
|
||||
import com.volmit.config.Desc;
|
||||
import com.volmit.config.MaxNumber;
|
||||
import com.volmit.config.MinNumber;
|
||||
import com.volmit.config.Required;
|
||||
import com.volmit.world.Weighted;
|
||||
|
||||
/** A child of a {@link CarvingEntry}: the id of another carving entry and the weight it has in the child noise's pick. */
|
||||
@Desc("A carving entry in the list the child noise picks from")
|
||||
public final class CarvingChild {
|
||||
@Required
|
||||
@Desc("The id of the carving entry. List the parent's own id where it should stay itself.")
|
||||
private String id = "";
|
||||
|
||||
@MinNumber(Weighted.MIN_WEIGHT)
|
||||
@MaxNumber(Weighted.MAX_WEIGHT)
|
||||
@Desc("A weight of two is just as if this entry were listed twice in a row, making it more common. The noise picks along the list in the order it is written.")
|
||||
private int weight = 1;
|
||||
|
||||
private CarvingChild() {
|
||||
}
|
||||
|
||||
public CarvingChild(String id, int weight) {
|
||||
this.id = id;
|
||||
this.weight = weight;
|
||||
}
|
||||
|
||||
public String id() {
|
||||
return id == null ? "" : id;
|
||||
}
|
||||
|
||||
public int weight() {
|
||||
return weight;
|
||||
}
|
||||
}
|
||||
@@ -60,8 +60,8 @@ public final class CarvingEntry {
|
||||
@Desc("If this carving entry has child carving entries, this controls the shape pattern used to pick them.")
|
||||
private NoiseStyle childStyle = NoiseStyle.of("CELLULAR_IRIS_DOUBLE");
|
||||
|
||||
@Desc("Child carving entry ids. Child ids can point back to parent ids to create cycles; recursion is bounded by childRecursionDepth.")
|
||||
private List<String> children = List.of();
|
||||
@Desc("What portions of this entry turn into: the child noise picks along this list in the order it is written. List this entry's own id where it should stay itself; an entry that is not listed does not stay anywhere. Child ids can point back to parent ids to create cycles; recursion is bounded by childRecursionDepth.")
|
||||
private List<CarvingChild> children = List.of();
|
||||
|
||||
@Desc("Maximum recursion depth when resolving child carving entries from this entry.")
|
||||
private int childRecursionDepth = DEFAULT_CHILD_RECURSION_DEPTH;
|
||||
@@ -93,7 +93,7 @@ public final class CarvingEntry {
|
||||
return childStyle;
|
||||
}
|
||||
|
||||
public List<String> children() {
|
||||
public List<CarvingChild> children() {
|
||||
return children == null ? List.of() : Collections.unmodifiableList(children);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user