From 3c3c5c00dd2fcad87858cf24c5a2643acf1fc197 Mon Sep 17 00:00:00 2001 From: iqtester Date: Wed, 16 Jul 2025 22:13:17 -0400 Subject: [PATCH 1/3] prevent multi-layer snow replacement --- .../craftengine/bukkit/world/BukkitBlockInWorld.java | 6 ++++++ 1 file changed, 6 insertions(+) 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..8d0451af7 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 @@ -10,7 +10,9 @@ import net.momirealms.craftengine.core.item.context.BlockPlaceContext; import net.momirealms.craftengine.core.world.BlockInWorld; import net.momirealms.craftengine.core.world.World; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.block.Block; +import org.bukkit.block.data.type.Snow; public class BukkitBlockInWorld implements BlockInWorld { private final Block block; @@ -25,6 +27,10 @@ public class BukkitBlockInWorld implements BlockInWorld { if (customState != null && !customState.isEmpty()) { return customState.behavior().canBeReplaced(context, customState); } + if (this.block.getType() == Material.SNOW) { + Snow snow = (Snow) block.getBlockData(); + return snow.getLayers() == 1; + } return this.block.isReplaceable(); } From fd94643440d752624969384f6ac26c3e470224dc Mon Sep 17 00:00:00 2001 From: iqtester Date: Thu, 17 Jul 2025 14:34:05 -0400 Subject: [PATCH 2/3] retrieving vanilla state once --- .../bukkit/world/BukkitBlockInWorld.java | 15 ++++++++++----- .../craftengine/core/item/ItemKeys.java | 1 + 2 files changed, 11 insertions(+), 5 deletions(-) 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 8d0451af7..a0596469f 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 @@ -3,14 +3,15 @@ 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.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; +import net.momirealms.craftengine.core.item.ItemKeys; import net.momirealms.craftengine.core.item.context.BlockPlaceContext; import net.momirealms.craftengine.core.world.BlockInWorld; import net.momirealms.craftengine.core.world.World; import org.bukkit.Location; -import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.data.type.Snow; @@ -23,15 +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); } - if (this.block.getType() == Material.SNOW) { - Snow snow = (Snow) block.getBlockData(); + if (BlockStateUtils.getBlockOwnerIdFromState(state).equals(ItemKeys.SNOW)) { + Snow snow = (Snow) BlockStateUtils.fromBlockData(state); return snow.getLayers() == 1; } - return this.block.isReplaceable(); + return BlockStateUtils.isReplaceable(state); } @Override diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/ItemKeys.java b/core/src/main/java/net/momirealms/craftengine/core/item/ItemKeys.java index 89916d9e3..a1991a9f8 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/ItemKeys.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/ItemKeys.java @@ -33,6 +33,7 @@ public class ItemKeys { public static final Key BARRIER = Key.of("minecraft:barrier"); public static final Key CACTUS = Key.of("minecraft:cactus"); public static final Key REDSTONE = Key.of("minecraft:redstone"); + public static final Key SNOW = Key.of("minecraft:snow"); public static final Key[] AXES = new Key[] { WOODEN_AXE, STONE_AXE, IRON_AXE, GOLDEN_AXE, DIAMOND_AXE, NETHERITE_AXE From 84725e177ee77e358fcbee0193567324fbfe1ad9 Mon Sep 17 00:00:00 2001 From: iqtester Date: Thu, 17 Jul 2025 16:32:23 -0400 Subject: [PATCH 3/3] improve comparison --- .../bukkit/plugin/reflection/minecraft/MBlocks.java | 2 ++ .../craftengine/bukkit/world/BukkitBlockInWorld.java | 4 ++-- .../java/net/momirealms/craftengine/core/item/ItemKeys.java | 1 - 3 files changed, 4 insertions(+), 3 deletions(-) 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 a0596469f..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,12 +2,12 @@ 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; -import net.momirealms.craftengine.core.item.ItemKeys; import net.momirealms.craftengine.core.item.context.BlockPlaceContext; import net.momirealms.craftengine.core.world.BlockInWorld; import net.momirealms.craftengine.core.world.World; @@ -32,7 +32,7 @@ public class BukkitBlockInWorld implements BlockInWorld { if (customState != null && !customState.isEmpty()) { return customState.behavior().canBeReplaced(context, customState); } - if (BlockStateUtils.getBlockOwnerIdFromState(state).equals(ItemKeys.SNOW)) { + if (BlockStateUtils.getBlockOwner(state) == MBlocks.SNOW) { Snow snow = (Snow) BlockStateUtils.fromBlockData(state); return snow.getLayers() == 1; } diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/ItemKeys.java b/core/src/main/java/net/momirealms/craftengine/core/item/ItemKeys.java index a1991a9f8..89916d9e3 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/ItemKeys.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/ItemKeys.java @@ -33,7 +33,6 @@ public class ItemKeys { public static final Key BARRIER = Key.of("minecraft:barrier"); public static final Key CACTUS = Key.of("minecraft:cactus"); public static final Key REDSTONE = Key.of("minecraft:redstone"); - public static final Key SNOW = Key.of("minecraft:snow"); public static final Key[] AXES = new Key[] { WOODEN_AXE, STONE_AXE, IRON_AXE, GOLDEN_AXE, DIAMOND_AXE, NETHERITE_AXE