init.lua 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. minetest.register_tool("tree_tap:tree_tap", {
  2. description = "Tree Tap",
  3. inventory_image = "technic_tree_tap.png",
  4. on_use = function(itemstack, user, pointed_thing)
  5. if pointed_thing.type ~= "node" then return end
  6. local pos = pointed_thing.under
  7. if minetest.is_protected(pos, user:get_player_name()) then
  8. minetest.record_protection_violation(pos, user:get_player_name())
  9. return
  10. end
  11. local node = minetest.get_node(pos)
  12. local node_name = node.name
  13. if node_name ~= "moretrees:rubber_tree_tree" then return end
  14. node.name = "moretrees:rubber_tree_trunk_empty"
  15. minetest.swap_node(pos, node)
  16. minetest.handle_node_drops(pointed_thing.above, {"rubber:raw_latex"}, user)
  17. local item_wear = tonumber(itemstack:get_wear())
  18. item_wear = item_wear + 819
  19. if item_wear > 65535 then
  20. ambiance.sound_play("default_tool_breaks", user:get_pos(), 0.7, 10)
  21. itemstack:clear()
  22. return itemstack
  23. end
  24. itemstack:set_wear(item_wear)
  25. return itemstack
  26. end,
  27. })
  28. minetest.register_craft({
  29. output = "tree_tap:tree_tap",
  30. recipe = {
  31. {"stainless_steel:ingot", "group:wood", "group:stick"},
  32. {"", "group:stick", "group:stick"}
  33. },
  34. })
  35. minetest.register_abm({
  36. nodenames = {"moretrees:rubber_tree_trunk_empty"},
  37. interval = 60 * default.ABM_TIMER_MULTIPLIER,
  38. chance = 30 * default.ABM_CHANCE_MULTIPLIER,
  39. action = function(pos, node)
  40. local t = minetest.find_node_near(pos, 2, "moretrees:rubber_tree_leaves")
  41. local w = minetest.find_node_near(pos, 5, "group:water")
  42. if t and w then
  43. node.name = "moretrees:rubber_tree_tree"
  44. minetest.swap_node(pos, node)
  45. end
  46. end
  47. })