mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-30 01:34:04 +00:00
Mirror objects along X and Z in the object transformer, mirroring block states through the platform's own mirror
This commit is contained in:
1 parent
563c2cd276
commit
844e3205ac
9 files changed
+221
-12
No files matched your search
@@ -2,7 +2,9 @@ package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.engine.UsableBlockPlatform;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObjectRotation;
|
||||
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.mantle.BlockBox;
|
||||
import com.volmit.object.GeneratedObject;
|
||||
@@ -21,8 +23,9 @@ 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 about their anchor the way Iris places them; what Iris cannot do is refused. */
|
||||
/** 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");
|
||||
@@ -95,12 +98,86 @@ public class IrisObjectTransformerTest {
|
||||
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 mirroringAlongXOrZAndScalingAreRefused() {
|
||||
assertThrows(UnsupportedOperationException.class,
|
||||
() -> transformer.transform(tree, new ObjectTransform(0, 0, 0, 1, 1, 1, true, false, false)));
|
||||
assertThrows(UnsupportedOperationException.class,
|
||||
() -> transformer.transform(tree, new ObjectTransform(0, 0, 0, 1, 1, 1, false, false, true)));
|
||||
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)));
|
||||
}
|
||||
|
||||
@@ -213,6 +213,16 @@ public class TreePlausibilizerTest {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformBlockState mirrorX() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformBlockState mirrorZ() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAttach(PlatformBlockState support, PlatformFace face) {
|
||||
return false;
|
||||
|
||||
@@ -59,6 +59,8 @@ public final class UsableBlockPlatform {
|
||||
when(block.materialKey()).thenReturn(key.split("\\[", 2)[0]);
|
||||
when(block.isSolid()).thenReturn(!key.contains("air"));
|
||||
when(block.isOccluding()).thenReturn(!key.contains("air"));
|
||||
when(block.mirrorX()).thenReturn(block);
|
||||
when(block.mirrorZ()).thenReturn(block);
|
||||
return block;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user