init.lua 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. minetest.register_node("chest:chest", {
  2. description = "Chest" .. "\n" ..
  3. "32 inventory slots",
  4. tiles ={"chest_chest.png^[sheet:2x2:0,0", "chest_chest.png^[sheet:2x2:0,0",
  5. "chest_chest.png^[sheet:2x2:1,0", "chest_chest.png^[sheet:2x2:1,0",
  6. "chest_chest.png^[sheet:2x2:1,0", "chest_chest.png^[sheet:2x2:0,1"},
  7. paramtype2 = "facedir",
  8. groups = {dig_immediate=2,choppy=3},
  9. is_ground_content = false,
  10. on_construct = function(pos)
  11. local meta = minetest.get_meta(pos)
  12. meta:set_string("formspec",
  13. "size[8,9]"..
  14. "list[current_name;main;0,0;8,4;]"..
  15. "list[current_player;main;0,5;8,4;]" ..
  16. "listring[]")
  17. meta:set_string("infotext", "Chest")
  18. local inv = meta:get_inventory()
  19. inv:set_size("main", 8*4)
  20. end,
  21. can_dig = function(pos,player)
  22. local meta = minetest.get_meta(pos);
  23. local inv = meta:get_inventory()
  24. return inv:is_empty("main")
  25. end,
  26. allow_metadata_inventory_put = function(pos, listname, index, stack, player)
  27. minetest.chat_send_player(player:get_player_name(), "Allow put: " .. stack:to_string())
  28. return stack:get_count()
  29. end,
  30. allow_metadata_inventory_take = function(pos, listname, index, stack, player)
  31. minetest.chat_send_player(player:get_player_name(), "Allow take: " .. stack:to_string())
  32. return stack:get_count()
  33. end,
  34. on_metadata_inventory_put = function(pos, listname, index, stack, player)
  35. minetest.chat_send_player(player:get_player_name(), "On put: " .. stack:to_string())
  36. end,
  37. on_metadata_inventory_take = function(pos, listname, index, stack, player)
  38. minetest.chat_send_player(player:get_player_name(), "On take: " .. stack:to_string())
  39. end,
  40. })