Calibrated converted decorator density

- Patch decorators converted from features that snap to a leaf-blocked heightmap lose the share of placements that land on tree canopy in the declaring biomes
- Canopy is estimated from the tree-like features that run before the decoration in each declaring biome's vegetal step, using their expected per-chunk count and a typical crown footprint
- Patches that snap below leaves or run before the trees keep their full density
This commit is contained in:
Brian Neumann-Fopiano committed 2026-10-14 21:38:00 -04:00
1 parent 7767d6d30a
commit c9786f2d23
7 files changed
+204 -7

No files matched your search

@@ -0,0 +1,81 @@
/*
* 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.generation.decoration.IrisDecorationStep;
import art.arcane.iris.pack.ingest.catalog.CatalogBiome;
import art.arcane.iris.pack.ingest.catalog.CatalogPlacedFeature;
import art.arcane.iris.pack.ingest.catalog.WorldgenCatalogIndex;
import java.util.List;
import java.util.Optional;
import java.util.Set;
final class CanopyEstimate {
static final double CROWN_COLUMNS = 20D;
private static final double UNKNOWN_TREE_COUNT = 1D;
private static final double COLUMNS_PER_CHUNK = 256D;
private static final int VEGETAL_STEP = IrisDecorationStep.VEGETAL_DECORATION.ordinal();
private final WorldgenCatalogIndex index;
private final TreeFeatures trees;
CanopyEstimate(WorldgenCatalogIndex index) {
this.index = index;
this.trees = new TreeFeatures(index);
}
double occlusion(String featureKey, Set<String> declaringBiomes) {
if (declaringBiomes.isEmpty()) {
return 0D;
}
double total = 0D;
for (String biomeKey : declaringBiomes) {
Optional<CatalogBiome> biome = index.biome(biomeKey);
total += biome.map((CatalogBiome value) -> canopyBefore(value, featureKey)).orElse(0D);
}
return total / declaringBiomes.size();
}
private double canopyBefore(CatalogBiome biome, String featureKey) {
if (biome.featureSteps().size() <= VEGETAL_STEP) {
return 0D;
}
List<String> vegetal = biome.featureSteps().get(VEGETAL_STEP);
double treesPerChunk = 0D;
for (String candidate : vegetal) {
if (candidate.equals(featureKey)) {
break;
}
Optional<CatalogPlacedFeature> feature = index.placedFeature(candidate);
if (feature.isPresent() && trees.isTree(feature.get())) {
treesPerChunk += treesPerChunk(feature.get());
}
}
return 1D - Math.exp(-treesPerChunk * CROWN_COLUMNS / COLUMNS_PER_CHUNK);
}
private static double treesPerChunk(CatalogPlacedFeature tree) {
try {
return VanillaPlacementChain.expectedCount(VanillaJson.placement(tree.placement()));
} catch (IngestConversionException unknownCount) {
return UNKNOWN_TREE_COUNT;
}
}
}
@@ -41,6 +41,7 @@ final class ModFeatureIngester {
private final IngestPackModel model;
private final WorldgenCatalogIndex index;
private final TreeFeatures trees;
private final CanopyEstimate canopy;
private final Map<String, FeaturePlan> plans = new TreeMap<>();
private final Set<String> nativeKeys = new TreeSet<>();
private final Set<String> vanillaScopedKeys = new TreeSet<>();
@@ -49,6 +50,7 @@ final class ModFeatureIngester {
this.model = model;
this.index = index;
this.trees = new TreeFeatures(index);
this.canopy = new CanopyEstimate(index);
Map<String, Set<String>> declaring = new TreeMap<>();
Map<String, Set<Integer>> steps = new TreeMap<>();
for (CatalogBiome biome : index.catalog().biomes()) {
@@ -151,7 +153,8 @@ final class ModFeatureIngester {
return new FeaturePlan(key, declaring, steps, deposits, null, "");
}
if (PatchDecoratorConverter.handles(placed)) {
return new FeaturePlan(key, declaring, steps, null, PatchDecoratorConverter.convert(placed, index), "");
return new FeaturePlan(key, declaring, steps, null,
PatchDecoratorConverter.convert(placed, index, canopy.occlusion(key, declaring)), "");
}
} catch (IngestConversionException e) {
return FeaturePlan.passthrough(key, declaring, steps, "generated natively: " + e.getMessage());
@@ -45,7 +45,7 @@ final class PatchDecoratorConverter {
return type.equals(SIMPLE_BLOCK) || LEGACY_PATCH_TYPES.contains(type);
}
static JsonObject convert(CatalogPlacedFeature feature, WorldgenCatalogIndex index) throws IngestConversionException {
static JsonObject convert(CatalogPlacedFeature feature, WorldgenCatalogIndex index, double canopy) throws IngestConversionException {
String type = VanillaJson.namespaced(feature.featureType());
JsonObject config = VanillaJson.featureConfig(feature.config());
VanillaPlacementChain outer = VanillaPlacementChain.surfaceChain(VanillaJson.placement(feature.placement()));
@@ -67,6 +67,9 @@ final class PatchDecoratorConverter {
if (expected <= 0D) {
throw new IngestConversionException("patch placement never places");
}
if (outer.leafBlocked()) {
expected *= 1D - Math.max(0D, Math.min(1D, canopy));
}
List<JsonObject> palette = VanillaBlockStates.palette(provider);
JsonObject decorator = new JsonObject();
decorator.addProperty("chance", IngestJson.round(columnCoverage(expected)));
@@ -27,12 +27,14 @@ import java.util.Set;
final class VanillaPlacementChain {
private static final Set<String> SURFACE_HEIGHTMAPS = Set.of("MOTION_BLOCKING", "MOTION_BLOCKING_NO_LEAVES", "WORLD_SURFACE", "WORLD_SURFACE_WG");
private static final Set<String> LEAF_BLOCKED_HEIGHTMAPS = Set.of("MOTION_BLOCKING", "WORLD_SURFACE", "WORLD_SURFACE_WG");
private static final int NOISE_SAMPLES = 201;
private final Set<String> whitelist = new LinkedHashSet<>();
private double expectedPlacements = 1D;
private double surfaceHitChance = 1D;
private boolean surface;
private boolean leafBlocked;
private VanillaPlacementChain() {
}
@@ -67,6 +69,28 @@ final class VanillaPlacementChain {
return surfaceHitChance;
}
boolean leafBlocked() {
return leafBlocked;
}
static double expectedCount(JsonArray placement) throws IngestConversionException {
double expected = 1D;
for (JsonElement modifier : placement) {
JsonObject object = VanillaJson.object(modifier, "placement modifier");
switch (VanillaJson.type(object, "type")) {
case "minecraft:count", "minecraft:count_on_every_layer" -> expected *= Math.max(0D, VanillaIntProviders.stats(object.get("count")).mean());
case "minecraft:rarity_filter" -> expected /= Math.max(1D, VanillaJson.number(object.get("chance"), "rarity_filter.chance"));
case "minecraft:random_chance" -> expected *= clampProbability(VanillaJson.number(object.get("chance"), "random_chance.chance"));
case "minecraft:noise_threshold_count" -> expected *= (VanillaJson.number(object.get("below_noise"), "noise_threshold_count.below_noise")
+ VanillaJson.number(object.get("above_noise"), "noise_threshold_count.above_noise")) / 2D;
case "minecraft:noise_based_count" -> expected *= noiseBasedMean(object);
default -> {
}
}
}
return expected;
}
Set<String> whitelist() {
return whitelist;
}
@@ -99,6 +123,7 @@ final class VanillaPlacementChain {
throw new IngestConversionException("heightmap " + heightmap + " is not a dry surface placement");
}
surface = true;
leafBlocked = LEAF_BLOCKED_HEIGHTMAPS.contains(heightmap);
}
private void readVerticalOffset(JsonElement provider) throws IngestConversionException {