diff --git a/adapters/modded-common/src/main/java/art/arcane/iris/modded/ModdedDecoratorHooks.java b/adapters/modded-common/src/main/java/art/arcane/iris/modded/ModdedDecoratorHooks.java deleted file mode 100644 index 5a46711ab..000000000 --- a/adapters/modded-common/src/main/java/art/arcane/iris/modded/ModdedDecoratorHooks.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Iris is a World Generator for Minecraft Servers - * Copyright (c) 2026 Arcane Arts (Volmit Software) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package art.arcane.iris.modded; - -import art.arcane.iris.engine.decorator.DecoratorPlatformHooks; -import art.arcane.iris.engine.mantle.EngineMantle; -import art.arcane.iris.spi.PlatformBlockState; -import art.arcane.iris.util.project.hunk.Hunk; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.world.level.EmptyBlockGetter; -import net.minecraft.world.level.block.SupportType; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.state.properties.BooleanProperty; -import net.minecraft.world.level.block.state.properties.Property; - -import java.util.LinkedHashMap; -import java.util.Map; - -public final class ModdedDecoratorHooks implements DecoratorPlatformHooks.FaceFixer, DecoratorPlatformHooks.SurfaceSturdiness { - private static final Direction[] CARTESIAN = {Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST, Direction.UP, Direction.DOWN}; - private static final String[] FACE_NAMES = {"north", "east", "south", "west", "up", "down"}; - - @Override - public PlatformBlockState fixFaces(PlatformBlockState state, Hunk hunk, int rX, int rZ, int x, int y, int z, EngineMantle mantle) { - ModdedBlockState fabric = (ModdedBlockState) state; - BlockState cloned = fabric.handle(); - Map allowed = faceProperties(cloned); - - for (Map.Entry entry : allowed.entrySet()) { - if (cloned.getValue(entry.getValue())) { - cloned = cloned.setValue(entry.getValue(), Boolean.FALSE); - } - } - - boolean found = false; - for (Direction f : CARTESIAN) { - int yy = y + f.getStepY(); - - PlatformBlockState rs = null; - if (mantle != null) { - rs = mantle.getMantle().get(x + f.getStepX(), yy, z + f.getStepZ(), PlatformBlockState.class); - } - BlockState r = rs == null ? (BlockState) EngineMantle.AIR.nativeHandle() : (BlockState) rs.nativeHandle(); - if (isFaceSturdy(r, f.getOpposite())) { - BooleanProperty property = allowed.get(f.getSerializedName()); - if (property != null) { - found = true; - cloned = cloned.setValue(property, Boolean.TRUE); - } - continue; - } - - int xx = rX + f.getStepX(); - int zz = rZ + f.getStepZ(); - if (xx < 0 || xx > 15 || zz < 0 || zz > 15 || yy < 0 || yy > hunk.getHeight()) { - continue; - } - - r = (BlockState) hunk.get(xx, yy, zz).nativeHandle(); - if (isFaceSturdy(r, f.getOpposite())) { - BooleanProperty property = allowed.get(f.getSerializedName()); - if (property != null) { - found = true; - cloned = cloned.setValue(property, Boolean.TRUE); - } - } - } - - if (!found) { - String fallback = allowed.containsKey("down") ? "down" : "up"; - BooleanProperty property = allowed.get(fallback); - if (property != null) { - cloned = cloned.setValue(property, Boolean.TRUE); - } - } - - return fabric.withHandle(cloned, fabric.parsedProperties()); - } - - @Override - public boolean canGoOn(PlatformBlockState surface) { - return isFaceSturdy((BlockState) surface.nativeHandle(), Direction.UP); - } - - private static boolean isFaceSturdy(BlockState state, Direction face) { - return state.isFaceSturdy(EmptyBlockGetter.INSTANCE, BlockPos.ZERO, face, SupportType.FULL); - } - - private static Map faceProperties(BlockState state) { - Map properties = new LinkedHashMap<>(); - for (String name : FACE_NAMES) { - for (Property property : state.getProperties()) { - if (property.getName().equals(name) && property instanceof BooleanProperty bool) { - properties.put(name, bool); - } - } - } - return properties; - } -} diff --git a/adapters/modded-common/src/main/java/art/arcane/iris/modded/ModdedEngineBootstrap.java b/adapters/modded-common/src/main/java/art/arcane/iris/modded/ModdedEngineBootstrap.java index 50540e54d..88d2ba709 100644 --- a/adapters/modded-common/src/main/java/art/arcane/iris/modded/ModdedEngineBootstrap.java +++ b/adapters/modded-common/src/main/java/art/arcane/iris/modded/ModdedEngineBootstrap.java @@ -21,7 +21,6 @@ package art.arcane.iris.modded; import art.arcane.iris.core.gui.GuiHost; import art.arcane.iris.core.localization.IrisLanguage; import art.arcane.iris.engine.data.cache.AtomicCacheFailureReporting; -import art.arcane.iris.engine.decorator.DecoratorPlatformHooks; import art.arcane.iris.engine.framework.Engine; import art.arcane.iris.engine.framework.EngineEffectsProvider; import art.arcane.iris.engine.framework.EnginePlatformHooks; @@ -372,10 +371,6 @@ public final class ModdedEngineBootstrap { ModdedGuiHost.install(); rollback.add(() -> GuiHost.set(previousGuiHost)); - ModdedDecoratorHooks decoratorHooks = new ModdedDecoratorHooks(); - DecoratorPlatformHooks.Bindings previousDecoratorBindings = DecoratorPlatformHooks.bind(decoratorHooks, decoratorHooks); - rollback.add(() -> DecoratorPlatformHooks.restore(previousDecoratorBindings)); - ModdedPreservationService preservation = createdServices.register( ModdedPreservationService.class, new ModdedPreservationService()); createdServices.register(ModdedLogFilterService.class, new ModdedLogFilterService()); diff --git a/adapters/modded-common/src/test/java/art/arcane/iris/modded/ModdedLifecycleFailureContractTest.java b/adapters/modded-common/src/test/java/art/arcane/iris/modded/ModdedLifecycleFailureContractTest.java index e60140732..5739a7b97 100644 --- a/adapters/modded-common/src/test/java/art/arcane/iris/modded/ModdedLifecycleFailureContractTest.java +++ b/adapters/modded-common/src/test/java/art/arcane/iris/modded/ModdedLifecycleFailureContractTest.java @@ -243,7 +243,6 @@ public class ModdedLifecycleFailureContractTest { assertTrue(bind.contains("rollback.add(() -> TileData.restorePlatformReader(")); assertTrue(bind.contains("rollback.add(() -> TileData.restorePlatformFactory(")); assertTrue(bind.contains("rollback.add(() -> GuiHost.set(")); - assertTrue(bind.contains("rollback.add(() -> DecoratorPlatformHooks.restore(")); assertTrue(bind.contains("bindService(PreservationRegistry.class")); assertTrue(bind.contains("bindService(EngineEffectsProvider.class")); assertTrue(bind.contains("bindService(EnginePlatformHooks.class")); diff --git a/core/src/main/java/art/arcane/iris/core/modules/IrisGenerationContext.java b/core/src/main/java/art/arcane/iris/core/modules/IrisGenerationContext.java index 19ed2457f..4d0668bff 100644 --- a/core/src/main/java/art/arcane/iris/core/modules/IrisGenerationContext.java +++ b/core/src/main/java/art/arcane/iris/core/modules/IrisGenerationContext.java @@ -40,6 +40,8 @@ import java.util.Collection; final class IrisGenerationContext implements GenerationContext { /** Chunk stages write only their own chunk, but see the terrain this far around it (IrisApi's promise). */ private static final int TERRAIN_MARGIN_BLOCKS = 16; + /** The mantle too reaches this far around the chunk; chunks beyond its own are pinned when a stage first reads them. */ + private static final int MANTLE_MARGIN_BLOCKS = 16; private static final int CHUNK_WIDTH = 16; private final Engine engine; @@ -61,7 +63,8 @@ final class IrisGenerationContext implements GenerationContext { this.blocks = new BlockStateHunk(blocks, states); this.terrain = new IrisTerrainSampler(engine, ids, originX, originZ, TERRAIN_MARGIN_BLOCKS, states); this.settings = new ChunkModuleSettings(engine, ids); - BlockBox chunk = ApiHeights.columns(engine, originX, originZ, originX + CHUNK_WIDTH, originZ + CHUNK_WIDTH); + BlockBox chunk = ApiHeights.columns(engine, originX - MANTLE_MARGIN_BLOCKS, originZ - MANTLE_MARGIN_BLOCKS, + originX + CHUNK_WIDTH + MANTLE_MARGIN_BLOCKS, originZ + CHUNK_WIDTH + MANTLE_MARGIN_BLOCKS); this.mantle = new IrisModuleMantle(chunk, mantleChunks, mantleLayers, PlannedBlocks.of(engine, chunk, mantleChunks, states)); } diff --git a/core/src/main/java/art/arcane/iris/core/modules/IrisModuleHost.java b/core/src/main/java/art/arcane/iris/core/modules/IrisModuleHost.java index add1322a2..68e9bb8cd 100644 --- a/core/src/main/java/art/arcane/iris/core/modules/IrisModuleHost.java +++ b/core/src/main/java/art/arcane/iris/core/modules/IrisModuleHost.java @@ -19,7 +19,6 @@ package art.arcane.iris.core.modules; import art.arcane.iris.core.loader.IrisData; -import art.arcane.iris.engine.actuator.DecorantModule; import art.arcane.iris.engine.actuator.TerrainModule; import art.arcane.iris.engine.loot.LootModule; import art.arcane.iris.engine.mantle.components.ObjectModule; @@ -62,7 +61,7 @@ public final class IrisModuleHost { * {@code IrisModule/builtin-modules.txt}) instead of being compiled into Iris. A pack loads them from its {@code modules} * folder, and {@link MissingBuiltInModules} warns when it loads none; a test keeps this equal to the jar's list. */ - public static final List JAR_MODULE_IDS = List.of("iris:post", "iris:perfection", "iris:matter", "iris:deposit"); + public static final List JAR_MODULE_IDS = List.of("iris:post", "iris:perfection", "iris:matter", "iris:deposit", "iris:decorant"); /** Iris's pack object model: built-in settings may hold these classes, which Iris reads and describes itself. */ public static final String HOST_TYPE_PACKAGE = "art.arcane.iris.engine.object"; private static final String[] JAR_COPY_FOLDER = {"cache", "module-jars"}; @@ -87,7 +86,7 @@ public final class IrisModuleHost { private static List generationModules() { return List.of(new TerrainModule(), new CarveModule(), new ObjectModule(), new StructureModule(), - new FloatingModule(), new DecorantModule(), new LootModule(), new SpawnModule()); + new FloatingModule(), new LootModule(), new SpawnModule()); } /** Iris's own log, labelled {@code [iris]}, for host code that calls module classes outside any module's stage, service or hook. */ diff --git a/core/src/main/java/art/arcane/iris/core/modules/ModuleChunkGeneration.java b/core/src/main/java/art/arcane/iris/core/modules/ModuleChunkGeneration.java index 8d6f55e0e..6d620e9e0 100644 --- a/core/src/main/java/art/arcane/iris/core/modules/ModuleChunkGeneration.java +++ b/core/src/main/java/art/arcane/iris/core/modules/ModuleChunkGeneration.java @@ -60,7 +60,7 @@ public final class ModuleChunkGeneration { int chunkX = x >> CHUNK_SHIFT; int chunkZ = z >> CHUNK_SHIFT; long seed = ModuleSeeds.chunk(engine.getSeedManager().getSeed(), chunkX, chunkZ); - try (PinnedMantleChunk mantle = new PinnedMantleChunk(engine, chunkX, chunkZ)) { + try (PinnedMantleChunks mantle = new PinnedMantleChunks(engine)) { IrisGenerationContext inputs = new IrisGenerationContext(engine, x, z, blocks, new PlatformBlockStates(platformStates), mantle, pack.catalog().mantle()); StageMetrics metrics = new StageMetrics(engine.getMetrics()); diff --git a/core/src/main/java/art/arcane/iris/core/modules/PackResourceIds.java b/core/src/main/java/art/arcane/iris/core/modules/PackResourceIds.java index 2b1263fd9..5d332493d 100644 --- a/core/src/main/java/art/arcane/iris/core/modules/PackResourceIds.java +++ b/core/src/main/java/art/arcane/iris/core/modules/PackResourceIds.java @@ -22,6 +22,8 @@ import com.volmit.resource.ResourceId; import java.io.File; import java.util.Locale; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import java.util.regex.Pattern; /** @@ -38,6 +40,8 @@ final class PackResourceIds { private static final String PACK_PATH = "pack"; private final String namespace; + /** Stages ask for the id of the same few keys for every column, so each is worked out once. */ + private final Map known = new ConcurrentHashMap<>(); PackResourceIds(File packFolder) { String name = NOT_NAMESPACE.matcher(packFolder.getName().toLowerCase(Locale.ROOT)).replaceAll(REPLACEMENT); @@ -56,11 +60,15 @@ final class PackResourceIds { /** {@code key} of a resource whose type its use makes clear, such as a biome in a biome sample. */ ResourceId of(String key) { - return new ResourceId(namespace, NOT_PATH.matcher(key.toLowerCase(Locale.ROOT)).replaceAll(REPLACEMENT)); + return known.computeIfAbsent(key, this::idOf); } /** {@code key} of a resource of {@code type}, such as {@code overworld:biome/desert/dunes}. */ ResourceId of(String type, String key) { return of(type + "/" + key); } + + private ResourceId idOf(String key) { + return new ResourceId(namespace, NOT_PATH.matcher(key.toLowerCase(Locale.ROOT)).replaceAll(REPLACEMENT)); + } } diff --git a/core/src/main/java/art/arcane/iris/core/modules/PinnedMantleChunk.java b/core/src/main/java/art/arcane/iris/core/modules/PinnedMantleChunk.java deleted file mode 100644 index bee6ae674..000000000 --- a/core/src/main/java/art/arcane/iris/core/modules/PinnedMantleChunk.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Iris is a World Generator for Minecraft Servers - * Copyright (c) 2026 Arcane Arts (Volmit Software) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package art.arcane.iris.core.modules; - -import art.arcane.iris.engine.framework.Engine; -import art.arcane.volmlib.util.mantle.runtime.MantleChunk; -import art.arcane.volmlib.util.matter.Matter; - -/** - * The one mantle chunk a generating chunk's stages may read: pinned the first time a stage asks for it and - * released once the chunk's stages are done. - */ -final class PinnedMantleChunk implements IrisModuleMantle.Chunks, AutoCloseable { - private final Engine engine; - private final int chunkX; - private final int chunkZ; - private MantleChunk pinned; - - PinnedMantleChunk(Engine engine, int chunkX, int chunkZ) { - this.engine = engine; - this.chunkX = chunkX; - this.chunkZ = chunkZ; - } - - @Override - public synchronized MantleChunk chunk(int x, int z) { - if (x != chunkX || z != chunkZ) { - return null; - } - if (pinned == null) { - pinned = engine.getMantle().getMantle().getChunk(chunkX, chunkZ).use(); - } - return pinned; - } - - @Override - public synchronized void close() { - if (pinned != null) { - pinned.release(); - pinned = null; - } - } -} diff --git a/core/src/main/java/art/arcane/iris/core/modules/StageMetrics.java b/core/src/main/java/art/arcane/iris/core/modules/StageMetrics.java index c10f0cca9..c2cc0ffc8 100644 --- a/core/src/main/java/art/arcane/iris/core/modules/StageMetrics.java +++ b/core/src/main/java/art/arcane/iris/core/modules/StageMetrics.java @@ -36,7 +36,8 @@ final class StageMetrics implements StageTimings { private static final Map> NAMED = Map.of( "iris:post/smooth", EngineMetrics::getPost, "iris:perfection/surface", EngineMetrics::getPerfection, - "iris:deposit/ores", EngineMetrics::getDeposit); + "iris:deposit/ores", EngineMetrics::getDeposit, + "iris:decorant/decorate", EngineMetrics::getDecoration); private final EngineMetrics metrics; diff --git a/core/src/main/java/art/arcane/iris/engine/framework/EngineDecorator.java b/core/src/main/java/art/arcane/iris/engine/framework/EngineDecorator.java deleted file mode 100644 index cca7d593a..000000000 --- a/core/src/main/java/art/arcane/iris/engine/framework/EngineDecorator.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Iris is a World Generator for Minecraft Bukkit Servers - * Copyright (c) 2022 Arcane Arts (Volmit Software) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package art.arcane.iris.engine.framework; - -import art.arcane.iris.engine.object.world.biome.IrisBiome; -import art.arcane.iris.spi.PlatformBlockState; -import art.arcane.iris.util.common.data.B; -import art.arcane.volmlib.util.documentation.BlockCoordinates; -import art.arcane.iris.util.project.hunk.Hunk; - -public interface EngineDecorator extends EngineComponent { - - @BlockCoordinates - void decorate(int x, int z, int realX, int realX1, int realX_1, int realZ, int realZ1, int realZ_1, Hunk data, IrisBiome biome, int height, int max); - - @BlockCoordinates - default void decorate(int x, int z, int realX, int realZ, Hunk data, IrisBiome biome, int height, int max) { - decorate(x, z, realX, realX, realX, realZ, realZ, realZ, data, biome, height, max); - } - - @SuppressWarnings("BooleanMethodIsAlwaysInverted") - default boolean canGoOn(PlatformBlockState decorant, PlatformBlockState atop) { - if (atop == null || atop.isAir()) { - return false; - } - - return B.canPlaceOnto(decorant, atop); - } -} diff --git a/core/src/test/java/art/arcane/iris/core/modules/BuiltInPack.java b/core/src/test/java/art/arcane/iris/core/modules/BuiltInPack.java index f72881eb8..be0cf5153 100644 --- a/core/src/test/java/art/arcane/iris/core/modules/BuiltInPack.java +++ b/core/src/test/java/art/arcane/iris/core/modules/BuiltInPack.java @@ -21,6 +21,7 @@ package art.arcane.iris.core.modules; import art.arcane.iris.core.loader.IrisData; import art.arcane.iris.engine.framework.Engine; import art.arcane.iris.engine.framework.SeedManager; +import art.arcane.iris.engine.actuator.DecorantModule; import art.arcane.iris.engine.modifier.DepositModule; import art.arcane.iris.engine.modifier.MatterModule; import art.arcane.iris.engine.modifier.PerfectionModule; @@ -52,7 +53,7 @@ public final class BuiltInPack { * with Iris; {@code BuiltInModulesJarTest} loads the same modules from the jar instead. */ public static List jarModules() { - return List.of(new PostModule(), new PerfectionModule(), new MatterModule(), new DepositModule()); + return List.of(new PostModule(), new PerfectionModule(), new MatterModule(), new DepositModule(), new DecorantModule()); } /** Every built-in module: Iris's own and the compiled-in copies of the jar's ({@link #jarModules()}). */ diff --git a/core/src/test/java/art/arcane/iris/core/modules/BuiltInServicesTest.java b/core/src/test/java/art/arcane/iris/core/modules/BuiltInServicesTest.java index ff4c4f9ee..cc7f2cf5b 100644 --- a/core/src/test/java/art/arcane/iris/core/modules/BuiltInServicesTest.java +++ b/core/src/test/java/art/arcane/iris/core/modules/BuiltInServicesTest.java @@ -37,7 +37,7 @@ import static org.junit.Assert.assertTrue; /** The services and hooks Iris's built-in modules provide, which Iris core asks instead of their features. */ public class BuiltInServicesTest { - private static final FeatureCatalog BUILT_INS = ModuleResourceFixture.catalogOf(IrisModuleHost.builtInModules().toArray(IrisModule[]::new)); + private static final FeatureCatalog BUILT_INS = ModuleResourceFixture.catalogOf(BuiltInPack.allBuiltIns().toArray(IrisModule[]::new)); @Test public void objectsTellWhichObjectsAChunkGets() { diff --git a/core/src/test/java/art/arcane/iris/core/modules/DimensionBottomTest.java b/core/src/test/java/art/arcane/iris/core/modules/DimensionBottomTest.java index e7c8d931e..bd987de94 100644 --- a/core/src/test/java/art/arcane/iris/core/modules/DimensionBottomTest.java +++ b/core/src/test/java/art/arcane/iris/core/modules/DimensionBottomTest.java @@ -179,7 +179,7 @@ public class DimensionBottomTest { assertEquals("minecraft:stone", blocks.get(0, BOTTOM, 0).key()); assertEquals("the chunk's block hunk starts at the bottom, not at the world's minimum height", 1, countBlocks(blocks)); assertEquals(List.of(WHOLE_HEIGHT_AROUND_ONE_CHUNK), terrainBounds); - assertEquals(List.of(WHOLE_HEIGHT_OF_ONE_CHUNK), viewBounds); + assertEquals("the mantle reaches as far around the chunk as the terrain", List.of(WHOLE_HEIGHT_AROUND_ONE_CHUNK), viewBounds); assertEquals("the terrain samples count from the same bottom", List.of(Double.valueOf(SURFACE_HEIGHT)), surfaces); } diff --git a/core/src/test/java/art/arcane/iris/engine/actuator/DecorantModuleTest.java b/core/src/test/java/art/arcane/iris/engine/actuator/DecorantModuleTest.java index 53e3514c2..dd2101c40 100644 --- a/core/src/test/java/art/arcane/iris/engine/actuator/DecorantModuleTest.java +++ b/core/src/test/java/art/arcane/iris/engine/actuator/DecorantModuleTest.java @@ -1,98 +1,72 @@ package art.arcane.iris.engine.actuator; -import art.arcane.iris.core.loader.IrisData; -import art.arcane.iris.core.modules.ModuleSettings; -import art.arcane.iris.engine.framework.Engine; -import art.arcane.iris.engine.framework.EngineGeneration; -import art.arcane.iris.engine.framework.EngineMetrics; -import art.arcane.iris.engine.framework.SeedManager; -import art.arcane.iris.engine.object.world.biome.IrisBiome; -import art.arcane.iris.engine.object.world.dimension.IrisDimension; -import art.arcane.iris.spi.PlatformBlockState; -import art.arcane.iris.util.project.context.ChunkContext; -import art.arcane.iris.util.project.context.ChunkedDataCache; -import art.arcane.iris.util.project.hunk.Hunk; -import com.volmit.world.PackWorld; +import art.arcane.iris.builtin.decorant.DecorantSettings; +import art.arcane.iris.builtin.decorant.DecorateSettings; +import art.arcane.iris.builtin.decorant.Decorator; +import art.arcane.iris.engine.modifier.ApiChunk; +import art.arcane.iris.engine.object.TestSettings; +import com.google.gson.Gson; +import com.volmit.block.BlockState; import org.junit.Test; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertSame; +import java.util.List; -import static org.mockito.ArgumentMatchers.anyInt; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoInteractions; -import static org.mockito.Mockito.when; +import static org.junit.Assert.assertEquals; -/** - * Decorating reads nothing of the chunk when the dimension does not decorate, skips biomes without decorators, and is - * kept per world in the world's state store. - */ +/** Decorating puts a biome's decorators on its surface, unless the dimension says not to or the biome has none. */ public class DecorantModuleTest { + private static final int GROUND = 8; + private static final BlockState GRASS_BLOCK = new BlockState("minecraft:grass_block"); + private static final BlockState POPPY = new BlockState("minecraft:poppy"); + private static final DecorantSettings POPPIES = new DecorantSettings(List.of(new Gson().fromJson("{\"chance\": 1, \"palette\": [{\"block\": \"poppy\"}]}", Decorator.class))); + @Test - public void eachWorldKeepsOneDecoratingInItsStateStore() { - Engine engine = engine(true); - when(engine.getData()).thenReturn(mock(IrisData.class)); - EngineGeneration generation = new EngineGeneration(engine); - when(engine.getGeneration()).thenReturn(generation); - PackWorld world = generation.world(); + public void everyColumnOfABiomeWithDecoratorsGetsOne() { + ApiChunk chunk = ground().biomeSettings(POPPIES); - DecorantModule.Decorating decorating = DecorantModule.decorating(world); + chunk.generate(new DecorantModule()); - assertSame(decorating, DecorantModule.decorating(world)); - assertSame("built-in stages share the store", decorating, - generation.state(DecorantModule.Decorating.class, DecorantModule.Decorating::new)); - EngineGeneration otherGeneration = new EngineGeneration(engine); - when(engine.getGeneration()).thenReturn(otherGeneration); - assertNotSame(decorating, DecorantModule.decorating(otherGeneration.world())); + assertEquals(256, countAt(chunk, GROUND + 1, POPPY)); + assertEquals("on top of the ground, not in it", 0, countAt(chunk, GROUND, POPPY)); } @Test public void aDimensionThatDoesNotDecorateIsLeftAlone() { - DecorantModule.Decorating decorating = new DecorantModule.Decorating(engineWithGeneration(false)); - ChunkContext context = mock(ChunkContext.class); + ApiChunk chunk = ground().biomeSettings(POPPIES).dimensionSettings(TestSettings.of(DecorateSettings.class, "{\"decorate\": false}")); - decorating.decorate(0, 0, Hunk.newArrayHunk(16, 16, 16), context); + chunk.generate(new DecorantModule()); - verifyNoInteractions(context); + assertEquals(0, countAt(chunk, GROUND + 1, POPPY)); } @Test - @SuppressWarnings("unchecked") public void aBiomeWithoutDecoratorsGetsNothingPlaced() { - DecorantModule.Decorating decorating = new DecorantModule.Decorating(engineWithGeneration(true)); - IrisBiome biome = mock(IrisBiome.class); - when(biome.getModuleSettings()).thenReturn(ModuleSettings.NONE); - ChunkedDataCache biomes = mock(ChunkedDataCache.class); - when(biomes.get(anyInt(), anyInt())).thenReturn(biome); - ChunkContext context = mock(ChunkContext.class); - when(context.getBiome()).thenReturn(biomes); - Hunk output = mock(Hunk.class); - when(output.getWidth()).thenReturn(16); - when(output.getDepth()).thenReturn(16); + ApiChunk chunk = ground(); - decorating.decorate(0, 0, output, context); + chunk.generate(new DecorantModule()); - verify(output, never()).set(anyInt(), anyInt(), anyInt(), org.mockito.ArgumentMatchers.any()); - verify(biomes, org.mockito.Mockito.times(16 * 16)).get(anyInt(), anyInt()); + assertEquals(0, countAt(chunk, GROUND + 1, POPPY)); } - private Engine engineWithGeneration(boolean decorate) { - Engine engine = engine(decorate); - when(engine.getData()).thenReturn(mock(IrisData.class)); - when(engine.getGeneration()).thenReturn(new EngineGeneration(engine)); - return engine; + private static ApiChunk ground() { + ApiChunk chunk = new ApiChunk(0, 0, 32).surface((x, z) -> GROUND); + for (int x = 0; x < ApiChunk.WIDTH; x++) { + for (int z = 0; z < ApiChunk.WIDTH; z++) { + for (int y = 0; y <= GROUND; y++) { + chunk.set(x, y, z, GRASS_BLOCK); + } + } + } + return chunk; } - private Engine engine(boolean decorate) { - IrisDimension dimension = mock(IrisDimension.class); - when(dimension.isDecorate()).thenReturn(decorate); - SeedManager seeds = mock(SeedManager.class); - Engine engine = mock(Engine.class); - when(engine.getDimension()).thenReturn(dimension); - when(engine.getSeedManager()).thenReturn(seeds); - when(engine.getMetrics()).thenReturn(new EngineMetrics(16)); - return engine; + private static int countAt(ApiChunk chunk, int y, BlockState block) { + int count = 0; + for (int x = 0; x < ApiChunk.WIDTH; x++) { + for (int z = 0; z < ApiChunk.WIDTH; z++) { + count += chunk.get(x, y, z).equals(block) ? 1 : 0; + } + } + return count; } } diff --git a/core/src/test/java/art/arcane/iris/engine/decorator/BiomeDecoratorsTest.java b/core/src/test/java/art/arcane/iris/engine/decorator/BiomeDecoratorsTest.java index f015ff3d1..a682b4a02 100644 --- a/core/src/test/java/art/arcane/iris/engine/decorator/BiomeDecoratorsTest.java +++ b/core/src/test/java/art/arcane/iris/engine/decorator/BiomeDecoratorsTest.java @@ -1,40 +1,27 @@ package art.arcane.iris.engine.decorator; +import art.arcane.iris.builtin.IrisSeed; import art.arcane.iris.builtin.decorant.DecorantSettings; import art.arcane.iris.builtin.decorant.DecorationPart; import art.arcane.iris.builtin.decorant.Decorator; -import art.arcane.iris.core.loader.IrisData; -import art.arcane.iris.core.loader.ResourceLoader; -import art.arcane.iris.core.modules.IrisPackResources; -import art.arcane.iris.core.modules.ModuleSettings; -import art.arcane.iris.engine.UsableBlockPlatform; -import art.arcane.iris.engine.framework.Engine; -import art.arcane.iris.engine.framework.SeedManager; -import art.arcane.iris.engine.object.material.IrisBlockData; -import art.arcane.iris.engine.object.world.biome.IrisBiome; -import art.arcane.iris.engine.object.world.dimension.IrisDimension; -import art.arcane.volmlib.util.collection.KList; +import art.arcane.iris.engine.modifier.ApiChunk; import com.google.gson.Gson; -import com.volmit.host.ModuleLogs; -import org.junit.After; +import com.volmit.resource.ResourceId; +import com.volmit.world.BiomeKind; +import com.volmit.world.PackWorld; import org.junit.Before; import org.junit.Test; -import java.io.File; import java.util.List; -import java.util.Optional; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; /** The decorators of a world's biomes, sorted into the places they decorate and seeded from the world. */ public class BiomeDecoratorsTest { - private static final long DECORATOR_SEED = 5000L; private static final String MEADOW_DECORATORS = """ [{"chance": 0.5, "palette": [{"block": "poppy"}]}, {"partOf": "SHORE_LINE", "chance": 1, "stackMax": 3, "palette": [{"block": "sugar_cane"}]}, @@ -42,36 +29,21 @@ public class BiomeDecoratorsTest { {"partOf": "CEILING", "chance": 1, "palette": [{"block": "glow_lichen"}]}] """; - private Engine engine; - private IrisBiome meadow; - private IrisBiome bare; + private ApiChunk chunk; + private PackWorld world; + private DecoratedBiome meadow; + private DecoratedBiome bare; private BiomeDecorators decorators; @Before public void createWorld() { - UsableBlockPlatform.bind(); - IrisData data = mock(IrisData.class); - @SuppressWarnings("unchecked") - ResourceLoader blocks = mock(ResourceLoader.class); - when(data.getBlockLoader()).thenReturn(blocks); - when(data.getDataFolder()).thenReturn(new File("pack")); - IrisPackResources resources = new IrisPackResources(data); - when(data.getPackResources()).thenReturn(resources); - SeedManager seeds = mock(SeedManager.class); - when(seeds.getDecorator()).thenReturn(DECORATOR_SEED); - engine = mock(Engine.class); - when(engine.getData()).thenReturn(data); - when(engine.getSeedManager()).thenReturn(seeds); - meadow = biome("meadow", MEADOW_DECORATORS); - bare = mock(IrisBiome.class); - when(bare.getLoadKey()).thenReturn("bare"); - when(bare.getModuleSettings()).thenReturn(ModuleSettings.NONE); - decorators = new BiomeDecorators(engine, ModuleLogs.discarding()); - } - - @After - public void unbindPlatform() { - UsableBlockPlatform.unbind(); + List list = List.of(new Gson().fromJson(MEADOW_DECORATORS, Decorator[].class)); + DecorantSettings settings = new DecorantSettings(list); + chunk = new ApiChunk(0, 0, 16).biomeSettings(settings); + world = chunk.world(); + meadow = new DecoratedBiome("meadow", settings, BiomeKind.LAND); + bare = new DecoratedBiome("bare", null, BiomeKind.LAND); + decorators = BiomeDecorators.of(world); } @Test @@ -87,65 +59,43 @@ public class BiomeDecoratorsTest { @Test public void aBiomeWithoutTheSettingsHasNoDecorators() { assertFalse(decorators.hasDecorators(bare)); + assertFalse(decorators.hasDecorators(null)); assertEquals(0, decorators.decorators(bare, DecorationPart.NONE).length); - assertEquals(0D, decorators.load(bare), 0); } @Test public void decoratorsAreResolvedOnceAndKeptForTheWorld() { assertSame(decorators.decorators(meadow, DecorationPart.NONE)[0], decorators.decorators(meadow, DecorationPart.NONE)[0]); + assertSame(decorators, BiomeDecorators.of(world)); } @Test public void everyDecoratorNoiseSeedIsAFunctionOfTheWorldsDecoratorSeedItsBiomeAndItsPlace() { - long first = seedOf(decorators.decorators(meadow, DecorationPart.NONE)[0]); - long second = seedOf(decorators.decorators(meadow, DecorationPart.NONE)[1]); + long decoratorSeed = IrisSeed.DECORATOR.of(world); + long first = decorators.decorators(meadow, DecorationPart.NONE)[0].seed(); + long second = decorators.decorators(meadow, DecorationPart.NONE)[1].seed(); - assertEquals("biome meadow, index 0", DECORATOR_SEED + "meadow".hashCode() * 0x9E3779B97F4A7C15L, first); - assertEquals("biome meadow, index 2", DECORATOR_SEED + "meadow".hashCode() * 0x9E3779B97F4A7C15L + 2 * 0xC2B2AE3D27D4EB4FL, second); + assertEquals("biome meadow, index 0", decoratorSeed + "meadow".hashCode() * 0x9E3779B97F4A7C15L, first); + assertEquals("biome meadow, index 2", decoratorSeed + "meadow".hashCode() * 0x9E3779B97F4A7C15L + 2 * 0xC2B2AE3D27D4EB4FL, second); assertNotEquals(first, second); assertEquals("another build of the same world draws the same seeds", first, - seedOf(new BiomeDecorators(engine, ModuleLogs.discarding()).decorators(meadow, DecorationPart.NONE)[0])); + new BiomeDecorators(world).decorators(meadow, DecorationPart.NONE)[0].seed()); } @Test - public void warmingResolvesEveryDecoratorOfEveryReachableBiome() { - IrisDimension dimension = mock(IrisDimension.class); - when(dimension.getReachableBiomes(engine)).thenReturn(new KList<>(List.of(meadow, bare))); - when(engine.getDimension()).thenReturn(dimension); - when(engine.getAllBiomes()).thenCallRealMethod(); + public void aBiomesKeyIsTheRestOfTheIdOfTheSettingsItDeclared() { + assertEquals("desert/dunes", BiomeDecorators.biomeKey(ResourceId.parse("overworld:biome/desert/dunes"))); + } + @Test + public void warmingResolvesEveryDecoratorOfEveryBiomeThePackDeclares() { decorators.warm(); - assertEquals(2, decorators.decorators(meadow, DecorationPart.NONE).length); - } - - @Test - public void theBusiestBiomeSetsTheScaleOfTheLoadViews() { - IrisDimension dimension = mock(IrisDimension.class); - when(dimension.getReachableBiomes(engine)).thenReturn(new KList<>(List.of(meadow, bare))); - when(engine.getDimension()).thenReturn(dimension); - - assertEquals(0.5 + 3 * 1.0 + 0.25 + 1.0, decorators.load(meadow), 1e-9); - assertEquals(decorators.load(meadow), decorators.busiestBiomeLoad(), 0); - assertEquals((0.5 + 1.0 + 0.25 + 1.0) * 256, decorators.colourLoad(meadow), 1e-9); - } - - private IrisBiome biome(String key, String decoratorsJson) { - List list = List.of(new Gson().fromJson(decoratorsJson, Decorator[].class)); - ModuleSettings settings = mock(ModuleSettings.class); - when(settings.find(DecorantSettings.class)).thenReturn(Optional.of(new DecorantSettings(list))); - IrisBiome biome = mock(IrisBiome.class); - when(biome.getLoadKey()).thenReturn(key); - when(biome.getModuleSettings()).thenReturn(settings); - return biome; + assertEquals(2, decorators.decorators(new DecoratedBiome("plains", chunk.world().settings().declared(DecorantSettings.class).getFirst().value(), + BiomeKind.LAND), DecorationPart.NONE).length); } private static List chances(ResolvedDecorator[] bucket) { return java.util.Arrays.stream(bucket).map(decorator -> decorator.settings().chance()).toList(); } - - private static long seedOf(ResolvedDecorator decorator) { - return decorator.seed(); - } } diff --git a/core/src/test/java/art/arcane/iris/engine/decorator/DecoratorCoreTest.java b/core/src/test/java/art/arcane/iris/engine/decorator/DecoratorCoreTest.java index 816a66b91..ff7bbae25 100644 --- a/core/src/test/java/art/arcane/iris/engine/decorator/DecoratorCoreTest.java +++ b/core/src/test/java/art/arcane/iris/engine/decorator/DecoratorCoreTest.java @@ -1,14 +1,19 @@ package art.arcane.iris.engine.decorator; -import art.arcane.iris.builtin.decorant.DecorationPart; -import art.arcane.iris.spi.PlatformBlockState; -import art.arcane.iris.util.project.hunk.Hunk; +import art.arcane.iris.engine.modifier.ApiChunk; import art.arcane.volmlib.util.math.RNG; +import com.volmit.block.BlockState; +import com.volmit.host.ArrayHunk; import com.volmit.host.ModuleLogs; -import org.bukkit.block.BlockSupport; -import org.bukkit.block.data.BlockData; +import com.volmit.hunk.Hunk; +import com.volmit.mantle.BlockBox; +import com.volmit.mantle.MantleLayer; +import com.volmit.mantle.MantleVisitor; import org.junit.Test; +import java.util.HashMap; +import java.util.Map; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; @@ -16,13 +21,16 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyDouble; -import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; public class DecoratorCoreTest { + private static final BlockState AIR = ApiChunk.AIR; + private static final BlockState GRASS_BLOCK = new BlockState("minecraft:grass_block"); + private static final BlockState STONE = new BlockState("minecraft:stone"); + private static final BlockState POPPY = new BlockState("minecraft:poppy"); + private static final BlockState TALL_GRASS = BlockState.parse("minecraft:tall_grass[half=lower]"); @Test public void partSeed_differsByPartOrdinal() { @@ -121,252 +129,182 @@ public class DecoratorCoreTest { @Test public void singleStackTargetsBlockAboveSupport() { ResolvedDecorator decorator = mock(ResolvedDecorator.class); - PlatformBlockState support = sturdyState(); - PlatformBlockState air = mock(PlatformBlockState.class); - PlatformBlockState decorant = mock(PlatformBlockState.class); - when(air.isAir()).thenReturn(true); - when(decorant.key()).thenReturn("minecraft:stone"); - when(decorant.canPlaceOnto(support)).thenReturn(true); when(decorator.stackHeight(anyDouble(), anyDouble())).thenReturn(1); - when(decorator.pickTopBlock(anyDouble(), anyDouble())).thenReturn(decorant); + when(decorator.pickTopBlock(anyDouble(), anyDouble())).thenReturn(POPPY); - Hunk output = Hunk.newArrayHunk(1, 4, 1); - output.set(0, 1, 0, support); - output.set(0, 2, 0, air); + Hunk output = hunk(1, 4, 1); + output.set(0, 1, 0, GRASS_BLOCK); DecoratorCore.PlaceOpts opts = new DecoratorCore.PlaceOpts(); - DecoratorCore.placeStackUp(decorator, 0, 0, 0, 0, 1, 3, output, opts); + DecoratorCore.placeStackUp(decorator, scene(output), 0, 0, 0, 0, 1, 3, opts); - assertSame(support, output.get(0, 1, 0)); - assertSame(decorant, output.get(0, 2, 0)); + assertSame(GRASS_BLOCK, output.get(0, 1, 0)); + assertSame(POPPY, output.get(0, 2, 0)); } @Test public void singleStackDoesNotOverwriteOccupiedTarget() { ResolvedDecorator decorator = mock(ResolvedDecorator.class); - PlatformBlockState support = sturdyState(); - PlatformBlockState occupied = mock(PlatformBlockState.class); - PlatformBlockState decorant = mock(PlatformBlockState.class); - when(occupied.isAir()).thenReturn(false); - when(occupied.isFluid()).thenReturn(false); when(decorator.stackHeight(anyDouble(), anyDouble())).thenReturn(1); - when(decorator.pickTopBlock(anyDouble(), anyDouble())).thenReturn(decorant); + when(decorator.pickTopBlock(anyDouble(), anyDouble())).thenReturn(POPPY); - Hunk output = Hunk.newArrayHunk(1, 4, 1); - output.set(0, 1, 0, support); - output.set(0, 2, 0, occupied); - DecoratorCore.PlaceOpts opts = new DecoratorCore.PlaceOpts(); + Hunk output = hunk(1, 4, 1); + output.set(0, 1, 0, GRASS_BLOCK); + output.set(0, 2, 0, STONE); - DecoratorCore.placeStackUp(decorator, 0, 0, 0, 0, 1, 3, output, opts); + DecoratorCore.placeStackUp(decorator, scene(output), 0, 0, 0, 0, 1, 3, new DecoratorCore.PlaceOpts()); - assertSame(support, output.get(0, 1, 0)); - assertSame(occupied, output.get(0, 2, 0)); + assertSame(GRASS_BLOCK, output.get(0, 1, 0)); + assertSame(STONE, output.get(0, 2, 0)); } @Test public void multiStackStopsBeforeOccupiedTarget() { ResolvedDecorator decorator = mock(ResolvedDecorator.class); - PlatformBlockState support = sturdyState(); - PlatformBlockState air = mock(PlatformBlockState.class); - PlatformBlockState occupied = mock(PlatformBlockState.class); - PlatformBlockState decorant = mock(PlatformBlockState.class); - when(air.isAir()).thenReturn(true); - when(occupied.isAir()).thenReturn(false); - when(occupied.isFluid()).thenReturn(false); - when(decorant.key()).thenReturn("minecraft:tall_grass"); - when(decorant.canPlaceOnto(support)).thenReturn(true); + BlockState decorant = new BlockState("minecraft:tall_grass"); when(decorator.stackHeight(anyDouble(), anyDouble())).thenReturn(3); when(decorator.topThreshold()).thenReturn(0.75); when(decorator.pickBlock(anyDouble(), anyDouble())).thenReturn(decorant); when(decorator.pickTopBlock(anyDouble(), anyDouble())).thenReturn(decorant); - Hunk output = Hunk.newArrayHunk(1, 5, 1); - output.set(0, 1, 0, support); - output.set(0, 2, 0, air); - output.set(0, 3, 0, occupied); - output.set(0, 4, 0, air); - DecoratorCore.PlaceOpts opts = new DecoratorCore.PlaceOpts(); + Hunk output = hunk(1, 5, 1); + output.set(0, 1, 0, GRASS_BLOCK); + output.set(0, 3, 0, STONE); - DecoratorCore.placeStackUp(decorator, 0, 0, 0, 0, 1, 4, output, opts); + DecoratorCore.placeStackUp(decorator, scene(output), 0, 0, 0, 0, 1, 4, new DecoratorCore.PlaceOpts()); assertSame(decorant, output.get(0, 2, 0)); - assertSame(occupied, output.get(0, 3, 0)); - assertSame(air, output.get(0, 4, 0)); + assertSame(STONE, output.get(0, 3, 0)); + assertSame(AIR, output.get(0, 4, 0)); } @Test public void descendingStackStopsAtLocalWorldFloor() { ResolvedDecorator decorator = mock(ResolvedDecorator.class); - PlatformBlockState decorant = mock(PlatformBlockState.class); - when(decorant.key()).thenReturn("minecraft:stone"); when(decorator.stackHeight(anyDouble(), anyDouble())).thenReturn(2); when(decorator.topThreshold()).thenReturn(1.0); - when(decorator.pickBlock(anyDouble(), anyDouble())).thenReturn(decorant); - when(decorator.pickTopBlock(anyDouble(), anyDouble())).thenReturn(decorant); + when(decorator.pickBlock(anyDouble(), anyDouble())).thenReturn(STONE); + when(decorator.pickTopBlock(anyDouble(), anyDouble())).thenReturn(STONE); - Hunk output = Hunk.newArrayHunk(1, 2, 1); - DecoratorCore.PlaceOpts opts = new DecoratorCore.PlaceOpts(); + Hunk output = hunk(1, 2, 1); - DecoratorCore.placeStackDown( - decorator, 0, 0, 0, 0, 0, -64, output, 2, opts, null); + DecoratorCore.placeStackDown(decorator, scene(output), 0, 0, 0, 0, 0, -64, 2, new DecoratorCore.PlaceOpts()); - assertSame(decorant, output.get(0, 0, 0)); + assertSame(STONE, output.get(0, 0, 0)); } @Test public void singleDescendingStackPreservesTargetWhenPickIsNull() { ResolvedDecorator decorator = mock(ResolvedDecorator.class); - PlatformBlockState existing = mock(PlatformBlockState.class); when(decorator.stackHeight(anyDouble(), anyDouble())).thenReturn(1); - Hunk output = Hunk.newArrayHunk(1, 2, 1); - output.set(0, 0, 0, existing); - DecoratorCore.PlaceOpts opts = new DecoratorCore.PlaceOpts(); + Hunk output = hunk(1, 2, 1); + output.set(0, 0, 0, STONE); - DecoratorCore.placeStackDown( - decorator, 0, 0, 0, 0, 0, 0, output, 1, opts, null); + DecoratorCore.placeStackDown(decorator, scene(output), 0, 0, 0, 0, 0, 0, 1, new DecoratorCore.PlaceOpts()); - assertSame(existing, output.get(0, 0, 0)); + assertSame(STONE, output.get(0, 0, 0)); } @Test public void multiDescendingStackStopsWhenPickIsNull() { ResolvedDecorator decorator = mock(ResolvedDecorator.class); - PlatformBlockState lowerExisting = mock(PlatformBlockState.class); - PlatformBlockState upperExisting = mock(PlatformBlockState.class); when(decorator.stackHeight(anyDouble(), anyDouble())).thenReturn(2); when(decorator.topThreshold()).thenReturn(1.0); - Hunk output = Hunk.newArrayHunk(1, 2, 1); - output.set(0, 0, 0, lowerExisting); - output.set(0, 1, 0, upperExisting); - DecoratorCore.PlaceOpts opts = new DecoratorCore.PlaceOpts(); + Hunk output = hunk(1, 2, 1); + output.set(0, 0, 0, STONE); + output.set(0, 1, 0, GRASS_BLOCK); - DecoratorCore.placeStackDown( - decorator, 0, 0, 0, 0, 1, 0, output, 2, opts, null); + DecoratorCore.placeStackDown(decorator, scene(output), 0, 0, 0, 0, 1, 0, 2, new DecoratorCore.PlaceOpts()); - assertSame(lowerExisting, output.get(0, 0, 0)); - assertSame(upperExisting, output.get(0, 1, 0)); + assertSame(STONE, output.get(0, 0, 0)); + assertSame(GRASS_BLOCK, output.get(0, 1, 0)); } @Test public void floatingStackStopsAtHunkCeiling() { ResolvedDecorator decorator = mock(ResolvedDecorator.class); - PlatformBlockState decorant = mock(PlatformBlockState.class); - when(decorant.key()).thenReturn("minecraft:stone"); when(decorator.stackHeight(anyDouble(), anyDouble())).thenReturn(3); when(decorator.topThreshold()).thenReturn(1.0); - when(decorator.pickBlock(anyDouble(), anyDouble())).thenReturn(decorant); - when(decorator.pickTopBlock(anyDouble(), anyDouble())).thenReturn(decorant); + when(decorator.pickBlock(anyDouble(), anyDouble())).thenReturn(STONE); + when(decorator.pickTopBlock(anyDouble(), anyDouble())).thenReturn(STONE); - Hunk output = Hunk.newArrayHunk(1, 2, 1); - int placed = DecoratorCore.placeFloatingStacked( - decorator, 0, 0, 0, 0, 0, 3, output); + Hunk output = hunk(1, 2, 1); + int placed = DecoratorCore.placeFloatingStacked(decorator, scene(output), 0, 0, 0, 0, 0, 3); assertEquals(1, placed); - assertSame(decorant, output.get(0, 1, 0)); + assertSame(STONE, output.get(0, 1, 0)); } @Test public void tallSurfacePlantDoesNotPlaceWhenUpperTargetIsOccupied() { ResolvedDecorator decorator = mock(ResolvedDecorator.class); - PlatformBlockState support = sturdyState(); - PlatformBlockState air = airState(); - PlatformBlockState occupied = mock(PlatformBlockState.class); - PlatformBlockState plant = tallPlantState(); - when(decorator.pickBlock(anyDouble(), anyDouble())).thenReturn(plant); + when(decorator.pickBlock(anyDouble(), anyDouble())).thenReturn(TALL_GRASS); - Hunk output = Hunk.newArrayHunk(1, 4, 1); - output.set(0, 0, 0, support); - output.set(0, 1, 0, air); - output.set(0, 2, 0, occupied); + Hunk output = hunk(1, 4, 1); + output.set(0, 0, 0, GRASS_BLOCK); + output.set(0, 2, 0, STONE); - DecoratorCore.placeSurfaceSingle( - decorator, 0, 0, 0, 0, 0, output, false, false, null, ModuleLogs.discarding()); + DecoratorCore.placeSurfaceSingle(decorator, scene(output), 0, 0, 0, 0, 0, false, false); - assertSame(air, output.get(0, 1, 0)); - assertSame(occupied, output.get(0, 2, 0)); + assertSame(AIR, output.get(0, 1, 0)); + assertSame(STONE, output.get(0, 2, 0)); } @Test public void tallFloatingPlantDoesNotPlaceWhenUpperTargetIsOccupied() { ResolvedDecorator decorator = mock(ResolvedDecorator.class); - PlatformBlockState air = airState(); - PlatformBlockState occupied = mock(PlatformBlockState.class); - PlatformBlockState plant = tallPlantState(); - when(decorator.pickBlock(anyDouble(), anyDouble())).thenReturn(plant); + when(decorator.pickBlock(anyDouble(), anyDouble())).thenReturn(TALL_GRASS); - Hunk output = Hunk.newArrayHunk(1, 4, 1); - output.set(0, 1, 0, air); - output.set(0, 2, 0, occupied); + Hunk output = hunk(1, 4, 1); + output.set(0, 2, 0, STONE); - DecoratorCore.placeFloatingSimple( - decorator, 0, 0, 0, 0, 0, 3, output, ModuleLogs.discarding()); + DecoratorCore.placeFloatingSimple(decorator, scene(output), 0, 0, 0, 0, 0, 3); - assertSame(air, output.get(0, 1, 0)); - assertSame(occupied, output.get(0, 2, 0)); + assertSame(AIR, output.get(0, 1, 0)); + assertSame(STONE, output.get(0, 2, 0)); } @Test public void tallSurfacePlantPlacesBothHalvesTogether() { ResolvedDecorator decorator = mock(ResolvedDecorator.class); - PlatformBlockState support = sturdyState(); - PlatformBlockState lowerAir = airState(); - PlatformBlockState upperAir = airState(); - PlatformBlockState lower = mock(PlatformBlockState.class); - PlatformBlockState upper = mock(PlatformBlockState.class); - PlatformBlockState plant = tallPlantState(lower, upper); - when(plant.canPlaceOnto(support)).thenReturn(true); - when(decorator.pickBlock(anyDouble(), anyDouble())).thenReturn(plant); + when(decorator.pickBlock(anyDouble(), anyDouble())).thenReturn(TALL_GRASS); - Hunk output = Hunk.newArrayHunk(1, 4, 1); - output.set(0, 0, 0, support); - output.set(0, 1, 0, lowerAir); - output.set(0, 2, 0, upperAir); + Hunk output = hunk(1, 4, 1); + output.set(0, 0, 0, GRASS_BLOCK); - DecoratorCore.placeSurfaceSingle( - decorator, 0, 0, 0, 0, 0, output, false, false, null, ModuleLogs.discarding()); + DecoratorCore.placeSurfaceSingle(decorator, scene(output), 0, 0, 0, 0, 0, false, false); - assertSame(lower, output.get(0, 1, 0)); - assertSame(upper, output.get(0, 2, 0)); + assertEquals(BlockState.parse("minecraft:tall_grass[half=lower]"), output.get(0, 1, 0)); + assertEquals(BlockState.parse("minecraft:tall_grass[half=upper]"), output.get(0, 2, 0)); } @Test - public void surfaceDecorantRejectsInvalidNativeSupport() { + public void surfaceDecorantRejectsInvalidSupport() { ResolvedDecorator decorator = mock(ResolvedDecorator.class); - PlatformBlockState support = sturdyState(); - PlatformBlockState air = airState(); - PlatformBlockState decorant = mock(PlatformBlockState.class); - when(decorant.canPlaceOnto(support)).thenReturn(false); - when(decorator.pickBlock(anyDouble(), anyDouble())).thenReturn(decorant); + when(decorator.pickBlock(anyDouble(), anyDouble())).thenReturn(POPPY); - Hunk output = Hunk.newArrayHunk(1, 3, 1); - output.set(0, 0, 0, support); - output.set(0, 1, 0, air); + Hunk output = hunk(1, 3, 1); + output.set(0, 0, 0, STONE); - DecoratorCore.placeSurfaceSingle( - decorator, 0, 0, 0, 0, 0, output, false, false, null, ModuleLogs.discarding()); + DecoratorCore.placeSurfaceSingle(decorator, scene(output), 0, 0, 0, 0, 0, false, false); - assertSame(air, output.get(0, 1, 0)); + assertSame(AIR, output.get(0, 1, 0)); } @Test public void forcedSurfaceBlockStillPlacesDecorantAboveIt() { ResolvedDecorator decorator = mock(ResolvedDecorator.class); - PlatformBlockState support = sturdyState(); - PlatformBlockState farmland = sturdyState(); - PlatformBlockState air = airState(); - PlatformBlockState wheat = mock(PlatformBlockState.class); - when(wheat.key()).thenReturn("minecraft:wheat[age=7]"); + BlockState farmland = new BlockState("minecraft:farmland"); + BlockState wheat = BlockState.parse("minecraft:wheat[age=7]"); when(decorator.forceBlock()).thenReturn(farmland); when(decorator.pickBlock(anyDouble(), anyDouble())).thenReturn(wheat); - Hunk output = Hunk.newArrayHunk(1, 3, 1); - output.set(0, 0, 0, support); - output.set(0, 1, 0, air); + Hunk output = hunk(1, 3, 1); + output.set(0, 0, 0, STONE); - DecoratorCore.placeSurfaceSingle( - decorator, 0, 0, 0, 0, 0, output, false, false, null, ModuleLogs.discarding()); + DecoratorCore.placeSurfaceSingle(decorator, scene(output), 0, 0, 0, 0, 0, false, false); assertSame(farmland, output.get(0, 0, 0)); assertSame(wheat, output.get(0, 1, 0)); @@ -374,69 +312,104 @@ public class DecoratorCoreTest { @Test public void descendingWeepingVinesUsePlantBodiesAndOneFreeEndTip() { - PlatformBlockState vine = mock(PlatformBlockState.class); - when(vine.key()).thenReturn("minecraft:weeping_vines"); + BlockState vine = new BlockState("minecraft:weeping_vines"); - assertEquals("minecraft:weeping_vines_plant", DecoratorCore.stackedVineKey(vine, 3, 0)); - assertEquals("minecraft:weeping_vines_plant", DecoratorCore.stackedVineKey(vine, 3, 1)); - assertEquals("minecraft:weeping_vines", DecoratorCore.stackedVineKey(vine, 3, 2)); + assertEquals("minecraft:weeping_vines_plant", DecoratorCore.stackedVineMaterial(vine, 3, 0).toString()); + assertEquals("minecraft:weeping_vines_plant", DecoratorCore.stackedVineMaterial(vine, 3, 1).toString()); + assertEquals("minecraft:weeping_vines", DecoratorCore.stackedVineMaterial(vine, 3, 2).toString()); } @Test public void ascendingTwistingVinesUsePlantBodiesAndOneFreeEndTip() { - PlatformBlockState vine = mock(PlatformBlockState.class); - when(vine.key()).thenReturn("minecraft:twisting_vines_plant"); + BlockState vine = new BlockState("minecraft:twisting_vines_plant"); - assertEquals("minecraft:twisting_vines_plant", DecoratorCore.stackedVineKey(vine, 3, 0)); - assertEquals("minecraft:twisting_vines_plant", DecoratorCore.stackedVineKey(vine, 3, 1)); - assertEquals("minecraft:twisting_vines", DecoratorCore.stackedVineKey(vine, 3, 2)); + assertEquals("minecraft:twisting_vines_plant", DecoratorCore.stackedVineMaterial(vine, 3, 0).toString()); + assertEquals("minecraft:twisting_vines_plant", DecoratorCore.stackedVineMaterial(vine, 3, 1).toString()); + assertEquals("minecraft:twisting_vines", DecoratorCore.stackedVineMaterial(vine, 3, 2).toString()); + assertNull(DecoratorCore.stackedVineMaterial(STONE, 3, 2)); } @Test - public void boundDecoratorHooksWinWhenBukkitClassesArePresent() { - PlatformBlockState vine = mock(PlatformBlockState.class); - PlatformBlockState fixed = mock(PlatformBlockState.class); - PlatformBlockState decorator = mock(PlatformBlockState.class); - PlatformBlockState surface = mock(PlatformBlockState.class); - Hunk output = Hunk.newArrayHunk(1, 1, 1); - DecoratorPlatformHooks.FaceFixer faceFixer = mock(DecoratorPlatformHooks.FaceFixer.class); - DecoratorPlatformHooks.SurfaceSturdiness sturdiness = mock(DecoratorPlatformHooks.SurfaceSturdiness.class); - when(vine.isVineBlock()).thenReturn(true); - when(faceFixer.fixFaces(vine, output, 0, 0, 0, 0, 0, null)).thenReturn(fixed); - when(decorator.canPlaceOnto(surface)).thenReturn(true); - when(sturdiness.canGoOn(surface)).thenReturn(true); - DecoratorPlatformHooks.Bindings previous = DecoratorPlatformHooks.bind(faceFixer, sturdiness); - try { - assertSame(fixed, DecoratorCore.fixFacesForHunk(vine, output, 0, 0, 0, 0, 0, null)); - assertTrue(DecoratorCore.canGoOn(decorator, surface)); - } finally { - DecoratorPlatformHooks.restore(previous); + public void aVineFacesTheNeighboursThatCanHoldIt() { + Hunk output = hunk(3, 3, 3); + output.set(2, 1, 1, STONE); + + BlockState fixed = DecoratorCore.fixFacesForHunk(scene(output), vine(), 1, 1, 1, 1, 1); + + assertEquals("true", fixed.properties().get("east")); + for (String face : new String[]{"north", "south", "west", "up", "down"}) { + assertEquals(face, "false", fixed.properties().get(face)); } } - private PlatformBlockState airState() { - PlatformBlockState air = mock(PlatformBlockState.class); - when(air.isAir()).thenReturn(true); - return air; + @Test + public void aVineHeldByBlocksThePlannedMantleHoldsOutsideTheChunkFacesThem() { + Hunk output = hunk(3, 3, 3); + Map planned = new HashMap<>(); + planned.put("-1,1,1", STONE); + + BlockState fixed = DecoratorCore.fixFacesForHunk(scene(output, plannedLayer(planned)), vine(), 0, 1, 0, 1, 1); + + assertEquals("true", fixed.properties().get("west")); + assertEquals("false", fixed.properties().get("east")); } - private PlatformBlockState tallPlantState() { - return tallPlantState(mock(PlatformBlockState.class), mock(PlatformBlockState.class)); + @Test + public void aVineNothingHoldsFacesDown() { + BlockState fixed = DecoratorCore.fixFacesForHunk(scene(hunk(3, 3, 3)), vine(), 1, 1, 1, 1, 1); + + assertEquals("true", fixed.properties().get("down")); + assertEquals("false", fixed.properties().get("up")); } - private PlatformBlockState tallPlantState(PlatformBlockState lower, PlatformBlockState upper) { - PlatformBlockState plant = mock(PlatformBlockState.class); - when(plant.key()).thenReturn("minecraft:tall_grass[half=lower]"); - when(plant.withProperty("half", "lower")).thenReturn(lower); - when(plant.withProperty("half", "upper")).thenReturn(upper); - return plant; + @Test + public void otherBlocksAreNotFaced() { + assertSame(STONE, DecoratorCore.fixFacesForHunk(scene(hunk(1, 1, 1)), STONE, 0, 0, 0, 0, 0)); } - private PlatformBlockState sturdyState() { - PlatformBlockState support = mock(PlatformBlockState.class); - BlockData blockData = mock(BlockData.class); - when(support.nativeHandle()).thenReturn(blockData); - when(blockData.isFaceSturdy(any(), eq(BlockSupport.FULL))).thenReturn(true); - return support; + private static BlockState vine() { + return BlockState.parse("minecraft:vine[down=false,east=false,north=false,south=false,up=false,west=false]"); + } + + private static Hunk hunk(int width, int height, int depth) { + return new ArrayHunk<>(BlockState.class, width, height, depth, AIR); + } + + private static DecorationScene scene(Hunk blocks) { + return scene(blocks, null); + } + + private static DecorationScene scene(Hunk blocks, MantleLayer planned) { + return new DecorationScene(blocks, ApiChunk.blocks(), null, planned, null, 1L, ModuleLogs.discarding()); + } + + /** Blocks planned at "x,y,z" in world coordinates; everywhere else reads none. */ + private static MantleLayer plannedLayer(Map planned) { + return new MantleLayer<>() { + @Override + public BlockState get(int x, int y, int z) { + return planned.get(x + "," + y + "," + z); + } + + @Override + public void set(int x, int y, int z, BlockState value) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove(int x, int y, int z) { + throw new UnsupportedOperationException(); + } + + @Override + public void visit(BlockBox area, MantleVisitor visitor) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear(BlockBox area) { + throw new UnsupportedOperationException(); + } + }; } } diff --git a/core/src/test/java/art/arcane/iris/engine/decorator/DecoratorTestEngines.java b/core/src/test/java/art/arcane/iris/engine/decorator/DecoratorTestEngines.java index 255b55f4c..4171ff501 100644 --- a/core/src/test/java/art/arcane/iris/engine/decorator/DecoratorTestEngines.java +++ b/core/src/test/java/art/arcane/iris/engine/decorator/DecoratorTestEngines.java @@ -21,9 +21,4 @@ public final class DecoratorTestEngines { when(engine.getGeneration()).thenReturn(generation); return generation; } - - /** Makes {@code engine} keep {@code decorators} as its world's decorators. */ - static void keepDecorators(Engine engine, BiomeDecorators decorators) { - withGeneration(engine).state(BiomeDecorators.class, ignored -> decorators); - } } diff --git a/core/src/test/java/art/arcane/iris/engine/decorator/IrisDecoratorCaveContextTest.java b/core/src/test/java/art/arcane/iris/engine/decorator/IrisDecoratorCaveContextTest.java index f5717c8af..766295cbb 100644 --- a/core/src/test/java/art/arcane/iris/engine/decorator/IrisDecoratorCaveContextTest.java +++ b/core/src/test/java/art/arcane/iris/engine/decorator/IrisDecoratorCaveContextTest.java @@ -1,34 +1,29 @@ package art.arcane.iris.engine.decorator; -import art.arcane.iris.core.loader.IrisData; -import art.arcane.iris.engine.framework.Engine; -import art.arcane.iris.engine.framework.SeedManager; -import art.arcane.iris.engine.object.world.biome.InferredType; -import art.arcane.iris.engine.object.world.biome.IrisBiome; import art.arcane.iris.builtin.decorant.DecorationPart; -import art.arcane.iris.engine.object.world.dimension.IrisDimension; -import art.arcane.iris.spi.PlatformBlockState; -import art.arcane.iris.util.project.hunk.Hunk; +import art.arcane.iris.engine.modifier.ApiChunk; +import com.volmit.block.BlockState; +import com.volmit.host.ArrayHunk; +import com.volmit.host.ModuleLogs; +import com.volmit.hunk.Hunk; +import com.volmit.world.BiomeKind; +import com.volmit.world.TerrainSampler; import org.junit.Test; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.anyDouble; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; public class IrisDecoratorCaveContextTest { + private static final int FLUID_HEIGHT = 63; + @Test - @SuppressWarnings("unchecked") - public void explicitCaveContextSkipsFluidWithoutMutatingBiome() { - Engine engine = mock(Engine.class); - SeedManager seedManager = mock(SeedManager.class); - doReturn(seedManager).when(engine).getSeedManager(); - doReturn(mock(IrisData.class)).when(engine).getData(); - IrisDimension dimension = mock(IrisDimension.class); - doReturn(63).when(dimension).getFluidHeight(); - doReturn(dimension).when(engine).getDimension(); + public void explicitCaveContextSkipsFluid() { + TerrainSampler terrain = mock(TerrainSampler.class); + doReturn(FLUID_HEIGHT).when(terrain).fluidHeight(); ResolvedDecorator decorator = mock(ResolvedDecorator.class); doReturn(true).when(decorator).passesChanceGate(anyDouble(), anyDouble()); @@ -36,35 +31,29 @@ public class IrisDecoratorCaveContextTest { doReturn(true).when(decorator).isForcePlace(); doReturn(1).when(decorator).stackHeight(anyDouble(), anyDouble()); - IrisBiome biome = mock(IrisBiome.class); - doReturn(InferredType.LAND).when(biome).getInferredType(); + DecoratedBiome cave = new DecoratedBiome("cave", null, BiomeKind.CAVE); BiomeDecorators decorators = mock(BiomeDecorators.class); - doReturn(new ResolvedDecorator[]{decorator}).when(decorators).decorators(biome, DecorationPart.NONE); - doReturn(new ResolvedDecorator[]{decorator}).when(decorators).decorators(biome, DecorationPart.CEILING); - DecoratorTestEngines.keepDecorators(engine, decorators); + doReturn(new ResolvedDecorator[]{decorator}).when(decorators).decorators(cave, DecorationPart.NONE); + doReturn(new ResolvedDecorator[]{decorator}).when(decorators).decorators(cave, DecorationPart.CEILING); - PlatformBlockState fluid = mock(PlatformBlockState.class); - doReturn(true).when(fluid).isFluid(); - Hunk output = mock(Hunk.class); - doReturn(128).when(output).getHeight(); - doReturn(fluid).when(output).get(0, 10, 0); + Hunk output = new ArrayHunk<>(BlockState.class, 1, 128, 1, new BlockState("minecraft:water")); + DecorationScene scene = new DecorationScene(output, ApiChunk.blocks(), terrain, null, decorators, 1L, ModuleLogs.discarding()); - IrisSurfaceDecorator surfaceDecorator = new IrisSurfaceDecorator(engine); - surfaceDecorator.decorate(0, 0, 0, 0, 0, 0, 0, 0, output, biome, InferredType.CAVE, 10, 10); + new IrisSurfaceDecorator(scene).decorate(0, 0, 0, 0, 0, 0, 0, 0, cave, 10, 10); DecoratorCore.PlaceOpts surfaceOptions = DecoratorCore.SCRATCH_OPTS.get(); assertTrue(surfaceOptions.caveSkipFluid); assertFalse(surfaceOptions.underwater); - IrisCeilingDecorator ceilingDecorator = new IrisCeilingDecorator(engine); - ceilingDecorator.decorate(0, 0, 0, 0, 0, 0, 0, 0, output, biome, InferredType.CAVE, 10, 10); - DecoratorCore.PlaceOpts ceilingOptions = DecoratorCore.SCRATCH_OPTS.get(); - assertTrue(ceilingOptions.caveSkipFluid); - assertEquals(InferredType.LAND, biome.getInferredType()); + new IrisCeilingDecorator(scene).decorate(0, 0, 0, 0, 0, 0, 0, 0, cave, 10, 10); + assertTrue(DecoratorCore.SCRATCH_OPTS.get().caveSkipFluid); + assertSame(BiomeKind.CAVE, cave.kind()); } @Test - public void nullInferenceRemainsSafeForNormalSurfaceContext() { - assertTrue(IrisSurfaceDecorator.isUnderwater(null, 10, 63)); - assertFalse(IrisSurfaceDecorator.skipsFluid(null)); + public void aSurfaceBiomeIsUnderwaterBelowTheFluidAndNeverSkipsFluid() { + assertTrue(IrisSurfaceDecorator.isUnderwater(BiomeKind.LAND, 10, FLUID_HEIGHT)); + assertFalse(IrisSurfaceDecorator.isUnderwater(BiomeKind.CAVE, 10, FLUID_HEIGHT)); + assertFalse(IrisSurfaceDecorator.skipsFluid(BiomeKind.SEA)); + assertTrue(IrisSurfaceDecorator.skipsFluid(BiomeKind.CAVE)); } } diff --git a/core/src/test/java/art/arcane/iris/engine/decorator/IrisShoreLineDecoratorTest.java b/core/src/test/java/art/arcane/iris/engine/decorator/IrisShoreLineDecoratorTest.java index 9ae129e25..2716c10d8 100644 --- a/core/src/test/java/art/arcane/iris/engine/decorator/IrisShoreLineDecoratorTest.java +++ b/core/src/test/java/art/arcane/iris/engine/decorator/IrisShoreLineDecoratorTest.java @@ -1,23 +1,18 @@ package art.arcane.iris.engine.decorator; -import art.arcane.iris.core.loader.IrisData; -import art.arcane.iris.engine.IrisComplex; -import art.arcane.iris.engine.framework.Engine; -import art.arcane.iris.engine.framework.SeedManager; -import art.arcane.iris.engine.object.world.biome.IrisBiome; import art.arcane.iris.builtin.decorant.DecorationPart; -import art.arcane.iris.engine.object.world.dimension.IrisDimension; -import art.arcane.iris.spi.PlatformBlockState; -import art.arcane.iris.util.project.hunk.Hunk; -import art.arcane.iris.util.project.stream.ProceduralStream; -import org.bukkit.block.BlockSupport; -import org.bukkit.block.data.BlockData; +import art.arcane.iris.engine.modifier.ApiChunk; +import com.volmit.block.BlockState; +import com.volmit.host.ArrayHunk; +import com.volmit.host.ModuleLogs; +import com.volmit.hunk.Hunk; +import com.volmit.world.BiomeKind; +import com.volmit.world.TerrainSampler; import org.junit.Test; import static org.junit.Assert.assertSame; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyDouble; -import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; @@ -25,123 +20,75 @@ import static org.mockito.Mockito.when; public class IrisShoreLineDecoratorTest { private static final int FLUID_HEIGHT = 4; + private static final BlockState AIR = ApiChunk.AIR; + private static final BlockState GRASS_BLOCK = new BlockState("minecraft:grass_block"); + private static final BlockState WATER = new BlockState("minecraft:water"); + private static final BlockState POPPY = new BlockState("minecraft:poppy"); + private static final DecoratedBiome BIOME = new DecoratedBiome("shore", null, BiomeKind.SHORE); @Test public void carvedSurfaceRejectsShorelineDecoration() { Fixture fixture = createFixture(false); - PlatformBlockState carvedAir = airState(); - PlatformBlockState targetAir = airState(); - Hunk output = output(carvedAir, targetAir); + Hunk output = fixture.withSupport(AIR); - fixture.shoreline.decorate(0, 0, 0, 1, -1, 0, 1, -1, - output, fixture.biome, FLUID_HEIGHT, output.getHeight()); + fixture.shoreline.decorate(0, 0, 0, 1, -1, 0, 1, -1, BIOME, FLUID_HEIGHT, output.getHeight()); - assertSame(targetAir, output.get(0, FLUID_HEIGHT + 1, 0)); + assertSame(AIR, output.get(0, FLUID_HEIGHT + 1, 0)); verify(fixture.decorator).passesChanceGate(anyDouble(), anyDouble()); - verify(fixture.decorator, never()).blockAt(eq(fixture.biome), anyDouble(), anyDouble(), anyDouble()); + verify(fixture.decorator, never()).blockAt(anyDouble(), anyDouble(), anyDouble()); } @Test public void preservedFluidRejectsShorelineDecoration() { Fixture fixture = createFixture(false); - PlatformBlockState fluid = mock(PlatformBlockState.class); - PlatformBlockState targetAir = airState(); - when(fluid.isFluid()).thenReturn(true); - Hunk output = output(fluid, targetAir); + Hunk output = fixture.withSupport(WATER); - fixture.shoreline.decorate(0, 0, 0, 1, -1, 0, 1, -1, - output, fixture.biome, FLUID_HEIGHT, output.getHeight()); + fixture.shoreline.decorate(0, 0, 0, 1, -1, 0, 1, -1, BIOME, FLUID_HEIGHT, output.getHeight()); - assertSame(targetAir, output.get(0, FLUID_HEIGHT + 1, 0)); - verify(fixture.decorator, never()).blockAt(eq(fixture.biome), anyDouble(), anyDouble(), anyDouble()); + assertSame(AIR, output.get(0, FLUID_HEIGHT + 1, 0)); + verify(fixture.decorator, never()).blockAt(anyDouble(), anyDouble(), anyDouble()); } @Test public void sturdySurfacePlacesShorelineDecoration() { Fixture fixture = createFixture(false); - PlatformBlockState support = sturdyState(); - PlatformBlockState targetAir = airState(); - when(fixture.decorant.canPlaceOnto(support)).thenReturn(true); - Hunk output = output(support, targetAir); + Hunk output = fixture.withSupport(GRASS_BLOCK); - fixture.shoreline.decorate(0, 0, 0, 1, -1, 0, 1, -1, - output, fixture.biome, FLUID_HEIGHT, output.getHeight()); + fixture.shoreline.decorate(0, 0, 0, 1, -1, 0, 1, -1, BIOME, FLUID_HEIGHT, output.getHeight()); - assertSame(fixture.decorant, output.get(0, FLUID_HEIGHT + 1, 0)); + assertSame(POPPY, output.get(0, FLUID_HEIGHT + 1, 0)); } @Test public void forcePlaceStillRejectsMissingSurface() { Fixture fixture = createFixture(true); - PlatformBlockState targetAir = airState(); - Hunk output = output(airState(), targetAir); + Hunk output = fixture.withSupport(AIR); - fixture.shoreline.decorate(0, 0, 0, 1, -1, 0, 1, -1, - output, fixture.biome, FLUID_HEIGHT, output.getHeight()); + fixture.shoreline.decorate(0, 0, 0, 1, -1, 0, 1, -1, BIOME, FLUID_HEIGHT, output.getHeight()); - assertSame(targetAir, output.get(0, FLUID_HEIGHT + 1, 0)); + assertSame(AIR, output.get(0, FLUID_HEIGHT + 1, 0)); } - @SuppressWarnings("unchecked") private Fixture createFixture(boolean forcePlace) { - Engine engine = mock(Engine.class); - SeedManager seedManager = mock(SeedManager.class); - IrisDimension dimension = mock(IrisDimension.class); - IrisComplex complex = mock(IrisComplex.class); - IrisData data = mock(IrisData.class); - IrisBiome biome = mock(IrisBiome.class); + TerrainSampler terrain = mock(TerrainSampler.class); + when(terrain.fluidHeight()).thenReturn(FLUID_HEIGHT); + when(terrain.surfaceY(anyInt(), anyInt())).thenReturn((double) FLUID_HEIGHT - 1); ResolvedDecorator decorator = mock(ResolvedDecorator.class); BiomeDecorators decorators = mock(BiomeDecorators.class); - PlatformBlockState decorant = mock(PlatformBlockState.class); - ProceduralStream heightStream = mock(ProceduralStream.class); - - when(engine.getCacheID()).thenReturn(1); - when(engine.getSeedManager()).thenReturn(seedManager); - when(seedManager.getComponent()).thenReturn(17L); - when(engine.getDimension()).thenReturn(dimension); - when(dimension.getFluidHeight()).thenReturn(FLUID_HEIGHT); - when(engine.getComplex()).thenReturn(complex); - when(complex.getFluidHeight()).thenReturn((double) FLUID_HEIGHT); - when(complex.getHeightStream()).thenReturn(heightStream); - when(heightStream.get(anyDouble(), anyDouble())).thenReturn((double) FLUID_HEIGHT - 1); - when(engine.getData()).thenReturn(data); - when(decorators.decorators(biome, DecorationPart.SHORE_LINE)).thenReturn(new ResolvedDecorator[]{decorator}); + when(decorators.decorators(BIOME, DecorationPart.SHORE_LINE)).thenReturn(new ResolvedDecorator[]{decorator}); when(decorator.passesChanceGate(anyDouble(), anyDouble())).thenReturn(true); when(decorator.isForcePlace()).thenReturn(forcePlace); - when(decorator.blockAt(eq(biome), anyDouble(), anyDouble(), anyDouble())).thenReturn(decorant); - DecoratorTestEngines.keepDecorators(engine, decorators); - - return new Fixture(new IrisShoreLineDecorator(engine), data, biome, decorator, decorant); + when(decorator.blockAt(anyDouble(), anyDouble(), anyDouble())).thenReturn(POPPY); + Hunk blocks = new ArrayHunk<>(BlockState.class, 1, FLUID_HEIGHT + 3, 1, AIR); + return new Fixture(new IrisShoreLineDecorator(new DecorationScene(blocks, ApiChunk.blocks(), terrain, null, decorators, 17L, + ModuleLogs.discarding())), decorator, blocks); } - private Hunk output(PlatformBlockState support, PlatformBlockState target) { - Hunk output = Hunk.newArrayHunk(1, FLUID_HEIGHT + 3, 1); - output.set(0, FLUID_HEIGHT, 0, support); - output.set(0, FLUID_HEIGHT + 1, 0, target); - return output; - } - - private PlatformBlockState airState() { - PlatformBlockState air = mock(PlatformBlockState.class); - when(air.isAir()).thenReturn(true); - return air; - } - - private PlatformBlockState sturdyState() { - PlatformBlockState support = mock(PlatformBlockState.class); - BlockData blockData = mock(BlockData.class); - when(support.isSolid()).thenReturn(true); - when(support.nativeHandle()).thenReturn(blockData); - when(blockData.isFaceSturdy(any(), eq(BlockSupport.FULL))).thenReturn(true); - return support; - } - - private record Fixture( - IrisShoreLineDecorator shoreline, - IrisData data, - IrisBiome biome, - ResolvedDecorator decorator, - PlatformBlockState decorant - ) { + private record Fixture(IrisShoreLineDecorator shoreline, ResolvedDecorator decorator, Hunk blocks) { + /** The blocks with {@code support} at the fluid height, where the shoreline decorates from. */ + Hunk withSupport(BlockState support) { + blocks.set(0, FLUID_HEIGHT, 0, support); + return blocks; + } } } diff --git a/core/src/test/java/art/arcane/iris/engine/decorator/ResolvedDecoratorTest.java b/core/src/test/java/art/arcane/iris/engine/decorator/ResolvedDecoratorTest.java index 44eb89c21..3313d4a4d 100644 --- a/core/src/test/java/art/arcane/iris/engine/decorator/ResolvedDecoratorTest.java +++ b/core/src/test/java/art/arcane/iris/engine/decorator/ResolvedDecoratorTest.java @@ -5,11 +5,10 @@ import art.arcane.iris.core.loader.IrisData; import art.arcane.iris.core.loader.ResourceLoader; import art.arcane.iris.core.modules.IrisPackResources; import art.arcane.iris.engine.UsableBlockPlatform; -import art.arcane.iris.engine.framework.Engine; +import art.arcane.iris.engine.modifier.ApiChunk; import art.arcane.iris.engine.object.material.IrisBlockData; -import art.arcane.iris.engine.object.world.biome.IrisBiome; -import art.arcane.iris.spi.PlatformBlockState; import com.google.gson.Gson; +import com.volmit.block.BlockState; import com.volmit.host.ModuleLogs; import com.volmit.noise.NoiseFactory; import com.volmit.noise.NoiseSampler; @@ -50,19 +49,16 @@ public class ResolvedDecoratorTest { public void everyDecoratorPicksAsIrisDecoratorDid() { UsableBlockPlatform.bind(); IrisData data = data(); - Engine engine = engine(data); - IrisBiome biome = mock(IrisBiome.class); - when(biome.getName()).thenReturn("test"); Gson gson = new Gson(); StringBuilder transcript = new StringBuilder(); for (String json : DECORATORS) { - ResolvedDecorator resolved = ResolvedDecorator.of(gson.fromJson(json, Decorator.class), engine, SEED, ModuleLogs.discarding()); + ResolvedDecorator resolved = ResolvedDecorator.of(gson.fromJson(json, Decorator.class), data.getPackResources(), SEED, ModuleLogs.discarding(), "test"); for (int x = -40; x < 40; x += 3) { for (int z = -40; z < 40; z += 5) { transcript.append(resolved.passesChanceGate(x, z)).append(resolved.stackHeight(x, z)).append(key(resolved.pickBlock(x, z))) .append(key(resolved.pickTopBlock(x, z))); for (int y = 60; y < 66; y += 2) { - transcript.append(key(resolved.blockAt(biome, x, y, z))).append(key(resolved.topBlockAt(biome, x, y, z))); + transcript.append(key(resolved.blockAt(x, y, z))).append(key(resolved.topBlockAt(x, y, z))); } } } @@ -83,7 +79,7 @@ public class ResolvedDecoratorTest { }; Decorator decorator = new Gson().fromJson("{\"style\": {\"style\": \"SIMPLEX\"}, \"variance\": {\"style\": \"PERLIN\"}, \"heightVariance\": {\"style\": \"CLOVER\"}," + "\"stackMin\": 2, \"stackMax\": 7}", Decorator.class); - ResolvedDecorator resolved = new ResolvedDecorator(decorator, SEED, recording, state("a", "b", "b"), List.of(), null, List.of(), List.of(), ModuleLogs.discarding()); + ResolvedDecorator resolved = new ResolvedDecorator(decorator, SEED, recording, state("a", "b", "b"), List.of(), null, List.of(), List.of(), ModuleLogs.discarding(), "test"); resolved.warm(); @@ -95,7 +91,7 @@ public class ResolvedDecoratorTest { NoiseFactory refusing = (style, seed) -> { throw new IllegalStateException("no noise"); }; - ResolvedDecorator single = new ResolvedDecorator(new Decorator(), SEED, refusing, state("a"), List.of(), null, List.of(), List.of(), ModuleLogs.discarding()); + ResolvedDecorator single = new ResolvedDecorator(new Decorator(), SEED, refusing, state("a"), List.of(), null, List.of(), List.of(), ModuleLogs.discarding(), "test"); assertEquals("a one block palette never needs its variance noise", "minecraft:a", single.pickBlock(1, 2).key()); assertEquals("equal limits never need the height noise", 1, single.stackHeight(1, 2)); @@ -105,8 +101,8 @@ public class ResolvedDecoratorTest { @Test public void stackHeightFollowsTheHeightNoiseBetweenTheLimits() { Decorator decorator = new Gson().fromJson("{\"stackMin\": 1, \"stackMax\": 2}", Decorator.class); - ResolvedDecorator top = new ResolvedDecorator(decorator, SEED, (style, seed) -> constant(1.0), state("a"), List.of(), null, List.of(), List.of(), ModuleLogs.discarding()); - ResolvedDecorator bottom = new ResolvedDecorator(decorator, SEED, (style, seed) -> constant(0.0), state("a"), List.of(), null, List.of(), List.of(), ModuleLogs.discarding()); + ResolvedDecorator top = new ResolvedDecorator(decorator, SEED, (style, seed) -> constant(1.0), state("a"), List.of(), null, List.of(), List.of(), ModuleLogs.discarding(), "test"); + ResolvedDecorator bottom = new ResolvedDecorator(decorator, SEED, (style, seed) -> constant(0.0), state("a"), List.of(), null, List.of(), List.of(), ModuleLogs.discarding(), "test"); assertEquals(2, top.stackHeight(0, 0)); assertEquals(1, bottom.stackHeight(0, 0)); @@ -114,12 +110,12 @@ public class ResolvedDecoratorTest { @Test public void whiteAndBlackListsKeepTheDecoratorOffSurfaces() { - PlatformBlockState sand = state("sand").get(0); - PlatformBlockState stone = state("stone").get(0); + BlockState sand = state("sand").get(0); + BlockState stone = state("stone").get(0); Decorator listed = new Gson().fromJson("{\"whitelist\": [{\"block\": \"sand\"}], \"blacklist\": [{\"block\": \"stone\"}]}", Decorator.class); ResolvedDecorator resolved = new ResolvedDecorator(listed, SEED, (style, seed) -> constant(0), state("a"), List.of(), - null, List.of(sand), List.of(stone), ModuleLogs.discarding()); - ResolvedDecorator unlisted = new ResolvedDecorator(new Decorator(), SEED, (style, seed) -> constant(0), state("a"), List.of(), null, List.of(), List.of(), ModuleLogs.discarding()); + null, List.of(sand), List.of(stone), ModuleLogs.discarding(), "test"); + ResolvedDecorator unlisted = new ResolvedDecorator(new Decorator(), SEED, (style, seed) -> constant(0), state("a"), List.of(), null, List.of(), List.of(), ModuleLogs.discarding(), "test"); assertFalse(resolved.rejectsSurface(sand)); assertTrue(resolved.rejectsSurface(stone)); @@ -131,9 +127,9 @@ public class ResolvedDecoratorTest { public void onlyASlopeOutsideTheLimitsBlocksAndOnlyWhenTheDecoratorLimitsIt() { Decorator limited = new Gson().fromJson("{\"slopeCondition\": {\"maximumSlope\": 4}}", Decorator.class); Decorator forced = new Gson().fromJson("{\"forcePlace\": true, \"slopeCondition\": {\"maximumSlope\": 4}}", Decorator.class); - ResolvedDecorator resolvedLimited = new ResolvedDecorator(limited, SEED, (style, seed) -> constant(0), state("a"), List.of(), null, List.of(), List.of(), ModuleLogs.discarding()); - ResolvedDecorator resolvedForced = new ResolvedDecorator(forced, SEED, (style, seed) -> constant(0), state("a"), List.of(), null, List.of(), List.of(), ModuleLogs.discarding()); - ResolvedDecorator resolvedDefault = new ResolvedDecorator(new Decorator(), SEED, (style, seed) -> constant(0), state("a"), List.of(), null, List.of(), List.of(), ModuleLogs.discarding()); + ResolvedDecorator resolvedLimited = new ResolvedDecorator(limited, SEED, (style, seed) -> constant(0), state("a"), List.of(), null, List.of(), List.of(), ModuleLogs.discarding(), "test"); + ResolvedDecorator resolvedForced = new ResolvedDecorator(forced, SEED, (style, seed) -> constant(0), state("a"), List.of(), null, List.of(), List.of(), ModuleLogs.discarding(), "test"); + ResolvedDecorator resolvedDefault = new ResolvedDecorator(new Decorator(), SEED, (style, seed) -> constant(0), state("a"), List.of(), null, List.of(), List.of(), ModuleLogs.discarding(), "test"); assertTrue(resolvedLimited.slopeBlocks(() -> 5)); assertFalse(resolvedLimited.slopeBlocks(() -> 3)); @@ -143,11 +139,10 @@ public class ResolvedDecoratorTest { })); } - private static List state(String... keys) { - UsableBlockPlatform.bind(); - List states = new ArrayList<>(); + private static List state(String... keys) { + List states = new ArrayList<>(); for (String key : keys) { - states.add(UsableBlockPlatform.block(key)); + states.add(ApiChunk.blocks().resolve(key)); } return states; } @@ -166,7 +161,7 @@ public class ResolvedDecoratorTest { }; } - private static String key(PlatformBlockState state) { + private static String key(BlockState state) { return state == null ? null : state.key(); } @@ -180,10 +175,4 @@ public class ResolvedDecoratorTest { when(data.getPackResources()).thenReturn(resources); return data; } - - private static Engine engine(IrisData data) { - Engine engine = mock(Engine.class); - when(engine.getData()).thenReturn(data); - return engine; - } } diff --git a/core/src/test/java/art/arcane/iris/engine/modifier/ApiChunk.java b/core/src/test/java/art/arcane/iris/engine/modifier/ApiChunk.java index 6bdb7a5c1..9dda26951 100644 --- a/core/src/test/java/art/arcane/iris/engine/modifier/ApiChunk.java +++ b/core/src/test/java/art/arcane/iris/engine/modifier/ApiChunk.java @@ -58,6 +58,7 @@ import com.volmit.mantle.MantleKey; import com.volmit.mantle.MantleLayer; import com.volmit.mantle.MantleVisitor; import com.volmit.noise.NoiseFactory; +import com.volmit.noise.NoiseSampler; import com.volmit.object.BlockEntityData; import com.volmit.resource.PackResources; import com.volmit.resource.ResourceId; @@ -95,6 +96,8 @@ public final class ApiChunk implements GenerationContext { public static final int WIDTH = 16; public static final BlockState AIR = new BlockState("minecraft:air"); private static final long SEED = 1337L; + /** What every noise of the fixture's pack samples, everywhere. */ + private static final double HALF = 0.5; /** A key that the fixture's pack has no block for. */ public static final String UNKNOWN_BLOCK = "unknown_block"; private static final ResourceId DIMENSION = ResourceId.parse("test:dimension/overworld"); @@ -571,7 +574,17 @@ public final class ApiChunk implements GenerationContext { @Override public NoiseFactory noise() { - throw new UnsupportedOperationException("No noise here"); + return (style, seed) -> new NoiseSampler() { + @Override + public double sample(double worldX, double worldZ) { + return HALF; + } + + @Override + public double sample(double worldX, double y, double worldZ) { + return HALF; + } + }; } @Override diff --git a/core/src/test/java/art/arcane/iris/engine/modifier/FloatingIslandsTest.java b/core/src/test/java/art/arcane/iris/engine/modifier/FloatingIslandsTest.java index 5dc8ffd12..33c6d4471 100644 --- a/core/src/test/java/art/arcane/iris/engine/modifier/FloatingIslandsTest.java +++ b/core/src/test/java/art/arcane/iris/engine/modifier/FloatingIslandsTest.java @@ -39,7 +39,7 @@ public class FloatingIslandsTest { when(output.getHeight()).thenReturn(64); islands.fillSolids(CHUNK_ORIGIN, CHUNK_ORIGIN, output, false, context); - islands.decorateColumns(CHUNK_ORIGIN, CHUNK_ORIGIN, output, false, context); + islands.decorateColumns(CHUNK_ORIGIN, CHUNK_ORIGIN, output, false, context, null); verify(sampler, times(2)).parent(CHUNK_ORIGIN + 15, CHUNK_ORIGIN + 15); verify(output, never()).set(anyInt(), anyInt(), anyInt(), any()); diff --git a/core/src/test/java/art/arcane/iris/engine/modifier/ResolvedDepositVariantTest.java b/core/src/test/java/art/arcane/iris/engine/modifier/ResolvedDepositVariantTest.java index 0e6c81d6d..ef8b0bedd 100644 --- a/core/src/test/java/art/arcane/iris/engine/modifier/ResolvedDepositVariantTest.java +++ b/core/src/test/java/art/arcane/iris/engine/modifier/ResolvedDepositVariantTest.java @@ -5,6 +5,8 @@ import com.google.gson.Gson; import com.volmit.ModuleLog; import com.volmit.block.BlockState; import com.volmit.host.ModuleLogs; +import art.arcane.iris.engine.UsableBlockPlatform; +import org.junit.After; import org.junit.Test; import static org.junit.Assert.assertEquals; @@ -18,6 +20,12 @@ public class ResolvedDepositVariantTest { """; private static final ModuleLog LOG = ModuleLogs.discarding(); + /** Other tests bind a platform and leave B's cached registries behind; the tests that run after this class bind their own. */ + @After + public void forgetCachedPlatform() { + UsableBlockPlatform.unbind(); + } + private static ResolvedDepositVariant variant(String json) { return new ResolvedDepositVariant(new Gson().fromJson(json, DepositVariant.class), ApiChunk.blocks(), LOG); }