diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/reflection/minecraft/MBlocks.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/reflection/minecraft/MBlocks.java index 2cf9d1613..34d2f0e65 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/reflection/minecraft/MBlocks.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/reflection/minecraft/MBlocks.java @@ -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"); } } diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/world/BukkitBlockInWorld.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/world/BukkitBlockInWorld.java index 170c50dd1..6b6b6e675 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/world/BukkitBlockInWorld.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/world/BukkitBlockInWorld.java @@ -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