Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,9 @@ public ItemStack onItemRightClick(ItemStack item, World world, EntityPlayer play
}

// 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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@
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;
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;
Expand Down Expand Up @@ -118,7 +117,8 @@ public ItemStack onItemRightClick(ItemStack item, World world, EntityPlayer play
}

// 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)) {
Expand Down Expand Up @@ -147,10 +147,16 @@ public ItemStack onItemRightClick(ItemStack item, World world, EntityPlayer play
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<ItemType> dropMultiset, World world, double x, double y, double z) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ public ItemStack onItemRightClick(ItemStack item, World world, EntityPlayer play
}

// 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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void breakBlock(ItemStack container, World world, EntityPlayer player, fl
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;
}

Expand Down