Answer the GRAVITY, LOG and LEAVES traits, block tags and attachment to a face from the platform layer, with Bukkit, modded and stub implementations

This commit is contained in:
piexel committed 2026-10-08 15:06:27 +02:00
1 parent 818dbef261
commit 563c2cd276
15 files changed
+344 -35

No files matched your search

@@ -3,6 +3,7 @@ package art.arcane.iris.core.modules;
import art.arcane.iris.spi.IrisPlatform;
import art.arcane.iris.spi.IrisPlatforms;
import art.arcane.iris.spi.PlatformBlockState;
import art.arcane.iris.spi.PlatformFace;
import art.arcane.iris.spi.PlatformRegistries;
import com.volmit.block.BlockFace;
import com.volmit.block.BlockState;
@@ -19,21 +20,38 @@ import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
/** IrisApi's blocks are the bound platform's, through their keys; what the platform cannot answer is said so. */
/** IrisApi's blocks are the bound platform's, through their keys, and so are its traits, tags and face support. */
public class IrisBlockRegistryTest {
private final IrisBlockRegistry blocks = new IrisBlockRegistry();
private PlatformRegistries registries;
private PlatformBlockState stone;
private PlatformBlockState sand;
@Before
public void bindPlatform() {
PlatformBlockState stone = mock(PlatformBlockState.class);
stone = mock(PlatformBlockState.class);
when(stone.key()).thenReturn("stone");
when(stone.isSolid()).thenReturn(true);
when(stone.isOre()).thenReturn(false);
PlatformRegistries registries = mock(PlatformRegistries.class);
sand = mock(PlatformBlockState.class);
when(sand.key()).thenReturn("minecraft:sand");
when(sand.hasGravity()).thenReturn(true);
PlatformBlockState log = mock(PlatformBlockState.class);
when(log.key()).thenReturn("minecraft:oak_log");
when(log.isLog()).thenReturn(true);
PlatformBlockState leaves = mock(PlatformBlockState.class);
when(leaves.key()).thenReturn("minecraft:oak_leaves");
when(leaves.isLeaves()).thenReturn(true);
registries = mock(PlatformRegistries.class);
when(registries.blockOrNull(eq("minecraft:stone"), anyBoolean())).thenReturn(stone);
when(registries.blockOrNull(eq("minecraft:sand"), anyBoolean())).thenReturn(sand);
when(registries.blockOrNull(eq("minecraft:oak_log"), anyBoolean())).thenReturn(log);
when(registries.blockOrNull(eq("minecraft:oak_leaves"), anyBoolean())).thenReturn(leaves);
when(registries.blockOrNull(eq("minecraft:nothing"), anyBoolean())).thenReturn(null);
when(registries.isInTag(log, "minecraft:logs")).thenReturn(true);
IrisPlatform platform = mock(IrisPlatform.class);
when(platform.registries()).thenReturn(registries);
IrisPlatforms.unbind();
@@ -53,6 +71,8 @@ public class IrisBlockRegistryTest {
@Test
public void aBlockThePlatformDoesNotKnowIsRejected() {
assertThrows(IllegalArgumentException.class, () -> blocks.resolve("minecraft:nothing"));
assertThrows(IllegalArgumentException.class, () -> blocks.hasTrait(BlockState.parse("minecraft:nothing"), BlockTrait.LOG));
assertThrows(IllegalArgumentException.class, () -> blocks.inTag(BlockState.parse("minecraft:nothing"), ResourceId.parse("minecraft:logs")));
}
@Test
@@ -64,11 +84,37 @@ public class IrisBlockRegistryTest {
}
@Test
public void whatThePlatformLayerDoesNotOfferFailsInsteadOfGuessing() {
BlockState stone = BlockState.parse("minecraft:stone");
public void gravityLogAndLeavesComeFromThePlatformToo() {
BlockState sand = BlockState.parse("minecraft:sand");
BlockState log = BlockState.parse("minecraft:oak_log");
BlockState leaves = BlockState.parse("minecraft:oak_leaves");
assertThrows(UnsupportedOperationException.class, () -> blocks.hasTrait(stone, BlockTrait.GRAVITY));
assertThrows(UnsupportedOperationException.class, () -> blocks.inTag(stone, ResourceId.parse("minecraft:logs")));
assertThrows(UnsupportedOperationException.class, () -> blocks.canAttach(stone, stone, BlockFace.UP));
assertTrue(blocks.hasTrait(sand, BlockTrait.GRAVITY));
assertFalse(blocks.hasTrait(sand, BlockTrait.LOG));
assertTrue(blocks.hasTrait(log, BlockTrait.LOG));
assertFalse(blocks.hasTrait(log, BlockTrait.GRAVITY));
assertTrue(blocks.hasTrait(leaves, BlockTrait.LEAVES));
assertFalse(blocks.hasTrait(leaves, BlockTrait.LOG));
}
@Test
public void tagsAreTheRegistrysMembership() {
assertTrue(blocks.inTag(BlockState.parse("minecraft:oak_log"), ResourceId.parse("minecraft:logs")));
assertFalse(blocks.inTag(BlockState.parse("minecraft:stone"), ResourceId.parse("minecraft:logs")));
assertFalse("a tag nobody knows has no members", blocks.inTag(BlockState.parse("minecraft:oak_log"), ResourceId.parse("pack:nothing")));
}
@Test
public void everyFaceAsksThePlatformAboutThatFace() {
BlockState torch = BlockState.parse("minecraft:stone");
BlockState support = BlockState.parse("minecraft:sand");
for (BlockFace face : BlockFace.values()) {
when(stone.canAttach(sand, PlatformFace.valueOf(face.name()))).thenReturn(face == BlockFace.NORTH);
}
for (BlockFace face : BlockFace.values()) {
assertEquals(face.name(), face == BlockFace.NORTH, blocks.canAttach(torch, support, face));
verify(stone).canAttach(sand, PlatformFace.valueOf(face.name()));
}
}
}
@@ -228,6 +228,11 @@ public class ContentKeyValidatorTest {
return null;
}
@Override
public boolean isInTag(PlatformBlockState block, String tag) {
return false;
}
@Override
public PlatformBlockState deepSlateOre(PlatformBlockState block, PlatformBlockState ore) {
return null;
@@ -476,6 +476,11 @@ public class SchemaBuilderParityTest {
return null;
}
@Override
public boolean isInTag(PlatformBlockState block, String tag) {
return false;
}
@Override
public PlatformBlockState deepSlateOre(PlatformBlockState block, PlatformBlockState ore) {
return null;
@@ -4,6 +4,7 @@ import art.arcane.iris.engine.object.prefab.IrisObject;
import art.arcane.iris.spi.IrisPlatform;
import art.arcane.iris.spi.IrisPlatforms;
import art.arcane.iris.spi.PlatformBlockState;
import art.arcane.iris.spi.PlatformFace;
import art.arcane.iris.spi.PlatformRegistries;
import art.arcane.iris.util.common.math.IrisBlockVector;
import org.junit.AfterClass;
@@ -198,7 +199,22 @@ public class TreePlausibilizerTest {
}
@Override
public boolean isTreeBlock() {
public boolean isLog() {
return false;
}
@Override
public boolean isLeaves() {
return false;
}
@Override
public boolean hasGravity() {
return false;
}
@Override
public boolean canAttach(PlatformBlockState support, PlatformFace face) {
return false;
}