mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 16:54:04 +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();
|
||||
|
||||
Reference in new issue
Block a user