mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-12-01 10:14:36 +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
@@ -26,6 +26,7 @@ import art.arcane.iris.engine.object.image.IrisImageMap;
|
||||
import art.arcane.iris.engine.object.noise.expression.IrisExpression;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObject;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiomeEntry;
|
||||
import art.arcane.iris.engine.object.world.region.IrisRegion;
|
||||
import com.volmit.block.BlockRegistry;
|
||||
import com.volmit.host.ResourceKindRegistration;
|
||||
@@ -39,6 +40,7 @@ import com.volmit.resource.ResourceId;
|
||||
import com.volmit.resource.ResourceKind;
|
||||
import com.volmit.world.PackBiome;
|
||||
import com.volmit.world.PackRegion;
|
||||
import com.volmit.world.Weighted;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@@ -247,16 +249,16 @@ public final class IrisPackResources implements PackResources {
|
||||
|
||||
private PackBiome biomeOf(ResourceId id, IrisBiome biome) {
|
||||
return new PackBiome(id, biome.getName(), ResourceId.parse(biome.getDerivativeKey()), ResourceId.parse(biome.getVanillaDerivativeKey()),
|
||||
biome.getRarity(), idsOf(biome.getChildren()));
|
||||
weightedIdsOf(biome.getChildren()));
|
||||
}
|
||||
|
||||
private PackRegion regionOf(ResourceId id, IrisRegion region) {
|
||||
return new PackRegion(id, region.getName(), region.getRarity(), idsOf(region.getLandBiomes()), idsOf(region.getSeaBiomes()),
|
||||
idsOf(region.getShoreBiomes()), idsOf(region.getCaveBiomes()));
|
||||
return new PackRegion(id, region.getName(), weightedIdsOf(region.getLandBiomes()), weightedIdsOf(region.getSeaBiomes()),
|
||||
weightedIdsOf(region.getShoreBiomes()), weightedIdsOf(region.getCaveBiomes()));
|
||||
}
|
||||
|
||||
private List<ResourceId> idsOf(Collection<String> keys) {
|
||||
return keys.stream().map(ids::of).toList();
|
||||
private List<Weighted<ResourceId>> weightedIdsOf(Collection<IrisBiomeEntry> entries) {
|
||||
return entries.stream().map(entry -> new Weighted<>(ids.of(entry.getBiome()), entry.getWeight())).toList();
|
||||
}
|
||||
|
||||
/** One kind of pack resource: the keys the pack has, how a key's resource is read, an index from ids to keys and what was read so far. */
|
||||
|
||||
@@ -24,6 +24,7 @@ import art.arcane.iris.engine.object.world.dimension.IrisDimensionType;
|
||||
import art.arcane.iris.engine.object.world.IrisWorldBoundary;
|
||||
import art.arcane.volmlib.util.json.JSONArray;
|
||||
import art.arcane.volmlib.util.json.JSONObject;
|
||||
import com.volmit.world.Weighted;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -59,7 +60,8 @@ final class PackDimensionValidator {
|
||||
|
||||
int resolvedRegions = 0;
|
||||
for (int i = 0; i < regionsArray.length(); i++) {
|
||||
String regionKey = regionsArray.optString(i, null);
|
||||
String regionKey = PackValidationIo.entryKey(regionsArray, i, "region");
|
||||
validateWeight(regionsArray.optJSONObject(i), "Dimension '" + dimensionKey + "' regions[" + i + "]", blockingErrors);
|
||||
if (regionKey == null || regionKey.isBlank()) {
|
||||
warnings.add("Dimension '" + dimensionKey + "' has a blank region entry at index " + i + ".");
|
||||
continue;
|
||||
@@ -78,10 +80,10 @@ final class PackDimensionValidator {
|
||||
continue;
|
||||
}
|
||||
|
||||
int anyBiome = countBiomeRefs(regionJson, "landBiomes", biomesFolder, regionKey, warnings)
|
||||
+ countBiomeRefs(regionJson, "seaBiomes", biomesFolder, regionKey, warnings)
|
||||
+ countBiomeRefs(regionJson, "shoreBiomes", biomesFolder, regionKey, warnings)
|
||||
+ countBiomeRefs(regionJson, "caveBiomes", biomesFolder, regionKey, warnings);
|
||||
int anyBiome = countBiomeRefs(regionJson, "landBiomes", biomesFolder, regionKey, blockingErrors, warnings)
|
||||
+ countBiomeRefs(regionJson, "seaBiomes", biomesFolder, regionKey, blockingErrors, warnings)
|
||||
+ countBiomeRefs(regionJson, "shoreBiomes", biomesFolder, regionKey, blockingErrors, warnings)
|
||||
+ countBiomeRefs(regionJson, "caveBiomes", biomesFolder, regionKey, blockingErrors, warnings);
|
||||
if (anyBiome == 0) {
|
||||
blockingErrors.add("Region '" + regionKey + "' has no resolvable biomes.");
|
||||
}
|
||||
@@ -94,14 +96,25 @@ final class PackDimensionValidator {
|
||||
}
|
||||
}
|
||||
|
||||
private static int countBiomeRefs(JSONObject regionJson, String field, File biomesFolder, String regionKey, List<String> warnings) {
|
||||
private static void validateWeight(JSONObject entry, String path, List<String> blockingErrors) {
|
||||
if (entry == null) {
|
||||
return;
|
||||
}
|
||||
Integer weight = PackIntegerChecks.integerField(entry, "weight", Weighted.MIN_WEIGHT, path, blockingErrors);
|
||||
PackIntegerChecks.requireMinimum(path + ".weight", weight, Weighted.MIN_WEIGHT, blockingErrors);
|
||||
PackIntegerChecks.requireMaximum(path + ".weight", weight, Weighted.MAX_WEIGHT, blockingErrors);
|
||||
}
|
||||
|
||||
private static int countBiomeRefs(JSONObject regionJson, String field, File biomesFolder, String regionKey,
|
||||
List<String> blockingErrors, List<String> warnings) {
|
||||
JSONArray arr = regionJson.optJSONArray(field);
|
||||
if (arr == null) {
|
||||
return 0;
|
||||
}
|
||||
int resolved = 0;
|
||||
for (int i = 0; i < arr.length(); i++) {
|
||||
String biomeKey = arr.optString(i, null);
|
||||
String biomeKey = PackValidationIo.entryKey(arr, i, "biome");
|
||||
validateWeight(arr.optJSONObject(i), "Region '" + regionKey + "' " + field + "[" + i + "]", blockingErrors);
|
||||
if (biomeKey == null || biomeKey.isBlank()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -519,7 +519,7 @@ final class PackImageMapValidator {
|
||||
return;
|
||||
}
|
||||
for (int index = 0; index < values.length(); index++) {
|
||||
if (biomeKey.equals(values.optString(index, null))) {
|
||||
if (biomeKey.equals(PackValidationIo.entryKey(values, index, "biome"))) {
|
||||
roles.add(role);
|
||||
return;
|
||||
}
|
||||
@@ -532,7 +532,7 @@ final class PackImageMapValidator {
|
||||
) {
|
||||
Set<String> regionKeys = new TreeSet<>();
|
||||
if (dimension.getRegions() != null) {
|
||||
for (String regionKey : dimension.getRegions()) {
|
||||
for (String regionKey : dimension.getRegionKeys()) {
|
||||
String normalized = normalized(regionKey);
|
||||
if (normalized != null) {
|
||||
regionKeys.add(normalized);
|
||||
|
||||
@@ -57,6 +57,12 @@ public final class PackValidationIo {
|
||||
}
|
||||
}
|
||||
|
||||
/** The key the entry at {@code index} of a weighted list names in {@code field}; null when the entry is not an object with one. */
|
||||
static String entryKey(JSONArray entries, int index, String field) {
|
||||
JSONObject entry = entries.optJSONObject(index);
|
||||
return entry == null ? null : entry.optString(field, null);
|
||||
}
|
||||
|
||||
static boolean isScannableJsonPath(Path path) {
|
||||
String name = path.getFileName().toString();
|
||||
if (!name.endsWith(".json")) {
|
||||
|
||||
@@ -1230,7 +1230,7 @@ public class StudioSVC implements IrisService {
|
||||
{
|
||||
"name": "%s",
|
||||
"version": 1,
|
||||
"regions": ["starter"],
|
||||
"regions": [{"region": "starter", "weight": 1}],
|
||||
"logicalHeight": 384,
|
||||
"dimensionHeight": {"min": -64, "max": 320}
|
||||
}
|
||||
@@ -1238,9 +1238,9 @@ public class StudioSVC implements IrisService {
|
||||
Files.writeString(stage.resolve("regions/starter.json"), """
|
||||
{
|
||||
"name": "Starter",
|
||||
"landBiomes": ["starter"],
|
||||
"seaBiomes": ["starter"],
|
||||
"shoreBiomes": ["starter"]
|
||||
"landBiomes": [{"biome": "starter", "weight": 1}],
|
||||
"seaBiomes": [{"biome": "starter", "weight": 1}],
|
||||
"shoreBiomes": [{"biome": "starter", "weight": 1}]
|
||||
}
|
||||
""", StandardCharsets.UTF_8);
|
||||
Files.writeString(stage.resolve("biomes/starter.json"), """
|
||||
|
||||
@@ -20,6 +20,7 @@ package art.arcane.iris.core.studio.map;
|
||||
|
||||
import art.arcane.iris.engine.IrisComplex;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import com.volmit.world.Weighted;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -35,13 +36,13 @@ final class ChildPicks {
|
||||
List<ChildPick> picks = new ArrayList<>();
|
||||
IrisBiome parent = biome;
|
||||
for (int level = 0; level < IrisComplex.CHILD_PICK_LEVELS && !parent.getChildren().isEmpty(); level++) {
|
||||
List<IrisBiome> slots = complex.childSlots(parent);
|
||||
if (slots.isEmpty()) {
|
||||
List<Weighted<IrisBiome>> options = complex.childOptions(parent);
|
||||
if (options.isEmpty()) {
|
||||
break;
|
||||
}
|
||||
double noise = complex.childNoise(parent).noiseFast2D(x, z);
|
||||
IrisBiome picked = slots.get(slotIndex(noise, slots.size())).withInferredType(parent.getInferredType());
|
||||
ChildPick pick = new ChildPick(parent, slots, noise, picked);
|
||||
IrisBiome picked = Weighted.pick(options, noise, IrisComplex.CHILD_EDGE).withInferredType(parent.getInferredType());
|
||||
ChildPick pick = new ChildPick(parent, options, noise, picked);
|
||||
picks.add(pick);
|
||||
if (pick.kept()) {
|
||||
break;
|
||||
@@ -57,17 +58,8 @@ final class ChildPicks {
|
||||
return picks.isEmpty() ? listNoise : picks.getLast().noise();
|
||||
}
|
||||
|
||||
/** The slot the child noise picks, rounded the way {@code CNG.fit2D} rounds. */
|
||||
static int slotIndex(double noise, int slotCount) {
|
||||
if (slotCount == 1) {
|
||||
return 0;
|
||||
}
|
||||
long rounded = Math.round(noise * (slotCount - 1));
|
||||
return (int) Math.clamp(rounded, 0, slotCount - 1);
|
||||
}
|
||||
|
||||
/** One level of children: the parent's slots, the noise that read them, and the biome it picked. */
|
||||
record ChildPick(IrisBiome parent, List<IrisBiome> slots, double noise, IrisBiome picked) {
|
||||
/** One level of children: the parent's weighted list, the noise that read it, and the biome it picked. */
|
||||
record ChildPick(IrisBiome parent, List<Weighted<IrisBiome>> options, double noise, IrisBiome picked) {
|
||||
boolean kept() {
|
||||
return Objects.equals(picked.getLoadKey(), parent.getLoadKey());
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.object.world.biome.InferredType;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.world.region.IrisRegion;
|
||||
import com.volmit.world.Weighted;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
@@ -62,7 +63,7 @@ public final class MapPickInspection {
|
||||
if (complex.getFocusRegion() != null) {
|
||||
return new Inspection("One region is focused", List.of());
|
||||
}
|
||||
SpreadCounter regions = new SpreadCounter("Region noise", MapPickPath.regionBands(engine));
|
||||
SpreadCounter regions = new SpreadCounter("Region noise", MapPickPath.regionBands(engine), Weighted.Edge.EARLIER);
|
||||
area.forEachSpot((x, z) -> {
|
||||
if (complex.getImageMapRuntime().sampleRegion(x, z) == null) {
|
||||
regions.add(complex.getRegionStyleStream().get(x, z));
|
||||
@@ -172,7 +173,7 @@ public final class MapPickInspection {
|
||||
private SpreadCounter listCounter(InferredType list) {
|
||||
String name = MapPickPath.listName(list);
|
||||
String title = Character.toUpperCase(name.charAt(0)) + name.substring(1) + " biome noise";
|
||||
return new SpreadCounter(title, MapPickPath.biomeBands(engine, view, region, list));
|
||||
return new SpreadCounter(title, MapPickPath.biomeBands(engine, view, region, list), Weighted.Edge.EARLIER);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,7 +203,8 @@ public final class MapPickInspection {
|
||||
|
||||
private SpreadCounter counterOf(ChildPicks.ChildPick pick) {
|
||||
return new SpreadCounter(pick.parent().getName() + " child noise",
|
||||
MapPickPath.slotBands(pick.slots(), slot -> MapPickPath.biomeLabel(engine, view, slot)));
|
||||
MapPickPath.weightBands(pick.options(), option -> MapPickPath.biomeLabel(engine, view, option)),
|
||||
IrisComplex.CHILD_EDGE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,13 +212,15 @@ public final class MapPickInspection {
|
||||
private static final class SpreadCounter {
|
||||
private final String title;
|
||||
private final List<MapPickPath.PickBand> bands;
|
||||
private final Weighted.Edge edge;
|
||||
private final long[] histogram = new long[HISTOGRAM_BINS];
|
||||
private final long[] samplesByBand;
|
||||
private long samples;
|
||||
|
||||
private SpreadCounter(String title, List<MapPickPath.PickBand> bands) {
|
||||
private SpreadCounter(String title, List<MapPickPath.PickBand> bands, Weighted.Edge edge) {
|
||||
this.title = title;
|
||||
this.bands = bands;
|
||||
this.edge = edge;
|
||||
this.samplesByBand = new long[bands.size()];
|
||||
}
|
||||
|
||||
@@ -248,10 +252,12 @@ public final class MapPickInspection {
|
||||
return samples == 0 ? 0D : count / (double) samples;
|
||||
}
|
||||
|
||||
// The generator gives values below 0 the first option and values above 1 the last, as these bands do.
|
||||
// The generator gives values below 0 the first option and values above 1 the last, as these bands do; a value
|
||||
// on the edge between two bands goes where the list's edge rule sends it.
|
||||
private int bandIndexOf(double noise) {
|
||||
for (int index = 0; index < bands.size(); index++) {
|
||||
if (noise <= bands.get(index).to()) {
|
||||
double to = bands.get(index).to();
|
||||
if (edge == Weighted.Edge.EARLIER ? noise <= to : noise < to) {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,10 +21,11 @@ package art.arcane.iris.core.studio.map;
|
||||
import art.arcane.iris.engine.IrisComplex;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.render.RenderType;
|
||||
import art.arcane.iris.engine.object.value.IRare;
|
||||
import art.arcane.iris.engine.object.world.biome.InferredType;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.world.region.IrisRegion;
|
||||
import art.arcane.iris.engine.object.world.region.IrisRegionEntry;
|
||||
import com.volmit.world.Weighted;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -93,13 +94,13 @@ public final class MapPickPath {
|
||||
|
||||
/** Each of the dimension's regions' share of the region noise. */
|
||||
static List<PickBand> regionBands(Engine engine) {
|
||||
List<IrisRegion> regions = engine.getData().getRegionLoader().loadAll(engine.getDimension().getRegions());
|
||||
return rarityBands(regions, region -> MapLabel.of(engine, region));
|
||||
List<Weighted<IrisRegion>> regions = IrisRegionEntry.load(engine.getDimension().getRegions(), engine.getData().getRegionLoader());
|
||||
return weightBands(regions, region -> MapLabel.of(engine, region));
|
||||
}
|
||||
|
||||
/** Each biome of the region's list of this type's share of the list's noise; empty when the list is. */
|
||||
static List<PickBand> biomeBands(Engine engine, MapView view, IrisRegion region, InferredType type) {
|
||||
return rarityBands(engine.getComplex().pickableBiomes(region, type), biome -> biomeLabel(engine, view, biome));
|
||||
return weightBands(engine.getComplex().pickableBiomes(region, type), biome -> biomeLabel(engine, view, biome));
|
||||
}
|
||||
|
||||
// The base biome: the noise picks from the land or sea list the continent noise chose, then children replace it.
|
||||
@@ -126,14 +127,14 @@ public final class MapPickPath {
|
||||
private static IrisBiome addListStep(List<PickStep> path, Engine engine, MapView view, IrisRegion region,
|
||||
InferredType type, double x, double z) {
|
||||
IrisComplex complex = engine.getComplex();
|
||||
List<IrisBiome> options = complex.pickableBiomes(region, type);
|
||||
List<Weighted<IrisBiome>> options = complex.pickableBiomes(region, type);
|
||||
if (options.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
double noise = complex.biomePickNoise(region, type).get(x, z);
|
||||
IrisBiome picked = IRare.pick(options, noise);
|
||||
IrisBiome picked = Weighted.pick(options, noise, Weighted.Edge.EARLIER);
|
||||
path.add(new PickStep(Kind.BIOME, biomeLabel(engine, view, picked), listName(type), null,
|
||||
noise, rarityBands(options, option -> biomeLabel(engine, view, option))));
|
||||
noise, weightBands(options, option -> biomeLabel(engine, view, option))));
|
||||
return picked;
|
||||
}
|
||||
|
||||
@@ -141,38 +142,21 @@ public final class MapPickPath {
|
||||
for (ChildPicks.ChildPick pick : ChildPicks.from(engine.getComplex(), biome, x, z)) {
|
||||
path.add(new PickStep(Kind.CHILD, biomeLabel(engine, view, pick.picked()), null,
|
||||
pick.kept() ? null : pick.parent().getName(), pick.noise(),
|
||||
slotBands(pick.slots(), option -> biomeLabel(engine, view, option))));
|
||||
weightBands(pick.options(), option -> biomeLabel(engine, view, option))));
|
||||
}
|
||||
}
|
||||
|
||||
/** Each option's share of the noise, 1 / rarity wide, in the order {@link IRare#pick} walks them. */
|
||||
static <T> List<PickBand> rarityBands(List<T> options, Function<T, MapLabel> label) {
|
||||
double total = options.stream().mapToDouble(option -> 1D / IRare.get(option)).sum();
|
||||
/** Each entry's share of the noise, as wide as its weight, in the order {@link Weighted#pick} walks them. */
|
||||
static <T> List<PickBand> weightBands(List<Weighted<T>> entries, Function<T, MapLabel> label) {
|
||||
int totalWeight = Weighted.totalWeight(entries);
|
||||
List<PickBand> bands = new ArrayList<>();
|
||||
double from = 0D;
|
||||
for (int index = 0; index < options.size(); index++) {
|
||||
T option = options.get(index);
|
||||
double to = index == options.size() - 1 ? 1D : from + 1D / IRare.get(option) / total;
|
||||
bands.add(new PickBand(label.apply(option), from, to));
|
||||
from = to;
|
||||
}
|
||||
return bands;
|
||||
}
|
||||
|
||||
/** Each slot's share of the child noise, neighbouring slots of one biome joined into one band. */
|
||||
static <T> List<PickBand> slotBands(List<T> slots, Function<T, MapLabel> label) {
|
||||
List<PickBand> bands = new ArrayList<>();
|
||||
int last = slots.size() - 1;
|
||||
for (int index = 0; index <= last; index++) {
|
||||
double from = index == 0 ? 0D : (index - 0.5D) / last;
|
||||
double to = index == last ? 1D : (index + 0.5D) / last;
|
||||
MapLabel option = label.apply(slots.get(index));
|
||||
PickBand previous = bands.isEmpty() ? null : bands.getLast();
|
||||
if (previous != null && previous.option().key().equals(option.key())) {
|
||||
bands.set(bands.size() - 1, new PickBand(option, previous.from(), to));
|
||||
} else {
|
||||
bands.add(new PickBand(option, from, to));
|
||||
}
|
||||
int weightBefore = 0;
|
||||
for (int index = 0; index < entries.size(); index++) {
|
||||
Weighted<T> entry = entries.get(index);
|
||||
int weightUpToHere = weightBefore + entry.weight();
|
||||
double to = index == entries.size() - 1 ? 1D : (double) weightUpToHere / totalWeight;
|
||||
bands.add(new PickBand(label.apply(entry.value()), (double) weightBefore / totalWeight, to));
|
||||
weightBefore = weightUpToHere;
|
||||
}
|
||||
return bands;
|
||||
}
|
||||
|
||||
@@ -25,11 +25,13 @@ import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.image.IrisImageMapRuntime;
|
||||
import art.arcane.iris.engine.object.world.biome.InferredType;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiomeEntry;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiomeGeneratorLink;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.engine.object.terrain.IrisGenerator;
|
||||
import art.arcane.iris.engine.object.noise.IrisInterpolator;
|
||||
import art.arcane.iris.engine.object.world.region.IrisRegion;
|
||||
import art.arcane.iris.engine.object.world.region.IrisRegionEntry;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.spi.PlatformBiome;
|
||||
@@ -42,6 +44,7 @@ import art.arcane.iris.util.project.interpolation.NoiseBoundsProvider;
|
||||
import art.arcane.iris.util.project.noise.CNG;
|
||||
import art.arcane.iris.util.project.stream.ProceduralStream;
|
||||
import art.arcane.iris.util.project.stream.interpolation.Interpolated;
|
||||
import com.volmit.world.Weighted;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@@ -84,6 +87,8 @@ public class IrisComplex implements DataProvider {
|
||||
/** How many levels of children a biome can be replaced through, parent first. */
|
||||
public static final int CHILD_PICK_LEVELS = DEEPEST_CHILD_LEVEL + 1;
|
||||
private static final int CHILD_NOISE_SIGNATURE = 123;
|
||||
/** Noise lying exactly between two children goes to the later one; region and biome lists give it to the earlier. */
|
||||
public static final Weighted.Edge CHILD_EDGE = Weighted.Edge.LATER;
|
||||
private static final InferredType[] INFERRED_BIOME_PREPARATION_ORDER = {
|
||||
InferredType.LAND,
|
||||
InferredType.CAVE,
|
||||
@@ -134,8 +139,6 @@ public class IrisComplex implements DataProvider {
|
||||
// Copy-on-write: reads happen per column on every burst thread; the synchronizedMap
|
||||
// monitor was taken on every HIT. Writes are once per biome and bounded, so a fresh map
|
||||
// per insert is cheap. Identity keying is load-bearing (IrisBiome is mutable/value-hashed).
|
||||
private volatile IdentityHashMap<IrisBiome, ChildSelectionPlan> childSelectionPlans = new IdentityHashMap<>();
|
||||
private final Object childSelectionPlanLock = new Object();
|
||||
|
||||
public IrisComplex(Engine engine) {
|
||||
this(engine, false);
|
||||
@@ -167,7 +170,7 @@ public class IrisComplex implements DataProvider {
|
||||
prepareInferredBiomes(focusRegion, regionsToPrepare);
|
||||
focusRegion.getAllBiomes(this).forEach(this::registerGenerators);
|
||||
} else {
|
||||
engine.getDimension().getRegions().forEach(regionKey -> {
|
||||
engine.getDimension().getRegionKeys().forEach(regionKey -> {
|
||||
IrisRegion region = data.getRegionLoader().load(regionKey);
|
||||
if (region == null) {
|
||||
return;
|
||||
@@ -220,7 +223,7 @@ public class IrisComplex implements DataProvider {
|
||||
ProceduralStream.of((x, z) -> focusRegion,
|
||||
Interpolated.of(a -> 0D, a -> focusRegion))
|
||||
: regionStyleStream
|
||||
.selectRarity(data.getRegionLoader().loadAll(engine.getDimension().getRegions()))
|
||||
.selectWeighted(IrisRegionEntry.load(engine.getDimension().getRegions(), data.getRegionLoader()))
|
||||
.cache2D("regionStream", engine, cacheSize);
|
||||
regionStream = focusRegion != null ? proceduralRegionStream : proceduralRegionStream
|
||||
.convertAware2D((region, x, z) -> {
|
||||
@@ -375,9 +378,9 @@ public class IrisComplex implements DataProvider {
|
||||
|
||||
String key = UUID.randomUUID().toString();
|
||||
IrisRegion region = new IrisRegion();
|
||||
region.getLandBiomes().add(focus.getLoadKey());
|
||||
region.getSeaBiomes().add(focus.getLoadKey());
|
||||
region.getShoreBiomes().add(focus.getLoadKey());
|
||||
region.getLandBiomes().add(new IrisBiomeEntry(focus.getLoadKey(), 1));
|
||||
region.getSeaBiomes().add(new IrisBiomeEntry(focus.getLoadKey(), 1));
|
||||
region.getShoreBiomes().add(new IrisBiomeEntry(focus.getLoadKey(), 1));
|
||||
region.setLoadKey(key);
|
||||
region.setLoader(data);
|
||||
region.setLoadFile(new File(data.getDataFolder(), data.getRegionLoader().getFolderName() + "/" + key + ".json"));
|
||||
@@ -547,10 +550,10 @@ public class IrisComplex implements DataProvider {
|
||||
}
|
||||
|
||||
private void prepareInferredBiomes(IrisRegion region, KList<IrisRegion> preparedRegions) {
|
||||
loadInferredBiomes(region.getLandBiomes(), InferredType.LAND);
|
||||
loadInferredBiomes(region.getCaveBiomes(), InferredType.CAVE);
|
||||
loadInferredBiomes(region.getSeaBiomes(), InferredType.SEA);
|
||||
loadInferredBiomes(region.getShoreBiomes(), InferredType.SHORE);
|
||||
pickableBiomes(region, InferredType.LAND);
|
||||
pickableBiomes(region, InferredType.CAVE);
|
||||
pickableBiomes(region, InferredType.SEA);
|
||||
pickableBiomes(region, InferredType.SHORE);
|
||||
preparedRegions.add(region);
|
||||
}
|
||||
|
||||
@@ -589,7 +592,7 @@ public class IrisComplex implements DataProvider {
|
||||
InferredType inferredType,
|
||||
IrisBiome emptyBiome
|
||||
) {
|
||||
ProceduralStream<IrisBiome> picked = pickNoise.selectRarity(pickableBiomes(region, inferredType));
|
||||
ProceduralStream<IrisBiome> picked = pickNoise.selectWeighted(pickableBiomes(region, inferredType));
|
||||
return inferredType == InferredType.CAVE ? picked.onNull(emptyBiome) : picked;
|
||||
}
|
||||
|
||||
@@ -633,44 +636,40 @@ public class IrisComplex implements DataProvider {
|
||||
|
||||
/**
|
||||
* The noise that picks one of the region's biomes of this type, from 0 to 1; {@link #pickableBiomes} split it by
|
||||
* rarity. The biome streams pick from this very stream.
|
||||
* weight. The biome streams pick from this very stream.
|
||||
*/
|
||||
public ProceduralStream<Double> biomePickNoise(IrisRegion region, InferredType inferredType) {
|
||||
return preparedInferredBiomeStream(inferredPickNoiseStreams, region, inferredType);
|
||||
}
|
||||
|
||||
/** The region's biomes of this type, in the order their rarities split {@link #biomePickNoise}. */
|
||||
public KList<IrisBiome> pickableBiomes(IrisRegion region, InferredType inferredType) {
|
||||
KList<String> keys = switch (inferredType) {
|
||||
/** The region's biomes of this type with their weights, in the order they split {@link #biomePickNoise}. */
|
||||
public KList<Weighted<IrisBiome>> pickableBiomes(IrisRegion region, InferredType inferredType) {
|
||||
List<IrisBiomeEntry> entries = switch (inferredType) {
|
||||
case CAVE -> region.getCaveBiomes();
|
||||
case LAND -> region.getLandBiomes();
|
||||
case SEA -> region.getSeaBiomes();
|
||||
case SHORE -> region.getShoreBiomes();
|
||||
};
|
||||
return loadInferredBiomes(keys, inferredType);
|
||||
KList<Weighted<IrisBiome>> inferred = new KList<>();
|
||||
for (Weighted<IrisBiome> entry : IrisBiomeEntry.load(entries, data.getBiomeLoader())) {
|
||||
inferred.add(new Weighted<>(entry.value().withInferredType(inferredType), entry.weight()));
|
||||
}
|
||||
return inferred;
|
||||
}
|
||||
|
||||
/**
|
||||
* The slots a biome's child noise picks from, in noise order: its children and itself, each as often as its rarity
|
||||
* allows. Slot {@code i} of {@code n} is picked where {@link #childNoise} rounds to {@code i / (n - 1)}.
|
||||
* What a biome's child noise picks from, with weights, in noise order: its children, and itself where it is listed
|
||||
* among them.
|
||||
*/
|
||||
public List<IrisBiome> childSlots(IrisBiome parent) {
|
||||
return List.of(resolveChildSelectionPlan(parent).mappedBiomes);
|
||||
public KList<Weighted<IrisBiome>> childOptions(IrisBiome parent) {
|
||||
return parent.getChildOptions(this);
|
||||
}
|
||||
|
||||
/** The noise that picks among {@link #childSlots}, read with {@link CNG#noiseFast2D}. */
|
||||
/** The noise that picks among {@link #childOptions}, read with {@link CNG#noiseFast2D}. */
|
||||
public CNG childNoise(IrisBiome parent) {
|
||||
return parent.getChildrenGenerator(rng, CHILD_NOISE_SIGNATURE, parent.getChildShrinkFactor());
|
||||
}
|
||||
|
||||
private KList<IrisBiome> loadInferredBiomes(KList<String> keys, InferredType type) {
|
||||
KList<IrisBiome> inferred = new KList<>();
|
||||
for (IrisBiome biome : data.getBiomeLoader().loadAll(keys)) {
|
||||
inferred.add(biome.withInferredType(type));
|
||||
}
|
||||
return inferred;
|
||||
}
|
||||
|
||||
private void registerGenerators(IrisBiome biome) {
|
||||
generatorBiomes.add(biome);
|
||||
biome.getGenerators().forEach(c -> registerGenerator(c.getCachedGenerator(this)));
|
||||
@@ -796,39 +795,12 @@ public class IrisComplex implements DataProvider {
|
||||
return b;
|
||||
}
|
||||
|
||||
CNG childCell = childNoise(b);
|
||||
ChildSelectionPlan childSelectionPlan = resolveChildSelectionPlan(b);
|
||||
IrisBiome biome = childSelectionPlan.select(childCell, x, z).withInferredType(b.getInferredType());
|
||||
return implode(biome, x, z, max - 1);
|
||||
}
|
||||
|
||||
private ChildSelectionPlan resolveChildSelectionPlan(IrisBiome biome) {
|
||||
ChildSelectionPlan cachedPlan = childSelectionPlans.get(biome);
|
||||
if (cachedPlan != null) {
|
||||
return cachedPlan;
|
||||
IrisBiome picked = Weighted.pick(childOptions(b), childNoise(b).noiseFast2D(x, z), CHILD_EDGE);
|
||||
if (picked == null) {
|
||||
return b;
|
||||
}
|
||||
|
||||
synchronized (childSelectionPlanLock) {
|
||||
ChildSelectionPlan synchronizedPlan = childSelectionPlans.get(biome);
|
||||
if (synchronizedPlan != null) {
|
||||
return synchronizedPlan;
|
||||
}
|
||||
|
||||
KList<IrisBiome> children = biome.getRealChildren(this);
|
||||
KList<IrisBiome> options = new KList<>();
|
||||
for (IrisBiome child : children) {
|
||||
if (child != null) {
|
||||
options.add(child);
|
||||
}
|
||||
}
|
||||
options.add(biome);
|
||||
|
||||
ChildSelectionPlan createdPlan = ChildSelectionPlan.create(options);
|
||||
IdentityHashMap<IrisBiome, ChildSelectionPlan> next = new IdentityHashMap<>(childSelectionPlans);
|
||||
next.put(biome, createdPlan);
|
||||
childSelectionPlans = next;
|
||||
return createdPlan;
|
||||
}
|
||||
return implode(picked.withInferredType(b.getInferredType()), x, z, max - 1);
|
||||
}
|
||||
|
||||
private static class GeneratorBounds {
|
||||
@@ -1051,78 +1023,6 @@ public class IrisComplex implements DataProvider {
|
||||
}
|
||||
}
|
||||
|
||||
static final class ChildSelectionPlan {
|
||||
private final IrisBiome[] mappedBiomes;
|
||||
private final int maxIndex;
|
||||
|
||||
private ChildSelectionPlan(IrisBiome[] mappedBiomes) {
|
||||
this.mappedBiomes = mappedBiomes;
|
||||
this.maxIndex = mappedBiomes.length - 1;
|
||||
}
|
||||
|
||||
static ChildSelectionPlan create(KList<IrisBiome> options) {
|
||||
if (options.isEmpty()) {
|
||||
return new ChildSelectionPlan(new IrisBiome[0]);
|
||||
}
|
||||
|
||||
int maxRarity = 1;
|
||||
for (IrisBiome biome : options) {
|
||||
if (biome != null && biome.getRarity() > maxRarity) {
|
||||
maxRarity = biome.getRarity();
|
||||
}
|
||||
}
|
||||
|
||||
int rarityMax = maxRarity + 1;
|
||||
boolean flip = false;
|
||||
KList<IrisBiome> mapped = new KList<>();
|
||||
for (IrisBiome biome : options) {
|
||||
if (biome == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int rarity = Math.max(1, biome.getRarity());
|
||||
int count = rarityMax - rarity;
|
||||
for (int index = 0; index < count; index++) {
|
||||
flip = !flip;
|
||||
if (flip) {
|
||||
mapped.add(biome);
|
||||
} else {
|
||||
mapped.add(0, biome);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (mapped.isEmpty()) {
|
||||
IrisBiome[] fallback = new IrisBiome[]{options.get(0)};
|
||||
return new ChildSelectionPlan(fallback);
|
||||
}
|
||||
|
||||
IrisBiome[] mappedBiomes = mapped.toArray(new IrisBiome[0]);
|
||||
return new ChildSelectionPlan(mappedBiomes);
|
||||
}
|
||||
|
||||
IrisBiome select(CNG childCell, double x, double z) {
|
||||
if (mappedBiomes.length == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (mappedBiomes.length == 1) {
|
||||
return mappedBiomes[0];
|
||||
}
|
||||
|
||||
int selectedIndex = childCell.fit2D(0, maxIndex, x, z);
|
||||
if (selectedIndex < 0) {
|
||||
return mappedBiomes[0];
|
||||
}
|
||||
|
||||
if (selectedIndex > maxIndex) {
|
||||
return mappedBiomes[maxIndex];
|
||||
}
|
||||
|
||||
return mappedBiomes[selectedIndex];
|
||||
}
|
||||
}
|
||||
|
||||
record GeneratorGroup(IrisInterpolator interpolator, IrisGenerator[] generators) {
|
||||
}
|
||||
|
||||
|
||||
@@ -6,10 +6,12 @@ import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.image.IrisImageMapRuntime;
|
||||
import art.arcane.iris.engine.object.world.biome.InferredType;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiomeEntry;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.engine.object.terrain.IrisGenerator;
|
||||
import art.arcane.iris.engine.object.noise.IrisInterpolator;
|
||||
import art.arcane.iris.engine.object.world.region.IrisRegion;
|
||||
import art.arcane.iris.engine.object.world.region.IrisRegionEntry;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiomeGeneratorLink;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
@@ -19,6 +21,7 @@ import art.arcane.iris.util.project.interpolation.NoiseBounds;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.util.project.stream.ProceduralStream;
|
||||
import art.arcane.iris.util.project.stream.interpolation.Interpolated;
|
||||
import com.volmit.world.Weighted;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
@@ -91,9 +94,7 @@ public class UpperDimensionContext implements DataProvider {
|
||||
|
||||
Map<IrisInterpolator, Set<IrisGenerator>> generators = new HashMap<>();
|
||||
Set<IrisBiome> allBiomes = Collections.newSetFromMap(new IdentityHashMap<>());
|
||||
Map<IrisBiome, IrisComplex.ChildSelectionPlan> childSelectionPlans =
|
||||
Collections.synchronizedMap(new IdentityHashMap<>());
|
||||
upperDim.getRegions().forEach(regionKey -> {
|
||||
upperDim.getRegionKeys().forEach(regionKey -> {
|
||||
IrisRegion region = upperData.getRegionLoader().load(regionKey);
|
||||
if (region != null) {
|
||||
region.getAllBiomes(dataProvider).forEach(biome -> registerBiomeGenerators(
|
||||
@@ -132,7 +133,7 @@ public class UpperDimensionContext implements DataProvider {
|
||||
.create(rng.nextParallelRNG(883), upperData).stream()
|
||||
.zoom(upperDim.getRegionZoom());
|
||||
ProceduralStream<IrisRegion> proceduralRegionStream = regionStyleStream
|
||||
.selectRarity(upperData.getRegionLoader().loadAll(upperDim.getRegions()));
|
||||
.selectWeighted(IrisRegionEntry.load(upperDim.getRegions(), upperData.getRegionLoader()));
|
||||
ProceduralStream<IrisRegion> regionStream = proceduralRegionStream
|
||||
.convertAware2D((region, x, z) -> mappedRegion(imageMapRuntime, region, x, z))
|
||||
.cache2D("upperImageMappedRegionStream", engine, cacheSize);
|
||||
@@ -143,7 +144,7 @@ public class UpperDimensionContext implements DataProvider {
|
||||
.zoom(upperDim.getBiomeZoom())
|
||||
.zoom(upperDim.getLandZoom())
|
||||
.zoom(r.getLandBiomeZoom())
|
||||
.selectRarity(loadInferredBiomes(upperData, r.getLandBiomes(), InferredType.LAND)))
|
||||
.selectWeighted(loadInferredBiomes(upperData, r.getLandBiomes(), InferredType.LAND)))
|
||||
.convertAware2D(ProceduralStream::get);
|
||||
ProceduralStream<IrisBiome> seaBiomeStream = regionStream
|
||||
.convert(r -> upperDim.getSeaBiomeStyle()
|
||||
@@ -151,14 +152,14 @@ public class UpperDimensionContext implements DataProvider {
|
||||
.zoom(upperDim.getBiomeZoom())
|
||||
.zoom(upperDim.getSeaZoom())
|
||||
.zoom(r.getSeaBiomeZoom())
|
||||
.selectRarity(loadInferredBiomes(upperData, r.getSeaBiomes(), InferredType.SEA)))
|
||||
.selectWeighted(loadInferredBiomes(upperData, r.getSeaBiomes(), InferredType.SEA)))
|
||||
.convertAware2D(ProceduralStream::get);
|
||||
ProceduralStream<IrisBiome> shoreBiomeStream = regionStream
|
||||
.convert(r -> upperDim.getShoreBiomeStyle()
|
||||
.create(rng.nextParallelRNG(InferredType.SHORE.ordinal()), upperData).stream()
|
||||
.zoom(upperDim.getBiomeZoom())
|
||||
.zoom(r.getShoreBiomeZoom())
|
||||
.selectRarity(loadInferredBiomes(upperData, r.getShoreBiomes(), InferredType.SHORE)))
|
||||
.selectWeighted(loadInferredBiomes(upperData, r.getShoreBiomes(), InferredType.SHORE)))
|
||||
.convertAware2D(ProceduralStream::get);
|
||||
|
||||
Map<InferredType, ProceduralStream<IrisBiome>> inferredStreams = new HashMap<>();
|
||||
@@ -175,7 +176,7 @@ public class UpperDimensionContext implements DataProvider {
|
||||
return stream != null ? stream.get(x, z) : inferredStreams.get(InferredType.LAND).get(x, z);
|
||||
})
|
||||
.convertAware2D((biome, x, z) -> implode(
|
||||
biome, x, z, rng, dataProvider, childSelectionPlans, 3));
|
||||
biome, x, z, rng, dataProvider, 3));
|
||||
ProceduralStream<IrisBiome> baseBiomeStream = proceduralBaseBiomeStream
|
||||
.convertAware2D((biome, x, z) -> mappedBiome(imageMapRuntime, biome, x, z))
|
||||
.cache2D("upperImageMappedBaseBiomeStream", engine, cacheSize);
|
||||
@@ -268,7 +269,7 @@ public class UpperDimensionContext implements DataProvider {
|
||||
shoreBiomeStream);
|
||||
return resolved == baseBiome
|
||||
? baseBiome
|
||||
: implode(resolved, x, z, rng, dataProvider, childSelectionPlans, 3);
|
||||
: implode(resolved, x, z, rng, dataProvider, 3);
|
||||
}).cache2D("upperImageMappedFinalBiomeStream", engine, cacheSize);
|
||||
|
||||
return new UpperDimensionContext(new ContextState(
|
||||
@@ -337,10 +338,10 @@ public class UpperDimensionContext implements DataProvider {
|
||||
return mappedBlock == null ? proceduralBlock : mappedBlock;
|
||||
}
|
||||
|
||||
private static KList<IrisBiome> loadInferredBiomes(IrisData data, KList<String> keys, InferredType type) {
|
||||
KList<IrisBiome> inferred = new KList<>();
|
||||
for (IrisBiome biome : data.getBiomeLoader().loadAll(keys)) {
|
||||
inferred.add(biome.withInferredType(type));
|
||||
private static KList<Weighted<IrisBiome>> loadInferredBiomes(IrisData data, KList<IrisBiomeEntry> entries, InferredType type) {
|
||||
KList<Weighted<IrisBiome>> inferred = new KList<>();
|
||||
for (Weighted<IrisBiome> entry : IrisBiomeEntry.load(entries, data.getBiomeLoader())) {
|
||||
inferred.add(new Weighted<>(entry.value().withInferredType(type), entry.weight()));
|
||||
}
|
||||
return inferred;
|
||||
}
|
||||
@@ -351,33 +352,15 @@ public class UpperDimensionContext implements DataProvider {
|
||||
double z,
|
||||
RNG rng,
|
||||
DataProvider dataProvider,
|
||||
Map<IrisBiome, IrisComplex.ChildSelectionPlan> childSelectionPlans,
|
||||
int remainingDepth
|
||||
) {
|
||||
if (biome == null || remainingDepth < 0 || biome.getChildren().isEmpty()) {
|
||||
return biome;
|
||||
}
|
||||
|
||||
IrisComplex.ChildSelectionPlan selectionPlan = childSelectionPlans.get(biome);
|
||||
if (selectionPlan == null) {
|
||||
synchronized (childSelectionPlans) {
|
||||
selectionPlan = childSelectionPlans.get(biome);
|
||||
if (selectionPlan == null) {
|
||||
KList<IrisBiome> options = new KList<>();
|
||||
for (IrisBiome child : biome.getRealChildren(dataProvider)) {
|
||||
if (child != null) {
|
||||
options.add(child);
|
||||
}
|
||||
}
|
||||
options.add(biome);
|
||||
selectionPlan = IrisComplex.ChildSelectionPlan.create(options);
|
||||
childSelectionPlans.put(biome, selectionPlan);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IrisBiome selected = selectionPlan.select(
|
||||
biome.getChildrenGenerator(rng, 123, biome.getChildShrinkFactor()), x, z);
|
||||
IrisBiome selected = Weighted.pick(biome.getChildOptions(dataProvider),
|
||||
biome.getChildrenGenerator(rng, 123, biome.getChildShrinkFactor()).noiseFast2D(x, z),
|
||||
IrisComplex.CHILD_EDGE);
|
||||
if (selected == null) {
|
||||
return biome;
|
||||
}
|
||||
@@ -387,7 +370,6 @@ public class UpperDimensionContext implements DataProvider {
|
||||
z,
|
||||
rng,
|
||||
dataProvider,
|
||||
childSelectionPlans,
|
||||
remainingDepth - 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -345,7 +345,7 @@ public interface Engine extends DataProvider, Fallible, BlockUpdater, Renderer,
|
||||
if (focusRegion != null) {
|
||||
return focusRegion.getLoadKey().equals(region.getLoadKey());
|
||||
}
|
||||
return getDimension().getRegions().contains(region.getLoadKey());
|
||||
return getDimension().getRegionKeys().contains(region.getLoadKey());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import art.arcane.iris.core.IrisSettings;
|
||||
import art.arcane.iris.core.modules.ModuleServices;
|
||||
import art.arcane.iris.engine.IrisComplex;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiomeEntry;
|
||||
import art.arcane.iris.engine.object.world.region.IrisRegion;
|
||||
import art.arcane.iris.util.common.parallel.BurstExecutor;
|
||||
import art.arcane.iris.util.common.parallel.MultiBurst;
|
||||
@@ -299,21 +300,21 @@ public final class HintedLocator<T> implements Locator<T> {
|
||||
|
||||
boolean hosted = false;
|
||||
|
||||
for (String root : region.getLandBiomes()) {
|
||||
for (String root : IrisBiomeEntry.keys(region.getLandBiomes())) {
|
||||
if (source.closureContains(root, biomeKey)) {
|
||||
landHosts.add(root);
|
||||
hosted = true;
|
||||
}
|
||||
}
|
||||
|
||||
for (String root : region.getSeaBiomes()) {
|
||||
for (String root : IrisBiomeEntry.keys(region.getSeaBiomes())) {
|
||||
if (source.closureContains(root, biomeKey)) {
|
||||
seaHosts.add(root);
|
||||
hosted = true;
|
||||
}
|
||||
}
|
||||
|
||||
for (String root : region.getShoreBiomes()) {
|
||||
for (String root : IrisBiomeEntry.keys(region.getShoreBiomes())) {
|
||||
if (source.closureContains(root, biomeKey)) {
|
||||
shoreHosts.add(root);
|
||||
hosted = true;
|
||||
@@ -324,7 +325,7 @@ public final class HintedLocator<T> implements Locator<T> {
|
||||
surfaceRegions.add(region.getLoadKey());
|
||||
}
|
||||
|
||||
if (region.getCaveBiomes().contains(biomeKey)) {
|
||||
if (IrisBiomeEntry.keys(region.getCaveBiomes()).contains(biomeKey)) {
|
||||
caveRegions.add(region.getLoadKey());
|
||||
}
|
||||
}
|
||||
@@ -355,7 +356,7 @@ public final class HintedLocator<T> implements Locator<T> {
|
||||
KSet<String> caveRegions = new KSet<>();
|
||||
|
||||
for (IrisRegion region : engine.getDimension().getAllRegions(engine)) {
|
||||
if (region != null && region.getCaveBiomes().contains(biomeKey)) {
|
||||
if (region != null && IrisBiomeEntry.keys(region.getCaveBiomes()).contains(biomeKey)) {
|
||||
caveRegions.add(region.getLoadKey());
|
||||
}
|
||||
}
|
||||
@@ -372,7 +373,7 @@ public final class HintedLocator<T> implements Locator<T> {
|
||||
return SearchPlan.unpruned();
|
||||
}
|
||||
|
||||
if (!engine.getDimension().getRegions().contains(regionKey)) {
|
||||
if (!engine.getDimension().getRegionKeys().contains(regionKey)) {
|
||||
return SearchPlan.impossible();
|
||||
}
|
||||
|
||||
@@ -410,21 +411,21 @@ public final class HintedLocator<T> implements Locator<T> {
|
||||
|
||||
boolean hosted = false;
|
||||
|
||||
for (String root : region.getLandBiomes()) {
|
||||
for (String root : IrisBiomeEntry.keys(region.getLandBiomes())) {
|
||||
if (source.closureContainsAny(root, placers.biomes())) {
|
||||
landHosts.add(root);
|
||||
hosted = true;
|
||||
}
|
||||
}
|
||||
|
||||
for (String root : region.getSeaBiomes()) {
|
||||
for (String root : IrisBiomeEntry.keys(region.getSeaBiomes())) {
|
||||
if (source.closureContainsAny(root, placers.biomes())) {
|
||||
seaHosts.add(root);
|
||||
hosted = true;
|
||||
}
|
||||
}
|
||||
|
||||
for (String root : region.getShoreBiomes()) {
|
||||
for (String root : IrisBiomeEntry.keys(region.getShoreBiomes())) {
|
||||
if (source.closureContainsAny(root, placers.biomes())) {
|
||||
shoreHosts.add(root);
|
||||
hosted = true;
|
||||
@@ -559,7 +560,7 @@ public final class HintedLocator<T> implements Locator<T> {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (String child : biome.getChildren()) {
|
||||
for (String child : biome.getChildKeys()) {
|
||||
if (child != null && !visited.contains(child)) {
|
||||
queue.add(child);
|
||||
}
|
||||
@@ -595,7 +596,7 @@ public final class HintedLocator<T> implements Locator<T> {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (String child : biome.getChildren()) {
|
||||
for (String child : biome.getChildKeys()) {
|
||||
if (child != null && !visited.contains(child)) {
|
||||
queue.add(child);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package art.arcane.iris.engine.image;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiomeEntry;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.engine.object.image.IrisImage;
|
||||
import art.arcane.iris.engine.object.image.IrisImageMap;
|
||||
@@ -299,13 +300,13 @@ public final class IrisImageMapRuntime {
|
||||
if (region == null) {
|
||||
continue;
|
||||
}
|
||||
if (region.getLandBiomes().contains(biomeKey)) {
|
||||
if (IrisBiomeEntry.keys(region.getLandBiomes()).contains(biomeKey)) {
|
||||
types.add(InferredType.LAND);
|
||||
}
|
||||
if (region.getSeaBiomes().contains(biomeKey)) {
|
||||
if (IrisBiomeEntry.keys(region.getSeaBiomes()).contains(biomeKey)) {
|
||||
types.add(InferredType.SEA);
|
||||
}
|
||||
if (region.getShoreBiomes().contains(biomeKey)) {
|
||||
if (IrisBiomeEntry.keys(region.getShoreBiomes()).contains(biomeKey)) {
|
||||
types.add(InferredType.SHORE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,97 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 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.engine.object.value;
|
||||
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.iris.util.project.stream.ProceduralStream;
|
||||
import art.arcane.iris.util.project.stream.interpolation.Interpolated;
|
||||
import java.util.List;
|
||||
|
||||
public interface IRare {
|
||||
static <T extends IRare> ProceduralStream<T> stream(ProceduralStream<Double> noise, List<T> possibilities) {
|
||||
return ProceduralStream.of((x, z) -> pick(possibilities, noise.get(x, z)),
|
||||
(x, y, z) -> pick(possibilities, noise.get(x, y, z)),
|
||||
new Interpolated<T>() {
|
||||
@Override
|
||||
public double toDouble(T t) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T fromDouble(double d) {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
static <T extends IRare> T pickSlowly(List<T> possibilities, double noiseValue) {
|
||||
if (possibilities.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (possibilities.size() == 1) {
|
||||
return possibilities.get(0);
|
||||
}
|
||||
|
||||
KList<T> rarityTypes = new KList<>();
|
||||
int totalRarity = 0;
|
||||
for (T i : possibilities) {
|
||||
totalRarity += IRare.get(i);
|
||||
}
|
||||
|
||||
for (T i : possibilities) {
|
||||
rarityTypes.addMultiple(i, totalRarity / IRare.get(i));
|
||||
}
|
||||
|
||||
return rarityTypes.get((int) (noiseValue * rarityTypes.last()));
|
||||
}
|
||||
|
||||
static <T extends IRare> T pick(List<T> possibilities, double noiseValue) {
|
||||
if (possibilities.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (possibilities.size() == 1) {
|
||||
return possibilities.getFirst();
|
||||
}
|
||||
|
||||
double total = 0;
|
||||
for (T i : possibilities) {
|
||||
total += 1d / IRare.get(i);
|
||||
}
|
||||
|
||||
double threshold = total * noiseValue;
|
||||
double buffer = 0;
|
||||
for (T i : possibilities) {
|
||||
buffer += 1d / IRare.get(i);
|
||||
if (buffer >= threshold) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return possibilities.getLast();
|
||||
}
|
||||
|
||||
static int get(Object v) {
|
||||
return v instanceof IRare ? Math.max(1, ((IRare) v).getRarity()) : 1;
|
||||
}
|
||||
|
||||
int getRarity();
|
||||
}
|
||||
@@ -20,7 +20,6 @@ package art.arcane.iris.engine.object.world.biome;
|
||||
|
||||
import art.arcane.iris.engine.object.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.engine.object.noise.NoiseStyle;
|
||||
import art.arcane.iris.engine.object.value.IRare;
|
||||
import art.arcane.iris.engine.object.world.biome.custom.IrisBiomeCustom;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.engine.framework.render.RenderType;
|
||||
@@ -33,10 +32,8 @@ import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.object.annotations.ArrayType;
|
||||
import art.arcane.iris.engine.object.annotations.DependsOn;
|
||||
import art.arcane.iris.engine.object.annotations.Desc;
|
||||
import art.arcane.iris.engine.object.annotations.MaxNumber;
|
||||
import art.arcane.iris.engine.object.annotations.MinNumber;
|
||||
import art.arcane.iris.engine.object.annotations.RegistryListBiome;
|
||||
import art.arcane.iris.engine.object.annotations.RegistryListResource;
|
||||
import art.arcane.iris.engine.object.annotations.Required;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.collection.KMap;
|
||||
@@ -45,6 +42,7 @@ import art.arcane.iris.util.common.data.DataProvider;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import art.arcane.iris.util.project.noise.CNG;
|
||||
import art.arcane.iris.util.project.context.IrisContext;
|
||||
import com.volmit.world.Weighted;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@@ -71,8 +69,10 @@ import java.util.Objects;
|
||||
@Desc("Represents a biome in iris. Biomes are placed inside of regions and hold objects.\nA biome consists of layers (block palletes), decorations, objects & generators.")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class IrisBiome extends IrisRegistrant implements IRare {
|
||||
public class IrisBiome extends IrisRegistrant {
|
||||
private static final int BIOME_GENERATOR_CACHE_SIZE = 8;
|
||||
// The seed once added the biome's rarity; the 1 keeps biomes that had the default rarity on their old scatter.
|
||||
private static final int BIOME_GENERATOR_SEED = 213949 + 228888 + 1;
|
||||
private static final int CHILDREN_SEED_SALT = 2137;
|
||||
|
||||
private final transient AtomicCache<KMap<String, IrisBiomeGeneratorLink>> genCache = new AtomicCache<>();
|
||||
@@ -87,7 +87,7 @@ public class IrisBiome extends IrisRegistrant implements IRare {
|
||||
@Getter(AccessLevel.NONE)
|
||||
@Setter(AccessLevel.NONE)
|
||||
private transient volatile SeededBiomeGenerator recentBiomeGenerator;
|
||||
private final transient AtomicCache<KList<IrisBiome>> realChildren = new AtomicCache<>();
|
||||
private final transient AtomicCache<KList<Weighted<IrisBiome>>> childOptions = new AtomicCache<>();
|
||||
private final transient AtomicCache<Biome> derivativeResolved = new AtomicCache<>();
|
||||
private final transient AtomicCache<Biome> vanillaDerivativeResolved = new AtomicCache<>();
|
||||
private final transient AtomicCache<KList<Biome>> biomeScatterResolved = new AtomicCache<>();
|
||||
@@ -102,10 +102,6 @@ public class IrisBiome extends IrisRegistrant implements IRare {
|
||||
@DependsOn({"biomeStyle", "biomeZoom", "biomeScatter"})
|
||||
@Desc("This changes the dispersion of the biome colors if multiple derivatives are chosen.")
|
||||
private IrisGeneratorStyle biomeStyle = NoiseStyle.SIMPLEX.style();
|
||||
@MinNumber(1)
|
||||
@MaxNumber(512)
|
||||
@Desc("The rarity of this biome (integer)")
|
||||
private int rarity = 1;
|
||||
@Desc("A color for visualizing this biome with a color. I.e. #F13AF5. This will show up on the map.")
|
||||
private String color = null;
|
||||
@Required
|
||||
@@ -130,10 +126,9 @@ public class IrisBiome extends IrisRegistrant implements IRare {
|
||||
@DependsOn({"children"})
|
||||
@Desc("If this biome has children biomes, and the gen layer chooses one of this biomes children, How will it be shaped?")
|
||||
private IrisGeneratorStyle childStyle = NoiseStyle.CELLULAR_IRIS_DOUBLE.style();
|
||||
@RegistryListResource(IrisBiome.class)
|
||||
@ArrayType(min = 1, type = String.class)
|
||||
@Desc("List any biome names (file names without.json) here as children. Portions of this biome can sometimes morph into their children. Iris supports cyclic relationships such as A > B > A > B. Iris will stop checking 4 biomes down the tree.")
|
||||
private KList<String> children = new KList<>();
|
||||
@ArrayType(min = 1, type = IrisBiomeEntry.class)
|
||||
@Desc("What portions of this biome turn into: the child noise picks along this list in the order it is written. List this biome itself where it should stay itself; a biome that isn't listed doesn't stay anywhere. Iris supports cyclic relationships such as A > B > A > B, and stops 4 levels down.")
|
||||
private KList<IrisBiomeEntry> children = new KList<>();
|
||||
@ArrayType(min = 1, type = IrisBiomeGeneratorLink.class)
|
||||
@Desc("Generators for this biome. Multiple generators with different interpolation sizes will mix with other biomes how you would expect. This defines your biome height relative to the fluid height. Use negative for oceans.")
|
||||
private KList<IrisBiomeGeneratorLink> generators = new KList<IrisBiomeGeneratorLink>().qadd(new IrisBiomeGeneratorLink());
|
||||
@@ -291,7 +286,7 @@ public class IrisBiome extends IrisRegistrant implements IRare {
|
||||
}
|
||||
|
||||
private CNG createBiomeGenerator(long seed, IrisData loader) {
|
||||
int signature = 213949 + 228888 + getRarity() + getName().length();
|
||||
int signature = BIOME_GENERATOR_SEED + getName().length();
|
||||
return biomeStyle.createNoCache(new RNG(seed).nextParallelRNG(signature), loader);
|
||||
}
|
||||
|
||||
@@ -343,26 +338,29 @@ public class IrisBiome extends IrisRegistrant implements IRare {
|
||||
return IrisBiomeDerivatives.getCustomBiome(this, rng, engine, x, y, z);
|
||||
}
|
||||
|
||||
public KList<IrisBiome> getRealChildren(DataProvider g) {
|
||||
return realChildren.aquire(() ->
|
||||
{
|
||||
KList<IrisBiome> realChildren = new KList<>();
|
||||
/**
|
||||
* The biomes this one turns into, leaving out the entries where it stays itself.
|
||||
*/
|
||||
public KList<String> getChildKeys() {
|
||||
KList<String> keys = IrisBiomeEntry.keys(getChildren());
|
||||
keys.removeIf(key -> key.equals(getLoadKey()));
|
||||
return keys;
|
||||
}
|
||||
|
||||
for (String i : getChildren()) {
|
||||
realChildren.add(g.getData().getBiomeLoader().load(i));
|
||||
}
|
||||
|
||||
return realChildren;
|
||||
});
|
||||
/**
|
||||
* What the child noise picks from, with weights, in noise order.
|
||||
*/
|
||||
public KList<Weighted<IrisBiome>> getChildOptions(DataProvider g) {
|
||||
return childOptions.aquire(() -> IrisBiomeEntry.load(getChildren(), g.getData().getBiomeLoader()));
|
||||
}
|
||||
|
||||
public KList<String> getAllChildren(DataProvider g, int limit) {
|
||||
KSet<String> m = new KSet<>();
|
||||
m.addAll(getChildren());
|
||||
m.addAll(getChildKeys());
|
||||
limit--;
|
||||
|
||||
if (limit > 0) {
|
||||
for (String i : getChildren()) {
|
||||
for (String i : getChildKeys()) {
|
||||
IrisBiome b = g.getData().getBiomeLoader().load(i);
|
||||
m.addAll(b.getAllChildren(g, limit));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 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.engine.object.world.biome;
|
||||
|
||||
import art.arcane.iris.core.loader.ResourceLoader;
|
||||
import art.arcane.iris.engine.object.annotations.Desc;
|
||||
import art.arcane.iris.engine.object.annotations.MaxNumber;
|
||||
import art.arcane.iris.engine.object.annotations.MinNumber;
|
||||
import art.arcane.iris.engine.object.annotations.RegistryListResource;
|
||||
import art.arcane.iris.engine.object.annotations.Required;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import com.volmit.world.Weighted;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Desc("A biome in a list a noise picks from")
|
||||
@Data
|
||||
public class IrisBiomeEntry {
|
||||
@Required
|
||||
@RegistryListResource(IrisBiome.class)
|
||||
@Desc("The biome (file name without .json)")
|
||||
private String biome;
|
||||
@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 the biome more common. The noise picks along the list in the order it is written.")
|
||||
private int weight = 1;
|
||||
|
||||
public static KList<String> keys(List<IrisBiomeEntry> entries) {
|
||||
KList<String> keys = new KList<>();
|
||||
entries.forEach(entry -> keys.add(entry.getBiome()));
|
||||
return keys;
|
||||
}
|
||||
|
||||
/**
|
||||
* The entries' biomes with their weights, in list order, leaving out biomes that don't load.
|
||||
*/
|
||||
public static KList<Weighted<IrisBiome>> load(List<IrisBiomeEntry> entries, ResourceLoader<IrisBiome> loader) {
|
||||
KList<Weighted<IrisBiome>> loaded = new KList<>();
|
||||
for (IrisBiomeEntry entry : entries) {
|
||||
IrisBiome biome = loader.load(entry.getBiome());
|
||||
if (biome != null) {
|
||||
loaded.add(new Weighted<>(biome, entry.getWeight()));
|
||||
}
|
||||
}
|
||||
return loaded;
|
||||
}
|
||||
}
|
||||
+22
-8
@@ -32,6 +32,7 @@ import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiomeGeneratorLink;
|
||||
import art.arcane.iris.engine.object.world.biome.custom.IrisBiomeCustom;
|
||||
import art.arcane.iris.engine.object.world.region.IrisRegion;
|
||||
import art.arcane.iris.engine.object.world.region.IrisRegionEntry;
|
||||
import art.arcane.iris.core.IrisDatapackCompiler.DimensionHeight;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
@@ -135,11 +136,10 @@ public class IrisDimension extends IrisRegistrant {
|
||||
private IrisGeneratorStyle caveBiomeStyle = NoiseStyle.CELLULAR_IRIS_DOUBLE.style();
|
||||
@Desc("The world environment")
|
||||
private IrisEnvironment environment = IrisEnvironment.NORMAL;
|
||||
@RegistryListResource(IrisRegion.class)
|
||||
@Required
|
||||
@ArrayType(min = 1, type = String.class)
|
||||
@Desc("Define all of the regions to include in this dimension. Dimensions -> Regions -> Biomes -> Objects etc")
|
||||
private KList<String> regions = new KList<>();
|
||||
@ArrayType(min = 1, type = IrisRegionEntry.class)
|
||||
@Desc("The regions of this dimension, picked along the list by the region noise. Dimensions -> Regions -> Biomes -> Objects etc")
|
||||
private KList<IrisRegionEntry> regions = new KList<>();
|
||||
@Required
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1024)
|
||||
@@ -164,7 +164,7 @@ public class IrisDimension extends IrisRegistrant {
|
||||
@Desc("Minimum air gap in blocks between the lower terrain surface and the upper terrain surface.")
|
||||
private int upperDimensionGap = 32;
|
||||
@RegistryListResource(IrisBiome.class)
|
||||
@Desc("Keep this either undefined or empty. Setting any biome name into this will force iris to only generate the specified biome. Great for testing.")
|
||||
@Desc("Keep this either undefined or empty. Setting any biome name into this will force iris to only generate the specified biome and its children. Great for testing.")
|
||||
private String focus = "";
|
||||
@RegistryListResource(IrisRegion.class)
|
||||
@Desc("Keep this either undefined or empty. Setting any region name into this will force iris to only generate the specified region. Great for testing.")
|
||||
@@ -268,7 +268,7 @@ public class IrisDimension extends IrisRegistrant {
|
||||
return regions.v();
|
||||
}
|
||||
|
||||
for (String key : getRegions()) {
|
||||
for (String key : getRegionKeys()) {
|
||||
IrisRegion region = data.getRegionLoader().load(key);
|
||||
if (region != null) {
|
||||
regions.put(key, region);
|
||||
@@ -293,10 +293,24 @@ public class IrisDimension extends IrisRegistrant {
|
||||
return regions.v();
|
||||
}
|
||||
|
||||
public KList<String> getRegionKeys() {
|
||||
return IrisRegionEntry.keys(getRegions());
|
||||
}
|
||||
|
||||
/** The weight the region has in the region noise's pick; 0 for a region the dimension does not list. */
|
||||
public int getRegionWeight(String regionKey) {
|
||||
for (IrisRegionEntry entry : regions) {
|
||||
if (entry.getRegion().equals(regionKey)) {
|
||||
return entry.getWeight();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public KList<IrisRegion> getAllAnyRegions() {
|
||||
KList<IrisRegion> r = new KList<>();
|
||||
|
||||
for (String i : getRegions()) {
|
||||
for (String i : getRegionKeys()) {
|
||||
r.add(IrisData.loadAnyRegion(i, getLoader()));
|
||||
}
|
||||
|
||||
@@ -366,7 +380,7 @@ public class IrisDimension extends IrisRegistrant {
|
||||
|
||||
visited.add(loadKey);
|
||||
biomes.put(loadKey, biome);
|
||||
addReachableBiomeKeys(pending, biome.getChildren());
|
||||
addReachableBiomeKeys(pending, biome.getChildKeys());
|
||||
addReachableBiomeKeys(pending, biome.getModuleSettings().treeBiomes(data.getPackResources()));
|
||||
addReachableBiomeKeys(pending, biome.getModuleSettings().usedBiomes(data.getPackResources(), getModuleSettings(), getLoadKey()));
|
||||
}
|
||||
|
||||
@@ -18,9 +18,9 @@
|
||||
|
||||
package art.arcane.iris.engine.object.world.region;
|
||||
|
||||
import art.arcane.iris.engine.object.value.IRare;
|
||||
import art.arcane.iris.engine.object.world.biome.InferredType;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiomeEntry;
|
||||
import art.arcane.iris.engine.framework.render.RenderType;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
@@ -28,9 +28,7 @@ import art.arcane.iris.core.loader.IrisRegistrant;
|
||||
import art.arcane.volmlib.util.cache.AtomicCache;
|
||||
import art.arcane.iris.engine.object.annotations.ArrayType;
|
||||
import art.arcane.iris.engine.object.annotations.Desc;
|
||||
import art.arcane.iris.engine.object.annotations.MaxNumber;
|
||||
import art.arcane.iris.engine.object.annotations.MinNumber;
|
||||
import art.arcane.iris.engine.object.annotations.RegistryListResource;
|
||||
import art.arcane.iris.engine.object.annotations.Required;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.collection.KMap;
|
||||
@@ -54,7 +52,7 @@ import java.util.Random;
|
||||
@Desc("Represents an iris region")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class IrisRegion extends IrisRegistrant implements IRare {
|
||||
public class IrisRegion extends IrisRegistrant {
|
||||
private final transient AtomicCache<KList<String>> cacheRidge = new AtomicCache<>();
|
||||
private final transient AtomicCache<KList<String>> cacheSpot = new AtomicCache<>();
|
||||
private final transient AtomicCache<CNG> shoreHeightGenerator = new AtomicCache<>();
|
||||
@@ -67,10 +65,6 @@ public class IrisRegion extends IrisRegistrant implements IRare {
|
||||
@Required
|
||||
@Desc("The name of the region")
|
||||
private String name = "A Region";
|
||||
@MinNumber(1)
|
||||
@MaxNumber(128)
|
||||
@Desc("The rarity of the region")
|
||||
private int rarity = 1;
|
||||
@MinNumber(0)
|
||||
@Desc("The min shore height")
|
||||
private double shoreHeightMin = 1.2;
|
||||
@@ -92,23 +86,19 @@ public class IrisRegion extends IrisRegistrant implements IRare {
|
||||
@MinNumber(0.0001)
|
||||
@Desc("How large cave biomes are in this region")
|
||||
private double caveBiomeZoom = 1;
|
||||
@RegistryListResource(IrisBiome.class)
|
||||
@Required
|
||||
@ArrayType(min = 1, type = String.class)
|
||||
@Desc("A list of root-level biomes in this region. Don't specify child biomes of other biomes here. Just the root parents.")
|
||||
private KList<String> landBiomes = new KList<>();
|
||||
@RegistryListResource(IrisBiome.class)
|
||||
@ArrayType(type = String.class)
|
||||
@Desc("A list of root-level sea biomes in this region. Optional: leave empty for land-only dimensions (flat, island, or fully-land worlds where no ocean is generated). Don't specify child biomes of other biomes here. Just the root parents.")
|
||||
private KList<String> seaBiomes = new KList<>();
|
||||
@RegistryListResource(IrisBiome.class)
|
||||
@ArrayType(type = String.class)
|
||||
@Desc("A list of root-level shore biomes in this region. Optional: leave empty for land-only dimensions (flat, island, or fully-land worlds where no shoreline is generated). Don't specify child biomes of other biomes here. Just the root parents.")
|
||||
private KList<String> shoreBiomes = new KList<>();
|
||||
@RegistryListResource(IrisBiome.class)
|
||||
@ArrayType(min = 1, type = String.class)
|
||||
@Desc("A list of root-level cave biomes in this region, used for carved cave interiors. Don't specify child biomes of other biomes here. Just the root parents.")
|
||||
private KList<String> caveBiomes = new KList<>();
|
||||
@ArrayType(min = 1, type = IrisBiomeEntry.class)
|
||||
@Desc("The root-level land biomes of this region, picked along the list by the biome noise. Don't list child biomes of other biomes here, just the root parents.")
|
||||
private KList<IrisBiomeEntry> landBiomes = new KList<>();
|
||||
@ArrayType(type = IrisBiomeEntry.class)
|
||||
@Desc("The root-level sea biomes of this region, picked along the list by the biome noise. Optional: leave empty for land-only dimensions (flat, island, or fully-land worlds where no ocean is generated). Don't list child biomes of other biomes here, just the root parents.")
|
||||
private KList<IrisBiomeEntry> seaBiomes = new KList<>();
|
||||
@ArrayType(type = IrisBiomeEntry.class)
|
||||
@Desc("The root-level shore biomes of this region, picked along the list by the biome noise. Optional: leave empty for land-only dimensions (flat, island, or fully-land worlds where no shoreline is generated). Don't list child biomes of other biomes here, just the root parents.")
|
||||
private KList<IrisBiomeEntry> shoreBiomes = new KList<>();
|
||||
@ArrayType(min = 1, type = IrisBiomeEntry.class)
|
||||
@Desc("The root-level cave biomes of this region, picked along the list by the cave biome noise and used for carved cave interiors. Don't list child biomes of other biomes here, just the root parents.")
|
||||
private KList<IrisBiomeEntry> caveBiomes = new KList<>();
|
||||
@Desc("A color for visualizing this region with a color. I.e. #F13AF5. This will show up on the map.")
|
||||
private String color = null;
|
||||
|
||||
@@ -127,10 +117,10 @@ public class IrisRegion extends IrisRegistrant implements IRare {
|
||||
|
||||
public KSet<String> getAllBiomeIds() {
|
||||
KSet<String> names = new KSet<>();
|
||||
names.addAll(landBiomes);
|
||||
names.addAll(caveBiomes);
|
||||
names.addAll(seaBiomes);
|
||||
names.addAll(shoreBiomes);
|
||||
names.addAll(IrisBiomeEntry.keys(landBiomes));
|
||||
names.addAll(IrisBiomeEntry.keys(caveBiomes));
|
||||
names.addAll(IrisBiomeEntry.keys(seaBiomes));
|
||||
names.addAll(IrisBiomeEntry.keys(shoreBiomes));
|
||||
|
||||
return names;
|
||||
}
|
||||
@@ -155,7 +145,7 @@ public class IrisRegion extends IrisRegistrant implements IRare {
|
||||
|
||||
names.addAll(biome.getModuleSettings().treeBiomes(g.getData().getPackResources()));
|
||||
b.put(biome.getLoadKey(), biome);
|
||||
names.addAll(biome.getChildren());
|
||||
names.addAll(biome.getChildKeys());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,7 +171,7 @@ public class IrisRegion extends IrisRegistrant implements IRare {
|
||||
{
|
||||
KList<IrisBiome> realCaveBiomes = new KList<>();
|
||||
|
||||
for (String i : getCaveBiomes()) {
|
||||
for (String i : IrisBiomeEntry.keys(getCaveBiomes())) {
|
||||
realCaveBiomes.add(g.getData().getBiomeLoader().load(i));
|
||||
}
|
||||
|
||||
@@ -194,7 +184,7 @@ public class IrisRegion extends IrisRegistrant implements IRare {
|
||||
{
|
||||
KList<IrisBiome> realShoreBiomes = new KList<>();
|
||||
|
||||
for (String i : getShoreBiomes()) {
|
||||
for (String i : IrisBiomeEntry.keys(getShoreBiomes())) {
|
||||
realShoreBiomes.add(g.getData().getBiomeLoader().load(i));
|
||||
}
|
||||
|
||||
@@ -207,7 +197,7 @@ public class IrisRegion extends IrisRegistrant implements IRare {
|
||||
{
|
||||
KList<IrisBiome> realSeaBiomes = new KList<>();
|
||||
|
||||
for (String i : getSeaBiomes()) {
|
||||
for (String i : IrisBiomeEntry.keys(getSeaBiomes())) {
|
||||
realSeaBiomes.add(g.getData().getBiomeLoader().load(i));
|
||||
}
|
||||
|
||||
@@ -220,7 +210,7 @@ public class IrisRegion extends IrisRegistrant implements IRare {
|
||||
{
|
||||
KList<IrisBiome> realLandBiomes = new KList<>();
|
||||
|
||||
for (String i : getLandBiomes()) {
|
||||
for (String i : IrisBiomeEntry.keys(getLandBiomes())) {
|
||||
realLandBiomes.add(g.getData().getBiomeLoader().load(i));
|
||||
}
|
||||
|
||||
@@ -231,10 +221,10 @@ public class IrisRegion extends IrisRegistrant implements IRare {
|
||||
public KList<IrisBiome> getAllAnyBiomes() {
|
||||
KMap<String, IrisBiome> b = new KMap<>();
|
||||
KSet<String> names = new KSet<>();
|
||||
names.addAll(landBiomes);
|
||||
names.addAll(caveBiomes);
|
||||
names.addAll(seaBiomes);
|
||||
names.addAll(shoreBiomes);
|
||||
names.addAll(IrisBiomeEntry.keys(landBiomes));
|
||||
names.addAll(IrisBiomeEntry.keys(caveBiomes));
|
||||
names.addAll(IrisBiomeEntry.keys(seaBiomes));
|
||||
names.addAll(IrisBiomeEntry.keys(shoreBiomes));
|
||||
|
||||
while (!names.isEmpty()) {
|
||||
for (String i : new KList<>(names)) {
|
||||
@@ -252,7 +242,7 @@ public class IrisRegion extends IrisRegistrant implements IRare {
|
||||
|
||||
names.addAll(biome.getModuleSettings().treeBiomes(biome.getLoader().getPackResources()));
|
||||
b.put(biome.getLoadKey(), biome);
|
||||
names.addAll(biome.getChildren());
|
||||
names.addAll(biome.getChildKeys());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 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.engine.object.world.region;
|
||||
|
||||
import art.arcane.iris.core.loader.ResourceLoader;
|
||||
import art.arcane.iris.engine.object.annotations.Desc;
|
||||
import art.arcane.iris.engine.object.annotations.MaxNumber;
|
||||
import art.arcane.iris.engine.object.annotations.MinNumber;
|
||||
import art.arcane.iris.engine.object.annotations.RegistryListResource;
|
||||
import art.arcane.iris.engine.object.annotations.Required;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import com.volmit.world.Weighted;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Desc("A region in the dimension's region list")
|
||||
@Data
|
||||
public class IrisRegionEntry {
|
||||
@Required
|
||||
@RegistryListResource(IrisRegion.class)
|
||||
@Desc("The region (file name without .json)")
|
||||
private String region;
|
||||
@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 the region more common. The noise picks along the list in the order it is written.")
|
||||
private int weight = 1;
|
||||
|
||||
public static KList<String> keys(List<IrisRegionEntry> entries) {
|
||||
KList<String> keys = new KList<>();
|
||||
entries.forEach(entry -> keys.add(entry.getRegion()));
|
||||
return keys;
|
||||
}
|
||||
|
||||
/**
|
||||
* The entries' regions with their weights, in list order, leaving out regions that don't load.
|
||||
*/
|
||||
public static KList<Weighted<IrisRegion>> load(List<IrisRegionEntry> entries, ResourceLoader<IrisRegion> loader) {
|
||||
KList<Weighted<IrisRegion>> loaded = new KList<>();
|
||||
for (IrisRegionEntry entry : entries) {
|
||||
IrisRegion region = loader.load(entry.getRegion());
|
||||
if (region != null) {
|
||||
loaded.add(new Weighted<>(region, entry.getWeight()));
|
||||
}
|
||||
}
|
||||
return loaded;
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package art.arcane.iris.util.project.noise;
|
||||
|
||||
import art.arcane.iris.engine.object.value.IRare;
|
||||
import art.arcane.iris.engine.object.noise.NoiseStyle;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.volmlib.util.cache.FloatCache;
|
||||
@@ -429,79 +428,6 @@ public class CNG {
|
||||
return InjectorMode.CUSTOM;
|
||||
}
|
||||
|
||||
public <T extends IRare> T fitRarity(KList<T> b, double... dim) {
|
||||
if (dim.length == 2) {
|
||||
return fitRarity2D(b, dim[0], dim[1]);
|
||||
}
|
||||
|
||||
if (b.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (b.size() == 1) {
|
||||
return b.get(0);
|
||||
}
|
||||
|
||||
KList<T> rarityMapped = buildRarityMapped(b);
|
||||
|
||||
if (rarityMapped.size() == 1) {
|
||||
return rarityMapped.get(0);
|
||||
}
|
||||
|
||||
if (rarityMapped.isEmpty()) {
|
||||
throw new RuntimeException("BAD RARITY MAP! RELATED TO: " + b.toString(", or possibly "));
|
||||
}
|
||||
|
||||
return fit(rarityMapped, dim);
|
||||
}
|
||||
|
||||
public <T extends IRare> T fitRarity2D(KList<T> b, double x, double z) {
|
||||
if (b.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (b.size() == 1) {
|
||||
return b.get(0);
|
||||
}
|
||||
|
||||
KList<T> rarityMapped = buildRarityMapped(b);
|
||||
if (rarityMapped.size() == 1) {
|
||||
return rarityMapped.get(0);
|
||||
}
|
||||
|
||||
if (rarityMapped.isEmpty()) {
|
||||
throw new RuntimeException("BAD RARITY MAP! RELATED TO: " + b.toString(", or possibly "));
|
||||
}
|
||||
|
||||
return fit2D(rarityMapped, x, z);
|
||||
}
|
||||
|
||||
private <T extends IRare> KList<T> buildRarityMapped(KList<T> values) {
|
||||
KList<T> rarityMapped = new KList<>();
|
||||
boolean flip = false;
|
||||
int max = 1;
|
||||
for (T value : values) {
|
||||
if (value.getRarity() > max) {
|
||||
max = value.getRarity();
|
||||
}
|
||||
}
|
||||
|
||||
max++;
|
||||
for (T value : values) {
|
||||
int count = max - value.getRarity();
|
||||
for (int j = 0; j < count; j++) {
|
||||
flip = !flip;
|
||||
if (flip) {
|
||||
rarityMapped.add(value);
|
||||
} else {
|
||||
rarityMapped.add(0, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rarityMapped;
|
||||
}
|
||||
|
||||
public <T> T fit2D(T[] values, double x, double z) {
|
||||
if (values.length == 0) {
|
||||
return null;
|
||||
|
||||
@@ -21,7 +21,7 @@ package art.arcane.iris.util.project.stream;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.volmlib.util.cache.CacheKey;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.object.value.IRare;
|
||||
import com.volmit.world.Weighted;
|
||||
import art.arcane.iris.engine.object.noise.IrisStyledRange;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
@@ -356,45 +356,11 @@ public interface ProceduralStream<T> extends ProceduralLayer, Interpolated<T> {
|
||||
return new SelectionStream<V>(this, types);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
default <V> ProceduralStream<V> selectRarity(V... types) {
|
||||
KList<V> rarityTypes = new KList<>();
|
||||
int totalRarity = 0;
|
||||
for (V i : types) {
|
||||
totalRarity += IRare.get(i);
|
||||
}
|
||||
|
||||
for (V i : types) {
|
||||
rarityTypes.addMultiple(i, totalRarity / IRare.get(i));
|
||||
}
|
||||
|
||||
return new SelectionStream<V>(this, rarityTypes);
|
||||
}
|
||||
|
||||
default <V extends IRare> ProceduralStream<V> selectRarity(List<V> types) {
|
||||
return IRare.stream(this.forceDouble(), types);
|
||||
}
|
||||
|
||||
default <V> ProceduralStream<IRare> selectRarity(List<V> types, Function<V, IRare> loader) {
|
||||
List<IRare> r = new ArrayList<>();
|
||||
for (V f : types) {
|
||||
r.add(loader.apply(f));
|
||||
}
|
||||
return selectRarity(r);
|
||||
}
|
||||
|
||||
default <V> int countPossibilities(List<V> types, Function<V, IRare> loader) {
|
||||
KList<V> rarityTypes = new KList<>();
|
||||
int totalRarity = 0;
|
||||
for (V i : types) {
|
||||
totalRarity += IRare.get(loader.apply(i));
|
||||
}
|
||||
|
||||
for (V i : types) {
|
||||
rarityTypes.addMultiple(i, totalRarity / IRare.get(loader.apply(i)));
|
||||
}
|
||||
|
||||
return rarityTypes.size();
|
||||
default <V> ProceduralStream<V> selectWeighted(List<Weighted<V>> entries) {
|
||||
ProceduralStream<Double> noise = this.forceDouble();
|
||||
return ProceduralStream.of((x, z) -> Weighted.pick(entries, noise.get(x, z), Weighted.Edge.EARLIER),
|
||||
(x, y, z) -> Weighted.pick(entries, noise.get(x, y, z), Weighted.Edge.EARLIER),
|
||||
Interpolated.of(entry -> 0D, value -> null));
|
||||
}
|
||||
|
||||
default ProceduralStream<T> clamp(double min, double max) {
|
||||
|
||||
@@ -518,7 +518,7 @@
|
||||
"iris.modded.moddedstudiocommands.this_command_can_only_be_used_by_players_sampling_is": "This command can only be used by players (sampling is centered on your position).",
|
||||
"iris.modded.moddedstudiocommands.this_dimension_is_not_generated_by_iris": "This dimension is not generated by Iris.",
|
||||
"iris.modded.moddedstudiocommands.sampling_region_distribution_x_chunks_around_you": "Sampling region distribution in {value}x{value2} chunks around you...",
|
||||
"iris.modded.moddedstudiocommands.rarity": "{key}: rarity={rarity} / {value}%",
|
||||
"iris.modded.moddedstudiocommands.rarity": "{key}: weight={rarity} / {value}%",
|
||||
"iris.modded.moddedstudiocommands.region_sampling_failed": "Region sampling failed: {value}",
|
||||
"iris.modded.moddedworldcommands.required_pack_is_not_installed_install_then_restart": "Required pack '{pack}' is not installed. Install it with /iris download, then restart.",
|
||||
"iris.modded.moddedworldcommands.failed_inject_iris_world": "Failed to inject Iris world '{dimensionId}': {value}{errorMessage}",
|
||||
|
||||
Reference in new issue
Block a user