mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 00:04:42 +00:00
VanillaStructures service replaces the vanilla structure hook; fit values leave the API
The hook's rule, starts and setup move to a @Service(ALL) VanillaStructures with default methods. adjustment and the fit value types (VanillaStructureAdjustment, VanillaStructureFit, StructureTerrain, StructureStilts, YBand) are gone: modules keep their fit vocabulary as settings. New neutral questions: shift (vertical move of a platform start), reach (how far around its pieces a module changes terrain for a start), beforePieces/afterPieces around the platform placing a chunk's starts. StructureFit hands a module the chunk's starts (pieces, junctions, processed template cells, template columns, legacy template air, platform terrain adaptation and step, the start's memo), the chunk's live blocks as a BlockAccess, the surface heights and the platform's natural block. VanillaStructureStart carries a StartMemo instead of a fit; the host keeps it with the start's ownership record.
This commit is contained in:
1 parent
b82c292dcb
commit
ee7bb11790
25 files changed
+555
-715
No files matched your search
@@ -1,19 +1,18 @@
|
||||
package com.volmit;
|
||||
|
||||
import com.volmit.block.BlockSpec;
|
||||
import com.volmit.block.PaletteSpec;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.config.OptionsMetadata;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.service.VanillaStructures;
|
||||
import com.volmit.vanilla.JigsawOverrides;
|
||||
import com.volmit.vanilla.StructureStilts;
|
||||
import com.volmit.vanilla.StructureTerrain;
|
||||
import com.volmit.vanilla.VanillaStructureAdjustment;
|
||||
import com.volmit.vanilla.VanillaStructureFit;
|
||||
import com.volmit.vanilla.VanillaStructureHook;
|
||||
import com.volmit.vanilla.StartMemo;
|
||||
import com.volmit.vanilla.StartReach;
|
||||
import com.volmit.vanilla.StructureStep;
|
||||
import com.volmit.vanilla.TemplateCells;
|
||||
import com.volmit.vanilla.VanillaStructureContext;
|
||||
import com.volmit.vanilla.VanillaStructureRule;
|
||||
import com.volmit.vanilla.VanillaStructureSetup;
|
||||
import com.volmit.vanilla.VanillaStructureStart;
|
||||
import com.volmit.vanilla.YBand;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -21,45 +20,18 @@ import java.util.Optional;
|
||||
import java.util.OptionalInt;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/** The values a vanilla structure hook answers with and how the host combines several modules' answers. */
|
||||
/** The values a vanilla structures provider answers with and how the host combines several modules' answers. */
|
||||
class VanillaStructureValuesTest {
|
||||
private static final ResourceId VILLAGES = ResourceId.parse("minecraft:villages");
|
||||
private static final ResourceId CITY = ResourceId.parse("minecraft:ancient_city");
|
||||
|
||||
@Test
|
||||
void fitValuesKeepThePacksJsonNamesAndDefaults() {
|
||||
assertEquals(List.of("mode", "horizontalPadding", "ceilingPadding", "floorPadding", "shape", "encasePalette",
|
||||
"erosionStrength", "erosionFrequency", "lobeFrequency", "lobeStrength"), names(StructureTerrain.class));
|
||||
assertEquals(List.of("maxDepth", "palette", "spacing", "supportNonOccluding"), names(StructureStilts.class));
|
||||
assertEquals(List.of("min", "max"), names(YBand.class));
|
||||
void jigsawOverridesKeepThePacksJsonNamesAndDefaults() {
|
||||
assertEquals(List.of("startPool", "startJigsawName", "maxDepth", "maxDistanceHorizontal", "maxDistanceVertical",
|
||||
"useExpansionHack", "projectStartToHeightmap", "dimensionPaddingBottom", "dimensionPaddingTop",
|
||||
"liquidSettings"), names(JigsawOverrides.class));
|
||||
|
||||
var terrain = StructureTerrain.of(StructureTerrain.Mode.FORCE_CARVE);
|
||||
assertEquals(StructureTerrain.Shape.BOX, terrain.shape());
|
||||
assertEquals(0.8, terrain.erosionStrength());
|
||||
assertEquals(0.07, terrain.erosionFrequency());
|
||||
assertEquals(Optional.empty(), terrain.encasePalette());
|
||||
var stilts = StructureStilts.of(PaletteSpec.of(List.of(BlockSpec.of("minecraft:cobblestone"))));
|
||||
assertEquals(64, stilts.maxDepth());
|
||||
assertEquals(1, stilts.spacing());
|
||||
assertEquals(OptionalInt.empty(), JigsawOverrides.none().maxDepth());
|
||||
assertEquals(JigsawOverrides.Heightmap.SOURCE, JigsawOverrides.none().projectStartToHeightmap());
|
||||
}
|
||||
|
||||
@Test
|
||||
void fitValuesAreValuesChangedOnlyThroughWithers() {
|
||||
var carve = StructureTerrain.of(StructureTerrain.Mode.FORCE_CARVE).withPadding(4, 2, 1)
|
||||
.withShape(StructureTerrain.Shape.ERODED).withErosion(0.5, 0.1).withLobes(0.2, 0.4);
|
||||
|
||||
assertEquals(carve, StructureTerrain.of(StructureTerrain.Mode.FORCE_CARVE).withShape(StructureTerrain.Shape.ERODED)
|
||||
.withLobes(0.2, 0.4).withErosion(0.5, 0.1).withPadding(4, 2, 1));
|
||||
assertEquals(4, carve.horizontalPadding());
|
||||
assertEquals(0.4, carve.lobeStrength());
|
||||
assertNotEquals(carve, carve.withPadding(4, 2, 0));
|
||||
assertEquals(YBand.of(-20, -120), YBand.of(-120, -20), "reversed bounds are the same band");
|
||||
assertEquals(-120, YBand.of(-20, -120).lowest());
|
||||
var overrides = JigsawOverrides.none().withStartPool("minecraft:village/plains/town_centers").withMaxDepth(4)
|
||||
.withMaxDistance(80, 120).withHeightmap(JigsawOverrides.Heightmap.NONE);
|
||||
assertEquals(OptionalInt.of(4), overrides.maxDepth());
|
||||
@@ -69,22 +41,36 @@ class VanillaStructureValuesTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void adjustmentsAddShiftsAndLetTheLaterBandAndFitPartsWin() {
|
||||
var stilts = StructureStilts.of(PaletteSpec.of(List.of(BlockSpec.of("stone"))));
|
||||
var carve = StructureTerrain.of(StructureTerrain.Mode.BORE);
|
||||
var first = VanillaStructureAdjustment.NONE.shifted(-32).withYBand(YBand.of(-60, -20))
|
||||
.withFit(VanillaStructureFit.SOURCE.withStilts(stilts));
|
||||
var second = VanillaStructureAdjustment.NONE.shifted(8).keepingSourceY()
|
||||
.withFit(VanillaStructureFit.SOURCE.withTerrain(carve));
|
||||
void reachesAreThePlatformsOrANumberOfBlocks() {
|
||||
assertTrue(StartReach.PLATFORM.platform());
|
||||
assertEquals(StartReach.blocks(0), StartReach.blocks(0));
|
||||
assertFalse(StartReach.blocks(12).platform());
|
||||
assertEquals(12, StartReach.blocks(12).blocks());
|
||||
assertThrows(IllegalArgumentException.class, () -> StartReach.blocks(-1));
|
||||
assertThrows(IllegalArgumentException.class, () -> new StartReach(true, 3));
|
||||
}
|
||||
|
||||
var combined = first.then(second);
|
||||
@Test
|
||||
void templateCellsKeepTheirCellsAndMarkRemovedBlocks() {
|
||||
var stone = new BlockState("minecraft:stone");
|
||||
var cells = TemplateCells.of(new int[]{1, 2}, new int[]{60, 61}, new int[]{-3, -4}, new BlockState[]{stone, null}, 7);
|
||||
|
||||
assertEquals(-24, combined.yShift());
|
||||
assertEquals(Optional.of(YBand.of(-60, -20)), combined.yBand(), "the later adjustment has no band");
|
||||
assertTrue(combined.keepsSourceY());
|
||||
assertEquals(VanillaStructureFit.SOURCE.withStilts(stilts).withTerrain(carve), combined.fit());
|
||||
assertEquals(Optional.of(YBand.of(0, 10)), combined.then(VanillaStructureAdjustment.NONE.withYBand(YBand.of(0, 10))).yBand());
|
||||
assertEquals(first, first.then(VanillaStructureAdjustment.NONE), "NONE changes nothing");
|
||||
assertTrue(cells.resolved());
|
||||
assertEquals(2, cells.size());
|
||||
assertEquals(7, cells.readBlocks());
|
||||
assertEquals(61, cells.y(1));
|
||||
assertSame(stone, cells.state(0));
|
||||
assertTrue(cells.removed(1));
|
||||
assertFalse(TemplateCells.UNRESOLVED.resolved());
|
||||
assertEquals(0, TemplateCells.UNRESOLVED.size());
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> TemplateCells.of(new int[]{1}, new int[0], new int[]{1}, new BlockState[]{stone}, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
void onlyTheUndergroundStepsAreUnderground() {
|
||||
assertEquals(List.of(StructureStep.UNDERGROUND_STRUCTURES, StructureStep.STRONGHOLDS, StructureStep.UNDERGROUND_DECORATION),
|
||||
java.util.Arrays.stream(StructureStep.values()).filter(StructureStep::isUnderground).toList());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -101,12 +87,15 @@ class VanillaStructureValuesTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void startsSitOnTheSurfaceWithTheStructuresOwnFitUnlessTheModuleSaysOtherwise() {
|
||||
void startsSitOnTheSurfaceWithoutAMemoUnlessTheModuleSaysOtherwise() {
|
||||
var start = VanillaStructureStart.at(CITY, 12, -7, 40);
|
||||
|
||||
assertFalse(start.isUnderground());
|
||||
assertFalse(start.replacesPlatformStart());
|
||||
assertEquals(VanillaStructureFit.SOURCE, start.fit());
|
||||
assertEquals(Optional.empty(), start.memo());
|
||||
var memo = new StartMemo("{\"mode\":\"VACUUM\"}", "null");
|
||||
assertEquals(Optional.of(memo), start.withMemo(memo).memo());
|
||||
assertNotEquals(start, start.withMemo(memo));
|
||||
assertEquals(Optional.empty(), start.jigsaw());
|
||||
var underground = start.underground().replacingPlatformStart().withIdentity(-5L)
|
||||
.withJigsaw(JigsawOverrides.none().withMaxDepth(3));
|
||||
@@ -119,12 +108,20 @@ class VanillaStructureValuesTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void aHookThatOnlyRulesChangesNothingElse() {
|
||||
VanillaStructureHook hook = (structure, context) -> VanillaStructureRule.BLOCK;
|
||||
void aProviderThatOnlyRulesChangesNothingElse() {
|
||||
VanillaStructures provider = new VanillaStructures() {
|
||||
@Override
|
||||
public VanillaStructureRule rule(ResourceId structure, VanillaStructureContext context) {
|
||||
return VanillaStructureRule.BLOCK;
|
||||
}
|
||||
};
|
||||
|
||||
assertEquals(VanillaStructureAdjustment.NONE, hook.adjustment(CITY, true, null));
|
||||
assertEquals(List.of(), hook.starts(0, 0, null));
|
||||
assertEquals(VanillaStructureSetup.UNCHANGED, hook.setup(null));
|
||||
assertEquals(VanillaStructureRule.BLOCK, provider.rule(CITY, null));
|
||||
assertEquals(List.of(), provider.starts(0, 0, null));
|
||||
assertEquals(0, provider.shift(null, null));
|
||||
assertEquals(StartReach.PLATFORM, provider.reach(CITY, true, Optional.empty(), null));
|
||||
assertEquals(VanillaStructureSetup.UNCHANGED, provider.setup(null));
|
||||
assertEquals(VanillaStructureRule.GENERATE, new VanillaStructures() { }.rule(CITY, null));
|
||||
}
|
||||
|
||||
private static List<String> names(Class<?> type) {
|
||||
|
||||
@@ -7,8 +7,7 @@ import com.volmit.resource.ResourceKind;
|
||||
import com.volmit.service.Providers;
|
||||
import com.volmit.service.Service;
|
||||
import com.volmit.validation.Validator;
|
||||
import com.volmit.vanilla.VanillaStructureHook;
|
||||
import com.volmit.vanilla.VanillaStructureRule;
|
||||
import com.volmit.service.VanillaStructures;
|
||||
import com.volmit.stage.PlacementStage;
|
||||
import com.volmit.stage.Stage;
|
||||
import com.volmit.stage.StageGraph;
|
||||
@@ -429,22 +428,14 @@ class ModuleRegistryTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void vanillaStructureHooksAreCataloguedByModuleIdInTheOrderEachModuleRegisteredThem() {
|
||||
void vanillaStructuresAreAServiceEveryModuleMayProvide() {
|
||||
var registry = new ModuleRegistry();
|
||||
VanillaStructureHook first = (structure, world) -> VanillaStructureRule.REPLACE;
|
||||
VanillaStructureHook second = (structure, world) -> VanillaStructureRule.GENERATE;
|
||||
VanillaStructureHook other = (structure, world) -> VanillaStructureRule.BLOCK;
|
||||
registerAs(registry, "test:zeta", hooks -> hooks.registerVanillaStructureHook(other));
|
||||
registerAs(registry, "test:alpha", hooks -> {
|
||||
hooks.registerVanillaStructureHook(first);
|
||||
hooks.registerVanillaStructureHook(second);
|
||||
});
|
||||
VanillaStructures first = new VanillaStructures() { };
|
||||
VanillaStructures other = new VanillaStructures() { };
|
||||
registerAs(registry, "test:zeta", services -> services.registerService(VanillaStructures.class, other));
|
||||
registerAs(registry, "test:alpha", services -> services.registerService(VanillaStructures.class, first));
|
||||
|
||||
assertThrows(IllegalStateException.class, () -> registry.registerVanillaStructureHook(first), "outside register");
|
||||
var hooks = registry.freeze().vanillaStructureHooks();
|
||||
assertEquals(List.of(first, second, other), hooks.stream().map(VanillaStructureHookRegistration::hook).toList());
|
||||
assertEquals("test:alpha", hooks.getFirst().module().info().id().toString());
|
||||
assertThrows(IllegalStateException.class, () -> registry.registerVanillaStructureHook(first), "registration has ended");
|
||||
assertEquals(List.of(first, other), registry.freeze().services(VanillaStructures.class));
|
||||
}
|
||||
|
||||
private static MantleCodec<String> codec(int version) {
|
||||
|
||||
Reference in new issue
Block a user