hoe.lua 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. local function add_hoe(material)
  2. -- registering as tool
  3. local name = "farming:hoe_"..material
  4. toolranks.add_tool(name)
  5. -- getting after_use
  6. local def = minetest.registered_items[name]
  7. local hoe_on_use = def.on_use
  8. local hoe_after_use = def.after_use
  9. if (hoe_on_use == nil) or (hoe_after_use == nil) then
  10. return
  11. end
  12. minetest.override_item(name, {
  13. -- we also want hoes to increase dugnodes when farming soil
  14. on_use = function(itemstack, user, pointed_thing, uses)
  15. local under = minetest.get_node(pointed_thing.under)
  16. -- get origin wear
  17. local wear = itemstack:get_wear()
  18. -- apply previous on_use
  19. local ret_itemstack = hoe_on_use(itemstack, user, pointed_thing, uses)
  20. if ret_itemstack == nil then
  21. return nil
  22. end
  23. -- compute wear diff
  24. local hoe_uses = ret_itemstack:get_wear() - wear
  25. -- set wear back because it is up to hoe_after_use to add wear
  26. ret_itemstack:set_wear(wear)
  27. -- apply afteruse
  28. return hoe_after_use(ret_itemstack, user, under, {wear = hoe_uses})
  29. end
  30. })
  31. end
  32. add_hoe("wood")
  33. add_hoe("stone")
  34. add_hoe("steel")
  35. -- Following hoes are not available in creative inventory, but
  36. -- it is possible to /give them
  37. add_hoe("bronze")
  38. add_hoe("mese")
  39. add_hoe("diamond")