mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 00:04:42 +00:00
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:
1 parent
818dbef261
commit
563c2cd276
15 files changed
+344
-35
No files matched your search
+32
@@ -22,15 +22,19 @@ import art.arcane.iris.core.IrisSettings;
|
||||
import art.arcane.iris.modded.api.ModdedCustomContentRegistry;
|
||||
import art.arcane.iris.modded.api.ModdedBlockData;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.spi.PlatformFace;
|
||||
import art.arcane.volmlib.util.data.UnresolvedKeyLog;
|
||||
import com.mojang.brigadier.StringReader;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import net.minecraft.commands.arguments.blocks.BlockStateParser;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.tags.BlockTags;
|
||||
import net.minecraft.world.level.EmptyBlockGetter;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.FallingBlock;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.LeavesBlock;
|
||||
import net.minecraft.world.level.block.PointedDripstoneBlock;
|
||||
@@ -457,6 +461,34 @@ public final class ModdedBlockResolution {
|
||||
return state.getBlock().defaultBlockState().isRedstoneConductor(EmptyBlockGetter.INSTANCE, BlockPos.ZERO);
|
||||
}
|
||||
|
||||
public static boolean isLog(BlockState state) {
|
||||
return state.is(BlockTags.LOGS);
|
||||
}
|
||||
|
||||
public static boolean isLeaves(BlockState state) {
|
||||
return state.is(BlockTags.LEAVES);
|
||||
}
|
||||
|
||||
public static boolean hasGravity(BlockState state) {
|
||||
return state.getBlock() instanceof FallingBlock;
|
||||
}
|
||||
|
||||
/** Whether the face of the support is sturdy enough to hold a block against it, without a world to ask. */
|
||||
public static boolean canAttach(BlockState support, PlatformFace face) {
|
||||
return support.isFaceSturdy(EmptyBlockGetter.INSTANCE, BlockPos.ZERO, directionOf(face));
|
||||
}
|
||||
|
||||
private static Direction directionOf(PlatformFace face) {
|
||||
return switch (face) {
|
||||
case UP -> Direction.UP;
|
||||
case DOWN -> Direction.DOWN;
|
||||
case NORTH -> Direction.NORTH;
|
||||
case SOUTH -> Direction.SOUTH;
|
||||
case EAST -> Direction.EAST;
|
||||
case WEST -> Direction.WEST;
|
||||
};
|
||||
}
|
||||
|
||||
public static boolean isFluid(BlockState state) {
|
||||
Block block = state.getBlock();
|
||||
return block == Blocks.WATER || block == Blocks.LAVA;
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
package art.arcane.iris.modded;
|
||||
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.spi.PlatformFace;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.tags.BlockTags;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.properties.Property;
|
||||
|
||||
@@ -45,7 +45,9 @@ public final class ModdedBlockState implements PlatformBlockState {
|
||||
private volatile Boolean fluid;
|
||||
private volatile Boolean water;
|
||||
private volatile Boolean foliage;
|
||||
private volatile Boolean treeBlock;
|
||||
private volatile Boolean log;
|
||||
private volatile Boolean leaves;
|
||||
private volatile Boolean gravity;
|
||||
private volatile Boolean decorant;
|
||||
|
||||
private ModdedBlockState(BlockState state, Map<Property<?>, Comparable<?>> parsedProperties, String key, String deferredPlacementKey) {
|
||||
@@ -251,15 +253,40 @@ public final class ModdedBlockState implements PlatformBlockState {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTreeBlock() {
|
||||
Boolean cached = treeBlock;
|
||||
public boolean isLog() {
|
||||
Boolean cached = log;
|
||||
if (cached == null) {
|
||||
cached = state.is(BlockTags.LOGS) || state.is(BlockTags.LEAVES);
|
||||
treeBlock = cached;
|
||||
cached = ModdedBlockResolution.isLog(state);
|
||||
log = cached;
|
||||
}
|
||||
return cached;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLeaves() {
|
||||
Boolean cached = leaves;
|
||||
if (cached == null) {
|
||||
cached = ModdedBlockResolution.isLeaves(state);
|
||||
leaves = cached;
|
||||
}
|
||||
return cached;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasGravity() {
|
||||
Boolean cached = gravity;
|
||||
if (cached == null) {
|
||||
cached = ModdedBlockResolution.hasGravity(state);
|
||||
gravity = cached;
|
||||
}
|
||||
return cached;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAttach(PlatformBlockState support, PlatformFace face) {
|
||||
return ModdedBlockResolution.canAttach((BlockState) support.nativeHandle(), face);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFoliagePlantable() {
|
||||
return ModdedBlockResolution.isFoliagePlantable(state);
|
||||
|
||||
@@ -34,6 +34,7 @@ import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.enchantment.Enchantment;
|
||||
@@ -74,6 +75,15 @@ public final class ModdedRegistries implements PlatformRegistries {
|
||||
return ModdedBlockResolution.getOrNull(key, warn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInTag(PlatformBlockState block, String tag) {
|
||||
Identifier identifier = Identifier.tryParse(tag);
|
||||
if (identifier == null) {
|
||||
return false;
|
||||
}
|
||||
return ((BlockState) block.nativeHandle()).is(TagKey.create(Registries.BLOCK, identifier));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformBlockState air() {
|
||||
return ModdedBlockResolution.getAir();
|
||||
|
||||
@@ -20,6 +20,7 @@ package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.spi.PlatformFace;
|
||||
import com.volmit.block.BlockFace;
|
||||
import com.volmit.block.BlockRegistry;
|
||||
import com.volmit.block.BlockState;
|
||||
@@ -28,10 +29,8 @@ import com.volmit.resource.ResourceId;
|
||||
|
||||
/**
|
||||
* IrisApi's view of the bound platform's blocks. States convert through their keys, as {@link PlatformBlockStates}
|
||||
* does; the platform decides which blocks exist, so a key it does not know fails. Traits answer from what the
|
||||
* platform's block states can tell. Three traits ({@code GRAVITY}, {@code LOG}, {@code LEAVES}), tags and
|
||||
* attachment to a face are not offered by the platform layer yet, and asking for them throws
|
||||
* {@link UnsupportedOperationException} rather than guessing.
|
||||
* does; the platform decides which blocks exist, so a key it does not know fails. Traits, tags and attachment to
|
||||
* a face are the platform's own answers: its block tags, its falling blocks and its face support.
|
||||
*/
|
||||
final class IrisBlockRegistry implements BlockRegistry {
|
||||
@Override
|
||||
@@ -55,18 +54,20 @@ final class IrisBlockRegistry implements BlockRegistry {
|
||||
case BLOCK_ENTITY -> platform.hasTileEntity();
|
||||
case CUSTOM -> platform.isCustom();
|
||||
case NEEDS_UPDATE -> platform.isUpdatable();
|
||||
case GRAVITY, LOG, LEAVES -> throw unsupported("The " + trait + " trait");
|
||||
case GRAVITY -> platform.hasGravity();
|
||||
case LOG -> platform.isLog();
|
||||
case LEAVES -> platform.isLeaves();
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean inTag(BlockState state, ResourceId tag) {
|
||||
throw unsupported("Block tags");
|
||||
return IrisPlatforms.get().registries().isInTag(platformState(state.key()), tag.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAttach(BlockState state, BlockState support, BlockFace face) {
|
||||
throw unsupported("Attachment to a face");
|
||||
return platformState(state.key()).canAttach(platformState(support.key()), PlatformFace.valueOf(face.name()));
|
||||
}
|
||||
|
||||
private static PlatformBlockState platformState(String key) {
|
||||
@@ -76,8 +77,4 @@ final class IrisBlockRegistry implements BlockRegistry {
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
private static UnsupportedOperationException unsupported(String what) {
|
||||
return new UnsupportedOperationException(what + " cannot be answered yet: Iris's platform layer does not offer it");
|
||||
}
|
||||
}
|
||||
@@ -20,9 +20,12 @@ package art.arcane.iris.platform.bukkit;
|
||||
|
||||
import art.arcane.iris.core.nms.INMS;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.spi.PlatformFace;
|
||||
import art.arcane.iris.util.common.data.IrisCustomData;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Tag;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockSupport;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -52,7 +55,9 @@ public final class BukkitBlockState implements PlatformBlockState {
|
||||
private volatile Boolean lit;
|
||||
private volatile Boolean updatable;
|
||||
private volatile Boolean foliage;
|
||||
private volatile Boolean treeBlock;
|
||||
private volatile Boolean log;
|
||||
private volatile Boolean leaves;
|
||||
private volatile Boolean gravity;
|
||||
private volatile Boolean foliagePlantable;
|
||||
private volatile Boolean decorant;
|
||||
private volatile Boolean storage;
|
||||
@@ -263,15 +268,51 @@ public final class BukkitBlockState implements PlatformBlockState {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTreeBlock() {
|
||||
Boolean cached = treeBlock;
|
||||
public boolean isLog() {
|
||||
Boolean cached = log;
|
||||
if (cached == null) {
|
||||
cached = Tag.LOGS.isTagged(data.getMaterial()) || Tag.LEAVES.isTagged(data.getMaterial());
|
||||
treeBlock = cached;
|
||||
cached = Tag.LOGS.isTagged(data.getMaterial());
|
||||
log = cached;
|
||||
}
|
||||
return cached;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLeaves() {
|
||||
Boolean cached = leaves;
|
||||
if (cached == null) {
|
||||
cached = Tag.LEAVES.isTagged(data.getMaterial());
|
||||
leaves = cached;
|
||||
}
|
||||
return cached;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasGravity() {
|
||||
Boolean cached = gravity;
|
||||
if (cached == null) {
|
||||
cached = data.getMaterial().hasGravity();
|
||||
gravity = cached;
|
||||
}
|
||||
return cached;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAttach(PlatformBlockState support, PlatformFace face) {
|
||||
return ((BlockData) support.nativeHandle()).isFaceSturdy(blockFaceOf(face), BlockSupport.FULL);
|
||||
}
|
||||
|
||||
private static BlockFace blockFaceOf(PlatformFace face) {
|
||||
return switch (face) {
|
||||
case UP -> BlockFace.UP;
|
||||
case DOWN -> BlockFace.DOWN;
|
||||
case NORTH -> BlockFace.NORTH;
|
||||
case SOUTH -> BlockFace.SOUTH;
|
||||
case EAST -> BlockFace.EAST;
|
||||
case WEST -> BlockFace.WEST;
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFoliagePlantable() {
|
||||
Boolean cached = foliagePlantable;
|
||||
|
||||
@@ -35,9 +35,11 @@ import art.arcane.iris.spi.PlatformRegistries;
|
||||
import art.arcane.iris.util.common.reflect.KeyedType;
|
||||
import art.arcane.volmlib.util.json.JSONArray;
|
||||
import art.arcane.volmlib.util.json.JSONObject;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.Tag;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
@@ -76,6 +78,16 @@ public final class BukkitRegistries implements PlatformRegistries {
|
||||
return data == null ? null : BukkitBlockState.of(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInTag(PlatformBlockState block, String tag) {
|
||||
NamespacedKey tagKey = NamespacedKey.fromString(tag);
|
||||
if (tagKey == null) {
|
||||
return false;
|
||||
}
|
||||
Tag<Material> blockTag = Bukkit.getTag(Tag.REGISTRY_BLOCKS, tagKey, Material.class);
|
||||
return blockTag != null && blockTag.isTagged(((BlockData) block.nativeHandle()).getMaterial());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformBlockState air() {
|
||||
return BukkitBlockState.of(BukkitBlockResolution.getAir());
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ import art.arcane.iris.spi.PlatformBiomeWriter;
|
||||
import art.arcane.iris.spi.PlatformBlockProperty;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.spi.PlatformEntityType;
|
||||
import art.arcane.iris.spi.PlatformFace;
|
||||
import art.arcane.iris.spi.PlatformItem;
|
||||
import art.arcane.iris.spi.PlatformRegistries;
|
||||
import art.arcane.iris.spi.PlatformScheduler;
|
||||
@@ -166,13 +167,33 @@ public final class StubPlatform implements IrisPlatform {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTreeBlock() {
|
||||
public boolean isLog() {
|
||||
String blockKey = blockKey();
|
||||
return blockKey.endsWith("_log")
|
||||
|| blockKey.endsWith("_wood")
|
||||
|| blockKey.endsWith("_stem")
|
||||
|| blockKey.endsWith("_hyphae")
|
||||
|| blockKey.endsWith("_leaves");
|
||||
|| blockKey.endsWith("_hyphae");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLeaves() {
|
||||
return blockKey().endsWith("_leaves");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasGravity() {
|
||||
String blockKey = blockKey();
|
||||
return blockKey.endsWith(":sand")
|
||||
|| blockKey.endsWith(":red_sand")
|
||||
|| blockKey.endsWith(":gravel")
|
||||
|| blockKey.endsWith("_concrete_powder")
|
||||
|| blockKey.endsWith("anvil");
|
||||
}
|
||||
|
||||
/** The stub has no shapes: every solid block is sturdy on every face. */
|
||||
@Override
|
||||
public boolean canAttach(PlatformBlockState support, PlatformFace face) {
|
||||
return support.isSolid();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -567,6 +588,17 @@ public final class StubPlatform implements IrisPlatform {
|
||||
return StubBlockState.of(key);
|
||||
}
|
||||
|
||||
/** The stub knows the tags of the block traits it has: logs, leaves and the falling blocks. */
|
||||
@Override
|
||||
public boolean isInTag(PlatformBlockState block, String tag) {
|
||||
return switch (tag) {
|
||||
case "minecraft:logs" -> block.isLog();
|
||||
case "minecraft:leaves" -> block.isLeaves();
|
||||
case "minecraft:sand" -> block.key().endsWith(":sand") || block.key().endsWith(":red_sand");
|
||||
default -> false;
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformBlockState air() {
|
||||
return StubBlockState.of("minecraft:air");
|
||||
|
||||
@@ -3,6 +3,8 @@ package art.arcane.iris.probe;
|
||||
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.PlatformFace;
|
||||
import art.arcane.iris.spi.PlatformRegistries;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -59,6 +61,29 @@ public final class StubPlatformStateTest {
|
||||
assertTrue(stone.isSolid());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void answersLogLeavesGravityTagsAndFaceSupport() {
|
||||
PlatformBlockState log = state("minecraft:oak_log[axis=y]");
|
||||
PlatformBlockState leaves = state("minecraft:oak_leaves[distance=7]");
|
||||
PlatformBlockState sand = state("minecraft:sand");
|
||||
PlatformBlockState stone = state("minecraft:stone");
|
||||
PlatformBlockState torch = state("minecraft:wall_torch");
|
||||
|
||||
assertTrue(log.isLog());
|
||||
assertFalse(log.isLeaves());
|
||||
assertTrue(leaves.isLeaves());
|
||||
assertTrue(log.isTreeBlock() && leaves.isTreeBlock());
|
||||
assertFalse(stone.isTreeBlock());
|
||||
assertTrue(sand.hasGravity());
|
||||
assertFalse(stone.hasGravity());
|
||||
PlatformRegistries registries = IrisPlatforms.get().registries();
|
||||
assertTrue(registries.isInTag(log, "minecraft:logs"));
|
||||
assertFalse(registries.isInTag(leaves, "minecraft:logs"));
|
||||
assertFalse(registries.isInTag(log, "pack:unknown"));
|
||||
assertTrue(torch.canAttach(stone, PlatformFace.NORTH));
|
||||
assertFalse(torch.canAttach(state("minecraft:air"), PlatformFace.NORTH));
|
||||
}
|
||||
|
||||
private PlatformBlockState state(String key) {
|
||||
return IrisPlatforms.get().registries().block(key);
|
||||
}
|
||||
|
||||
@@ -120,7 +120,25 @@ public interface PlatformBlockState {
|
||||
/**
|
||||
* Whether this is part of a tree - tagged as a log or as leaves.
|
||||
*/
|
||||
boolean isTreeBlock();
|
||||
default boolean isTreeBlock() {
|
||||
return isLog() || isLeaves();
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this block is tagged as a log, in the platform's block tags.
|
||||
*/
|
||||
boolean isLog();
|
||||
|
||||
/**
|
||||
* Whether this block is tagged as leaves, in the platform's block tags.
|
||||
*/
|
||||
boolean isLeaves();
|
||||
|
||||
/**
|
||||
* Whether this block falls when nothing holds it up - sand, gravel, concrete powder, anvils and the like, as
|
||||
* the platform's own falling block type decides.
|
||||
*/
|
||||
boolean hasGravity();
|
||||
|
||||
/**
|
||||
* Whether foliage can be planted on top of this block.
|
||||
@@ -164,6 +182,13 @@ public interface PlatformBlockState {
|
||||
*/
|
||||
boolean canPlaceOnto(PlatformBlockState onto);
|
||||
|
||||
/**
|
||||
* Whether this block can attach to the {@code face} of {@code support}, ignoring every other neighbour: the
|
||||
* support's face is sturdy enough to hold a torch, a ladder or a button against it, which is the platform's own
|
||||
* full-face support test. Passing a state from a different adapter fails at runtime.
|
||||
*/
|
||||
boolean canAttach(PlatformBlockState support, PlatformFace face);
|
||||
|
||||
/**
|
||||
* Whether the two states are the same block with the same properties. Prefer this to {@code equals}, which
|
||||
* is identity-based on some adapters.
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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.spi;
|
||||
|
||||
/**
|
||||
* One of the six faces of a block, named as the world sees them: up is toward the sky, north toward negative Z,
|
||||
* east toward positive X.
|
||||
* <p>
|
||||
* Internal to Iris; not a published integration surface.
|
||||
*/
|
||||
public enum PlatformFace {
|
||||
UP, DOWN, NORTH, SOUTH, EAST, WEST
|
||||
}
|
||||
@@ -54,6 +54,13 @@ public interface PlatformRegistries {
|
||||
*/
|
||||
PlatformBlockState blockOrNull(String key, boolean warn);
|
||||
|
||||
/**
|
||||
* Whether {@code block} is in the block tag named {@code tag}, a namespaced key such as
|
||||
* {@code minecraft:logs}. A tag the platform does not know has no members, so it answers false. Goes through the
|
||||
* platform's tag lookup on each call: not for the per-block generation path.
|
||||
*/
|
||||
boolean isInTag(PlatformBlockState block, String tag);
|
||||
|
||||
/**
|
||||
* The interned air state. Never null; identity-comparable across calls.
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user