9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-25 09:59:20 +00:00

Merge pull request #291 from iqtesterrr/dev

prevent multi-layer snow replacement
This commit is contained in:
XiaoMoMi
2025-07-18 16:01:35 +08:00
committed by GitHub
2 changed files with 15 additions and 2 deletions

View File

@@ -17,6 +17,7 @@ public final class MBlocks {
public static final Object SHORT_GRASS$defaultState;
public static final Object SHULKER_BOX;
public static final Object COMPOSTER;
public static final Object SNOW;
private static Object getById(String id) {
Object rl = FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath("minecraft", id);
@@ -35,5 +36,6 @@ public final class MBlocks {
SHORT_GRASS$defaultState = FastNMS.INSTANCE.method$Block$defaultState(SHORT_GRASS);
SHULKER_BOX = getById("shulker_box");
COMPOSTER = getById("composter");
SNOW = getById("snow");
}
}

View File

@@ -2,7 +2,9 @@ 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.MBlocks;
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MFluids;
import net.momirealms.craftengine.bukkit.util.BlockStateUtils;
import net.momirealms.craftengine.bukkit.util.LocationUtils;
import net.momirealms.craftengine.core.block.CustomBlock;
import net.momirealms.craftengine.core.block.ImmutableBlockState;
@@ -11,6 +13,7 @@ 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;
@@ -21,11 +24,19 @@ public class BukkitBlockInWorld implements BlockInWorld {
@Override
public boolean canBeReplaced(BlockPlaceContext context) {
ImmutableBlockState customState = CraftEngineBlocks.getCustomBlockState(this.block);
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);
ImmutableBlockState customState = BlockStateUtils.getOptionalCustomBlockState(state).orElse(null);
if (customState != null && !customState.isEmpty()) {
return customState.behavior().canBeReplaced(context, customState);
}
return this.block.isReplaceable();
if (BlockStateUtils.getBlockOwner(state) == MBlocks.SNOW) {
Snow snow = (Snow) BlockStateUtils.fromBlockData(state);
return snow.getLayers() == 1;
}
return BlockStateUtils.isReplaceable(state);
}
@Override