mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-25 09:59:20 +00:00
@@ -3873,4 +3873,27 @@ public final class CoreReflections {
|
||||
throw new ReflectionInitException("Failed to initialize HashOps", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static final Class<?> clazz$SnowLayerBlock = requireNonNull(
|
||||
BukkitReflectionUtils.findReobfOrMojmapClass(
|
||||
"world.level.block.BlockSnow",
|
||||
"world.level.block.SnowLayerBlock"
|
||||
)
|
||||
);
|
||||
|
||||
public static final Field field$SnowLayerBlock$LAYERS = requireNonNull(
|
||||
ReflectionUtils.getDeclaredField(
|
||||
clazz$SnowLayerBlock, clazz$IntegerProperty, 0
|
||||
)
|
||||
);
|
||||
|
||||
public static final Object instance$SnowLayerBlock$LAYERS;
|
||||
|
||||
static {
|
||||
try {
|
||||
instance$SnowLayerBlock$LAYERS = field$SnowLayerBlock$LAYERS.get(null);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new ReflectionInitException("Failed to initialize SnowLayerBlock$LAYERS", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import net.momirealms.craftengine.core.block.DelegatingBlockState;
|
||||
import net.momirealms.craftengine.core.block.ImmutableBlockState;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -142,4 +143,10 @@ public class BlockStateUtils {
|
||||
Object blockOwner = getBlockOwner(state);
|
||||
return IGNITE_ODDS.getOrDefault(blockOwner, 0) > 0;
|
||||
}
|
||||
|
||||
public static Object getBlockState(Block block) {
|
||||
Object worldServer = FastNMS.INSTANCE.field$CraftWorld$ServerLevel(block.getWorld());
|
||||
Object blockPos = LocationUtils.toBlockPos(block.getX(), block.getY(), block.getZ());
|
||||
return FastNMS.INSTANCE.method$BlockGetter$getBlockState(worldServer, blockPos);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package net.momirealms.craftengine.bukkit.world;
|
||||
|
||||
import net.momirealms.craftengine.bukkit.api.CraftEngineBlocks;
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.CoreReflections;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MBlocks;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MFluids;
|
||||
import net.momirealms.craftengine.bukkit.util.BlockStateUtils;
|
||||
@@ -13,7 +14,6 @@ import net.momirealms.craftengine.core.world.BlockInWorld;
|
||||
import net.momirealms.craftengine.core.world.World;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.type.Snow;
|
||||
|
||||
public class BukkitBlockInWorld implements BlockInWorld {
|
||||
private final Block block;
|
||||
@@ -24,17 +24,13 @@ public class BukkitBlockInWorld implements BlockInWorld {
|
||||
|
||||
@Override
|
||||
public boolean canBeReplaced(BlockPlaceContext context) {
|
||||
Object worldServer = FastNMS.INSTANCE.field$CraftWorld$ServerLevel(this.block.getWorld());
|
||||
Object blockPos = LocationUtils.toBlockPos(this.block.getX(), this.block.getY(), this.block.getZ());
|
||||
Object state = FastNMS.INSTANCE.method$BlockGetter$getBlockState(worldServer, blockPos);
|
||||
|
||||
Object state = BlockStateUtils.getBlockState(this.block);
|
||||
ImmutableBlockState customState = BlockStateUtils.getOptionalCustomBlockState(state).orElse(null);
|
||||
if (customState != null && !customState.isEmpty()) {
|
||||
return customState.behavior().canBeReplaced(context, customState);
|
||||
}
|
||||
if (BlockStateUtils.getBlockOwner(state) == MBlocks.SNOW) {
|
||||
Snow snow = (Snow) BlockStateUtils.fromBlockData(state);
|
||||
return snow.getLayers() == 1;
|
||||
return (int) FastNMS.INSTANCE.method$StateHolder$getValue(state, CoreReflections.instance$SnowLayerBlock$LAYERS) == 1;
|
||||
}
|
||||
return BlockStateUtils.isReplaceable(state);
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ byte_buddy_version=1.17.5
|
||||
ahocorasick_version=0.6.3
|
||||
snake_yaml_version=2.4
|
||||
anti_grief_version=0.18
|
||||
nms_helper_version=1.0.36
|
||||
nms_helper_version=1.0.37
|
||||
evalex_version=3.5.0
|
||||
reactive_streams_version=1.0.4
|
||||
amazon_awssdk_version=2.31.23
|
||||
|
||||
Reference in New Issue
Block a user