init.lua 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. if not minetest.global_exists("shears") then shears = {} end
  2. shears.modpath = minetest.get_modpath("shears")
  3. local USES = 200
  4. shears.on_place = function(itemstack, user, pointed_thing)
  5. if pointed_thing.type ~= "node" then
  6. return
  7. end
  8. local pos = pointed_thing.under
  9. local node = minetest.get_node(pos)
  10. -- Pass through interactions to nodes that define them (like chests).
  11. do
  12. local pdef = minetest.reg_ns_nodes[node.name]
  13. if pdef and pdef.on_rightclick and not user:get_player_control().sneak then
  14. return pdef.on_rightclick(pos, node, user, itemstack, pointed_thing)
  15. end
  16. end
  17. if minetest.is_protected(pos, user:get_player_name()) then
  18. minetest.record_protection_violation(pos, user:get_player_name())
  19. return
  20. end
  21. if node.name == "vines:rope" then
  22. itemstack:add_wear(65535 / (USES - 1))
  23. minetest.swap_node(pos, {name="vines:rope_bottom"}) -- Do not wipe metadata.
  24. local p = {x=pos.x, y=pos.y-1, z=pos.z}
  25. local n = minetest.get_node(p)
  26. if (n.name == 'vines:rope' or n.name == 'vines:rope_bottom') then
  27. -- This will trigger removal of the rope underneath.
  28. minetest.set_node(p, {name="vines:rope_top"})
  29. end
  30. end
  31. end
  32. if not shears.run_once then
  33. minetest.register_tool("shears:shears", {
  34. description = "Shears",
  35. inventory_image = "shears_shears.png",
  36. wield_image = "shears_shears.png",
  37. stack_max = 1,
  38. tool_capabilities = tooldata["shears_shears"],
  39. -- OnPlace is used to avoid interfering with regular digging actions on the client.
  40. -- The shears are allowed to dig leaves and ropes.
  41. on_place = function(...) return shears.on_place(...) end,
  42. sounds = {breaks = "basictools_tool_breaks"},
  43. groups = {flammable=2},
  44. })
  45. minetest.register_alias("vines:shears", "shears:shears")
  46. minetest.register_craft({
  47. output = 'shears:shears',
  48. recipe = {
  49. {'', 'default:steel_ingot', '' },
  50. {'default:stick', 'group:wood', 'default:steel_ingot'},
  51. {'', 'default:stick', '' },
  52. },
  53. })
  54. minetest.register_craft({
  55. output = 'shears:shears',
  56. recipe = {
  57. {'', 'moreores:tin_ingot', '' },
  58. {'default:stick', 'group:wood', 'moreores:tin_ingot' },
  59. {'', 'default:stick', '' },
  60. },
  61. })
  62. -- Reloadable.
  63. local name = "shears:core"
  64. local file = shears.modpath .. "/init.lua"
  65. reload.register_file(name, file, false)
  66. shears.run_once = true
  67. end