init.lua 665 B

12345678910111213141516171819202122232425262728
  1. undiggable_node_api = {}
  2. --helper function
  3. local function allow_remove_self(itemstack, user, pointed_thing)
  4. if pointed_thing.type == "node"
  5. then
  6. local node = minetest.get_node(pointed_thing.under)
  7. if node.name == itemstack:get_name()
  8. then
  9. minetest.remove_node(pointed_thing.under)
  10. end
  11. end
  12. end
  13. --API FUNCTION
  14. --registers an undiggable node but it can be used as a tool to dig itself
  15. undiggable_node_api.register_barrier = function(name, definition)
  16. definition.diggable = false
  17. definition.on_use = allow_remove_self
  18. definition.groups = definition.groups or {}
  19. definition.groups.indestructible = 1
  20. minetest.register_node(name, definition)
  21. end