tools.lua 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. -- Localize for performance.
  2. function mese_crystals.on_tool_use(itemstack, user, pt)
  3. if not user or not user:is_player() then return end
  4. if pt.type ~= "node" then return end
  5. local pos = pt.under
  6. local pname = user:get_player_name()
  7. if minetest.test_protection(pos, pname) then
  8. return
  9. end
  10. local node = minetest.get_node(pos)
  11. if node.name == "default:diamondblock" then
  12. ambiance.sound_play("default_break_glass", pos, 1.0, 32)
  13. local dir = vector.subtract(pt.under, pt.above)
  14. if dir.y == 0 then
  15. local np = vector.add(pos, dir)
  16. local gotten = mese_crystals.harvest_direction(np, dir, pname)
  17. if gotten then
  18. itemstack:add_wear_by_uses(400)
  19. end
  20. end
  21. return itemstack
  22. end
  23. local gotten = mese_crystals.harvest_pos(pos, user)
  24. if gotten then
  25. itemstack:add_wear_by_uses(400)
  26. end
  27. return itemstack
  28. end
  29. if not mese_crystals.tool_registered then
  30. minetest.register_tool("mese_crystals:crystaline_bell", {
  31. description = "Crystaline Bell",
  32. inventory_image = "crystalline_bell.png",
  33. groups = {not_repaired_by_anvil = 1},
  34. on_use = function(...)
  35. return mese_crystals.on_tool_use(...)
  36. end,
  37. })
  38. mese_crystals.tool_registered = true
  39. end