1
0

chest.lua 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. local function print_to_everything(msg)
  2. core.log("action", "[chest] " .. msg)
  3. core.chat_send_all(msg)
  4. end
  5. core.register_node("chest:chest", {
  6. description = "Chest" .. "\n" ..
  7. "32 inventory slots",
  8. tiles ={"chest_chest.png^[sheet:2x2:0,0", "chest_chest.png^[sheet:2x2:0,0",
  9. "chest_chest.png^[sheet:2x2:1,0", "chest_chest.png^[sheet:2x2:1,0",
  10. "chest_chest.png^[sheet:2x2:1,0", "chest_chest.png^[sheet:2x2:0,1"},
  11. paramtype2 = "4dir",
  12. groups = {dig_immediate=2,choppy=3,meta_is_privatizable=1},
  13. is_ground_content = false,
  14. on_construct = function(pos)
  15. local meta = core.get_meta(pos)
  16. meta:set_string("formspec",
  17. "size[8,9]"..
  18. "list[current_name;main;0,0;8,4;]"..
  19. "list[current_player;main;0,5;8,4;]" ..
  20. "listring[]")
  21. meta:set_string("infotext", "Chest")
  22. local inv = meta:get_inventory()
  23. inv:set_size("main", 8*4)
  24. end,
  25. can_dig = function(pos,player)
  26. local meta = core.get_meta(pos);
  27. local inv = meta:get_inventory()
  28. return inv:is_empty("main")
  29. end,
  30. allow_metadata_inventory_put = function(pos, listname, index, stack, player)
  31. print_to_everything("Chest: ".. player:get_player_name() .. " triggered 'allow put' (10) event for " .. stack:to_string())
  32. return 10
  33. end,
  34. allow_metadata_inventory_take = function(pos, listname, index, stack, player)
  35. print_to_everything("Chest: ".. player:get_player_name() .. " triggered 'allow take' (20) event for " .. stack:to_string())
  36. return 20
  37. end,
  38. allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
  39. print_to_everything("Chest: ".. player:get_player_name() .. " triggered 'allow move' (30) event")
  40. return 30
  41. end,
  42. on_metadata_inventory_put = function(pos, listname, index, stack, player)
  43. print_to_everything("Chest: ".. player:get_player_name() .. " put " .. stack:to_string())
  44. end,
  45. on_metadata_inventory_take = function(pos, listname, index, stack, player)
  46. print_to_everything("Chest: ".. player:get_player_name() .. " took " .. stack:to_string())
  47. end,
  48. on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
  49. print_to_everything("Chest: ".. player:get_player_name() .. " moved " .. count)
  50. end,
  51. })