mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 00:34:19 +00:00
Batch 7 stage 3: host the api object model and placement service
IrisPlacements runs the pack's placement graph for PlacementRun over a PlacerTerrain (an IObjectPlacer seen as an api PlacementTerrain) through TerrainEdit; ModuleObjectPlacement uses it for Iris's own placements. Iris offers IrisPackObjects, IrisLegacyStreams and the api block operations (rotate, merge, withProperty, matches), and IrisObject is an api PlaceableObject. IrisObjectHost, IrisObjectChunk, IrisObjectBuilder, the placement facades, the placers they used (heightmap, sink, decay, island, golden debug, cave and floating transactions) and IrisDimension.debugSmartBore are gone. Tests follow; EdgeSimplexPinTest pins the module's simplex copy.
This commit is contained in:
1 parent
e47acc847d
commit
c0ed5ed81e
96 files changed
+1487
-3709
No files matched your search
@@ -26,6 +26,8 @@ dependencies {
|
||||
testImplementation(libs.caffeine)
|
||||
testImplementation(libs.paralithic)
|
||||
testImplementation(project(':core'))
|
||||
// Iris's objects are API placeable objects, so tests that read them compile against the API too.
|
||||
testImplementation('com.volmit:iris-api')
|
||||
testImplementation(volmLibCoordinate) {
|
||||
transitive = false
|
||||
}
|
||||
|
||||
@@ -261,11 +261,6 @@ public class CommandObject implements DirectorExecutor {
|
||||
: targetEngine.getMinHeight() + targetEngine.getDimension().getFluidHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebugSmartBore() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTile(int xx, int yy, int zz, TileData tile) {
|
||||
tile.toBukkitTry(world.getBlockAt(xx, yy, zz));
|
||||
|
||||
+8
-16
@@ -18,11 +18,11 @@
|
||||
|
||||
package art.arcane.iris.modded;
|
||||
|
||||
import art.arcane.iris.builtin.prepare.ObjectRotation;
|
||||
import art.arcane.iris.engine.object.prefab.BlockStateRotation;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.volmlib.util.math.IrisBlockVector;
|
||||
import com.volmit.block.BlockTurn;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
||||
@@ -47,20 +47,12 @@ public final class ModdedStateRotator implements BlockStateRotation.StateRotator
|
||||
};
|
||||
|
||||
@Override
|
||||
public PlatformBlockState rotate(ObjectRotation rotation, PlatformBlockState state, int spinxx, int spinyy, int spinzz) {
|
||||
public PlatformBlockState rotate(BlockTurn turn, PlatformBlockState state) {
|
||||
ModdedBlockState fabric = (ModdedBlockState) state;
|
||||
BlockState d = fabric.handle();
|
||||
boolean deleted = false;
|
||||
|
||||
try {
|
||||
int spinx = (int) (90D * (Math.ceil(Math.abs((spinxx % 360D) / 90D))));
|
||||
int spiny = (int) (90D * (Math.ceil(Math.abs((spinyy % 360D) / 90D))));
|
||||
int spinz = (int) (90D * (Math.ceil(Math.abs((spinzz % 360D) / 90D))));
|
||||
|
||||
if (!rotation.canRotate()) {
|
||||
return state;
|
||||
}
|
||||
|
||||
Property<?> facing = findFacing(d);
|
||||
Property<?> rotationProperty = findRotation(d);
|
||||
Property<?> axis = findAxis(d);
|
||||
@@ -71,7 +63,7 @@ public final class ModdedStateRotator implements BlockStateRotation.StateRotator
|
||||
if (facing != null) {
|
||||
Direction f = (Direction) d.getValue(facing);
|
||||
IrisBlockVector bv = new IrisBlockVector(f.getStepX(), f.getStepY(), f.getStepZ());
|
||||
bv = rotation.rotate(bv.clone(), spinx, spiny, spinz);
|
||||
bv = BlockStateRotation.turned(turn, bv.getX(), bv.getY(), bv.getZ());
|
||||
Direction t = faceFor(bv);
|
||||
|
||||
if (facing.getPossibleValues().contains(t)) {
|
||||
@@ -84,7 +76,7 @@ public final class ModdedStateRotator implements BlockStateRotation.StateRotator
|
||||
int[] mods = ROTATION_CYCLE_MODS[segment];
|
||||
|
||||
IrisBlockVector bv = new IrisBlockVector(mods[0], 0, mods[1]);
|
||||
bv = rotation.rotate(bv.clone(), spinx, spiny, spinz);
|
||||
bv = BlockStateRotation.turned(turn, bv.getX(), bv.getY(), bv.getZ());
|
||||
int[] hex = hexMods(bv);
|
||||
|
||||
if (hex[0] == 0 && hex[1] == 0) {
|
||||
@@ -96,7 +88,7 @@ public final class ModdedStateRotator implements BlockStateRotation.StateRotator
|
||||
} else if (axis != null) {
|
||||
Direction.Axis current = (Direction.Axis) d.getValue(axis);
|
||||
IrisBlockVector bv = axisFaceVector(current);
|
||||
bv = rotation.rotate(bv.clone(), spinx, spiny, spinz);
|
||||
bv = BlockStateRotation.turned(turn, bv.getX(), bv.getY(), bv.getZ());
|
||||
Direction.Axis a = axisOf(bv);
|
||||
|
||||
if (!a.equals(current) && axis.getPossibleValues().contains(a)) {
|
||||
@@ -113,7 +105,7 @@ public final class ModdedStateRotator implements BlockStateRotation.StateRotator
|
||||
List<String> faces = new ArrayList<>();
|
||||
for (String name : trueFaces) {
|
||||
IrisBlockVector bv = faceVector(name);
|
||||
bv = rotation.rotate(bv.clone(), spinx, spiny, spinz);
|
||||
bv = BlockStateRotation.turned(turn, bv.getX(), bv.getY(), bv.getZ());
|
||||
String r = faceName(faceFor(bv));
|
||||
|
||||
if (multipleFacing.containsKey(r)) {
|
||||
@@ -134,7 +126,7 @@ public final class ModdedStateRotator implements BlockStateRotation.StateRotator
|
||||
for (String name : WALL_FACE_NAMES) {
|
||||
WallSide h = (WallSide) d.getValue(wall.get(name));
|
||||
IrisBlockVector bv = faceVector(name);
|
||||
bv = rotation.rotate(bv.clone(), spinx, spiny, spinz);
|
||||
bv = BlockStateRotation.turned(turn, bv.getX(), bv.getY(), bv.getZ());
|
||||
String r = faceName(faceFor(bv));
|
||||
if (wall.containsKey(r)) {
|
||||
heights.put(r, h);
|
||||
@@ -150,7 +142,7 @@ public final class ModdedStateRotator implements BlockStateRotation.StateRotator
|
||||
for (String name : WALL_FACE_NAMES) {
|
||||
RedstoneSide connection = (RedstoneSide) d.getValue(wire.get(name));
|
||||
IrisBlockVector bv = faceVector(name);
|
||||
bv = rotation.rotate(bv.clone(), spinx, spiny, spinz);
|
||||
bv = BlockStateRotation.turned(turn, bv.getX(), bv.getY(), bv.getZ());
|
||||
String r = faceName(faceFor(bv));
|
||||
if (wire.containsKey(r)) {
|
||||
connections.put(r, connection);
|
||||
|
||||
-5
@@ -160,11 +160,6 @@ final class ModdedObjectPlacer implements IObjectPlacer {
|
||||
: engine.getMinHeight() + engine.getDimension().getFluidHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebugSmartBore() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTile(int xx, int yy, int zz, TileData tile) {
|
||||
if (!(tile instanceof ModdedTileData moddedTile)) {
|
||||
|
||||
@@ -23,6 +23,7 @@ import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import com.volmit.IrisFeature;
|
||||
import com.volmit.config.PackSettings;
|
||||
import com.volmit.config.SettingsStack;
|
||||
import com.volmit.resource.PackResources;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -42,6 +43,11 @@ final class DimensionSettings implements PackSettings {
|
||||
this.ids = new PackResourceIds(data.getDataFolder());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackResources resources() {
|
||||
return data.getPackResources();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <F extends IrisFeature> SettingsStack<F> declared(Class<F> featureType) {
|
||||
return IrisPackSettings.declaredBy(dimension, () -> data, ids, featureType);
|
||||
|
||||
@@ -26,11 +26,15 @@ import art.arcane.iris.engine.object.prefab.TileData;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.spi.PlatformFace;
|
||||
import art.arcane.iris.util.common.data.B;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.block.BlockRegistry;
|
||||
import com.volmit.block.BlockSpec;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.block.BlockTrait;
|
||||
import com.volmit.block.BlockTurn;
|
||||
import art.arcane.iris.engine.object.material.BlockDataMergeSupport;
|
||||
import art.arcane.iris.engine.object.prefab.BlockStateRotation;
|
||||
import com.volmit.block.PaletteSampler;
|
||||
import com.volmit.block.PaletteSpec;
|
||||
import com.volmit.geometry.BlockFace;
|
||||
@@ -60,8 +64,7 @@ final class IrisBlockRegistry implements BlockRegistry {
|
||||
private final IrisPackResources resources;
|
||||
private final Map<BlockSpec, IrisBlockData> specs = new ConcurrentHashMap<>();
|
||||
/** Stages ask about every block of a chunk; the platform's state of each block is found once per snapshot. */
|
||||
private final Map<BlockState, PlatformBlockState> platformStates = new ConcurrentHashMap<>();
|
||||
private final LazyBoundedCache<SeededPalette, PaletteSampler> palettes = new LazyBoundedCache<>(PALETTE_CACHE_SIZE);
|
||||
private final Map<BlockState, PlatformBlockState> platformStates = new ConcurrentHashMap<>(); private final LazyBoundedCache<SeededPalette, PaletteSampler> palettes = new LazyBoundedCache<>(PALETTE_CACHE_SIZE);
|
||||
|
||||
/**
|
||||
* @param data the pack whose {@code blocks} folder custom blocks come from
|
||||
@@ -75,8 +78,9 @@ final class IrisBlockRegistry implements BlockRegistry {
|
||||
@Override
|
||||
public Optional<BlockState> find(String key) {
|
||||
try {
|
||||
return Optional.of(BlockState.parse(PlatformBlockStates.namespaced(platformState(key).key())));
|
||||
} catch (IllegalArgumentException unknownBlockOrProperty) {
|
||||
PlatformBlockState state = strictPlatformState(key);
|
||||
return state == null ? Optional.empty() : Optional.of(BlockState.parse(PlatformBlockStates.namespaced(state.key())));
|
||||
} catch (IllegalArgumentException unparsableKeyOrProperty) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
@@ -133,6 +137,7 @@ final class IrisBlockRegistry implements BlockRegistry {
|
||||
case DECORATION -> platform.isDecorant();
|
||||
case VINE -> platform.isVineBlock();
|
||||
case ORE -> platform.isOre();
|
||||
case STORAGE -> platform.isStorageChest();
|
||||
case CUSTOM -> platform.isCustom();
|
||||
case GRAVITY -> platform.hasGravity();
|
||||
case LOG -> platform.isLog();
|
||||
@@ -140,6 +145,32 @@ final class IrisBlockRegistry implements BlockRegistry {
|
||||
};
|
||||
}
|
||||
|
||||
/** A block that cannot face the way it is turned is dropped, as Iris drops it: it becomes air. */
|
||||
@Override
|
||||
public BlockState rotate(BlockState state, BlockTurn turn) {
|
||||
PlatformBlockState rotated = BlockStateRotation.rotate(turn, platformState(state));
|
||||
return rotated == null ? PlatformBlockStates.AIR : apiState(rotated);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState merge(BlockState base, BlockState update) {
|
||||
return apiState(BlockDataMergeSupport.merge(platformState(base), platformState(update)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState withProperty(BlockState state, String name, String value) {
|
||||
return apiState(platformState(state).withProperty(name, value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(BlockState state, BlockState pattern) {
|
||||
return platformState(state).matches(platformState(pattern));
|
||||
}
|
||||
|
||||
private static BlockState apiState(PlatformBlockState state) {
|
||||
return state == null ? PlatformBlockStates.AIR : BlockState.parse(PlatformBlockStates.namespaced(state.key()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean inTag(BlockState state, ResourceId tag) {
|
||||
return IrisPlatforms.get().registries().isInTag(platformState(state), tag.toString());
|
||||
@@ -159,14 +190,26 @@ final class IrisBlockRegistry implements BlockRegistry {
|
||||
return platformStates.computeIfAbsent(state, known -> platformState(known.key()));
|
||||
}
|
||||
|
||||
/**
|
||||
* The platform's state for {@code key}. A key the strict lookup does not know is read as Iris's placers read it
|
||||
* ({@code B.getState}), through custom-content providers and the platform's compatibility layer.
|
||||
*/
|
||||
private static PlatformBlockState platformState(String key) {
|
||||
PlatformBlockState state = IrisPlatforms.get().registries().blockOrNull(PlatformBlockStates.namespaced(key), false);
|
||||
PlatformBlockState state = strictPlatformState(key);
|
||||
if (state == null) {
|
||||
state = B.getState(key);
|
||||
}
|
||||
if (state == null) {
|
||||
throw new IllegalArgumentException("Unknown block: " + key);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
/** The platform's state for {@code key}; null when the platform has no such block. */
|
||||
private static PlatformBlockState strictPlatformState(String key) {
|
||||
return IrisPlatforms.get().registries().blockOrNull(PlatformBlockStates.namespaced(key), false);
|
||||
}
|
||||
|
||||
private record SeededPalette(PaletteSpec spec, long seed) {
|
||||
}
|
||||
}
|
||||
@@ -19,51 +19,21 @@
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.floating.FloatingHost;
|
||||
import art.arcane.iris.builtin.floating.IslandAnchor;
|
||||
import art.arcane.iris.builtin.floating.IslandFootprint;
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.builtin.objects.PlaceableObject;
|
||||
import art.arcane.iris.builtin.prepare.ObjectRotation;
|
||||
import art.arcane.iris.builtin.prepare.ObjectTranslate;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.mantle.MantleWriter;
|
||||
import art.arcane.iris.engine.mantle.components.FloatingObjectPlacementTransaction;
|
||||
import art.arcane.iris.engine.mantle.components.IslandAnchorPlacer;
|
||||
import art.arcane.iris.engine.object.placement.FloatingObjectFootprint;
|
||||
import art.arcane.iris.engine.object.placement.IObjectPlacer;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObject;
|
||||
import art.arcane.iris.engine.object.prefab.ScaledObjects;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObjectShaping;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.world.biome.custom.IrisBiomeCustom;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.util.common.data.B;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import art.arcane.volmlib.util.matter.MatterBiomeInject;
|
||||
import art.arcane.volmlib.util.matter.slices.BiomeInjectMatter;
|
||||
import com.volmit.ModuleLog;
|
||||
import com.volmit.generation.InvocationContext;
|
||||
import com.volmit.resource.ResourceId;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Iris's answers to {@code iris:floating}: a biome's terrain height by its generators, sky biomes into the engine's
|
||||
* mantle, and floating objects placed by Iris's own object placement into the mantle chunk being generated.
|
||||
*/
|
||||
/** Iris's answers to {@code iris:floating}: a biome's terrain height by its generators, and sky biomes into the engine's mantle. */
|
||||
final class IrisFloatingHost implements FloatingHost {
|
||||
private static final ObjectRotation NO_ROTATION = ObjectRotation.of(0, 0, 0);
|
||||
private static final int FLOATING_OBJECT_Y = -1;
|
||||
|
||||
private final Engine engine;
|
||||
private final ModuleLog log;
|
||||
|
||||
IrisFloatingHost(Engine engine, ModuleLog log) {
|
||||
IrisFloatingHost(Engine engine) {
|
||||
this.engine = engine;
|
||||
this.log = log;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -91,104 +61,4 @@ final class IrisFloatingHost implements FloatingHost {
|
||||
return ((IrisPackResources) engine.getData().getPackResources()).irisBiome(biome)
|
||||
.orElseThrow(() -> new IllegalArgumentException("The pack has no biome " + biome));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IslandFootprint footprint(PlaceableObject object) {
|
||||
FloatingObjectFootprint footprint = FloatingObjectFootprint.compute((IrisObject) object);
|
||||
return new IslandFootprint(footprint.getTallestKx(), footprint.getTallestKz(), footprint.getLowestSolidKeyY(), footprint.footprintXZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<PlaceableObject> shrink(PlaceableObject object, double factor, RNG random) {
|
||||
return Optional.ofNullable(ScaledObjects.resized((IrisObject) object, factor, random, engine));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void placeFloating(InvocationContext context, PlaceableObject object, int worldX, int worldZ, ObjectPlacement placement,
|
||||
RNG random) {
|
||||
IrisObject placed = (IrisObject) object;
|
||||
IrisData data = engine.getData();
|
||||
ObjectPlacement floating = placement.toBuilder().place(List.of(placed.getLoadKey())).build();
|
||||
MantleWriter writer = writerOf(context);
|
||||
int id = random.i(0, Integer.MAX_VALUE);
|
||||
try {
|
||||
placed.place(worldX, FLOATING_OBJECT_Y, worldZ, writer, floating, random, (block, state) -> writeMarker(writer, placed, id, block.getX(),
|
||||
block.getY(), block.getZ(), state), null, data);
|
||||
} catch (Throwable e) {
|
||||
log.error("Failed to place a floating object", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void placeOnTop(InvocationContext context, PlaceableObject object, int worldX, int y, int worldZ, ObjectPlacement placement,
|
||||
IslandAnchor anchor, RNG random) {
|
||||
placeAgainstIsland(writerOf(context), (IrisObject) object, worldX, y, worldZ, placement, NO_ROTATION, anchor, random, "anchored");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void placeUnder(InvocationContext context, PlaceableObject object, int worldX, int y, int worldZ, int yRotation,
|
||||
ObjectPlacement placement, IslandAnchor anchor, RNG random) {
|
||||
placeAgainstIsland(writerOf(context), (IrisObject) object, worldX, y, worldZ, placement, ObjectRotation.xFlip180WithY(yRotation),
|
||||
anchor, random, "inverted");
|
||||
}
|
||||
|
||||
private static MantleWriter writerOf(InvocationContext context) {
|
||||
return context.extension(IrisMantleChunk.class).orElseThrow().writer();
|
||||
}
|
||||
|
||||
/** Places the object through a transaction that writes nothing unless every block lands where the anchor allows. */
|
||||
private void placeAgainstIsland(MantleWriter writer, IrisObject object, int worldX, int y, int worldZ, ObjectPlacement placement,
|
||||
ObjectRotation rotation, IslandAnchor anchor, RNG random, String kind) {
|
||||
IrisData data = engine.getData();
|
||||
ObjectPlacement anchored = placement.toBuilder()
|
||||
.place(List.of(object.getLoadKey()))
|
||||
.mode(placement.mode().onFloatingIsland())
|
||||
.translate(new ObjectTranslate())
|
||||
.rotation(rotation)
|
||||
.forcePlace(true)
|
||||
.bottom(false)
|
||||
.build();
|
||||
|
||||
FloatingObjectPlacementTransaction transaction = new FloatingObjectPlacementTransaction(
|
||||
new IslandAnchorPlacer(writer, anchor));
|
||||
int id = random.i(0, Integer.MAX_VALUE);
|
||||
try {
|
||||
int resultY = object.place(worldX, y, worldZ, transaction, anchored, random, (block, state) -> writeMarker(transaction, object, id,
|
||||
block.getX(), block.getY(), block.getZ(), state), null, data);
|
||||
if (resultY < 0) {
|
||||
transaction.discard();
|
||||
} else {
|
||||
transaction.commit();
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
transaction.discard();
|
||||
log.error("Failed to place an " + kind + " floating object", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void writeMarker(IObjectPlacer placer, IrisObject object, int id, int x, int y, int z, PlatformBlockState state) {
|
||||
String marker = placementMarker(object, id);
|
||||
if (marker != null && shouldWritePlacementMarker(placer, state, x, y, z)) {
|
||||
placer.setData(x, y, z, marker);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean shouldWritePlacementMarker(IObjectPlacer placer, PlatformBlockState state, int x, int y, int z) {
|
||||
if (state == null) {
|
||||
return false;
|
||||
}
|
||||
PlatformBlockState existingState = placer.get(x, y, z);
|
||||
boolean wouldReplace = B.isSolid(existingState) && B.isVineBlock(state);
|
||||
String material = IrisObjectShaping.materialKey(state);
|
||||
boolean placesBlock = !material.equals("minecraft:air") && !material.equals("minecraft:cave_air") && !wouldReplace;
|
||||
return state.isCustom() || placesBlock;
|
||||
}
|
||||
|
||||
private static String placementMarker(IrisObject object, int id) {
|
||||
String key = object.getLoadKey();
|
||||
if (key == null || key.isEmpty() || key.equals("null")) {
|
||||
return null;
|
||||
}
|
||||
return key + "@" + id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.LegacyStreams;
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.framework.SeedManager;
|
||||
import art.arcane.iris.engine.object.noise.IrisNoiseGenerator;
|
||||
import art.arcane.iris.engine.object.placement.IrisPlacementForm;
|
||||
import art.arcane.iris.util.project.noise.CNG;
|
||||
import art.arcane.iris.util.project.noise.NoiseType;
|
||||
import art.arcane.volmlib.util.cache.CacheKey;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
/** Iris's own random streams and placement noise, from the world's legacy seeds and the pack's data. */
|
||||
final class IrisLegacyStreams implements LegacyStreams {
|
||||
private final IrisData data;
|
||||
private final SeedManager seeds;
|
||||
|
||||
IrisLegacyStreams(IrisData data, SeedManager seeds) {
|
||||
this.data = data;
|
||||
this.seeds = seeds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RNG objectChunkRandom(int chunkX, int chunkZ) {
|
||||
long seed = CacheKey.key(chunkX, chunkZ) + seeds.getMantle();
|
||||
CNG noise = CNG.signatureFast(new RNG(seed), NoiseType.WHITE, NoiseType.GLOB);
|
||||
return new RNG((long) (seed * noise.noise(chunkX, chunkZ)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int density(ObjectPlacement placement, RNG rng, double x, double z) {
|
||||
return IrisPlacementForm.of(placement, data).density(placement, rng, x, z, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int heightmapSurface(ObjectPlacement placement, long seed, int x, int z) {
|
||||
IrisNoiseGenerator heightmap = IrisPlacementForm.of(placement, data).heightmap();
|
||||
if (heightmap == null) {
|
||||
throw new IllegalArgumentException("The placement has no virtual heightmap");
|
||||
}
|
||||
return (int) Math.round(heightmap.getNoise(seed, x, z, data));
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,7 @@ import com.volmit.generation.MantleGenerationContext;
|
||||
import com.volmit.host.MantleRegistration;
|
||||
import com.volmit.geometry.BlockBox;
|
||||
import com.volmit.mantle.Mantle;
|
||||
import com.volmit.placement.PlacementTerrain;
|
||||
import com.volmit.world.PackWorld;
|
||||
import com.volmit.world.TerrainSampler;
|
||||
|
||||
@@ -51,6 +52,7 @@ final class IrisMantleGenerationContext implements MantleGenerationContext {
|
||||
private final IrisModuleMantle mantle;
|
||||
private final IrisMantleChunk irisChunk;
|
||||
private PackWorld world;
|
||||
private PlacementTerrain placementTerrain;
|
||||
|
||||
/** {@code irisChunk} is what Iris's built-in mantle stages see of the chunk as an extension. */
|
||||
IrisMantleGenerationContext(Engine engine, int chunkX, int chunkZ, int reachBlocks, IrisModuleMantle.Chunks chunks,
|
||||
@@ -106,6 +108,15 @@ final class IrisMantleGenerationContext implements MantleGenerationContext {
|
||||
}
|
||||
|
||||
|
||||
/** The chunk's mantle as Iris's object placer writes it, within the chunk's reach. */
|
||||
@Override
|
||||
public PlacementTerrain placementTerrain() {
|
||||
if (placementTerrain == null) {
|
||||
placementTerrain = PlacerTerrain.of(irisChunk.writer(), engine.getData());
|
||||
}
|
||||
return placementTerrain;
|
||||
}
|
||||
|
||||
/** The world this invocation first asked for; it keeps it if the world restarts meanwhile. */
|
||||
@Override
|
||||
public PackWorld world() {
|
||||
|
||||
@@ -1,90 +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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.objects.ObjectBuilder;
|
||||
import art.arcane.iris.builtin.objects.PlaceableObject;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObject;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.util.common.data.B;
|
||||
import art.arcane.volmlib.util.math.IrisBlockVector;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.block.PaletteSpec;
|
||||
import com.volmit.object.ObjectBlock;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Builds a module's objects as Iris objects of the pack. Every state it hands out comes from the platform through one
|
||||
* {@link PlatformBlockStates}, so setting a property on it or building it gives back the platform's own state: a content
|
||||
* plugin's block keeps its identity, as it did when the generators held platform states themselves.
|
||||
*/
|
||||
public final class IrisObjectBuilder implements ObjectBuilder {
|
||||
private static final File GOLDEN_DEBUG_SWITCH = new File("plugins/Iris/goldendebug.txt");
|
||||
|
||||
private final IrisData data;
|
||||
private final PlatformBlockStates states = new PlatformBlockStates(B::getState);
|
||||
|
||||
public IrisObjectBuilder(IrisData data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState block(String key) {
|
||||
PlatformBlockState state = B.getStateOrNull(key, false);
|
||||
return state == null ? null : states.toApi(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState pick(PaletteSpec palette, long seed, int x, int y, int z) {
|
||||
return states.toApi(B.getState(data.getPackResources().blocks().palette(palette, seed).at(x, y, z).key()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState withProperty(BlockState state, String name, String value) {
|
||||
return states.toApi(states.toPlatform(state).withProperty(name, value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlaceableObject build(String loadKey, int width, int height, int depth, List<ObjectBlock> blocks) {
|
||||
IrisObject object = new IrisObject(width, height, depth);
|
||||
for (ObjectBlock block : blocks) {
|
||||
object.getBlocks().put(new IrisBlockVector(block.position().x(), block.position().y(), block.position().z()),
|
||||
states.toPlatform(block.state()));
|
||||
}
|
||||
object.setLoadKey(loadKey);
|
||||
object.setLoader(data);
|
||||
logGoldenDebugDigest(object);
|
||||
return object;
|
||||
}
|
||||
|
||||
private static void logGoldenDebugDigest(IrisObject object) {
|
||||
if (!GOLDEN_DEBUG_SWITCH.isFile()) {
|
||||
return;
|
||||
}
|
||||
long[] digest = new long[]{0L};
|
||||
object.getBlocks().forEach((vector, state) -> {
|
||||
long position = ((long) vector.getBlockX() << 40) ^ ((long) vector.getBlockY() << 20) ^ vector.getBlockZ();
|
||||
digest[0] ^= Long.rotateLeft(position * 0x9E3779B97F4A7C15L ^ state.key().hashCode(), (int) (position & 63));
|
||||
});
|
||||
IrisLogging.debug("Goldendebug bake: " + object.getLoadKey() + " blocks=" + object.getBlocks().size() + " digest=" + Long.toHexString(digest[0]));
|
||||
}
|
||||
}
|
||||
@@ -1,212 +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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.anchor.PlaceTrait;
|
||||
import art.arcane.iris.builtin.objects.CarvedSpace;
|
||||
import art.arcane.iris.builtin.objects.Cavern;
|
||||
import art.arcane.iris.builtin.objects.CavePlacement;
|
||||
import art.arcane.iris.builtin.objects.ObjectChunk;
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.builtin.objects.PlaceableObject;
|
||||
import art.arcane.iris.builtin.objects.PlacementChanges;
|
||||
import art.arcane.iris.builtin.objects.PlacementSource;
|
||||
import art.arcane.iris.builtin.objects.PlacementTags;
|
||||
import art.arcane.iris.builtin.objects.ProceduralPlacement;
|
||||
import art.arcane.iris.builtin.prepare.AxisRotationClamp;
|
||||
import art.arcane.iris.builtin.prepare.ObjectRotation;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.TreeBlockMaterial;
|
||||
import art.arcane.iris.engine.mantle.MantleWriter;
|
||||
import art.arcane.iris.engine.mantle.components.CaveObjectPlacementTransaction;
|
||||
import art.arcane.iris.engine.mantle.components.GoldenDebugObjectPlacer;
|
||||
import art.arcane.iris.engine.object.placement.DecayControlPlacer;
|
||||
import art.arcane.iris.engine.object.placement.IObjectPlacer;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObject;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.util.common.data.B;
|
||||
import art.arcane.volmlib.util.math.BlockPosition;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import art.arcane.volmlib.util.matter.MatterCavern;
|
||||
import art.arcane.volmlib.util.matter.MatterStructurePOI;
|
||||
import com.volmit.ModuleLog;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
/** The chunk whose mantle {@code iris:objects} is placing into: Iris's mantle writer around it and the engine it belongs to. */
|
||||
final class IrisObjectChunk implements ObjectChunk {
|
||||
private static final double UPSIDE_DOWN_TURN_DEGREES = 180D;
|
||||
private static final double QUARTER_TURN_DEGREES = 90D;
|
||||
|
||||
private final Engine engine;
|
||||
private final MantleWriter writer;
|
||||
private final ModuleLog log;
|
||||
private final Function<ProceduralPlacement, ObjectPlacement> proceduralOptions;
|
||||
|
||||
IrisObjectChunk(Engine engine, MantleWriter writer, ModuleLog log, Function<ProceduralPlacement, ObjectPlacement> proceduralOptions) {
|
||||
this.engine = engine;
|
||||
this.writer = writer;
|
||||
this.log = log;
|
||||
this.proceduralOptions = proceduralOptions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CarvedSpace carved() {
|
||||
return new CarvedSpace() {
|
||||
@Override
|
||||
public boolean isCarved(int x, int y, int z) {
|
||||
return writer.isCarved(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] column(int x, int z, int height) {
|
||||
return writer.getCarvedColumn(x, z, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Cavern> cavernAt(int x, int y, int z) {
|
||||
MatterCavern cavern = writer.getDataIfPresent(x, y, z, MatterCavern.class);
|
||||
if (cavern == null || !cavern.isCavern()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(new Cavern(cavern.isAir(), cavern.getLiquid()));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean goldenDebug(int chunkX, int chunkZ) {
|
||||
return GoldenDebugObjectPlacer.isGoldenDebugChunk(chunkX, chunkZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int placeOnSurface(PlaceableObject object, int x, int z, PlacementSource placement, PlacementChanges changes,
|
||||
PlacementTags tags, RNG rng, String goldenTag) {
|
||||
ObjectPlacement effective = effective(placement, changes);
|
||||
IObjectPlacer base = placement instanceof ProceduralPlacement procedural && procedural.plausible()
|
||||
? new DecayControlPlacer(writer) : writer;
|
||||
IObjectPlacer placer = goldenTag == null ? base : new GoldenDebugObjectPlacer(base, goldenTag, log);
|
||||
IObjectPlacer written = placement instanceof ProceduralPlacement ? placer : writer;
|
||||
return ((IrisObject) object).place(x, -1, z, placer, effective, rng, taggedBlocks(written, tags), null, engine.getData());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CavePlacement placeInCave(PlaceableObject object, int x, int anchorY, int z, PlacementSource placement, PlacementChanges changes,
|
||||
int minDepthBelowSurface, PlacementTags tags, RNG rng, String goldenTag) {
|
||||
ObjectPlacement effective = effective(placement, changes);
|
||||
IrisObject irisObject = (IrisObject) object;
|
||||
IObjectPlacer placer = caveBase(placement, goldenTag);
|
||||
CaveObjectPlacementTransaction transaction = new CaveObjectPlacementTransaction(placer, anchorY, minDepthBelowSurface);
|
||||
int placeY = anchorY;
|
||||
if (effective.mode().placeMode().has(PlaceTrait.UPSIDE_DOWN)) {
|
||||
placeY = Math.max(1, transaction.getCaveCeiling(x, z) - 1 - Math.floorDiv(irisObject.getH(), 2));
|
||||
}
|
||||
int result = irisObject.place(x, placeY, z, transaction, effective, rng, taggedBlocks(transaction, tags), null, engine.getData());
|
||||
if (result < 0) {
|
||||
transaction.discard();
|
||||
return new CavePlacement(result, CavePlacement.Commit.EMPTY);
|
||||
}
|
||||
return new CavePlacement(result, commitResult(transaction.commit()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int placeUpper(PlaceableObject object, int x, int anchorY, int z, ObjectPlacement placement, PlacementChanges changes,
|
||||
PlacementTags tags, RNG rng) {
|
||||
ObjectPlacement effective = effective(placement, changes);
|
||||
return ((IrisObject) object).place(x, anchorY, z, writer, effective, rng, taggedBlocks(writer, tags), null, engine.getData());
|
||||
}
|
||||
|
||||
private IObjectPlacer caveBase(PlacementSource placement, String goldenTag) {
|
||||
if (!(placement instanceof ProceduralPlacement procedural)) {
|
||||
return writer;
|
||||
}
|
||||
IObjectPlacer base = procedural.plausible() ? new DecayControlPlacer(writer) : writer;
|
||||
return goldenTag == null ? base : new GoldenDebugObjectPlacer(base, goldenTag, log);
|
||||
}
|
||||
|
||||
private static CavePlacement.Commit commitResult(CaveObjectPlacementTransaction.CommitResult result) {
|
||||
return switch (result) {
|
||||
case COMMITTED -> CavePlacement.Commit.COMMITTED;
|
||||
case EMPTY -> CavePlacement.Commit.EMPTY;
|
||||
case REJECTED_BOUNDS -> CavePlacement.Commit.REJECTED_BOUNDS;
|
||||
};
|
||||
}
|
||||
|
||||
/** Writes the tags beside each block of the object, into {@code placer}. */
|
||||
private static BiConsumer<BlockPosition, PlatformBlockState> taggedBlocks(IObjectPlacer placer, PlacementTags tags) {
|
||||
return (position, state) -> {
|
||||
if (tags.marker() != null) {
|
||||
placer.setData(position.getX(), position.getY(), position.getZ(), tags.marker());
|
||||
if (tags.treeMaterial()) {
|
||||
placer.setData(position.getX(), position.getY(), position.getZ(), TreeBlockMaterial.of(state));
|
||||
}
|
||||
}
|
||||
if (tags.buriedTreasure() && B.isStorageChest(state)) {
|
||||
placer.setData(position.getX(), position.getY(), position.getZ(), MatterStructurePOI.BURIED_TREASURE);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/** The placement {@code placement} places with, with {@code changes} made to a copy of it. */
|
||||
private ObjectPlacement effective(PlacementSource placement, PlacementChanges changes) {
|
||||
ObjectPlacement base = placement instanceof ObjectPlacement settings
|
||||
? settings
|
||||
: proceduralOptions.apply((ProceduralPlacement) placement);
|
||||
return withChanges(base, changes);
|
||||
}
|
||||
|
||||
/** {@code base} with {@code changes} made to a copy of it; {@code base} itself when there are none. */
|
||||
static ObjectPlacement withChanges(ObjectPlacement base, PlacementChanges changes) {
|
||||
if (changes.isNone()) {
|
||||
return base;
|
||||
}
|
||||
ObjectPlacement.Builder changed = base.toBuilder();
|
||||
if (changes.place() != null) {
|
||||
changed.place(changes.place());
|
||||
}
|
||||
if (changes.mode() != null) {
|
||||
changed.mode(changes.mode());
|
||||
}
|
||||
if (changes.upsideDown() != null && changes.upsideDown()) {
|
||||
changed.rotation(upsideDownRotation());
|
||||
}
|
||||
if (changes.carvingSupport() != null) {
|
||||
changed.carvingSupport(changes.carvingSupport());
|
||||
}
|
||||
if (changes.requireSurfaceSupport() != null) {
|
||||
changed.requireSurfaceSupport(changes.requireSurfaceSupport());
|
||||
}
|
||||
if (changes.surfaceSupportBuffer() != null) {
|
||||
changed.surfaceSupportBuffer(changes.surfaceSupportBuffer());
|
||||
}
|
||||
if (changes.forcePlace() != null) {
|
||||
changed.forcePlace(changes.forcePlace());
|
||||
}
|
||||
return changed.build();
|
||||
}
|
||||
|
||||
private static ObjectRotation upsideDownRotation() {
|
||||
return ObjectRotation.of(true,
|
||||
AxisRotationClamp.of(true, true, UPSIDE_DOWN_TURN_DEGREES, UPSIDE_DOWN_TURN_DEGREES, QUARTER_TURN_DEGREES),
|
||||
AxisRotationClamp.of(true, false, 0D, 0D, QUARTER_TURN_DEGREES),
|
||||
new AxisRotationClamp());
|
||||
}
|
||||
}
|
||||
@@ -1,185 +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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.objects.ObjectBuilder;
|
||||
import art.arcane.iris.builtin.objects.ObjectChunk;
|
||||
import art.arcane.iris.builtin.objects.ObjectHost;
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.builtin.objects.ObjectSink;
|
||||
import art.arcane.iris.builtin.objects.ObjectSize;
|
||||
import art.arcane.iris.builtin.objects.PlaceableObject;
|
||||
import art.arcane.iris.builtin.objects.ProceduralPlacement;
|
||||
import art.arcane.iris.core.IrisSettings;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.loader.IrisRegistrant;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.PlacedObject;
|
||||
import art.arcane.iris.engine.object.placement.IrisPlacementForm;
|
||||
import art.arcane.iris.engine.object.placement.ObjectPlacements;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObject;
|
||||
import art.arcane.iris.engine.object.prefab.ScaledObjects;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.world.region.IrisRegion;
|
||||
import art.arcane.iris.util.project.noise.CNG;
|
||||
import art.arcane.iris.util.project.noise.NoiseType;
|
||||
import art.arcane.volmlib.util.cache.CacheKey;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.IrisFeature;
|
||||
import com.volmit.ModuleLog;
|
||||
import com.volmit.config.Level;
|
||||
import com.volmit.generation.InvocationContext;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* What {@code iris:objects} asks of Iris's object system, answered from the world's engine: the pack's objects, how Iris
|
||||
* scales, picks and places them, and the loot of what it placed.
|
||||
*/
|
||||
final class IrisObjectHost implements ObjectHost {
|
||||
private final Engine engine;
|
||||
private final ModuleLog log;
|
||||
private volatile PackResourceIds ids;
|
||||
private final Map<ProceduralPlacement, ObjectPlacement> proceduralOptions = new ConcurrentHashMap<>();
|
||||
|
||||
IrisObjectHost(Engine engine, ModuleLog log) {
|
||||
this.engine = engine;
|
||||
this.log = log;
|
||||
}
|
||||
|
||||
private PackResourceIds ids() {
|
||||
PackResourceIds known = ids;
|
||||
if (known == null) {
|
||||
known = new PackResourceIds(engine.getData().getDataFolder());
|
||||
ids = known;
|
||||
}
|
||||
return known;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean debugging() {
|
||||
return IrisSettings.get().getGeneral().isDebug();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RNG chunkRandom(int chunkX, int chunkZ) {
|
||||
long seed = CacheKey.key(chunkX, chunkZ) + engine.getSeedManager().getMantle();
|
||||
CNG noise = CNG.signatureFast(new RNG(seed), NoiseType.WHITE, NoiseType.GLOB);
|
||||
return new RNG((long) (seed * noise.noise(chunkX, chunkZ)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectChunk chunk(InvocationContext context) {
|
||||
IrisMantleChunk chunk = context.extension(IrisMantleChunk.class).orElseThrow();
|
||||
return new IrisObjectChunk(chunk.engine(), chunk.writer(), log, this::options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<PlaceableObject> object(String key) {
|
||||
return Optional.ofNullable(engine.getData().getObjectLoader().load(key));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<PlaceableObject> pickScaled(ObjectPlacement placement, RNG rng) {
|
||||
IrisObject picked = ObjectPlacements.pickObject(placement, engine.getData(), rng);
|
||||
return Optional.ofNullable(ScaledObjects.variant(placement.scale(), rng, picked, engine));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int density(ObjectPlacement placement, RNG rng, double x, double z) {
|
||||
return formOf(placement).density(placement, rng, x, z, engine.getData());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ObjectSize> sizeOf(String objectKey) {
|
||||
File file = engine.getData().getObjectLoader().findFile(objectKey);
|
||||
if (file == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
try {
|
||||
var size = IrisObject.sampleSize(file);
|
||||
return Optional.of(new ObjectSize(size.getBlockX(), size.getBlockY(), size.getBlockZ()));
|
||||
} catch (IOException failure) {
|
||||
throw new UncheckedIOException(failure);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warm(ObjectPlacement placement, RNG rng) {
|
||||
IrisPlacementForm form = formOf(placement);
|
||||
form.surfaceWarp(rng, engine.getData(), engine);
|
||||
form.density(placement, rng, 0, 0, engine.getData());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectBuilder builder() {
|
||||
return new IrisObjectBuilder(engine.getData());
|
||||
}
|
||||
|
||||
/** The options {@code placement} is scattered with, as an object placement, made once per placement. */
|
||||
ObjectPlacement options(ProceduralPlacement placement) {
|
||||
return proceduralOptions.computeIfAbsent(placement, ProceduralOptions::of);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int placeInto(PlaceableObject object, int x, int y, int z, ObjectPlacement placement, ObjectSink sink, RNG rng) {
|
||||
IrisData data = engine.getData();
|
||||
return ((IrisObject) object).place(x, y, z, new SinkPlacer(engine, sink), placement, rng, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ObjectLoots> placedLoot(int x, int y, int z) {
|
||||
PlacedObject placed = engine.getObjectPlacement(x, y, z);
|
||||
ObjectPlacement placement = placed == null ? null : placed.getPlacement();
|
||||
if (placement == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(new ObjectLoots(placement.loot(), placement.vanillaLoot(), placement.overrideGlobalLoot()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <F extends IrisFeature> List<Declaration<F>> declarations(Class<F> type) {
|
||||
List<Declaration<F>> found = new ArrayList<>();
|
||||
for (IrisRegion region : engine.getDimension().getAllRegions(engine)) {
|
||||
addDeclaration(found, Level.REGION, region, type);
|
||||
}
|
||||
for (IrisBiome biome : engine.getDimension().getReachableBiomes(engine)) {
|
||||
addDeclaration(found, Level.BIOME, biome, type);
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
private <F extends IrisFeature> void addDeclaration(List<Declaration<F>> found, Level level, IrisRegistrant owner, Class<F> type) {
|
||||
if (owner == null) {
|
||||
return;
|
||||
}
|
||||
owner.getModuleSettings().find(type).ifPresent(settings -> found.add(new Declaration<>(level, ids().of(owner.getLoadKey()), settings)));
|
||||
}
|
||||
|
||||
private IrisPlacementForm formOf(ObjectPlacement placement) {
|
||||
return IrisPlacementForm.of(placement, engine.getData());
|
||||
}
|
||||
}
|
||||
@@ -1,79 +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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.placement.ObjectShape;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObject;
|
||||
import art.arcane.volmlib.util.math.IrisBlockVector;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/** An Iris object as the placement stages see it. */
|
||||
final class IrisObjectShape implements ObjectShape {
|
||||
private final IrisObject object;
|
||||
private final PackResources resources;
|
||||
|
||||
IrisObjectShape(IrisObject object, PackResources resources) {
|
||||
this.object = object;
|
||||
this.resources = resources;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int width() {
|
||||
return object.getW();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int height() {
|
||||
return object.getH();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int depth() {
|
||||
return object.getD();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int centerX() {
|
||||
return object.getCenter().getBlockX();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int centerY() {
|
||||
return object.getCenter().getBlockY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int centerZ() {
|
||||
return object.getCenter().getBlockZ();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ResourceId> id() {
|
||||
return Optional.ofNullable(object.getLoadKey()).map(resources::idOf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IrisBlockVector> surfaceSupportOffsets() {
|
||||
return object.getSurfaceSupportOffsets();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.objects.ScaleInterpolation;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObject;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObjectShaping;
|
||||
import art.arcane.iris.engine.object.prefab.ScaledObjects;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.util.common.data.B;
|
||||
import art.arcane.volmlib.util.math.IrisBlockVector;
|
||||
import com.volmit.geometry.BlockBox;
|
||||
import com.volmit.object.ObjectBlock;
|
||||
import com.volmit.object.PackObjects;
|
||||
import com.volmit.object.PlaceableObject;
|
||||
import com.volmit.object.ScaleMethod;
|
||||
import com.volmit.resource.PackResources;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* The pack's objects as Iris loads, scales and bores them: each a cached {@link IrisObject}. Scaled variants live in the
|
||||
* scale cache of the world generating, so scaling needs the pack's engine. Built objects are Iris objects of the pack.
|
||||
*/
|
||||
final class IrisPackObjects implements PackObjects {
|
||||
private static final File GOLDEN_DEBUG_SWITCH = new File("plugins/Iris/goldendebug.txt");
|
||||
|
||||
private final IrisData data;
|
||||
private final IrisPackResources resources;
|
||||
|
||||
IrisPackObjects(IrisData data, IrisPackResources resources) {
|
||||
this.data = data;
|
||||
this.resources = resources;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<PlaceableObject> object(com.volmit.resource.ResourceId id) {
|
||||
return Optional.ofNullable(data.getObjectLoader().load(keyOf(id)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<BlockBox> sizeOf(com.volmit.resource.ResourceId id) {
|
||||
File file = data.getObjectLoader().findFile(keyOf(id));
|
||||
if (file == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
try {
|
||||
var size = IrisObject.sampleSize(file);
|
||||
return Optional.of(new BlockBox(0, 0, 0, size.getBlockX(), size.getBlockY(), size.getBlockZ()));
|
||||
} catch (IOException failure) {
|
||||
throw new UncheckedIOException(failure);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlaceableObject scaled(PlaceableObject object, double factor, ScaleMethod method) {
|
||||
Engine engine = data.getEngine();
|
||||
if (engine == null) {
|
||||
throw new IllegalStateException("Scaling " + object.name() + " needs the world the pack generates, and it has none");
|
||||
}
|
||||
return ScaledObjects.scaled(irisObject(object), factor, ScaleInterpolation.valueOf(method.name()), engine);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlaceableObject smartBored(PlaceableObject object) {
|
||||
IrisObject bored = irisObject(object);
|
||||
IrisObjectShaping.ensureSmartBored(bored);
|
||||
return bored;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlaceableObject build(String name, int width, int height, int depth, List<ObjectBlock> blocks) {
|
||||
PlatformBlockStates states = new PlatformBlockStates(B::getState);
|
||||
IrisObject object = new IrisObject(width, height, depth);
|
||||
for (ObjectBlock block : blocks) {
|
||||
object.getBlocks().put(new IrisBlockVector(block.position().x(), block.position().y(), block.position().z()),
|
||||
states.toPlatform(block.state()));
|
||||
}
|
||||
object.setLoadKey(name);
|
||||
object.setLoader(data);
|
||||
logGoldenDebugDigest(object);
|
||||
return object;
|
||||
}
|
||||
|
||||
private String keyOf(com.volmit.resource.ResourceId id) {
|
||||
return resources.keyOf(PackResources.OBJECTS, id);
|
||||
}
|
||||
|
||||
private static IrisObject irisObject(PlaceableObject object) {
|
||||
if (object instanceof IrisObject iris) {
|
||||
return iris;
|
||||
}
|
||||
throw new IllegalArgumentException("Iris scales and bores the objects of its packs and of its builder only, not " + object.name());
|
||||
}
|
||||
|
||||
private static void logGoldenDebugDigest(IrisObject object) {
|
||||
if (!GOLDEN_DEBUG_SWITCH.isFile()) {
|
||||
return;
|
||||
}
|
||||
long[] digest = new long[]{0L};
|
||||
object.getBlocks().forEach((vector, state) -> {
|
||||
long position = ((long) vector.getBlockX() << 40) ^ ((long) vector.getBlockY() << 20) ^ vector.getBlockZ();
|
||||
digest[0] ^= Long.rotateLeft(position * 0x9E3779B97F4A7C15L ^ state.key().hashCode(), (int) (position & 63));
|
||||
});
|
||||
IrisLogging.debug("Goldendebug bake: " + object.getLoadKey() + " blocks=" + object.getBlocks().size() + " digest=" + Long.toHexString(digest[0]));
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import com.volmit.object.PackObjects;
|
||||
import art.arcane.iris.core.loader.IrisRegistrant;
|
||||
import art.arcane.iris.core.loader.ResourceLoader;
|
||||
import art.arcane.iris.engine.object.image.IrisImageMap;
|
||||
@@ -75,6 +76,7 @@ public final class IrisPackResources implements PackResources {
|
||||
private final UUID snapshotId = UUID.randomUUID();
|
||||
private final SettingsStacks settingsStacks = new SettingsStacks();
|
||||
private final BlockRegistry blocks;
|
||||
private final PackObjects objects;
|
||||
private final ItemRegistry items = new IrisItemRegistry();
|
||||
private final NoiseFactory noise;
|
||||
private final Map<ResourceId, Kind<?>> irisKinds;
|
||||
@@ -95,6 +97,7 @@ public final class IrisPackResources implements PackResources {
|
||||
this.ids = new PackResourceIds(data.getDataFolder());
|
||||
this.moduleKindList = moduleKinds;
|
||||
this.blocks = new IrisBlockRegistry(data, this);
|
||||
this.objects = new IrisPackObjects(data, this);
|
||||
this.noise = new IrisNoiseFactory(data, this);
|
||||
this.irisKinds = Map.of(
|
||||
OBJECTS.id(), Kind.<IrisObject, GeneratedObject>ofLoader(ids, data::getObjectLoader, (id, object) -> object.getGeometry()),
|
||||
@@ -136,6 +139,11 @@ public final class IrisPackResources implements PackResources {
|
||||
return blocks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackObjects objects() {
|
||||
return objects;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemRegistry items() {
|
||||
return items;
|
||||
|
||||
@@ -20,7 +20,6 @@ package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisRegistrant;
|
||||
import art.arcane.iris.builtin.structure.StructureHost;
|
||||
import art.arcane.iris.builtin.objects.ObjectHost;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
@@ -31,6 +30,7 @@ import com.volmit.IrisFeature;
|
||||
import com.volmit.config.FeatureSettings.Entry;
|
||||
import com.volmit.config.PackSettings;
|
||||
import com.volmit.config.SettingsStack;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -61,6 +61,11 @@ public final class IrisPackSettings implements PackSettings {
|
||||
return engine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackResources resources() {
|
||||
return engine.getData().getPackResources();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Optional<T> extension(Class<T> type) {
|
||||
return HostExtensions.as(type, offered(type));
|
||||
@@ -71,9 +76,6 @@ public final class IrisPackSettings implements PackSettings {
|
||||
if (type == Engine.class) {
|
||||
return engine;
|
||||
}
|
||||
if (type == ObjectHost.class) {
|
||||
return new IrisObjectHost(engine, IrisApiLogger.hostLog());
|
||||
}
|
||||
if (type == StructureHost.class) {
|
||||
return new IrisStructureHost(engine, IrisApiLogger.hostLog());
|
||||
}
|
||||
|
||||
@@ -19,13 +19,14 @@
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.floating.FloatingHost;
|
||||
import art.arcane.iris.builtin.objects.ObjectHost;
|
||||
import art.arcane.iris.builtin.LegacyStreams;
|
||||
import art.arcane.iris.builtin.spawn.SpawnCooldowns;
|
||||
import art.arcane.iris.builtin.structure.StructureHost;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import com.volmit.ModuleLog;
|
||||
import com.volmit.config.PackSettings;
|
||||
import com.volmit.host.WorldStates;
|
||||
import com.volmit.placement.Placements;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.world.PackWorld;
|
||||
import com.volmit.world.RunningWorld;
|
||||
@@ -36,8 +37,8 @@ import java.util.function.Function;
|
||||
* One Iris world as modules see it: an engine runtime generating with one snapshot of its pack's resources, and the
|
||||
* state modules keep for it. {@link ModuleWorlds} makes one when the runtime is built and a new one whenever the
|
||||
* pack's resources reload under it. Iris's built-in modules reach what they need of Iris through its
|
||||
* {@linkplain #extension extensions}: the spawners' cooldowns Iris saves with the world and the object, floating and
|
||||
* structure hosts.
|
||||
* {@linkplain #extension extensions}: the spawners' cooldowns Iris saves with the world, Iris's legacy random streams,
|
||||
* and the floating and structure hosts.
|
||||
*/
|
||||
public final class IrisPackWorld implements PackWorld {
|
||||
private final Engine engine;
|
||||
@@ -46,7 +47,8 @@ public final class IrisPackWorld implements PackWorld {
|
||||
private final ModuleLog log;
|
||||
private final SpawnCooldowns spawnCooldowns;
|
||||
private volatile RunningWorld running;
|
||||
private volatile IrisObjectHost objectHost;
|
||||
private final LegacyStreams legacyStreams;
|
||||
private final Placements placements;
|
||||
private volatile IrisFloatingHost floatingHost;
|
||||
private volatile IrisStructureHost structureHost;
|
||||
|
||||
@@ -56,6 +58,13 @@ public final class IrisPackWorld implements PackWorld {
|
||||
this.states = new WorldStates();
|
||||
this.log = IrisApiLogger.hostLog();
|
||||
this.spawnCooldowns = new EngineSpawnCooldowns(engine);
|
||||
this.legacyStreams = new IrisLegacyStreams(engine.getData(), engine.getSeedManager());
|
||||
this.placements = new IrisPlacements(engine.getData(), engine, () -> this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Placements placements() {
|
||||
return placements;
|
||||
}
|
||||
|
||||
/** The engine generating this world. */
|
||||
@@ -121,8 +130,8 @@ public final class IrisPackWorld implements PackWorld {
|
||||
if (type == SpawnCooldowns.class) {
|
||||
return spawnCooldowns;
|
||||
}
|
||||
if (type == ObjectHost.class) {
|
||||
return objects();
|
||||
if (type == LegacyStreams.class) {
|
||||
return legacyStreams;
|
||||
}
|
||||
if (type == FloatingHost.class) {
|
||||
return floating();
|
||||
@@ -133,19 +142,10 @@ public final class IrisPackWorld implements PackWorld {
|
||||
return null;
|
||||
}
|
||||
|
||||
private ObjectHost objects() {
|
||||
IrisObjectHost host = objectHost;
|
||||
if (host == null) {
|
||||
host = new IrisObjectHost(engine, log);
|
||||
objectHost = host;
|
||||
}
|
||||
return host;
|
||||
}
|
||||
|
||||
private FloatingHost floating() {
|
||||
IrisFloatingHost host = floatingHost;
|
||||
if (host == null) {
|
||||
host = new IrisFloatingHost(engine, log);
|
||||
host = new IrisFloatingHost(engine);
|
||||
floatingHost = host;
|
||||
}
|
||||
return host;
|
||||
|
||||
@@ -1,203 +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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.placement.CaveSpace;
|
||||
import art.arcane.iris.builtin.placement.ObjectPlacement;
|
||||
import art.arcane.iris.builtin.placement.ObjectShape;
|
||||
import art.arcane.iris.builtin.placement.PlacementSettings;
|
||||
import art.arcane.iris.builtin.placement.PlacementTerrain;
|
||||
import art.arcane.iris.builtin.placement.PlaneNoise;
|
||||
import art.arcane.iris.builtin.placement.SurfaceWarp;
|
||||
import art.arcane.iris.builtin.prepare.ObjectRotation;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.framework.placer.HeightmapObjectPlacer;
|
||||
import art.arcane.iris.engine.object.material.BlockDataMergeSupport;
|
||||
import art.arcane.iris.engine.object.placement.IObjectPlacer;
|
||||
import art.arcane.iris.engine.object.placement.IrisPlacementForm;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObject;
|
||||
import art.arcane.iris.engine.object.prefab.BlockStateRotation;
|
||||
import art.arcane.iris.engine.object.terrain.carving.CarveResult;
|
||||
import art.arcane.iris.util.project.noise.CNG;
|
||||
import art.arcane.iris.util.project.noise.SimplexNoise;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.block.BlockTrait;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.geometry.BlockPosition;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Iris's own inputs of the object placement being run: the placement settings, object, placer and cave that IrisApi
|
||||
* does not describe, answered to Iris's built-in placement stages as an {@link ObjectPlacement}, the extension of the
|
||||
* placement invocation. Pack modules cannot see this class.
|
||||
*/
|
||||
public final class IrisPlacement implements ObjectPlacement {
|
||||
private static final int NOT_ANCHORED = Integer.MIN_VALUE;
|
||||
|
||||
private final IrisObject object;
|
||||
private final IrisPlacementForm form;
|
||||
private final IObjectPlacer placer;
|
||||
private final CarveResult cave;
|
||||
private final int x;
|
||||
private final int requestedY;
|
||||
private final int z;
|
||||
private final IrisData data;
|
||||
private final PlatformBlockStates states;
|
||||
private final ObjectPlacerEdit edit;
|
||||
private final IrisObjectShape shape;
|
||||
private final IrisPlacementSettings settings;
|
||||
private final IrisPlacementTerrain terrain;
|
||||
private int anchorY = NOT_ANCHORED;
|
||||
|
||||
IrisPlacement(IrisObject object, art.arcane.iris.builtin.objects.ObjectPlacement config, IrisPlacementForm form,
|
||||
IObjectPlacer placer, CarveResult cave, int x, int requestedY, int z, IrisData data, PlatformBlockStates states,
|
||||
ObjectPlacerEdit edit) {
|
||||
this.object = object;
|
||||
this.form = form;
|
||||
this.placer = placer;
|
||||
this.cave = cave;
|
||||
this.x = x;
|
||||
this.requestedY = requestedY;
|
||||
this.z = z;
|
||||
this.data = data;
|
||||
this.states = states;
|
||||
this.edit = edit;
|
||||
this.shape = new IrisObjectShape(object, data.getPackResources());
|
||||
this.settings = new IrisPlacementSettings(config, data);
|
||||
this.terrain = new IrisPlacementTerrain(placer, object.getLoader(), data);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ObjectShape object() {
|
||||
return shape;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlacementSettings settings() {
|
||||
return settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int x() {
|
||||
return x;
|
||||
}
|
||||
|
||||
/** The height the caller asked for, negative when the placement samples it. */
|
||||
@Override
|
||||
public int requestedY() {
|
||||
return requestedY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int z() {
|
||||
return z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<CaveSpace> cave() {
|
||||
return Optional.ofNullable(cave).map(space -> new CaveSpace(space.getSurface(), space.getHeight()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlacementTerrain terrain() {
|
||||
return terrain;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlacementTerrain terrainFor(RNG rng) {
|
||||
if (form.heightmap() == null) {
|
||||
return terrain;
|
||||
}
|
||||
return new IrisPlacementTerrain(new HeightmapObjectPlacer(rng, x, requestedY, z, form.heightmap(), placer), object.getLoader(), data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<SurfaceWarp> surfaceWarp(RNG rng) {
|
||||
if (form.warp().isFlat()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
IrisData loader = object.getLoader();
|
||||
CNG warp = form.surfaceWarp(rng, loader, loader.getEngine());
|
||||
double multiplier = form.warp().getMultiplier();
|
||||
return Optional.of(new SurfaceWarp() {
|
||||
@Override
|
||||
public double multiplier() {
|
||||
return multiplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double fit(double min, double max, double x, double y, double z) {
|
||||
return warp.fitDouble(min, max, x, y, z);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlaneNoise simplex(long seed) {
|
||||
SimplexNoise noise = new SimplexNoise(seed);
|
||||
return noise::noiseSigned;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState rotate(BlockState state, ObjectRotation rotation, int spinX, int spinY, int spinZ) {
|
||||
return states.toApi(BlockStateRotation.rotate(rotation, states.toPlatform(state), spinX, spinY, spinZ));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState merge(BlockState base, BlockState update) {
|
||||
return states.toApi(BlockDataMergeSupport.merge(states.toPlatform(base), states.toPlatform(update)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(BlockState state, BlockState other) {
|
||||
return states.toPlatform(state).matches(states.toPlatform(other));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTrait(BlockState state, BlockTrait trait) {
|
||||
return IrisBlockRegistry.hasTrait(states.toPlatform(state), trait);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackResources resources() {
|
||||
return object.getLoader().getPackResources();
|
||||
}
|
||||
|
||||
/** Reports a buffered write as one of the object's own blocks, which Iris's placement listener hears after the commit. */
|
||||
@Override
|
||||
public void objectBlockWritten(BlockPosition position) {
|
||||
edit.recordObjectBlock(position);
|
||||
}
|
||||
|
||||
/** Reports the height the object was anchored at, which the placement returns to its caller. */
|
||||
@Override
|
||||
public void anchoredAt(int y) {
|
||||
anchorY = y;
|
||||
}
|
||||
|
||||
int anchorY() {
|
||||
if (anchorY == NOT_ANCHORED) {
|
||||
throw new IllegalStateException("The placement graph placed " + object.getLoadKey() + " without anchoring it");
|
||||
}
|
||||
return anchorY;
|
||||
}
|
||||
}
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.placement.ObjectPlacement;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import com.volmit.placement.PlacementTerrain;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.config.FeatureSettings;
|
||||
import com.volmit.geometry.BlockBox;
|
||||
@@ -44,25 +44,37 @@ final class IrisPlacementInputs implements PlacementContext {
|
||||
private final FeatureSettings settings;
|
||||
private final BlockView blocks;
|
||||
private final Supplier<PackWorld> worldSource;
|
||||
private final ObjectPlacement placement;
|
||||
private final PlacementTerrain placementTerrain;
|
||||
private final Object input;
|
||||
private PackWorld world;
|
||||
|
||||
/**
|
||||
* @param worldSource the world the placement generates in, asked for the first time a stage needs it
|
||||
* @param placement what Iris's built-in placement stages see of the placement as an extension
|
||||
* @param input what the placing module passed for its stages to read
|
||||
*/
|
||||
IrisPlacementInputs(TerrainSampler terrain, FeatureSettings settings, BlockView blocks, Supplier<PackWorld> worldSource,
|
||||
ObjectPlacement placement) {
|
||||
PlacementTerrain placementTerrain, Object input) {
|
||||
this.terrain = terrain;
|
||||
this.settings = settings;
|
||||
this.blocks = blocks;
|
||||
this.worldSource = worldSource;
|
||||
this.placement = placement;
|
||||
this.placementTerrain = placementTerrain;
|
||||
this.input = input;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Optional<T> extension(Class<T> type) {
|
||||
return type == ObjectPlacement.class ? HostExtensions.as(type, placement) : Optional.empty();
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlacementTerrain placementTerrain() {
|
||||
return placementTerrain;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Optional<T> input(Class<T> type) {
|
||||
return type.isInstance(input) ? Optional.of(type.cast(input)) : Optional.empty();
|
||||
}
|
||||
|
||||
/** The world of the engine's runtime, as it is when the placement first asks. */
|
||||
|
||||
@@ -1,222 +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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.anchor.ObjectPlaceMode;
|
||||
import art.arcane.iris.builtin.blocks.ObjectReplace;
|
||||
import art.arcane.iris.builtin.carve.CarvingMode;
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.builtin.placement.MarkerRule;
|
||||
import art.arcane.iris.builtin.spawn.PlacementMarker;
|
||||
import art.arcane.iris.builtin.placement.PlacementSettings;
|
||||
import art.arcane.iris.builtin.prepare.ObjectRotation;
|
||||
import art.arcane.iris.builtin.prepare.ObjectTranslate;
|
||||
import art.arcane.iris.builtin.prepare.SlopeClip;
|
||||
import art.arcane.iris.builtin.stilt.StiltSettings;
|
||||
import art.arcane.iris.builtin.vacuum.VacuumSettings;
|
||||
import art.arcane.iris.builtin.validate.ObjectLimit;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.resource.ResourceId;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/** An object placement's settings as the placement stages read them, its markers and collisions resolved in the pack. */
|
||||
final class IrisPlacementSettings implements PlacementSettings {
|
||||
private final ObjectPlacement config;
|
||||
private final IrisData data;
|
||||
|
||||
IrisPlacementSettings(ObjectPlacement config, IrisData data) {
|
||||
this.config = config;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean forcePlace() {
|
||||
return config.forcePlace();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SlopeClip slopeCondition() {
|
||||
return config.slopeCondition();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean rotateTowardsSlope() {
|
||||
return config.rotateTowardsSlope();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectRotation rotation() {
|
||||
return config.rotation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectTranslate translate() {
|
||||
return config.translate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectPlaceMode mode() {
|
||||
return config.mode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean fromBottom() {
|
||||
return config.fromBottom();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean bottom() {
|
||||
return config.bottom();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CarvingMode carvingSupport() {
|
||||
return config.carvingSupport();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean underwater() {
|
||||
return config.underwater();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onwater() {
|
||||
return config.onwater();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requireSurfaceSupport() {
|
||||
return config.requireSurfaceSupport();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int surfaceSupportBuffer() {
|
||||
return config.surfaceSupportBuffer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int surfaceSupportDepth() {
|
||||
return config.surfaceSupportDepth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectLimit clamp() {
|
||||
return config.clamp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean bore() {
|
||||
return config.bore();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int boreExtendMinY() {
|
||||
return config.boreExtendMinY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int boreExtendMaxY() {
|
||||
return config.boreExtendMaxY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ObjectReplace> edit() {
|
||||
return config.edit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean waterloggable() {
|
||||
return config.waterloggable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean meld() {
|
||||
return config.meld();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MarkerRule> markers() {
|
||||
return config.markers().stream().<MarkerRule>map(marker -> new Marker(marker, data)).toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<StiltSettings> stilt() {
|
||||
return config.stiltSettings();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<VacuumSettings> vacuum() {
|
||||
return config.vacuumSettings();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double snow() {
|
||||
return config.snow();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<ResourceId> allowedCollisions() {
|
||||
return objectIds(config.allowedCollisions());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<ResourceId> forbiddenCollisions() {
|
||||
return objectIds(config.forbiddenCollisions());
|
||||
}
|
||||
|
||||
private Set<ResourceId> objectIds(List<String> keys) {
|
||||
return keys.stream().filter(Objects::nonNull).map(data.getPackResources()::idOf).collect(Collectors.toUnmodifiableSet());
|
||||
}
|
||||
|
||||
private static final class Marker implements MarkerRule {
|
||||
private final PlacementMarker marker;
|
||||
private final IrisData data;
|
||||
|
||||
private Marker(PlacementMarker marker, IrisData data) {
|
||||
this.marker = marker;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String marker() {
|
||||
return marker.marker();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BlockState> targets() {
|
||||
return marker.mark().stream().map(spec -> data.getPackResources().blocks().resolve(spec)).toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exact() {
|
||||
return marker.exact();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int maximum() {
|
||||
return marker.maximumMarkers();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,176 +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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.placement.PlacementTerrain;
|
||||
import art.arcane.iris.builtin.placement.StructureVolumes;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.NativeStructureVolume;
|
||||
import art.arcane.iris.engine.object.placement.IObjectPlacer;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import com.volmit.resource.ResourceId;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* An Iris object placer as the placement stages see their terrain. {@code loader} is the object's data, which the placer
|
||||
* reads heights through; {@code data} is the pack data the placement was asked to run with, whose engine knows the
|
||||
* objects already placed.
|
||||
*/
|
||||
final class IrisPlacementTerrain implements PlacementTerrain {
|
||||
private static final StructureVolumes NO_VOLUMES = new StructureVolumes() {
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean intersects(int minX, int minY, int minZ, int maxX, int maxY, int maxZ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsWithin(int x, int y, int z, int margin) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
private final IObjectPlacer placer;
|
||||
private final IrisData loader;
|
||||
private final IrisData data;
|
||||
|
||||
IrisPlacementTerrain(IObjectPlacer placer, IrisData loader, IrisData data) {
|
||||
this.placer = placer;
|
||||
this.loader = loader;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int highest(int x, int z, boolean ignoreFluid) {
|
||||
return placer.getHighest(x, z, loader, ignoreFluid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCarved(int x, int y, int z) {
|
||||
return placer.isCarved(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSurfaceSolid(int x, int y, int z) {
|
||||
return placer.isSurfaceSolid(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUnderwater(int x, int z) {
|
||||
return placer.isUnderwater(x, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fluidHeight() {
|
||||
return placer.getFluidHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean preventsDecay() {
|
||||
return placer.isPreventingDecay();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean debugsSmartBore() {
|
||||
return placer.isDebugSmartBore();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasWorld() {
|
||||
return placer.getEngine() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double slopeAt(int x, int z) {
|
||||
return engine().getComplex().getSlopeStream().get(x, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double heightAt(double x, double z) {
|
||||
return engine().getComplex().getHeightStream().get(x, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int minWorldY() {
|
||||
return engine().getMinHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int worldHeight() {
|
||||
return engine().getHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public StructureVolumes structureVolumes(int minX, int minZ, int maxX, int maxZ) {
|
||||
KList<NativeStructureVolume> volumes = engine().getNativeStructureVolumes(minX, minZ, maxX, maxZ);
|
||||
if (volumes == null || volumes.isEmpty()) {
|
||||
return NO_VOLUMES;
|
||||
}
|
||||
return new NativeVolumes(volumes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ResourceId> objectAt(int x, int y, int z) {
|
||||
Engine engine = data.getEngine();
|
||||
if (engine == null) {
|
||||
throw new IllegalStateException("Object placement requires active Iris data for collision settings.");
|
||||
}
|
||||
var placed = engine.getObjectPlacement(x, y, z);
|
||||
if (placed == null || placed.getObject() == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(data.getPackResources().idOf(placed.getObject().getLoadKey()));
|
||||
}
|
||||
|
||||
private Engine engine() {
|
||||
Engine engine = placer.getEngine();
|
||||
if (engine == null) {
|
||||
throw new IllegalStateException("This placement runs without an Iris engine, so it has no world");
|
||||
}
|
||||
return engine;
|
||||
}
|
||||
|
||||
private record NativeVolumes(KList<NativeStructureVolume> volumes) implements StructureVolumes {
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean intersects(int minX, int minY, int minZ, int maxX, int maxY, int maxZ) {
|
||||
return volumes.stream().anyMatch(volume -> volume.intersects(minX, minY, minZ, maxX, maxY, maxZ));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsWithin(int x, int y, int z, int margin) {
|
||||
for (NativeStructureVolume volume : volumes) {
|
||||
if (volume.containsWithin(x, y, z, margin)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.objects.ObjectRun;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.object.placement.IrisPlacementForm;
|
||||
import com.volmit.config.FeatureSettings;
|
||||
import com.volmit.geometry.BlockBox;
|
||||
import com.volmit.host.LoadedPack;
|
||||
import com.volmit.host.PlacementRunner;
|
||||
import com.volmit.host.ResolvedGraph;
|
||||
import com.volmit.placement.PlacementOutcome;
|
||||
import com.volmit.placement.PlacementRun;
|
||||
import com.volmit.placement.Placements;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.world.PackWorld;
|
||||
import com.volmit.world.TerrainSampler;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Runs the pack's placement graph for one world with IrisApi's {@link PlacementRunner}: the area widened by the graph's
|
||||
* reach, the writes buffered in a {@link TerrainEdit} over the run's terrain, and the world's terrain, settings and
|
||||
* blocks as the stages' inputs. Without an engine, such as for a studio paste, the stages have no terrain to sample and
|
||||
* no mantle.
|
||||
* <p>
|
||||
* The placement settings the stages read are those of the placed object's placement when the run's input is an
|
||||
* {@link ObjectRun}, which Iris's built-in stages and Iris's own placements pass; other inputs place with none.
|
||||
*/
|
||||
final class IrisPlacements implements Placements {
|
||||
private static final String OBJECT_KIND = "object";
|
||||
private static final String UNNAMED_PLACEMENT = "placement";
|
||||
|
||||
private final IrisData data;
|
||||
private final Engine engine;
|
||||
private final Supplier<PackWorld> world;
|
||||
|
||||
/** @param engine the engine of the world placed in; null for a world Iris does not generate */
|
||||
IrisPlacements(IrisData data, Engine engine, Supplier<PackWorld> world) {
|
||||
this.data = data;
|
||||
this.engine = engine;
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlacementOutcome place(PlacementRun run) {
|
||||
LoadedPack pack = data.getModules().pack();
|
||||
ResolvedGraph graph = pack.placement();
|
||||
BlockBox area = widened(run.area(), graph.reach().blocks());
|
||||
PackResourceIds ids = new PackResourceIds(data.getDataFolder());
|
||||
ResourceId source = ids.of(OBJECT_KIND, placedName(run));
|
||||
ModuleSettings placementSettings = placementSettingsOf(run);
|
||||
TerrainEdit edit = new TerrainEdit(run.terrain(), area, () -> mantle(area, pack));
|
||||
IrisPlacementInputs inputs = new IrisPlacementInputs(terrain(ids, area),
|
||||
new PlacementModuleSettings(worldSettings(ids), placementSettings, source),
|
||||
new TerrainBlockView(run.terrain(), area), world, run.terrain(), run.input());
|
||||
StageMetrics metrics = new StageMetrics(engine != null ? engine.getMetrics() : null);
|
||||
return new PlacementRunner(graph).place(run.request(), edit, inputs, run.seed(), placementSettings.placement(source), metrics);
|
||||
}
|
||||
|
||||
private static BlockBox widened(BlockBox area, int blocks) {
|
||||
return new BlockBox(area.minX() - blocks, area.minY(), area.minZ() - blocks, area.maxX() + blocks, area.maxY(),
|
||||
area.maxZ() + blocks);
|
||||
}
|
||||
|
||||
private static String placedName(PlacementRun run) {
|
||||
return run.input() instanceof ObjectRun objectRun ? objectRun.object().name() : UNNAMED_PLACEMENT;
|
||||
}
|
||||
|
||||
private ModuleSettings placementSettingsOf(PlacementRun run) {
|
||||
if (!(run.input() instanceof ObjectRun objectRun)) {
|
||||
return ModuleSettings.NONE;
|
||||
}
|
||||
return IrisPlacementForm.of(objectRun.settings(), data).moduleSettings();
|
||||
}
|
||||
|
||||
private TerrainSampler terrain(PackResourceIds ids, BlockBox area) {
|
||||
if (engine == null) {
|
||||
return IrisPlacementInputs.noTerrain(area);
|
||||
}
|
||||
return new IrisTerrainSampler(engine, ids, area.minX(), area.minZ(), area.maxX(), area.maxZ());
|
||||
}
|
||||
|
||||
private PlacementMantle mantle(BlockBox area, LoadedPack pack) {
|
||||
if (engine == null) {
|
||||
throw new UnsupportedOperationException("This placement runs without an Iris engine, so it has no mantle");
|
||||
}
|
||||
return new PlacementMantle(engine, area, pack.catalog().mantle());
|
||||
}
|
||||
|
||||
private FeatureSettings worldSettings(PackResourceIds ids) {
|
||||
return engine == null ? PlacementModuleSettings.noWorld() : new ChunkModuleSettings(engine, ids);
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,8 @@ import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.iris.spi.PlatformWorld;
|
||||
import art.arcane.iris.util.common.scheduling.J;
|
||||
import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
|
||||
import art.arcane.volmlib.util.matter.Matter;
|
||||
import art.arcane.volmlib.util.matter.slices.MarkerMatter;
|
||||
import com.volmit.config.FeatureSettings;
|
||||
import com.volmit.geometry.BlockPosition;
|
||||
@@ -110,6 +112,17 @@ final class IrisRunningWorld implements RunningWorld {
|
||||
return known;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> placementAt(int worldX, int y, int worldZ) {
|
||||
MantleChunk<Matter> chunk = engine.getMantle().getMantle().getChunk(worldX >> 4, worldZ >> 4).use();
|
||||
try {
|
||||
String recorded = chunk.get(worldX & 15, y, worldZ & 15, String.class);
|
||||
return recorded == null || recorded.isEmpty() ? Optional.empty() : Optional.of(recorded);
|
||||
} finally {
|
||||
chunk.release();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean debug() {
|
||||
return engine.isStudio();
|
||||
|
||||
@@ -20,10 +20,15 @@ package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.structure.StructureHost;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.structure.StructureResources;
|
||||
import art.arcane.iris.engine.mantle.components.StructurePlacing;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructure;
|
||||
import com.volmit.ModuleLog;
|
||||
import com.volmit.generation.InvocationContext;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/** Iris's {@link StructureHost}: the engine's {@link StructurePlacing}, one per engine runtime, places and sizes its structures. */
|
||||
final class IrisStructureHost implements StructureHost {
|
||||
private final Engine engine;
|
||||
@@ -45,6 +50,18 @@ final class IrisStructureHost implements StructureHost {
|
||||
return placing().reach();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<List<String>> lootTables(String structureKey) {
|
||||
IrisStructure structure = StructureResources.structure(engine.getData().getPackResources(), structureKey);
|
||||
if (structure == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
if (structure.getLoot() == null) {
|
||||
return Optional.of(List.of());
|
||||
}
|
||||
return Optional.of(structure.getLoot().stream().filter(table -> table != null && !table.isBlank()).toList());
|
||||
}
|
||||
|
||||
private StructurePlacing placing() {
|
||||
return engine.getGeneration().state(StructurePlacing.class, generating -> new StructurePlacing(generating, log));
|
||||
}
|
||||
|
||||
@@ -13,6 +13,8 @@ import java.util.function.ToLongFunction;
|
||||
* get the seeds Iris's worlds always used for those features, every other purpose the API's rule.
|
||||
*/
|
||||
final class IrisWorldSeeds {
|
||||
/** Object placements warped their surface with the component seed moved by this much. */
|
||||
private static final long OBJECT_WARP_OFFSET = 1024L;
|
||||
private static final Map<ResourceId, ToLongFunction<SeedManager>> LEGACY_SEEDS = Map.ofEntries(
|
||||
Map.entry(IrisSeedPurposes.BIOME, SeedManager::getBiome),
|
||||
Map.entry(IrisSeedPurposes.CARVE, SeedManager::getCarve),
|
||||
@@ -23,6 +25,7 @@ final class IrisWorldSeeds {
|
||||
Map.entry(IrisSeedPurposes.ENTITY, SeedManager::getEntity),
|
||||
Map.entry(IrisSeedPurposes.LOOT, SeedManager::getLoot),
|
||||
Map.entry(IrisSeedPurposes.MANTLE, SeedManager::getMantle),
|
||||
Map.entry(IrisSeedPurposes.OBJECT_WARP, seeds -> seeds.getComponent() + OBJECT_WARP_OFFSET),
|
||||
Map.entry(IrisSeedPurposes.POST, SeedManager::getPost),
|
||||
Map.entry(IrisSeedPurposes.TERRAIN, SeedManager::getTerrain));
|
||||
|
||||
|
||||
@@ -19,43 +19,28 @@
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.builtin.objects.ObjectRun;
|
||||
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.placement.IObjectPlacer;
|
||||
import art.arcane.iris.engine.object.placement.IrisPlacementForm;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObject;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObjectShaping;
|
||||
import art.arcane.iris.engine.object.terrain.carving.CarveResult;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.config.FeatureSettings;
|
||||
import com.volmit.host.PlacementOutcome;
|
||||
import com.volmit.host.LoadedPack;
|
||||
import com.volmit.host.PlacementRunner;
|
||||
import com.volmit.host.ResolvedGraph;
|
||||
import com.volmit.geometry.BlockBox;
|
||||
import com.volmit.geometry.BlockPosition;
|
||||
import com.volmit.object.GeneratedObject;
|
||||
import com.volmit.placement.PlacementRequest;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.world.TerrainSampler;
|
||||
import com.volmit.placement.PlacementOutcome;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
/**
|
||||
* Places an Iris object by running the pack's placement graph, Iris's built-in placement stages included,
|
||||
* with IrisApi's {@link PlacementRunner}. The writes are buffered and reach the placer only when no stage
|
||||
* rejects the placement.
|
||||
* <p>
|
||||
* Each stage draws from its own stream of one seed per placement, from the world seed and the placement's
|
||||
* identity: the object and the requested position. Without an engine, such as for a studio paste, the placement
|
||||
* runs in a {@link ToolWorld} of its own, whose seed is one draw from the caller's random.
|
||||
* Places an Iris object for Iris's own callers (structures, commands, pastes) through the pack's placement graph, as
|
||||
* {@code PackWorld.placements()} places a module's. The writes reach the placer only when no stage rejects the
|
||||
* placement. Without an engine, such as for a studio paste, the placement runs in a {@link ToolWorld} of its own, whose
|
||||
* seed is one draw from the caller's random.
|
||||
*/
|
||||
public final class ModuleObjectPlacement {
|
||||
private static final String UNNAMED_OBJECT = "unnamed";
|
||||
|
||||
private ModuleObjectPlacement() {
|
||||
}
|
||||
|
||||
@@ -72,67 +57,40 @@ public final class ModuleObjectPlacement {
|
||||
Objects.requireNonNull(config, "Object placement config is required.");
|
||||
Objects.requireNonNull(rng, "Object placement RNG is required.");
|
||||
Objects.requireNonNull(data, "Object placement data is required.");
|
||||
LoadedPack pack = data.getModules().pack();
|
||||
ResolvedGraph graph = pack.placement();
|
||||
IrisPlacementForm form = IrisPlacementForm.of(config, data);
|
||||
GeneratedObject geometry = geometryOf(object, config);
|
||||
BlockBox area = PlacementArea.around(object, geometry, config.translate(), form.warp(), x, z, graph.reach().blocks());
|
||||
PlatformBlockStates states = new PlatformBlockStates(ModuleObjectPlacement::platformState);
|
||||
ObjectPlacerEdit edit = new ObjectPlacerEdit(placer, area, states, listener, () -> mantle(placer.getEngine(), area, pack));
|
||||
IrisPlacement placement = new IrisPlacement(object, config, form, placer, cave, x, requestedY, z, data, states, edit);
|
||||
PackResourceIds ids = new PackResourceIds(data.getDataFolder());
|
||||
String objectKey = keyOf(object);
|
||||
Engine engine = placer.getEngine();
|
||||
long worldSeed = engine != null ? engine.getSeedManager().getSeed() : rng.nextLong();
|
||||
ResourceId source = ids.of("object", objectKey);
|
||||
PlacementRequest request = new PlacementRequest(geometry, new BlockPosition(x, requestedY, z));
|
||||
long seed = ModuleSeeds.placement(worldSeed, objectKey, x, requestedY, z);
|
||||
StageMetrics metrics = new StageMetrics(engine != null ? engine.getMetrics() : null);
|
||||
try (ToolWorld toolWorld = engine == null ? new ToolWorld(worldSeed, data.getPackResources(), new PackDeclaredSettings(data)) : null) {
|
||||
IrisPlacementInputs inputs = new IrisPlacementInputs(terrain(engine, ids, area),
|
||||
new PlacementModuleSettings(worldSettings(engine, ids), form.moduleSettings(), source),
|
||||
new PlacerBlockView(placer, area, states), engine != null ? IrisPlacementInputs.worldOf(engine) : () -> toolWorld,
|
||||
placement);
|
||||
PlacementOutcome outcome = new PlacementRunner(graph)
|
||||
.place(request, edit, inputs, seed, form.moduleSettings().placement(source), metrics);
|
||||
return outcome.isPlaced()
|
||||
? ObjectPlacementResult.placed(placement.anchorY())
|
||||
: ObjectPlacementResult.rejected(outcome.rejection().orElseThrow());
|
||||
PlacerTerrain terrain = listener == null ? PlacerTerrain.of(placer, data) : PlacerTerrain.rememberingWrites(placer, data);
|
||||
ObjectRun run = cave == null
|
||||
? ObjectRun.of(object, config, x, requestedY, z)
|
||||
: ObjectRun.inCave(object, config, x, requestedY, z, new ObjectRun.Cave(cave.getSurface(), cave.getHeight()));
|
||||
PlacementOutcome outcome = placeIn(run, terrain, placer.getEngine(), rng, data);
|
||||
if (!outcome.isPlaced()) {
|
||||
return ObjectPlacementResult.rejected(outcome.rejection().orElseThrow());
|
||||
}
|
||||
reportObjectBlocks(run, terrain, listener);
|
||||
int anchorY = run.anchorY().orElseThrow(() -> new IllegalStateException(
|
||||
"The placement graph placed " + object.name() + " without anchoring it"));
|
||||
return ObjectPlacementResult.placed(anchorY);
|
||||
}
|
||||
|
||||
private static PlacementOutcome placeIn(ObjectRun run, PlacerTerrain terrain, Engine engine, RNG rng, IrisData data) {
|
||||
if (engine != null) {
|
||||
IrisPlacements placements = new IrisPlacements(data, engine, IrisPlacementInputs.worldOf(engine));
|
||||
return placements.place(run.toRun(terrain, engine.getSeedManager().getSeed(), data.getPackResources().objects()));
|
||||
}
|
||||
long worldSeed = rng.nextLong();
|
||||
try (ToolWorld toolWorld = new ToolWorld(worldSeed, data.getPackResources(), new PackDeclaredSettings(data),
|
||||
world -> new IrisPlacements(data, null, () -> world), new IrisLegacyStreams(data, new SeedManager(worldSeed)))) {
|
||||
return run.placeIn(toolWorld, terrain);
|
||||
}
|
||||
}
|
||||
|
||||
/** Smart boring adds the object's bored air, so it has to happen before the geometry is read. */
|
||||
private static GeneratedObject geometryOf(IrisObject object, ObjectPlacement config) {
|
||||
if (config.smartBore()) {
|
||||
IrisObjectShaping.ensureSmartBored(object);
|
||||
private static void reportObjectBlocks(ObjectRun run, PlacerTerrain terrain,
|
||||
BiConsumer<art.arcane.volmlib.util.math.BlockPosition, PlatformBlockState> listener) {
|
||||
if (listener == null) {
|
||||
return;
|
||||
}
|
||||
return object.getGeometry();
|
||||
}
|
||||
|
||||
private static TerrainSampler terrain(Engine engine, PackResourceIds ids, BlockBox area) {
|
||||
if (engine == null) {
|
||||
return IrisPlacementInputs.noTerrain(area);
|
||||
for (BlockPosition position : run.objectBlocks()) {
|
||||
listener.accept(new art.arcane.volmlib.util.math.BlockPosition(position.x(), position.y(), position.z()),
|
||||
terrain.writtenState(position));
|
||||
}
|
||||
return new IrisTerrainSampler(engine, ids, area.minX(), area.minZ(), area.maxX(), area.maxZ());
|
||||
}
|
||||
|
||||
private static PlacementMantle mantle(Engine engine, BlockBox area, LoadedPack pack) {
|
||||
if (engine == null) {
|
||||
throw new UnsupportedOperationException("This placement runs without an Iris engine, so it has no mantle");
|
||||
}
|
||||
return new PlacementMantle(engine, area, pack.catalog().mantle());
|
||||
}
|
||||
|
||||
private static FeatureSettings worldSettings(Engine engine, PackResourceIds ids) {
|
||||
return engine == null ? PlacementModuleSettings.noWorld() : new ChunkModuleSettings(engine, ids);
|
||||
}
|
||||
|
||||
/** Resolved by the platform bound now, so a rebound platform never answers with another's states. */
|
||||
private static PlatformBlockState platformState(String key) {
|
||||
return IrisPlatforms.get().registries().block(key);
|
||||
}
|
||||
|
||||
private static String keyOf(IrisObject object) {
|
||||
return object.getLoadKey() == null ? UNNAMED_OBJECT : object.getLoadKey();
|
||||
}
|
||||
}
|
||||
@@ -18,19 +18,13 @@
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* The seed of one module invocation: a chunk from the world seed and the chunk position, a placement
|
||||
* from the world seed and the placement's identity. IrisApi derives each stage's stream from it and the
|
||||
* stage id.
|
||||
* The seed of one chunk's module invocation, from the world seed and the chunk position. IrisApi derives each stage's
|
||||
* stream from it and the stage id. A placement's seed comes with its run ({@code PlacementRun.seed()}).
|
||||
*/
|
||||
final class ModuleSeeds {
|
||||
private static final long X_MULTIPLIER = 0x9E3779B97F4A7C15L;
|
||||
private static final long Z_MULTIPLIER = 0xC2B2AE3D27D4EB4FL;
|
||||
private static final long Y_MULTIPLIER = 0x165667B19E3779F9L;
|
||||
private static final long FNV_OFFSET_BASIS = 0xCBF29CE484222325L;
|
||||
private static final long FNV_PRIME = 0x100000001B3L;
|
||||
|
||||
private ModuleSeeds() {
|
||||
}
|
||||
@@ -38,17 +32,4 @@ final class ModuleSeeds {
|
||||
static long chunk(long worldSeed, int chunkX, int chunkZ) {
|
||||
return worldSeed ^ (chunkX * X_MULTIPLIER) ^ (chunkZ * Z_MULTIPLIER);
|
||||
}
|
||||
|
||||
/** {@code y} is the requested height, negative when the placement samples it. */
|
||||
static long placement(long worldSeed, String objectKey, int x, int y, int z) {
|
||||
return worldSeed ^ fnv1a(objectKey) ^ (x * X_MULTIPLIER) ^ (y * Y_MULTIPLIER) ^ (z * Z_MULTIPLIER);
|
||||
}
|
||||
|
||||
private static long fnv1a(String text) {
|
||||
long hash = FNV_OFFSET_BASIS;
|
||||
for (byte value : text.getBytes(StandardCharsets.UTF_8)) {
|
||||
hash = (hash ^ (value & 0xFF)) * FNV_PRIME;
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
@@ -82,13 +82,19 @@ public final class ModuleSettings {
|
||||
* @param dimensionKey that dimension's key
|
||||
*/
|
||||
public Set<String> usedBiomes(IrisPackResources resources, ModuleSettings dimension, String dimensionKey) {
|
||||
PackSettings declared = dimension.declaredByDimension(() -> resources.idOf(IrisPackSettings.DIMENSION + "/" + dimensionKey));
|
||||
PackSettings declared = dimension.declaredByDimension(resources,
|
||||
() -> resources.idOf(IrisPackSettings.DIMENSION + "/" + dimensionKey));
|
||||
return linkedBiomes(resources, linked -> linked.usedBiomes(resources, declared));
|
||||
}
|
||||
|
||||
/** These settings as what a dimension declares itself: each type a stack of at most its dimension entry. */
|
||||
private PackSettings declaredByDimension(Supplier<ResourceId> dimension) {
|
||||
private PackSettings declaredByDimension(PackResources resources, Supplier<ResourceId> dimension) {
|
||||
return new PackSettings() {
|
||||
@Override
|
||||
public PackResources resources() {
|
||||
return resources;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <F extends IrisFeature> SettingsStack<F> declared(Class<F> featureType) {
|
||||
return find(featureType)
|
||||
|
||||
@@ -26,6 +26,7 @@ import com.volmit.IrisFeature;
|
||||
import com.volmit.config.FeatureSettings.Entry;
|
||||
import com.volmit.config.PackSettings;
|
||||
import com.volmit.config.SettingsStack;
|
||||
import com.volmit.resource.PackResources;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -45,6 +46,11 @@ final class PackDeclaredSettings implements PackSettings {
|
||||
this.ids = new PackResourceIds(data.getDataFolder());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackResources resources() {
|
||||
return data.getPackResources();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <F extends IrisFeature> SettingsStack<F> declared(Class<F> featureType) {
|
||||
List<Entry<F>> entries = new ArrayList<>();
|
||||
|
||||
@@ -1,79 +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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.prepare.ObjectTranslate;
|
||||
import art.arcane.iris.engine.object.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObject;
|
||||
import com.volmit.geometry.BlockBox;
|
||||
import com.volmit.object.GeneratedObject;
|
||||
|
||||
/**
|
||||
* The columns one object placement may read and write: every column the object reaches in any rotation
|
||||
* around its anchor, moved by its translation and surface warp, widened by one block for neighbor reads and
|
||||
* by the placement pipeline's reach. The object reaches as far as its blocks or its declared size, whichever
|
||||
* is larger, since boring and terrain bends cover the declared size. Heights are not bounded; the placer
|
||||
* keeps writes inside its world.
|
||||
*/
|
||||
final class PlacementArea {
|
||||
private static final int NEIGHBOR_READ_BLOCKS = 1;
|
||||
|
||||
private PlacementArea() {
|
||||
}
|
||||
|
||||
static BlockBox around(IrisObject object, GeneratedObject geometry, ObjectTranslate translate, IrisGeneratorStyle warp,
|
||||
int x, int z, int pipelineReachBlocks) {
|
||||
int objectRadius = Math.max(rotationRadius(geometry.bounds()), rotationRadius(declaredBox(object)));
|
||||
int reach = objectRadius + translationLength(translate)
|
||||
+ warpMargin(warp) + NEIGHBOR_READ_BLOCKS + pipelineReachBlocks;
|
||||
return new BlockBox(x - reach, Integer.MIN_VALUE, z - reach, x + reach + 1, Integer.MAX_VALUE, z + reach + 1);
|
||||
}
|
||||
|
||||
/** The object's declared size around its center, which its block offsets count from. */
|
||||
private static BlockBox declaredBox(IrisObject object) {
|
||||
int centerX = object.getCenter().getBlockX();
|
||||
int centerY = object.getCenter().getBlockY();
|
||||
int centerZ = object.getCenter().getBlockZ();
|
||||
return new BlockBox(-centerX, -centerY, -centerZ,
|
||||
Math.max(1, object.getW()) - centerX, Math.max(1, object.getH()) - centerY, Math.max(1, object.getD()) - centerZ);
|
||||
}
|
||||
|
||||
/** The farthest any block of {@code bounds} lies from the origin, which rotations turn around. */
|
||||
private static int rotationRadius(BlockBox bounds) {
|
||||
long x = farthest(bounds.minX(), bounds.maxX());
|
||||
long y = farthest(bounds.minY(), bounds.maxY());
|
||||
long z = farthest(bounds.minZ(), bounds.maxZ());
|
||||
return (int) Math.ceil(Math.sqrt(x * x + y * y + z * z));
|
||||
}
|
||||
|
||||
private static long farthest(int min, int maxExclusive) {
|
||||
return Math.max(Math.abs((long) min), Math.abs((long) maxExclusive - 1));
|
||||
}
|
||||
|
||||
private static int translationLength(ObjectTranslate translate) {
|
||||
long x = translate.x();
|
||||
long y = translate.y();
|
||||
long z = translate.z();
|
||||
return (int) Math.ceil(Math.sqrt(x * x + y * y + z * z));
|
||||
}
|
||||
|
||||
private static int warpMargin(IrisGeneratorStyle warp) {
|
||||
return warp.isFlat() ? 0 : (int) Math.ceil(Math.abs(warp.getMultiplier()) / 2D);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,241 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.blocks.ObjectMarkers;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.NativeStructureVolume;
|
||||
import art.arcane.iris.engine.framework.PlacedObject;
|
||||
import art.arcane.iris.engine.framework.TreeBlockMaterial;
|
||||
import art.arcane.iris.engine.object.placement.IObjectPlacer;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.matter.MatterMarker;
|
||||
import art.arcane.volmlib.util.matter.MatterStructurePOI;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.geometry.BlockPosition;
|
||||
import com.volmit.object.BlockEntityData;
|
||||
import com.volmit.placement.PlacedMarker;
|
||||
import com.volmit.placement.PlacementTerrain;
|
||||
import com.volmit.placement.StructureVolumes;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* An Iris object placer as a placement's terrain: the mantle a module stage writes, or the world a command or a structure
|
||||
* pastes into. States convert through one {@link PlatformBlockStates}, so a block read and written back keeps its
|
||||
* platform identity. Markers are kept in Iris's mantle form: a pack marker as a {@link MatterMarker}, tree material as a
|
||||
* {@link TreeBlockMaterial} of the block written there, buried treasure as a structure point of interest. Meant for one
|
||||
* invocation; not thread-safe.
|
||||
*/
|
||||
final class PlacerTerrain implements PlacementTerrain {
|
||||
private static final StructureVolumes NO_VOLUMES = new StructureVolumes() {
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean intersects(int minX, int minY, int minZ, int maxX, int maxY, int maxZ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsWithin(int x, int y, int z, int margin) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
private static final char PLACEMENT_ID_SEPARATOR = '@';
|
||||
|
||||
private final IObjectPlacer placer;
|
||||
private final IrisData data;
|
||||
private final PlatformBlockStates states = new PlatformBlockStates(PlacerTerrain::platformState);
|
||||
private final Map<BlockPosition, PlatformBlockState> written;
|
||||
|
||||
private PlacerTerrain(IObjectPlacer placer, IrisData data, Map<BlockPosition, PlatformBlockState> written) {
|
||||
this.placer = placer;
|
||||
this.data = data;
|
||||
this.written = written;
|
||||
}
|
||||
|
||||
/** {@code data} is the pack the placer reads heights with. */
|
||||
static PlacerTerrain of(IObjectPlacer placer, IrisData data) {
|
||||
return new PlacerTerrain(placer, data, null);
|
||||
}
|
||||
|
||||
/** As {@link #of}, remembering the platform state of each block written ({@link #writtenState}). */
|
||||
static PlacerTerrain rememberingWrites(IObjectPlacer placer, IrisData data) {
|
||||
return new PlacerTerrain(placer, data, new HashMap<>());
|
||||
}
|
||||
|
||||
/** The platform state last written at the block; null when none was, or when this terrain does not remember writes. */
|
||||
PlatformBlockState writtenState(BlockPosition position) {
|
||||
return written == null ? null : written.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int highest(int x, int z, boolean ignoreFluid) {
|
||||
return placer.getHighest(x, z, data, ignoreFluid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState get(int x, int y, int z) {
|
||||
return states.toApi(placer.get(x, y, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(int x, int y, int z, BlockState state) {
|
||||
write(x, y, z, states.toPlatform(state));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(int x, int y, int z, BlockState state, BlockEntityData blockEntity) {
|
||||
write(x, y, z, states.toPlatform(state));
|
||||
placer.setTile(x, y, z, BlockEntities.tileOf(blockEntity));
|
||||
}
|
||||
|
||||
private void write(int x, int y, int z, PlatformBlockState state) {
|
||||
placer.set(x, y, z, state);
|
||||
if (written != null) {
|
||||
written.put(new BlockPosition(x, y, z), state);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCarved(int x, int y, int z) {
|
||||
return placer.isCarved(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSurfaceSolid(int x, int y, int z) {
|
||||
return placer.isSurfaceSolid(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUnderwater(int x, int z) {
|
||||
return placer.isUnderwater(x, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fluidHeight() {
|
||||
return placer.getFluidHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean preventsDecay() {
|
||||
return placer.isPreventingDecay();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordPlacement(int x, int y, int z, String placement) {
|
||||
placer.setData(x, y, z, placement);
|
||||
}
|
||||
|
||||
/**
|
||||
* The object Iris finds placed at the block, as its object lookup finds it ({@link Engine#getObjectPlacement}): a
|
||||
* structure piece, or an object a placement of the column's region or biome places. Other records, such as a
|
||||
* procedural object's, read as no placement, so placements collide with what they collided with before.
|
||||
*/
|
||||
@Override
|
||||
public Optional<String> placementAt(int x, int y, int z) {
|
||||
Engine engine = data.getEngine();
|
||||
if (engine == null) {
|
||||
throw new IllegalStateException("Object placement requires active Iris data for collision settings.");
|
||||
}
|
||||
PlacedObject placed = engine.getObjectPlacement(x, y, z);
|
||||
if (placed == null || placed.getObject() == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(placed.getObject().getLoadKey() + PLACEMENT_ID_SEPARATOR + placed.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public StructureVolumes structureVolumes(int minX, int minZ, int maxX, int maxZ) {
|
||||
Engine engine = placer.getEngine();
|
||||
if (engine == null) {
|
||||
throw new IllegalStateException("This placement runs without an Iris engine, so it has no world");
|
||||
}
|
||||
KList<NativeStructureVolume> volumes = engine.getNativeStructureVolumes(minX, minZ, maxX, maxZ);
|
||||
if (volumes == null || volumes.isEmpty()) {
|
||||
return NO_VOLUMES;
|
||||
}
|
||||
return new NativeVolumes(volumes, engine.getMinHeight());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mark(PlacedMarker marker) {
|
||||
BlockPosition position = marker.position();
|
||||
int x = position.x();
|
||||
int y = position.y();
|
||||
int z = position.z();
|
||||
if (marker.type().equals(ObjectMarkers.TREE_MATERIAL)) {
|
||||
placer.setData(x, y, z, TreeBlockMaterial.of(placer.get(x, y, z)));
|
||||
return;
|
||||
}
|
||||
if (marker.type().equals(ObjectMarkers.BURIED_TREASURE)) {
|
||||
placer.setData(x, y, z, MatterStructurePOI.BURIED_TREASURE);
|
||||
return;
|
||||
}
|
||||
placer.setData(x, y, z, new MatterMarker(ObjectMarkers.markerKey(marker)));
|
||||
}
|
||||
|
||||
/** Resolved by the platform bound now, so a rebound platform never answers with another's states. */
|
||||
private static PlatformBlockState platformState(String key) {
|
||||
return IrisPlatforms.get().registries().block(key);
|
||||
}
|
||||
|
||||
/** The engine's volumes, which are in world heights, asked in heights above the dimension's bottom at {@code bottomY}. */
|
||||
private record NativeVolumes(KList<NativeStructureVolume> volumes, int bottomY) implements StructureVolumes {
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean intersects(int minX, int minY, int minZ, int maxX, int maxY, int maxZ) {
|
||||
int worldMinY = worldY(minY);
|
||||
int worldMaxY = worldY(maxY);
|
||||
return volumes.stream().anyMatch(volume -> volume.intersects(minX, worldMinY, minZ, maxX, worldMaxY, maxZ));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsWithin(int x, int y, int z, int margin) {
|
||||
int worldY = worldY(y);
|
||||
for (NativeStructureVolume volume : volumes) {
|
||||
if (volume.containsWithin(x, worldY, z, margin)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** An unbounded height stays unbounded. */
|
||||
private int worldY(int height) {
|
||||
if (height == Integer.MIN_VALUE || height == Integer.MAX_VALUE) {
|
||||
return height;
|
||||
}
|
||||
return height + bottomY;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,43 +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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.builtin.objects.ProceduralPlacement;
|
||||
|
||||
/** The options a procedural object is scattered with, as an object placement. */
|
||||
public final class ProceduralOptions {
|
||||
private ProceduralOptions() {
|
||||
}
|
||||
|
||||
public static ObjectPlacement of(ProceduralPlacement procedural) {
|
||||
return ObjectPlacement.builder()
|
||||
.mode(procedural.mode())
|
||||
.rotation(procedural.rotation())
|
||||
.clamp(procedural.clamp())
|
||||
.carvingSupport(procedural.carvingSupport())
|
||||
.underwater(procedural.underwater())
|
||||
.translate(procedural.translate())
|
||||
.stiltSettings(procedural.stiltSettings().orElse(null))
|
||||
.vacuumSettings(procedural.vacuumSettings().orElse(null))
|
||||
.chance(procedural.chance())
|
||||
.density(procedural.density())
|
||||
.surfaceSupportBuffer(procedural.surfaceSupportBuffer())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -1,112 +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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.objects.ObjectSink;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.object.placement.IObjectPlacer;
|
||||
import art.arcane.iris.engine.object.prefab.TileData;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
|
||||
/** An {@link ObjectSink}, which sees blocks as IrisApi's, as the placer an Iris object places into. */
|
||||
final class SinkPlacer implements IObjectPlacer {
|
||||
private final Engine engine;
|
||||
private final ObjectSink sink;
|
||||
private final PlatformBlockStates states = new PlatformBlockStates(key -> IrisPlatforms.get().registries().block(key));
|
||||
|
||||
SinkPlacer(Engine engine, ObjectSink sink) {
|
||||
this.engine = engine;
|
||||
this.sink = sink;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHighest(int x, int z, IrisData data) {
|
||||
return sink.highest(x, z, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHighest(int x, int z, IrisData data, boolean ignoreFluid) {
|
||||
return sink.highest(x, z, ignoreFluid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(int x, int y, int z, PlatformBlockState state) {
|
||||
sink.set(x, y, z, states.toApi(state));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformBlockState get(int x, int y, int z) {
|
||||
return states.toPlatform(sink.get(x, y, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPreventingDecay() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCarved(int x, int y, int z) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSurfaceSolid(int x, int y, int z) {
|
||||
return isSolid(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSolid(int x, int y, int z) {
|
||||
return get(x, y, z).isSolid();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUnderwater(int x, int z) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFluidHeight() {
|
||||
return sink.fluidHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebugSmartBore() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTile(int xx, int yy, int zz, TileData tile) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> void setData(int xx, int yy, int zz, T data) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getData(int xx, int yy, int zz, Class<T> t) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Engine getEngine() {
|
||||
return engine;
|
||||
}
|
||||
}
|
||||
+7
-12
@@ -18,24 +18,19 @@
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.engine.object.placement.IObjectPlacer;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.geometry.BlockBox;
|
||||
import com.volmit.placement.PlacementTerrain;
|
||||
import com.volmit.world.BlockView;
|
||||
|
||||
/**
|
||||
* The blocks an Iris object placer holds before a placement's writes, within the placement area. The placer's
|
||||
* heights count from the dimension's bottom, like IrisApi's.
|
||||
*/
|
||||
final class PlacerBlockView implements BlockView {
|
||||
private final IObjectPlacer placer;
|
||||
/** The blocks a placement's terrain holds before the placement's writes, within the placement area. */
|
||||
final class TerrainBlockView implements BlockView {
|
||||
private final PlacementTerrain terrain;
|
||||
private final BlockBox bounds;
|
||||
private final PlatformBlockStates states;
|
||||
|
||||
PlacerBlockView(IObjectPlacer placer, BlockBox bounds, PlatformBlockStates states) {
|
||||
this.placer = placer;
|
||||
TerrainBlockView(PlacementTerrain terrain, BlockBox bounds) {
|
||||
this.terrain = terrain;
|
||||
this.bounds = bounds;
|
||||
this.states = states;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -48,6 +43,6 @@ final class PlacerBlockView implements BlockView {
|
||||
if (!bounds.contains(worldX, y, worldZ)) {
|
||||
throw new IndexOutOfBoundsException("Block " + worldX + ", " + y + ", " + worldZ + " is outside the placement area " + bounds);
|
||||
}
|
||||
return states.toApi(placer.get(worldX, y, worldZ));
|
||||
return terrain.get(worldX, y, worldZ);
|
||||
}
|
||||
}
|
||||
+16
-49
@@ -18,10 +18,6 @@
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.blocks.ObjectMarkers;
|
||||
import art.arcane.iris.engine.object.placement.IObjectPlacer;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.volmlib.util.matter.MatterMarker;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.geometry.BlockBox;
|
||||
import com.volmit.geometry.BlockPosition;
|
||||
@@ -30,6 +26,7 @@ import com.volmit.object.BlockEntityData;
|
||||
import com.volmit.placement.PlacedBlock;
|
||||
import com.volmit.placement.PlacedMarker;
|
||||
import com.volmit.placement.PlacementEdit;
|
||||
import com.volmit.placement.PlacementTerrain;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -37,43 +34,34 @@ import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* One placement's writes, buffered over an Iris object placer until IrisApi commits them. Reads see the
|
||||
* buffered writes. Committing writes blocks in the order they were first set, then their tile data and
|
||||
* markers, then reports the object's own blocks to the caller's listener. The placer offers no rollback,
|
||||
* so a placer that fails part way through a commit keeps the writes before the failure.
|
||||
* One placement's writes, buffered over a placement's terrain until IrisApi commits them. Reads see the buffered
|
||||
* writes. Committing writes the mantle first, then blocks in the order they were first set, each with its block
|
||||
* entity, then the markers. The terrain offers no rollback, so a terrain that fails part way through a commit keeps
|
||||
* the writes before the failure.
|
||||
*/
|
||||
final class ObjectPlacerEdit implements PlacementEdit {
|
||||
final class TerrainEdit implements PlacementEdit {
|
||||
private enum State { OPEN, COMMITTED, FAILED, CLOSED }
|
||||
|
||||
private final IObjectPlacer placer;
|
||||
private final PlacementTerrain terrain;
|
||||
private final BlockBox bounds;
|
||||
private final PlatformBlockStates states;
|
||||
private final BiConsumer<art.arcane.volmlib.util.math.BlockPosition, PlatformBlockState> listener;
|
||||
private final Supplier<PlacementMantle> mantleSource;
|
||||
private final Map<BlockPosition, BlockState> blocks = new LinkedHashMap<>();
|
||||
private final Map<BlockPosition, BlockEntityData> blockEntities = new HashMap<>();
|
||||
private final List<PlacedMarker> markers = new ArrayList<>();
|
||||
private final List<BlockPosition> objectBlocks = new ArrayList<>();
|
||||
private PlacementMantle mantle;
|
||||
private State state = State.OPEN;
|
||||
|
||||
/**
|
||||
* {@code listener} hears each object block after the commit, as Iris placements report them; null for none.
|
||||
* {@code mantleSource} makes the placement's mantle the first time a stage asks for it, and fails when the
|
||||
* placement has none.
|
||||
*/
|
||||
ObjectPlacerEdit(IObjectPlacer placer, BlockBox bounds, PlatformBlockStates states,
|
||||
BiConsumer<art.arcane.volmlib.util.math.BlockPosition, PlatformBlockState> listener,
|
||||
Supplier<PlacementMantle> mantleSource) {
|
||||
this.mantleSource = mantleSource;
|
||||
this.placer = placer;
|
||||
TerrainEdit(PlacementTerrain terrain, BlockBox bounds, Supplier<PlacementMantle> mantleSource) {
|
||||
this.terrain = terrain;
|
||||
this.bounds = bounds;
|
||||
this.states = states;
|
||||
this.listener = listener;
|
||||
this.mantleSource = mantleSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -86,7 +74,7 @@ final class ObjectPlacerEdit implements PlacementEdit {
|
||||
public BlockState get(int x, int y, int z) {
|
||||
requireInside(x, y, z);
|
||||
BlockState buffered = blocks.get(new BlockPosition(x, y, z));
|
||||
return buffered != null ? buffered : states.toApi(placer.get(x, y, z));
|
||||
return buffered != null ? buffered : terrain.get(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -113,7 +101,6 @@ final class ObjectPlacerEdit implements PlacementEdit {
|
||||
public void marker(PlacedMarker marker) {
|
||||
BlockPosition position = marker.position();
|
||||
requireInside(position.x(), position.y(), position.z());
|
||||
ObjectMarkers.requireIrisMarker(marker);
|
||||
markers.add(marker);
|
||||
}
|
||||
|
||||
@@ -126,12 +113,6 @@ final class ObjectPlacerEdit implements PlacementEdit {
|
||||
return mantle;
|
||||
}
|
||||
|
||||
/** Marks a buffered write as one of the object's own blocks, which the listener hears after the commit. */
|
||||
void recordObjectBlock(BlockPosition position) {
|
||||
requireOpen();
|
||||
objectBlocks.add(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void commit() {
|
||||
requireOpen();
|
||||
@@ -139,7 +120,6 @@ final class ObjectPlacerEdit implements PlacementEdit {
|
||||
commitMantle();
|
||||
writeBlocks();
|
||||
writeMarkers();
|
||||
reportObjectBlocks();
|
||||
state = State.COMMITTED;
|
||||
}
|
||||
|
||||
@@ -149,7 +129,6 @@ final class ObjectPlacerEdit implements PlacementEdit {
|
||||
blocks.clear();
|
||||
blockEntities.clear();
|
||||
markers.clear();
|
||||
objectBlocks.clear();
|
||||
state = State.CLOSED;
|
||||
}
|
||||
|
||||
@@ -168,29 +147,17 @@ final class ObjectPlacerEdit implements PlacementEdit {
|
||||
|
||||
private void writeBlocks() {
|
||||
blocks.forEach((position, block) -> {
|
||||
placer.set(position.x(), position.y(), position.z(), states.toPlatform(block));
|
||||
BlockEntityData entity = blockEntities.get(position);
|
||||
if (entity != null) {
|
||||
placer.setTile(position.x(), position.y(), position.z(), BlockEntities.tileOf(entity));
|
||||
if (entity == null) {
|
||||
terrain.set(position.x(), position.y(), position.z(), block);
|
||||
} else {
|
||||
terrain.set(position.x(), position.y(), position.z(), block, entity);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void writeMarkers() {
|
||||
for (PlacedMarker marker : markers) {
|
||||
BlockPosition position = marker.position();
|
||||
placer.setData(position.x(), position.y(), position.z(), new MatterMarker(ObjectMarkers.markerKey(marker)));
|
||||
}
|
||||
}
|
||||
|
||||
private void reportObjectBlocks() {
|
||||
if (listener == null) {
|
||||
return;
|
||||
}
|
||||
for (BlockPosition position : objectBlocks) {
|
||||
listener.accept(new art.arcane.volmlib.util.math.BlockPosition(position.x(), position.y(), position.z()),
|
||||
states.toPlatform(blocks.get(position)));
|
||||
}
|
||||
markers.forEach(terrain::mark);
|
||||
}
|
||||
|
||||
private void requireInside(int x, int y, int z) {
|
||||
@@ -18,10 +18,12 @@
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.LegacyStreams;
|
||||
import art.arcane.iris.engine.framework.SeedManager;
|
||||
import com.volmit.ModuleLog;
|
||||
import com.volmit.config.PackSettings;
|
||||
import com.volmit.host.WorldStates;
|
||||
import com.volmit.placement.Placements;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.world.PackWorld;
|
||||
@@ -41,13 +43,19 @@ final class ToolWorld implements PackWorld, AutoCloseable {
|
||||
private final PackSettings settings;
|
||||
private final WorldStates states;
|
||||
private final ModuleLog log;
|
||||
private final Placements placements;
|
||||
private final LegacyStreams legacyStreams;
|
||||
|
||||
ToolWorld(long seed, PackResources resources, PackSettings settings) {
|
||||
/** {@code placements} makes the placements of the new world; {@code legacyStreams} are offered as its extension. */
|
||||
ToolWorld(long seed, PackResources resources, PackSettings settings, Function<PackWorld, Placements> placements,
|
||||
LegacyStreams legacyStreams) {
|
||||
this.legacyStreams = legacyStreams;
|
||||
this.seeds = new SeedManager(seed);
|
||||
this.resources = resources;
|
||||
this.settings = settings;
|
||||
this.states = new WorldStates();
|
||||
this.log = IrisApiLogger.hostLog();
|
||||
this.placements = placements.apply(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -82,6 +90,16 @@ final class ToolWorld implements PackWorld, AutoCloseable {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Placements placements() {
|
||||
return placements;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Optional<T> extension(Class<T> type) {
|
||||
return type == LegacyStreams.class ? HostExtensions.as(type, legacyStreams) : Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T state(Class<T> type, Function<? super PackWorld, ? extends T> create) {
|
||||
return states.state(type, () -> create.apply(this));
|
||||
|
||||
-104
@@ -1,104 +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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.framework.placer;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.object.noise.IrisNoiseGenerator;
|
||||
import art.arcane.iris.engine.object.placement.IObjectPlacer;
|
||||
import art.arcane.iris.engine.object.prefab.TileData;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
public class HeightmapObjectPlacer implements IObjectPlacer {
|
||||
private final long s;
|
||||
private final IrisNoiseGenerator heightmap;
|
||||
private final IObjectPlacer oplacer;
|
||||
|
||||
public HeightmapObjectPlacer(RNG rng, int x, int yv, int z, IrisNoiseGenerator heightmap, IObjectPlacer oplacer) {
|
||||
s = rng.nextLong() + yv + z - x;
|
||||
this.heightmap = heightmap;
|
||||
this.oplacer = oplacer;
|
||||
}
|
||||
|
||||
public int getHighest(int param1Int1, int param1Int2, IrisData data) {
|
||||
return (int) Math.round(heightmap.getNoise(this.s, param1Int1, param1Int2, data));
|
||||
}
|
||||
|
||||
public int getHighest(int param1Int1, int param1Int2, IrisData data, boolean param1Boolean) {
|
||||
return (int) Math.round(heightmap.getNoise(this.s, param1Int1, param1Int2, data));
|
||||
}
|
||||
|
||||
public void set(int param1Int1, int param1Int2, int param1Int3, PlatformBlockState param1BlockData) {
|
||||
oplacer.set(param1Int1, param1Int2, param1Int3, param1BlockData);
|
||||
}
|
||||
|
||||
public PlatformBlockState get(int param1Int1, int param1Int2, int param1Int3) {
|
||||
return oplacer.get(param1Int1, param1Int2, param1Int3);
|
||||
}
|
||||
|
||||
public boolean isPreventingDecay() {
|
||||
return oplacer.isPreventingDecay();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCarved(int x, int y, int z) {
|
||||
return oplacer.isCarved(x,y,z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSurfaceSolid(int x, int y, int z) {
|
||||
return oplacer.isSurfaceSolid(x, y, z);
|
||||
}
|
||||
|
||||
public boolean isSolid(int param1Int1, int param1Int2, int param1Int3) {
|
||||
return oplacer.isSolid(param1Int1, param1Int2, param1Int3);
|
||||
}
|
||||
|
||||
public boolean isUnderwater(int param1Int1, int param1Int2) {
|
||||
return oplacer.isUnderwater(param1Int1, param1Int2);
|
||||
}
|
||||
|
||||
public int getFluidHeight() {
|
||||
return oplacer.getFluidHeight();
|
||||
}
|
||||
|
||||
public boolean isDebugSmartBore() {
|
||||
return oplacer.isDebugSmartBore();
|
||||
}
|
||||
|
||||
public void setTile(int param1Int1, int param1Int2, int param1Int3, TileData param1TileData) {
|
||||
oplacer.setTile(param1Int1, param1Int2, param1Int3, param1TileData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> void setData(int xx, int yy, int zz, T data) {
|
||||
oplacer.setData(xx, yy, zz, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getData(int xx, int yy, int zz, Class<T> t) {
|
||||
return oplacer.getData(xx, yy, zz, t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Engine getEngine() {
|
||||
return oplacer.getEngine();
|
||||
}
|
||||
}
|
||||
@@ -133,11 +133,6 @@ public class WorldObjectPlacer implements IObjectPlacer {
|
||||
return mantle.getFluidHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebugSmartBore() {
|
||||
return mantle.isDebugSmartBore();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTile(int xx, int yy, int zz, TileData tile) {
|
||||
int worldY = yy + world.getMinHeight();
|
||||
|
||||
@@ -124,10 +124,6 @@ public interface EngineMantle extends MatterGenerator {
|
||||
return getEngine().getDimension().getFluidHeight();
|
||||
}
|
||||
|
||||
default boolean isDebugSmartBore() {
|
||||
return getEngine().getDimension().isDebugSmartBore();
|
||||
}
|
||||
|
||||
default void trim(long duration) {
|
||||
getMantle().trim(duration);
|
||||
}
|
||||
|
||||
@@ -506,11 +506,6 @@ public class MantleWriter implements IObjectPlacer, AutoCloseable {
|
||||
return getEngineMantle().getFluidHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebugSmartBore() {
|
||||
return getEngineMantle().isDebugSmartBore();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTile(int xx, int yy, int zz, TileData tile) {
|
||||
setData(xx, yy, zz, new TileWrapper(tile));
|
||||
|
||||
-286
@@ -1,286 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.mantle.components;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.volmlib.util.cache.CacheKey;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.object.placement.IObjectPlacer;
|
||||
import art.arcane.iris.engine.object.prefab.TileData;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.util.common.data.B;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public final class CaveObjectPlacementTransaction implements IObjectPlacer {
|
||||
private static final int CACHE_MISS = Integer.MIN_VALUE;
|
||||
|
||||
private final IObjectPlacer delegate;
|
||||
private final Engine engine;
|
||||
private final int anchorY;
|
||||
private final int minDepthBelowSurface;
|
||||
private final int worldHeight;
|
||||
private final KList<BufferedMutation> mutations;
|
||||
private final Map<PositionKey, PlatformBlockState> bufferedBlocks;
|
||||
private final Long2IntOpenHashMap surfaceHeights;
|
||||
private final Long2IntOpenHashMap caveCeilings;
|
||||
private int blockWrites;
|
||||
|
||||
public CaveObjectPlacementTransaction(IObjectPlacer delegate, int anchorY, int minDepthBelowSurface) {
|
||||
this.delegate = delegate;
|
||||
this.engine = delegate.getEngine();
|
||||
this.anchorY = anchorY;
|
||||
this.minDepthBelowSurface = Math.max(0, minDepthBelowSurface);
|
||||
this.worldHeight = engine == null ? 0 : engine.getHeight();
|
||||
this.mutations = new KList<>();
|
||||
this.bufferedBlocks = new HashMap<>();
|
||||
this.surfaceHeights = new Long2IntOpenHashMap();
|
||||
this.caveCeilings = new Long2IntOpenHashMap();
|
||||
this.surfaceHeights.defaultReturnValue(CACHE_MISS);
|
||||
this.caveCeilings.defaultReturnValue(CACHE_MISS);
|
||||
}
|
||||
|
||||
public CommitResult commit() {
|
||||
if (blockWrites == 0) {
|
||||
discard();
|
||||
return CommitResult.EMPTY;
|
||||
}
|
||||
|
||||
for (BufferedMutation mutation : mutations) {
|
||||
if (!isWithinBounds(mutation.x(), mutation.y(), mutation.z())) {
|
||||
discard();
|
||||
return CommitResult.REJECTED_BOUNDS;
|
||||
}
|
||||
}
|
||||
|
||||
for (BufferedMutation mutation : mutations) {
|
||||
mutation.apply(delegate);
|
||||
}
|
||||
discard();
|
||||
return CommitResult.COMMITTED;
|
||||
}
|
||||
|
||||
public void discard() {
|
||||
mutations.clear();
|
||||
bufferedBlocks.clear();
|
||||
blockWrites = 0;
|
||||
}
|
||||
|
||||
public int getCaveCeiling(int x, int z) {
|
||||
long key = CacheKey.key(x, z);
|
||||
int cached = caveCeilings.get(key);
|
||||
if (cached != CACHE_MISS) {
|
||||
return cached;
|
||||
}
|
||||
|
||||
int ceiling = findCaveCeiling(x, z);
|
||||
caveCeilings.put(key, ceiling);
|
||||
return ceiling;
|
||||
}
|
||||
|
||||
static int maxBuriedY(int worldHeight, int surfaceY, int minDepthBelowSurface) {
|
||||
return Math.min(worldHeight - 1, surfaceY - Math.max(0, minDepthBelowSurface));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHighest(int x, int z, IrisData data) {
|
||||
return delegate.getHighest(x, z, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHighest(int x, int z, IrisData data, boolean ignoreFluid) {
|
||||
return delegate.getHighest(x, z, data, ignoreFluid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(int x, int y, int z, PlatformBlockState state) {
|
||||
if (state == null) {
|
||||
return;
|
||||
}
|
||||
mutations.add(new BlockMutation(x, y, z, state));
|
||||
bufferedBlocks.put(new PositionKey(x, y, z), state);
|
||||
blockWrites++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformBlockState get(int x, int y, int z) {
|
||||
PlatformBlockState buffered = bufferedBlocks.get(new PositionKey(x, y, z));
|
||||
return buffered == null ? delegate.get(x, y, z) : buffered;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPreventingDecay() {
|
||||
return delegate.isPreventingDecay();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCarved(int x, int y, int z) {
|
||||
return delegate.isCarved(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSurfaceSolid(int x, int y, int z) {
|
||||
return delegate.isSurfaceSolid(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSolid(int x, int y, int z) {
|
||||
PlatformBlockState buffered = bufferedBlocks.get(new PositionKey(x, y, z));
|
||||
return buffered == null ? delegate.isSolid(x, y, z) : B.isSolid(buffered);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUnderwater(int x, int z) {
|
||||
return delegate.isUnderwater(x, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFluidHeight() {
|
||||
return delegate.getFluidHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebugSmartBore() {
|
||||
return delegate.isDebugSmartBore();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTile(int x, int y, int z, TileData tile) {
|
||||
if (tile != null) {
|
||||
mutations.add(new TileMutation(x, y, z, tile));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> void setData(int x, int y, int z, T data) {
|
||||
if (data == null) {
|
||||
return;
|
||||
}
|
||||
mutations.add(new DataMutation(x, y, z, data));
|
||||
if (data instanceof PlatformBlockState state) {
|
||||
bufferedBlocks.put(new PositionKey(x, y, z), state);
|
||||
blockWrites++;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> @Nullable T getData(int x, int y, int z, Class<T> type) {
|
||||
for (int i = mutations.size() - 1; i >= 0; i--) {
|
||||
BufferedMutation mutation = mutations.get(i);
|
||||
if (mutation.x() != x || mutation.y() != y || mutation.z() != z) {
|
||||
continue;
|
||||
}
|
||||
Object value = mutation.value();
|
||||
if (type.isInstance(value)) {
|
||||
return type.cast(value);
|
||||
}
|
||||
}
|
||||
return delegate.getData(x, y, z, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Engine getEngine() {
|
||||
return engine;
|
||||
}
|
||||
|
||||
private boolean isWithinBounds(int x, int y, int z) {
|
||||
if (engine == null || y < 0 || y >= worldHeight) {
|
||||
return false;
|
||||
}
|
||||
int surfaceY = getSurfaceHeight(x, z);
|
||||
if (y > maxBuriedY(worldHeight, surfaceY, minDepthBelowSurface)) {
|
||||
return false;
|
||||
}
|
||||
return y < getCaveCeiling(x, z);
|
||||
}
|
||||
|
||||
private int getSurfaceHeight(int x, int z) {
|
||||
long key = CacheKey.key(x, z);
|
||||
int cached = surfaceHeights.get(key);
|
||||
if (cached != CACHE_MISS) {
|
||||
return cached;
|
||||
}
|
||||
int surfaceY = engine.getHeight(x, z, true);
|
||||
surfaceHeights.put(key, surfaceY);
|
||||
return surfaceY;
|
||||
}
|
||||
|
||||
private int findCaveCeiling(int x, int z) {
|
||||
if (worldHeight <= 0 || anchorY < 0 || anchorY >= worldHeight) {
|
||||
return 0;
|
||||
}
|
||||
if (!delegate.isCarved(x, anchorY, z)) {
|
||||
return Math.min(worldHeight, anchorY + 1);
|
||||
}
|
||||
|
||||
int scanLimit = Math.min(worldHeight - 1, Math.max(anchorY, getSurfaceHeight(x, z)));
|
||||
for (int y = anchorY + 1; y <= scanLimit; y++) {
|
||||
if (!delegate.isCarved(x, y, z)) {
|
||||
return y;
|
||||
}
|
||||
}
|
||||
return Math.min(worldHeight, scanLimit + 1);
|
||||
}
|
||||
|
||||
public enum CommitResult {
|
||||
COMMITTED,
|
||||
EMPTY,
|
||||
REJECTED_BOUNDS
|
||||
}
|
||||
|
||||
private interface BufferedMutation {
|
||||
int x();
|
||||
|
||||
int y();
|
||||
|
||||
int z();
|
||||
|
||||
Object value();
|
||||
|
||||
void apply(IObjectPlacer placer);
|
||||
}
|
||||
|
||||
private record BlockMutation(int x, int y, int z, PlatformBlockState value) implements BufferedMutation {
|
||||
@Override
|
||||
public void apply(IObjectPlacer placer) {
|
||||
placer.set(x, y, z, value);
|
||||
}
|
||||
}
|
||||
|
||||
private record TileMutation(int x, int y, int z, TileData value) implements BufferedMutation {
|
||||
@Override
|
||||
public void apply(IObjectPlacer placer) {
|
||||
placer.setTile(x, y, z, value);
|
||||
}
|
||||
}
|
||||
|
||||
private record DataMutation(int x, int y, int z, Object value) implements BufferedMutation {
|
||||
@Override
|
||||
public void apply(IObjectPlacer placer) {
|
||||
placer.setData(x, y, z, value);
|
||||
}
|
||||
}
|
||||
|
||||
private record PositionKey(int x, int y, int z) {
|
||||
}
|
||||
}
|
||||
-211
@@ -1,211 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.mantle.components;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.object.placement.IObjectPlacer;
|
||||
import art.arcane.iris.engine.object.prefab.TileData;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.util.common.data.B;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public final class FloatingObjectPlacementTransaction implements IObjectPlacer {
|
||||
private final IslandAnchorPlacer delegate;
|
||||
private final KList<BufferedMutation> mutations;
|
||||
private final Map<PositionKey, PlatformBlockState> bufferedBlocks;
|
||||
private int blockWrites;
|
||||
|
||||
public FloatingObjectPlacementTransaction(IslandAnchorPlacer delegate) {
|
||||
this.delegate = delegate;
|
||||
this.mutations = new KList<>();
|
||||
this.bufferedBlocks = new HashMap<>();
|
||||
}
|
||||
|
||||
public CommitResult commit() {
|
||||
if (blockWrites == 0) {
|
||||
discard();
|
||||
return CommitResult.EMPTY;
|
||||
}
|
||||
for (BufferedMutation mutation : mutations) {
|
||||
if (!delegate.canWriteObjectBlock(mutation.x(), mutation.y(), mutation.z())) {
|
||||
discard();
|
||||
return CommitResult.REJECTED_SUPPORT;
|
||||
}
|
||||
}
|
||||
for (BufferedMutation mutation : mutations) {
|
||||
mutation.apply(delegate);
|
||||
}
|
||||
discard();
|
||||
return CommitResult.COMMITTED;
|
||||
}
|
||||
|
||||
public void discard() {
|
||||
mutations.clear();
|
||||
bufferedBlocks.clear();
|
||||
blockWrites = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHighest(int x, int z, IrisData data) {
|
||||
return delegate.getHighest(x, z, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHighest(int x, int z, IrisData data, boolean ignoreFluid) {
|
||||
return delegate.getHighest(x, z, data, ignoreFluid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(int x, int y, int z, PlatformBlockState state) {
|
||||
if (state == null) {
|
||||
return;
|
||||
}
|
||||
mutations.add(new BlockMutation(x, y, z, state));
|
||||
bufferedBlocks.put(new PositionKey(x, y, z), state);
|
||||
blockWrites++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformBlockState get(int x, int y, int z) {
|
||||
PlatformBlockState state = bufferedBlocks.get(new PositionKey(x, y, z));
|
||||
return state == null ? delegate.get(x, y, z) : state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPreventingDecay() {
|
||||
return delegate.isPreventingDecay();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCarved(int x, int y, int z) {
|
||||
return delegate.isCarved(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSurfaceSolid(int x, int y, int z) {
|
||||
return delegate.isSurfaceSolid(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSolid(int x, int y, int z) {
|
||||
PlatformBlockState state = bufferedBlocks.get(new PositionKey(x, y, z));
|
||||
return state == null ? delegate.isSolid(x, y, z) : B.isSolid(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUnderwater(int x, int z) {
|
||||
return delegate.isUnderwater(x, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFluidHeight() {
|
||||
return delegate.getFluidHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebugSmartBore() {
|
||||
return delegate.isDebugSmartBore();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTile(int x, int y, int z, TileData tile) {
|
||||
if (tile != null) {
|
||||
mutations.add(new TileMutation(x, y, z, tile));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> void setData(int x, int y, int z, T data) {
|
||||
if (data == null) {
|
||||
return;
|
||||
}
|
||||
mutations.add(new DataMutation(x, y, z, data));
|
||||
if (data instanceof PlatformBlockState state) {
|
||||
bufferedBlocks.put(new PositionKey(x, y, z), state);
|
||||
blockWrites++;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> @Nullable T getData(int x, int y, int z, Class<T> type) {
|
||||
for (int i = mutations.size() - 1; i >= 0; i--) {
|
||||
BufferedMutation mutation = mutations.get(i);
|
||||
if (mutation.x() != x || mutation.y() != y || mutation.z() != z) {
|
||||
continue;
|
||||
}
|
||||
Object value = mutation.value();
|
||||
if (type.isInstance(value)) {
|
||||
return type.cast(value);
|
||||
}
|
||||
}
|
||||
return delegate.getData(x, y, z, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Engine getEngine() {
|
||||
return delegate.getEngine();
|
||||
}
|
||||
|
||||
public enum CommitResult {
|
||||
COMMITTED,
|
||||
EMPTY,
|
||||
REJECTED_SUPPORT
|
||||
}
|
||||
|
||||
private interface BufferedMutation {
|
||||
int x();
|
||||
|
||||
int y();
|
||||
|
||||
int z();
|
||||
|
||||
Object value();
|
||||
|
||||
void apply(IObjectPlacer placer);
|
||||
}
|
||||
|
||||
private record BlockMutation(int x, int y, int z, PlatformBlockState value) implements BufferedMutation {
|
||||
@Override
|
||||
public void apply(IObjectPlacer placer) {
|
||||
placer.set(x, y, z, value);
|
||||
}
|
||||
}
|
||||
|
||||
private record TileMutation(int x, int y, int z, TileData value) implements BufferedMutation {
|
||||
@Override
|
||||
public void apply(IObjectPlacer placer) {
|
||||
placer.setTile(x, y, z, value);
|
||||
}
|
||||
}
|
||||
|
||||
private record DataMutation(int x, int y, int z, Object value) implements BufferedMutation {
|
||||
@Override
|
||||
public void apply(IObjectPlacer placer) {
|
||||
placer.setData(x, y, z, value);
|
||||
}
|
||||
}
|
||||
|
||||
private record PositionKey(int x, int y, int z) {
|
||||
}
|
||||
}
|
||||
-161
@@ -1,161 +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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.mantle.components;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.object.placement.IObjectPlacer;
|
||||
import art.arcane.iris.engine.object.prefab.TileData;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import com.volmit.ModuleLog;
|
||||
|
||||
public final class GoldenDebugObjectPlacer implements IObjectPlacer {
|
||||
private static final int[] GOLDEN_DEBUG_TARGET = parseGoldenDebugTarget(resolveGoldenDebugSpec());
|
||||
private static final boolean GOLDEN_DEBUG = GOLDEN_DEBUG_TARGET != null;
|
||||
|
||||
private final IObjectPlacer delegate;
|
||||
private final String tag;
|
||||
private final ModuleLog log;
|
||||
|
||||
public GoldenDebugObjectPlacer(IObjectPlacer delegate, String tag, ModuleLog log) {
|
||||
this.delegate = delegate;
|
||||
this.tag = tag;
|
||||
this.log = log;
|
||||
}
|
||||
|
||||
private static String resolveGoldenDebugSpec() {
|
||||
String property = System.getProperty("iris.goldendebug");
|
||||
if (property != null && !property.isBlank()) {
|
||||
return property;
|
||||
}
|
||||
try {
|
||||
java.io.File marker = new java.io.File("plugins/Iris/goldendebug.txt");
|
||||
if (marker.isFile()) {
|
||||
return java.nio.file.Files.readString(marker.toPath()).trim();
|
||||
}
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static int[] parseGoldenDebugTarget(String raw) {
|
||||
if (raw == null || raw.isBlank()) {
|
||||
return null;
|
||||
}
|
||||
String[] parts = raw.split(",");
|
||||
if (parts.length != 2 && parts.length != 3) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
int radius = parts.length == 3 ? Integer.parseInt(parts[2].trim()) : 0;
|
||||
return new int[]{Integer.parseInt(parts[0].trim()), Integer.parseInt(parts[1].trim()), radius};
|
||||
} catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isGoldenDebugChunk(int x, int z) {
|
||||
return GOLDEN_DEBUG
|
||||
&& Math.abs(GOLDEN_DEBUG_TARGET[0] - x) <= GOLDEN_DEBUG_TARGET[2]
|
||||
&& Math.abs(GOLDEN_DEBUG_TARGET[1] - z) <= GOLDEN_DEBUG_TARGET[2];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHighest(int x, int z, IrisData data) {
|
||||
int result = delegate.getHighest(x, z, data);
|
||||
log.debug("Goldendebug query: tag=" + tag + " getHighest(" + x + "," + z + ")=" + result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHighest(int x, int z, IrisData data, boolean ignoreFluid) {
|
||||
int result = delegate.getHighest(x, z, data, ignoreFluid);
|
||||
log.debug("Goldendebug query: tag=" + tag + " getHighest(" + x + "," + z + ",ignoreFluid=" + ignoreFluid + ")=" + result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(int x, int y, int z, PlatformBlockState d) {
|
||||
delegate.set(x, y, z, d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformBlockState get(int x, int y, int z) {
|
||||
return delegate.get(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPreventingDecay() {
|
||||
return delegate.isPreventingDecay();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCarved(int x, int y, int z) {
|
||||
boolean result = delegate.isCarved(x, y, z);
|
||||
log.debug("Goldendebug query: tag=" + tag + " isCarved(" + x + "," + y + "," + z + ")=" + result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSurfaceSolid(int x, int y, int z) {
|
||||
return delegate.isSurfaceSolid(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSolid(int x, int y, int z) {
|
||||
boolean result = delegate.isSolid(x, y, z);
|
||||
log.debug("Goldendebug query: tag=" + tag + " isSolid(" + x + "," + y + "," + z + ")=" + result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUnderwater(int x, int z) {
|
||||
return delegate.isUnderwater(x, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFluidHeight() {
|
||||
return delegate.getFluidHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebugSmartBore() {
|
||||
return delegate.isDebugSmartBore();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> void setData(int xx, int yy, int zz, T data) {
|
||||
delegate.setData(xx, yy, zz, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getData(int xx, int yy, int zz, Class<T> t) {
|
||||
return delegate.getData(xx, yy, zz, t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTile(int xx, int yy, int zz, TileData tile) {
|
||||
delegate.setTile(xx, yy, zz, tile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Engine getEngine() {
|
||||
return delegate.getEngine();
|
||||
}
|
||||
}
|
||||
@@ -1,128 +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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.mantle.components;
|
||||
|
||||
import art.arcane.iris.builtin.floating.IslandAnchor;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.mantle.MantleWriter;
|
||||
import art.arcane.iris.engine.object.placement.IObjectPlacer;
|
||||
import art.arcane.iris.engine.object.prefab.TileData;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Iris's placer for an object placed against a floating island: heights and the island's solid blocks come from the
|
||||
* {@link IslandAnchor} the floating module samples, and a block is written only where the anchor lets the object write.
|
||||
* Everything else is the mantle's.
|
||||
*/
|
||||
public final class IslandAnchorPlacer implements IObjectPlacer {
|
||||
private final MantleWriter wrapped;
|
||||
private final IslandAnchor anchor;
|
||||
|
||||
public IslandAnchorPlacer(MantleWriter wrapped, IslandAnchor anchor) {
|
||||
this.wrapped = wrapped;
|
||||
this.anchor = anchor;
|
||||
}
|
||||
|
||||
public boolean canWriteObjectBlock(int x, int y, int z) {
|
||||
return anchor.writes(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHighest(int x, int z, IrisData data) {
|
||||
return anchor.faceY(x, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHighest(int x, int z, IrisData data, boolean ignoreFluid) {
|
||||
return getHighest(x, z, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUnderwater(int x, int z) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSolid(int x, int y, int z) {
|
||||
return anchor.hasIsland(x, z) ? anchor.islandSolid(x, y, z) : wrapped.isSolid(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCarved(int x, int y, int z) {
|
||||
return wrapped.isCarved(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSurfaceSolid(int x, int y, int z) {
|
||||
return wrapped.isSurfaceSolid(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(int x, int y, int z, PlatformBlockState state) {
|
||||
if (anchor.writes(x, y, z)) {
|
||||
wrapped.set(x, y, z, state);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformBlockState get(int x, int y, int z) {
|
||||
return wrapped.get(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPreventingDecay() {
|
||||
return wrapped.isPreventingDecay();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFluidHeight() {
|
||||
return wrapped.getFluidHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebugSmartBore() {
|
||||
return wrapped.isDebugSmartBore();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTile(int x, int y, int z, TileData tile) {
|
||||
if (anchor.writes(x, y, z)) {
|
||||
wrapped.setTile(x, y, z, tile);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> void setData(int x, int y, int z, T data) {
|
||||
if (anchor.writes(x, y, z)) {
|
||||
wrapped.setData(x, y, z, data);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> @Nullable T getData(int x, int y, int z, Class<T> type) {
|
||||
return wrapped.getData(x, y, z, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Engine getEngine() {
|
||||
return wrapped == null ? null : wrapped.getEngine();
|
||||
}
|
||||
}
|
||||
@@ -1,108 +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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.object.placement;
|
||||
|
||||
import art.arcane.iris.engine.object.prefab.TileData;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class DecayControlPlacer implements IObjectPlacer {
|
||||
private final IObjectPlacer delegate;
|
||||
|
||||
public DecayControlPlacer(IObjectPlacer delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHighest(int x, int z, IrisData data) {
|
||||
return delegate.getHighest(x, z, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHighest(int x, int z, IrisData data, boolean ignoreFluid) {
|
||||
return delegate.getHighest(x, z, data, ignoreFluid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(int x, int y, int z, PlatformBlockState d) {
|
||||
delegate.set(x, y, z, d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformBlockState get(int x, int y, int z) {
|
||||
return delegate.get(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPreventingDecay() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCarved(int x, int y, int z) {
|
||||
return delegate.isCarved(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSurfaceSolid(int x, int y, int z) {
|
||||
return delegate.isSurfaceSolid(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSolid(int x, int y, int z) {
|
||||
return delegate.isSolid(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUnderwater(int x, int z) {
|
||||
return delegate.isUnderwater(x, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFluidHeight() {
|
||||
return delegate.getFluidHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebugSmartBore() {
|
||||
return delegate.isDebugSmartBore();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTile(int xx, int yy, int zz, TileData tile) {
|
||||
delegate.setTile(xx, yy, zz, tile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> void setData(int xx, int yy, int zz, T data) {
|
||||
delegate.setData(xx, yy, zz, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> @Nullable T getData(int xx, int yy, int zz, Class<T> t) {
|
||||
return delegate.getData(xx, yy, zz, t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Engine getEngine() {
|
||||
return delegate.getEngine();
|
||||
}
|
||||
}
|
||||
-171
@@ -1,171 +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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.object.placement;
|
||||
|
||||
import art.arcane.iris.engine.object.prefab.IrisObject;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class FloatingObjectFootprint {
|
||||
private final int lowestSolidKeyY;
|
||||
private final int highestSolidKeyY;
|
||||
private final int centerX;
|
||||
private final int centerY;
|
||||
private final int centerZ;
|
||||
private final int tallestKx;
|
||||
private final int tallestKz;
|
||||
private final int tallestKxBottom;
|
||||
private final int tallestKzBottom;
|
||||
private final long[] footprintXZ;
|
||||
|
||||
private FloatingObjectFootprint(int lowestSolidKeyY, int highestSolidKeyY, int centerX, int centerY, int centerZ, int tallestKx, int tallestKz, int tallestKxBottom, int tallestKzBottom, long[] footprintXZ) {
|
||||
this.lowestSolidKeyY = lowestSolidKeyY;
|
||||
this.highestSolidKeyY = highestSolidKeyY;
|
||||
this.centerX = centerX;
|
||||
this.centerY = centerY;
|
||||
this.centerZ = centerZ;
|
||||
this.tallestKx = tallestKx;
|
||||
this.tallestKz = tallestKz;
|
||||
this.tallestKxBottom = tallestKxBottom;
|
||||
this.tallestKzBottom = tallestKzBottom;
|
||||
this.footprintXZ = footprintXZ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Memoized per object instance, never in a global map: loadKey + declared dimensions is
|
||||
* not unique across packs or across hotloads (a block edit keeps the header W/H/D), so a
|
||||
* shared key space served stale or foreign footprints. A reload builds a new IrisObject,
|
||||
* which drops the memo for free.
|
||||
*/
|
||||
public static FloatingObjectFootprint compute(IrisObject obj) {
|
||||
return obj.floatingFootprint.aquire(() -> doCompute(obj));
|
||||
}
|
||||
|
||||
private static FloatingObjectFootprint doCompute(IrisObject obj) {
|
||||
int cx = obj.getCenter().getBlockX();
|
||||
int cy = obj.getCenter().getBlockY();
|
||||
int cz = obj.getCenter().getBlockZ();
|
||||
Map<Long, int[]> columnStats = new HashMap<>();
|
||||
|
||||
int[] globalHighestY = {Integer.MIN_VALUE};
|
||||
int[] globalHighestKx = {0};
|
||||
int[] globalHighestKz = {0};
|
||||
|
||||
obj.getBlocks().forEach((key, bd) -> {
|
||||
if (!bd.isSolid()) {
|
||||
return;
|
||||
}
|
||||
int kx = key.getBlockX();
|
||||
int ky = key.getBlockY();
|
||||
int kz = key.getBlockZ();
|
||||
long packed = ((long) kx << 32) | (kz & 0xFFFFFFFFL);
|
||||
int[] stats = columnStats.get(packed);
|
||||
if (stats == null) {
|
||||
stats = new int[]{ky, 1};
|
||||
columnStats.put(packed, stats);
|
||||
} else {
|
||||
if (ky < stats[0]) {
|
||||
stats[0] = ky;
|
||||
}
|
||||
stats[1]++;
|
||||
}
|
||||
if (ky > globalHighestY[0]) {
|
||||
globalHighestY[0] = ky;
|
||||
globalHighestKx[0] = kx;
|
||||
globalHighestKz[0] = kz;
|
||||
}
|
||||
});
|
||||
|
||||
long[] footprintArray = new long[columnStats.size()];
|
||||
int idx = 0;
|
||||
for (Long packed : columnStats.keySet()) {
|
||||
footprintArray[idx++] = packed;
|
||||
}
|
||||
|
||||
long tallestPacked = resolveTallestColumn(columnStats);
|
||||
int lowestSolidKeyY = columnStats.isEmpty() ? cy : columnStats.get(tallestPacked)[0];
|
||||
int highestSolidKeyY = columnStats.isEmpty() ? cy : globalHighestY[0];
|
||||
int tallestKx = columnStats.isEmpty() ? 0 : (int) (tallestPacked >> 32);
|
||||
int tallestKz = columnStats.isEmpty() ? 0 : (int) (tallestPacked & 0xFFFFFFFFL);
|
||||
int tallestKxBottom = columnStats.isEmpty() ? 0 : globalHighestKx[0];
|
||||
int tallestKzBottom = columnStats.isEmpty() ? 0 : globalHighestKz[0];
|
||||
return new FloatingObjectFootprint(lowestSolidKeyY, highestSolidKeyY, cx, cy, cz, tallestKx, tallestKz, tallestKxBottom, tallestKzBottom, footprintArray);
|
||||
}
|
||||
|
||||
private static long resolveTallestColumn(Map<Long, int[]> columnStats) {
|
||||
long bestPacked = 0L;
|
||||
int tallestCount = 0;
|
||||
int tallestLow = Integer.MAX_VALUE;
|
||||
for (Map.Entry<Long, int[]> e : columnStats.entrySet()) {
|
||||
int[] stats = e.getValue();
|
||||
int count = stats[1];
|
||||
int low = stats[0];
|
||||
if (count > tallestCount || (count == tallestCount && low < tallestLow)) {
|
||||
tallestCount = count;
|
||||
tallestLow = low;
|
||||
bestPacked = e.getKey();
|
||||
}
|
||||
}
|
||||
return bestPacked;
|
||||
}
|
||||
|
||||
public int lowestSolidRelCenterY() {
|
||||
return lowestSolidKeyY - centerY;
|
||||
}
|
||||
|
||||
public int getLowestSolidKeyY() {
|
||||
return lowestSolidKeyY;
|
||||
}
|
||||
|
||||
public int getCenterX() {
|
||||
return centerX;
|
||||
}
|
||||
|
||||
public int getCenterY() {
|
||||
return centerY;
|
||||
}
|
||||
|
||||
public int getCenterZ() {
|
||||
return centerZ;
|
||||
}
|
||||
|
||||
public int getTallestKx() {
|
||||
return tallestKx;
|
||||
}
|
||||
|
||||
public int getTallestKz() {
|
||||
return tallestKz;
|
||||
}
|
||||
|
||||
public int getHighestSolidKeyY() {
|
||||
return highestSolidKeyY;
|
||||
}
|
||||
|
||||
public int getTallestKxBottom() {
|
||||
return tallestKxBottom;
|
||||
}
|
||||
|
||||
public int getTallestKzBottom() {
|
||||
return tallestKzBottom;
|
||||
}
|
||||
|
||||
public long[] footprintXZ() {
|
||||
return footprintXZ;
|
||||
}
|
||||
}
|
||||
@@ -51,8 +51,6 @@ public interface IObjectPlacer {
|
||||
|
||||
int getFluidHeight();
|
||||
|
||||
boolean isDebugSmartBore();
|
||||
|
||||
void setTile(int xx, int yy, int zz, TileData tile);
|
||||
|
||||
<T> void setData(int xx, int yy, int zz, T data);
|
||||
|
||||
@@ -25,6 +25,7 @@ import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.collection.KMap;
|
||||
import art.arcane.volmlib.util.math.IrisBlockVector;
|
||||
import com.volmit.block.BlockTurn;
|
||||
import org.bukkit.Axis;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
@@ -43,8 +44,8 @@ import java.util.Set;
|
||||
|
||||
/**
|
||||
* Turns a platform block state with an object: the facing, axis and connections of stairs, logs, walls and wires follow
|
||||
* the {@link ObjectRotation} that turns the object's positions. A platform other than Bukkit binds its own
|
||||
* {@link StateRotator}.
|
||||
* the {@link BlockTurn} that turns the object's directions, such as an {@link ObjectRotation}'s. A platform other than
|
||||
* Bukkit binds its own {@link StateRotator}.
|
||||
*/
|
||||
public final class BlockStateRotation {
|
||||
private static final double QUARTER_TURN_DEGREES = 90D;
|
||||
@@ -53,7 +54,8 @@ public final class BlockStateRotation {
|
||||
|
||||
/** How a platform turns its own block states. */
|
||||
public interface StateRotator {
|
||||
PlatformBlockState rotate(ObjectRotation rotation, PlatformBlockState state, int spinX, int spinY, int spinZ);
|
||||
/** {@code state} turned by {@code turn}; null when a block that cannot face the new way is dropped. */
|
||||
PlatformBlockState rotate(BlockTurn turn, PlatformBlockState state);
|
||||
}
|
||||
|
||||
/** Holds the Bukkit faces apart so a platform without Bukkit can load this class and bind its own rotator. */
|
||||
@@ -74,23 +76,51 @@ public final class BlockStateRotation {
|
||||
platformRotator = rotator;
|
||||
}
|
||||
|
||||
/** {@code state} turned by {@code rotation}; null when a block that cannot face the new way is dropped. */
|
||||
/**
|
||||
* {@code state} turned by {@code rotation}, spun by the given degrees counted in whole quarter turns; null when a
|
||||
* block that cannot face the new way is dropped.
|
||||
*/
|
||||
public static PlatformBlockState rotate(ObjectRotation rotation, PlatformBlockState state, int spinX, int spinY, int spinZ) {
|
||||
if (!rotation.canRotate()) {
|
||||
return state;
|
||||
}
|
||||
return rotate(turnOf(rotation, spinX, spinY, spinZ), state);
|
||||
}
|
||||
|
||||
/** {@code state} turned by {@code turn}; null when a block that cannot face the new way is dropped. */
|
||||
public static PlatformBlockState rotate(BlockTurn turn, PlatformBlockState state) {
|
||||
if (state == null) {
|
||||
return null;
|
||||
}
|
||||
StateRotator rotator = platformRotator;
|
||||
if (rotator != null) {
|
||||
return rotator.rotate(rotation, state, spinX, spinY, spinZ);
|
||||
return rotator.rotate(turn, state);
|
||||
}
|
||||
BlockData original = (BlockData) state.nativeHandle();
|
||||
if (!rotation.canRotate() || !canRotateBlockData(original)) {
|
||||
if (!canRotateBlockData(original)) {
|
||||
return state;
|
||||
}
|
||||
BlockData rotated = rotate(rotation, original.clone(), spinX, spinY, spinZ);
|
||||
BlockData rotated = rotate(turn, original.clone());
|
||||
return rotated == null ? null : BukkitBlockState.of(rotated);
|
||||
}
|
||||
|
||||
/** The directions {@code rotation} turns, spun by the given degrees counted in whole quarter turns. */
|
||||
public static BlockTurn turnOf(ObjectRotation rotation, int spinXDegrees, int spinYDegrees, int spinZDegrees) {
|
||||
int spinX = wholeQuarterTurns(spinXDegrees);
|
||||
int spinY = wholeQuarterTurns(spinYDegrees);
|
||||
int spinZ = wholeQuarterTurns(spinZDegrees);
|
||||
return (x, y, z) -> {
|
||||
IrisBlockVector turned = rotation.rotate(new IrisBlockVector(x, y, z), spinX, spinY, spinZ);
|
||||
return new BlockTurn.Direction(turned.getX(), turned.getY(), turned.getZ());
|
||||
};
|
||||
}
|
||||
|
||||
/** {@code direction} turned by {@code turn}. */
|
||||
public static IrisBlockVector turned(BlockTurn turn, double x, double y, double z) {
|
||||
BlockTurn.Direction direction = turn.turn(x, y, z);
|
||||
return new IrisBlockVector(direction.x(), direction.y(), direction.z());
|
||||
}
|
||||
|
||||
private static boolean canRotateBlockData(BlockData data) {
|
||||
return data instanceof Directional
|
||||
|| data instanceof Rotatable
|
||||
@@ -102,19 +132,19 @@ public final class BlockStateRotation {
|
||||
|
||||
/** {@code data}, changed in place, turned by {@code rotation} in whole quarter turns; null when it cannot face the new way. */
|
||||
public static BlockData rotate(ObjectRotation rotation, BlockData data, int spinXDegrees, int spinYDegrees, int spinZDegrees) {
|
||||
if (!rotation.canRotate()) {
|
||||
return data;
|
||||
}
|
||||
return rotate(turnOf(rotation, spinXDegrees, spinYDegrees, spinZDegrees), data);
|
||||
}
|
||||
|
||||
/** {@code data}, changed in place, turned by {@code turn}; null when it cannot face the new way. */
|
||||
public static BlockData rotate(BlockTurn turn, BlockData data) {
|
||||
BlockData d = data;
|
||||
try {
|
||||
int spinX = wholeQuarterTurns(spinXDegrees);
|
||||
int spinY = wholeQuarterTurns(spinYDegrees);
|
||||
int spinZ = wholeQuarterTurns(spinZDegrees);
|
||||
|
||||
if (!rotation.canRotate()) {
|
||||
return d;
|
||||
}
|
||||
|
||||
if (d instanceof Directional g) {
|
||||
BlockFace f = g.getFacing();
|
||||
IrisBlockVector bv = rotation.rotate(new IrisBlockVector(f.getModX(), f.getModY(), f.getModZ()), spinX, spinY, spinZ);
|
||||
IrisBlockVector bv = turned(turn, f.getModX(), f.getModY(), f.getModZ());
|
||||
BlockFace t = faceOf(bv);
|
||||
|
||||
if (g.getFaces().contains(t)) {
|
||||
@@ -124,11 +154,11 @@ public final class BlockStateRotation {
|
||||
}
|
||||
} else if (d instanceof Rotatable g) {
|
||||
BlockFace f = g.getRotation();
|
||||
IrisBlockVector bv = rotation.rotate(new IrisBlockVector(f.getModX(), 0, f.getModZ()), spinX, spinY, spinZ);
|
||||
IrisBlockVector bv = turned(turn, f.getModX(), 0, f.getModZ());
|
||||
g.setRotation(sixteenWayFaceOf(bv));
|
||||
} else if (d instanceof Orientable g) {
|
||||
BlockFace f = faceOf(g.getAxis());
|
||||
IrisBlockVector bv = rotation.rotate(new IrisBlockVector(f.getModX(), f.getModY(), f.getModZ()), spinX, spinY, spinZ);
|
||||
IrisBlockVector bv = turned(turn, f.getModX(), f.getModY(), f.getModZ());
|
||||
Axis a = axisOf(bv);
|
||||
|
||||
if (!a.equals(g.getAxis()) && g.getAxes().contains(a)) {
|
||||
@@ -138,7 +168,7 @@ public final class BlockStateRotation {
|
||||
List<BlockFace> faces = new KList<>();
|
||||
|
||||
for (BlockFace i : g.getFaces()) {
|
||||
IrisBlockVector bv = rotation.rotate(new IrisBlockVector(i.getModX(), i.getModY(), i.getModZ()), spinX, spinY, spinZ);
|
||||
IrisBlockVector bv = turned(turn, i.getModX(), i.getModY(), i.getModZ());
|
||||
BlockFace r = faceOf(bv);
|
||||
|
||||
if (g.getAllowedFaces().contains(r)) {
|
||||
@@ -158,7 +188,7 @@ public final class BlockStateRotation {
|
||||
|
||||
for (BlockFace i : Faces.WALL_FACES) {
|
||||
Wall.Height h = wall.getHeight(i);
|
||||
IrisBlockVector bv = rotation.rotate(new IrisBlockVector(i.getModX(), i.getModY(), i.getModZ()), spinX, spinY, spinZ);
|
||||
IrisBlockVector bv = turned(turn, i.getModX(), i.getModY(), i.getModZ());
|
||||
BlockFace r = faceOf(bv);
|
||||
if (Faces.WALL_FACES.contains(r)) {
|
||||
faces.put(r, h);
|
||||
@@ -174,7 +204,7 @@ public final class BlockStateRotation {
|
||||
Set<BlockFace> allowed = wire.getAllowedFaces();
|
||||
for (BlockFace i : allowed) {
|
||||
RedstoneWire.Connection connection = wire.getFace(i);
|
||||
IrisBlockVector bv = rotation.rotate(new IrisBlockVector(i.getModX(), i.getModY(), i.getModZ()), spinX, spinY, spinZ);
|
||||
IrisBlockVector bv = turned(turn, i.getModX(), i.getModY(), i.getModZ());
|
||||
BlockFace r = faceOf(bv);
|
||||
if (allowed.contains(r)) {
|
||||
faces.put(r, connection);
|
||||
|
||||
@@ -18,10 +18,9 @@
|
||||
|
||||
package art.arcane.iris.engine.object.prefab;
|
||||
|
||||
import art.arcane.iris.builtin.objects.PlaceableObject;
|
||||
import com.volmit.object.PlaceableObject;
|
||||
import art.arcane.iris.builtin.objects.ScaleInterpolation;
|
||||
import art.arcane.iris.builtin.prepare.ObjectRotation;
|
||||
import art.arcane.iris.engine.object.placement.FloatingObjectFootprint;
|
||||
import art.arcane.iris.engine.object.placement.IObjectPlacer;
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.engine.object.terrain.carving.CarveResult;
|
||||
@@ -76,6 +75,8 @@ import java.util.function.BiConsumer;
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class IrisObject extends IrisRegistrant implements PlaceableObject {
|
||||
protected static final IrisVector HALF = new IrisVector(0.5, 0.5, 0.5);
|
||||
/** The name of an object made in code without a load key. */
|
||||
public static final String UNNAMED = "unnamed";
|
||||
public static final class States {
|
||||
public static final PlatformBlockState AIR = B.getState("CAVE_AIR");
|
||||
public static final PlatformBlockState STONE = B.getState("STONE");
|
||||
@@ -91,7 +92,6 @@ public class IrisObject extends IrisRegistrant implements PlaceableObject {
|
||||
@Setter
|
||||
protected transient AtomicCache<AxisAlignedBB> aabb = new AtomicCache<>();
|
||||
transient final AtomicCache<KList<IrisBlockVector>> surfaceSupportOffsets = new AtomicCache<>();
|
||||
public transient final AtomicCache<FloatingObjectFootprint> floatingFootprint = new AtomicCache<>();
|
||||
private transient final AtomicCache<GeneratedObject> geometry = new AtomicCache<>();
|
||||
@Getter
|
||||
public VectorMap<PlatformBlockState> blocks;
|
||||
@@ -289,7 +289,6 @@ public class IrisObject extends IrisRegistrant implements PlaceableObject {
|
||||
/** Drops what is computed from the blocks, after they change. */
|
||||
void forgetDerivedShapes() {
|
||||
surfaceSupportOffsets.reset();
|
||||
floatingFootprint.reset();
|
||||
geometry.reset();
|
||||
}
|
||||
|
||||
@@ -376,8 +375,19 @@ public class IrisObject extends IrisRegistrant implements PlaceableObject {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String key() {
|
||||
return getLoadKey();
|
||||
public String name() {
|
||||
String key = getLoadKey();
|
||||
return key == null ? UNNAMED : key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public com.volmit.geometry.BlockPosition center() {
|
||||
return new com.volmit.geometry.BlockPosition(center.getX(), center.getY(), center.getZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
public GeneratedObject geometry() {
|
||||
return getGeometry();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -65,7 +65,6 @@ final class IrisObjectTransforms {
|
||||
self.states = dx;
|
||||
IrisObjectShaping.shrinkwrap(self);
|
||||
self.surfaceSupportOffsets.reset();
|
||||
self.floatingFootprint.reset();
|
||||
} finally {
|
||||
self.writeLock.unlock();
|
||||
}
|
||||
@@ -165,7 +164,6 @@ final class IrisObjectTransforms {
|
||||
|
||||
self.blocks = b;
|
||||
self.surfaceSupportOffsets.reset();
|
||||
self.floatingFootprint.reset();
|
||||
} finally {
|
||||
self.writeLock.unlock();
|
||||
}
|
||||
@@ -202,7 +200,6 @@ final class IrisObjectTransforms {
|
||||
|
||||
self.blocks = b;
|
||||
self.surfaceSupportOffsets.reset();
|
||||
self.floatingFootprint.reset();
|
||||
} finally {
|
||||
self.writeLock.unlock();
|
||||
}
|
||||
@@ -243,7 +240,6 @@ final class IrisObjectTransforms {
|
||||
|
||||
self.blocks = b;
|
||||
self.surfaceSupportOffsets.reset();
|
||||
self.floatingFootprint.reset();
|
||||
} finally {
|
||||
self.writeLock.unlock();
|
||||
}
|
||||
|
||||
@@ -46,15 +46,12 @@ public final class ScaledObjects {
|
||||
private ScaledObjects() {
|
||||
}
|
||||
|
||||
/** The scaled variant of {@code origin} that {@code scale} picks; {@code origin} itself when it does not scale. */
|
||||
public static IrisObject variant(ObjectScale scale, RNG rng, IrisObject origin, Engine engine) {
|
||||
return variant(new ScaleRequest(scale.size(), scale.minimumScale(), scale.maximumScale(), scale.variations(),
|
||||
scale.interpolation()), rng, origin, engine);
|
||||
}
|
||||
|
||||
/** {@code origin} scaled by exactly {@code factor}, without interpolation. */
|
||||
public static IrisObject resized(IrisObject origin, double factor, RNG rng, Engine engine) {
|
||||
return variant(new ScaleRequest(factor, 1D, 1D, NO_VARIATIONS, ScaleInterpolation.NONE), rng, origin, engine);
|
||||
/**
|
||||
* {@code origin} scaled by {@code factor} with {@code interpolation}, even by a factor of 1, which interpolation may
|
||||
* still change; built once per origin, factor and interpolation.
|
||||
*/
|
||||
public static IrisObject scaled(IrisObject origin, double factor, ScaleInterpolation interpolation, Engine engine) {
|
||||
return cachedVariant(new ScaleRequest(factor, factor, factor, NO_VARIATIONS, interpolation), 0, origin, engine);
|
||||
}
|
||||
|
||||
static IrisObject variant(ScaleRequest request, RNG rng, IrisObject origin, Engine engine) {
|
||||
@@ -66,7 +63,10 @@ public final class ScaledObjects {
|
||||
return origin;
|
||||
}
|
||||
|
||||
int variantIndex = request.selectVariant(rng);
|
||||
return cachedVariant(request, request.selectVariant(rng), origin, engine);
|
||||
}
|
||||
|
||||
private static IrisObject cachedVariant(ScaleRequest request, int variantIndex, IrisObject origin, Engine engine) {
|
||||
ScaleCache cache = cacheOf(engine);
|
||||
CacheKey key = cache.key(origin, request, variantIndex);
|
||||
IrisObject cached = cache.lookup(key);
|
||||
|
||||
@@ -133,8 +133,6 @@ public class IrisDimension extends IrisRegistrant {
|
||||
private IrisGeneratorStyle seaBiomeStyle = NoiseStyle.CELLULAR_IRIS_DOUBLE.style();
|
||||
@Desc("The noise style used to select cave biomes within a region")
|
||||
private IrisGeneratorStyle caveBiomeStyle = NoiseStyle.CELLULAR_IRIS_DOUBLE.style();
|
||||
@Desc("Instead of filling objects with air, fills them with cobweb so you can see them")
|
||||
private boolean debugSmartBore = false;
|
||||
@Desc("The world environment")
|
||||
private IrisEnvironment environment = IrisEnvironment.NORMAL;
|
||||
@RegistryListResource(IrisRegion.class)
|
||||
|
||||
@@ -54,7 +54,7 @@ public class DiagnosticSeverityPolicyTest {
|
||||
public void generationTracingStaysAtDebugLevel() {
|
||||
assertLoggedWith("engine/mantle/components/ChunkObjectPlacing.java", "Regen object layer start:", "debug");
|
||||
assertLoggedWith("engine/mantle/components/ChunkObjectPlacing.java", "Goldendebug object attempt:", "debug");
|
||||
assertLoggedWith("engine/mantle/components/GoldenDebugObjectPlacer.java", "Goldendebug query:", "debug");
|
||||
assertLoggedWith("engine/mantle/components/GoldenDebugTerrain.java", "Goldendebug query:", "debug");
|
||||
assertLoggedWith("engine/mantle/components/StructurePlacing.java", "[StructTrace] ORIGIN", "debug");
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,10 @@ import com.volmit.ModuleLog;
|
||||
import com.volmit.block.BlockSpec;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.block.BlockTrait;
|
||||
import com.volmit.block.BlockTurn;
|
||||
import com.volmit.block.BlockRegistry;
|
||||
import com.volmit.object.PackObjects;
|
||||
import com.volmit.placement.Placements;
|
||||
import com.volmit.block.PaletteSampler;
|
||||
import com.volmit.block.PaletteSpec;
|
||||
import com.volmit.config.FeatureSettings.Entry;
|
||||
@@ -122,6 +125,11 @@ public final class CarveTestWorld implements PackWorld {
|
||||
@Override
|
||||
public PackSettings settings() {
|
||||
return new PackSettings() {
|
||||
@Override
|
||||
public PackResources resources() {
|
||||
return resources;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <F extends IrisFeature> SettingsStack<F> declared(Class<F> featureType) {
|
||||
@@ -165,6 +173,11 @@ public final class CarveTestWorld implements PackWorld {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Placements placements() {
|
||||
throw new UnsupportedOperationException("No placements here");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static IrisData packData() {
|
||||
IrisData pack = mock(IrisData.class);
|
||||
@@ -198,6 +211,11 @@ public final class CarveTestWorld implements PackWorld {
|
||||
throw new UnsupportedOperationException("No items here");
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackObjects objects() {
|
||||
throw new UnsupportedOperationException("No objects here");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NoiseFactory noise() {
|
||||
return noise;
|
||||
@@ -279,5 +297,25 @@ public final class CarveTestWorld implements PackWorld {
|
||||
public boolean canPlaceOn(BlockState state, BlockState below) {
|
||||
return hasTrait(below, BlockTrait.SOLID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState rotate(BlockState state, BlockTurn turn) {
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState merge(BlockState base, BlockState update) {
|
||||
return update;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState withProperty(BlockState state, String name, String value) {
|
||||
return state.withProperty(name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(BlockState state, BlockState pattern) {
|
||||
return state.equals(pattern);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -134,6 +134,7 @@ public class ChunkSettingsScanTimingTest {
|
||||
public FeatureSettings settings() { return settings; }
|
||||
public Mantle mantle() { throw new UnsupportedOperationException(); }
|
||||
public PackWorld world() { throw new UnsupportedOperationException(); }
|
||||
public com.volmit.placement.PlacementTerrain placementTerrain() { throw new UnsupportedOperationException(); }
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.placement.ObjectPlacement;
|
||||
import art.arcane.iris.builtin.objects.ObjectRun;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.IrisComplex;
|
||||
import art.arcane.iris.engine.UsableBlockPlatform;
|
||||
@@ -123,7 +123,7 @@ public class DimensionBottomTest {
|
||||
graph.define(Stage.placement("test:bottom/placement")).run(context -> {
|
||||
record(context.terrain());
|
||||
viewBounds.add(context.access().bounds());
|
||||
context.extension(ObjectPlacement.class).orElseThrow().anchoredAt(BOTTOM);
|
||||
context.input(ObjectRun.class).orElseThrow().anchoredAt(BOTTOM);
|
||||
context.access().set(new PlacedBlock(new BlockPosition(0, BOTTOM, 0), STONE, Optional.empty()));
|
||||
context.access().mantle().layer(MARKS).set(0, BOTTOM, 0, "bottom");
|
||||
});
|
||||
|
||||
+6
-5
@@ -3,7 +3,8 @@ package art.arcane.iris.core.modules;
|
||||
import art.arcane.iris.builtin.anchor.ObjectPlaceMode;
|
||||
import art.arcane.iris.builtin.carve.CarvingMode;
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.builtin.objects.PlacementChanges;
|
||||
import art.arcane.iris.modules.objects.PlacementChanges;
|
||||
import art.arcane.iris.modules.objects.EffectiveSettings;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
@@ -14,19 +15,19 @@ import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/** The changes iris:objects asks for are made to a copy of the placement, and the placement it came from is left alone. */
|
||||
public class IrisObjectChunkChangesTest {
|
||||
public class EffectiveSettingsChangesTest {
|
||||
@Test
|
||||
public void withoutChangesThePlacementIsUsedAsItIs() {
|
||||
ObjectPlacement base = placement("a", "b");
|
||||
|
||||
assertSame(base, IrisObjectChunk.withChanges(base, PlacementChanges.NONE));
|
||||
assertSame(base, EffectiveSettings.withChanges(base, PlacementChanges.NONE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void changesAreMadeToACopyThatKeepsTheObjectsUnlessTheyAreReplaced() {
|
||||
ObjectPlacement base = placement("a", "b");
|
||||
|
||||
ObjectPlacement changed = IrisObjectChunk.withChanges(base, PlacementChanges.NONE
|
||||
ObjectPlacement changed = EffectiveSettings.withChanges(base, PlacementChanges.NONE
|
||||
.withSurfaceSupport(false, 7).withForcePlace(true));
|
||||
|
||||
assertNotSame(base, changed);
|
||||
@@ -42,7 +43,7 @@ public class IrisObjectChunkChangesTest {
|
||||
public void objectsModeCarvingAndRotationAreReplaced() {
|
||||
ObjectPlacement base = placement("a");
|
||||
|
||||
ObjectPlacement changed = IrisObjectChunk.withChanges(base, PlacementChanges.NONE
|
||||
ObjectPlacement changed = EffectiveSettings.withChanges(base, PlacementChanges.NONE
|
||||
.withPlace(List.of("hut")).withMode(ObjectPlaceMode.FAST_MIN_STILT).withCarvingSupport(CarvingMode.ANYWHERE).withUpsideDown(true));
|
||||
|
||||
assertEquals(List.of("hut"), changed.place());
|
||||
@@ -42,7 +42,7 @@ public class IrisObjectTransformerTest {
|
||||
@Before
|
||||
public void bindPlatform() {
|
||||
UsableBlockPlatform.bind();
|
||||
previousRotator = BlockStateRotation.bindPlatformRotator((rotation, state, spinX, spinY, spinZ) -> state);
|
||||
previousRotator = BlockStateRotation.bindPlatformRotator((turn, state) -> state);
|
||||
}
|
||||
|
||||
@After
|
||||
|
||||
@@ -1,206 +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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.anchor.ObjectPlaceMode;
|
||||
import art.arcane.iris.builtin.placement.CaveSpace;
|
||||
import art.arcane.iris.builtin.placement.MarkerRule;
|
||||
import art.arcane.iris.builtin.prepare.AxisRotationClamp;
|
||||
import art.arcane.iris.builtin.prepare.ObjectRotation;
|
||||
import art.arcane.iris.builtin.prepare.ObjectTranslate;
|
||||
import art.arcane.iris.builtin.stilt.StiltSettings;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.builtin.spawn.PlacementMarker;
|
||||
import art.arcane.iris.engine.UsableBlockPlatform;
|
||||
import art.arcane.iris.engine.object.placement.IObjectPlacer;
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.engine.object.placement.IrisPlacementForm;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObject;
|
||||
import art.arcane.iris.engine.object.prefab.BlockStateRotation;
|
||||
import art.arcane.iris.engine.object.terrain.carving.CarveResult;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.block.BlockRegistry;
|
||||
import com.volmit.block.BlockSpec;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
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.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/** An Iris object placement as the built-in placement stages see it through the {@code ObjectPlacement} facade. */
|
||||
public class IrisPlacementTest {
|
||||
private static final int X = 12;
|
||||
private static final int Y = 70;
|
||||
private static final int Z = -4;
|
||||
|
||||
private IrisObject object;
|
||||
private ObjectPlacement.Builder config;
|
||||
private IrisData data;
|
||||
private IrisPlacement placement;
|
||||
private PlatformBlockStates states;
|
||||
private BlockStateRotation.StateRotator previousRotator;
|
||||
|
||||
@Before
|
||||
public void bindPlatform() {
|
||||
UsableBlockPlatform.bind();
|
||||
config = ObjectPlacement.builder();
|
||||
data = mock(IrisData.class);
|
||||
when(data.getPackResources()).thenReturn(mock(IrisPackResources.class));
|
||||
IrisObject object = new IrisObject(3, 4, 5);
|
||||
object.setLoader(data);
|
||||
this.object = object;
|
||||
states = new PlatformBlockStates(UsableBlockPlatform::block);
|
||||
placement = placementOf(config);
|
||||
}
|
||||
|
||||
/** The placement settings are read when the placement starts, so a test configures first. */
|
||||
private IrisPlacement placementOf(ObjectPlacement.Builder configured) {
|
||||
ObjectPlacement settings = configured.build();
|
||||
return new IrisPlacement(object, settings, IrisPlacementForm.of(settings, data), mock(IObjectPlacer.class), new CarveResult(70, 90), X, Y, Z, data, states,
|
||||
mock(ObjectPlacerEdit.class));
|
||||
}
|
||||
|
||||
@After
|
||||
public void unbindPlatform() {
|
||||
if (previousRotator != null) {
|
||||
BlockStateRotation.restorePlatformRotator(previousRotator);
|
||||
}
|
||||
UsableBlockPlatform.unbind();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void thePositionAndTheObjectsSizeAreTheOnesItWasAskedFor() {
|
||||
assertEquals(X, placement.x());
|
||||
assertEquals(Y, placement.requestedY());
|
||||
assertEquals(Z, placement.z());
|
||||
assertEquals(3, placement.object().width());
|
||||
assertEquals(4, placement.object().height());
|
||||
assertEquals(5, placement.object().depth());
|
||||
assertEquals(new CaveSpace(70, 20), placement.cave().orElseThrow());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void settingsReadTheIrisPlacementAsItIs() {
|
||||
config.mode(ObjectPlaceMode.VACUUM).snow(0.5).bore(true).boreExtendMaxY(3);
|
||||
config.translate(ObjectTranslate.of(1, 2, 3, 4));
|
||||
config.stiltSettings(null);
|
||||
placement = placementOf(config);
|
||||
|
||||
assertEquals(ObjectPlaceMode.VACUUM, placement.settings().mode());
|
||||
assertEquals(0.5, placement.settings().snow(), 0);
|
||||
assertTrue(placement.settings().bore());
|
||||
assertEquals(3, placement.settings().boreExtendMaxY());
|
||||
ObjectTranslate translate = placement.settings().translate();
|
||||
assertEquals(List.of(1, 2, 3, 4), List.of(translate.x(), translate.y(), translate.yRandom(), translate.z()));
|
||||
assertTrue(placement.settings().stilt().isEmpty());
|
||||
assertTrue(placement.settings().edit().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void settingsHandOutThePlacementsOwnRotation() {
|
||||
ObjectRotation model = ObjectRotation.of(0, 90, 0);
|
||||
config.rotation(model);
|
||||
placement = placementOf(config);
|
||||
|
||||
ObjectRotation rotation = placement.settings().rotation();
|
||||
|
||||
assertSame(model, rotation);
|
||||
assertTrue(rotation.canRotateY());
|
||||
assertFalse(rotation.canRotateX());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aMarkerRuleHasTheStatesOfItsTargetsAsApiStates() {
|
||||
BlockSpec planks = BlockSpec.of("minecraft:oak_planks");
|
||||
PlacementMarker marker = mock(PlacementMarker.class);
|
||||
when(marker.marker()).thenReturn("spawn/zombie");
|
||||
when(marker.maximumMarkers()).thenReturn(5);
|
||||
when(marker.exact()).thenReturn(true);
|
||||
when(marker.mark()).thenReturn(List.of(planks));
|
||||
IrisPackResources resources = mock(IrisPackResources.class);
|
||||
BlockRegistry blocks = mock(BlockRegistry.class);
|
||||
when(data.getPackResources()).thenReturn(resources);
|
||||
when(resources.blocks()).thenReturn(blocks);
|
||||
when(blocks.resolve(planks)).thenReturn(BlockState.parse("minecraft:oak_planks"));
|
||||
config.markers(List.of(marker));
|
||||
placement = placementOf(config);
|
||||
|
||||
MarkerRule rule = placement.settings().markers().getFirst();
|
||||
|
||||
assertEquals("spawn/zombie", rule.marker());
|
||||
assertEquals(5, rule.maximum());
|
||||
assertTrue(rule.exact());
|
||||
assertEquals(List.of(BlockState.parse("minecraft:oak_planks")), rule.targets());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aFlatWarpGivesNoSurfaceWarp() {
|
||||
assertTrue(placement.surfaceWarp(new RNG(1)).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void statesAreTurnedWithTheRotationTheStagesChose() {
|
||||
List<ObjectRotation> turnedWith = new ArrayList<>();
|
||||
previousRotator = BlockStateRotation.bindPlatformRotator((rotation, state, x, y, z) -> {
|
||||
turnedWith.add(rotation);
|
||||
return state;
|
||||
});
|
||||
BlockState stairs = BlockState.parse("minecraft:oak_stairs");
|
||||
|
||||
placement.rotate(stairs, placement.settings().rotation(), 1, 2, 3);
|
||||
ObjectRotation derived = ObjectRotation.of(true, new AxisRotationClamp(), AxisRotationClamp.of(true, false, 90, 90, 90),
|
||||
new AxisRotationClamp());
|
||||
placement.rotate(stairs, derived, 1, 2, 3);
|
||||
placement.rotate(stairs, derived, 1, 2, 3);
|
||||
|
||||
assertSame(placement.settings().rotation(), turnedWith.get(0));
|
||||
assertSame(derived, turnedWith.get(1));
|
||||
assertSame(derived, turnedWith.get(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void statesKeepTheirPlatformIdentityThroughTraitsAndRotation() {
|
||||
PlatformBlockState custom = mock(PlatformBlockState.class);
|
||||
when(custom.key()).thenReturn("minecraft:air");
|
||||
when(custom.isCustom()).thenReturn(true);
|
||||
BlockState api = states.toApi(custom);
|
||||
|
||||
assertTrue(placement.hasTrait(api, com.volmit.block.BlockTrait.CUSTOM));
|
||||
assertFalse(placement.hasTrait(BlockState.parse("minecraft:air"), com.volmit.block.BlockTrait.CUSTOM));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theAnchorIsKnownOnceTheStagesReportedIt() {
|
||||
placement.anchoredAt(64);
|
||||
|
||||
assertEquals(64, placement.anchorY());
|
||||
}
|
||||
}
|
||||
@@ -20,8 +20,9 @@ package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.loot.LootSettings;
|
||||
import art.arcane.iris.builtin.loot.ObjectLoot;
|
||||
import art.arcane.iris.builtin.objects.ObjectHost;
|
||||
import art.arcane.iris.builtin.objects.ObjectHost.ObjectLoots;
|
||||
import art.arcane.volmlib.util.mantle.runtime.Mantle;
|
||||
import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
|
||||
import art.arcane.volmlib.util.matter.Matter;
|
||||
import art.arcane.iris.builtin.spawn.SpawnCooldowns;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.loader.IrisRegistrant;
|
||||
@@ -168,21 +169,21 @@ public class IrisRunningWorldTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void anObjectsLootIsWhatItsPlacementDefines() {
|
||||
ObjectPlacement placement = ObjectPlacement.builder().loot(List.of(new ObjectLoot("chest", 2))).overrideGlobalLoot(true).build();
|
||||
when(engine.getObjectPlacement(X, Y, Z)).thenReturn(new PlacedObject(placement, null, 1, X, Z));
|
||||
when(engine.getObjectPlacement(X + 1, Y, Z)).thenReturn(new PlacedObject(null, null, 1, X + 1, Z));
|
||||
ObjectHost objects = world.extension(ObjectHost.class).orElseThrow();
|
||||
@SuppressWarnings("unchecked")
|
||||
public void thePlacementAtABlockIsWhatTheMantleRecordedThere() {
|
||||
EngineMantle engineMantle = mock(EngineMantle.class);
|
||||
Mantle<Matter> mantle = mock(Mantle.class);
|
||||
MantleChunk<Matter> chunk = mock(MantleChunk.class);
|
||||
when(engine.getMantle()).thenReturn(engineMantle);
|
||||
when(engineMantle.getMantle()).thenReturn(mantle);
|
||||
when(mantle.getChunk(X >> 4, Z >> 4)).thenReturn(chunk);
|
||||
when(chunk.use()).thenReturn(chunk);
|
||||
when(chunk.get(X & 15, Y, Z & 15, String.class)).thenReturn("trees/oak@7");
|
||||
when(chunk.get((X + 1) & 15, Y, Z & 15, String.class)).thenReturn("");
|
||||
|
||||
ObjectLoots loots = objects.placedLoot(X, Y, Z).orElseThrow();
|
||||
|
||||
assertEquals(1, loots.packTables().size());
|
||||
assertEquals("chest", loots.packTables().getFirst().name());
|
||||
assertTrue(loots.platformTables().isEmpty());
|
||||
assertTrue(loots.overridesGlobalLoot());
|
||||
assertTrue(loots.defined());
|
||||
assertTrue(objects.placedLoot(X + 1, Y, Z).isEmpty());
|
||||
assertTrue(objects.placedLoot(X + 2, Y, Z).isEmpty());
|
||||
assertEquals(Optional.of("trees/oak@7"), running.placementAt(X, Y, Z));
|
||||
assertTrue("an empty record is no placement", running.placementAt(X + 1, Y, Z).isEmpty());
|
||||
assertTrue(running.placementAt(X + 2, Y, Z).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+3
-3
@@ -19,7 +19,7 @@
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.anchor.ObjectPlaceMode;
|
||||
import art.arcane.iris.builtin.IrisStages;
|
||||
import art.arcane.iris.modules.placement.PlacementStages;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.object.placement.IObjectPlacer;
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
@@ -94,8 +94,8 @@ public class ObjectPlacementModuleSettingsTest {
|
||||
|
||||
@Override
|
||||
public void setup(ModuleSetup setup) {
|
||||
setup.stages().define(TOP).when(GlowSettings.class).requires(IrisStages.Blocks.COMPLETE, IrisStages.Anchor.FINAL).run(context -> {
|
||||
int y = context.output(IrisStages.Anchor.FINAL).y() + 1;
|
||||
setup.stages().define(TOP).when(GlowSettings.class).requires(PlacementStages.Blocks.COMPLETE, PlacementStages.Anchor.FINAL).run(context -> {
|
||||
int y = context.output(PlacementStages.Anchor.FINAL).y() + 1;
|
||||
String block = context.configured(GlowSettings.class).values().getFirst().block;
|
||||
context.access().set(new PlacedBlock(new BlockPosition(0, y, 0), com.volmit.block.BlockState.parse(block), Optional.empty()));
|
||||
});
|
||||
|
||||
@@ -2,7 +2,7 @@ package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.engine.UsableBlockPlatform;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.object.placement.IObjectPlacer;
|
||||
import com.volmit.placement.PlacementTerrain;
|
||||
import com.volmit.host.MantleRegistration;
|
||||
import com.volmit.geometry.BlockBox;
|
||||
import com.volmit.mantle.MantleCodec;
|
||||
@@ -59,9 +59,8 @@ public class PlacementMantleTest {
|
||||
return engine;
|
||||
}
|
||||
|
||||
private ObjectPlacerEdit edit(Engine engine) {
|
||||
return new ObjectPlacerEdit(mock(IObjectPlacer.class), area, new PlatformBlockStates(key -> null), null,
|
||||
() -> new PlacementMantle(engine, area, LAYERS));
|
||||
private TerrainEdit edit(Engine engine) {
|
||||
return new TerrainEdit(mock(PlacementTerrain.class), area, () -> new PlacementMantle(engine, area, LAYERS));
|
||||
}
|
||||
|
||||
private String stored(int x, int z) {
|
||||
@@ -70,7 +69,7 @@ public class PlacementMantleTest {
|
||||
|
||||
@Test
|
||||
public void writesReachTheMantleTogetherWhenThePlacementCommits() {
|
||||
ObjectPlacerEdit placement = edit(engine());
|
||||
TerrainEdit placement = edit(engine());
|
||||
placement.mantle().layer(MARKS).set(1, Y, 1, "near");
|
||||
placement.mantle().layer(MARKS).set(17, Y, 2, "next chunk");
|
||||
placement.mantle().layer(MARKS).set(17, Y, 3, "removed");
|
||||
@@ -89,7 +88,7 @@ public class PlacementMantleTest {
|
||||
|
||||
@Test
|
||||
public void aDiscardedPlacementLeavesTheMantleAsItWas() {
|
||||
ObjectPlacerEdit placement = edit(engine());
|
||||
TerrainEdit placement = edit(engine());
|
||||
placement.mantle().layer(MARKS).set(1, Y, 1, "written");
|
||||
|
||||
placement.close();
|
||||
@@ -99,14 +98,14 @@ public class PlacementMantleTest {
|
||||
|
||||
@Test
|
||||
public void aStageCannotOpenAnEditOfItsOwn() {
|
||||
ObjectPlacerEdit placement = edit(engine());
|
||||
TerrainEdit placement = edit(engine());
|
||||
|
||||
assertThrows(UnsupportedOperationException.class, () -> placement.mantle().edit());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void visitsAndClearsStayWithinTheHeightsTheMantleStores() {
|
||||
ObjectPlacerEdit placement = edit(engine());
|
||||
TerrainEdit placement = edit(engine());
|
||||
placement.mantle().layer(MARKS).set(1, Y, 1, "low");
|
||||
placement.mantle().layer(MARKS).set(2, HEIGHT - 1, 1, "high");
|
||||
List<String> visited = new ArrayList<>();
|
||||
@@ -121,7 +120,7 @@ public class PlacementMantleTest {
|
||||
@Test
|
||||
public void aPlacementWhoseStagesNeverAskForTheMantleNeverTouchesIt() {
|
||||
Engine engine = engine();
|
||||
ObjectPlacerEdit placement = edit(engine);
|
||||
TerrainEdit placement = edit(engine);
|
||||
|
||||
placement.commit();
|
||||
|
||||
@@ -130,7 +129,7 @@ public class PlacementMantleTest {
|
||||
|
||||
@Test
|
||||
public void writesOutsideThePlacementAreaFail() {
|
||||
ObjectPlacerEdit placement = edit(engine());
|
||||
TerrainEdit placement = edit(engine());
|
||||
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> placement.mantle().layer(MARKS).set(24, Y, 0, "out"));
|
||||
assertThrows("above the heights the mantle stores", IndexOutOfBoundsException.class,
|
||||
@@ -140,7 +139,7 @@ public class PlacementMantleTest {
|
||||
|
||||
@Test
|
||||
public void aPlacementWithoutAnEngineHasNoMantle() {
|
||||
ObjectPlacerEdit placement = new ObjectPlacerEdit(mock(IObjectPlacer.class), area, new PlatformBlockStates(key -> null), null, () -> {
|
||||
TerrainEdit placement = new TerrainEdit(mock(PlacementTerrain.class), area, () -> {
|
||||
throw new UnsupportedOperationException("This placement runs without an Iris engine, so it has no mantle");
|
||||
});
|
||||
|
||||
|
||||
@@ -18,8 +18,10 @@
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.LegacyStreams;
|
||||
import com.volmit.ModuleLog;
|
||||
import com.volmit.config.PackSettings;
|
||||
import com.volmit.placement.Placements;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.world.PackWorld;
|
||||
import org.junit.Test;
|
||||
@@ -47,7 +49,8 @@ public class ToolWorldTest {
|
||||
public void theWorldKeepsItsStateUntilItIsClosed() {
|
||||
PackResources resources = mock(PackResources.class);
|
||||
Tracked tracked;
|
||||
try (ToolWorld world = new ToolWorld(SEED, resources, mock(PackSettings.class))) {
|
||||
try (ToolWorld world = new ToolWorld(SEED, resources, mock(PackSettings.class), ignored -> mock(Placements.class),
|
||||
mock(LegacyStreams.class))) {
|
||||
tracked = world.state(Tracked.class, ignored -> new Tracked());
|
||||
|
||||
assertSame(tracked, world.state(Tracked.class, ignored -> new Tracked()));
|
||||
|
||||
@@ -8,6 +8,7 @@ import art.arcane.iris.engine.object.world.region.IrisRegion;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.modules.ModuleResourceFixture;
|
||||
import art.arcane.iris.core.modules.ModuleSettings;
|
||||
import art.arcane.iris.engine.framework.EngineGeneration;
|
||||
import art.arcane.iris.engine.mantle.components.ObjectModule;
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
@@ -43,6 +44,7 @@ public class TreeDefinitionIndexTest {
|
||||
biome.setModuleSettings(BuiltInPack.settings(TestSettings.with(new ProceduralObjectSettings(), "trees", List.of(proceduralTree))));
|
||||
|
||||
when(engine.getDimension()).thenReturn(dimension);
|
||||
when(dimension.getModuleSettings()).thenReturn(ModuleSettings.NONE);
|
||||
IrisData data = mock(IrisData.class);
|
||||
when(engine.getData()).thenReturn(data);
|
||||
ModuleResourceFixture.serve(data);
|
||||
|
||||
@@ -38,6 +38,11 @@ public class OreWarmUpTest {
|
||||
declared.add(entry(Level.REGION, "region/x", ores, "x0", "x1"));
|
||||
declared.add(entry(Level.BIOME, "biome/a", ores, "a0"));
|
||||
PackSettings settings = new PackSettings() {
|
||||
@Override
|
||||
public com.volmit.resource.PackResources resources() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <F extends IrisFeature> SettingsStack<F> declared(Class<F> featureType) {
|
||||
|
||||
@@ -6,6 +6,7 @@ import art.arcane.iris.engine.object.prefab.IrisObject;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.loader.ResourceLoader;
|
||||
import art.arcane.iris.core.modules.ModuleResourceFixture;
|
||||
import art.arcane.iris.core.modules.ModuleSettings;
|
||||
import art.arcane.iris.engine.mantle.components.ObjectModule;
|
||||
import art.arcane.iris.engine.IrisComplex;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
@@ -89,6 +90,7 @@ public class HintedLocatorTest {
|
||||
data = mock(IrisData.class);
|
||||
biomeLoader = (ResourceLoader<IrisBiome>) mock(ResourceLoader.class);
|
||||
when(engine.getDimension()).thenReturn(dimension);
|
||||
when(dimension.getModuleSettings()).thenReturn(ModuleSettings.NONE);
|
||||
when(engine.getComplex()).thenReturn(complex);
|
||||
when(engine.getData()).thenReturn(data);
|
||||
when(engine.getFocus()).thenReturn(null);
|
||||
|
||||
-27
@@ -1,27 +0,0 @@
|
||||
package art.arcane.iris.engine.framework.placer;
|
||||
|
||||
import art.arcane.iris.engine.object.noise.IrisNoiseGenerator;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.object.placement.IObjectPlacer;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class HeightmapObjectPlacerTest {
|
||||
@Test
|
||||
public void engineOwnershipDelegatesWithoutAmbientContext() {
|
||||
Engine engine = mock(Engine.class);
|
||||
IObjectPlacer ownedDelegate = mock(IObjectPlacer.class);
|
||||
when(ownedDelegate.getEngine()).thenReturn(engine);
|
||||
HeightmapObjectPlacer owned = new HeightmapObjectPlacer(mock(RNG.class), 1, 2, 3, new IrisNoiseGenerator(), ownedDelegate);
|
||||
assertSame(engine, owned.getEngine());
|
||||
|
||||
IObjectPlacer unownedDelegate = mock(IObjectPlacer.class);
|
||||
HeightmapObjectPlacer unowned = new HeightmapObjectPlacer(mock(RNG.class), 1, 2, 3, new IrisNoiseGenerator(), unownedDelegate);
|
||||
assertNull(unowned.getEngine());
|
||||
}
|
||||
}
|
||||
+5
@@ -111,6 +111,11 @@ public class ImportedFeaturesTest {
|
||||
private static PackWorld worldWith(ImportedFeaturesSettings settings) {
|
||||
PackWorld world = mock(PackWorld.class);
|
||||
when(world.settings()).thenReturn(new PackSettings() {
|
||||
@Override
|
||||
public com.volmit.resource.PackResources resources() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <F extends IrisFeature> SettingsStack<F> declared(Class<F> featureType) {
|
||||
|
||||
@@ -211,6 +211,11 @@ public class LootValidatorTest {
|
||||
public <F extends IrisFeature> SettingsStack<F> declared(Class<F> featureType) {
|
||||
return featureType == LootSettings.class ? SettingsStack.of((List<Entry<F>>) (List<?>) List.copyOf(references)) : SettingsStack.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackResources resources() {
|
||||
return resources;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package art.arcane.iris.engine.mantle.components;
|
||||
|
||||
import art.arcane.iris.builtin.carve.CaveAnchorMode;
|
||||
import art.arcane.iris.builtin.objects.CarvedSpace;
|
||||
import art.arcane.iris.builtin.objects.Cavern;
|
||||
import art.arcane.iris.modules.objects.CarvedSpace;
|
||||
import art.arcane.iris.modules.objects.Cavern;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.world.BiomeSample;
|
||||
@@ -82,25 +82,22 @@ public class CaveAnchorsTest {
|
||||
|
||||
/** A cave from {@code CAVE_FLOOR} up to, not including, {@code CAVE_CEILING}, in every column. */
|
||||
private static CarvedSpace cave() {
|
||||
return new CarvedSpace() {
|
||||
@Override
|
||||
public boolean isCarved(int x, int y, int z) {
|
||||
return y >= CAVE_FLOOR && y < CAVE_CEILING;
|
||||
CarvedSpace cave = mock(CarvedSpace.class);
|
||||
when(cave.isCarved(anyInt(), anyInt(), anyInt())).thenAnswer(call -> isCarved(call.getArgument(1)));
|
||||
when(cave.column(anyInt(), anyInt(), anyInt())).thenAnswer(call -> {
|
||||
int height = call.getArgument(2);
|
||||
byte[] column = new byte[height];
|
||||
for (int y = 0; y < height; y++) {
|
||||
column[y] = (byte) (isCarved(y) ? 1 : 0);
|
||||
}
|
||||
return column;
|
||||
});
|
||||
when(cave.cavernAt(anyInt(), anyInt(), anyInt())).thenAnswer(call ->
|
||||
isCarved(call.getArgument(1)) ? Optional.of(new Cavern(true, (byte) 0)) : Optional.empty());
|
||||
return cave;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] column(int x, int z, int height) {
|
||||
byte[] column = new byte[height];
|
||||
for (int y = 0; y < height; y++) {
|
||||
column[y] = (byte) (isCarved(x, y, z) ? 1 : 0);
|
||||
}
|
||||
return column;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Cavern> cavernAt(int x, int y, int z) {
|
||||
return isCarved(x, y, z) ? Optional.of(new Cavern(true, (byte) 0)) : Optional.empty();
|
||||
}
|
||||
};
|
||||
private static boolean isCarved(int y) {
|
||||
return y >= CAVE_FLOOR && y < CAVE_CEILING;
|
||||
}
|
||||
}
|
||||
-124
@@ -1,124 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.mantle.components;
|
||||
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.object.placement.IObjectPlacer;
|
||||
import art.arcane.iris.engine.object.prefab.TileData;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.inOrder;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class CaveObjectPlacementTransactionTest {
|
||||
@Test
|
||||
public void validPlacementCommitsBlocksTilesAndMetadataTogether() {
|
||||
IObjectPlacer delegate = createPlacer(128, 80, 20, 60);
|
||||
PlatformBlockState state = mock(PlatformBlockState.class);
|
||||
TileData tile = mock(TileData.class);
|
||||
CaveObjectPlacementTransaction transaction = new CaveObjectPlacementTransaction(delegate, 20, 10);
|
||||
|
||||
transaction.set(4, 30, 7, state);
|
||||
transaction.setTile(4, 30, 7, tile);
|
||||
transaction.setData(4, 30, 7, "object@1");
|
||||
|
||||
assertSame(state, transaction.get(4, 30, 7));
|
||||
assertEquals("object@1", transaction.getData(4, 30, 7, String.class));
|
||||
verify(delegate, never()).set(anyInt(), anyInt(), anyInt(), any());
|
||||
verify(delegate, never()).setTile(anyInt(), anyInt(), anyInt(), any());
|
||||
verify(delegate, never()).setData(anyInt(), anyInt(), anyInt(), any());
|
||||
|
||||
assertEquals(CaveObjectPlacementTransaction.CommitResult.COMMITTED, transaction.commit());
|
||||
org.mockito.InOrder order = inOrder(delegate);
|
||||
order.verify(delegate).set(4, 30, 7, state);
|
||||
order.verify(delegate).setTile(4, 30, 7, tile);
|
||||
order.verify(delegate).setData(4, 30, 7, "object@1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void oneInvalidMetadataWriteRejectsTheWholePlacement() {
|
||||
Engine engine = mock(Engine.class);
|
||||
when(engine.getHeight()).thenReturn(128);
|
||||
when(engine.getHeight(eq(4), anyInt(), eq(true))).thenReturn(80);
|
||||
when(engine.getHeight(eq(5), anyInt(), eq(true))).thenReturn(35);
|
||||
IObjectPlacer delegate = mock(IObjectPlacer.class);
|
||||
when(delegate.getEngine()).thenReturn(engine);
|
||||
when(delegate.isCarved(anyInt(), anyInt(), anyInt())).thenReturn(true);
|
||||
CaveObjectPlacementTransaction transaction = new CaveObjectPlacementTransaction(delegate, 20, 10);
|
||||
|
||||
transaction.set(4, 30, 7, mock(PlatformBlockState.class));
|
||||
transaction.setData(5, 26, 7, "ghost");
|
||||
|
||||
assertEquals(CaveObjectPlacementTransaction.CommitResult.REJECTED_BOUNDS, transaction.commit());
|
||||
verify(delegate, never()).set(anyInt(), anyInt(), anyInt(), any());
|
||||
verify(delegate, never()).setData(anyInt(), anyInt(), anyInt(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void perColumnCaveCeilingRejectsTheWholePlacement() {
|
||||
Engine engine = mock(Engine.class);
|
||||
when(engine.getHeight()).thenReturn(128);
|
||||
when(engine.getHeight(anyInt(), anyInt(), eq(true))).thenReturn(80);
|
||||
IObjectPlacer delegate = mock(IObjectPlacer.class);
|
||||
when(delegate.getEngine()).thenReturn(engine);
|
||||
when(delegate.isCarved(eq(4), anyInt(), eq(7))).thenAnswer(invocation -> invocation.<Integer>getArgument(1) <= 60);
|
||||
when(delegate.isCarved(eq(5), anyInt(), eq(7))).thenAnswer(invocation -> invocation.<Integer>getArgument(1) <= 24);
|
||||
CaveObjectPlacementTransaction transaction = new CaveObjectPlacementTransaction(delegate, 20, 10);
|
||||
|
||||
transaction.set(4, 30, 7, mock(PlatformBlockState.class));
|
||||
transaction.setData(5, 25, 7, "outside-cave");
|
||||
|
||||
assertEquals(CaveObjectPlacementTransaction.CommitResult.REJECTED_BOUNDS, transaction.commit());
|
||||
verify(delegate, never()).set(anyInt(), anyInt(), anyInt(), any());
|
||||
verify(delegate, never()).setData(anyInt(), anyInt(), anyInt(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exactBurialBoundaryIsAllowedAndShallowerAnchorsAreExcluded() {
|
||||
IObjectPlacer delegate = createPlacer(128, 80, 20, 90);
|
||||
CaveObjectPlacementTransaction transaction = new CaveObjectPlacementTransaction(delegate, 20, 10);
|
||||
transaction.set(4, 70, 7, mock(PlatformBlockState.class));
|
||||
|
||||
assertEquals(CaveObjectPlacementTransaction.CommitResult.COMMITTED, transaction.commit());
|
||||
assertEquals(71, CaveAnchors.scanUpperBound(128, 80, 10));
|
||||
assertEquals(61, CaveAnchors.scanUpperBound(128, 80, 20));
|
||||
}
|
||||
|
||||
private IObjectPlacer createPlacer(int worldHeight, int surfaceHeight, int caveFloor, int caveCeiling) {
|
||||
Engine engine = mock(Engine.class);
|
||||
when(engine.getHeight()).thenReturn(worldHeight);
|
||||
when(engine.getHeight(anyInt(), anyInt(), eq(true))).thenReturn(surfaceHeight);
|
||||
IObjectPlacer delegate = mock(IObjectPlacer.class);
|
||||
when(delegate.getEngine()).thenReturn(engine);
|
||||
when(delegate.isCarved(anyInt(), anyInt(), anyInt())).thenAnswer(invocation -> {
|
||||
int y = invocation.getArgument(1);
|
||||
return y >= caveFloor && y < caveCeiling;
|
||||
});
|
||||
return delegate;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.mantle.components;
|
||||
|
||||
import art.arcane.iris.modules.objects.CaveTransaction;
|
||||
import art.arcane.iris.modules.objects.TerrainTransaction.Commit;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.object.BlockEntityData;
|
||||
import com.volmit.placement.PlacementTerrain;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.inOrder;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/** A cave object is written whole or not at all: every block must stay inside the cave and below the buried depth. */
|
||||
public class CaveTransactionTest {
|
||||
private static final int WORLD_HEIGHT = 128;
|
||||
private static final int ANCHOR_Y = 20;
|
||||
private static final int MIN_DEPTH = 10;
|
||||
private static final BlockState STONE = BlockState.parse("minecraft:stone");
|
||||
private static final BlockState CHEST = BlockState.parse("minecraft:chest");
|
||||
|
||||
@Test
|
||||
public void validPlacementCommitsBlocksBlockEntitiesAndRecordsTogether() {
|
||||
PlacementTerrain terrain = cave(80, 20, 60);
|
||||
BlockEntityData loot = new BlockEntityData(ResourceId.parse("test:chest"), 1, new byte[0]);
|
||||
CaveTransaction transaction = new CaveTransaction(terrain, WORLD_HEIGHT, ANCHOR_Y, MIN_DEPTH);
|
||||
|
||||
transaction.set(4, 30, 7, STONE);
|
||||
transaction.set(4, 31, 7, CHEST, loot);
|
||||
transaction.recordPlacement(4, 30, 7, "object@1");
|
||||
|
||||
assertEquals(STONE, transaction.get(4, 30, 7));
|
||||
assertEquals("object@1", transaction.placementAt(4, 30, 7).orElseThrow());
|
||||
verify(terrain, never()).set(anyInt(), anyInt(), anyInt(), any());
|
||||
verify(terrain, never()).recordPlacement(anyInt(), anyInt(), anyInt(), anyString());
|
||||
|
||||
assertEquals(Commit.COMMITTED, transaction.commit());
|
||||
org.mockito.InOrder order = inOrder(terrain);
|
||||
order.verify(terrain).set(4, 30, 7, STONE);
|
||||
order.verify(terrain).set(4, 31, 7, CHEST, loot);
|
||||
order.verify(terrain).recordPlacement(4, 30, 7, "object@1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void oneRecordAboveTheBuriedDepthRejectsTheWholePlacement() {
|
||||
PlacementTerrain terrain = mock(PlacementTerrain.class);
|
||||
when(terrain.highest(eq(4), anyInt(), eq(true))).thenReturn(80);
|
||||
when(terrain.highest(eq(5), anyInt(), eq(true))).thenReturn(35);
|
||||
when(terrain.isCarved(anyInt(), anyInt(), anyInt())).thenReturn(true);
|
||||
CaveTransaction transaction = new CaveTransaction(terrain, WORLD_HEIGHT, ANCHOR_Y, MIN_DEPTH);
|
||||
|
||||
transaction.set(4, 30, 7, STONE);
|
||||
transaction.recordPlacement(5, 26, 7, "ghost");
|
||||
|
||||
assertEquals(Commit.REJECTED, transaction.commit());
|
||||
verify(terrain, never()).set(anyInt(), anyInt(), anyInt(), any());
|
||||
verify(terrain, never()).recordPlacement(anyInt(), anyInt(), anyInt(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void perColumnCaveCeilingRejectsTheWholePlacement() {
|
||||
PlacementTerrain terrain = mock(PlacementTerrain.class);
|
||||
when(terrain.highest(anyInt(), anyInt(), anyBoolean())).thenReturn(80);
|
||||
when(terrain.isCarved(eq(4), anyInt(), eq(7))).thenAnswer(call -> call.<Integer>getArgument(1) <= 60);
|
||||
when(terrain.isCarved(eq(5), anyInt(), eq(7))).thenAnswer(call -> call.<Integer>getArgument(1) <= 24);
|
||||
CaveTransaction transaction = new CaveTransaction(terrain, WORLD_HEIGHT, ANCHOR_Y, MIN_DEPTH);
|
||||
|
||||
transaction.set(4, 30, 7, STONE);
|
||||
transaction.recordPlacement(5, 25, 7, "outside-cave");
|
||||
|
||||
assertEquals(Commit.REJECTED, transaction.commit());
|
||||
verify(terrain, never()).set(anyInt(), anyInt(), anyInt(), any());
|
||||
verify(terrain, never()).recordPlacement(anyInt(), anyInt(), anyInt(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exactBurialBoundaryIsAllowedAndShallowerAnchorsAreExcluded() {
|
||||
CaveTransaction transaction = new CaveTransaction(cave(80, 20, 90), WORLD_HEIGHT, ANCHOR_Y, MIN_DEPTH);
|
||||
transaction.set(4, 70, 7, STONE);
|
||||
|
||||
assertEquals(Commit.COMMITTED, transaction.commit());
|
||||
assertEquals(71, CaveAnchors.scanUpperBound(WORLD_HEIGHT, 80, 10));
|
||||
assertEquals(61, CaveAnchors.scanUpperBound(WORLD_HEIGHT, 80, 20));
|
||||
}
|
||||
|
||||
private static PlacementTerrain cave(int surfaceHeight, int caveFloor, int caveCeiling) {
|
||||
PlacementTerrain terrain = mock(PlacementTerrain.class);
|
||||
when(terrain.highest(anyInt(), anyInt(), eq(true))).thenReturn(surfaceHeight);
|
||||
when(terrain.isCarved(anyInt(), anyInt(), anyInt())).thenAnswer(call -> {
|
||||
int y = call.getArgument(1);
|
||||
return y >= caveFloor && y < caveCeiling;
|
||||
});
|
||||
return terrain;
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -3,8 +3,8 @@ package art.arcane.iris.engine.mantle.components;
|
||||
import art.arcane.iris.builtin.anchor.ObjectPlaceMode;
|
||||
import art.arcane.iris.builtin.carve.CaveProfile;
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.builtin.objects.PlaceableObject;
|
||||
import art.arcane.iris.builtin.objects.PlacementChanges;
|
||||
import art.arcane.iris.modules.objects.PlacementChanges;
|
||||
import com.volmit.object.PlaceableObject;
|
||||
import art.arcane.iris.engine.object.TestSettings;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -68,7 +68,7 @@ public class EffectivePlacementsTest {
|
||||
|
||||
private static PlaceableObject object(String key) {
|
||||
PlaceableObject object = mock(PlaceableObject.class);
|
||||
when(object.key()).thenReturn(key);
|
||||
when(object.name()).thenReturn(key);
|
||||
return object;
|
||||
}
|
||||
}
|
||||
-100
@@ -1,100 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.mantle.components;
|
||||
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.object.prefab.TileData;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.inOrder;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class FloatingObjectPlacementTransactionTest {
|
||||
@Test
|
||||
public void unsupportedFinalTerrainRejectsBlocksTilesAndMarkersTogether() {
|
||||
IslandAnchorPlacer delegate = createPlacer(false);
|
||||
FloatingObjectPlacementTransaction transaction = new FloatingObjectPlacementTransaction(delegate);
|
||||
PlatformBlockState first = mock(PlatformBlockState.class);
|
||||
PlatformBlockState second = mock(PlatformBlockState.class);
|
||||
TileData tile = mock(TileData.class);
|
||||
|
||||
transaction.set(15, 101, 8, first);
|
||||
transaction.setData(15, 101, 8, "tree@7");
|
||||
transaction.set(16, 101, 8, second);
|
||||
transaction.setTile(16, 101, 8, tile);
|
||||
transaction.setData(16, 101, 8, "tree@7");
|
||||
|
||||
assertSame(second, transaction.get(16, 101, 8));
|
||||
assertEquals("tree@7", transaction.getData(16, 101, 8, String.class));
|
||||
verify(delegate, never()).set(anyInt(), anyInt(), anyInt(), any());
|
||||
verify(delegate, never()).setTile(anyInt(), anyInt(), anyInt(), any());
|
||||
verify(delegate, never()).setData(anyInt(), anyInt(), anyInt(), any());
|
||||
|
||||
assertEquals(FloatingObjectPlacementTransaction.CommitResult.REJECTED_SUPPORT, transaction.commit());
|
||||
verify(delegate, never()).set(anyInt(), anyInt(), anyInt(), any());
|
||||
verify(delegate, never()).setTile(anyInt(), anyInt(), anyInt(), any());
|
||||
verify(delegate, never()).setData(anyInt(), anyInt(), anyInt(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportedNeighborChunkCommitsBlocksTilesAndMarkers() {
|
||||
IslandAnchorPlacer delegate = createPlacer(true);
|
||||
FloatingObjectPlacementTransaction transaction = new FloatingObjectPlacementTransaction(delegate);
|
||||
PlatformBlockState first = mock(PlatformBlockState.class);
|
||||
PlatformBlockState second = mock(PlatformBlockState.class);
|
||||
TileData tile = mock(TileData.class);
|
||||
|
||||
transaction.set(15, 101, 8, first);
|
||||
transaction.setData(15, 101, 8, "tree@7");
|
||||
transaction.set(16, 101, 8, second);
|
||||
transaction.setTile(16, 101, 8, tile);
|
||||
transaction.setData(16, 101, 8, "tree@7");
|
||||
|
||||
assertEquals(FloatingObjectPlacementTransaction.CommitResult.COMMITTED, transaction.commit());
|
||||
org.mockito.InOrder order = inOrder(delegate);
|
||||
order.verify(delegate).set(15, 101, 8, first);
|
||||
order.verify(delegate).setData(15, 101, 8, "tree@7");
|
||||
order.verify(delegate).set(16, 101, 8, second);
|
||||
order.verify(delegate).setTile(16, 101, 8, tile);
|
||||
order.verify(delegate).setData(16, 101, 8, "tree@7");
|
||||
|
||||
assertEquals(FloatingObjectPlacementTransaction.CommitResult.EMPTY, transaction.commit());
|
||||
verify(delegate).set(16, 101, 8, second);
|
||||
}
|
||||
|
||||
private IslandAnchorPlacer createPlacer(boolean supportNeighborChunk) {
|
||||
IslandAnchorPlacer placer = mock(IslandAnchorPlacer.class);
|
||||
Engine engine = mock(Engine.class);
|
||||
when(engine.getHeight()).thenReturn(384);
|
||||
when(placer.getEngine()).thenReturn(engine);
|
||||
when(placer.canWriteObjectBlock(anyInt(), anyInt(), anyInt())).thenAnswer(invocation -> {
|
||||
int x = invocation.getArgument(0);
|
||||
return x == 15 || (supportNeighborChunk && x == 16);
|
||||
});
|
||||
return placer;
|
||||
}
|
||||
}
|
||||
+17
-10
@@ -21,10 +21,11 @@ package art.arcane.iris.engine.mantle.components;
|
||||
import art.arcane.iris.builtin.floating.FloatingChildBiome;
|
||||
import art.arcane.iris.modules.floating.FloatingChildSettings;
|
||||
import art.arcane.iris.builtin.floating.FloatingHost;
|
||||
import art.arcane.iris.builtin.objects.ObjectHost;
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.builtin.objects.ObjectSize;
|
||||
import art.arcane.iris.engine.object.TestSettings;
|
||||
import com.volmit.geometry.BlockBox;
|
||||
import com.volmit.object.PackObjects;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.config.Level;
|
||||
import com.volmit.IrisFeature;
|
||||
import com.volmit.config.FeatureSettings.Entry;
|
||||
@@ -48,13 +49,17 @@ public class FloatingObjectPlacingBoundaryRadiusTest {
|
||||
public void transformedFloatingPlacementExpandsOwnerRadius() {
|
||||
ObjectPlacement placement = TestSettings.of(ObjectPlacement.class, "{\"place\":[\"test/floating\"],\"translate\":{\"x\":32}}");
|
||||
FloatingChildBiome floatingChild = TestSettings.with(new FloatingChildBiome(), "floatingObjects", List.of(placement));
|
||||
ObjectHost objects = mock(ObjectHost.class);
|
||||
when(objects.sizeOf("test/floating")).thenReturn(Optional.of(new ObjectSize(1, 1, 1)));
|
||||
PackResources resources = mock(PackResources.class);
|
||||
PackObjects objects = mock(PackObjects.class);
|
||||
ResourceId floating = ResourceId.parse("test:test/floating");
|
||||
when(resources.objects()).thenReturn(objects);
|
||||
when(resources.idOf("test/floating")).thenReturn(floating);
|
||||
when(objects.sizeOf(floating)).thenReturn(Optional.of(new BlockBox(0, 0, 0, 1, 1, 1)));
|
||||
|
||||
assertEquals(33, FloatingObjectPlacing.reach(pack(new FloatingChildSettings(List.of(floatingChild)), objects), ModuleLogs.discarding()));
|
||||
assertEquals(33, FloatingObjectPlacing.reach(pack(new FloatingChildSettings(List.of(floatingChild)), resources), ModuleLogs.discarding()));
|
||||
}
|
||||
|
||||
private static PackSettings pack(FloatingChildSettings declared, ObjectHost objects) {
|
||||
private static PackSettings pack(FloatingChildSettings declared, PackResources resources) {
|
||||
FloatingHost floating = mock(FloatingHost.class);
|
||||
return new PackSettings() {
|
||||
@Override
|
||||
@@ -66,10 +71,12 @@ public class FloatingObjectPlacingBoundaryRadiusTest {
|
||||
|
||||
@Override
|
||||
public <T> Optional<T> extension(Class<T> type) {
|
||||
if (type == FloatingHost.class) {
|
||||
return Optional.of(type.cast(floating));
|
||||
}
|
||||
return type == ObjectHost.class ? Optional.of(type.cast(objects)) : Optional.empty();
|
||||
return type == FloatingHost.class ? Optional.of(type.cast(floating)) : Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackResources resources() {
|
||||
return resources;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package art.arcane.iris.engine.mantle.components;
|
||||
|
||||
import art.arcane.iris.builtin.floating.IslandFootprint;
|
||||
import art.arcane.iris.modules.floating.IslandFootprint;
|
||||
import art.arcane.iris.engine.object.terrain.floating.FloatingIslandSample;
|
||||
import art.arcane.iris.engine.object.terrain.floating.FloatingIslandSamples;
|
||||
import art.arcane.iris.engine.object.terrain.floating.ResolvedFloatingChild;
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package art.arcane.iris.engine.mantle.components;
|
||||
|
||||
import art.arcane.iris.builtin.objects.Cavern;
|
||||
import art.arcane.iris.modules.objects.Cavern;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
@@ -1,15 +1,20 @@
|
||||
package art.arcane.iris.engine.mantle.components;
|
||||
|
||||
import art.arcane.iris.builtin.IrisSeedPurposes;
|
||||
import art.arcane.iris.builtin.objects.ObjectBuilder;
|
||||
import art.arcane.iris.builtin.objects.ObjectHost;
|
||||
import art.arcane.iris.builtin.objects.ObjectHost.Declaration;
|
||||
import art.arcane.iris.builtin.LegacyStreams;
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.builtin.objects.ObjectSettings;
|
||||
import art.arcane.iris.builtin.objects.ProceduralObjectSettings;
|
||||
import art.arcane.iris.engine.object.TestSettings;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.IrisFeature;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.config.FeatureSettings.Entry;
|
||||
import com.volmit.config.Level;
|
||||
import com.volmit.config.PackSettings;
|
||||
import com.volmit.config.SettingsStack;
|
||||
import com.volmit.object.PackObjects;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.world.PackWorld;
|
||||
import org.junit.Test;
|
||||
@@ -21,44 +26,57 @@ import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyDouble;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.contains;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Mockito.RETURNS_MOCKS;
|
||||
import static org.mockito.Mockito.atLeastOnce;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/** Object placing builds its placements' noise and its procedural objects' variants before generation asks. */
|
||||
public class ObjectWarmUpTest {
|
||||
private static final ResourceId REGION = new ResourceId("test", "region");
|
||||
private static final ResourceId BIOME = new ResourceId("test", "biome");
|
||||
private static final ResourceId REGION = new ResourceId("test", "region/region");
|
||||
private static final ResourceId BIOME = new ResourceId("test", "biome/biome");
|
||||
|
||||
@Test
|
||||
public void everyPlacementAndProceduralObjectOfBiomesAndRegionsIsBuilt() {
|
||||
ObjectHost host = mock(ObjectHost.class);
|
||||
when(host.builder()).thenReturn(mock(ObjectBuilder.class, RETURNS_MOCKS));
|
||||
PackWorld world = worldWithStates(host);
|
||||
LegacyStreams streams = mock(LegacyStreams.class);
|
||||
PackResources resources = mock(PackResources.class, RETURNS_DEEP_STUBS);
|
||||
PackObjects objects = mock(PackObjects.class, RETURNS_MOCKS);
|
||||
when(resources.objects()).thenReturn(objects);
|
||||
when(resources.blocks().find(anyString())).thenReturn(Optional.of(BlockState.parse("minecraft:oak_log")));
|
||||
PackSettings settings = mock(PackSettings.class);
|
||||
PackWorld world = worldWithStates(settings, resources, streams);
|
||||
ObjectPlacement biomePlacement = placement();
|
||||
ObjectPlacement regionPlacement = placement();
|
||||
when(host.declarations(ObjectSettings.class)).thenReturn(List.of(
|
||||
new Declaration<>(Level.REGION, REGION, objects(regionPlacement)),
|
||||
new Declaration<>(Level.BIOME, BIOME, objects(biomePlacement))));
|
||||
when(host.declarations(ProceduralObjectSettings.class)).thenReturn(List.of(
|
||||
new Declaration<>(Level.REGION, REGION, oneTree("region-oak")),
|
||||
new Declaration<>(Level.BIOME, BIOME, oneTree("biome-oak"))));
|
||||
declare(settings, ObjectSettings.class, objects(regionPlacement), objects(biomePlacement));
|
||||
declare(settings, ProceduralObjectSettings.class, oneTree("region-oak"), oneTree("biome-oak"));
|
||||
|
||||
new ObjectWarmUp(world).warm();
|
||||
|
||||
verify(host).warm(eq(biomePlacement), any(RNG.class));
|
||||
verify(host).warm(eq(regionPlacement), any(RNG.class));
|
||||
verify(host, times(2)).builder();
|
||||
verify(streams).density(eq(biomePlacement), any(RNG.class), anyDouble(), anyDouble());
|
||||
verify(streams).density(eq(regionPlacement), any(RNG.class), anyDouble(), anyDouble());
|
||||
verify(objects, atLeastOnce()).build(contains("region-oak"), anyInt(), anyInt(), anyInt(), any());
|
||||
verify(objects, atLeastOnce()).build(contains("biome-oak"), anyInt(), anyInt(), anyInt(), any());
|
||||
}
|
||||
|
||||
private static <F extends IrisFeature> void declare(PackSettings settings, Class<F> type, F inRegion, F inBiome) {
|
||||
when(settings.declared(type)).thenReturn(SettingsStack.of(List.of(
|
||||
new Entry<>(Level.REGION, REGION, inRegion), new Entry<>(Level.BIOME, BIOME, inBiome))));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static PackWorld worldWithStates(ObjectHost host) {
|
||||
private static PackWorld worldWithStates(PackSettings settings, PackResources resources, LegacyStreams streams) {
|
||||
PackWorld world = mock(PackWorld.class);
|
||||
Map<Class<?>, Object> states = new HashMap<>();
|
||||
when(world.extension(ObjectHost.class)).thenReturn(Optional.of(host));
|
||||
when(world.settings()).thenReturn(settings);
|
||||
when(world.resources()).thenReturn(resources);
|
||||
when(world.extension(LegacyStreams.class)).thenReturn(Optional.of(streams));
|
||||
when(world.seed(IrisSeedPurposes.COMPONENT)).thenReturn(1337L);
|
||||
when(world.state(any(), any())).thenAnswer(invocation -> states.computeIfAbsent(invocation.getArgument(0),
|
||||
ignored -> invocation.<Function<PackWorld, Object>>getArgument(1).apply(world)));
|
||||
|
||||
+18
-7
@@ -1,11 +1,13 @@
|
||||
package art.arcane.iris.engine.mantle.components;
|
||||
|
||||
import art.arcane.iris.builtin.objects.ObjectHost;
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.builtin.objects.ObjectSettings;
|
||||
import art.arcane.iris.builtin.objects.ObjectSize;
|
||||
import art.arcane.iris.builtin.objects.PlaceableObject;
|
||||
import art.arcane.iris.builtin.objects.ProceduralPlacement;
|
||||
import art.arcane.iris.modules.objects.ObjectSize;
|
||||
import com.volmit.geometry.BlockBox;
|
||||
import com.volmit.object.PackObjects;
|
||||
import com.volmit.object.PlaceableObject;
|
||||
import com.volmit.resource.PackResources;
|
||||
import art.arcane.iris.modules.objects.ProceduralPlacement;
|
||||
import art.arcane.iris.builtin.anchor.ObjectPlaceMode;
|
||||
import art.arcane.iris.builtin.prepare.ObjectRotation;
|
||||
import art.arcane.iris.builtin.prepare.ObjectTranslate;
|
||||
@@ -83,11 +85,15 @@ public class PlacementReachTest {
|
||||
@SuppressWarnings("unchecked")
|
||||
public void translatedTreeSchedulesDistantOwnerChunks() throws Exception {
|
||||
ObjectPlacement placement = TestSettings.of(ObjectPlacement.class, "{\"place\":[\"test/tree\"],\"translate\":{\"x\":32}}");
|
||||
ObjectHost host = mock(ObjectHost.class);
|
||||
when(host.sizeOf("test/tree")).thenReturn(Optional.of(new ObjectSize(1, 1, 1)));
|
||||
PackResources resources = mock(PackResources.class);
|
||||
PackObjects objects = mock(PackObjects.class);
|
||||
ResourceId tree = ResourceId.parse("test:test/tree");
|
||||
when(resources.objects()).thenReturn(objects);
|
||||
when(resources.idOf("test/tree")).thenReturn(tree);
|
||||
when(objects.sizeOf(tree)).thenReturn(Optional.of(new BlockBox(0, 0, 0, 1, 1, 1)));
|
||||
ObjectSettings settings = TestSettings.with(new ObjectSettings(), "objects", List.of(placement));
|
||||
|
||||
int reach = new PlacementReach(host, ModuleLogs.discarding()).ofPack(declaring(ObjectSettings.class, settings));
|
||||
int reach = new PlacementReach(resources, ModuleLogs.discarding()).ofPack(declaring(ObjectSettings.class, settings));
|
||||
assertEquals(33, reach);
|
||||
int chunkRadius = Math.ceilDiv(reach, 16);
|
||||
assertEquals(3, chunkRadius);
|
||||
@@ -133,6 +139,11 @@ public class PlacementReachTest {
|
||||
public <T extends IrisFeature> SettingsStack<T> declared(Class<T> featureType) {
|
||||
return featureType == type ? SettingsStack.of(List.of(new Entry<>(Level.BIOME, SOURCE, (T) settings))) : SettingsStack.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackResources resources() {
|
||||
throw new UnsupportedOperationException("the reach is handed the resources itself");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.mantle.components;
|
||||
|
||||
import art.arcane.iris.modules.objects.TerrainTransaction;
|
||||
import art.arcane.iris.modules.objects.TerrainTransaction.Commit;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.object.BlockEntityData;
|
||||
import com.volmit.placement.PlacementTerrain;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.inOrder;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/** A floating object that spills into a column its island does not support is written whole or not at all. */
|
||||
public class TerrainTransactionTest {
|
||||
private static final BlockState FIRST = BlockState.parse("minecraft:oak_log");
|
||||
private static final BlockState SECOND = BlockState.parse("minecraft:chest");
|
||||
private static final BlockEntityData LOOT = new BlockEntityData(ResourceId.parse("test:chest"), 1, new byte[0]);
|
||||
|
||||
@Test
|
||||
public void unsupportedFinalTerrainRejectsBlocksBlockEntitiesAndRecordsTogether() {
|
||||
PlacementTerrain terrain = mock(PlacementTerrain.class);
|
||||
TerrainTransaction transaction = islandOver(terrain, false);
|
||||
|
||||
writeTreeAcrossTheChunkBorder(transaction);
|
||||
|
||||
assertEquals(SECOND, transaction.get(16, 101, 8));
|
||||
assertEquals("tree@7", transaction.placementAt(16, 101, 8).orElseThrow());
|
||||
verify(terrain, never()).set(anyInt(), anyInt(), anyInt(), any());
|
||||
|
||||
assertEquals(Commit.REJECTED, transaction.commit());
|
||||
verify(terrain, never()).set(anyInt(), anyInt(), anyInt(), any());
|
||||
verify(terrain, never()).set(anyInt(), anyInt(), anyInt(), any(), any());
|
||||
verify(terrain, never()).recordPlacement(anyInt(), anyInt(), anyInt(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportedNeighborChunkCommitsBlocksBlockEntitiesAndRecords() {
|
||||
PlacementTerrain terrain = mock(PlacementTerrain.class);
|
||||
TerrainTransaction transaction = islandOver(terrain, true);
|
||||
|
||||
writeTreeAcrossTheChunkBorder(transaction);
|
||||
|
||||
assertEquals(Commit.COMMITTED, transaction.commit());
|
||||
org.mockito.InOrder order = inOrder(terrain);
|
||||
order.verify(terrain).set(15, 101, 8, FIRST);
|
||||
order.verify(terrain).recordPlacement(15, 101, 8, "tree@7");
|
||||
order.verify(terrain).set(16, 101, 8, SECOND, LOOT);
|
||||
order.verify(terrain).recordPlacement(16, 101, 8, "tree@7");
|
||||
|
||||
assertEquals(Commit.EMPTY, transaction.commit());
|
||||
verify(terrain).set(16, 101, 8, SECOND, LOOT);
|
||||
}
|
||||
|
||||
private static void writeTreeAcrossTheChunkBorder(TerrainTransaction transaction) {
|
||||
transaction.set(15, 101, 8, FIRST);
|
||||
transaction.recordPlacement(15, 101, 8, "tree@7");
|
||||
transaction.set(16, 101, 8, SECOND, LOOT);
|
||||
transaction.recordPlacement(16, 101, 8, "tree@7");
|
||||
}
|
||||
|
||||
private static TerrainTransaction islandOver(PlacementTerrain terrain, boolean supportsNeighborChunk) {
|
||||
return new TerrainTransaction(terrain) {
|
||||
@Override
|
||||
protected boolean accepts(int x, int y, int z) {
|
||||
return x == 15 || (supportsNeighborChunk && x == 16);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package art.arcane.iris.engine.mantle.components;
|
||||
|
||||
import art.arcane.iris.builtin.objects.ObjectHost;
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.builtin.objects.ObjectSettings;
|
||||
import art.arcane.iris.builtin.objects.TreeGrowthSettings;
|
||||
@@ -70,7 +69,6 @@ public class TreeGrowingTest {
|
||||
when(running.settings()).thenReturn(settings);
|
||||
when(running.layout()).thenReturn(layout);
|
||||
world = mock(PackWorld.class);
|
||||
when(world.extension(ObjectHost.class)).thenReturn(Optional.of(mock(ObjectHost.class)));
|
||||
when(world.running()).thenReturn(Optional.of(running));
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,10 @@ import com.volmit.noise.NoiseSampler;
|
||||
import art.arcane.iris.builtin.IrisStages;
|
||||
import art.arcane.iris.builtin.IrisSeedPurposes;
|
||||
import art.arcane.iris.builtin.floating.FloatingHost;
|
||||
import art.arcane.iris.builtin.objects.ObjectHost;
|
||||
import art.arcane.iris.builtin.LegacyStreams;
|
||||
import com.volmit.block.BlockTurn;
|
||||
import com.volmit.object.PackObjects;
|
||||
import com.volmit.placement.Placements;
|
||||
import art.arcane.iris.modules.post.PostProcessingSlabsSettings;
|
||||
import art.arcane.iris.modules.post.PostProcessingWallsSettings;
|
||||
import art.arcane.iris.builtin.prepare.SlopeClip;
|
||||
@@ -591,7 +594,8 @@ public final class ApiChunk implements GenerationContext {
|
||||
private final Resources resources = new Resources();
|
||||
private final Map<Class<?>, Object> states = new HashMap<>();
|
||||
private final FloatingHost floating = mock(FloatingHost.class);
|
||||
private final ObjectHost objects = mock(ObjectHost.class);
|
||||
private final LegacyStreams streams = mock(LegacyStreams.class);
|
||||
private final Placements placements = mock(Placements.class);
|
||||
private final RunningWorld running = mock(RunningWorld.class);
|
||||
|
||||
World() {
|
||||
@@ -603,10 +607,15 @@ public final class ApiChunk implements GenerationContext {
|
||||
|
||||
@Override
|
||||
public <T> Optional<T> extension(Class<T> type) {
|
||||
Object offered = type == FloatingHost.class ? floating : type == ObjectHost.class ? objects : null;
|
||||
Object offered = type == FloatingHost.class ? floating : type == LegacyStreams.class ? streams : null;
|
||||
return Optional.ofNullable(offered).map(type::cast);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Placements placements() {
|
||||
return placements;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long seed() {
|
||||
return SEED;
|
||||
@@ -630,6 +639,11 @@ public final class ApiChunk implements GenerationContext {
|
||||
@Override
|
||||
public PackSettings settings() {
|
||||
return new PackSettings() {
|
||||
@Override
|
||||
public PackResources resources() {
|
||||
return resources;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <F extends IrisFeature> SettingsStack<F> declared(Class<F> featureType) {
|
||||
return declaredAtEveryLevel(featureType);
|
||||
@@ -682,6 +696,11 @@ public final class ApiChunk implements GenerationContext {
|
||||
throw new UnsupportedOperationException("No items here");
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackObjects objects() {
|
||||
throw new UnsupportedOperationException("No objects here");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NoiseFactory noise() {
|
||||
return (style, seed) -> new NoiseSampler() {
|
||||
@@ -784,6 +803,26 @@ public final class ApiChunk implements GenerationContext {
|
||||
boolean plant = DECORATIONS.contains(material) || FOLIAGE.contains(material);
|
||||
return !plant || SOILS.contains(below.material().toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState rotate(BlockState state, BlockTurn turn) {
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState merge(BlockState base, BlockState update) {
|
||||
return update;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState withProperty(BlockState state, String name, String value) {
|
||||
return state.withProperty(name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(BlockState state, BlockState pattern) {
|
||||
return state.equals(pattern);
|
||||
}
|
||||
}
|
||||
|
||||
private static final class TerrainStandIn implements IrisModule {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package art.arcane.iris.engine.modifier;
|
||||
|
||||
import art.arcane.iris.builtin.floating.FloatingHost;
|
||||
import art.arcane.iris.builtin.objects.ObjectHost;
|
||||
import art.arcane.iris.builtin.LegacyStreams;
|
||||
import art.arcane.iris.engine.decorator.BiomeDecorators;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.config.FeatureSettings;
|
||||
@@ -70,7 +70,7 @@ public class FloatingIslandsTest {
|
||||
PackWorld world = mock(PackWorld.class);
|
||||
when(world.running()).thenReturn(Optional.of(running));
|
||||
when(world.extension(FloatingHost.class)).thenReturn(Optional.of(mock(FloatingHost.class)));
|
||||
when(world.extension(ObjectHost.class)).thenReturn(Optional.of(mock(ObjectHost.class)));
|
||||
when(world.extension(LegacyStreams.class)).thenReturn(Optional.of(mock(LegacyStreams.class)));
|
||||
when(world.resources()).thenReturn(mock(PackResources.class));
|
||||
PackSettings nothingDeclared = mock(PackSettings.class);
|
||||
when(nothingDeclared.declared(any())).thenAnswer(invocation -> SettingsStack.empty());
|
||||
|
||||
+1
-5
@@ -87,6 +87,7 @@ public class IrisObjectSurfaceSupportPlacementTest {
|
||||
data = mock(IrisData.class);
|
||||
when(data.getEngine()).thenReturn(engine);
|
||||
when(engine.getData()).thenReturn(data);
|
||||
BuiltInPack.runBareWorld(engine, data);
|
||||
pack = BuiltInPack.serve(data, folder, List.of());
|
||||
}
|
||||
|
||||
@@ -334,11 +335,6 @@ public class IrisObjectSurfaceSupportPlacementTest {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebugSmartBore() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTile(int x, int y, int z, TileData tile) {
|
||||
}
|
||||
|
||||
+19
-85
@@ -1,15 +1,13 @@
|
||||
package art.arcane.iris.engine.object.placement;
|
||||
|
||||
import art.arcane.iris.builtin.placement.PlacementTerrain;
|
||||
import art.arcane.iris.builtin.placement.StructureVolumes;
|
||||
import art.arcane.iris.modules.placement.StageTerrain;
|
||||
import com.volmit.resource.PackResources;
|
||||
import art.arcane.iris.builtin.prepare.AxisRotationClamp;
|
||||
import art.arcane.iris.builtin.prepare.ObjectRotation;
|
||||
import art.arcane.iris.builtin.prepare.ObjectTranslate;
|
||||
import art.arcane.iris.engine.object.procedural.formation.ResolvedFormation;
|
||||
import art.arcane.iris.engine.object.TestSettings;
|
||||
import art.arcane.iris.builtin.objects.ObjectHost;
|
||||
import art.arcane.iris.builtin.objects.formation.Formation;
|
||||
import art.arcane.iris.core.modules.ProceduralOptions;
|
||||
import art.arcane.iris.engine.object.placement.IObjectPlacer;
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.engine.object.placement.IrisSurfaceSupport;
|
||||
@@ -34,6 +32,8 @@ import java.util.Set;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -123,7 +123,7 @@ public class IrisSurfaceSupportTest {
|
||||
SurfacePlacer placer = new SurfacePlacer(80);
|
||||
placer.carve(5, 80, -3);
|
||||
|
||||
assertTrue(IrisSurfaceSupport.isUnsupported(new Terrain(placer), 0, 0, NO_TRANSLATE, NO_ROTATION, 0, 0, 0,
|
||||
assertTrue(IrisSurfaceSupport.isUnsupported(terrain(placer), 0, 0, NO_TRANSLATE, NO_ROTATION, 0, 0, 0,
|
||||
List.of(new IrisBlockVector(5, 0, -3)), 0, 1));
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ public class IrisSurfaceSupportTest {
|
||||
ObjectRotation rotation = ObjectRotation.of(0, 90, 0);
|
||||
placer.carve(-3, 80, -7);
|
||||
|
||||
assertTrue(IrisSurfaceSupport.isUnsupported(new Terrain(placer), 0, 0, translate, rotation, 0, 0, 0,
|
||||
assertTrue(IrisSurfaceSupport.isUnsupported(terrain(placer), 0, 0, translate, rotation, 0, 0, 0,
|
||||
List.of(new IrisBlockVector(2, 0, 0)), 0, 1));
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ public class IrisSurfaceSupportTest {
|
||||
ObjectTranslate translate = ObjectTranslate.of(4, 0, 0, -2);
|
||||
placer.carve(4, 80, -2);
|
||||
|
||||
assertTrue(IrisSurfaceSupport.isUnsupported(new Terrain(placer), 0, 0, translate, NO_ROTATION, 0, 0, 0,
|
||||
assertTrue(IrisSurfaceSupport.isUnsupported(terrain(placer), 0, 0, translate, NO_ROTATION, 0, 0, 0,
|
||||
List.of(), 0, 1));
|
||||
}
|
||||
|
||||
@@ -177,89 +177,28 @@ public class IrisSurfaceSupportTest {
|
||||
@Test
|
||||
public void formationDefaultsToWiderBufferThanObjectDefault() {
|
||||
assertEquals(2, ObjectPlacement.builder().build().surfaceSupportBuffer());
|
||||
assertEquals(3, ProceduralOptions.of(new ResolvedFormation(new Formation(), mock(ObjectHost.class))).surfaceSupportBuffer());
|
||||
assertEquals(3, new ResolvedFormation(new Formation(), mock(PackResources.class)).surfaceSupportBuffer());
|
||||
|
||||
Formation flush = TestSettings.with(new Formation(), "surfaceSupportBuffer", 0);
|
||||
assertEquals(0, ProceduralOptions.of(new ResolvedFormation(flush, mock(ObjectHost.class))).surfaceSupportBuffer());
|
||||
assertEquals(0, new ResolvedFormation(flush, mock(PackResources.class)).surfaceSupportBuffer());
|
||||
}
|
||||
|
||||
private static boolean isUnsupported(IObjectPlacer placer, List<IrisBlockVector> footprint,
|
||||
int buffer, int minSolidDepth) {
|
||||
return IrisSurfaceSupport.isUnsupported(new Terrain(placer), 0, 0, NO_TRANSLATE, NO_ROTATION, 0, 0, 0,
|
||||
return IrisSurfaceSupport.isUnsupported(terrain(placer), 0, 0, NO_TRANSLATE, NO_ROTATION, 0, 0, 0,
|
||||
footprint, buffer, minSolidDepth);
|
||||
}
|
||||
|
||||
/** The three questions the support check asks, answered by a placer; the rest of a placement's terrain is not asked. */
|
||||
private record Terrain(IObjectPlacer placer) implements PlacementTerrain {
|
||||
@Override
|
||||
public int highest(int x, int z, boolean ignoreFluid) {
|
||||
return placer.getHighest(x, z, null, ignoreFluid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCarved(int x, int y, int z) {
|
||||
return placer.isCarved(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSurfaceSolid(int x, int y, int z) {
|
||||
return placer.isSurfaceSolid(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUnderwater(int x, int z) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fluidHeight() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean preventsDecay() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean debugsSmartBore() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasWorld() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double slopeAt(int x, int z) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double heightAt(double x, double z) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int minWorldY() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int worldHeight() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public StructureVolumes structureVolumes(int minX, int minZ, int maxX, int maxZ) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ResourceId> objectAt(int x, int y, int z) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
private static StageTerrain terrain(IObjectPlacer placer) {
|
||||
StageTerrain terrain = mock(StageTerrain.class);
|
||||
when(terrain.highest(anyInt(), anyInt(), anyBoolean())).thenAnswer(call ->
|
||||
placer.getHighest(call.getArgument(0), call.getArgument(1), null, call.getArgument(2)));
|
||||
when(terrain.isCarved(anyInt(), anyInt(), anyInt())).thenAnswer(call ->
|
||||
placer.isCarved(call.getArgument(0), call.getArgument(1), call.getArgument(2)));
|
||||
when(terrain.isSurfaceSolid(anyInt(), anyInt(), anyInt())).thenAnswer(call ->
|
||||
placer.isSurfaceSolid(call.getArgument(0), call.getArgument(1), call.getArgument(2)));
|
||||
return terrain;
|
||||
}
|
||||
|
||||
private static final class SurfacePlacer implements IObjectPlacer {
|
||||
@@ -345,11 +284,6 @@ public class IrisSurfaceSupportTest {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebugSmartBore() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTile(int x, int y, int z, TileData tile) {
|
||||
}
|
||||
|
||||
@@ -251,11 +251,6 @@ public class ObjectPlaceModePinTest {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebugSmartBore() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTile(int x, int y, int z, TileData tile) {
|
||||
}
|
||||
|
||||
+12
-19
@@ -8,7 +8,8 @@ import art.arcane.iris.engine.object.TestSettings;
|
||||
import art.arcane.iris.builtin.stilt.StiltSettings;
|
||||
import art.arcane.iris.builtin.prepare.SlopeClip;
|
||||
import art.arcane.iris.builtin.vacuum.VacuumSettings;
|
||||
import art.arcane.iris.builtin.IrisStages;
|
||||
import art.arcane.iris.modules.blocks.SmartBoreDebugSettings;
|
||||
import art.arcane.iris.modules.placement.PlacementStages;
|
||||
import art.arcane.iris.engine.object.noise.IrisNoiseGenerator;
|
||||
import art.arcane.iris.engine.object.placement.IObjectPlacer;
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
@@ -232,9 +233,10 @@ public class ObjectPlacementRegressionTest {
|
||||
object.setSmartBored(true);
|
||||
ObjectPlacement.Builder placement = placement();
|
||||
placement.smartBore(true);
|
||||
RecordingPlacer debug = new RecordingPlacer(null);
|
||||
debug.setDebugSmartBore(true);
|
||||
RecordingPlacer debug = new RecordingPlacer(engine);
|
||||
RecordingPlacer normal = new RecordingPlacer(null);
|
||||
SmartBoreDebugSettings shown = TestSettings.of(SmartBoreDebugSettings.class, "{\"show\":true}");
|
||||
when(engine.getDimension().getModuleSettings()).thenReturn(BuiltInPack.settings(shown));
|
||||
|
||||
object.place(0, ANCHOR_Y, 0, debug, placement.build(), new RNG(2L), data);
|
||||
object.place(0, ANCHOR_Y, 0, normal, placement.build(), new RNG(2L), data);
|
||||
@@ -394,8 +396,8 @@ public class ObjectPlacementRegressionTest {
|
||||
|
||||
@Override
|
||||
public void setup(ModuleSetup setup) {
|
||||
setup.stages().define(CAP).requires(IrisStages.Blocks.COMPLETE, IrisStages.Blocks.WRITE).run(context -> {
|
||||
WrittenBlocks written = context.output(IrisStages.Blocks.WRITE);
|
||||
setup.stages().define(CAP).requires(PlacementStages.Blocks.COMPLETE, PlacementStages.Blocks.WRITE).run(context -> {
|
||||
WrittenBlocks written = context.output(PlacementStages.Blocks.WRITE);
|
||||
writtenSizes.add(written.positions().size());
|
||||
BlockPosition first = written.positions().getFirst();
|
||||
context.access().set(0, first.y() + 1, 0, written.states().getFirst());
|
||||
@@ -414,7 +416,7 @@ public class ObjectPlacementRegressionTest {
|
||||
|
||||
@Override
|
||||
public void setup(ModuleSetup setup) {
|
||||
setup.stages().define(VETO).requires(IrisStages.Bore.CLEAR, IrisStages.Blocks.COMPLETE).run(context -> context.reject("veto"));
|
||||
setup.stages().define(VETO).requires(PlacementStages.Bore.CLEAR, PlacementStages.Blocks.COMPLETE).run(context -> context.reject("veto"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -434,7 +436,7 @@ public class ObjectPlacementRegressionTest {
|
||||
|
||||
@Override
|
||||
public void setup(ModuleSetup setup) {
|
||||
setup.stages().define(FIND).requires(IrisStages.Blocks.COMPLETE).run(context ->
|
||||
setup.stages().define(FIND).requires(PlacementStages.Blocks.COMPLETE).run(context ->
|
||||
found.add(PackResourceFixture.oak(context.world().resources())));
|
||||
}
|
||||
}
|
||||
@@ -469,7 +471,7 @@ public class ObjectPlacementRegressionTest {
|
||||
|
||||
@Override
|
||||
public void setup(ModuleSetup setup) {
|
||||
setup.stages().define(MARK).requires(IrisStages.Blocks.COMPLETE).run(context -> {
|
||||
setup.stages().define(MARK).requires(PlacementStages.Blocks.COMPLETE).run(context -> {
|
||||
Mantle mantle = context.access().mantle();
|
||||
mantle.layer(MARKS).set(0, ANCHOR_Y, 0, "first");
|
||||
mantle.layer(MARKS).set(1, ANCHOR_Y, 0, "second");
|
||||
@@ -520,7 +522,7 @@ public class ObjectPlacementRegressionTest {
|
||||
|
||||
@Override
|
||||
public void setup(ModuleSetup setup) {
|
||||
setup.stages().define(TURN).requires(IrisStages.Blocks.COMPLETE).run(context -> turned.add(context.objects().transform(
|
||||
setup.stages().define(TURN).requires(PlacementStages.Blocks.COMPLETE).run(context -> turned.add(context.objects().transform(
|
||||
PackResourceFixture.oak(context.world().resources()),
|
||||
new ObjectTransform(90, 0, 0, 1, 1, 1, false, false, false))));
|
||||
}
|
||||
@@ -654,6 +656,7 @@ public class ObjectPlacementRegressionTest {
|
||||
when(engine.getComplex()).thenReturn(complex);
|
||||
when(complex.getSlopeStream()).thenReturn(slopes);
|
||||
when(slopes.get(anyDouble(), anyDouble())).thenReturn(0.5);
|
||||
when(complex.getHeightStream()).thenReturn(ProceduralStream.ofDouble((x, z) -> (double) ANCHOR_Y));
|
||||
ObjectPlacement.Builder config = placement().bore(true);
|
||||
config.slopeCondition(TestSettings.of(SlopeClip.class, "{\"minimumSlope\":1,\"maximumSlope\":2}"));
|
||||
RNG rng = new RNG(91);
|
||||
@@ -739,7 +742,6 @@ public class ObjectPlacementRegressionTest {
|
||||
private final List<String> sampledColumns = new ArrayList<>();
|
||||
private final Engine engine;
|
||||
private int failAfterWrites = Integer.MAX_VALUE;
|
||||
private boolean debugSmartBore;
|
||||
private boolean carved;
|
||||
private boolean underwater;
|
||||
private int fluidHeight;
|
||||
@@ -752,10 +754,6 @@ public class ObjectPlacementRegressionTest {
|
||||
failAfterWrites = writes;
|
||||
}
|
||||
|
||||
private void setDebugSmartBore(boolean debugSmartBore) {
|
||||
this.debugSmartBore = debugSmartBore;
|
||||
}
|
||||
|
||||
private List<BlockWrite> writes() {
|
||||
return writes;
|
||||
}
|
||||
@@ -820,11 +818,6 @@ public class ObjectPlacementRegressionTest {
|
||||
return fluidHeight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebugSmartBore() {
|
||||
return debugSmartBore;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTile(int x, int y, int z, TileData tile) {
|
||||
}
|
||||
|
||||
+4
-4
@@ -1,6 +1,6 @@
|
||||
package art.arcane.iris.engine.object.prefab;
|
||||
|
||||
import art.arcane.iris.builtin.prepare.ObjectRotation;
|
||||
import com.volmit.block.BlockTurn;
|
||||
import art.arcane.iris.engine.object.material.BlockDataMergeSupport;
|
||||
import art.arcane.iris.engine.object.prefab.TileData;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
@@ -21,11 +21,11 @@ public class PlatformStateHookContractTest {
|
||||
PlatformBlockState source = mock(PlatformBlockState.class);
|
||||
PlatformBlockState rotated = mock(PlatformBlockState.class);
|
||||
BlockStateRotation.StateRotator hook = mock(BlockStateRotation.StateRotator.class);
|
||||
ObjectRotation rotation = new ObjectRotation();
|
||||
when(hook.rotate(rotation, source, 1, 2, 3)).thenReturn(rotated);
|
||||
BlockTurn turn = (x, y, z) -> new BlockTurn.Direction(x, y, z);
|
||||
when(hook.rotate(turn, source)).thenReturn(rotated);
|
||||
BlockStateRotation.StateRotator previous = BlockStateRotation.bindPlatformRotator(hook);
|
||||
try {
|
||||
assertSame(rotated, BlockStateRotation.rotate(rotation, source, 1, 2, 3));
|
||||
assertSame(rotated, BlockStateRotation.rotate(turn, source));
|
||||
} finally {
|
||||
BlockStateRotation.restorePlatformRotator(previous);
|
||||
}
|
||||
|
||||
+44
-10
@@ -18,16 +18,18 @@
|
||||
|
||||
package art.arcane.iris.engine.object.procedural;
|
||||
|
||||
import art.arcane.iris.builtin.objects.ObjectHost;
|
||||
import art.arcane.iris.builtin.objects.PlaceableObject;
|
||||
import art.arcane.iris.builtin.objects.ProceduralObjectSettings;
|
||||
import art.arcane.iris.builtin.objects.ProceduralPlacement;
|
||||
import art.arcane.iris.modules.objects.PlacementChanges;
|
||||
import art.arcane.iris.modules.objects.ProceduralPlacement;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.loader.ResourceLoader;
|
||||
import art.arcane.iris.core.modules.IrisObjectBuilder;
|
||||
import art.arcane.iris.core.modules.IrisPackResources;
|
||||
import art.arcane.iris.core.modules.PlatformBlockStates;
|
||||
import art.arcane.iris.core.modules.ProceduralOptions;
|
||||
import art.arcane.iris.modules.objects.EffectiveSettings;
|
||||
import art.arcane.iris.modules.objects.ObjectBuilder;
|
||||
import com.volmit.block.BlockTurn;
|
||||
import com.volmit.object.PlaceableObject;
|
||||
import com.volmit.resource.PackResources;
|
||||
import art.arcane.iris.engine.UsableBlockPlatform;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObject;
|
||||
import art.arcane.iris.util.common.data.B;
|
||||
@@ -182,7 +184,11 @@ public class ProceduralObjectsGoldenTest {
|
||||
IrisPackResources resources = mock(IrisPackResources.class, withSettings().stubOnly());
|
||||
doReturn(folder.getRoot()).when(data).getDataFolder();
|
||||
doReturn(resources).when(data).getPackResources();
|
||||
when(resources.blocks()).thenReturn(new HashedPalettes());
|
||||
doReturn(mock(ResourceLoader.class)).when(data).getBlockLoader();
|
||||
doReturn(null).when(data).getEngine();
|
||||
IrisPackResources host = new IrisPackResources(data);
|
||||
when(resources.blocks()).thenReturn(new HashedPalettes(host.blocks()));
|
||||
when(resources.objects()).thenReturn(host.objects());
|
||||
Gson gson = new GsonBuilder().registerTypeAdapterFactory(data).create();
|
||||
JsonObject sets = JsonParser.parseString(Files.readString(folder.getRoot().toPath().resolve("sets.json"))).getAsJsonObject();
|
||||
|
||||
@@ -197,10 +203,12 @@ public class ProceduralObjectsGoldenTest {
|
||||
private static String bake(ProceduralObjectSettings settings, IrisData data) throws NoSuchAlgorithmException {
|
||||
Gson plain = new Gson();
|
||||
MessageDigest digest = MessageDigest.getInstance("SHA-256");
|
||||
IrisObjectBuilder builder = new IrisObjectBuilder(data);
|
||||
for (ProceduralPlacement placement : ResolvedProceduralObjects.resolve(settings, mock(ObjectHost.class))) {
|
||||
PackResources resources = data.getPackResources();
|
||||
ObjectBuilder builder = new ObjectBuilder(resources);
|
||||
EffectiveSettings options = new EffectiveSettings();
|
||||
for (ProceduralPlacement placement : ResolvedProceduralObjects.resolve(settings, resources)) {
|
||||
update(digest, placement.name() + '|' + placement.chance() + '|' + placement.density() + '|'
|
||||
+ placement.plausible() + '|' + plain.toJson(ProceduralOptions.of(placement)) + '\n');
|
||||
+ placement.plausible() + '|' + plain.toJson(options.of(placement, PlacementChanges.NONE)) + '\n');
|
||||
for (PlaceableObject variant : ((ResolvedProceduralPlacement) placement).bake(builder)) {
|
||||
IrisObject object = (IrisObject) variant;
|
||||
update(digest, object.getLoadKey() + ' ' + object.getW() + 'x' + object.getH() + 'x' + object.getD() + ':');
|
||||
@@ -222,9 +230,35 @@ public class ProceduralObjectsGoldenTest {
|
||||
* test does not have; it is the host's, unchanged by the port.
|
||||
*/
|
||||
private static final class HashedPalettes implements BlockRegistry {
|
||||
private final BlockRegistry host;
|
||||
|
||||
private HashedPalettes(BlockRegistry host) {
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<BlockState> find(String key) {
|
||||
return Optional.of(stateOf(key));
|
||||
return host.find(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState withProperty(BlockState state, String name, String value) {
|
||||
return host.withProperty(state, name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState rotate(BlockState state, BlockTurn turn) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState merge(BlockState state, BlockState onto) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(BlockState state, BlockState pattern) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+7
-6
@@ -20,9 +20,11 @@ package art.arcane.iris.engine.object.procedural;
|
||||
|
||||
import art.arcane.iris.builtin.anchor.ObjectPlaceMode;
|
||||
import art.arcane.iris.builtin.carve.CarvingMode;
|
||||
import art.arcane.iris.builtin.objects.ObjectHost;
|
||||
import art.arcane.iris.modules.objects.PlacementChanges;
|
||||
import art.arcane.iris.modules.objects.EffectiveSettings;
|
||||
import com.volmit.resource.PackResources;
|
||||
import art.arcane.iris.builtin.objects.ProceduralObjectSettings;
|
||||
import art.arcane.iris.builtin.objects.ProceduralPlacement;
|
||||
import art.arcane.iris.modules.objects.ProceduralPlacement;
|
||||
import art.arcane.iris.builtin.objects.coral.Coral;
|
||||
import art.arcane.iris.builtin.objects.coral.CoralForm;
|
||||
import art.arcane.iris.builtin.objects.crystal.Crystal;
|
||||
@@ -33,7 +35,6 @@ import art.arcane.iris.builtin.objects.fungi.Fungus;
|
||||
import art.arcane.iris.builtin.objects.ruin.Ruin;
|
||||
import art.arcane.iris.builtin.objects.tree.TreeLeafMode;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.modules.ProceduralOptions;
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
@@ -149,20 +150,20 @@ public class ProceduralSettingsDecodingTest {
|
||||
assertEquals(1, objects.formations().size());
|
||||
assertEquals(1, objects.crystals().size());
|
||||
assertEquals("glacial-iceberg", objects.formations().get(0).name());
|
||||
assertFalse(ResolvedProceduralObjects.resolve(objects, mock(ObjectHost.class)).isEmpty());
|
||||
assertFalse(ResolvedProceduralObjects.resolve(objects, mock(PackResources.class)).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void everyKindPlacesWithItsSettings() {
|
||||
List<ProceduralPlacement> placements = ResolvedProceduralObjects.resolve(gson.fromJson("{\"coral\": [{}], \"fungi\": [{}], \"ruins\": [{}], "
|
||||
+ "\"formations\": [" + ICEBERG + "], \"crystals\": [" + FROST_BLOOM + "]}", ProceduralObjectSettings.class), mock(ObjectHost.class));
|
||||
+ "\"formations\": [" + ICEBERG + "], \"crystals\": [" + FROST_BLOOM + "]}", ProceduralObjectSettings.class), mock(PackResources.class));
|
||||
|
||||
assertEquals(5, placements.size());
|
||||
|
||||
ProceduralPlacement iceberg = placements.get(1);
|
||||
assertEquals("glacial-iceberg", iceberg.name());
|
||||
assertEquals(0.08, iceberg.chance(), 0);
|
||||
ObjectPlacement placement = ProceduralOptions.of(iceberg);
|
||||
ObjectPlacement placement = new EffectiveSettings().of(iceberg, PlacementChanges.NONE);
|
||||
assertEquals(ObjectPlaceMode.CENTER_HEIGHT, placement.mode());
|
||||
assertEquals(1, placement.surfaceSupportBuffer());
|
||||
assertEquals(-4, placement.translate().y());
|
||||
|
||||
+1
-5
@@ -85,6 +85,7 @@ public class NativeStructureObjectVetoTest {
|
||||
data = mock(IrisData.class);
|
||||
when(data.getEngine()).thenReturn(engine);
|
||||
when(engine.getData()).thenReturn(data);
|
||||
BuiltInPack.runBareWorld(engine, data);
|
||||
pack = BuiltInPack.serve(data, folder, List.of());
|
||||
}
|
||||
|
||||
@@ -330,11 +331,6 @@ public class NativeStructureObjectVetoTest {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebugSmartBore() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTile(int x, int y, int z, TileData tile) {
|
||||
tiles++;
|
||||
|
||||
+1
-1
@@ -53,6 +53,6 @@ public class ResolvedFloatingChildCarvingResolutionTest {
|
||||
ResourceId id = invocation.getArgument(1);
|
||||
return biomes.containsValue(id) ? Optional.of(new PackBiome(id, id.path(), id, 1, List.of())) : Optional.empty();
|
||||
});
|
||||
return new FloatingWorld(mock(FloatingHost.class), null, resources, null, 0L, 0L, 0, dimensionCarving);
|
||||
return new FloatingWorld(mock(FloatingHost.class), resources, null, 0L, 0L, 0, dimensionCarving);
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,7 @@ import art.arcane.iris.modules.terrain.LayerBlocks;
|
||||
import com.volmit.ModuleLog;
|
||||
import com.volmit.config.PackSettings;
|
||||
import com.volmit.host.ModuleLogs;
|
||||
import com.volmit.placement.Placements;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.world.PackWorld;
|
||||
@@ -69,6 +70,11 @@ public final class TestLayerBlocks {
|
||||
throw new UnsupportedOperationException("Only the pack's resources here");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Placements placements() {
|
||||
throw new UnsupportedOperationException("Only the pack's resources here");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int minWorldY() {
|
||||
return 0;
|
||||
|
||||
@@ -27,6 +27,7 @@ import com.volmit.config.FeatureSettings.Entry;
|
||||
import com.volmit.config.PackSettings;
|
||||
import com.volmit.config.SettingsStack;
|
||||
import com.volmit.host.ModuleLogs;
|
||||
import com.volmit.placement.Placements;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.world.PackWorld;
|
||||
@@ -49,6 +50,11 @@ public final class TestPackWorld implements PackWorld {
|
||||
|
||||
public TestPackWorld(PackResources resources, ModuleSettings dimensionSettings, long seed) {
|
||||
this(resources, new PackSettings() {
|
||||
@Override
|
||||
public PackResources resources() {
|
||||
return resources;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <F extends IrisFeature> SettingsStack<F> declared(Class<F> featureType) {
|
||||
return dimensionStack(dimensionSettings, featureType);
|
||||
@@ -118,6 +124,11 @@ public final class TestPackWorld implements PackWorld {
|
||||
return seed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Placements placements() {
|
||||
throw new UnsupportedOperationException("No placements here");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<RunningWorld> running() {
|
||||
return Optional.empty();
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package art.arcane.iris.modules.placement;
|
||||
|
||||
import art.arcane.iris.util.project.noise.SimplexNoise;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/** The vacuum edge's copy of simplex noise draws exactly what Iris's own does, so vacuumed edges stay where they were. */
|
||||
public class EdgeSimplexPinTest {
|
||||
private static final long[] SEEDS = {0L, 1L, -7L, 1337L, 0x5DEECE66DL, Long.MAX_VALUE, Long.MIN_VALUE};
|
||||
private static final double SPAN = 400D;
|
||||
private static final double STEP = 37.25D;
|
||||
|
||||
@Test
|
||||
public void edgeSimplexMatchesIrisSimplexNoiseBitForBit() {
|
||||
for (long seed : SEEDS) {
|
||||
EdgeSimplex copy = new EdgeSimplex(seed);
|
||||
SimplexNoise iris = new SimplexNoise(seed);
|
||||
for (double x = -SPAN; x <= SPAN; x += STEP) {
|
||||
for (double z = -SPAN; z <= SPAN; z += STEP) {
|
||||
assertEquals("seed " + seed + " at " + x + "," + z, iris.noiseSigned(x, z), copy.signed(x, z), 0D);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,6 +36,7 @@ import art.arcane.iris.spi.PlatformScheduler;
|
||||
import art.arcane.iris.spi.PlatformStructureHooks;
|
||||
import art.arcane.iris.spi.PlatformWorld;
|
||||
import art.arcane.volmlib.util.math.IrisBlockVector;
|
||||
import com.volmit.block.BlockTurn;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -66,7 +67,10 @@ public final class StubPlatform implements IrisPlatform {
|
||||
}
|
||||
|
||||
static PlatformBlockState rotateForTest(ObjectRotation rotation, PlatformBlockState state) {
|
||||
return rotateState(rotation, state, 0, 0, 0);
|
||||
if (rotation == null || !rotation.canRotate()) {
|
||||
return state;
|
||||
}
|
||||
return rotateState(BlockStateRotation.turnOf(rotation, 0, 0, 0), state);
|
||||
}
|
||||
|
||||
static PlatformBlockState mergeForTest(PlatformBlockState base, PlatformBlockState update) {
|
||||
@@ -280,21 +284,20 @@ public final class StubPlatform implements IrisPlatform {
|
||||
}
|
||||
}
|
||||
|
||||
private static PlatformBlockState rotateState(ObjectRotation rotation, PlatformBlockState state,
|
||||
int spinX, int spinY, int spinZ) {
|
||||
if (state == null || rotation == null || !rotation.canRotate()) {
|
||||
return state;
|
||||
private static PlatformBlockState rotateState(BlockTurn turn, PlatformBlockState state) {
|
||||
if (state == null) {
|
||||
return null;
|
||||
}
|
||||
ParsedState parsed = ParsedState.parse(state.key());
|
||||
Map<String, String> properties = parsed.properties();
|
||||
if (properties.containsKey("facing")) {
|
||||
properties.put("facing", rotateFace(rotation, properties.get("facing"), spinX, spinY, spinZ));
|
||||
properties.put("facing", rotateFace(turn, properties.get("facing")));
|
||||
} else if (properties.containsKey("rotation")) {
|
||||
properties.put("rotation", rotateSegment(rotation, properties.get("rotation"), spinX, spinY, spinZ));
|
||||
properties.put("rotation", rotateSegment(turn, properties.get("rotation")));
|
||||
} else if (properties.containsKey("axis")) {
|
||||
properties.put("axis", rotateAxis(rotation, properties.get("axis"), spinX, spinY, spinZ));
|
||||
properties.put("axis", rotateAxis(turn, properties.get("axis")));
|
||||
} else {
|
||||
rotateFaceProperties(rotation, properties, spinX, spinY, spinZ);
|
||||
rotateFaceProperties(turn, properties);
|
||||
}
|
||||
return StubBlockState.of(parsed.serialize());
|
||||
}
|
||||
@@ -342,17 +345,19 @@ public final class StubPlatform implements IrisPlatform {
|
||||
return StubBlockState.of(parsedBase.serialize());
|
||||
}
|
||||
|
||||
private static String rotateFace(ObjectRotation rotation, String face,
|
||||
int spinX, int spinY, int spinZ) {
|
||||
private static IrisBlockVector turned(BlockTurn turn, IrisBlockVector vector) {
|
||||
return BlockStateRotation.turned(turn, vector.getX(), vector.getY(), vector.getZ());
|
||||
}
|
||||
|
||||
private static String rotateFace(BlockTurn turn, String face) {
|
||||
IrisBlockVector vector = faceVector(face);
|
||||
if (vector == null) {
|
||||
return face;
|
||||
}
|
||||
return faceName(rotation.rotate(vector, spinX, spinY, spinZ));
|
||||
return faceName(turned(turn, vector));
|
||||
}
|
||||
|
||||
private static String rotateAxis(ObjectRotation rotation, String axis,
|
||||
int spinX, int spinY, int spinZ) {
|
||||
private static String rotateAxis(BlockTurn turn, String axis) {
|
||||
IrisBlockVector vector = switch (axis) {
|
||||
case "x" -> new IrisBlockVector(1, 0, 0);
|
||||
case "y" -> new IrisBlockVector(0, 1, 0);
|
||||
@@ -362,7 +367,7 @@ public final class StubPlatform implements IrisPlatform {
|
||||
if (vector == null) {
|
||||
return axis;
|
||||
}
|
||||
IrisBlockVector rotated = rotation.rotate(vector, spinX, spinY, spinZ);
|
||||
IrisBlockVector rotated = turned(turn, vector);
|
||||
double x = Math.abs(rotated.getX());
|
||||
double y = Math.abs(rotated.getY());
|
||||
double z = Math.abs(rotated.getZ());
|
||||
@@ -372,8 +377,7 @@ public final class StubPlatform implements IrisPlatform {
|
||||
return y >= z ? "y" : "z";
|
||||
}
|
||||
|
||||
private static String rotateSegment(ObjectRotation rotation, String value,
|
||||
int spinX, int spinY, int spinZ) {
|
||||
private static String rotateSegment(BlockTurn turn, String value) {
|
||||
int segment;
|
||||
try {
|
||||
segment = Math.floorMod(Integer.parseInt(value), 16);
|
||||
@@ -382,7 +386,7 @@ public final class StubPlatform implements IrisPlatform {
|
||||
}
|
||||
double angle = segment * Math.PI * 2D / 16D;
|
||||
IrisBlockVector vector = new IrisBlockVector(-Math.sin(angle), 0D, Math.cos(angle));
|
||||
IrisBlockVector rotated = rotation.rotate(vector, spinX, spinY, spinZ);
|
||||
IrisBlockVector rotated = turned(turn, vector);
|
||||
if (Math.abs(rotated.getY()) > Math.max(Math.abs(rotated.getX()), Math.abs(rotated.getZ()))) {
|
||||
return value;
|
||||
}
|
||||
@@ -391,8 +395,7 @@ public final class StubPlatform implements IrisPlatform {
|
||||
return Integer.toString(Math.floorMod(rotatedSegment, 16));
|
||||
}
|
||||
|
||||
private static void rotateFaceProperties(ObjectRotation rotation, Map<String, String> properties,
|
||||
int spinX, int spinY, int spinZ) {
|
||||
private static void rotateFaceProperties(BlockTurn turn, Map<String, String> properties) {
|
||||
List<String> faces = List.of("north", "east", "south", "west", "up", "down");
|
||||
int present = 0;
|
||||
for (String face : faces) {
|
||||
@@ -407,7 +410,7 @@ public final class StubPlatform implements IrisPlatform {
|
||||
for (String face : faces) {
|
||||
String value = properties.get(face);
|
||||
if (value != null) {
|
||||
rotated.put(rotateFace(rotation, face, spinX, spinY, spinZ), value);
|
||||
rotated.put(rotateFace(turn, face), value);
|
||||
}
|
||||
}
|
||||
for (String face : faces) {
|
||||
|
||||
Reference in new issue
Block a user