Mirror objects along X and Z in the object transformer, mirroring block states through the platform's own mirror

This commit is contained in:
piexel committed 2026-10-08 15:16:25 +02:00
1 parent 563c2cd276
commit 844e3205ac
9 files changed
+221 -12

No files matched your search

@@ -190,6 +190,16 @@ public final class StubPlatform implements IrisPlatform {
|| blockKey.endsWith("anvil");
}
@Override
public PlatformBlockState mirrorX() {
return mirrorState(this, "east", "west", 16);
}
@Override
public PlatformBlockState mirrorZ() {
return mirrorState(this, "north", "south", 8);
}
/** The stub has no shapes: every solid block is sturdy on every face. */
@Override
public boolean canAttach(PlatformBlockState support, PlatformFace face) {
@@ -283,6 +293,33 @@ public final class StubPlatform implements IrisPlatform {
return StubBlockState.of(parsed.serialize());
}
/**
* Swaps what the two sides name: {@code facing}, and the connected side properties of fences and the like,
* and mirrors the 16 step {@code rotation} of signs and banners. {@code rotationMirror} is the segment that
* maps to itself, 16 for a mirror along X and 8 for one along Z, as Minecraft mirrors them. The stub knows
* no other shape-dependent property.
*/
private static PlatformBlockState mirrorState(StubBlockState state, String side, String opposite, int rotationMirror) {
ParsedState parsed = ParsedState.parse(state.key());
Map<String, String> properties = parsed.properties();
String facing = properties.get("facing");
if (side.equals(facing) || opposite.equals(facing)) {
properties.put("facing", side.equals(facing) ? opposite : side);
}
String sideValue = properties.get(side);
String oppositeValue = properties.get(opposite);
if (sideValue != null && oppositeValue != null) {
properties.put(side, oppositeValue);
properties.put(opposite, sideValue);
}
String rotation = properties.get("rotation");
if (rotation != null) {
properties.put("rotation", Integer.toString(Math.floorMod(rotationMirror - Integer.parseInt(rotation), 16)));
}
String mirrored = parsed.serialize();
return mirrored.equals(state.key()) ? state : StubBlockState.of(mirrored);
}
private static PlatformBlockState mergeStates(PlatformBlockState base, PlatformBlockState update) {
if (base == null) {
return update;
@@ -10,6 +10,7 @@ import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
public final class StubPlatformStateTest {
@@ -84,6 +85,21 @@ public final class StubPlatformStateTest {
assertFalse(torch.canAttach(state("minecraft:air"), PlatformFace.NORTH));
}
@Test
public void mirrorsFacingSidesAndRotationLikeMinecraftDoes() {
assertEquals("minecraft:oak_stairs[facing=west,half=bottom]", state("minecraft:oak_stairs[facing=east,half=bottom]").mirrorX().key());
assertEquals("minecraft:oak_stairs[facing=north,half=bottom]", state("minecraft:oak_stairs[facing=north,half=bottom]").mirrorX().key());
assertEquals("minecraft:oak_stairs[facing=south,half=bottom]", state("minecraft:oak_stairs[facing=north,half=bottom]").mirrorZ().key());
assertEquals("minecraft:oak_fence[north=true,east=false,south=false,west=false]",
state("minecraft:oak_fence[north=true,east=false,south=false,west=false]").mirrorX().key());
assertEquals("minecraft:oak_fence[north=false,east=false,south=true,west=false]",
state("minecraft:oak_fence[north=true,east=false,south=false,west=false]").mirrorZ().key());
assertEquals("minecraft:oak_sign[rotation=12]", state("minecraft:oak_sign[rotation=4]").mirrorX().key());
assertEquals("minecraft:oak_sign[rotation=4]", state("minecraft:oak_sign[rotation=4]").mirrorZ().key());
PlatformBlockState stone = state("minecraft:stone");
assertSame("a block with nothing to mirror is itself", stone, stone.mirrorX());
}
private PlatformBlockState state(String key) {
return IrisPlatforms.get().registries().block(key);
}