mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 00:34:19 +00:00
Iris implements the placement facade; the placement stages load from the built-ins jar
IrisPlacement implements ObjectPlacement over the placement's object, IrisObjectPlacement, placer and states (IrisObjectShape, IrisPlacementSettings, IrisPlacementTerrain). The placement modules leave IrisModuleHost and join JAR_MODULE_IDS and BuiltInPack.jarModules(); the new host module iris:placement-settings describes the classes IrisObjectPlacement holds, which a jar module may not. Tests ported; IrisPlacementTest and ObjectSpinKernelTest added.
This commit is contained in:
1 parent
48e328baef
commit
f51ba05ec5
14 files changed
+1078
-54
No files matched your search
@@ -102,7 +102,11 @@ final class IrisBlockRegistry implements BlockRegistry {
|
||||
|
||||
@Override
|
||||
public boolean hasTrait(BlockState state, BlockTrait trait) {
|
||||
PlatformBlockState platform = platformState(state);
|
||||
return hasTrait(platformState(state), trait);
|
||||
}
|
||||
|
||||
/** Whether the platform's {@code state} has {@code trait}. */
|
||||
static boolean hasTrait(PlatformBlockState platform, BlockTrait trait) {
|
||||
return switch (trait) {
|
||||
case AIR -> platform.isAir();
|
||||
case SOLID -> platform.isSolid();
|
||||
|
||||
@@ -28,7 +28,6 @@ import art.arcane.iris.engine.mantle.components.StructureModule;
|
||||
import art.arcane.iris.engine.modifier.CarveModule;
|
||||
import art.arcane.iris.engine.modifier.DepositModule;
|
||||
import art.arcane.iris.engine.modifier.FloatingModule;
|
||||
import art.arcane.iris.engine.object.placement.PlacementModules;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import com.volmit.IrisModule;
|
||||
import com.volmit.ModuleLog;
|
||||
@@ -63,7 +62,8 @@ public final class IrisModuleHost {
|
||||
* {@code IrisModule/builtin-modules.txt}) instead of being compiled into Iris. A pack loads them from its {@code modules}
|
||||
* folder, and {@link MissingBuiltInModules} warns when it loads none; a test keeps this equal to the jar's list.
|
||||
*/
|
||||
public static final List<String> JAR_MODULE_IDS = List.of("iris:post", "iris:perfection", "iris:matter");
|
||||
public static final List<String> JAR_MODULE_IDS = List.of("iris:post", "iris:perfection", "iris:matter", "iris:prepare",
|
||||
"iris:anchor", "iris:validate", "iris:bore", "iris:blocks", "iris:stilt", "iris:vacuum", "iris:snow");
|
||||
/** Iris's pack object model: built-in settings may hold these classes, which Iris reads and describes itself. */
|
||||
public static final String HOST_TYPE_PACKAGE = "art.arcane.iris.engine.object";
|
||||
private static final String[] JAR_COPY_FOLDER = {"cache", "module-jars"};
|
||||
@@ -76,14 +76,14 @@ public final class IrisModuleHost {
|
||||
return Holder.HOST;
|
||||
}
|
||||
|
||||
/** The modules every pack loads before its own: Iris's own, placement and the chunk generation every world runs. */
|
||||
/** The modules every pack loads before its own: Iris's own and the chunk generation every world runs. */
|
||||
public static List<IrisModule> builtInModules() {
|
||||
return Stream.of(hostModules(), PlacementModules.all(), generationModules()).flatMap(List::stream).toList();
|
||||
return Stream.of(hostModules(), generationModules()).flatMap(List::stream).toList();
|
||||
}
|
||||
|
||||
/** Modules that are Iris itself, not features: they write the layout's platform biomes and record the platform's custom blocks. A pack never replaces them and the built-ins jar does not hold them. */
|
||||
/** Modules that are Iris itself, not features: they write the layout's platform biomes, record the platform's custom blocks and describe the classes Iris's placement settings hold. A pack never replaces them and the built-ins jar does not hold them. */
|
||||
private static List<IrisModule> hostModules() {
|
||||
return List.of(new BiomeModule(), new CustomModule());
|
||||
return List.of(new BiomeModule(), new CustomModule(), new PlacementSettingsModule());
|
||||
}
|
||||
|
||||
private static List<IrisModule> generationModules() {
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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 java.util.List;
|
||||
|
||||
/** An Iris object as the placement stages see it. */
|
||||
final class IrisObjectShape implements ObjectShape {
|
||||
private final IrisObject object;
|
||||
|
||||
IrisObjectShape(IrisObject object) {
|
||||
this.object = object;
|
||||
}
|
||||
|
||||
@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 String key() {
|
||||
return object.getLoadKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IrisBlockVector> surfaceSupportOffsets() {
|
||||
return object.getSurfaceSupportOffsets();
|
||||
}
|
||||
}
|
||||
@@ -18,22 +18,40 @@
|
||||
|
||||
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.builtin.spawn.SpawnMarker;
|
||||
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.IrisObjectPlacement;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObject;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObjectRotation;
|
||||
import art.arcane.iris.engine.object.terrain.carving.CarveResult;
|
||||
import art.arcane.iris.engine.spawn.SpawnResources;
|
||||
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.world.BlockPosition;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Iris's own inputs of the object placement being run: the placement settings, object, placer and cave
|
||||
* that IrisApi does not describe. Iris's built-in placement stages read them through {@link #current()},
|
||||
* bound on the placing thread while the placement graph runs; pack modules cannot see this class.
|
||||
* 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}, bound on the placing
|
||||
* thread while the placement graph runs. Pack modules cannot see this class.
|
||||
*/
|
||||
public final class IrisPlacement {
|
||||
private static final ScopedValue<IrisPlacement> CURRENT = ScopedValue.newInstance();
|
||||
public final class IrisPlacement implements ObjectPlacement {
|
||||
private static final int NOT_ANCHORED = Integer.MIN_VALUE;
|
||||
|
||||
private final IrisObject object;
|
||||
@@ -46,6 +64,11 @@ public final class IrisPlacement {
|
||||
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 ObjectRotation derivedRotation;
|
||||
private IrisObjectRotation derivedIrisRotation;
|
||||
private int anchorY = NOT_ANCHORED;
|
||||
|
||||
IrisPlacement(IrisObject object, IrisObjectPlacement config, IObjectPlacer placer, CarveResult cave,
|
||||
@@ -60,66 +83,135 @@ public final class IrisPlacement {
|
||||
this.data = data;
|
||||
this.states = states;
|
||||
this.edit = edit;
|
||||
}
|
||||
|
||||
/** The placement running on this thread. */
|
||||
public static IrisPlacement current() {
|
||||
if (!CURRENT.isBound()) {
|
||||
throw new IllegalStateException("No Iris object placement is running on this thread");
|
||||
}
|
||||
return CURRENT.get();
|
||||
this.shape = new IrisObjectShape(object);
|
||||
this.settings = new IrisPlacementSettings(config, data, states);
|
||||
this.terrain = new IrisPlacementTerrain(placer, object.getLoader(), data, states);
|
||||
}
|
||||
|
||||
<T> T runBound(Supplier<T> placement) {
|
||||
return ScopedValue.where(CURRENT, this).call(placement::get);
|
||||
return ObjectPlacement.runBound(this, placement);
|
||||
}
|
||||
|
||||
public IrisObject object() {
|
||||
return object;
|
||||
@Override
|
||||
public ObjectShape object() {
|
||||
return shape;
|
||||
}
|
||||
|
||||
/** The settings as the caller passed them; the built-in preparation may derive others for this placement. */
|
||||
public IrisObjectPlacement config() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public IObjectPlacer placer() {
|
||||
return placer;
|
||||
}
|
||||
|
||||
/** The cave the object is placed in, or null outside caves. */
|
||||
public CarveResult cave() {
|
||||
return cave;
|
||||
@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;
|
||||
}
|
||||
|
||||
public IrisData data() {
|
||||
return data;
|
||||
@Override
|
||||
public Optional<CaveSpace> cave() {
|
||||
return Optional.ofNullable(cave).map(space -> new CaveSpace(space.getSurface(), space.getHeight()));
|
||||
}
|
||||
|
||||
/** Converts block states for this placement. */
|
||||
public PlatformBlockStates states() {
|
||||
return states;
|
||||
@Override
|
||||
public PlacementTerrain terrain() {
|
||||
return terrain;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlacementTerrain terrainFor(RNG rng) {
|
||||
if (config.getHeightmap() == null) {
|
||||
return terrain;
|
||||
}
|
||||
return new IrisPlacementTerrain(new HeightmapObjectPlacer(rng, x, requestedY, z, config, placer), object.getLoader(), data, states);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<SurfaceWarp> surfaceWarp(RNG rng) {
|
||||
if (config.getWarp().isFlat()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
CNG warp = config.getSurfaceWarp(rng, object.getLoader());
|
||||
double multiplier = config.getWarp().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(irisRotation(rotation).rotate(states.toPlatform(state), spinX, spinY, spinZ));
|
||||
}
|
||||
|
||||
/** The rotation model that turns blocks for the rotation the stages chose, which is the settings' own or one derived from it. */
|
||||
private IrisObjectRotation irisRotation(ObjectRotation rotation) {
|
||||
if (settings.gaveRotation(rotation)) {
|
||||
return settings.irisRotation();
|
||||
}
|
||||
if (rotation != derivedRotation) {
|
||||
IrisObjectRotation converted = new IrisObjectRotation();
|
||||
converted.setEnabled(rotation.enabled());
|
||||
converted.setXAxis(rotation.xAxis());
|
||||
converted.setYAxis(rotation.yAxis());
|
||||
converted.setZAxis(rotation.zAxis());
|
||||
derivedIrisRotation = converted;
|
||||
derivedRotation = rotation;
|
||||
}
|
||||
return derivedIrisRotation;
|
||||
}
|
||||
|
||||
@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 Optional<SpawnMarker> marker(String key) {
|
||||
return Optional.ofNullable(SpawnResources.marker(object.getLoader(), key));
|
||||
}
|
||||
|
||||
/** 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;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,233 @@
|
||||
/*
|
||||
* 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.placement.MarkerRule;
|
||||
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 art.arcane.iris.engine.object.marker.IrisObjectMarker;
|
||||
import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObjectRotation;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObjectTranslate;
|
||||
import com.volmit.block.BlockState;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/** An Iris object placement's settings as the placement stages read them. */
|
||||
final class IrisPlacementSettings implements PlacementSettings {
|
||||
private final IrisObjectPlacement config;
|
||||
private final IrisData data;
|
||||
private final PlatformBlockStates states;
|
||||
private final ObjectRotation rotation;
|
||||
|
||||
IrisPlacementSettings(IrisObjectPlacement config, IrisData data, PlatformBlockStates states) {
|
||||
this.config = config;
|
||||
this.data = data;
|
||||
this.states = states;
|
||||
IrisObjectRotation requested = config.getRotation();
|
||||
this.rotation = ObjectRotation.of(requested.isEnabled(), requested.getXAxis(), requested.getYAxis(), requested.getZAxis());
|
||||
}
|
||||
|
||||
/** The Iris rotation the settings were read from, if {@code rotation} is the one they gave. */
|
||||
boolean gaveRotation(ObjectRotation candidate) {
|
||||
return candidate == rotation;
|
||||
}
|
||||
|
||||
IrisObjectRotation irisRotation() {
|
||||
return config.getRotation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean forcePlace() {
|
||||
return config.isForcePlace();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SlopeClip slopeCondition() {
|
||||
return config.getSlopeCondition();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean rotateTowardsSlope() {
|
||||
return config.isRotateTowardsSlope();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectRotation rotation() {
|
||||
return rotation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectTranslate translate() {
|
||||
IrisObjectTranslate translate = config.getTranslate();
|
||||
return ObjectTranslate.of(translate.getX(), translate.getY(), translate.getYRandom(), translate.getZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectPlaceMode mode() {
|
||||
return config.getMode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean fromBottom() {
|
||||
return config.isFromBottom();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean bottom() {
|
||||
return config.isBottom();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CarvingMode carvingSupport() {
|
||||
return config.getCarvingSupport();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean underwater() {
|
||||
return config.isUnderwater();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onwater() {
|
||||
return config.isOnwater();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requireSurfaceSupport() {
|
||||
return config.isRequireSurfaceSupport();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int surfaceSupportBuffer() {
|
||||
return config.getSurfaceSupportBuffer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int surfaceSupportDepth() {
|
||||
return config.getSurfaceSupportDepth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectLimit clamp() {
|
||||
return config.getClamp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean bore() {
|
||||
return config.isBore();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int boreExtendMinY() {
|
||||
return config.getBoreExtendMinY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int boreExtendMaxY() {
|
||||
return config.getBoreExtendMaxY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ObjectReplace> edit() {
|
||||
return config.getEdit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean waterloggable() {
|
||||
return config.isWaterloggable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean meld() {
|
||||
return config.isMeld();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MarkerRule> markers() {
|
||||
return config.getMarkers().stream().<MarkerRule>map(marker -> new Marker(marker, data, states)).toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<StiltSettings> stilt() {
|
||||
return Optional.ofNullable(config.getStiltSettings());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<VacuumSettings> vacuum() {
|
||||
return Optional.ofNullable(config.getVacuumSettings());
|
||||
}
|
||||
|
||||
@Override
|
||||
public double snow() {
|
||||
return config.getSnow();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> allowedCollisions() {
|
||||
return config.getAllowedCollisions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> forbiddenCollisions() {
|
||||
return config.getForbiddenCollisions();
|
||||
}
|
||||
|
||||
private static final class Marker implements MarkerRule {
|
||||
private final IrisObjectMarker marker;
|
||||
private final IrisData data;
|
||||
private final PlatformBlockStates states;
|
||||
|
||||
private Marker(IrisObjectMarker marker, IrisData data, PlatformBlockStates states) {
|
||||
this.marker = marker;
|
||||
this.data = data;
|
||||
this.states = states;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String marker() {
|
||||
return marker.getMarker();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BlockState> targets() {
|
||||
return marker.getMark(data).stream().map(states::toApi).toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exact() {
|
||||
return marker.isExact();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int maximum() {
|
||||
return marker.getMaximumMarkers();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
/*
|
||||
* 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.iris.engine.terrain.TerrainPalettes;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import com.volmit.block.BlockState;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
private final PlatformBlockStates states;
|
||||
|
||||
IrisPlacementTerrain(IObjectPlacer placer, IrisData loader, IrisData data, PlatformBlockStates states) {
|
||||
this.placer = placer;
|
||||
this.loader = loader;
|
||||
this.data = data;
|
||||
this.states = states;
|
||||
}
|
||||
|
||||
@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 boolean hasBedrock() {
|
||||
return engine().getDimension().isBedrock();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int minHeight() {
|
||||
return engine().getMinHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int worldHeight() {
|
||||
return engine().getHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState rockAt(int x, int z) {
|
||||
Engine engine = engine();
|
||||
if (engine.getComplex() == null) {
|
||||
return PlatformBlockStates.AIR;
|
||||
}
|
||||
return states.toApi(TerrainPalettes.of(engine).rockAt(x, z));
|
||||
}
|
||||
|
||||
@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 String objectKeyAt(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);
|
||||
return placed == null || placed.getObject() == null ? null : 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,59 @@
|
||||
/*
|
||||
* 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.ObjectReplace;
|
||||
import art.arcane.iris.builtin.prepare.AxisRotationClamp;
|
||||
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 com.volmit.FeatureRegistry;
|
||||
import com.volmit.IrisModule;
|
||||
import com.volmit.ModuleInfo;
|
||||
import com.volmit.stage.StageGraph;
|
||||
|
||||
/**
|
||||
* Module {@code iris:placement-settings}: describes the classes an object placement's settings hold, which Iris's own
|
||||
* {@code IrisObjectPlacement} holds as fields. Only a module compiled into Iris may describe such a class, so the
|
||||
* placement stages, which ship in the built-ins jar, cannot. It has no stages and goes when the placement settings move
|
||||
* into a module and nothing of Iris's holds these classes.
|
||||
*/
|
||||
public final class PlacementSettingsModule implements IrisModule {
|
||||
private static final String VERSION = "built-in";
|
||||
|
||||
@Override
|
||||
public ModuleInfo info() {
|
||||
return ModuleInfo.of("iris:placement-settings", "Placement settings", VERSION);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void install(StageGraph graph) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(FeatureRegistry registry) {
|
||||
registry.registerHeldType(SlopeClip.class);
|
||||
registry.registerHeldType(AxisRotationClamp.class);
|
||||
registry.registerHeldType(ObjectLimit.class);
|
||||
registry.registerHeldType(StiltSettings.class);
|
||||
registry.registerHeldType(VacuumSettings.class);
|
||||
registry.registerHeldType(ObjectReplace.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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.builtin.prepare;
|
||||
|
||||
import art.arcane.iris.engine.object.prefab.IrisObjectRotation;
|
||||
import art.arcane.volmlib.util.math.IrisBlockVector;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/** The spin kernel the placement stages turn blocks with gives exactly what Iris's rotation model gives. */
|
||||
public class ObjectSpinKernelTest {
|
||||
private static final int[] SPINS = {0, 1, 4_096, 123_456, 2_147_483};
|
||||
private static final List<IrisBlockVector> POINTS = List.of(
|
||||
new IrisBlockVector(3, 5, -7), new IrisBlockVector(0, 2, 0), new IrisBlockVector(-4, 0, 9), new IrisBlockVector(11, -13, 2));
|
||||
|
||||
@Test
|
||||
public void everyKindOfAxisTurnsVectorsAsTheRotationModelTurnsThem() {
|
||||
for (IrisObjectRotation model : rotations()) {
|
||||
ObjectRotation rotation = ObjectRotation.of(model.isEnabled(), model.getXAxis(), model.getYAxis(), model.getZAxis());
|
||||
for (int spin : SPINS) {
|
||||
ObjectSpinKernel kernel = new ObjectSpinKernel(rotation, spin, spin / 3, spin / 7);
|
||||
for (IrisBlockVector point : POINTS) {
|
||||
IrisBlockVector expected = model.rotate(point, spin, spin / 3, spin / 7);
|
||||
IrisBlockVector actual = point.clone();
|
||||
kernel.rotate(actual);
|
||||
String where = model + " spin " + spin + " at " + point;
|
||||
assertEquals(where, expected.getX(), actual.getX(), 0);
|
||||
assertEquals(where, expected.getY(), actual.getY(), 0);
|
||||
assertEquals(where, expected.getZ(), actual.getZ(), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aDisabledRotationLeavesVectorsAlone() {
|
||||
ObjectRotation rotation = ObjectRotation.of(false, AxisRotationClamp.locked(true, 90, 90), AxisRotationClamp.locked(true, 90, 90),
|
||||
AxisRotationClamp.locked(true, 90, 90));
|
||||
IrisBlockVector point = new IrisBlockVector(3, 5, -7);
|
||||
|
||||
new ObjectSpinKernel(rotation, 5, 6, 7).rotate(point);
|
||||
|
||||
assertEquals(new IrisBlockVector(3, 5, -7), point);
|
||||
}
|
||||
|
||||
private static List<IrisObjectRotation> rotations() {
|
||||
IrisObjectRotation free = new IrisObjectRotation();
|
||||
free.setXAxis(AxisRotationClamp.of(true, false, 0, 0, 15));
|
||||
free.setYAxis(AxisRotationClamp.of(true, false, 0, 0, 7));
|
||||
free.setZAxis(AxisRotationClamp.of(true, false, -40, 40, 5));
|
||||
return List.of(new IrisObjectRotation(), IrisObjectRotation.of(0, 90, 0), IrisObjectRotation.of(0, 180, 0),
|
||||
IrisObjectRotation.of(0, -90, 0), IrisObjectRotation.of(90, 270, 180), IrisObjectRotation.of(-270, 0, 90),
|
||||
IrisObjectRotation.xFlip180(), IrisObjectRotation.xFlip180RandomY(), IrisObjectRotation.xFlip180WithY(270), free);
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,14 @@ import art.arcane.iris.engine.framework.SeedManager;
|
||||
import art.arcane.iris.engine.modifier.MatterModule;
|
||||
import art.arcane.iris.engine.modifier.PerfectionModule;
|
||||
import art.arcane.iris.engine.modifier.PostModule;
|
||||
import art.arcane.iris.engine.object.placement.AnchorModule;
|
||||
import art.arcane.iris.engine.object.placement.BlocksModule;
|
||||
import art.arcane.iris.engine.object.placement.BoreModule;
|
||||
import art.arcane.iris.engine.object.placement.PrepareModule;
|
||||
import art.arcane.iris.engine.object.placement.SnowModule;
|
||||
import art.arcane.iris.engine.object.placement.StiltModule;
|
||||
import art.arcane.iris.engine.object.placement.ValidateModule;
|
||||
import art.arcane.iris.engine.object.placement.VacuumModule;
|
||||
import com.volmit.IrisFeature;
|
||||
import com.volmit.IrisModule;
|
||||
import com.volmit.host.LoadedPack;
|
||||
@@ -51,7 +59,8 @@ public final class BuiltInPack {
|
||||
* with Iris; {@code BuiltInModulesJarTest} loads the same modules from the jar instead.
|
||||
*/
|
||||
public static List<IrisModule> jarModules() {
|
||||
return List.of(new PostModule(), new PerfectionModule(), new MatterModule());
|
||||
return List.of(new PostModule(), new PerfectionModule(), new MatterModule(), new PrepareModule(), new AnchorModule(),
|
||||
new ValidateModule(), new BoreModule(), new BlocksModule(), new StiltModule(), new VacuumModule(), new SnowModule());
|
||||
}
|
||||
|
||||
/** Every built-in module: Iris's own and the compiled-in copies of the jar's ({@link #jarModules()}). */
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.placement.ObjectPlacement;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.IrisComplex;
|
||||
import art.arcane.iris.engine.UsableBlockPlatform;
|
||||
@@ -122,7 +123,7 @@ public class DimensionBottomTest {
|
||||
graph.define(Stage.placement("test:bottom/placement")).run(context -> {
|
||||
record(context.terrain());
|
||||
viewBounds.add(context.access().bounds());
|
||||
IrisPlacement.current().anchoredAt(BOTTOM);
|
||||
ObjectPlacement.current().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");
|
||||
});
|
||||
|
||||
@@ -0,0 +1,199 @@
|
||||
/*
|
||||
* 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.engine.UsableBlockPlatform;
|
||||
import art.arcane.iris.engine.object.marker.IrisObjectMarker;
|
||||
import art.arcane.iris.engine.object.placement.IObjectPlacer;
|
||||
import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObject;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObjectRotation;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObjectTranslate;
|
||||
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 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 IrisObjectPlacement config;
|
||||
private IrisData data;
|
||||
private IrisPlacement placement;
|
||||
private PlatformBlockStates states;
|
||||
private IrisObjectRotation.StateRotator previousRotator;
|
||||
|
||||
@Before
|
||||
public void bindPlatform() {
|
||||
UsableBlockPlatform.bind();
|
||||
config = new IrisObjectPlacement();
|
||||
data = mock(IrisData.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(IrisObjectPlacement settings) {
|
||||
return new IrisPlacement(object, settings, mock(IObjectPlacer.class), new CarveResult(70, 90), X, Y, Z, data, states,
|
||||
mock(ObjectPlacerEdit.class));
|
||||
}
|
||||
|
||||
@After
|
||||
public void unbindPlatform() {
|
||||
if (previousRotator != null) {
|
||||
IrisObjectRotation.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.setMode(ObjectPlaceMode.VACUUM).setSnow(0.5).setBore(true).setBoreExtendMaxY(3);
|
||||
config.setTranslate(new IrisObjectTranslate().setX(1).setY(2).setYRandom(3).setZ(4));
|
||||
config.setStiltSettings(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());
|
||||
assertSame(config.getEdit(), placement.settings().edit());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void settingsHandOutTheRotationAsTheModelWritesIt() {
|
||||
IrisObjectRotation model = IrisObjectRotation.of(0, 90, 0);
|
||||
config.setRotation(model);
|
||||
placement = placementOf(config);
|
||||
|
||||
ObjectRotation rotation = placement.settings().rotation();
|
||||
|
||||
assertSame(model.getYAxis(), rotation.yAxis());
|
||||
assertEquals(model.isEnabled(), rotation.enabled());
|
||||
assertTrue(rotation.canRotateY());
|
||||
assertFalse(rotation.canRotateX());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aMarkerRuleHasTheStatesOfItsTargetsAsApiStates() {
|
||||
IrisObjectMarker marker = mock(IrisObjectMarker.class);
|
||||
PlatformBlockState planks = UsableBlockPlatform.block("minecraft:oak_planks");
|
||||
when(marker.getMarker()).thenReturn("spawn/zombie");
|
||||
when(marker.getMaximumMarkers()).thenReturn(5);
|
||||
when(marker.isExact()).thenReturn(true);
|
||||
when(marker.getMark(any())).thenReturn(new KList<>(List.of(planks)));
|
||||
config.setMarkers(new KList<>(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 statesAreTurnedWithTheSettingsRotationOrWithOneTheStagesDerived() {
|
||||
List<IrisObjectRotation> turnedWith = new ArrayList<>();
|
||||
previousRotator = IrisObjectRotation.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(config.getRotation(), turnedWith.get(0));
|
||||
assertEquals(90, turnedWith.get(1).getYAxis().max(), 0);
|
||||
assertTrue(turnedWith.get(1).isEnabled());
|
||||
assertSame("the converted rotation is kept for the placement", turnedWith.get(1), 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());
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -68,7 +68,7 @@ public class PackModuleJarNextToBuiltInsTest {
|
||||
Map.of("pack.ported.Ported", module("ported", "Ported", FIRST_ID),
|
||||
"pack.companion.Companion", module("companion", "Companion", SECOND_ID)));
|
||||
|
||||
try (LoadedPack pack = BuiltInPack.serve(mock(IrisData.class), folder, packFolder, List.of())) {
|
||||
try (LoadedPack pack = BuiltInPack.serve(mock(IrisData.class), folder, packFolder, BuiltInPack.jarModules())) {
|
||||
assertEquals(List.of(FIRST_ID, SECOND_ID), pack.packModules().stream().map(module -> module.info().id().toString()).toList());
|
||||
List<String> stages = pack.placement().stages().stream().map(stage -> stage.stage().id().toString()).toList();
|
||||
assertTrue(stages.toString(), stages.contains(PREPARE_STAGE));
|
||||
|
||||
+99
-8
@@ -1,5 +1,10 @@
|
||||
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.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.formation.Formation;
|
||||
@@ -8,12 +13,12 @@ import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
|
||||
import art.arcane.iris.engine.object.placement.IrisSurfaceSupport;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObject;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObjectRotation;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObjectTranslate;
|
||||
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 art.arcane.volmlib.util.math.IrisBlockVector;
|
||||
import com.volmit.block.BlockState;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -31,6 +36,8 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
public class IrisSurfaceSupportTest {
|
||||
private static final List<IrisBlockVector> SINGLE_COLUMN = List.of(new IrisBlockVector(0, 0, 0));
|
||||
private static final ObjectTranslate NO_TRANSLATE = new ObjectTranslate();
|
||||
private static final ObjectRotation NO_ROTATION = ObjectRotation.of(false, new AxisRotationClamp(), new AxisRotationClamp(), new AxisRotationClamp());
|
||||
|
||||
@Test
|
||||
public void carvedSurfaceColumnRejectsPlacement() {
|
||||
@@ -113,28 +120,29 @@ public class IrisSurfaceSupportTest {
|
||||
SurfacePlacer placer = new SurfacePlacer(80);
|
||||
placer.carve(5, 80, -3);
|
||||
|
||||
assertTrue(IrisSurfaceSupport.isUnsupported(placer, null, 0, 0, null, null, 0, 0, 0,
|
||||
assertTrue(IrisSurfaceSupport.isUnsupported(new Terrain(placer), 0, 0, NO_TRANSLATE, NO_ROTATION, 0, 0, 0,
|
||||
List.of(new IrisBlockVector(5, 0, -3)), 0, 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void placementTranslationAndRotationMatchObjectBlocks() {
|
||||
SurfacePlacer placer = new SurfacePlacer(80);
|
||||
IrisObjectTranslate translate = new IrisObjectTranslate().setX(5).setZ(-3);
|
||||
IrisObjectRotation rotation = IrisObjectRotation.of(0, 90, 0);
|
||||
ObjectTranslate translate = ObjectTranslate.of(5, 0, 0, -3);
|
||||
IrisObjectRotation turned = IrisObjectRotation.of(0, 90, 0);
|
||||
ObjectRotation rotation = ObjectRotation.of(turned.isEnabled(), turned.getXAxis(), turned.getYAxis(), turned.getZAxis());
|
||||
placer.carve(-3, 80, -7);
|
||||
|
||||
assertTrue(IrisSurfaceSupport.isUnsupported(placer, null, 0, 0, translate, rotation, 0, 0, 0,
|
||||
assertTrue(IrisSurfaceSupport.isUnsupported(new Terrain(placer), 0, 0, translate, rotation, 0, 0, 0,
|
||||
List.of(new IrisBlockVector(2, 0, 0)), 0, 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptyFootprintFallsBackToPlacementOrigin() {
|
||||
SurfacePlacer placer = new SurfacePlacer(80);
|
||||
IrisObjectTranslate translate = new IrisObjectTranslate().setX(4).setZ(-2);
|
||||
ObjectTranslate translate = ObjectTranslate.of(4, 0, 0, -2);
|
||||
placer.carve(4, 80, -2);
|
||||
|
||||
assertTrue(IrisSurfaceSupport.isUnsupported(placer, null, 0, 0, translate, null, 0, 0, 0,
|
||||
assertTrue(IrisSurfaceSupport.isUnsupported(new Terrain(placer), 0, 0, translate, NO_ROTATION, 0, 0, 0,
|
||||
List.of(), 0, 1));
|
||||
}
|
||||
|
||||
@@ -175,10 +183,93 @@ public class IrisSurfaceSupportTest {
|
||||
|
||||
private static boolean isUnsupported(IObjectPlacer placer, List<IrisBlockVector> footprint,
|
||||
int buffer, int minSolidDepth) {
|
||||
return IrisSurfaceSupport.isUnsupported(placer, null, 0, 0, null, null, 0, 0, 0,
|
||||
return IrisSurfaceSupport.isUnsupported(new 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 boolean hasBedrock() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int minHeight() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int worldHeight() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState rockAt(int x, int z) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public StructureVolumes structureVolumes(int minX, int minZ, int maxX, int maxZ) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String objectKeyAt(int x, int y, int z) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
private static final class SurfacePlacer implements IObjectPlacer {
|
||||
private final int defaultHeight;
|
||||
private final Map<String, Integer> heights = new HashMap<>();
|
||||
|
||||
@@ -107,7 +107,7 @@ public class ResolvedReplaceTest {
|
||||
ResolvedReplace replace = new ResolvedReplace(List.of(), false, 1F, spec, blocks);
|
||||
RNG rng = new RNG(SEED);
|
||||
|
||||
assertEquals("minecraft:chest", replace.tile(rng).orElseThrow().getMaterialKey());
|
||||
assertEquals("minecraft:chest", BlockEntities.tileOf(replace.tile(rng).orElseThrow()).getMaterialKey());
|
||||
assertEquals("no draw", new RNG(SEED).nextInt(1000), rng.nextInt(1000));
|
||||
}
|
||||
|
||||
@@ -124,11 +124,11 @@ public class ResolvedReplaceTest {
|
||||
|
||||
for (long seed = 0; seed < 40; seed++) {
|
||||
int drawn = new RNG(seed).nextInt(3);
|
||||
Optional<TileData> tile = replace.tile(new RNG(seed));
|
||||
Optional<BlockEntityData> tile = replace.tile(new RNG(seed));
|
||||
if (drawn == 2) {
|
||||
assertTrue("an entry without tile data gives none", tile.isEmpty());
|
||||
} else {
|
||||
assertEquals(drawn == 0 ? "minecraft:chest" : "minecraft:barrel", tile.orElseThrow().getMaterialKey());
|
||||
assertEquals(drawn == 0 ? "minecraft:chest" : "minecraft:barrel", BlockEntities.tileOf(tile.orElseThrow()).getMaterialKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user