mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-10-26 22:10:18 +00:00
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:
1 parent
7767d6d30a
commit
c9786f2d23
7 files changed
+204
-7
No files matched your search
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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.CatalogNamespace;
|
||||
import art.arcane.iris.pack.ingest.catalog.CatalogPlacedFeature;
|
||||
import art.arcane.iris.pack.ingest.catalog.WorldgenCatalog;
|
||||
import art.arcane.iris.pack.ingest.catalog.WorldgenCatalogIndex;
|
||||
import com.google.gson.JsonParser;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class CanopyEstimateTest {
|
||||
private static final double CANOPY = 1D - Math.exp(-10D * CanopyEstimate.CROWN_COLUMNS / 256D);
|
||||
|
||||
@Test
|
||||
public void flowersPlacedAfterTreesSeeTheTreeCanopy() {
|
||||
CanopyEstimate estimate = new CanopyEstimate(WorldgenCatalogIndex.of(catalog()));
|
||||
|
||||
assertEquals(CANOPY, estimate.occlusion("mod:flowers_after", Set.of("mod:woods")), 0.000001D);
|
||||
assertEquals(0D, estimate.occlusion("mod:flowers_before", Set.of("mod:woods")), 0.000001D);
|
||||
assertEquals(CANOPY / 2D, estimate.occlusion("mod:flowers_after", Set.of("mod:woods", "mod:meadow")), 0.000001D);
|
||||
}
|
||||
|
||||
private static WorldgenCatalog catalog() {
|
||||
List<CatalogBiome> biomes = List.of(
|
||||
biome("mod:woods", List.of("mod:flowers_before", "mod:oak_trees", "mod:flowers_after")),
|
||||
biome("mod:meadow", List.of("mod:flowers_after")));
|
||||
List<CatalogPlacedFeature> features = new ArrayList<>();
|
||||
features.add(new CatalogPlacedFeature("mod:oak_trees", "mod:oak_trees", "minecraft:tree", JsonParser.parseString("{}"),
|
||||
JsonParser.parseString("[{\"type\": \"minecraft:count\", \"count\": 10}, {\"type\": \"minecraft:in_square\"},"
|
||||
+ "{\"type\": \"minecraft:surface_water_depth_filter\", \"max_water_depth\": 0}, {\"type\": \"minecraft:biome\"}]")));
|
||||
return new WorldgenCatalog(WorldgenCatalog.FORMAT, "26.3", "fabric", 1L, "canopy", List.of(new CatalogNamespace("mod", "Mod", "1")),
|
||||
biomes, features, List.of(), List.of(), List.of());
|
||||
}
|
||||
|
||||
private static CatalogBiome biome(String key, List<String> vegetal) {
|
||||
List<List<String>> steps = new ArrayList<>(11);
|
||||
for (int index = 0; index < 11; index++) {
|
||||
steps.add(index == ModIngestFixture.VEGETAL_STEP ? vegetal : List.of());
|
||||
}
|
||||
return new CatalogBiome(key, 0.7F, 0.8F, true, List.of("minecraft:is_overworld"), steps, List.of(), null);
|
||||
}
|
||||
}
|
||||
@@ -114,12 +114,29 @@ public class FeatureConverterFormatTest {
|
||||
+ "{\"type\": \"minecraft:heightmap\", \"heightmap\": \"WORLD_SURFACE_WG\"}, {\"type\": \"minecraft:biome\"},"
|
||||
+ "{\"type\": \"minecraft:count\", \"count\": 96}," + PATCH_TAIL + "]");
|
||||
|
||||
JsonObject decorator = PatchDecoratorConverter.convert(lavender, index());
|
||||
JsonObject decorator = PatchDecoratorConverter.convert(lavender, index(), 0D);
|
||||
|
||||
assertEquals(1.0D - Math.exp(-(15.0D * 96.0D * 0.25D) / 256.0D), decorator.get("chance").getAsDouble(), 0.000001D);
|
||||
assertTrue(decorator.get("chance").getAsDouble() < 1.0D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void leafBlockedHeightmapsLoseTheCanopyShareOfTheirPlacements() throws Exception {
|
||||
CatalogPlacedFeature lavender = feature(PatchDecoratorConverter.SIMPLE_BLOCK,
|
||||
"{\"type\": \"minecraft:simple_block\", \"to_place\": {\"id\": \"examplemod:lavender\"}}",
|
||||
"[{\"type\": \"minecraft:count\", \"count\": 4}, {\"type\": \"minecraft:in_square\"},"
|
||||
+ "{\"type\": \"minecraft:heightmap\", \"heightmap\": \"MOTION_BLOCKING\"}, {\"type\": \"minecraft:biome\"}]");
|
||||
CatalogPlacedFeature underLeaves = feature(PatchDecoratorConverter.SIMPLE_BLOCK,
|
||||
"{\"type\": \"minecraft:simple_block\", \"to_place\": {\"id\": \"examplemod:lavender\"}}",
|
||||
"[{\"type\": \"minecraft:count\", \"count\": 4}, {\"type\": \"minecraft:in_square\"},"
|
||||
+ "{\"type\": \"minecraft:heightmap\", \"heightmap\": \"MOTION_BLOCKING_NO_LEAVES\"}, {\"type\": \"minecraft:biome\"}]");
|
||||
|
||||
assertEquals(1.0D - Math.exp(-(4.0D * 0.5D) / 256.0D),
|
||||
PatchDecoratorConverter.convert(lavender, index(), 0.5D).get("chance").getAsDouble(), 0.000001D);
|
||||
assertEquals(1.0D - Math.exp(-4.0D / 256.0D),
|
||||
PatchDecoratorConverter.convert(underLeaves, index(), 0.5D).get("chance").getAsDouble(), 0.000001D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unnamespacedTypesAndClampedCountsConvert() throws Exception {
|
||||
CatalogPlacedFeature flowers = feature("simple_block", "{\"type\": \"simple_block\", \"to_place\": {\"id\": \"minecraft:poppy\"}}", """
|
||||
@@ -134,7 +151,7 @@ public class FeatureConverterFormatTest {
|
||||
{"type": "minecraft:biome"}]
|
||||
""");
|
||||
|
||||
JsonObject decorator = PatchDecoratorConverter.convert(flowers, index());
|
||||
JsonObject decorator = PatchDecoratorConverter.convert(flowers, index(), 0D);
|
||||
|
||||
assertEquals(1.0D - Math.exp(-(0.5D * 0.2D * 0.25D) / 256.0D), decorator.get("chance").getAsDouble(), 0.000001D);
|
||||
assertEquals("minecraft:grass_block", decorator.getAsJsonArray("whitelist").get(0).getAsJsonObject().get("block").getAsString());
|
||||
@@ -149,8 +166,8 @@ public class FeatureConverterFormatTest {
|
||||
"{\"type\": \"minecraft:simple_block\", \"to_place\": \"minecraft:flower_plain\"}",
|
||||
"[{\"type\": \"minecraft:heightmap\", \"heightmap\": \"MOTION_BLOCKING\"}]");
|
||||
|
||||
assertThrows(IngestConversionException.class, () -> PatchDecoratorConverter.convert(seagrass, index()));
|
||||
IngestConversionException reference = assertThrows(IngestConversionException.class, () -> PatchDecoratorConverter.convert(plains, index()));
|
||||
assertThrows(IngestConversionException.class, () -> PatchDecoratorConverter.convert(seagrass, index(), 0D));
|
||||
IngestConversionException reference = assertThrows(IngestConversionException.class, () -> PatchDecoratorConverter.convert(plains, index(), 0D));
|
||||
assertTrue(reference.getMessage(), reference.getMessage().contains("minecraft:flower_plain"));
|
||||
}
|
||||
|
||||
|
||||
@@ -123,7 +123,9 @@ public class ModIngesterFeatureTest {
|
||||
assertNotNull(mapleFlowers);
|
||||
assertNotNull(forestFlowers);
|
||||
assertEquals(2, forest.getAsJsonArray("decorators").size());
|
||||
assertEquals(1.0D - Math.exp(-(1.0D / 4.0D * 32.0D * 0.25D) / 256.0D), forestFlowers.get("chance").getAsDouble(), 0.000001D);
|
||||
double mapleCanopy = 1.0D - Math.exp(-CanopyEstimate.CROWN_COLUMNS / 256.0D);
|
||||
double openShare = 1.0D - mapleCanopy / 2.0D;
|
||||
assertEquals(1.0D - Math.exp(-(1.0D / 4.0D * 32.0D * 0.25D * openShare) / 256.0D), forestFlowers.get("chance").getAsDouble(), 0.000001D);
|
||||
JsonArray palette = forestFlowers.getAsJsonArray("palette");
|
||||
assertEquals(3, palette.get(0).getAsJsonObject().get("weight").getAsInt());
|
||||
assertEquals("examplemod:glowbell", palette.get(1).getAsJsonObject().get("block").getAsString());
|
||||
|
||||
Reference in new issue
Block a user