mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 16:54:04 +00:00
Merge branch 'v3/lane-engine' into v3/lane-studio
This commit is contained in:
commit
1e44f45a34
95 files changed
+2134
-1186
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);
|
||||
|
||||
@@ -0,0 +1,224 @@
|
||||
/*
|
||||
* 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.core.pack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Positions in the text of a JSON file as Iris reads it, with comments and trailing commas, so a file can be edited
|
||||
* in place without rewriting the formatting around the edit.
|
||||
*/
|
||||
final class PackJsonText {
|
||||
private PackJsonText() {
|
||||
}
|
||||
|
||||
/** A member of an object: the key and where its value starts and ends in the text. */
|
||||
record Member(String key, int keyStart, int valueStart, int valueEnd) {
|
||||
}
|
||||
|
||||
/** A value inside an array: where it starts and ends in the text. */
|
||||
record Item(int start, int end) {
|
||||
}
|
||||
|
||||
/** A replacement of the text from {@code start} up to {@code end}. */
|
||||
record Edit(int start, int end, String replacement) {
|
||||
}
|
||||
|
||||
static List<Member> members(String text, int objectStart) {
|
||||
if (text.charAt(objectStart) != '{') {
|
||||
throw new IllegalArgumentException("An object was expected at " + objectStart);
|
||||
}
|
||||
|
||||
List<Member> members = new ArrayList<>();
|
||||
int index = skipBlank(text, objectStart + 1);
|
||||
while (index < text.length() && text.charAt(index) != '}') {
|
||||
if (text.charAt(index) == ',') {
|
||||
index = skipBlank(text, index + 1);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (text.charAt(index) != '"') {
|
||||
throw new IllegalArgumentException("A key was expected at " + index);
|
||||
}
|
||||
|
||||
int keyEnd = stringEnd(text, index);
|
||||
int colon = skipBlank(text, keyEnd + 1);
|
||||
int valueStart = skipBlank(text, colon + 1);
|
||||
int valueEnd = valueEnd(text, valueStart);
|
||||
members.add(new Member(text.substring(index + 1, keyEnd), index, valueStart, valueEnd));
|
||||
index = skipBlank(text, valueEnd);
|
||||
}
|
||||
return members;
|
||||
}
|
||||
|
||||
static Member member(List<Member> members, String key) {
|
||||
return members.stream().filter(member -> member.key().equals(key)).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
static List<Item> items(String text, int arrayStart) {
|
||||
if (text.charAt(arrayStart) != '[') {
|
||||
throw new IllegalArgumentException("An array was expected at " + arrayStart);
|
||||
}
|
||||
|
||||
List<Item> items = new ArrayList<>();
|
||||
int index = skipBlank(text, arrayStart + 1);
|
||||
while (index < text.length() && text.charAt(index) != ']') {
|
||||
if (text.charAt(index) == ',') {
|
||||
index = skipBlank(text, index + 1);
|
||||
continue;
|
||||
}
|
||||
|
||||
int end = valueEnd(text, index);
|
||||
items.add(new Item(index, end));
|
||||
index = skipBlank(text, end);
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
/** The text of the file with every edit applied; the edits must not overlap. */
|
||||
static String apply(String text, List<Edit> edits) {
|
||||
StringBuilder edited = new StringBuilder(text);
|
||||
edits.stream().sorted(Comparator.comparingInt(Edit::start).reversed())
|
||||
.forEach(edit -> edited.replace(edit.start(), edit.end(), edit.replacement()));
|
||||
return edited.toString();
|
||||
}
|
||||
|
||||
/** The edit that takes the member out, together with its comma and, when it stands alone there, its lines. */
|
||||
static Edit removal(String text, Member member) {
|
||||
int start = member.keyStart();
|
||||
int end = member.valueEnd();
|
||||
int after = skipBlank(text, end);
|
||||
if (after < text.length() && text.charAt(after) == ',') {
|
||||
end = after + 1;
|
||||
} else {
|
||||
int before = start - 1;
|
||||
while (before >= 0 && Character.isWhitespace(text.charAt(before))) {
|
||||
before--;
|
||||
}
|
||||
if (before >= 0 && text.charAt(before) == ',') {
|
||||
start = before;
|
||||
}
|
||||
}
|
||||
|
||||
int lineStart = text.lastIndexOf('\n', start - 1) + 1;
|
||||
int lineEnd = text.indexOf('\n', end);
|
||||
if (lineEnd < 0) {
|
||||
lineEnd = text.length();
|
||||
}
|
||||
|
||||
boolean alone = text.substring(lineStart, start).isBlank() && text.substring(end, lineEnd).isBlank();
|
||||
if (!alone) {
|
||||
return new Edit(start, end, "");
|
||||
}
|
||||
return new Edit(lineStart, Math.min(lineEnd + 1, text.length()), "");
|
||||
}
|
||||
|
||||
/** The whitespace the line holding {@code position} starts with. */
|
||||
static String indentAt(String text, int position) {
|
||||
int lineStart = text.lastIndexOf('\n', position - 1) + 1;
|
||||
int index = lineStart;
|
||||
while (index < position && (text.charAt(index) == ' ' || text.charAt(index) == '\t')) {
|
||||
index++;
|
||||
}
|
||||
return text.substring(lineStart, index);
|
||||
}
|
||||
|
||||
static int skipBlank(String text, int index) {
|
||||
int position = index;
|
||||
while (position < text.length()) {
|
||||
if (Character.isWhitespace(text.charAt(position))) {
|
||||
position++;
|
||||
} else if (isComment(text, position)) {
|
||||
position = commentEnd(text, position);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return position;
|
||||
}
|
||||
|
||||
static int valueEnd(String text, int start) {
|
||||
char first = text.charAt(start);
|
||||
if (first == '"') {
|
||||
return stringEnd(text, start) + 1;
|
||||
}
|
||||
|
||||
if (first != '[' && first != '{') {
|
||||
return literalEnd(text, start);
|
||||
}
|
||||
|
||||
int depth = 0;
|
||||
int index = start;
|
||||
while (index < text.length()) {
|
||||
char current = text.charAt(index);
|
||||
if (current == '"') {
|
||||
index = stringEnd(text, index);
|
||||
} else if (isComment(text, index)) {
|
||||
index = commentEnd(text, index) - 1;
|
||||
} else if (current == '[' || current == '{') {
|
||||
depth++;
|
||||
} else if (current == ']' || current == '}') {
|
||||
depth--;
|
||||
if (depth == 0) {
|
||||
return index + 1;
|
||||
}
|
||||
}
|
||||
index++;
|
||||
}
|
||||
throw new IllegalArgumentException("The value at " + start + " is not closed");
|
||||
}
|
||||
|
||||
private static int literalEnd(String text, int start) {
|
||||
int index = start;
|
||||
while (index < text.length() && ",]} \t\r\n".indexOf(text.charAt(index)) < 0 && !isComment(text, index)) {
|
||||
index++;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
private static int stringEnd(String text, int quote) {
|
||||
int index = quote + 1;
|
||||
while (index < text.length() && text.charAt(index) != '"') {
|
||||
index += text.charAt(index) == '\\' ? 2 : 1;
|
||||
}
|
||||
if (index >= text.length()) {
|
||||
throw new IllegalArgumentException("The string at " + quote + " is not closed");
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
private static boolean isComment(String text, int index) {
|
||||
return text.startsWith("//", index) || text.startsWith("/*", index);
|
||||
}
|
||||
|
||||
private static int commentEnd(String text, int start) {
|
||||
if (text.startsWith("//", start)) {
|
||||
int lineEnd = text.indexOf('\n', start);
|
||||
return lineEnd < 0 ? text.length() : lineEnd;
|
||||
}
|
||||
|
||||
int close = text.indexOf("*/", start + 2);
|
||||
if (close < 0) {
|
||||
throw new IllegalArgumentException("The comment at " + start + " is not closed");
|
||||
}
|
||||
return close + 2;
|
||||
}
|
||||
}
|
||||
@@ -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")) {
|
||||
|
||||
@@ -0,0 +1,514 @@
|
||||
/*
|
||||
* 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.core.pack;
|
||||
|
||||
import art.arcane.iris.core.pack.PackJsonText.Edit;
|
||||
import art.arcane.iris.core.pack.PackJsonText.Item;
|
||||
import art.arcane.iris.core.pack.PackJsonText.Member;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.volmit.world.Weighted;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeSet;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Converts a pack from rarity to weighted list entries, keeping the share every list entry had in its pick:
|
||||
* <pre>
|
||||
* "landBiomes": [{"biome": "plains", "weight": 3}, ...] (also seaBiomes, shoreBiomes, caveBiomes)
|
||||
* "regions": [{"region": "temperate", "weight": 2}, ...] (in the dimension)
|
||||
* "children": [{"biome": "forest", "weight": 2}, {"biome": "plains", "weight": 5}, ...]
|
||||
* "carving": [{"id": "deep", "children": [{"id": "lush", "weight": 2}, {"id": "deep", "weight": 5}]}]
|
||||
* </pre>
|
||||
* Region, biome and dimension lists were picked with a share of 1 / rarity per entry, so an entry's weight is the least
|
||||
* common multiple of the list's rarities divided by its rarity, reduced by the greatest common divisor. Children were
|
||||
* picked from rounded slots, the rarer a biome the fewer, alternating from both ends, with the parent among them; the
|
||||
* parent is listed among its children wherever it kept the spot, in half slots, since the first and last slot only
|
||||
* held half a slot of noise. A carving entry's children pick the same way by the rarity of the entries' biomes. The
|
||||
* top-level {@code rarity} of biomes and regions is removed; nested rarities (loot, spawns, objects) stay.
|
||||
* <p>
|
||||
* Files are edited as text, so formatting elsewhere stays; a rewritten list gets one entry per line. A list that would need
|
||||
* a weight above {@link Weighted#MAX_WEIGHT} stops the conversion. A pack with lists already converted and lists not yet
|
||||
* converted cannot be told apart from rarity 1 and is refused.
|
||||
* <p>
|
||||
* Usage: {@code PackWeightConverter [--dry-run] <pack folder>...}
|
||||
*/
|
||||
public final class PackWeightConverter {
|
||||
private static final String INDENT_STEP = " ";
|
||||
private static final String JSON_EXTENSION = ".json";
|
||||
private static final int DEFAULT_RARITY = 1;
|
||||
private static final List<String> BIOME_LISTS = List.of("landBiomes", "seaBiomes", "shoreBiomes", "caveBiomes");
|
||||
|
||||
/** The files a conversion changed (relative to the pack) and what it could not carry over exactly. */
|
||||
public record Result(List<String> changedFiles, List<String> warnings) {
|
||||
}
|
||||
|
||||
/** A pack the converter cannot convert while keeping every pick. */
|
||||
public static final class ConversionException extends RuntimeException {
|
||||
ConversionException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
private record Entry(String key, int weight) {
|
||||
}
|
||||
|
||||
private record Option(String key, int rarity) {
|
||||
}
|
||||
|
||||
private record CarvingBand(String biome, boolean enabled) {
|
||||
}
|
||||
|
||||
private final Path pack;
|
||||
private final Map<String, Integer> biomeRarities;
|
||||
private final Map<String, Integer> regionRarities;
|
||||
private final TreeSet<String> warnings = new TreeSet<>();
|
||||
private String currentFile = "";
|
||||
|
||||
private PackWeightConverter(Path pack) throws IOException {
|
||||
this.pack = pack;
|
||||
this.biomeRarities = rarities("biomes");
|
||||
this.regionRarities = rarities("regions");
|
||||
}
|
||||
|
||||
public static Result convert(Path pack, boolean dryRun) throws IOException {
|
||||
PackWeightConverter converter = new PackWeightConverter(pack);
|
||||
converter.refusePartlyConverted();
|
||||
Map<Path, String> converted = new LinkedHashMap<>();
|
||||
for (String folder : List.of("biomes", "regions", "dimensions")) {
|
||||
for (Path file : converter.files(folder)) {
|
||||
String text = converter.convertFile(folder, file);
|
||||
if (text != null) {
|
||||
converted.put(file, text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<String> changed = new ArrayList<>();
|
||||
for (Map.Entry<Path, String> file : converted.entrySet()) {
|
||||
changed.add(relative(pack, file.getKey()));
|
||||
if (!dryRun) {
|
||||
Files.writeString(file.getKey(), file.getValue(), StandardCharsets.UTF_8);
|
||||
}
|
||||
}
|
||||
return new Result(changed, List.copyOf(converter.warnings));
|
||||
}
|
||||
|
||||
public static void main(String[] arguments) throws IOException {
|
||||
boolean dryRun = false;
|
||||
List<Path> packs = new ArrayList<>();
|
||||
for (String argument : arguments) {
|
||||
if (argument.equals("--dry-run")) {
|
||||
dryRun = true;
|
||||
} else {
|
||||
packs.add(Path.of(argument));
|
||||
}
|
||||
}
|
||||
|
||||
if (packs.isEmpty()) {
|
||||
System.err.println("Usage: PackWeightConverter [--dry-run] <pack folder>...");
|
||||
System.exit(2);
|
||||
}
|
||||
|
||||
for (Path folder : packs) {
|
||||
try {
|
||||
Result result = convert(folder, dryRun);
|
||||
result.changedFiles().forEach(System.out::println);
|
||||
result.warnings().forEach(warning -> System.out.println("warning: " + warning));
|
||||
System.out.println(folder + ": " + result.changedFiles().size() + " files " + (dryRun ? "would change" : "changed"));
|
||||
} catch (ConversionException refusal) {
|
||||
System.err.println(folder + ": " + refusal.getMessage());
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** The converted text of the file; null when nothing in it changes. */
|
||||
private String convertFile(String folder, Path file) throws IOException {
|
||||
currentFile = relative(pack, file);
|
||||
String text = Files.readString(file, StandardCharsets.UTF_8);
|
||||
String converted = switch (folder) {
|
||||
case "biomes" -> convertBiome(keyOf(pack.resolve(folder), file), text);
|
||||
case "regions" -> convertRegion(text);
|
||||
default -> convertDimension(text);
|
||||
};
|
||||
if (converted.equals(text)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
verifyParses(converted);
|
||||
return converted;
|
||||
}
|
||||
|
||||
private static String relative(Path pack, Path file) {
|
||||
return pack.relativize(file).toString().replace('\\', '/');
|
||||
}
|
||||
|
||||
private String convertBiome(String key, String text) {
|
||||
List<Member> members = rootMembers(text);
|
||||
List<Edit> edits = new ArrayList<>();
|
||||
Member children = PackJsonText.member(members, "children");
|
||||
List<String> childKeys = stringItems(text, children);
|
||||
if (childKeys != null) {
|
||||
edits.add(replaceList(text, children, "biome", childEntries(key, childKeys)));
|
||||
}
|
||||
addRarityRemoval(text, members, edits);
|
||||
return PackJsonText.apply(text, edits);
|
||||
}
|
||||
|
||||
private String convertRegion(String text) {
|
||||
List<Member> members = rootMembers(text);
|
||||
List<Edit> edits = new ArrayList<>();
|
||||
for (String list : BIOME_LISTS) {
|
||||
Member member = PackJsonText.member(members, list);
|
||||
List<String> keys = stringItems(text, member);
|
||||
if (keys != null) {
|
||||
edits.add(replaceList(text, member, "biome", listEntries(keys, biomeRarities)));
|
||||
}
|
||||
}
|
||||
addRarityRemoval(text, members, edits);
|
||||
return PackJsonText.apply(text, edits);
|
||||
}
|
||||
|
||||
private String convertDimension(String text) {
|
||||
List<Member> members = rootMembers(text);
|
||||
List<Edit> edits = new ArrayList<>();
|
||||
Member regions = PackJsonText.member(members, "regions");
|
||||
List<String> regionKeys = stringItems(text, regions);
|
||||
if (regionKeys != null) {
|
||||
edits.add(replaceList(text, regions, "region", listEntries(regionKeys, regionRarities)));
|
||||
}
|
||||
|
||||
Member carving = PackJsonText.member(members, "carving");
|
||||
if (carving != null && text.charAt(carving.valueStart()) == '[') {
|
||||
edits.addAll(convertCarving(text, carving));
|
||||
}
|
||||
return PackJsonText.apply(text, edits);
|
||||
}
|
||||
|
||||
private List<Edit> convertCarving(String text, Member carving) {
|
||||
List<List<Member>> bands = new ArrayList<>();
|
||||
for (Item item : PackJsonText.items(text, carving.valueStart())) {
|
||||
bands.add(text.charAt(item.start()) == '{' ? PackJsonText.members(text, item.start()) : List.of());
|
||||
}
|
||||
|
||||
Map<String, CarvingBand> bandsById = new HashMap<>();
|
||||
for (List<Member> members : bands) {
|
||||
String id = stringValue(text, PackJsonText.member(members, "id")).trim();
|
||||
if (!id.isEmpty()) {
|
||||
bandsById.put(id, carvingBand(text, members));
|
||||
}
|
||||
}
|
||||
|
||||
List<Edit> edits = new ArrayList<>();
|
||||
for (List<Member> members : bands) {
|
||||
Member children = PackJsonText.member(members, "children");
|
||||
List<String> childIds = stringItems(text, children);
|
||||
if (childIds != null) {
|
||||
edits.add(replaceList(text, children, "id", carvingChildEntries(text, members, childIds, bandsById)));
|
||||
}
|
||||
}
|
||||
return edits;
|
||||
}
|
||||
|
||||
private CarvingBand carvingBand(String text, List<Member> members) {
|
||||
Member enabled = PackJsonText.member(members, "enabled");
|
||||
boolean isEnabled = enabled == null || !text.startsWith("false", enabled.valueStart());
|
||||
return new CarvingBand(stringValue(text, PackJsonText.member(members, "biome")).trim(), isEnabled);
|
||||
}
|
||||
|
||||
private List<Entry> carvingChildEntries(String text, List<Member> members, List<String> childIds, Map<String, CarvingBand> bandsById) {
|
||||
String parentId = stringValue(text, PackJsonText.member(members, "id")).trim();
|
||||
if (parentId.isEmpty()) {
|
||||
throw new ConversionException(currentFile + ": a carving entry with children needs an id, so that it can list itself among them");
|
||||
}
|
||||
|
||||
List<Option> options = new ArrayList<>();
|
||||
for (String listed : childIds) {
|
||||
String childId = listed.trim();
|
||||
CarvingBand child = bandsById.get(childId);
|
||||
if (child == null || !child.enabled() || !biomeRarities.containsKey(child.biome())) {
|
||||
warnings.add(currentFile + ": the carving child '" + childId + "' is not an enabled entry with a biome of this pack; Iris skipped it");
|
||||
continue;
|
||||
}
|
||||
options.add(new Option(childId, biomeRarities.get(child.biome())));
|
||||
}
|
||||
|
||||
CarvingBand parent = bandsById.get(parentId);
|
||||
options.add(new Option(parentId, biomeRarities.getOrDefault(parent.biome(), DEFAULT_RARITY)));
|
||||
return halfSlotRuns(oldChildSlots(options));
|
||||
}
|
||||
|
||||
private List<Entry> childEntries(String parent, List<String> children) {
|
||||
List<Option> options = new ArrayList<>();
|
||||
for (String child : children) {
|
||||
if (!biomeRarities.containsKey(child)) {
|
||||
warnings.add(currentFile + ": the child '" + child + "' has no file in this pack; Iris skipped it");
|
||||
continue;
|
||||
}
|
||||
options.add(new Option(child, biomeRarities.get(child)));
|
||||
}
|
||||
options.add(new Option(parent, biomeRarities.getOrDefault(parent, DEFAULT_RARITY)));
|
||||
return halfSlotRuns(oldChildSlots(options));
|
||||
}
|
||||
|
||||
private List<Entry> listEntries(List<String> keys, Map<String, Integer> rarities) {
|
||||
List<Integer> loadedRarities = new ArrayList<>();
|
||||
for (String key : keys) {
|
||||
if (rarities.containsKey(key)) {
|
||||
loadedRarities.add(rarities.get(key));
|
||||
} else {
|
||||
warnings.add(currentFile + ": '" + key + "' is listed but has no file in this pack; Iris skips it");
|
||||
}
|
||||
}
|
||||
|
||||
List<Integer> weights = shareWeights(loadedRarities);
|
||||
List<Entry> entries = new ArrayList<>();
|
||||
int loaded = 0;
|
||||
for (String key : keys) {
|
||||
entries.add(new Entry(key, rarities.containsKey(key) ? weights.get(loaded++) : Weighted.MIN_WEIGHT));
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
|
||||
/** Weights proportional to 1 / rarity: the least common multiple of the rarities divided by each, reduced. */
|
||||
private List<Integer> shareWeights(List<Integer> rarities) {
|
||||
if (rarities.size() <= 1) {
|
||||
return rarities.stream().map(rarity -> Weighted.MIN_WEIGHT).toList();
|
||||
}
|
||||
|
||||
long commonMultiple = 1;
|
||||
for (int rarity : rarities) {
|
||||
commonMultiple = commonMultiple / gcd(commonMultiple, rarity) * rarity;
|
||||
if (commonMultiple > Integer.MAX_VALUE) {
|
||||
throw new ConversionException(currentFile + ": the rarities " + rarities + " share no weights up to " + Weighted.MAX_WEIGHT);
|
||||
}
|
||||
}
|
||||
|
||||
long divisor = 0;
|
||||
for (int rarity : rarities) {
|
||||
divisor = gcd(divisor, commonMultiple / rarity);
|
||||
}
|
||||
|
||||
List<Integer> weights = new ArrayList<>();
|
||||
for (int rarity : rarities) {
|
||||
long weight = commonMultiple / rarity / divisor;
|
||||
if (weight > Weighted.MAX_WEIGHT) {
|
||||
throw new ConversionException(currentFile + ": the rarities " + rarities + " need a weight of " + weight
|
||||
+ ", above the maximum of " + Weighted.MAX_WEIGHT + "; list them with weights by hand");
|
||||
}
|
||||
weights.add((int) weight);
|
||||
}
|
||||
return weights;
|
||||
}
|
||||
|
||||
/** The old child picker's slots: rarer options get fewer, and each option adds its slots to alternating ends. */
|
||||
private static List<String> oldChildSlots(List<Option> options) {
|
||||
int most = options.stream().mapToInt(option -> Math.max(DEFAULT_RARITY, option.rarity())).max().orElse(DEFAULT_RARITY) + 1;
|
||||
List<String> slots = new ArrayList<>();
|
||||
boolean atEnd = false;
|
||||
for (Option option : options) {
|
||||
for (int copy = 0; copy < most - Math.max(DEFAULT_RARITY, option.rarity()); copy++) {
|
||||
atEnd = !atEnd;
|
||||
if (atEnd) {
|
||||
slots.add(option.key());
|
||||
} else {
|
||||
slots.addFirst(option.key());
|
||||
}
|
||||
}
|
||||
}
|
||||
return slots;
|
||||
}
|
||||
|
||||
/** The old picker rounded the noise onto the slots, so the first and last slot had half a slot of noise. */
|
||||
private List<Entry> halfSlotRuns(List<String> slots) {
|
||||
List<String> keys = new ArrayList<>();
|
||||
List<Integer> halves = new ArrayList<>();
|
||||
for (int index = 0; index < slots.size(); index++) {
|
||||
int slotHalves = index == 0 || index == slots.size() - 1 ? 1 : 2;
|
||||
if (!keys.isEmpty() && keys.getLast().equals(slots.get(index))) {
|
||||
halves.set(halves.size() - 1, halves.getLast() + slotHalves);
|
||||
} else {
|
||||
keys.add(slots.get(index));
|
||||
halves.add(slotHalves);
|
||||
}
|
||||
}
|
||||
|
||||
List<Entry> entries = new ArrayList<>();
|
||||
for (int run = 0; run < keys.size(); run++) {
|
||||
if (halves.get(run) > Weighted.MAX_WEIGHT) {
|
||||
throw new ConversionException(currentFile + ": the children of one biome need a weight of " + halves.get(run)
|
||||
+ ", above the maximum of " + Weighted.MAX_WEIGHT + "; list them with weights by hand");
|
||||
}
|
||||
entries.add(new Entry(keys.get(run), halves.get(run)));
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
|
||||
private Edit replaceList(String text, Member list, String field, List<Entry> entries) {
|
||||
String indent = PackJsonText.indentAt(text, list.keyStart());
|
||||
StringBuilder replacement = new StringBuilder("[\n");
|
||||
for (int index = 0; index < entries.size(); index++) {
|
||||
Entry entry = entries.get(index);
|
||||
replacement.append(indent).append(INDENT_STEP)
|
||||
.append("{\"").append(field).append("\": \"").append(entry.key()).append("\", \"weight\": ").append(entry.weight()).append('}')
|
||||
.append(index < entries.size() - 1 ? ",\n" : "\n");
|
||||
}
|
||||
replacement.append(indent).append(']');
|
||||
return new Edit(list.valueStart(), list.valueEnd(), replacement.toString());
|
||||
}
|
||||
|
||||
private void addRarityRemoval(String text, List<Member> members, List<Edit> edits) {
|
||||
Member rarity = PackJsonText.member(members, "rarity");
|
||||
if (rarity != null) {
|
||||
edits.add(PackJsonText.removal(text, rarity));
|
||||
}
|
||||
}
|
||||
|
||||
/** The strings of a list, or null when the list is missing, empty or already holds entries. */
|
||||
private List<String> stringItems(String text, Member list) {
|
||||
if (list == null || text.charAt(list.valueStart()) != '[') {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<Item> items = PackJsonText.items(text, list.valueStart());
|
||||
if (items.isEmpty() || items.stream().anyMatch(item -> text.charAt(item.start()) != '"')) {
|
||||
return null;
|
||||
}
|
||||
return items.stream().map(item -> plainString(text.substring(item.start() + 1, item.end() - 1))).toList();
|
||||
}
|
||||
|
||||
private String stringValue(String text, Member member) {
|
||||
if (member == null || text.charAt(member.valueStart()) != '"') {
|
||||
return "";
|
||||
}
|
||||
return plainString(text.substring(member.valueStart() + 1, member.valueEnd() - 1));
|
||||
}
|
||||
|
||||
private String plainString(String content) {
|
||||
if (content.indexOf('\\') >= 0) {
|
||||
throw new ConversionException(currentFile + ": the key \"" + content + "\" holds an escape; rewrite it by hand");
|
||||
}
|
||||
return content;
|
||||
}
|
||||
|
||||
private List<Member> rootMembers(String text) {
|
||||
int start = PackJsonText.skipBlank(text, 0);
|
||||
if (start >= text.length() || text.charAt(start) != '{') {
|
||||
throw new ConversionException(currentFile + ": the file is not a JSON object");
|
||||
}
|
||||
|
||||
try {
|
||||
return PackJsonText.members(text, start);
|
||||
} catch (IllegalArgumentException unreadable) {
|
||||
throw new ConversionException(currentFile + ": " + unreadable.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void verifyParses(String converted) {
|
||||
try {
|
||||
JsonParser.parseString(converted);
|
||||
} catch (RuntimeException broken) {
|
||||
throw new ConversionException(currentFile + ": the converted file does not parse: " + broken.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, Integer> rarities(String folder) throws IOException {
|
||||
Map<String, Integer> rarities = new HashMap<>();
|
||||
for (Path file : files(folder)) {
|
||||
currentFile = relative(pack, file);
|
||||
String text = Files.readString(file, StandardCharsets.UTF_8);
|
||||
Member rarity = PackJsonText.member(rootMembers(text), "rarity");
|
||||
rarities.put(keyOf(pack.resolve(folder), file), rarity == null ? DEFAULT_RARITY : rarityOf(text, rarity));
|
||||
}
|
||||
return rarities;
|
||||
}
|
||||
|
||||
private int rarityOf(String text, Member rarity) {
|
||||
try {
|
||||
return (int) Math.round(Double.parseDouble(text.substring(rarity.valueStart(), rarity.valueEnd())));
|
||||
} catch (NumberFormatException notANumber) {
|
||||
throw new ConversionException(currentFile + ": the rarity is not a number");
|
||||
}
|
||||
}
|
||||
|
||||
private void refusePartlyConverted() throws IOException {
|
||||
boolean convertedLists = false;
|
||||
boolean legacyLists = false;
|
||||
for (String folder : List.of("biomes", "regions", "dimensions")) {
|
||||
for (Path file : files(folder)) {
|
||||
currentFile = relative(pack, file);
|
||||
String text = Files.readString(file, StandardCharsets.UTF_8);
|
||||
List<Member> members = rootMembers(text);
|
||||
for (String list : listKeys(folder)) {
|
||||
Member member = PackJsonText.member(members, list);
|
||||
if (member == null || text.charAt(member.valueStart()) != '[') {
|
||||
continue;
|
||||
}
|
||||
List<Item> items = PackJsonText.items(text, member.valueStart());
|
||||
boolean hasStrings = items.stream().anyMatch(item -> text.charAt(item.start()) == '"');
|
||||
boolean hasEntries = items.stream().anyMatch(item -> text.charAt(item.start()) == '{');
|
||||
legacyLists |= hasStrings;
|
||||
convertedLists |= hasEntries;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (convertedLists && legacyLists) {
|
||||
throw new ConversionException("some lists are weighted entries already and some are not; the rarities of the converted"
|
||||
+ " files are gone, so restore the pack and convert it in one run");
|
||||
}
|
||||
}
|
||||
|
||||
private static List<String> listKeys(String folder) {
|
||||
return switch (folder) {
|
||||
case "biomes" -> List.of("children");
|
||||
case "regions" -> BIOME_LISTS;
|
||||
default -> List.of("regions");
|
||||
};
|
||||
}
|
||||
|
||||
private List<Path> files(String folder) throws IOException {
|
||||
Path root = pack.resolve(folder);
|
||||
if (!Files.isDirectory(root)) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
try (Stream<Path> walk = Files.walk(root)) {
|
||||
return walk.filter(file -> Files.isRegularFile(file) && file.getFileName().toString().endsWith(JSON_EXTENSION)).sorted().toList();
|
||||
}
|
||||
}
|
||||
|
||||
private static String keyOf(Path folder, Path file) {
|
||||
String relative = folder.relativize(file).toString().replace('\\', '/');
|
||||
return relative.substring(0, relative.length() - JSON_EXTENSION.length());
|
||||
}
|
||||
|
||||
private static long gcd(long first, long second) {
|
||||
return second == 0 ? first : gcd(second, first % second);
|
||||
}
|
||||
}
|
||||
@@ -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,13 +63,13 @@ 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));
|
||||
}
|
||||
});
|
||||
return new Inspection("Region noise by rarity", List.of(new Section(null, 1D, 0, List.of(regions.spread()))));
|
||||
return new Inspection("Region noise by weight", List.of(new Section(null, 1D, 0, List.of(regions.spread()))));
|
||||
}
|
||||
|
||||
// The previewed region owns every spot, so each spot's biome list is the one its surface needs.
|
||||
@@ -79,7 +80,7 @@ public final class MapPickInspection {
|
||||
}
|
||||
RegionSamples samples = new RegionSamples(engine, MapView.REGIONS, region);
|
||||
area.forEachSpot((x, z) -> samples.add(complex.surfacePickAsIfIn(region, x, z).list(), x, z));
|
||||
return new Inspection("Biome noise by rarity", List.of(samples.section(1)));
|
||||
return new Inspection("Biome noise by weight", List.of(samples.section(1)));
|
||||
}
|
||||
|
||||
// Each region picks the base biomes on its ground from the list the continent chose there.
|
||||
@@ -114,7 +115,7 @@ public final class MapPickInspection {
|
||||
area.forEachSpot((x, z) -> children.add(ChildPicks.from(complex, focus, x, z)));
|
||||
List<Spread> spreads = children.mostSampledFirst();
|
||||
Section section = new Section(MapPickPath.biomeLabel(engine, view, focus), 1D, distinctOptions(spreads), spreads);
|
||||
return new Inspection("Child noise by rarity", List.of(section));
|
||||
return new Inspection("Child noise by weight", List.of(section));
|
||||
}
|
||||
|
||||
private static int distinctOptions(List<Spread> spreads) {
|
||||
@@ -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,12 +25,14 @@ 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.IrisGeneratorStyle;
|
||||
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;
|
||||
@@ -43,6 +45,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;
|
||||
@@ -87,6 +90,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,
|
||||
@@ -137,8 +142,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);
|
||||
@@ -170,7 +173,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;
|
||||
@@ -223,7 +226,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) -> {
|
||||
@@ -378,9 +381,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"));
|
||||
@@ -550,10 +553,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);
|
||||
}
|
||||
|
||||
@@ -612,7 +615,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;
|
||||
}
|
||||
|
||||
@@ -656,44 +659,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)));
|
||||
@@ -819,39 +818,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 {
|
||||
@@ -1074,78 +1046,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