tools.lua 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. function mese_crystals.on_tool_use(itemstack, user, pt)
  2. if pt.type ~= "node" then return end
  3. local pos = pt.under
  4. if minetest.test_protection(pos, user:get_player_name()) then return end
  5. local node = minetest.get_node(pos)
  6. local growth_stage = 0
  7. -- Determine growth stage.
  8. if node.name == "mese_crystals:mese_crystal_ore4" then
  9. growth_stage = 4
  10. elseif node.name == "mese_crystals:mese_crystal_ore3" then
  11. growth_stage = 3
  12. elseif node.name == "mese_crystals:mese_crystal_ore2" then
  13. growth_stage = 2
  14. elseif node.name == "mese_crystals:mese_crystal_ore1" then
  15. growth_stage = 1
  16. end
  17. -- Update crystaline plant.
  18. if growth_stage == 4 then
  19. node.name = "mese_crystals:mese_crystal_ore3"
  20. minetest.swap_node(pos, node)
  21. minetest.get_node_timer(pos):start(mese_crystals.get_grow_time())
  22. elseif growth_stage == 3 then
  23. node.name = "mese_crystals:mese_crystal_ore2"
  24. minetest.swap_node(pos, node)
  25. minetest.get_node_timer(pos):start(mese_crystals.get_grow_time())
  26. elseif growth_stage == 2 then
  27. node.name = "mese_crystals:mese_crystal_ore1"
  28. minetest.swap_node(pos, node)
  29. minetest.get_node_timer(pos):start(mese_crystals.get_grow_time())
  30. else
  31. -- Just restart growing timer.
  32. minetest.get_node_timer(pos):start(mese_crystals.get_grow_time())
  33. end
  34. -- Give wielder a harvest.
  35. if growth_stage > 1 then
  36. ambiance.sound_play("default_break_glass", pos, 0.3, 10)
  37. itemstack:add_wear(65535 / 400)
  38. local inv = user:get_inventory()
  39. local stack
  40. if math.random(1, 40) == 1 then
  41. stack = ItemStack("default:mese_crystal")
  42. else
  43. stack = ItemStack("mese_crystals:zentamine")
  44. end
  45. if inv:room_for_item("main", stack) then
  46. inv:add_item("main", stack)
  47. else
  48. minetest.item_drop(stack, nil, pos)
  49. minetest.chat_send_player(user:get_player_name(), "# Server: Cannot obtain harvest, no room in inventory!")
  50. end
  51. end
  52. return itemstack
  53. end
  54. if not mese_crystals.tool_registered then
  55. minetest.register_tool("mese_crystals:crystaline_bell", {
  56. description = "Crystaline Bell\n\nHarvests zentamine crystals.\nCannot be repaired on anvil.\nNon-metalic.",
  57. inventory_image = "crystalline_bell.png",
  58. groups = {not_repaired_by_anvil = 1},
  59. on_use = function(...)
  60. return mese_crystals.on_tool_use(...)
  61. end,
  62. })
  63. mese_crystals.tool_registered = true
  64. end