mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-29 09:15:27 +00:00
Datapack export fidelity fixes
- Aquatic decorators place on the sea floor in water only - Decorator waterlogging follows the placement site - Templates never bake waterlogged blocks - Object blocks outside the nominal box stay in the template - Procedural objects export their pre-built variants as content-keyed templates - Surface objects anchor on the ocean floor heightmap - Surface objects reject leaf, log, or fluid ground under the origin - Surface support checks test base corners with a slope-scaled drop - Support ground search covers the full 16 block window - MIN_HEIGHT, MAX_HEIGHT, and stilt modes sample terrain across every allowed rotation - Procedural tree roots extend down to the ground - Underwater objects need water and stay below the surface - On-water objects anchor at the fluid surface - Unsupported coral, sea pickles, and wall fans are left out of templates - Object placements honor slopeCondition - Two-block plants place both halves - Shore decorators need solid ground below - Decorator coverage matches the Iris style density - Patchy decorator styles export as noise threshold patches - Palette end weights round to the nearest count - Ores in deepslate place their deepslate variants - Pack description tells players to keep the Default pack selected - Aquifer floods open sea cells near the fluid height
This commit is contained in:
1 parent
1ed1044474
commit
7ff4292013
25 files changed
+2518
-186
No files matched your search
+73
-1
@@ -4,6 +4,7 @@ import art.arcane.iris.generation.cave.IrisCaveProfile;
|
||||
import art.arcane.iris.pack.datapack.export.ExportTestPacks;
|
||||
import art.arcane.iris.pack.datapack.export.compile.PackCompileContext;
|
||||
import art.arcane.iris.pack.datapack.export.ir.AquiferDef;
|
||||
import art.arcane.iris.pack.datapack.export.ir.Axis;
|
||||
import art.arcane.iris.pack.datapack.export.ir.ExportDiagnostic;
|
||||
import art.arcane.iris.pack.datapack.export.ir.ExportLimit;
|
||||
import art.arcane.iris.pack.datapack.export.ir.Field;
|
||||
@@ -26,6 +27,16 @@ import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class AquiferCompilerTest {
|
||||
private static final Field SURFACE = new Field.Const(120.0);
|
||||
private static final Field SEA_FLOOR_SLOPE = new Field.Coord(Axis.X, Field.Tiling.CLAMP, -1000, 1000, -100.0, 300.0);
|
||||
private static final Field HIGH_ESTIMATE = new Field.Const(120.0);
|
||||
private static final int SEA_X = -275;
|
||||
private static final int LAND_X = 400;
|
||||
private static final int DEEP_SEA_X = -800;
|
||||
private static final int SHORE_X = -165;
|
||||
private static final int HILL_X = -125;
|
||||
private static final int SEA_FLOOR = 45;
|
||||
private static final int FLUID_HEIGHT = 63;
|
||||
private static final double FULLY_FLOODED = 0.8;
|
||||
private static final double DRY = -1.0;
|
||||
private static final double PARTIAL = 0.6;
|
||||
private static final int FLUID_BAND_HEIGHT = 40;
|
||||
@@ -45,12 +56,67 @@ public class AquiferCompilerTest {
|
||||
PackCompileContext context = compile(CaveTestPacks.dimension(20), CaveTestPacks.constantProfile(-0.1));
|
||||
|
||||
AquiferDef aquifer = context.aquifer();
|
||||
assertEquals(AquiferDef.dry(SURFACE), aquifer);
|
||||
AquiferDef vanilla = AquiferDef.dry(SURFACE);
|
||||
assertEquals(vanilla.barrier(), aquifer.barrier());
|
||||
assertEquals(vanilla.spread(), aquifer.spread());
|
||||
assertEquals(vanilla.lava(), aquifer.lava());
|
||||
assertEquals(vanilla.exclusion(), aquifer.exclusion());
|
||||
assertEquals(vanilla.surfaceLevel(), aquifer.surfaceLevel());
|
||||
for (int y = CaveTestPacks.MIN_Y; y < CaveTestPacks.MAX_Y; y += 8) {
|
||||
assertEquals(DRY, CaveTestPacks.sample(aquifer.floodedness(), context.noises(), 17, y, -9), 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void openWaterAboveTheTerrainFloodsToSeaLevel() throws Exception {
|
||||
PackCompileContext context = compile(CaveTestPacks.dimension(20), CaveTestPacks.constantProfile(-0.1), SEA_FLOOR_SLOPE, SEA_FLOOR_SLOPE);
|
||||
|
||||
Field floodedness = context.aquifer().floodedness();
|
||||
assertTrue(CaveTestPacks.sample(floodedness, context.noises(), SEA_X, SEA_FLOOR + 1, 4) > FULLY_FLOODED);
|
||||
assertTrue(CaveTestPacks.sample(floodedness, context.noises(), SEA_X, FLUID_HEIGHT, 4) > FULLY_FLOODED);
|
||||
assertTrue(CaveTestPacks.sample(floodedness, context.noises(), SEA_X, FLUID_HEIGHT + 6, 4) > FULLY_FLOODED);
|
||||
assertTrue(CaveTestPacks.sample(floodedness, context.noises(), SEA_X, SEA_FLOOR - 4, 4) > FULLY_FLOODED);
|
||||
assertEquals(DRY, CaveTestPacks.sample(floodedness, context.noises(), SEA_X, SEA_FLOOR - 12, 4), 0.0);
|
||||
assertEquals(DRY, CaveTestPacks.sample(floodedness, context.noises(), LAND_X, FLUID_HEIGHT - 10, 4), 0.0);
|
||||
assertEquals(DRY, CaveTestPacks.sample(floodedness, context.noises(), LAND_X, SEA_FLOOR + 1, 4), 0.0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void openWaterLiftStaysNearSeaLevel() throws Exception {
|
||||
PackCompileContext context = compile(CaveTestPacks.dimension(20), CaveTestPacks.constantProfile(-0.1), SEA_FLOOR_SLOPE, SEA_FLOOR_SLOPE);
|
||||
|
||||
Field floodedness = context.aquifer().floodedness();
|
||||
assertEquals(DRY, CaveTestPacks.sample(floodedness, context.noises(), DEEP_SEA_X, FLUID_HEIGHT - 40, 4), 0.0);
|
||||
assertTrue(CaveTestPacks.sample(floodedness, context.noises(), DEEP_SEA_X, FLUID_HEIGHT - 20, 4) > FULLY_FLOODED);
|
||||
assertEquals(DRY, CaveTestPacks.sample(floodedness, context.noises(), SEA_X, FLUID_HEIGHT + 12, 4), 0.0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void openWaterLiftStopsAtTheShore() throws Exception {
|
||||
PackCompileContext context = compile(CaveTestPacks.dimension(20), CaveTestPacks.constantProfile(-0.1), SEA_FLOOR_SLOPE, SEA_FLOOR_SLOPE);
|
||||
|
||||
Field floodedness = context.aquifer().floodedness();
|
||||
assertTrue(CaveTestPacks.sample(floodedness, context.noises(), SHORE_X, FLUID_HEIGHT, 4) > FULLY_FLOODED);
|
||||
assertEquals(DRY, CaveTestPacks.sample(floodedness, context.noises(), HILL_X, FLUID_HEIGHT + 7, 4), 0.0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void openWaterLiftSkipsColumnsWithAHighSurfaceEstimate() throws Exception {
|
||||
PackCompileContext context = compile(CaveTestPacks.dimension(20), CaveTestPacks.constantProfile(-0.1), SEA_FLOOR_SLOPE, HIGH_ESTIMATE);
|
||||
|
||||
assertEquals(DRY, CaveTestPacks.sample(context.aquifer().floodedness(), context.noises(), SEA_X, SEA_FLOOR + 1, 4), 0.0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wetCavesBelowTheTerrainKeepPartialFlooding() throws Exception {
|
||||
PackCompileContext context = compile(CaveTestPacks.dimension(20), CaveTestPacks.constantProfile(-0.1).setAllowFluid(true), SEA_FLOOR_SLOPE, SEA_FLOOR_SLOPE);
|
||||
|
||||
Field floodedness = context.aquifer().floodedness();
|
||||
assertTrue(CaveTestPacks.sample(floodedness, context.noises(), SEA_X, SEA_FLOOR + 6, 4) > FULLY_FLOODED);
|
||||
assertEquals(PARTIAL, CaveTestPacks.sample(floodedness, context.noises(), SEA_X, SEA_FLOOR - 24, 4), 1.0e-6);
|
||||
assertEquals(PARTIAL, CaveTestPacks.sample(floodedness, context.noises(), LAND_X, FLUID_HEIGHT - 10, 4), 1.0e-6);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lavaAboveMinus10ReportsLimit() throws Exception {
|
||||
PackCompileContext context = compile(CaveTestPacks.dimension(60), CaveTestPacks.constantProfile(-0.1).setAllowLava(true));
|
||||
@@ -115,11 +181,17 @@ public class AquiferCompilerTest {
|
||||
}
|
||||
|
||||
private PackCompileContext compile(JsonObject dimension, IrisCaveProfile profile) throws Exception {
|
||||
return compile(dimension, profile, SURFACE, SURFACE);
|
||||
}
|
||||
|
||||
private PackCompileContext compile(JsonObject dimension, IrisCaveProfile profile, Field height, Field estimate) throws Exception {
|
||||
File pack = CaveTestPacks.pack(temporaryFolder.newFolder("pack"), dimension, CaveTestPacks.region(List.of("cave-only"), null),
|
||||
Map.of("cave-only", profile));
|
||||
IrisData data = IrisData.openRuntime(pack);
|
||||
try {
|
||||
PackCompileContext context = context(data, "cave-only");
|
||||
context.setHeight(height);
|
||||
context.setSurfaceEstimate(estimate);
|
||||
new CaveStage().apply(context);
|
||||
return context;
|
||||
} finally {
|
||||
|
||||
+8
-1
@@ -133,7 +133,14 @@ public class CaveStageTest {
|
||||
new CaveStage().apply(context);
|
||||
|
||||
assertEquals(new Field.Const(1.0e6), context.caves());
|
||||
assertEquals(AquiferDef.dry(SURFACE), context.aquifer());
|
||||
AquiferDef aquifer = context.aquifer();
|
||||
AquiferDef vanilla = AquiferDef.dry(SURFACE);
|
||||
assertEquals(vanilla.barrier(), aquifer.barrier());
|
||||
assertEquals(vanilla.spread(), aquifer.spread());
|
||||
assertEquals(vanilla.lava(), aquifer.lava());
|
||||
assertEquals(vanilla.exclusion(), aquifer.exclusion());
|
||||
assertEquals(vanilla.surfaceLevel(), aquifer.surfaceLevel());
|
||||
assertEquals(-1.0, CaveTestPacks.sample(aquifer.floodedness(), context.noises(), 4, 40, 4), 0.0);
|
||||
assertTrue(context.diagnostics().isEmpty());
|
||||
} finally {
|
||||
data.close();
|
||||
|
||||
+246
-1
@@ -1,9 +1,11 @@
|
||||
package art.arcane.iris.pack.datapack.export.compile.decoration;
|
||||
|
||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.pack.datapack.DataVersion;
|
||||
import art.arcane.iris.pack.datapack.export.ExportTestPacks;
|
||||
import art.arcane.iris.pack.datapack.export.compile.PackCompileContext;
|
||||
import art.arcane.iris.pack.datapack.export.compile.StageTestPacks;
|
||||
import art.arcane.iris.pack.datapack.export.compile.noise.VanillaNoiseModel;
|
||||
import art.arcane.iris.pack.datapack.export.compile.surface.MaterialProgramCompiler;
|
||||
import art.arcane.iris.pack.datapack.export.compile.surface.SurfaceStage;
|
||||
import art.arcane.iris.pack.datapack.export.ir.BiomeDef;
|
||||
@@ -13,6 +15,9 @@ import art.arcane.iris.pack.datapack.export.ir.Field;
|
||||
import art.arcane.iris.pack.datapack.export.ir.JsonResource;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.testsupport.PlatformLeakGuard;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import art.arcane.volmlib.util.noise.CNG;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
@@ -27,6 +32,7 @@ import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiPredicate;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
@@ -132,6 +138,167 @@ public class DecorationStageTest {
|
||||
modern.under("worldgen/feature/decorator/").getFirst().json().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aquaticDecoratorsPlaceOnlyUnderwater() throws Exception {
|
||||
Map<String, String> biomes = new LinkedHashMap<>();
|
||||
biomes.put("reef", "{\"decorators\":[" + decorator("seagrass", 0.2) + ","
|
||||
+ "{\"palette\":[{\"block\":\"kelp_plant\"}],\"chance\":0.02,\"stackMin\":2,\"stackMax\":6},"
|
||||
+ "{\"palette\":[{\"block\":\"kelp_plant\"}],\"chance\":0.03,\"stackMin\":2,\"stackMax\":6,\"partOf\":\"SEA_FLOOR\"}]}");
|
||||
Result result = decorate(biomes, DataVersion.V26_3, context -> {
|
||||
});
|
||||
|
||||
List<JsonResource> placed = result.under("worldgen/placed_feature/decorator/");
|
||||
assertEquals(3, placed.size());
|
||||
for (JsonResource resource : placed) {
|
||||
JsonArray placement = resource.json().getAsJsonObject().getAsJsonArray("placement");
|
||||
assertEquals(resource.path(), Placements.OCEAN_FLOOR,
|
||||
StageTestPacks.ofType(placement, "minecraft:heightmap").getFirst().get("heightmap").getAsString());
|
||||
JsonObject filter = StageTestPacks.ofType(placement, "minecraft:block_predicate_filter").getLast();
|
||||
assertFalse(resource.path(), StageTestPacks.ofType(filter, "minecraft:matching_fluids").isEmpty());
|
||||
assertTrue(resource.path(), StageTestPacks.ofType(filter, "minecraft:matching_block_tag").isEmpty());
|
||||
}
|
||||
for (JsonResource resource : result.under("worldgen/feature/decorator/")) {
|
||||
JsonObject feature = resource.json().getAsJsonObject();
|
||||
if (feature.has("allowed_placement")) {
|
||||
assertEquals(resource.path(), "minecraft:matching_fluids",
|
||||
feature.getAsJsonObject("allowed_placement").get("type").getAsString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shoreDecoratorsGrowOnSolidGroundBesideWater() throws Exception {
|
||||
Map<String, String> biomes = new LinkedHashMap<>();
|
||||
biomes.put("beach", "{\"decorators\":[{\"palette\":[{\"block\":\"sugar_cane\"}],\"partOf\":\"SHORE_LINE\",\"chance\":0.5,"
|
||||
+ "\"stackMin\":1,\"stackMax\":4}]}");
|
||||
Result result = decorate(biomes, DataVersion.V26_3, context -> {
|
||||
});
|
||||
|
||||
JsonArray placement = result.under("worldgen/placed_feature/decorator/").getFirst().json().getAsJsonObject().getAsJsonArray("placement");
|
||||
JsonObject filter = StageTestPacks.ofType(placement, "minecraft:block_predicate_filter").getLast();
|
||||
List<String> supports = new ArrayList<>();
|
||||
for (JsonObject solid : StageTestPacks.ofType(filter, "minecraft:solid")) {
|
||||
supports.add(solid.get("offset").toString());
|
||||
}
|
||||
assertEquals(List.of("[0,-1,0]"), supports);
|
||||
assertEquals(4, StageTestPacks.ofType(filter, "minecraft:matching_fluids").size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tallPlantsPlaceBothHalves() throws Exception {
|
||||
Map<String, String> biomes = new LinkedHashMap<>();
|
||||
biomes.put("reef", "{\"decorators\":[{\"palette\":[{\"block\":\"tall_seagrass\",\"data\":{\"half\":\"lower\"}}],"
|
||||
+ "\"topPalette\":[{\"block\":\"tall_seagrass\",\"data\":{\"half\":\"upper\"}}],\"partOf\":\"SEA_FLOOR\",\"chance\":0.2}]}");
|
||||
Result result = decorate(biomes, DataVersion.V26_3, context -> {
|
||||
});
|
||||
|
||||
JsonObject feature = result.under("worldgen/feature/decorator/").getFirst().json().getAsJsonObject();
|
||||
assertEquals(feature.toString(), "minecraft:simple_block", feature.get("type").getAsString());
|
||||
assertEquals("{\"id\":\"minecraft:tall_seagrass\",\"properties\":{\"half\":\"lower\"}}", feature.get("to_place").toString());
|
||||
JsonArray placement = result.under("worldgen/placed_feature/decorator/").getFirst().json().getAsJsonObject().getAsJsonArray("placement");
|
||||
List<String> water = new ArrayList<>();
|
||||
for (JsonObject fluid : StageTestPacks.ofType(placement, "minecraft:matching_fluids")) {
|
||||
water.add(fluid.has("offset") ? fluid.get("offset").toString() : "[0,0,0]");
|
||||
}
|
||||
assertEquals(List.of("[0,0,0]", "[0,1,0]"), water);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void waterlogFollowsWhereTheDecoratorPlaces() throws Exception {
|
||||
Map<String, String> biomes = new LinkedHashMap<>();
|
||||
biomes.put("reef", "{\"decorators\":[" + decorator("sea_pickle[pickles=2,waterlogged=false]", 0.2) + ","
|
||||
+ "{\"palette\":[{\"block\":\"oak_stairs[waterlogged=true]\"},{\"block\":\"short_grass\"}],\"chance\":0.1}]}");
|
||||
Result result = decorate(biomes, DataVersion.V26_3, context -> {
|
||||
});
|
||||
|
||||
String pickles = result.resource("data/iris_export/worldgen/feature/decorator/sea_pickle.json").toString();
|
||||
String stairs = result.resource("data/iris_export/worldgen/feature/decorator/oak_stairs.json").toString();
|
||||
assertTrue(pickles, pickles.contains("\"waterlogged\":\"true\""));
|
||||
assertTrue(stairs, stairs.contains("\"waterlogged\":\"false\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void paletteEndsCarryHalfWeightLikeIrisRounding() throws Exception {
|
||||
Map<String, String> biomes = new LinkedHashMap<>();
|
||||
biomes.put("meadow", "{\"decorators\":[{\"palette\":[{\"block\":\"bush\"},{\"block\":\"air\",\"weight\":4}],\"chance\":0.5},"
|
||||
+ "{\"palette\":[{\"block\":\"fern\",\"weight\":2},{\"block\":\"short_grass\",\"weight\":3}],\"chance\":0.2,\"partOf\":\"SHORE_LINE\"}]}");
|
||||
Result result = decorate(biomes, DataVersion.V26_3, context -> {
|
||||
});
|
||||
|
||||
JsonArray placement = placement(result, "data/iris_export/worldgen/placed_feature/decorator/bush.json");
|
||||
assertEquals(0.5 / 8.0, StageTestPacks.ofType(placement, "minecraft:random_chance").getFirst().get("chance").getAsDouble(), 1.0e-6);
|
||||
JsonArray weighted = result.resource("data/iris_export/worldgen/feature/decorator/fern.json").getAsJsonObject()
|
||||
.getAsJsonObject("to_place").getAsJsonArray("entries");
|
||||
assertEquals(3, weighted.get(0).getAsJsonObject().get("weight").getAsInt());
|
||||
assertEquals(5, weighted.get(1).getAsJsonObject().get("weight").getAsInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void styledDecoratorPlacesAtStyleCoverage() throws Exception {
|
||||
String style = "{\"style\":\"SIMPLEX\",\"zoom\":0.2,\"fracture\":{\"style\":\"STATIC\",\"multiplier\":8}}";
|
||||
Map<String, String> biomes = new LinkedHashMap<>();
|
||||
biomes.put("meadow", "{\"decorators\":[{\"palette\":[{\"block\":\"poppy\"}],\"chance\":0.2,\"style\":" + style + "}]}");
|
||||
Result result = decorate(biomes, DataVersion.V26_3, context -> {
|
||||
});
|
||||
|
||||
JsonArray placement = placement(result, "data/iris_export/worldgen/placed_feature/decorator/poppy.json");
|
||||
double exported = StageTestPacks.ofType(placement, "minecraft:random_chance").getFirst().get("chance").getAsDouble();
|
||||
double coverage = irisCoverage(style, 0.2);
|
||||
assertTrue("coverage " + coverage, coverage < 0.1);
|
||||
assertEquals(coverage, exported, coverage * 0.2);
|
||||
assertEquals("{\"type\":\"minecraft:simple_block\",\"to_place\":{\"id\":\"minecraft:poppy\"}}",
|
||||
result.resource("data/iris_export/worldgen/feature/decorator/poppy.json").toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void decoratorWhoseStyleNeverPassesIsLeftOut() throws Exception {
|
||||
Map<String, String> biomes = new LinkedHashMap<>();
|
||||
biomes.put("meadow", "{\"decorators\":[{\"palette\":[{\"block\":\"poppy\"}],\"chance\":0.5,\"style\":{\"style\":\"FLAT\"}},"
|
||||
+ decorator("short_grass", 0.3) + "]}");
|
||||
Result result = decorate(biomes, DataVersion.V26_3, context -> {
|
||||
});
|
||||
|
||||
assertEquals(List.of("iris_export:decorator/short_grass"), step(result.biomes().getFirst(), GenerationStep.VEGETAL_DECORATION));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clusteredStyleFollowsFittedNoisePattern() throws Exception {
|
||||
String style = "{\"style\":\"SIMPLEX\",\"zoom\":4}";
|
||||
Map<String, String> biomes = new LinkedHashMap<>();
|
||||
biomes.put("meadow", "{\"decorators\":[{\"palette\":[{\"block\":\"poppy\"},{\"block\":\"dandelion\",\"weight\":2}],\"chance\":0.3,\"style\":"
|
||||
+ style + "}]}");
|
||||
Result result = decorate(biomes, DataVersion.V26_3, context -> {
|
||||
});
|
||||
|
||||
JsonObject provider = result.resource("data/iris_export/worldgen/feature/decorator/poppy.json").getAsJsonObject()
|
||||
.getAsJsonObject("to_place");
|
||||
assertEquals("minecraft:noise_threshold", provider.get("type").getAsString());
|
||||
assertEquals("minecraft:air", provider.getAsJsonObject("default_state").get("id").getAsString());
|
||||
assertEquals(0.0, provider.get("high_chance").getAsDouble(), 0.0);
|
||||
List<String> low = new ArrayList<>();
|
||||
for (JsonElement state : provider.getAsJsonArray("low_states")) {
|
||||
low.add(state.getAsJsonObject().get("id").getAsString());
|
||||
}
|
||||
assertEquals(List.of("minecraft:poppy", "minecraft:dandelion", "minecraft:dandelion", "minecraft:dandelion"), low);
|
||||
assertTrue(StageTestPacks.ofType(placement(result, "data/iris_export/worldgen/placed_feature/decorator/poppy.json"),
|
||||
"minecraft:random_chance").isEmpty());
|
||||
|
||||
JsonObject noise = provider.getAsJsonObject("noise");
|
||||
List<Double> amplitudes = new ArrayList<>();
|
||||
for (JsonElement amplitude : noise.getAsJsonArray("amplitude_modifiers")) {
|
||||
amplitudes.add(amplitude.getAsDouble());
|
||||
}
|
||||
VanillaNoiseModel model = VanillaNoiseModel.create("iris_export:test", noise.get("base_octave").getAsInt(), amplitudes, 99L, DataVersion.V26_3);
|
||||
double scale = provider.get("scale").getAsDouble();
|
||||
double threshold = provider.get("threshold").getAsDouble();
|
||||
GatePattern iris = irisPattern(style, 0.3);
|
||||
GatePattern vanilla = pattern((x, z) -> model.sample(x * scale, 70.0 * scale, z * scale) < threshold);
|
||||
assertTrue("iris coverage " + iris.coverage(), iris.coverage() > 0.1 && iris.coverage() < 0.5);
|
||||
assertEquals(iris.coverage(), vanilla.coverage(), 0.03);
|
||||
assertTrue("iris patch " + iris.patch() + " vanilla " + vanilla.patch(),
|
||||
vanilla.patch() > iris.patch() * 0.7 && vanilla.patch() < iris.patch() * 1.4);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void columnWinnerSharesFollowIrisReservoirPick() {
|
||||
assertArrayEquals(new double[]{0.5, 0.5}, DecoratorCompiler.columnShares(new double[]{1.0, 1.0}), 1.0e-12);
|
||||
@@ -163,12 +330,40 @@ public class DecorationStageTest {
|
||||
JsonObject ore = result.resource("data/iris_export/worldgen/feature/deposit/coal_ore.json").getAsJsonObject();
|
||||
assertEquals("minecraft:ore", ore.get("type").getAsString());
|
||||
assertEquals(8, ore.get("size").getAsInt());
|
||||
JsonObject target = ore.getAsJsonArray("targets").get(0).getAsJsonObject();
|
||||
JsonObject target = ore.getAsJsonArray("targets").get(1).getAsJsonObject();
|
||||
assertEquals("{\"predicate_type\":\"minecraft:tag_match\",\"tag\":\"iris_export:deposit_host\"}", target.get("target").toString());
|
||||
assertEquals("{\"id\":\"minecraft:coal_ore\"}", target.get("state").toString());
|
||||
assertNotNull(result.resource("data/iris_export/tags/block/deposit_host.json"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void depositOresFollowTheirHostStone() throws Exception {
|
||||
String explicit = "{\"palette\":[{\"block\":\"deepslate_redstone_ore[lit=false]\"}],\"minHeight\":0,\"maxHeight\":40,"
|
||||
+ "\"minPerChunk\":1,\"maxPerChunk\":2,\"minSize\":4,\"maxSize\":4,\"replaceableBlocks\":[\"stone\",\"deepslate\",\"tuff\"]}";
|
||||
Map<String, String> biomes = new LinkedHashMap<>();
|
||||
biomes.put("hills", "{\"deposits\":[" + COAL + "," + explicit + "]}");
|
||||
Result result = decorate(biomes, DataVersion.V26_3, context -> {
|
||||
});
|
||||
|
||||
JsonArray coal = result.resource("data/iris_export/worldgen/feature/deposit/coal_ore.json").getAsJsonObject().getAsJsonArray("targets");
|
||||
assertEquals(2, coal.size());
|
||||
assertEquals("{\"predicate_type\":\"minecraft:block_match\",\"block\":\"minecraft:deepslate\"}",
|
||||
coal.get(0).getAsJsonObject().get("target").toString());
|
||||
assertEquals("{\"id\":\"minecraft:deepslate_coal_ore\"}", coal.get(0).getAsJsonObject().get("state").toString());
|
||||
assertEquals("{\"id\":\"minecraft:coal_ore\"}", coal.get(1).getAsJsonObject().get("state").toString());
|
||||
|
||||
JsonArray redstone = result.resource("data/iris_export/worldgen/feature/deposit/deepslate_redstone_ore.json").getAsJsonObject()
|
||||
.getAsJsonArray("targets");
|
||||
Map<String, String> byHost = new LinkedHashMap<>();
|
||||
for (JsonElement element : redstone) {
|
||||
JsonObject target = element.getAsJsonObject();
|
||||
byHost.put(target.getAsJsonObject("target").get("block").getAsString(), target.get("state").toString());
|
||||
}
|
||||
assertEquals("{\"id\":\"minecraft:redstone_ore\",\"properties\":{\"lit\":\"false\"}}", byHost.get("minecraft:stone"));
|
||||
assertEquals("{\"id\":\"minecraft:deepslate_redstone_ore\",\"properties\":{\"lit\":\"false\"}}", byHost.get("minecraft:deepslate"));
|
||||
assertEquals("{\"id\":\"minecraft:redstone_ore\",\"properties\":{\"lit\":\"false\"}}", byHost.get("minecraft:tuff"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void vanillaOreVeinsDisabled() throws Exception {
|
||||
Map<String, String> biomes = new LinkedHashMap<>();
|
||||
@@ -260,6 +455,56 @@ public class DecorationStageTest {
|
||||
return "{\"palette\":[{\"block\":\"" + block + "\"}],\"chance\":" + chance + "}";
|
||||
}
|
||||
|
||||
private static double irisCoverage(String styleJson, double chance) {
|
||||
return irisPattern(styleJson, chance).coverage();
|
||||
}
|
||||
|
||||
private static GatePattern irisPattern(String styleJson, double chance) {
|
||||
IrisGeneratorStyle style = new Gson().fromJson(styleJson, IrisGeneratorStyle.class);
|
||||
CNG generator = style.create(new RNG(4242L), null);
|
||||
double zoom = style.getZoom();
|
||||
return pattern((x, z) -> generator.fitDouble(0.0, 1.0, x / zoom, z / zoom) <= chance);
|
||||
}
|
||||
|
||||
private static GatePattern pattern(BiPredicate<Double, Double> gate) {
|
||||
int[] lags = {1, 2, 4, 8, 16, 32, 64, 128};
|
||||
int hits = 0;
|
||||
int total = 0;
|
||||
int[] both = new int[lags.length];
|
||||
for (int i = 0; i < 150; i++) {
|
||||
for (int j = 0; j < 150; j++) {
|
||||
double x = i * 197.0 + 3.0;
|
||||
double z = j * 173.0 - 11.0;
|
||||
total++;
|
||||
if (!gate.test(x, z)) {
|
||||
continue;
|
||||
}
|
||||
hits++;
|
||||
for (int lag = 0; lag < lags.length; lag++) {
|
||||
both[lag] += gate.test(x + lags[lag], z) ? 1 : 0;
|
||||
both[lag] += gate.test(x, z + lags[lag]) ? 1 : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
double coverage = (double) hits / total;
|
||||
double previousLag = 0.0;
|
||||
double previousExcess = 1.0;
|
||||
for (int lag = 0; lag < lags.length; lag++) {
|
||||
double excess = ((double) both[lag] / (2.0 * hits) - coverage) / (1.0 - coverage);
|
||||
if (excess < 0.5) {
|
||||
double low = previousLag == 0.0 ? 0.0 : Math.log(previousLag);
|
||||
double fraction = (previousExcess - 0.5) / (previousExcess - excess);
|
||||
return new GatePattern(coverage, previousLag == 0.0 ? lags[lag] * fraction : Math.exp(low + (Math.log(lags[lag]) - low) * fraction));
|
||||
}
|
||||
previousLag = lags[lag];
|
||||
previousExcess = excess;
|
||||
}
|
||||
return new GatePattern(coverage, lags[lags.length - 1]);
|
||||
}
|
||||
|
||||
private record GatePattern(double coverage, double patch) {
|
||||
}
|
||||
|
||||
private static List<String> step(BiomeDef biome, GenerationStep step) {
|
||||
List<String> features = new ArrayList<>();
|
||||
for (JsonElement feature : biome.json().getAsJsonArray("features").get(step.ordinal()).getAsJsonArray()) {
|
||||
|
||||
+157
@@ -0,0 +1,157 @@
|
||||
package art.arcane.iris.pack.datapack.export.compile.object;
|
||||
|
||||
import art.arcane.iris.generation.decoration.tree.TreeGrounding;
|
||||
import art.arcane.iris.pack.datapack.export.TemplateBlock;
|
||||
import art.arcane.iris.pack.datapack.export.ir.ExportDiagnostic;
|
||||
import art.arcane.iris.spi.IrisPlatform;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.iris.spi.PlatformRegistries;
|
||||
import art.arcane.iris.structure.object.IrisObject;
|
||||
import art.arcane.iris.testsupport.PlatformLeakGuard;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class ObjectSourceTest {
|
||||
@ClassRule
|
||||
public static final PlatformLeakGuard PLATFORM_GUARD = PlatformLeakGuard.clean();
|
||||
|
||||
@BeforeClass
|
||||
public static void bindPlatform() {
|
||||
IrisPlatforms.unbind();
|
||||
NativeBlockState stone = blockState("minecraft:stone");
|
||||
PlatformRegistries registries = mock(PlatformRegistries.class);
|
||||
when(registries.block(anyString())).thenReturn(stone);
|
||||
IrisPlatform platform = mock(IrisPlatform.class);
|
||||
when(platform.registries()).thenReturn(registries);
|
||||
when(platform.minecraftVersion()).thenReturn("26.3");
|
||||
IrisPlatforms.bind(platform);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void unbindPlatform() {
|
||||
IrisPlatforms.unbind();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void containedObjectKeepsItsBox() {
|
||||
IrisObject object = new IrisObject(3, 3, 3);
|
||||
object.setUnsigned(1, 0, 1, blockState("minecraft:oak_log[axis=y]"));
|
||||
object.setUnsigned(0, 2, 2, blockState("minecraft:oak_leaves[distance=1,persistent=true,waterlogged=false]"));
|
||||
List<ExportDiagnostic> diagnostics = new ArrayList<>();
|
||||
|
||||
ObjectSource source = ObjectSource.of(object, "objects/bush", diagnostics);
|
||||
|
||||
assertTrue(diagnostics.isEmpty());
|
||||
assertEquals(0, source.baseY());
|
||||
assertEquals(3, source.volume().sizeX());
|
||||
assertEquals(3, source.volume().sizeY());
|
||||
assertEquals(3, source.volume().sizeZ());
|
||||
assertEquals(2, source.volume().blocks().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void waterlogIsLeftToThePlacementSite() {
|
||||
IrisObject object = new IrisObject(1, 2, 1);
|
||||
object.setUnsigned(0, 0, 0, blockState("minecraft:tube_coral_block"));
|
||||
object.setUnsigned(0, 1, 0, blockState("minecraft:sea_pickle[pickles=2,waterlogged=true]"));
|
||||
|
||||
ObjectSource source = ObjectSource.of(object, "objects/reef", new ArrayList<>());
|
||||
|
||||
TemplateBlock pickle = blockAt(source, 0, 1, 0);
|
||||
assertEquals("false", pickle.state().properties().get("waterlogged"));
|
||||
assertEquals("2", pickle.state().properties().get("pickles"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rowsAndColumnsPastTheNominalBoxAreKeptAroundTheCenter() {
|
||||
IrisObject object = new IrisObject(3, 3, 3);
|
||||
object.setUnsigned(1, -1, 1, blockState("minecraft:oak_log[axis=y]"));
|
||||
object.setUnsigned(1, 0, 1, blockState("minecraft:oak_log[axis=y]"));
|
||||
object.setUnsigned(-1, 1, 1, blockState("minecraft:oak_log[axis=x]"));
|
||||
List<ExportDiagnostic> diagnostics = new ArrayList<>();
|
||||
|
||||
ObjectSource source = ObjectSource.of(object, "objects/tree", diagnostics);
|
||||
|
||||
assertTrue(diagnostics.isEmpty());
|
||||
assertEquals(3, source.volume().blocks().size());
|
||||
assertEquals(-1, source.baseY());
|
||||
int centerX = source.volume().sizeX() / 2;
|
||||
int centerZ = source.volume().sizeZ() / 2;
|
||||
TemplateBlock root = blockAt(source, centerX, 0, centerZ);
|
||||
assertEquals("minecraft:oak_log", root.state().name());
|
||||
TemplateBlock branch = blockAt(source, centerX - 2, 2, centerZ);
|
||||
assertEquals("x", branch.state().properties().get("axis"));
|
||||
|
||||
BakedVariant variant = new ObjectVariantBaker().bake("iris_export:object/tree/a", source, VariantSpec.builder().build());
|
||||
|
||||
assertEquals(-1, variant.baseY());
|
||||
assertEquals(3, variant.volume().blocks().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void treeRootsFollowTheTemplateShift() {
|
||||
IrisObject object = new IrisObject(3, 3, 3);
|
||||
NativeBlockState root = blockState("minecraft:oak_wood[axis=y]");
|
||||
object.setUnsigned(1, -1, 1, root);
|
||||
object.setUnsigned(0, -2, 1, root);
|
||||
object.setUnsigned(0, -1, 1, root);
|
||||
object.setUnsigned(1, 0, 1, blockState("minecraft:oak_log[axis=y]"));
|
||||
object.setTreeGrounding(TreeGrounding.create(List.of(
|
||||
new TreeGrounding.Root(0, -2, 0, root),
|
||||
new TreeGrounding.Root(-1, -3, 0, root),
|
||||
new TreeGrounding.Root(-1, -2, 0, root)), 3, Set.of()));
|
||||
|
||||
ObjectSource source = ObjectSource.of(object, "procedural/tree", new ArrayList<>());
|
||||
|
||||
assertEquals(-2, source.baseY());
|
||||
assertEquals(3, source.roots().reach());
|
||||
assertEquals(List.of("0,0,1", "1,1,1"), cells(source.roots()));
|
||||
assertEquals("minecraft:oak_wood", source.roots().cells().getFirst().state().name());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void objectsWithoutGroundingHaveNoRoots() {
|
||||
IrisObject object = new IrisObject(1, 1, 1);
|
||||
object.setUnsigned(0, 0, 0, blockState("minecraft:stone"));
|
||||
|
||||
assertFalse(ObjectSource.of(object, "objects/rock", new ArrayList<>()).roots().present());
|
||||
}
|
||||
|
||||
private static List<String> cells(TreeRoots roots) {
|
||||
List<String> cells = new ArrayList<>();
|
||||
for (TemplateBlock cell : roots.cells()) {
|
||||
cells.add(cell.x() + "," + cell.y() + "," + cell.z());
|
||||
}
|
||||
return cells;
|
||||
}
|
||||
|
||||
private static TemplateBlock blockAt(ObjectSource source, int x, int y, int z) {
|
||||
for (TemplateBlock block : source.volume().blocks()) {
|
||||
if (block.x() == x && block.y() == y && block.z() == z) {
|
||||
return block;
|
||||
}
|
||||
}
|
||||
throw new AssertionError("No block at " + x + "," + y + "," + z + " in " + source.volume().blocks());
|
||||
}
|
||||
|
||||
private static NativeBlockState blockState(String key) {
|
||||
NativeBlockState state = mock(NativeBlockState.class);
|
||||
when(state.key()).thenReturn(key);
|
||||
when(state.namespace()).thenReturn(key.substring(0, key.indexOf(':')));
|
||||
return state;
|
||||
}
|
||||
}
|
||||
+81
@@ -129,6 +129,87 @@ public class ObjectStageTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void proceduralTreesExportAsTemplates() throws Exception {
|
||||
File pack = pack();
|
||||
CompatTestPlatform.write(pack, "biomes/plains.json", """
|
||||
{"name":"Plains","proceduralObjects":{"trees":[{"name":"field-oak","chance":0.5,"density":2,"variants":2,"seed":7,
|
||||
"trunk":"minecraft:oak_log","leaves":"minecraft:oak_leaves","heightMin":5,"heightMax":7}]}}
|
||||
""");
|
||||
IrisData data = IrisData.openRuntime(pack);
|
||||
try {
|
||||
ExportIr ir = compile(data, DataVersion.V26_3, true);
|
||||
|
||||
JsonArray plains = features(ir, "plains");
|
||||
assertEquals(1, plains.get(GenerationStep.VEGETAL_DECORATION.ordinal()).getAsJsonArray().size());
|
||||
long templates = ir.binaryResources().stream()
|
||||
.filter(template -> template.path().contains("/procedural/") && template.path().contains("field-oak"))
|
||||
.count();
|
||||
assertTrue("procedural templates: " + templates, templates >= 2);
|
||||
} finally {
|
||||
data.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void proceduralTreeRootsReachDownToTheTerrain() throws Exception {
|
||||
File pack = pack();
|
||||
CompatTestPlatform.write(pack, "biomes/plains.json", """
|
||||
{"name":"Plains","proceduralObjects":{"trees":[{"name":"field-oak","chance":0.5,"density":2,"variants":2,"seed":7,
|
||||
"trunk":"minecraft:oak_log","leaves":"minecraft:oak_leaves","heightMin":5,"heightMax":7,"rootStyle":"TAPROOT","rootDepth":3}]}}
|
||||
""");
|
||||
IrisData data = IrisData.openRuntime(pack);
|
||||
try {
|
||||
ExportIr ir = compile(data, DataVersion.V26_3, true);
|
||||
|
||||
String placedId = features(ir, "plains").get(GenerationStep.VEGETAL_DECORATION.ordinal()).getAsJsonArray().get(0).getAsString();
|
||||
JsonObject placed = json(ir, "data/iris_export/worldgen/placed_feature/" + placedId.substring(NAMESPACE.length() + 1) + ".json");
|
||||
String featureId = placed.get("feature").getAsString();
|
||||
JsonObject feature = json(ir, "data/iris_export/worldgen/feature/" + featureId.substring(NAMESPACE.length() + 1) + ".json");
|
||||
assertEquals("minecraft:weighted_random_selector", feature.get("type").getAsString());
|
||||
Set<String> pillars = new HashSet<>();
|
||||
for (JsonElement branch : feature.getAsJsonArray("features")) {
|
||||
JsonObject entry = branch.getAsJsonObject().getAsJsonObject("data");
|
||||
JsonArray parts = entry.getAsJsonObject("feature").getAsJsonArray("features");
|
||||
for (int index = 1; index < parts.size(); index++) {
|
||||
pillars.add(parts.get(index).getAsJsonObject().get("feature").getAsString());
|
||||
}
|
||||
}
|
||||
assertFalse(pillars.isEmpty());
|
||||
for (String pillar : pillars) {
|
||||
assertTrue(pillar, paths(ir).contains("data/iris_export/worldgen/feature/" + pillar.substring(NAMESPACE.length() + 1) + ".json"));
|
||||
}
|
||||
} finally {
|
||||
data.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void proceduralObjectsSharedByBiomesShareTemplates() throws Exception {
|
||||
String procedural = """
|
||||
"proceduralObjects":{"trees":[{"name":"field-oak","chance":0.5,"density":2,"variants":2,"seed":7,
|
||||
"trunk":"minecraft:oak_log","leaves":"minecraft:oak_leaves","heightMin":5,"heightMax":7}]}""";
|
||||
File pack = pack();
|
||||
CompatTestPlatform.write(pack, "biomes/plains.json", "{\"name\":\"Plains\"," + procedural + "}");
|
||||
CompatTestPlatform.write(pack, "biomes/forest.json", "{\"name\":\"Forest\"," + procedural + "}");
|
||||
IrisData data = IrisData.openRuntime(pack);
|
||||
try {
|
||||
ExportIr ir = compile(data, DataVersion.V26_3, true);
|
||||
|
||||
Set<String> objects = new HashSet<>();
|
||||
for (BinaryResource template : ir.binaryResources()) {
|
||||
if (template.path().contains("field-oak")) {
|
||||
objects.add(template.path().substring(0, template.path().lastIndexOf('/')));
|
||||
}
|
||||
}
|
||||
assertEquals(objects.toString(), 2, objects.size());
|
||||
assertEquals(1, features(ir, "forest").get(GenerationStep.VEGETAL_DECORATION.ordinal()).getAsJsonArray().size());
|
||||
assertEquals(1, features(ir, "plains").get(GenerationStep.VEGETAL_DECORATION.ordinal()).getAsJsonArray().size());
|
||||
} finally {
|
||||
data.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lootBoundPerBiome() throws Exception {
|
||||
File pack = pack();
|
||||
|
||||
+101
-10
@@ -38,8 +38,8 @@ public class ObjectVariantBakerTest {
|
||||
.build();
|
||||
String id = ObjectVariantBaker.templateId(NAMESPACE, "trees/oak", spec, DataVersion.V26_3);
|
||||
|
||||
BakedVariant first = new ObjectVariantBaker().bake(id, tree, spec, "trees/oak", new ArrayList<>());
|
||||
BakedVariant second = new ObjectVariantBaker().bake(id, tree, spec, "trees/oak", new ArrayList<>());
|
||||
BakedVariant first = new ObjectVariantBaker().bake(id, new ObjectSource(tree, 0, TreeRoots.NONE), spec);
|
||||
BakedVariant second = new ObjectVariantBaker().bake(id, new ObjectSource(tree, 0, TreeRoots.NONE), spec);
|
||||
|
||||
assertEquals(first, second);
|
||||
assertEquals(id, ObjectVariantBaker.templateId(NAMESPACE, "trees/oak", spec, DataVersion.V26_3));
|
||||
@@ -58,7 +58,7 @@ public class ObjectVariantBakerTest {
|
||||
block(0, 1, 0, "minecraft:cave_air")));
|
||||
|
||||
BakedVariant variant = new ObjectVariantBaker()
|
||||
.bake("iris_export:object/rock/a", volume, VariantSpec.builder().build(), "rock", new ArrayList<>());
|
||||
.bake("iris_export:object/rock/a", new ObjectSource(volume, 0, TreeRoots.NONE), VariantSpec.builder().build());
|
||||
|
||||
assertEquals(List.of("minecraft:stone"), states(variant.volume()));
|
||||
assertEquals(2, variant.volume().sizeX());
|
||||
@@ -66,6 +66,30 @@ public class ObjectVariantBakerTest {
|
||||
assertEquals(0, variant.baseY());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void plantsWithNothingUnderThemAreLeftOut() {
|
||||
TemplateVolume reef = new TemplateVolume(3, 4, 3, List.of(
|
||||
block(1, 0, 1, "minecraft:sea_pickle[pickles=1,waterlogged=false]"),
|
||||
block(0, 0, 0, "minecraft:tube_coral_block"),
|
||||
block(0, 1, 0, "minecraft:tube_coral_block"),
|
||||
block(0, 2, 0, "minecraft:sea_pickle[pickles=2,waterlogged=false]"),
|
||||
block(2, 2, 2, "minecraft:sea_pickle[pickles=3,waterlogged=false]"),
|
||||
block(2, 1, 0, "minecraft:tube_coral_fan[waterlogged=false]"),
|
||||
block(1, 1, 0, "minecraft:tube_coral_wall_fan[facing=east,waterlogged=false]"),
|
||||
block(1, 2, 0, "minecraft:tube_coral_wall_fan[facing=west,waterlogged=false]"),
|
||||
block(2, 3, 2, "minecraft:tube_coral_block")));
|
||||
|
||||
BakedVariant variant = new ObjectVariantBaker()
|
||||
.bake("iris_export:object/reef/a", new ObjectSource(reef, 0, TreeRoots.NONE), VariantSpec.builder().build());
|
||||
|
||||
Set<String> kept = new HashSet<>();
|
||||
for (TemplateBlock block : variant.volume().blocks()) {
|
||||
kept.add(block.x() + "," + block.y() + "," + block.z() + " " + block.state().name());
|
||||
}
|
||||
assertEquals(Set.of("1,0,1 minecraft:sea_pickle", "0,0,0 minecraft:tube_coral_block", "0,1,0 minecraft:tube_coral_block",
|
||||
"0,2,0 minecraft:sea_pickle", "1,1,0 minecraft:tube_coral_wall_fan", "2,3,2 minecraft:tube_coral_block"), kept);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void quarterRotationMovesBlocksAndFacing() {
|
||||
TemplateVolume volume = new TemplateVolume(3, 1, 3, List.of(
|
||||
@@ -73,7 +97,7 @@ public class ObjectVariantBakerTest {
|
||||
block(1, 0, 0, "minecraft:oak_stairs[facing=north,half=bottom,shape=straight,waterlogged=false]")));
|
||||
VariantSpec spec = VariantSpec.builder().rotation(new VariantSpec.Rotation(0, 90, 0)).build();
|
||||
|
||||
BakedVariant variant = new ObjectVariantBaker().bake("iris_export:object/s/a", volume, spec, "s", new ArrayList<>());
|
||||
BakedVariant variant = new ObjectVariantBaker().bake("iris_export:object/s/a", new ObjectSource(volume, 0, TreeRoots.NONE), spec);
|
||||
|
||||
TemplateBlock stairs = variant.volume().blocks().stream()
|
||||
.filter(block -> block.state().name().equals("minecraft:oak_stairs")).findFirst().orElseThrow();
|
||||
@@ -89,7 +113,7 @@ public class ObjectVariantBakerTest {
|
||||
block(0, 1, 0, "minecraft:oak_slab[type=bottom,waterlogged=false]")));
|
||||
VariantSpec spec = VariantSpec.builder().rotation(new VariantSpec.Rotation(180, 0, 0)).build();
|
||||
|
||||
BakedVariant variant = new ObjectVariantBaker().bake("iris_export:object/f/a", volume, spec, "f", new ArrayList<>());
|
||||
BakedVariant variant = new ObjectVariantBaker().bake("iris_export:object/f/a", new ObjectSource(volume, 0, TreeRoots.NONE), spec);
|
||||
|
||||
TemplateBlock slab = variant.volume().blocks().getFirst();
|
||||
assertEquals("minecraft:oak_slab", slab.state().name());
|
||||
@@ -104,7 +128,7 @@ public class ObjectVariantBakerTest {
|
||||
block(1, 1, 1, "minecraft:oak_log[axis=y]")));
|
||||
VariantSpec scaled = VariantSpec.builder().scale(2).build();
|
||||
|
||||
BakedVariant big = new ObjectVariantBaker().bake("iris_export:object/l/a", volume, scaled, "l", new ArrayList<>());
|
||||
BakedVariant big = new ObjectVariantBaker().bake("iris_export:object/l/a", new ObjectSource(volume, 0, TreeRoots.NONE), scaled);
|
||||
|
||||
assertEquals(16, big.volume().blocks().size());
|
||||
assertEquals(4, big.volume().sizeY());
|
||||
@@ -124,8 +148,8 @@ public class ObjectVariantBakerTest {
|
||||
ObjectEdit half = new ObjectEdit(List.of(VanillaBlockState.parse("minecraft:stone_bricks")), false,
|
||||
List.of(new WeightedState(VanillaBlockState.parse("minecraft:mossy_stone_bricks"), 1)), 0.5);
|
||||
|
||||
BakedVariant variant = new ObjectVariantBaker().bake("iris_export:object/floor/a", floor,
|
||||
VariantSpec.builder().edits(List.of(always, half)).build(), "floor", new ArrayList<>());
|
||||
BakedVariant variant = new ObjectVariantBaker().bake("iris_export:object/floor/a", new ObjectSource(floor, 0, TreeRoots.NONE),
|
||||
VariantSpec.builder().edits(List.of(always, half)).build());
|
||||
|
||||
Set<String> names = new HashSet<>();
|
||||
int mossy = 0;
|
||||
@@ -141,8 +165,8 @@ public class ObjectVariantBakerTest {
|
||||
|
||||
@Test
|
||||
public void basesAlignAcrossVariants() {
|
||||
BakedVariant low = new BakedVariant("iris_export:object/a/low", new TemplateVolume(1, 3, 1, List.of(block(0, 0, 0, "minecraft:stone"))), -2);
|
||||
BakedVariant flat = new BakedVariant("iris_export:object/a/flat", new TemplateVolume(1, 1, 1, List.of(block(0, 0, 0, "minecraft:stone"))), 0);
|
||||
BakedVariant low = new BakedVariant("iris_export:object/a/low", new TemplateVolume(1, 3, 1, List.of(block(0, 0, 0, "minecraft:stone"))), -2, TreeRoots.NONE);
|
||||
BakedVariant flat = new BakedVariant("iris_export:object/a/flat", new TemplateVolume(1, 1, 1, List.of(block(0, 0, 0, "minecraft:stone"))), 0, TreeRoots.NONE);
|
||||
|
||||
List<BakedVariant> aligned = ObjectVariantBaker.alignBases(List.of(low, flat));
|
||||
|
||||
@@ -154,6 +178,73 @@ public class ObjectVariantBakerTest {
|
||||
assertFalse(aligned.get(1).volume().blocks().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rootsSurviveAnUnchangedBake() {
|
||||
TemplateVolume volume = new TemplateVolume(3, 2, 3, List.of(
|
||||
block(1, 0, 1, "minecraft:oak_wood[axis=y]"),
|
||||
block(2, 0, 1, "minecraft:oak_wood[axis=y]"),
|
||||
block(1, 1, 1, "minecraft:oak_log[axis=y]")));
|
||||
TreeRoots roots = new TreeRoots(List.of(block(1, 0, 1, "minecraft:oak_wood[axis=y]"),
|
||||
block(2, 0, 1, "minecraft:oak_wood[axis=y]")), 3);
|
||||
|
||||
BakedVariant variant = new ObjectVariantBaker()
|
||||
.bake("iris_export:object/tree/a", new ObjectSource(volume, 0, roots), VariantSpec.builder().build());
|
||||
|
||||
assertEquals(roots, variant.roots());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rootsTurnWithTheirBlocks() {
|
||||
TemplateVolume volume = new TemplateVolume(3, 2, 3, List.of(
|
||||
block(1, 0, 1, "minecraft:oak_wood[axis=y]"),
|
||||
block(2, 0, 1, "minecraft:spruce_wood[axis=x]"),
|
||||
block(1, 1, 1, "minecraft:oak_log[axis=y]")));
|
||||
TreeRoots roots = new TreeRoots(List.of(block(2, 0, 1, "minecraft:spruce_wood[axis=x]")), 2);
|
||||
VariantSpec spec = VariantSpec.builder().rotation(new VariantSpec.Rotation(0, 90, 0)).build();
|
||||
|
||||
BakedVariant variant = new ObjectVariantBaker().bake("iris_export:object/tree/b", new ObjectSource(volume, 0, roots), spec);
|
||||
|
||||
TemplateBlock moved = variant.volume().blocks().stream()
|
||||
.filter(block -> block.state().name().equals("minecraft:spruce_wood")).findFirst().orElseThrow();
|
||||
assertEquals(1, variant.roots().cells().size());
|
||||
TemplateBlock root = variant.roots().cells().getFirst();
|
||||
assertEquals(List.of(moved.x(), moved.y(), moved.z()), List.of(root.x(), root.y(), root.z()));
|
||||
assertEquals("z", root.state().properties().get("axis"));
|
||||
assertEquals(2, variant.roots().reach());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scaledRootsKeepTheLowestCellPerColumnAndStretchTheirReach() {
|
||||
TemplateVolume volume = new TemplateVolume(2, 2, 1, List.of(
|
||||
block(0, 0, 0, "minecraft:oak_wood[axis=y]"),
|
||||
block(0, 1, 0, "minecraft:oak_log[axis=y]"),
|
||||
block(1, 1, 0, "minecraft:oak_log[axis=y]")));
|
||||
TreeRoots roots = new TreeRoots(List.of(block(0, 0, 0, "minecraft:oak_wood[axis=y]")), 3);
|
||||
|
||||
BakedVariant variant = new ObjectVariantBaker().bake("iris_export:object/tree/c", new ObjectSource(volume, 0, roots),
|
||||
VariantSpec.builder().scale(2).build());
|
||||
|
||||
assertEquals(6, variant.roots().reach());
|
||||
assertEquals(4, variant.roots().cells().size());
|
||||
for (TemplateBlock cell : variant.roots().cells()) {
|
||||
assertEquals(0, cell.y());
|
||||
assertEquals("minecraft:oak_wood", cell.state().name());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void alignedBasesLiftRoots() {
|
||||
TreeRoots roots = new TreeRoots(List.of(block(0, 0, 0, "minecraft:oak_wood[axis=y]")), 2);
|
||||
BakedVariant low = new BakedVariant("iris_export:object/r/low", new TemplateVolume(1, 3, 1, List.of(block(0, 0, 0, "minecraft:stone"))), -2, TreeRoots.NONE);
|
||||
BakedVariant rooted = new BakedVariant("iris_export:object/r/rooted", new TemplateVolume(1, 1, 1,
|
||||
List.of(block(0, 0, 0, "minecraft:oak_wood[axis=y]"))), 0, roots);
|
||||
|
||||
BakedVariant lifted = ObjectVariantBaker.alignBases(List.of(low, rooted)).get(1);
|
||||
|
||||
assertEquals(2, lifted.roots().cells().getFirst().y());
|
||||
assertEquals(2, lifted.roots().reach());
|
||||
}
|
||||
|
||||
private static TemplateVolume tree() {
|
||||
List<TemplateBlock> blocks = new ArrayList<>();
|
||||
for (int y = 0; y < 5; y++) {
|
||||
|
||||
+565
-28
@@ -4,6 +4,7 @@ import art.arcane.iris.pack.datapack.DataVersion;
|
||||
import art.arcane.iris.pack.datapack.export.TemplateBlock;
|
||||
import art.arcane.iris.pack.datapack.export.TemplateVolume;
|
||||
import art.arcane.iris.pack.datapack.export.VanillaBlockState;
|
||||
import art.arcane.iris.pack.datapack.export.compile.StageTestPacks;
|
||||
import art.arcane.iris.pack.datapack.export.compile.decoration.GenerationStep;
|
||||
import art.arcane.iris.pack.datapack.export.ir.DimensionDef;
|
||||
import art.arcane.iris.pack.datapack.export.ir.ExportDiagnostic;
|
||||
@@ -21,9 +22,11 @@ import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
@@ -59,17 +62,244 @@ public class PlacementCompilerTest {
|
||||
assertFalse(templates.get(0).getAsJsonObject().getAsJsonObject("data").has("rotations"));
|
||||
JsonObject placed = placed(compiled);
|
||||
assertEquals(List.of("minecraft:random_chance", "minecraft:count", "minecraft:in_square", "minecraft:heightmap",
|
||||
"minecraft:block_predicate_filter", "minecraft:offset", "minecraft:biome"), types(placed));
|
||||
"minecraft:block_predicate_filter", "minecraft:block_predicate_filter", "minecraft:offset", "minecraft:biome"), types(placed));
|
||||
JsonArray modifiers = placed.getAsJsonArray("placement");
|
||||
assertEquals(0.5, modifiers.get(0).getAsJsonObject().get("chance").getAsDouble(), 1e-6);
|
||||
assertEquals(3, modifiers.get(1).getAsJsonObject().get("count").getAsInt());
|
||||
assertEquals("WORLD_SURFACE_WG", modifiers.get(3).getAsJsonObject().get("heightmap").getAsString());
|
||||
assertEquals(1, modifiers.get(5).getAsJsonObject().get("y").getAsInt());
|
||||
JsonObject support = modifiers.get(4).getAsJsonObject().getAsJsonObject("predicate");
|
||||
assertEquals("minecraft:volume_match", support.get("type").getAsString());
|
||||
assertEquals("OCEAN_FLOOR_WG", modifiers.get(3).getAsJsonObject().get("heightmap").getAsString());
|
||||
assertEquals(1, modifiers.get(6).getAsJsonObject().get("y").getAsInt());
|
||||
assertTrue(StageTestPacks.ofType(placed, "minecraft:volume_match").isEmpty());
|
||||
assertTrue(diagnostics.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void surfaceObjectsStandOnTerrainInsteadOfCanopiesOrWater() {
|
||||
IrisObjectPlacement placement = placement(ObjectPlaceMode.CENTER_HEIGHT, 1, 1);
|
||||
|
||||
JsonObject placed = placed(compiler(DataVersion.V26_3).compile(input(placement, objects(5), List.of()), new ArrayList<>()));
|
||||
JsonObject filter = filters(placed).getFirst();
|
||||
|
||||
assertEquals("OCEAN_FLOOR_WG", StageTestPacks.ofType(placed, "minecraft:heightmap").getFirst().get("heightmap").getAsString());
|
||||
List<String> rejected = new ArrayList<>();
|
||||
for (JsonObject negated : StageTestPacks.ofType(filter, "minecraft:not")) {
|
||||
JsonObject inner = negated.getAsJsonObject("predicate");
|
||||
rejected.add(inner.has("tag") ? inner.get("tag").getAsString() : inner.get("type").getAsString());
|
||||
}
|
||||
assertTrue(rejected.toString(), rejected.contains("minecraft:leaves"));
|
||||
assertTrue(rejected.toString(), rejected.contains("minecraft:logs"));
|
||||
assertTrue(rejected.toString(), rejected.contains("minecraft:matching_fluids"));
|
||||
assertFalse(StageTestPacks.ofType(filter, "minecraft:solid").isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportFollowsTheObjectBaseInsteadOfAFlatPlane() {
|
||||
IrisObjectPlacement placement = placement(ObjectPlaceMode.CENTER_HEIGHT, 1, 1);
|
||||
placement.setSurfaceSupportBuffer(1);
|
||||
placement.setSurfaceSupportDepth(2);
|
||||
TemplateBlock trunk = new TemplateBlock(4, 0, 4, VanillaBlockState.parse("minecraft:oak_log[axis=y]"), null);
|
||||
TemplateBlock crown = new TemplateBlock(0, 5, 0, VanillaBlockState.parse("minecraft:oak_leaves"), null);
|
||||
BakedVariant tree = new BakedVariant(NAMESPACE + ":object/tree/v", new TemplateVolume(9, 6, 9, List.of(trunk, crown)), 0, TreeRoots.NONE);
|
||||
List<ObjectTemplates> objects = List.of(new ObjectTemplates("tree", List.of(new TemplateChoice(tree, List.of(0, 1, 2, 3), 1))));
|
||||
|
||||
JsonObject support = filters(placed(compiler(DataVersion.V26_3).compile(input(placement, objects, List.of()), new ArrayList<>()))).get(1);
|
||||
|
||||
int reach = 0;
|
||||
int depth = 0;
|
||||
for (JsonObject solid : StageTestPacks.ofType(support, "minecraft:solid")) {
|
||||
JsonArray offset = solid.getAsJsonArray("offset");
|
||||
reach = Math.max(reach, Math.max(Math.abs(offset.get(0).getAsInt()), Math.abs(offset.get(2).getAsInt())));
|
||||
depth = Math.min(depth, offset.get(1).getAsInt());
|
||||
}
|
||||
assertEquals(1, reach);
|
||||
assertEquals(-16, depth);
|
||||
assertFalse(StageTestPacks.ofType(support, "minecraft:any_of").isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportAcceptsSteepGroundAnywhereInTheScanWindow() {
|
||||
IrisObjectPlacement placement = placement(ObjectPlaceMode.CENTER_HEIGHT, 1, 1);
|
||||
placement.setSurfaceSupportBuffer(2);
|
||||
placement.setSurfaceSupportDepth(2);
|
||||
TemplateBlock trunk = new TemplateBlock(0, 0, 4, VanillaBlockState.parse("minecraft:spruce_log[axis=y]"), null);
|
||||
BakedVariant tree = new BakedVariant(NAMESPACE + ":object/tree/v", new TemplateVolume(9, 20, 9, List.of(trunk)), 0, TreeRoots.NONE);
|
||||
List<ObjectTemplates> objects = List.of(new ObjectTemplates("tree", List.of(new TemplateChoice(tree, List.of(0, 1, 2, 3), 1))));
|
||||
|
||||
JsonObject support = filters(placed(compiler(DataVersion.V26_3).compile(input(placement, objects, List.of()), new ArrayList<>()))).get(1);
|
||||
|
||||
Set<String> corners = new HashSet<>();
|
||||
for (JsonObject solid : StageTestPacks.ofType(support, "minecraft:solid")) {
|
||||
JsonArray offset = solid.getAsJsonArray("offset");
|
||||
corners.add(offset.get(0).getAsInt() + "," + offset.get(2).getAsInt());
|
||||
}
|
||||
assertEquals(Set.of("-6,-6", "-6,6", "6,-6", "6,6"), corners);
|
||||
Set<String> steepSlope = new HashSet<>();
|
||||
Set<String> thinLedge = new HashSet<>();
|
||||
for (String corner : corners) {
|
||||
for (int y = -12; y >= -40; y--) {
|
||||
steepSlope.add(cell(corner, y));
|
||||
}
|
||||
thinLedge.add(cell(corner, -12));
|
||||
}
|
||||
JsonObject predicate = support.getAsJsonObject("predicate");
|
||||
assertTrue("ground 11 blocks below every corner must support the object", supported(predicate, steepSlope));
|
||||
assertFalse("a one block ledge is thinner than surfaceSupportDepth", supported(predicate, thinLedge));
|
||||
assertFalse("open air below every corner must not support the object", supported(predicate, Set.of()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stiltedObjectsRelyOnTheirStiltsInsteadOfCornerSupport() {
|
||||
IrisObjectPlacement placement = placement(ObjectPlaceMode.FAST_MIN_STILT, 1, 1);
|
||||
PlacementInput input = new PlacementInput(placement, PlacementInput.Anchor.SURFACE, true, objects(25), List.of(),
|
||||
List.of(VanillaBlockState.parse("minecraft:dark_oak_wood[axis=y]")), "willow");
|
||||
|
||||
List<JsonObject> filters = filters(placed(compiler(DataVersion.V26_3).compile(input, new ArrayList<>())));
|
||||
|
||||
assertEquals(1, filters.size());
|
||||
assertFalse(StageTestPacks.ofType(filters.getFirst(), "minecraft:matching_block_tag").isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void slopeConditionRejectsSteepAnchors() {
|
||||
IrisObjectPlacement placement = placement(ObjectPlaceMode.CENTER_HEIGHT, 1, 1);
|
||||
placement.setRequireSurfaceSupport(false);
|
||||
placement.getSlopeCondition().setMaximumSlope(1.5);
|
||||
List<ExportDiagnostic> diagnostics = new ArrayList<>();
|
||||
|
||||
List<JsonObject> filters = filters(placed(compiler(DataVersion.V26_3).compile(input(placement, objects(5), List.of()), diagnostics)));
|
||||
|
||||
assertTrue(diagnostics.stream().anyMatch(diagnostic -> diagnostic.limit() == ExportLimit.SLOPE));
|
||||
assertEquals(2, filters.size());
|
||||
JsonObject slope = filters.get(1).getAsJsonObject("predicate");
|
||||
Set<String> flat = new HashSet<>();
|
||||
Set<String> cliff = new HashSet<>();
|
||||
for (int x = -3; x <= 3; x++) {
|
||||
for (int z = -3; z <= 3; z++) {
|
||||
for (int y = -20; y <= -1; y++) {
|
||||
flat.add(x + "," + y + "," + z);
|
||||
cliff.add(x + "," + y + "," + z);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int y = 0; y <= 4; y++) {
|
||||
cliff.add("3," + y + ",0");
|
||||
}
|
||||
assertTrue("flat ground must pass the slope limit", supported(slope, flat));
|
||||
assertFalse("a wall 3 blocks higher 3 blocks away is steeper than slope 1.5", supported(slope, cliff));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void forcePlaceIgnoresSlopeCondition() {
|
||||
IrisObjectPlacement placement = placement(ObjectPlaceMode.CENTER_HEIGHT, 1, 1);
|
||||
placement.setForcePlace(true);
|
||||
placement.getSlopeCondition().setMinimumSlope(2);
|
||||
|
||||
List<JsonObject> filters = filters(placed(compiler(DataVersion.V26_3).compile(input(placement, objects(5), List.of()), new ArrayList<>())));
|
||||
|
||||
assertEquals(1, filters.size());
|
||||
}
|
||||
|
||||
private static String cell(String corner, int y) {
|
||||
String[] parts = corner.split(",");
|
||||
return parts[0] + "," + y + "," + parts[1];
|
||||
}
|
||||
|
||||
private static boolean supported(JsonObject predicate, Set<String> solids) {
|
||||
String type = predicate.get("type").getAsString();
|
||||
return switch (type) {
|
||||
case "minecraft:solid" -> {
|
||||
JsonArray offset = predicate.getAsJsonArray("offset");
|
||||
yield solids.contains(offset.get(0).getAsInt() + "," + offset.get(1).getAsInt() + "," + offset.get(2).getAsInt());
|
||||
}
|
||||
case "minecraft:all_of" -> {
|
||||
for (JsonElement child : predicate.getAsJsonArray("predicates")) {
|
||||
if (!supported(child.getAsJsonObject(), solids)) {
|
||||
yield false;
|
||||
}
|
||||
}
|
||||
yield true;
|
||||
}
|
||||
case "minecraft:any_of" -> {
|
||||
for (JsonElement child : predicate.getAsJsonArray("predicates")) {
|
||||
if (supported(child.getAsJsonObject(), solids)) {
|
||||
yield true;
|
||||
}
|
||||
}
|
||||
yield false;
|
||||
}
|
||||
case "minecraft:not" -> !supported(predicate.getAsJsonObject("predicate"), solids);
|
||||
default -> throw new AssertionError("Unexpected support predicate " + type);
|
||||
};
|
||||
}
|
||||
|
||||
@Test
|
||||
public void underwaterObjectsNeedWaterAndStayBelowTheSurface() {
|
||||
IrisObjectPlacement placement = placement(ObjectPlaceMode.CENTER_HEIGHT, 1, 1);
|
||||
placement.setUnderwater(true);
|
||||
placement.setTranslate(new IrisObjectTranslate().setY(2));
|
||||
|
||||
JsonObject placed = placed(compiler(DataVersion.V26_3).compile(input(placement, columns(7), List.of()), new ArrayList<>()));
|
||||
|
||||
List<JsonObject> filters = filters(placed);
|
||||
assertEquals(2, filters.size());
|
||||
assertTrue(StageTestPacks.ofType(filters.getFirst(), "minecraft:not").stream()
|
||||
.noneMatch(negated -> !StageTestPacks.ofType(negated, "minecraft:matching_fluids").isEmpty()));
|
||||
JsonObject water = StageTestPacks.ofType(filters.getFirst(), "minecraft:matching_fluids").getFirst();
|
||||
assertFalse(water.toString(), water.has("offset"));
|
||||
assertEquals(DIMENSION.fluidHeight() - 3 * (7 / 2) - 2, ceiling(placed));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void underwaterObjectsOfDifferentHeightsKeepTheirOwnDepth() {
|
||||
IrisObjectPlacement placement = placement(ObjectPlaceMode.CENTER_HEIGHT, 0.6, 2);
|
||||
placement.setUnderwater(true);
|
||||
|
||||
CompiledPlacement compiled = compiler(DataVersion.V26_3).compile(input(placement, columns(4, 9, 4), List.of()), new ArrayList<>());
|
||||
|
||||
assertEquals(2, compiled.placedFeatures().size());
|
||||
List<Integer> ceilings = new ArrayList<>();
|
||||
double perChunk = 0;
|
||||
for (JsonResource resource : compiled.resources()) {
|
||||
if (resource.path().contains("worldgen/placed_feature/")) {
|
||||
JsonObject placed = resource.json().getAsJsonObject();
|
||||
ceilings.add(ceiling(placed));
|
||||
perChunk += expectedPerChunk(placed);
|
||||
}
|
||||
}
|
||||
ceilings.sort(Integer::compareTo);
|
||||
assertEquals(List.of(DIMENSION.fluidHeight() - 3 * (9 / 2), DIMENSION.fluidHeight() - 3 * (4 / 2)), ceilings);
|
||||
assertEquals(0.6 * 2, perChunk, 1e-6);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onwaterObjectsStandOnTheWaterSurface() {
|
||||
IrisObjectPlacement placement = placement(ObjectPlaceMode.CENTER_HEIGHT, 1, 1);
|
||||
placement.setOnwater(true);
|
||||
|
||||
JsonObject placed = placed(compiler(DataVersion.V26_3).compile(input(placement, objects(5), List.of()), new ArrayList<>()));
|
||||
|
||||
assertEquals("WORLD_SURFACE_WG", StageTestPacks.ofType(placed, "minecraft:heightmap").getFirst().get("heightmap").getAsString());
|
||||
List<JsonObject> filters = filters(placed);
|
||||
assertEquals(1, filters.size());
|
||||
assertTrue(StageTestPacks.ofType(filters.getFirst(), "minecraft:solid").isEmpty());
|
||||
JsonObject water = StageTestPacks.ofType(filters.getFirst(), "minecraft:matching_fluids").getFirst();
|
||||
assertEquals("[0,-1,0]", water.get("offset").toString());
|
||||
assertTrue(StageTestPacks.ofType(placed, "minecraft:not").isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onwaterPaintDropsOntoTheWaterSurface() {
|
||||
IrisObjectPlacement placement = placement(ObjectPlaceMode.PAINT, 1, 1);
|
||||
placement.setOnwater(true);
|
||||
placement.setTranslate(new IrisObjectTranslate().setY(1));
|
||||
|
||||
CompiledPlacement compiled = compiler(DataVersion.V26_3).compile(input(placement, objects(1), List.of()), new ArrayList<>());
|
||||
|
||||
JsonObject gravity = feature(compiled, "worldgen/feature/").getAsJsonObject("processors").getAsJsonArray("processors").get(0).getAsJsonObject();
|
||||
assertEquals("WORLD_SURFACE_WG", gravity.get("heightmap").getAsString());
|
||||
assertEquals(0, gravity.get("offset").getAsInt());
|
||||
assertEquals("WORLD_SURFACE_WG", StageTestPacks.ofType(placed(compiled), "minecraft:heightmap").getFirst().get("heightmap").getAsString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wideObjectBecomesSinglePieceStructure() {
|
||||
IrisObjectPlacement placement = placement(ObjectPlaceMode.CENTER_HEIGHT, 0.02, 1);
|
||||
@@ -112,7 +342,8 @@ public class PlacementCompilerTest {
|
||||
@Test
|
||||
public void writeWindowNeverExceeded() {
|
||||
DataVersion target = DataVersion.V26_3;
|
||||
for (ObjectPlaceMode mode : List.of(ObjectPlaceMode.CENTER_HEIGHT, ObjectPlaceMode.STILT, ObjectPlaceMode.PAINT)) {
|
||||
for (ObjectPlaceMode mode : List.of(ObjectPlaceMode.CENTER_HEIGHT, ObjectPlaceMode.STILT, ObjectPlaceMode.PAINT,
|
||||
ObjectPlaceMode.MIN_HEIGHT, ObjectPlaceMode.FAST_MAX_HEIGHT)) {
|
||||
for (int footprint = 1; footprint <= 40; footprint++) {
|
||||
for (int translate : List.of(0, 3, -5, 12)) {
|
||||
IrisObjectPlacement placement = placement(mode, 1, 1);
|
||||
@@ -160,13 +391,13 @@ public class PlacementCompilerTest {
|
||||
assertEquals("minecraft:rule", processors.get(0).getAsJsonObject().get("processor_type").getAsString());
|
||||
JsonObject gravity = processors.get(1).getAsJsonObject();
|
||||
assertEquals("minecraft:gravity", gravity.get("processor_type").getAsString());
|
||||
assertEquals("WORLD_SURFACE_WG", gravity.get("heightmap").getAsString());
|
||||
assertEquals("OCEAN_FLOOR_WG", gravity.get("heightmap").getAsString());
|
||||
assertEquals(-1, gravity.get("offset").getAsInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stiltsUseOverlayPillarsOn26_3() {
|
||||
IrisObjectPlacement placement = placement(ObjectPlaceMode.STILT, 1, 1);
|
||||
IrisObjectPlacement placement = placement(ObjectPlaceMode.CENTER_STILT, 1, 1);
|
||||
PlacementInput input = new PlacementInput(placement, PlacementInput.Anchor.SURFACE, false, objects(20), List.of(),
|
||||
List.of(VanillaBlockState.parse("minecraft:oak_log[axis=y]")), "hut");
|
||||
|
||||
@@ -210,6 +441,254 @@ public class PlacementCompilerTest {
|
||||
assertEquals(first.resources().toString(), second.resources().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void minHeightScansDownUntilTheWholeFootprintHasGround() {
|
||||
IrisObjectPlacement placement = placement(ObjectPlaceMode.MIN_HEIGHT, 1, 1);
|
||||
|
||||
CompiledPlacement compiled = compiler(DataVersion.V26_3).compile(input(placement, objects(9), List.of()), new ArrayList<>());
|
||||
|
||||
JsonObject placed = placed(compiled);
|
||||
assertEquals(List.of("minecraft:in_square", "minecraft:heightmap", "minecraft:block_predicate_filter",
|
||||
"minecraft:block_predicate_filter", "minecraft:biome"), types(placed));
|
||||
JsonObject feature = feature(compiled, "worldgen/feature/");
|
||||
assertEquals("minecraft:weighted_random_selector", feature.get("type").getAsString());
|
||||
JsonArray branches = feature.getAsJsonArray("features");
|
||||
assertEquals(1, branches.size());
|
||||
JsonObject branch = branches.get(0).getAsJsonObject().getAsJsonObject("data");
|
||||
assertEquals("minecraft:template", branch.getAsJsonObject("feature").get("type").getAsString());
|
||||
assertEquals(List.of("minecraft:environment_scan", "minecraft:offset"), types(branch));
|
||||
JsonObject scan = branch.getAsJsonArray("placement").get(0).getAsJsonObject();
|
||||
assertEquals("down", scan.get("direction_of_search").getAsString());
|
||||
assertEquals(32, scan.get("max_steps").getAsInt());
|
||||
assertEquals(List.of("-4,-1,-4..4,-1,4"), boxes(scan));
|
||||
JsonObject match = StageTestPacks.ofType(scan, "minecraft:volume_match").getFirst().getAsJsonObject("match");
|
||||
assertFalse(StageTestPacks.ofType(match, "minecraft:solid").isEmpty());
|
||||
assertFalse(StageTestPacks.ofType(match, "minecraft:matching_fluids").isEmpty());
|
||||
assertEquals(-1, branch.getAsJsonArray("placement").get(1).getAsJsonObject().get("y").getAsInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void maxHeightScansUpUntilEveryColumnIsClear() {
|
||||
IrisObjectPlacement placement = placement(ObjectPlaceMode.MAX_HEIGHT, 1, 1);
|
||||
placement.setUnderwater(true);
|
||||
|
||||
CompiledPlacement compiled = compiler(DataVersion.V26_3).compile(input(placement, objects(9), List.of()), new ArrayList<>());
|
||||
|
||||
JsonObject scan = branchScan(feature(compiled, "worldgen/feature/"), 0);
|
||||
assertEquals("up", scan.get("direction_of_search").getAsString());
|
||||
assertEquals(List.of("-4,0,-4..4,0,4"), boxes(scan));
|
||||
JsonObject match = StageTestPacks.ofType(scan, "minecraft:volume_match").getFirst().getAsJsonObject("match");
|
||||
assertEquals("minecraft:not", match.get("type").getAsString());
|
||||
assertTrue(StageTestPacks.ofType(match, "minecraft:matching_fluids").isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fastHeightModesProbeTheRuntimeSamplePoints() {
|
||||
IrisObjectPlacement placement = placement(ObjectPlaceMode.FAST_MIN_HEIGHT, 1, 1);
|
||||
|
||||
CompiledPlacement compiled = compiler(DataVersion.V26_3).compile(input(placement, objects(9), List.of()), new ArrayList<>());
|
||||
|
||||
JsonObject scan = branchScan(feature(compiled, "worldgen/feature/"), 0);
|
||||
assertEquals(List.of("-4,-1,-4..-4,-1,-4", "-4,-1,1..-4,-1,1", "1,-1,-4..1,-1,-4", "1,-1,1..1,-1,1"), boxes(scan));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void heightScanCoversEveryAllowedQuarter() {
|
||||
TemplateBlock block = new TemplateBlock(0, 0, 0, VanillaBlockState.parse("minecraft:stone"), null);
|
||||
BakedVariant wall = new BakedVariant(NAMESPACE + ":object/wall/v", new TemplateVolume(5, 4, 9, List.of(block)), 0, TreeRoots.NONE);
|
||||
IrisObjectPlacement placement = placement(ObjectPlaceMode.MIN_HEIGHT, 1, 1);
|
||||
|
||||
JsonObject turning = feature(compiler(DataVersion.V26_3).compile(input(placement, List.of(new ObjectTemplates("wall",
|
||||
List.of(new TemplateChoice(wall, List.of(0, 1, 2, 3), 1)))), List.of()), new ArrayList<>()), "worldgen/feature/");
|
||||
JsonObject fixed = feature(compiler(DataVersion.V26_3).compile(input(placement, List.of(new ObjectTemplates("wall",
|
||||
List.of(new TemplateChoice(wall, List.of(0), 1)))), List.of()), new ArrayList<>()), "worldgen/feature/");
|
||||
|
||||
assertEquals(List.of("-2,-1,-4..2,-1,4", "-4,-1,-2..4,-1,2"), boxes(branchScan(turning, 0)));
|
||||
assertEquals(List.of("-2,-1,-4..2,-1,4"), boxes(branchScan(fixed, 0)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void everyTemplateAnchorsOnItsOwnFootprint() {
|
||||
IrisObjectPlacement placement = placement(ObjectPlaceMode.MIN_HEIGHT, 1, 1);
|
||||
|
||||
JsonObject feature = feature(compiler(DataVersion.V26_3).compile(input(placement, objects(5, 9), List.of()), new ArrayList<>()),
|
||||
"worldgen/feature/");
|
||||
|
||||
JsonArray branches = feature.getAsJsonArray("features");
|
||||
assertEquals(2, branches.size());
|
||||
assertEquals(branches.get(0).getAsJsonObject().get("weight"), branches.get(1).getAsJsonObject().get("weight"));
|
||||
assertEquals(List.of("-2,-1,-2..2,-1,2"), boxes(branchScan(feature, 0)));
|
||||
assertEquals(List.of("-4,-1,-4..4,-1,4"), boxes(branchScan(feature, 1)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void maxStiltsAnchorHighThenStilt() {
|
||||
IrisObjectPlacement placement = placement(ObjectPlaceMode.STILT, 1, 1);
|
||||
PlacementInput input = new PlacementInput(placement, PlacementInput.Anchor.SURFACE, false, objects(20), List.of(),
|
||||
List.of(VanillaBlockState.parse("minecraft:oak_log[axis=y]")), "hut");
|
||||
|
||||
JsonObject feature = feature(compiler(DataVersion.V26_3).compile(input, new ArrayList<>()), "worldgen/feature/");
|
||||
|
||||
JsonObject branch = feature.getAsJsonArray("features").get(0).getAsJsonObject().getAsJsonObject("data");
|
||||
assertEquals("up", branchScan(feature, 0).get("direction_of_search").getAsString());
|
||||
JsonObject stilts = branch.getAsJsonObject("feature");
|
||||
assertEquals("minecraft:overlay", stilts.get("type").getAsString());
|
||||
assertEquals(5, stilts.getAsJsonArray("features").size());
|
||||
assertEquals("minecraft:single_block_pillar", stilts.getAsJsonArray("features").get(1).getAsJsonObject()
|
||||
.getAsJsonObject("feature").get("type").getAsString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void groundedTreesExtendRootsToTheTerrain() {
|
||||
IrisObjectPlacement placement = placement(ObjectPlaceMode.CENTER_HEIGHT, 1, 1);
|
||||
|
||||
CompiledPlacement compiled = compiler(DataVersion.V26_3).compile(tree(placement, rootedTree()), new ArrayList<>());
|
||||
|
||||
JsonObject feature = feature(compiled, "worldgen/feature/");
|
||||
assertEquals("minecraft:weighted_random_selector", feature.get("type").getAsString());
|
||||
JsonArray branches = feature.getAsJsonArray("features");
|
||||
assertEquals(4, branches.size());
|
||||
List<String> rotations = new ArrayList<>();
|
||||
List<String> roots = new ArrayList<>();
|
||||
List<String> gaps = new ArrayList<>();
|
||||
String pillar = null;
|
||||
for (JsonElement element : branches) {
|
||||
assertEquals(branches.get(0).getAsJsonObject().get("weight"), element.getAsJsonObject().get("weight"));
|
||||
JsonObject branch = element.getAsJsonObject().getAsJsonObject("data");
|
||||
assertEquals(List.of("minecraft:offset", "minecraft:block_predicate_filter"), types(branch));
|
||||
gaps.addAll(boxes(branch.getAsJsonArray("placement").get(1)));
|
||||
JsonObject overlay = branch.getAsJsonObject("feature");
|
||||
assertEquals("minecraft:overlay", overlay.get("type").getAsString());
|
||||
JsonArray parts = overlay.getAsJsonArray("features");
|
||||
assertEquals(2, parts.size());
|
||||
JsonObject template = parts.get(0).getAsJsonObject().getAsJsonObject("feature");
|
||||
rotations.add(template.getAsJsonArray("templates").get(0).getAsJsonObject().getAsJsonObject("data")
|
||||
.getAsJsonArray("rotations").get(0).getAsString());
|
||||
JsonObject root = parts.get(1).getAsJsonObject();
|
||||
pillar = root.get("feature").getAsString();
|
||||
JsonObject offset = root.getAsJsonArray("placement").get(0).getAsJsonObject();
|
||||
roots.add(offset.get("x").getAsInt() + "," + offset.get("y").getAsInt() + "," + offset.get("z").getAsInt());
|
||||
}
|
||||
assertEquals(List.of("none", "counterclockwise_90", "180", "clockwise_90"), rotations);
|
||||
assertEquals(List.of("1,-1,0", "0,-1,-1", "-1,-1,0", "0,-1,1"), roots);
|
||||
assertEquals(List.of("1,-4,0..1,-1,0", "0,-4,-1..0,-1,-1", "-1,-4,0..-1,-1,0", "0,-4,1..0,-1,1"), gaps);
|
||||
JsonObject shared = resourceAt(compiled, pillar);
|
||||
JsonObject gated = shared.getAsJsonArray("features").get(0).getAsJsonObject();
|
||||
assertEquals("minecraft:block_predicate_filter", gated.getAsJsonArray("placement").get(0).getAsJsonObject().get("type").getAsString());
|
||||
JsonObject column = gated.getAsJsonObject("feature");
|
||||
assertEquals("minecraft:single_block_pillar", column.get("type").getAsString());
|
||||
assertEquals("down", column.get("direction").getAsString());
|
||||
assertEquals("minecraft:spruce_wood", column.getAsJsonObject("block").get("id").getAsString());
|
||||
JsonObject cap = column.getAsJsonObject("cap_feature");
|
||||
assertEquals("minecraft:simple_block", cap.getAsJsonObject("feature").get("type").getAsString());
|
||||
assertEquals(-1, cap.getAsJsonArray("placement").get(0).getAsJsonObject().get("y").getAsInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void groundedRotationBranchesKeepTheTemplateOdds() {
|
||||
BakedVariant turning = rootedTree().getFirst().choices().getFirst().variant();
|
||||
BakedVariant fixed = new BakedVariant(NAMESPACE + ":object/tree/fixed", turning.volume(), 0, turning.roots());
|
||||
List<ObjectTemplates> objects = List.of(new ObjectTemplates("tree", List.of(
|
||||
new TemplateChoice(turning, List.of(0, 1, 2, 3), 1),
|
||||
new TemplateChoice(fixed, List.of(2), 1))));
|
||||
|
||||
JsonObject feature = feature(compiler(DataVersion.V26_3).compile(tree(placement(ObjectPlaceMode.CENTER_HEIGHT, 1, 1), objects),
|
||||
new ArrayList<>()), "worldgen/feature/");
|
||||
|
||||
List<Integer> weights = new ArrayList<>();
|
||||
for (JsonElement branch : feature.getAsJsonArray("features")) {
|
||||
weights.add(branch.getAsJsonObject().get("weight").getAsInt());
|
||||
}
|
||||
assertEquals(List.of(1, 1, 1, 1, 4), weights);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void groundedTreesReplaceStiltsWithRoots() {
|
||||
IrisObjectPlacement placement = placement(ObjectPlaceMode.CENTER_STILT, 1, 1);
|
||||
|
||||
JsonObject feature = feature(compiler(DataVersion.V26_3).compile(tree(placement, rootedTree()), new ArrayList<>()), "worldgen/feature/");
|
||||
|
||||
for (JsonElement element : feature.getAsJsonArray("features")) {
|
||||
JsonObject overlay = element.getAsJsonObject().getAsJsonObject("data").getAsJsonObject("feature");
|
||||
assertTrue(StageTestPacks.ofType(overlay, "minecraft:cuboid").isEmpty());
|
||||
assertEquals(2, overlay.getAsJsonArray("features").size());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void forcedTreesKeepTheirBuiltRoots() {
|
||||
IrisObjectPlacement placement = placement(ObjectPlaceMode.CENTER_HEIGHT, 1, 1);
|
||||
placement.setForcePlace(true);
|
||||
|
||||
JsonObject feature = feature(compiler(DataVersion.V26_3).compile(tree(placement, rootedTree()), new ArrayList<>()), "worldgen/feature/");
|
||||
|
||||
assertEquals("minecraft:template", feature.get("type").getAsString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rootedHeightScansStayInsideTheFeatureWindow() {
|
||||
IrisObjectPlacement placement = placement(ObjectPlaceMode.FAST_MAX_HEIGHT, 1, 1);
|
||||
placement.setTranslate(new IrisObjectTranslate().setX(3).setZ(-3));
|
||||
List<ObjectTemplates> objects = rootedTree();
|
||||
|
||||
CompiledPlacement compiled = compiler(DataVersion.V26_3).compile(tree(placement, objects), new ArrayList<>());
|
||||
|
||||
assertWithinWindow(compiled, objects, "rooted fast max");
|
||||
}
|
||||
|
||||
private static List<ObjectTemplates> rootedTree() {
|
||||
List<TemplateBlock> blocks = new ArrayList<>();
|
||||
for (int y = 1; y < 4; y++) {
|
||||
blocks.add(new TemplateBlock(2, y, 2, VanillaBlockState.parse("minecraft:oak_log[axis=y]"), null));
|
||||
}
|
||||
TemplateBlock root = new TemplateBlock(3, 0, 2, VanillaBlockState.parse("minecraft:spruce_wood[axis=y]"), null);
|
||||
blocks.add(root);
|
||||
BakedVariant variant = new BakedVariant(NAMESPACE + ":object/tree/rooted", new TemplateVolume(5, 4, 5, blocks), 0,
|
||||
new TreeRoots(List.of(root), 3));
|
||||
return List.of(new ObjectTemplates("tree", List.of(new TemplateChoice(variant, List.of(0, 1, 2, 3), 1))));
|
||||
}
|
||||
|
||||
private static PlacementInput tree(IrisObjectPlacement placement, List<ObjectTemplates> objects) {
|
||||
return new PlacementInput(placement, PlacementInput.Anchor.SURFACE, true, objects, List.of(),
|
||||
List.of(VanillaBlockState.parse("minecraft:oak_log[axis=y]")), "tree");
|
||||
}
|
||||
|
||||
private static JsonObject branchScan(JsonObject selector, int index) {
|
||||
JsonObject branch = selector.getAsJsonArray("features").get(index).getAsJsonObject().getAsJsonObject("data");
|
||||
return StageTestPacks.ofType(branch, "minecraft:environment_scan").getFirst();
|
||||
}
|
||||
|
||||
private static List<String> boxes(JsonElement root) {
|
||||
List<String> boxes = new ArrayList<>();
|
||||
for (JsonObject volume : StageTestPacks.ofType(root, "minecraft:volume_match")) {
|
||||
JsonArray min = volume.getAsJsonArray("min");
|
||||
JsonArray max = volume.getAsJsonArray("max");
|
||||
boxes.add(min.get(0).getAsInt() + "," + min.get(1).getAsInt() + "," + min.get(2).getAsInt() + ".."
|
||||
+ max.get(0).getAsInt() + "," + max.get(1).getAsInt() + "," + max.get(2).getAsInt());
|
||||
}
|
||||
return boxes;
|
||||
}
|
||||
|
||||
private static JsonObject resourceAt(CompiledPlacement compiled, String id) {
|
||||
String path = "/worldgen/feature/" + id.substring(NAMESPACE.length() + 1) + ".json";
|
||||
for (JsonResource resource : compiled.resources()) {
|
||||
if (resource.path().endsWith(path)) {
|
||||
return resource.json().getAsJsonObject();
|
||||
}
|
||||
}
|
||||
throw new AssertionError("No resource for " + id);
|
||||
}
|
||||
|
||||
private static List<JsonObject> filters(JsonObject placed) {
|
||||
List<JsonObject> filters = new ArrayList<>();
|
||||
for (JsonElement element : placed.getAsJsonArray("placement")) {
|
||||
if (element.getAsJsonObject().get("type").getAsString().equals("minecraft:block_predicate_filter")) {
|
||||
filters.add(element.getAsJsonObject());
|
||||
}
|
||||
}
|
||||
return filters;
|
||||
}
|
||||
|
||||
private static void assertWithinWindow(CompiledPlacement compiled, List<ObjectTemplates> objects, String label) {
|
||||
Map<String, Integer> footprints = new HashMap<>();
|
||||
for (ObjectTemplates object : objects) {
|
||||
@@ -217,10 +696,23 @@ public class PlacementCompilerTest {
|
||||
footprints.put(choice.variant().id(), choice.variant().volume().footprint());
|
||||
}
|
||||
}
|
||||
JsonObject placed = placed(compiled);
|
||||
int offsetX = 0;
|
||||
int offsetZ = 0;
|
||||
for (JsonElement element : placed.getAsJsonArray("placement")) {
|
||||
int[] offset = probeWindow(placed(compiled).getAsJsonArray("placement"), 0, 0, label);
|
||||
JsonObject feature = feature(compiled, null);
|
||||
if (!feature.get("type").getAsString().equals("minecraft:weighted_random_selector")) {
|
||||
assertFeatureWithinWindow(feature, footprints, offset[0], offset[1], label);
|
||||
return;
|
||||
}
|
||||
for (JsonElement entry : feature.getAsJsonArray("features")) {
|
||||
JsonObject branch = entry.getAsJsonObject().getAsJsonObject("data");
|
||||
int[] branchOffset = probeWindow(branch.getAsJsonArray("placement"), offset[0], offset[1], label);
|
||||
assertFeatureWithinWindow(branch.getAsJsonObject("feature"), footprints, branchOffset[0], branchOffset[1], label);
|
||||
}
|
||||
}
|
||||
|
||||
private static int[] probeWindow(JsonArray modifiers, int startX, int startZ, String label) {
|
||||
int offsetX = startX;
|
||||
int offsetZ = startZ;
|
||||
for (JsonElement element : modifiers) {
|
||||
JsonObject modifier = element.getAsJsonObject();
|
||||
String type = modifier.get("type").getAsString();
|
||||
if (type.equals("minecraft:offset")) {
|
||||
@@ -229,15 +721,26 @@ public class PlacementCompilerTest {
|
||||
} else if (type.equals("minecraft:random_offset")) {
|
||||
offsetX += modifier.get("xz_spread").getAsInt();
|
||||
offsetZ += modifier.get("xz_spread").getAsInt();
|
||||
} else if (type.equals("minecraft:block_predicate_filter")) {
|
||||
JsonObject predicate = modifier.getAsJsonObject("predicate");
|
||||
if (predicate.get("type").getAsString().equals("minecraft:volume_match")) {
|
||||
assertRange(label + " support", predicate.getAsJsonArray("min").get(0).getAsInt() + offsetX,
|
||||
predicate.getAsJsonArray("max").get(0).getAsInt() + offsetX);
|
||||
} else if (type.equals("minecraft:block_predicate_filter") || type.equals("minecraft:environment_scan")) {
|
||||
for (JsonObject probe : StageTestPacks.find(modifier, object -> object.has("offset") || object.has("min"))) {
|
||||
for (String key : List.of("offset", "min", "max")) {
|
||||
if (!probe.has(key)) {
|
||||
continue;
|
||||
}
|
||||
JsonArray vector = probe.getAsJsonArray(key);
|
||||
for (int axis = 0; axis < 3; axis++) {
|
||||
assertTrue(label + " predicate " + key + " " + vector, Math.abs(vector.get(axis).getAsInt()) <= 16);
|
||||
}
|
||||
assertRange(label + " probe x", vector.get(0).getAsInt() + offsetX, vector.get(0).getAsInt() + offsetX);
|
||||
assertRange(label + " probe z", vector.get(2).getAsInt() + offsetZ, vector.get(2).getAsInt() + offsetZ);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
JsonObject feature = feature(compiled, null);
|
||||
return new int[]{offsetX, offsetZ};
|
||||
}
|
||||
|
||||
private static void assertFeatureWithinWindow(JsonObject feature, Map<String, Integer> footprints, int offsetX, int offsetZ, String label) {
|
||||
String type = feature.get("type").getAsString();
|
||||
JsonObject body = feature.has("config") ? feature.getAsJsonObject("config") : feature;
|
||||
if (type.equals("minecraft:fossil")) {
|
||||
@@ -255,16 +758,27 @@ public class PlacementCompilerTest {
|
||||
assertNotNull(label, footprint);
|
||||
assertTemplate(label, footprint, offsetX, offsetZ);
|
||||
}
|
||||
if (type.equals("minecraft:overlay")) {
|
||||
JsonArray features = body.getAsJsonArray("features");
|
||||
for (int index = 1; index < features.size(); index++) {
|
||||
JsonArray tile = features.get(index).getAsJsonObject().getAsJsonArray("placement");
|
||||
int tileX = tile.get(0).getAsJsonObject().get("x").getAsInt() + offsetX;
|
||||
int tileZ = tile.get(0).getAsJsonObject().get("z").getAsInt() + offsetZ;
|
||||
int size = tile.get(1).getAsJsonObject().get("xz_size").getAsInt();
|
||||
assertRange(label + " stilt tile x", tileX, tileX + size);
|
||||
assertRange(label + " stilt tile z", tileZ, tileZ + size);
|
||||
if (!type.equals("minecraft:overlay")) {
|
||||
return;
|
||||
}
|
||||
JsonArray features = body.getAsJsonArray("features");
|
||||
for (int index = 1; index < features.size(); index++) {
|
||||
JsonArray part = features.get(index).getAsJsonObject().getAsJsonArray("placement");
|
||||
int partX = offsetX;
|
||||
int partZ = offsetZ;
|
||||
int size = 0;
|
||||
for (JsonElement element : part) {
|
||||
JsonObject modifier = element.getAsJsonObject();
|
||||
String modifierType = modifier.get("type").getAsString();
|
||||
if (modifierType.equals("minecraft:offset")) {
|
||||
partX += modifier.get("x").getAsInt();
|
||||
partZ += modifier.get("z").getAsInt();
|
||||
} else if (modifierType.equals("minecraft:cuboid")) {
|
||||
size = modifier.get("xz_size").getAsInt();
|
||||
}
|
||||
}
|
||||
assertRange(label + " part x", partX, partX + size);
|
||||
assertRange(label + " part z", partZ, partZ + size);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -378,12 +892,35 @@ public class PlacementCompilerTest {
|
||||
int footprint = footprints[index];
|
||||
TemplateBlock block = new TemplateBlock(0, 0, 0, VanillaBlockState.parse("minecraft:stone"), null);
|
||||
BakedVariant variant = new BakedVariant(NAMESPACE + ":object/o" + index + "/v" + footprint,
|
||||
new TemplateVolume(footprint, 4, footprint, List.of(block)), 0);
|
||||
new TemplateVolume(footprint, 4, footprint, List.of(block)), 0, TreeRoots.NONE);
|
||||
objects.add(new ObjectTemplates("o" + index, List.of(new TemplateChoice(variant, List.of(0, 1, 2, 3), 1))));
|
||||
}
|
||||
return objects;
|
||||
}
|
||||
|
||||
private static List<ObjectTemplates> columns(int... heights) {
|
||||
List<ObjectTemplates> objects = new ArrayList<>();
|
||||
for (int index = 0; index < heights.length; index++) {
|
||||
List<TemplateBlock> blocks = new ArrayList<>();
|
||||
for (int y = 1; y <= heights[index]; y++) {
|
||||
blocks.add(new TemplateBlock(1, y, 1, VanillaBlockState.parse("minecraft:tube_coral_block"), null));
|
||||
}
|
||||
BakedVariant variant = new BakedVariant(NAMESPACE + ":object/c" + index + "/h" + heights[index],
|
||||
new TemplateVolume(3, heights[index] + 1, 3, blocks), 0, TreeRoots.NONE);
|
||||
objects.add(new ObjectTemplates("c" + index, List.of(new TemplateChoice(variant, List.of(0, 1, 2, 3), 1))));
|
||||
}
|
||||
return objects;
|
||||
}
|
||||
|
||||
private static int ceiling(JsonObject placed) {
|
||||
List<JsonObject> ranges = new ArrayList<>();
|
||||
for (JsonObject filter : filters(placed)) {
|
||||
ranges.addAll(StageTestPacks.ofType(filter, "minecraft:height_range"));
|
||||
}
|
||||
assertEquals(placed.toString(), 1, ranges.size());
|
||||
return ranges.getFirst().getAsJsonObject("max_inclusive").get("absolute").getAsInt();
|
||||
}
|
||||
|
||||
private static JsonObject rule() {
|
||||
JsonObject rule = new JsonObject();
|
||||
rule.addProperty("processor_type", "minecraft:rule");
|
||||
|
||||
@@ -70,6 +70,12 @@ public class Format26_3WriterTest {
|
||||
assertTrue(pack.get("description").getAsString().length() > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void packDescriptionTellsPlayersToKeepTheVanillaPack() {
|
||||
String description = json(write(fixture(WorldgenExportMode.OVERWORLD)), "pack.mcmeta").getAsJsonObject("pack").get("description").getAsString();
|
||||
assertTrue(description, description.contains("Keep Default selected"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noiseFileUsesNormalNoiseParameters() {
|
||||
JsonObject noise = json(write(fixture(WorldgenExportMode.PRESET)), "data/iris_export/worldgen/noise/flat/height.json");
|
||||
|
||||
Reference in new issue
Block a user