From 4ec1e7271a4dec18cad7c99dfa0afccad28b4f76 Mon Sep 17 00:00:00 2001 From: Algent Date: Sun, 12 Jul 2026 13:35:22 +0200 Subject: [PATCH] Fix Bound Pickaxe ignoring claims and bound tools not checking if they can act on modded block (#135) --- .../common/items/BoundAxe.java | 5 +++-- .../common/items/BoundPickaxe.java | 20 ++++++++++++------- .../common/items/BoundShovel.java | 4 ++-- .../impactEffects/tool/DigAreaEffect.java | 2 +- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/items/BoundAxe.java b/src/main/java/WayofTime/alchemicalWizardry/common/items/BoundAxe.java index dd4b922c..cf42a234 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/common/items/BoundAxe.java +++ b/src/main/java/WayofTime/alchemicalWizardry/common/items/BoundAxe.java @@ -110,8 +110,9 @@ public class BoundAxe extends ItemAxe implements IBindable { } // getStrVsBlock - if ((func_150893_a(item, block) <= 1f && !(block instanceof BlockLeavesBase)) - || BoundPickaxe.checkPermissions(world, x, y, z, block, meta, player)) { + if ((!ForgeHooks.isToolEffective(item, block, meta) && func_150893_a(item, block) <= 1f + && !(block instanceof BlockLeavesBase)) + || BoundPickaxe.isBreakDenied(world, x, y, z, player)) { continue; } if (silkTouch && block.canSilkHarvest(world, player, x, y, z, meta)) { diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/items/BoundPickaxe.java b/src/main/java/WayofTime/alchemicalWizardry/common/items/BoundPickaxe.java index f63b444c..b7f2b6bc 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/common/items/BoundPickaxe.java +++ b/src/main/java/WayofTime/alchemicalWizardry/common/items/BoundPickaxe.java @@ -10,6 +10,7 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemPickaxe; import net.minecraft.item.ItemStack; import net.minecraft.util.IIcon; @@ -17,8 +18,6 @@ import net.minecraft.util.StatCollector; import net.minecraft.util.Vec3; import net.minecraft.world.World; import net.minecraftforge.common.ForgeHooks; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.event.world.BlockEvent; import com.google.common.collect.HashMultiset; import com.google.common.collect.Multiset; @@ -118,7 +117,8 @@ public class BoundPickaxe extends ItemPickaxe implements IBindable { } // getStrVsBlock - if (func_150893_a(item, block) <= 1f || checkPermissions(world, x, y, z, block, meta, player)) { + if ((!ForgeHooks.isToolEffective(item, block, meta) && func_150893_a(item, block) <= 1f) + || isBreakDenied(world, x, y, z, player)) { continue; } if (silkTouch && block.canSilkHarvest(world, player, x, y, z, meta)) { @@ -147,10 +147,16 @@ public class BoundPickaxe extends ItemPickaxe implements IBindable { return item; } - public static boolean checkPermissions(World world, int x, int y, int z, Block block, int meta, - EntityPlayer player) { - final BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(x, y, z, world, block, meta, player); - return MinecraftForge.EVENT_BUS.post(event); + /** + * Fires the block break event so protection mods can veto the break. Returns true if the break was denied. + */ + public static boolean isBreakDenied(World world, int x, int y, int z, EntityPlayer player) { + if (!(player instanceof EntityPlayerMP mpPlayer) || mpPlayer.playerNetServerHandler == null) { + return false; + } + + return ForgeHooks.onBlockBreakEvent(world, mpPlayer.theItemInWorldManager.getGameType(), mpPlayer, x, y, z) + .isCanceled(); } public static void dropMultisetStacks(Multiset dropMultiset, World world, double x, double y, double z) { diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/items/BoundShovel.java b/src/main/java/WayofTime/alchemicalWizardry/common/items/BoundShovel.java index 051101bf..8fcd04f7 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/common/items/BoundShovel.java +++ b/src/main/java/WayofTime/alchemicalWizardry/common/items/BoundShovel.java @@ -114,8 +114,8 @@ public class BoundShovel extends ItemSpade implements IBindable { } // getStrVsBlock - if (func_150893_a(item, block) <= 1f - || BoundPickaxe.checkPermissions(world, x, y, z, block, meta, player)) { + if ((!ForgeHooks.isToolEffective(item, block, meta) && func_150893_a(item, block) <= 1f) + || BoundPickaxe.isBreakDenied(world, x, y, z, player)) { continue; } if (silkTouch && block.canSilkHarvest(world, player, x, y, z, meta)) { diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/spell/complex/effect/impactEffects/tool/DigAreaEffect.java b/src/main/java/WayofTime/alchemicalWizardry/common/spell/complex/effect/impactEffects/tool/DigAreaEffect.java index 55f636b1..7b33ad4e 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/common/spell/complex/effect/impactEffects/tool/DigAreaEffect.java +++ b/src/main/java/WayofTime/alchemicalWizardry/common/spell/complex/effect/impactEffects/tool/DigAreaEffect.java @@ -63,7 +63,7 @@ public class DigAreaEffect implements IDigAreaEffect { float localHardness = block.getBlockHardness(world, x, y, z); if (localHardness < 0 || localHardness - this.getHardnessDifference() > blockHardness - || BoundPickaxe.checkPermissions(world, x, y, z, block, meta, player)) { + || BoundPickaxe.isBreakDenied(world, x, y, z, player)) { return; }