mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-10-23 00:28:02 +00:00
Matched regions by biome category
- For land biomes with known categories, the region climate tie-breaker averages only the region's templates that share a category with the mod biome, so a mixed region no longer looks temperate on average - A small region affinity term favors regions whose templates share the mod biome's categories
This commit is contained in:
1 parent
ad66538d7a
commit
4d79d5ed5b
2 files changed
+145
-1
No files matched your search
@@ -27,6 +27,7 @@ import com.google.gson.JsonObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@@ -42,6 +43,7 @@ final class ModBiomeAdopter {
|
||||
private static final int VEGETAL_STEP = IrisDecorationStep.VEGETAL_DECORATION.ordinal();
|
||||
private static final double CATEGORY_WEIGHT = 1D;
|
||||
private static final double REGION_CLIMATE_WEIGHT = 0.25D;
|
||||
private static final double REGION_CATEGORY_WEIGHT = 0.25D;
|
||||
private static final double REUSE_WEIGHT = 0.05D;
|
||||
private static final double THEMED_REGION_PENALTY = 0.6D;
|
||||
private static final double BARE_SURFACE_PENALTY = 3D;
|
||||
@@ -107,8 +109,10 @@ final class ModBiomeAdopter {
|
||||
if (excludedRegions.contains(region.key())) {
|
||||
continue;
|
||||
}
|
||||
IngestClimate regionClimate = regionClimate(region, role, categories);
|
||||
double regionPenalty = (themedRegions.contains(region.key()) ? THEMED_REGION_PENALTY : 0D)
|
||||
+ (region.climate() == null ? 0D : REGION_CLIMATE_WEIGHT * climate.distance(region.climate()));
|
||||
+ (regionClimate == null ? 0D : REGION_CLIMATE_WEIGHT * climate.distance(regionClimate))
|
||||
+ REGION_CATEGORY_WEIGHT * (1D - regionAffinity(region, role, categories));
|
||||
for (String template : region.pool(role)) {
|
||||
IngestClimate templateClimate = model.biomeClimate(template);
|
||||
double score = climate.distance(templateClimate == null ? region.climate() : templateClimate)
|
||||
@@ -125,6 +129,34 @@ final class ModBiomeAdopter {
|
||||
return best;
|
||||
}
|
||||
|
||||
private IngestClimate regionClimate(IngestPackModel.RegionProfile region, BiomeRole role, Set<String> categories) {
|
||||
if (role != BiomeRole.LAND || categories.isEmpty()) {
|
||||
return region.climate();
|
||||
}
|
||||
List<IngestClimate> shared = new ArrayList<>();
|
||||
for (String template : region.pool(BiomeRole.LAND)) {
|
||||
IngestClimate templateClimate = model.biomeClimate(template);
|
||||
if (templateClimate != null && !Collections.disjoint(model.biomeCategories(template), categories)) {
|
||||
shared.add(templateClimate);
|
||||
}
|
||||
}
|
||||
return shared.isEmpty() ? region.climate() : IngestClimate.average(shared);
|
||||
}
|
||||
|
||||
private double regionAffinity(IngestPackModel.RegionProfile region, BiomeRole role, Set<String> categories) {
|
||||
List<String> pool = region.pool(role);
|
||||
if (categories.isEmpty() || pool.isEmpty()) {
|
||||
return 1D;
|
||||
}
|
||||
int shared = 0;
|
||||
for (String template : pool) {
|
||||
if (!Collections.disjoint(model.biomeCategories(template), categories)) {
|
||||
shared++;
|
||||
}
|
||||
}
|
||||
return shared / (double) pool.size();
|
||||
}
|
||||
|
||||
private static Set<String> themedRegions(List<IngestPackModel.RegionProfile> regions) {
|
||||
if (regions.isEmpty()) {
|
||||
return Set.of();
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* 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.pack.ingest;
|
||||
|
||||
import art.arcane.iris.pack.ingest.catalog.CatalogBiome;
|
||||
import art.arcane.iris.pack.ingest.catalog.CatalogDimensionType;
|
||||
import art.arcane.iris.pack.ingest.catalog.CatalogNamespace;
|
||||
import art.arcane.iris.pack.ingest.catalog.WorldgenCatalog;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class IngestRegionAffinityTest {
|
||||
private static final String MOD = "modisles";
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder folder = new TemporaryFolder();
|
||||
|
||||
@Test
|
||||
public void modBiomeJoinsTheRegionWhoseTemplatesShareItsCategory() throws Exception {
|
||||
Path root = folder.getRoot().toPath();
|
||||
Path source = root.resolve("source");
|
||||
ModIngestFixture.write(source, "dimensions/overworld.json", """
|
||||
{"name": "Overworld", "environment": "NORMAL", "regions": ["temperate", "hot", "cold", "wet", "magnetic", "mushroom"],
|
||||
"dimensionHeight": {"min": -64, "max": 320}}
|
||||
""");
|
||||
region(source, "temperate", 1, List.of("temperate/plains"));
|
||||
region(source, "hot", 1, List.of("hot/desert"));
|
||||
region(source, "cold", 1, List.of("cold/snow"));
|
||||
region(source, "wet", 1, List.of("wet/swamp"));
|
||||
region(source, "magnetic", 15, List.of("magnetic/mycelium", "magnetic/plains", "magnetic/frozen", "magnetic/marsh"));
|
||||
region(source, "mushroom", 15, List.of("mushroom/fields", "mushroom/forest", "mushroom/crimson", "mushroom/warped"));
|
||||
biome(source, "temperate/plains", "minecraft:plains");
|
||||
biome(source, "hot/desert", "minecraft:desert");
|
||||
biome(source, "cold/snow", "minecraft:snowy_plains");
|
||||
biome(source, "wet/swamp", "minecraft:swamp");
|
||||
biome(source, "magnetic/mycelium", "minecraft:mushroom_fields");
|
||||
biome(source, "magnetic/plains", "minecraft:plains");
|
||||
biome(source, "magnetic/frozen", "minecraft:snowy_plains");
|
||||
biome(source, "magnetic/marsh", "minecraft:swamp");
|
||||
biome(source, "mushroom/fields", "minecraft:mushroom_fields");
|
||||
biome(source, "mushroom/forest", "minecraft:mushroom_fields");
|
||||
biome(source, "mushroom/crimson", "minecraft:crimson_forest");
|
||||
biome(source, "mushroom/warped", "minecraft:warped_forest");
|
||||
Path target = root.resolve("packs").resolve("isles");
|
||||
|
||||
ModIngestReport report = ModIngester.ingest(new ModIngestRequest(source, target, "overworld", catalog(), Set.of(MOD), Set.of(), false));
|
||||
|
||||
String reason = ModIngestFixture.item(report, MOD + ":mirage_isles").reason();
|
||||
assertTrue(reason, reason.contains("in region mushroom "));
|
||||
}
|
||||
|
||||
private static void region(Path pack, String key, int rarity, List<String> land) throws IOException {
|
||||
StringBuilder pool = new StringBuilder();
|
||||
for (String biome : land) {
|
||||
pool.append(pool.isEmpty() ? "" : ", ").append('"').append(biome).append('"');
|
||||
}
|
||||
ModIngestFixture.write(pack, "regions/" + key + ".json", "{\"name\": \"" + key + "\", \"rarity\": " + rarity + ", \"landBiomes\": [" + pool + "]}");
|
||||
}
|
||||
|
||||
private static void biome(Path pack, String key, String derivative) throws IOException {
|
||||
ModIngestFixture.write(pack, "biomes/" + key + ".json", "{\"name\": \"" + key + "\", \"derivative\": \"" + derivative + "\"}");
|
||||
}
|
||||
|
||||
private static WorldgenCatalog catalog() {
|
||||
List<CatalogBiome> biomes = new ArrayList<>();
|
||||
biomes.add(biome("minecraft:plains", 0.8F, 0.4F, "c:is_plains"));
|
||||
biomes.add(biome("minecraft:desert", 2.0F, 0.0F, "c:is_desert"));
|
||||
biomes.add(biome("minecraft:snowy_plains", 0.0F, 0.5F, "c:is_snowy"));
|
||||
biomes.add(biome("minecraft:swamp", 0.8F, 0.9F, "c:is_swamp"));
|
||||
biomes.add(biome("minecraft:mushroom_fields", 0.9F, 1.0F, "c:is_mushroom"));
|
||||
biomes.add(biome("minecraft:crimson_forest", 2.0F, 0.0F, "c:is_nether"));
|
||||
biomes.add(biome("minecraft:warped_forest", 2.0F, 0.0F, "c:is_nether"));
|
||||
biomes.add(biome(MOD + ":mirage_isles", 0.7F, 0.8F, "c:is_mushroom"));
|
||||
return new WorldgenCatalog(WorldgenCatalog.FORMAT, "26.3", "fabric", 1L, "affinity",
|
||||
List.of(new CatalogNamespace(MOD, "Mod Isles", "1")), biomes, List.of(), List.of(),
|
||||
List.of(new CatalogDimensionType("minecraft:overworld", -64, 384, 384, null)), List.of(), Map.of());
|
||||
}
|
||||
|
||||
private static CatalogBiome biome(String key, float temperature, float downfall, String categoryTag) {
|
||||
List<List<String>> steps = new ArrayList<>(11);
|
||||
for (int index = 0; index < 11; index++) {
|
||||
steps.add(List.of());
|
||||
}
|
||||
return new CatalogBiome(key, temperature, downfall, true, List.of("minecraft:is_overworld", categoryTag), steps, List.of(), null);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user