Advertisement
Guest User

Untitled

a guest
Jun 8th, 2014
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. local defs = {}
  2.  
  3. minetest.after(0.01, function()
  4. for name, def in pairs(minetest.registered_items) do
  5. if def.can_dig then
  6. defs[name] = {}
  7. defs[name].can_dig = def.can_dig
  8. defs[name].on_metadata_inventory_take = def.on_metadata_inventory_take
  9. def.can_dig = function (pos,player)
  10. local node = minetest.get_node(pos)
  11. local meta = minetest.get_meta(pos)
  12. local owner = meta:get_string("owner")
  13. local def = defs[node.name]
  14. local inv = meta:get_inventory()
  15. local is_empty = true
  16. for inv_name in pairs(meta:to_table()["inventory"]) do
  17. if not inv:is_empty(inv_name) then is_empty = false end
  18. end
  19. if owner ~= "" and owner ~= player:get_player_name() then
  20. return defs[name].can_dig (pos,player)
  21. end
  22. for inv_name in pairs(meta:to_table()["inventory"]) do
  23. if not inv:is_empty(inv_name) then
  24. local size = inv:get_size(inv_name)
  25. for i = 1, size do
  26. local item = inv:get_stack(inv_name, i)
  27. if item ~= nil then
  28. minetest.add_item({x = pos.x + math.random() * 2 - 1, y = pos.y+math.random() * 2, z = pos.z + math.random() * 2 - 1}, item)
  29. inv:set_stack(inv_name, i, "")
  30. end
  31. end
  32. end
  33. end
  34. return defs[name].can_dig (pos,player)
  35. end
  36. end
  37. end
  38. end
  39. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement