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

@@ -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());