diff --git a/src/main/java/com/github/bartimaeusnek/cropspp/items/ItemBppSpade.java b/src/main/java/com/github/bartimaeusnek/cropspp/items/ItemBppSpade.java index 6d485bd..1a5fd27 100644 --- a/src/main/java/com/github/bartimaeusnek/cropspp/items/ItemBppSpade.java +++ b/src/main/java/com/github/bartimaeusnek/cropspp/items/ItemBppSpade.java @@ -13,6 +13,8 @@ import net.minecraft.item.ItemTool; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.entity.player.UseHoeEvent; import com.github.bartimaeusnek.croploadcore.MyRandom; import com.github.bartimaeusnek.croploadcore.Operators; @@ -107,18 +109,32 @@ public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, @Override public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) { - if (side != 0 && world.getBlock(x, y + 1, z).getMaterial() == Material.air - && (world.getBlock(x, y, z) == Blocks.grass || world.getBlock(x, y, z) == Blocks.dirt - || world.getBlock(x, y, z) == Blocks.mycelium)) { - world.setBlock(x, y, z, Blocks.farmland); - return true; - } else if (side != 0 && world.getBlock(x, y + 1, z).getMaterial() == Material.air - && (world.getBlock(x, y, z) == Blocks.farmland)) { - world.setBlock(x, y, z, Blocks.dirt); - return true; - } else { - return false; + if (!player.canPlayerEdit(x, y, z, side, stack)) { + return false; + } + + var event = new UseHoeEvent(player, stack, world, x, y, z); + if (MinecraftForge.EVENT_BUS.post(event)) { + return false; + } + + if (side != 0 && world.getBlock(x, y + 1, z).getMaterial() == Material.air) { + if (world.getBlock(x, y, z) == Blocks.grass || world.getBlock(x, y, z) == Blocks.dirt + || world.getBlock(x, y, z) == Blocks.mycelium + || world.getBlock(x, y, z) == Blocks.farmland) { + playSpadeSound(world, x, y, z); + if (!world.isRemote) { + world.setBlock( + x, + y, + z, + (world.getBlock(x, y, z) == Blocks.farmland) ? Blocks.dirt : Blocks.farmland); } + return true; + } + } + + return false; } @Override @@ -131,4 +147,15 @@ public boolean onBlockDestroyed(ItemStack stack, World p_150894_2_, Block p_1508 public boolean hitEntity(ItemStack stack, EntityLivingBase p_77644_2_, EntityLivingBase player) { return true; } + + private void playSpadeSound(World world, int x, int y, int z) { + var spadeBlock = Blocks.farmland; + world.playSoundEffect( + x + 0.5f, + y + 0.5f, + z + 0.5f, + spadeBlock.stepSound.getStepResourcePath(), + (spadeBlock.stepSound.getVolume() + 1f) + 0.5f, + spadeBlock.stepSound.getPitch() * 0.8f); + } }