mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 00:34:19 +00:00
Follow the API's removed object transformer and placement blocks
IrisObjectTransformer and TerrainBlockView served only PlacementContext.objects() and blocks(), now gone from the API. The settings decoder no longer reads object generator keys, and the schema drops the platform biome reference. The entity pin moves because EntitySpec no longer prints its empty extensions list (verified: the new print with ", extensions=[]" put back in its three places is the old one).
This commit is contained in:
1 parent
eb2ac206b1
commit
c0ac9d7f4e
9 files changed
+4
-434
No files matched your search
@@ -1,139 +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.engine.object.prefab.BlockStateRotation;
|
||||
import art.arcane.iris.engine.object.prefab.ObjectTurn;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.volmlib.util.math.IrisBlockVector;
|
||||
import com.volmit.geometry.BlockBox;
|
||||
import com.volmit.geometry.BlockPosition;
|
||||
import com.volmit.object.GeneratedObject;
|
||||
import com.volmit.object.ObjectBlock;
|
||||
import com.volmit.object.ObjectMarker;
|
||||
import com.volmit.object.ObjectTransform;
|
||||
import com.volmit.object.ObjectTransformer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Transforms geometry with the rotation Iris places objects with ({@link ObjectTurn}, its axis order
|
||||
* included) about the anchor, turning block states with the object so stairs and logs face the way it does.
|
||||
* Mirrors come first, as {@link ObjectTransform} says: an X or Z mirror flips positions about the anchor and
|
||||
* mirrors block states through the platform's own mirror, so stairs and doors face the mirrored way. A Y mirror
|
||||
* flips positions the way Iris hangs an object from a ceiling, without changing block states, since blocks have
|
||||
* no mirror along Y. Iris has no way to scale geometry, so that request fails with
|
||||
* {@link UnsupportedOperationException} rather than changing the request. Blocks that a turn by an angle that is
|
||||
* not a quarter turn sends to one position keep the last one, as Iris overwrites them when it places.
|
||||
*/
|
||||
final class IrisObjectTransformer implements ObjectTransformer {
|
||||
private static final double NO_SCALE = 1D;
|
||||
|
||||
@Override
|
||||
public GeneratedObject transform(GeneratedObject object, ObjectTransform transform) {
|
||||
requireSupported(transform);
|
||||
if (transform.equals(ObjectTransform.identity())) {
|
||||
return object;
|
||||
}
|
||||
Turn turn = new Turn(object.anchor(), transform);
|
||||
Map<BlockPosition, ObjectBlock> blocks = new LinkedHashMap<>();
|
||||
for (ObjectBlock block : object.blocks()) {
|
||||
BlockPosition moved = turn.position(block.position());
|
||||
blocks.put(moved, new ObjectBlock(moved, turn.state(block), block.blockEntity()));
|
||||
}
|
||||
List<ObjectMarker> markers = new ArrayList<>();
|
||||
for (ObjectMarker marker : object.markers()) {
|
||||
markers.add(new ObjectMarker(turn.position(marker.position()), marker.type(), marker.attributes()));
|
||||
}
|
||||
return new GeneratedObject(boundsOf(blocks.keySet(), markers, object.bounds()), object.anchor(), List.copyOf(blocks.values()), markers);
|
||||
}
|
||||
|
||||
private static void requireSupported(ObjectTransform transform) {
|
||||
if (transform.scaleX() != NO_SCALE || transform.scaleY() != NO_SCALE || transform.scaleZ() != NO_SCALE) {
|
||||
throw new UnsupportedOperationException("Iris cannot scale an object's geometry: " + transform);
|
||||
}
|
||||
}
|
||||
|
||||
private static BlockBox boundsOf(Iterable<BlockPosition> blocks, List<ObjectMarker> markers, BlockBox whenEmpty) {
|
||||
List<BlockPosition> positions = new ArrayList<>();
|
||||
blocks.forEach(positions::add);
|
||||
markers.forEach(marker -> positions.add(marker.position()));
|
||||
if (positions.isEmpty()) {
|
||||
return whenEmpty;
|
||||
}
|
||||
int minX = Integer.MAX_VALUE, minY = Integer.MAX_VALUE, minZ = Integer.MAX_VALUE;
|
||||
int maxX = Integer.MIN_VALUE, maxY = Integer.MIN_VALUE, maxZ = Integer.MIN_VALUE;
|
||||
for (BlockPosition position : positions) {
|
||||
minX = Math.min(minX, position.x());
|
||||
minY = Math.min(minY, position.y());
|
||||
minZ = Math.min(minZ, position.z());
|
||||
maxX = Math.max(maxX, position.x());
|
||||
maxY = Math.max(maxY, position.y());
|
||||
maxZ = Math.max(maxZ, position.z());
|
||||
}
|
||||
return new BlockBox(minX, minY, minZ, maxX + 1, maxY + 1, maxZ + 1);
|
||||
}
|
||||
|
||||
/** One requested turn about an anchor. */
|
||||
private static final class Turn {
|
||||
private final BlockPosition anchor;
|
||||
private final boolean mirrorX;
|
||||
private final boolean mirrorY;
|
||||
private final boolean mirrorZ;
|
||||
private final ObjectTurn rotation;
|
||||
private final PlatformBlockStates states = new PlatformBlockStates(key -> IrisPlatforms.get().registries().block(key));
|
||||
|
||||
Turn(BlockPosition anchor, ObjectTransform transform) {
|
||||
this.anchor = anchor;
|
||||
this.mirrorX = transform.mirrorX();
|
||||
this.mirrorY = transform.mirrorY();
|
||||
this.mirrorZ = transform.mirrorZ();
|
||||
this.rotation = ObjectTurn.of(transform.rotationX(), transform.rotationY(), transform.rotationZ());
|
||||
}
|
||||
|
||||
BlockPosition position(BlockPosition local) {
|
||||
IrisBlockVector offset = new IrisBlockVector(local.x() - anchor.x(), local.y() - anchor.y(), local.z() - anchor.z());
|
||||
if (mirrorX) {
|
||||
offset.setX(-offset.getX());
|
||||
}
|
||||
if (mirrorY) {
|
||||
offset.setY(-offset.getY());
|
||||
}
|
||||
if (mirrorZ) {
|
||||
offset.setZ(-offset.getZ());
|
||||
}
|
||||
IrisBlockVector turned = rotation.rotate(offset);
|
||||
return new BlockPosition(anchor.x() + (int) Math.round(turned.getX()), anchor.y() + (int) Math.round(turned.getY()),
|
||||
anchor.z() + (int) Math.round(turned.getZ()));
|
||||
}
|
||||
|
||||
com.volmit.block.BlockState state(ObjectBlock block) {
|
||||
return states.toApi(BlockStateRotation.rotate(rotation, mirrored(states.toPlatform(block.state()))));
|
||||
}
|
||||
|
||||
private PlatformBlockState mirrored(PlatformBlockState state) {
|
||||
PlatformBlockState result = mirrorX ? state.mirrorX() : state;
|
||||
return mirrorZ ? result.mirrorZ() : result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,12 +23,10 @@ import com.volmit.placement.PlacementTerrain;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.config.FeatureSettings;
|
||||
import com.volmit.geometry.BlockBox;
|
||||
import com.volmit.object.ObjectTransformer;
|
||||
import com.volmit.placement.PlacementContext;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.world.BiomeKind;
|
||||
import com.volmit.world.BiomeSample;
|
||||
import com.volmit.world.BlockView;
|
||||
import com.volmit.world.TerrainSample;
|
||||
import com.volmit.world.PackWorld;
|
||||
import com.volmit.world.TerrainSampler;
|
||||
@@ -40,10 +38,8 @@ import java.util.function.Supplier;
|
||||
|
||||
/** The read-only IrisApi inputs of one Iris object placement. */
|
||||
final class IrisPlacementInputs implements PlacementContext {
|
||||
private final ObjectTransformer objects = new IrisObjectTransformer();
|
||||
private final TerrainSampler terrain;
|
||||
private final FeatureSettings settings;
|
||||
private final BlockView blocks;
|
||||
private final Supplier<PackWorld> worldSource;
|
||||
private final PlacementTerrain placementTerrain;
|
||||
private final Object input;
|
||||
@@ -53,11 +49,10 @@ final class IrisPlacementInputs implements PlacementContext {
|
||||
* @param worldSource the world the placement generates in, asked for the first time a stage needs it
|
||||
* @param input what the placing module passed for its stages to read
|
||||
*/
|
||||
IrisPlacementInputs(TerrainSampler terrain, FeatureSettings settings, BlockView blocks, Supplier<PackWorld> worldSource,
|
||||
IrisPlacementInputs(TerrainSampler terrain, FeatureSettings settings, Supplier<PackWorld> worldSource,
|
||||
PlacementTerrain placementTerrain, Object input) {
|
||||
this.terrain = terrain;
|
||||
this.settings = settings;
|
||||
this.blocks = blocks;
|
||||
this.worldSource = worldSource;
|
||||
this.placementTerrain = placementTerrain;
|
||||
this.input = input;
|
||||
@@ -157,16 +152,6 @@ final class IrisPlacementInputs implements PlacementContext {
|
||||
return settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectTransformer objects() {
|
||||
return objects;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockView blocks() {
|
||||
return blocks;
|
||||
}
|
||||
|
||||
/** The world this placement first asked for; it keeps it if the world restarts meanwhile. */
|
||||
@Override
|
||||
public PackWorld world() {
|
||||
|
||||
@@ -70,7 +70,7 @@ final class IrisPlacements implements Placements {
|
||||
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());
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -37,7 +37,6 @@ import com.volmit.block.BlockState;
|
||||
import com.volmit.config.Snippet;
|
||||
import com.volmit.host.FeatureCatalog;
|
||||
import com.volmit.host.FeatureDescriptor;
|
||||
import com.volmit.host.ObjectRegistration;
|
||||
import com.volmit.host.OptionsMetadata;
|
||||
import com.volmit.resource.ResourceId;
|
||||
|
||||
@@ -55,7 +54,6 @@ import java.util.TreeSet;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Reads the module settings a dimension, region or biome declares: each settings feature of the pack at
|
||||
@@ -239,9 +237,8 @@ public final class ModuleSettingsDecoder {
|
||||
}
|
||||
|
||||
private static Set<String> keysAt(FeatureCatalog catalog, Level target) {
|
||||
Stream<FeatureDescriptor<?>> objects = catalog.objects().stream().map(ObjectRegistration::descriptor);
|
||||
Set<String> found = new TreeSet<>();
|
||||
Stream.concat(catalog.settings().stream(), objects)
|
||||
catalog.settings().stream()
|
||||
.filter(feature -> feature.targets().contains(target))
|
||||
.forEach(feature -> found.add(feature.key()));
|
||||
return Set.copyOf(found);
|
||||
|
||||
@@ -1,48 +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 com.volmit.block.BlockState;
|
||||
import com.volmit.geometry.BlockBox;
|
||||
import com.volmit.placement.PlacementTerrain;
|
||||
import com.volmit.world.BlockView;
|
||||
|
||||
/** 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;
|
||||
|
||||
TerrainBlockView(PlacementTerrain terrain, BlockBox bounds) {
|
||||
this.terrain = terrain;
|
||||
this.bounds = bounds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockBox bounds() {
|
||||
return bounds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState get(int worldX, int y, int worldZ) {
|
||||
if (!bounds.contains(worldX, y, worldZ)) {
|
||||
throw new IndexOutOfBoundsException("Block " + worldX + ", " + y + ", " + worldZ + " is outside the placement area " + bounds);
|
||||
}
|
||||
return terrain.get(worldX, y, worldZ);
|
||||
}
|
||||
}
|
||||
@@ -452,7 +452,6 @@ public class SchemaBuilder {
|
||||
}
|
||||
case ITEM -> putRegistryEnumRef(property, "enum-item-type", this::itemTypes);
|
||||
case ENTITY -> putRegistryEnumRef(property, "enum-entity-type", this::entityTypes);
|
||||
case BIOME -> putRegistryEnumRef(property, "enum-biome-type", this::biomeTypes);
|
||||
case STRUCTURE -> putRegistryEnumRef(property, "enum-vanilla-structure", this::vanillaStructures);
|
||||
case STRUCTURE_PREFIX -> putRegistryEnumOrPrefixRef(property, "enum-vanilla-structure-or-prefix",
|
||||
"enum-vanilla-structure", this::vanillaStructures, VANILLA_STRUCTURE_PREFIX_PATTERN);
|
||||
|
||||
@@ -1,184 +0,0 @@
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.engine.UsableBlockPlatform;
|
||||
import art.arcane.iris.engine.object.prefab.BlockStateRotation;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.spi.PlatformRegistries;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.geometry.BlockBox;
|
||||
import com.volmit.geometry.BlockPosition;
|
||||
import com.volmit.object.GeneratedObject;
|
||||
import com.volmit.object.ObjectBlock;
|
||||
import com.volmit.object.ObjectMarker;
|
||||
import com.volmit.object.ObjectTransform;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/** Objects turn and mirror about their anchor the way Iris places them; what Iris cannot do is refused. */
|
||||
public class IrisObjectTransformerTest {
|
||||
private static final BlockState LOG = BlockState.parse("minecraft:oak_log");
|
||||
private static final BlockState LEAVES = BlockState.parse("minecraft:oak_leaves");
|
||||
private static final ResourceId SPAWN = ResourceId.parse("test:marks/spawn");
|
||||
|
||||
private final IrisObjectTransformer transformer = new IrisObjectTransformer();
|
||||
private BlockStateRotation.StateRotator previousRotator;
|
||||
|
||||
/** A trunk and a leaf east of its top, with a marker beside the trunk. */
|
||||
private final GeneratedObject tree = new GeneratedObject(new BlockBox(0, 0, 0, 2, 2, 1), new BlockPosition(0, 0, 0),
|
||||
List.of(new ObjectBlock(new BlockPosition(0, 0, 0), LOG), new ObjectBlock(new BlockPosition(1, 1, 0), LEAVES)),
|
||||
List.of(new ObjectMarker(new BlockPosition(1, 0, 0), SPAWN, Map.of("kind", "bird"))));
|
||||
|
||||
@Before
|
||||
public void bindPlatform() {
|
||||
UsableBlockPlatform.bind();
|
||||
previousRotator = BlockStateRotation.bindPlatformRotator((turn, state) -> state);
|
||||
}
|
||||
|
||||
@After
|
||||
public void unbindPlatform() {
|
||||
BlockStateRotation.restorePlatformRotator(previousRotator);
|
||||
UsableBlockPlatform.unbind();
|
||||
}
|
||||
|
||||
private static ObjectTransform rotatedY(double degrees) {
|
||||
return new ObjectTransform(0, degrees, 0, 1, 1, 1, false, false, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theIdentityIsTheSameObject() {
|
||||
assertSame(tree, transformer.transform(tree, ObjectTransform.identity()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aQuarterTurnAboutYMovesBlocksAndMarkersAboutTheAnchor() {
|
||||
GeneratedObject turned = transformer.transform(tree, rotatedY(90));
|
||||
|
||||
assertEquals(List.of(new BlockPosition(0, 0, 0), new BlockPosition(0, 1, -1)),
|
||||
turned.blocks().stream().map(ObjectBlock::position).sorted().toList());
|
||||
assertEquals(new BlockPosition(0, 0, -1), turned.markers().getFirst().position());
|
||||
assertEquals(SPAWN, turned.markers().getFirst().type());
|
||||
assertEquals(Map.of("kind", "bird"), turned.markers().getFirst().attributes());
|
||||
assertEquals(tree.anchor(), turned.anchor());
|
||||
assertEquals(new BlockBox(0, 0, -1, 1, 2, 1), turned.bounds());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theSourceObjectIsLeftAsItWas() {
|
||||
transformer.transform(tree, rotatedY(90));
|
||||
|
||||
assertEquals(new BlockPosition(1, 1, 0), tree.blocks().getLast().position());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aYMirrorFlipsHeightsAboutTheAnchorWithoutChangingBlocks() {
|
||||
GeneratedObject hung = transformer.transform(tree, new ObjectTransform(0, 0, 0, 1, 1, 1, false, true, false));
|
||||
|
||||
assertEquals(List.of(new BlockPosition(0, 0, 0), new BlockPosition(1, -1, 0)),
|
||||
hung.blocks().stream().map(ObjectBlock::position).sorted().toList());
|
||||
assertEquals(List.of(LEAVES, LOG), hung.blocks().stream().map(ObjectBlock::state).sorted(java.util.Comparator.comparing(BlockState::key)).toList());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void blocksTurnedOntoOnePositionKeepTheLastOne() {
|
||||
GeneratedObject squeezed = transformer.transform(new GeneratedObject(new BlockBox(0, 0, 0, 2, 1, 1), new BlockPosition(0, 0, 0),
|
||||
List.of(new ObjectBlock(new BlockPosition(0, 0, 0), LOG), new ObjectBlock(new BlockPosition(1, 0, 0), LEAVES)), List.of()),
|
||||
new ObjectTransform(0, 0, 0, 1, 1, 1, false, true, false));
|
||||
|
||||
assertEquals(2, squeezed.blocks().size());
|
||||
}
|
||||
|
||||
private static ObjectTransform mirrored(boolean x, boolean z) {
|
||||
return new ObjectTransform(0, 0, 0, 1, 1, 1, x, false, z);
|
||||
}
|
||||
|
||||
/** What the platform answers for a state and its mirrors: the platform, not Iris, decides how a block looks mirrored. */
|
||||
private static void mirrorsBy(String key, String alongX, String alongZ) {
|
||||
PlatformRegistries registries = IrisPlatforms.get().registries();
|
||||
PlatformBlockState state = registries.block(key);
|
||||
PlatformBlockState mirroredAlongX = registries.block(alongX);
|
||||
PlatformBlockState mirroredAlongZ = registries.block(alongZ);
|
||||
when(state.mirrorX()).thenReturn(mirroredAlongX);
|
||||
when(state.mirrorZ()).thenReturn(mirroredAlongZ);
|
||||
}
|
||||
|
||||
/** A stair east of the anchor and a marker beside it, in a world whose stairs mirror as the test platform says. */
|
||||
private GeneratedObject stairsEastOfTheAnchor() {
|
||||
mirrorsBy("minecraft:oak_stairs[facing=east]", "minecraft:oak_stairs[facing=west]", "minecraft:oak_stairs[facing=east]");
|
||||
mirrorsBy("minecraft:oak_stairs[facing=west]", "minecraft:oak_stairs[facing=east]", "minecraft:oak_stairs[facing=west]");
|
||||
mirrorsBy("minecraft:oak_stairs[facing=north]", "minecraft:oak_stairs[facing=north]", "minecraft:oak_stairs[facing=south]");
|
||||
return new GeneratedObject(new BlockBox(0, 0, 0, 2, 1, 2), new BlockPosition(0, 0, 0),
|
||||
List.of(new ObjectBlock(new BlockPosition(1, 0, 0), BlockState.parse("minecraft:oak_stairs[facing=east]")),
|
||||
new ObjectBlock(new BlockPosition(0, 0, 1), BlockState.parse("minecraft:oak_stairs[facing=north]"))),
|
||||
List.of(new ObjectMarker(new BlockPosition(1, 0, 1), SPAWN, Map.of("kind", "bird"))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void anXMirrorFlipsXAboutTheAnchorAndMirrorsStatesThroughThePlatform() {
|
||||
GeneratedObject mirrored = transformer.transform(stairsEastOfTheAnchor(), mirrored(true, false));
|
||||
|
||||
assertEquals(List.of(new ObjectBlock(new BlockPosition(-1, 0, 0), BlockState.parse("minecraft:oak_stairs[facing=west]")),
|
||||
new ObjectBlock(new BlockPosition(0, 0, 1), BlockState.parse("minecraft:oak_stairs[facing=north]"))),
|
||||
mirrored.blocks());
|
||||
assertEquals(new BlockPosition(-1, 0, 1), mirrored.markers().getFirst().position());
|
||||
assertEquals(new BlockBox(-1, 0, 0, 1, 1, 2), mirrored.bounds());
|
||||
assertEquals(new BlockPosition(0, 0, 0), mirrored.anchor());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aZMirrorFlipsZAboutTheAnchorAndMirrorsStatesThroughThePlatform() {
|
||||
GeneratedObject mirrored = transformer.transform(stairsEastOfTheAnchor(), mirrored(false, true));
|
||||
|
||||
assertEquals(List.of(new ObjectBlock(new BlockPosition(0, 0, -1), BlockState.parse("minecraft:oak_stairs[facing=south]")),
|
||||
new ObjectBlock(new BlockPosition(1, 0, 0), BlockState.parse("minecraft:oak_stairs[facing=east]"))),
|
||||
mirrored.blocks().stream().sorted(java.util.Comparator.comparing(ObjectBlock::position)).toList());
|
||||
assertEquals(new BlockPosition(1, 0, -1), mirrored.markers().getFirst().position());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mirroringBothAxesMirrorsStatesAlongBoth() {
|
||||
GeneratedObject mirrored = transformer.transform(stairsEastOfTheAnchor(), mirrored(true, true));
|
||||
|
||||
assertEquals(List.of(new BlockPosition(-1, 0, 0), new BlockPosition(0, 0, -1)),
|
||||
mirrored.blocks().stream().map(ObjectBlock::position).sorted().toList());
|
||||
assertEquals(List.of("minecraft:oak_stairs[facing=south]", "minecraft:oak_stairs[facing=west]"),
|
||||
mirrored.blocks().stream().map(block -> block.state().key()).sorted().toList());
|
||||
assertEquals(new BlockPosition(-1, 0, -1), mirrored.markers().getFirst().position());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mirrorsComeBeforeRotation() {
|
||||
GeneratedObject object = new GeneratedObject(new BlockBox(0, 0, 0, 2, 1, 1), new BlockPosition(0, 0, 0),
|
||||
List.of(new ObjectBlock(new BlockPosition(1, 0, 0), LOG)), List.of());
|
||||
|
||||
GeneratedObject both = transformer.transform(object, new ObjectTransform(0, 90, 0, 1, 1, 1, true, false, false));
|
||||
|
||||
// Mirrored first (1,0,0) -> (-1,0,0), then a quarter turn about Y sends +X to -Z, so -X goes to +Z.
|
||||
assertEquals(new BlockPosition(0, 0, 1), both.blocks().getFirst().position());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aMirrorTheBlockIgnoresLeavesItsStateAsItWas() {
|
||||
GeneratedObject mirrored = transformer.transform(tree, mirrored(true, false));
|
||||
|
||||
assertEquals(List.of(LEAVES, LOG), mirrored.blocks().stream().map(ObjectBlock::state).toList());
|
||||
assertEquals(List.of(new BlockPosition(-1, 1, 0), new BlockPosition(0, 0, 0)),
|
||||
mirrored.blocks().stream().map(ObjectBlock::position).toList());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scalingIsRefused() {
|
||||
assertThrows(UnsupportedOperationException.class,
|
||||
() -> transformer.transform(tree, new ObjectTransform(0, 0, 0, 2, 1, 1, false, false, false)));
|
||||
}
|
||||
}
|
||||
-40
@@ -40,15 +40,11 @@ import com.volmit.IrisModule;
|
||||
import com.volmit.ModuleInfo;
|
||||
import com.volmit.ModuleSetup;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.geometry.BlockBox;
|
||||
import com.volmit.geometry.BlockPosition;
|
||||
import com.volmit.mantle.Mantle;
|
||||
import com.volmit.mantle.MantleCodec;
|
||||
import com.volmit.mantle.MantleKey;
|
||||
import com.volmit.mantle.MantleLifetime;
|
||||
import com.volmit.object.GeneratedObject;
|
||||
import com.volmit.object.ObjectBlock;
|
||||
import com.volmit.object.ObjectTransform;
|
||||
import com.volmit.host.LoadedPack;
|
||||
import com.volmit.stage.PlacementStage;
|
||||
import com.volmit.stage.Stage;
|
||||
@@ -525,42 +521,6 @@ public class ObjectPlacementRegressionTest {
|
||||
assertNull(storage.value(MARKS, TEXT, 1, ANCHOR_Y, 0));
|
||||
}
|
||||
|
||||
/** Lays the pack's oak on its side, a quarter turn about X, through the placement's object transformer. */
|
||||
private static final class TurnModule implements IrisModule {
|
||||
private static final PlacementStage<Void> TURN = Stage.placement("test:turn/oak");
|
||||
private final List<GeneratedObject> turned;
|
||||
|
||||
private TurnModule(List<GeneratedObject> turned) {
|
||||
this.turned = turned;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModuleInfo info() {
|
||||
return ModuleInfo.of("test:turn", "Turn", "1");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup(ModuleSetup setup) {
|
||||
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))));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aPlacementStageTurnsAnObjectThroughTheObjectTransformer() throws IOException {
|
||||
List<GeneratedObject> turned = new ArrayList<>();
|
||||
usePack(List.of(new TurnModule(turned)));
|
||||
PackResourceFixture.serve(data);
|
||||
|
||||
ObjectPlacementResult result = place(placement(), ANCHOR_Y, new RecordingPlacer(null), null);
|
||||
|
||||
assertTrue(result.isPlaced());
|
||||
assertEquals(List.of(new BlockPosition(0, 0, 0), new BlockPosition(0, 0, 1)),
|
||||
turned.getFirst().blocks().stream().map(ObjectBlock::position).toList());
|
||||
assertEquals("the oak's leaves moved with the turn", new BlockBox(0, 0, 0, 1, 1, 2), turned.getFirst().bounds());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fromBottomKeepsItsAnchorWithoutSamplingTerrain() {
|
||||
RecordingPlacer placer = new RecordingPlacer(null);
|
||||
|
||||
@@ -87,7 +87,7 @@ public class EntityResolutionPinTest {
|
||||
EntitySpec spec = new EntityResolution(resources, new LootItems(registry, false, log), sky, new EffectTimers(), log)
|
||||
.resolve(entity, new RNG(STREAM_SEED)).orElseThrow();
|
||||
|
||||
assertEquals(383685705, spec.toString().hashCode());
|
||||
assertEquals(-1825293612, spec.toString().hashCode());
|
||||
}
|
||||
|
||||
private static ContentKey platformItem(String name) {
|
||||
|
||||
Reference in new issue
Block a user