privatizer.lua 1.2 KB

1234567891011121314151617181920212223242526272829
  1. core.register_tool("testtools:privatizer", {
  2. description = "Node Meta Privatizer".."\n"..
  3. "Punch: Marks 'infotext' and 'formspec' meta fields of chest as private",
  4. inventory_image = "testtools_privatizer.png",
  5. groups = { testtool = 1, disable_repair = 1 },
  6. on_use = function(itemstack, user, pointed_thing)
  7. if pointed_thing.type == "node" then
  8. local node = core.get_node(pointed_thing.under)
  9. if core.get_item_group(node.name, "meta_is_privatizable") == 1 then
  10. local p = pointed_thing.under
  11. core.log("action", "[testtools] Privatizer used at "..core.pos_to_string(p))
  12. core.get_meta(p):mark_as_private({"infotext", "formspec"})
  13. if user and user:is_player() then
  14. core.chat_send_player(user:get_player_name(), "Node metadata (infotext, formspec) set private!")
  15. end
  16. return
  17. elseif node.name == "chest_of_everything:chest" then
  18. if user and user:is_player() then
  19. core.chat_send_player(user:get_player_name(), "Privatizer can't be used on the Chest of Everything. Use it on a normal chest.")
  20. end
  21. return
  22. end
  23. end
  24. if user and user:is_player() then
  25. core.chat_send_player(user:get_player_name(), "Privatizer can only be used on chest!")
  26. end
  27. end,
  28. })