You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

init.lua 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. local quest_chests_storage = minetest.get_mod_storage()
  2. minetest.register_node("quest_chest:chest", {
  3. description = "Quest Chest",
  4. tiles = {
  5. "default_chest_top.png",
  6. "default_chest_top.png",
  7. "default_chest_side.png",
  8. "default_chest_side.png",
  9. "default_chest_side.png",
  10. "quest_chest_lock.png"
  11. },
  12. paramtype2 = "facedir",
  13. groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2,},
  14. legacy_facedir_simple = true,
  15. sounds = default.node_sound_wood_defaults(),
  16. can_dig = function(pos,player)
  17. return minetest.check_player_privs(player:get_player_name(), "protection_bypass")
  18. end,
  19. on_destruct = function(pos)
  20. local meta = minetest.get_meta(pos)
  21. local chestid = meta:get_int("chestid")
  22. print("Destroying chest_"..chestid)
  23. end,
  24. on_construct = function(pos)
  25. local meta = minetest.get_meta(pos)
  26. local chestid = quest_chests_storage:get_int("next_id")
  27. meta:set_string("chestid", chestid)
  28. quest_chests_storage:set_int("next_id", chestid+1)
  29. meta:set_string("formspec",
  30. "size[8,9]"..
  31. default.gui_bg ..
  32. default.gui_bg_img ..
  33. default.gui_slots ..
  34. "list[current_player;quest_chest:chest"..chestid..";0,0.3;8,4;]"..
  35. "list[current_player;main;0,4.85;8,1;]" ..
  36. "list[current_player;main;0,6.08;8,3;8]" ..
  37. "listring[current_player;quest_chest:chest"..chestid.."]" ..
  38. "listring[current_player;main]" ..
  39. default.get_hotbar_bg(0,4.85))
  40. local spos = pos.x .. "," .. pos.y .. "," .. pos.z
  41. meta:set_string("formspec_admin",
  42. "size[8,9]"..
  43. default.gui_bg ..
  44. default.gui_bg_img ..
  45. default.gui_slots ..
  46. "list[nodemeta:" .. spos .. ";main;0,0.3;8,4;]" ..
  47. "list[current_player;main;0,4.85;8,1;]" ..
  48. "list[current_player;main;0,6.08;8,3;8]" ..
  49. "listring[nodemeta:" .. spos .. ";main]" ..
  50. "listring[current_player;main]" ..
  51. default.get_hotbar_bg(0,4.85))
  52. local inv = meta:get_inventory()
  53. inv:set_size("main", 8*2)
  54. end,
  55. allow_metadata_inventory_put = function(pos, listname, index, stack, player)
  56. local playername = player:get_player_name()
  57. if minetest.check_player_privs(playername, "protection_bypass") then
  58. return stack:get_count()
  59. else
  60. return 0
  61. end
  62. end,
  63. allow_metadata_inventory_take = function(pos, listname, index, stack, player)
  64. local playername = player:get_player_name()
  65. if minetest.check_player_privs(playername, "protection_bypass") then
  66. return stack:get_count()
  67. else
  68. return 0
  69. end
  70. end,
  71. allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
  72. local playername = player:get_player_name()
  73. if minetest.check_player_privs(playername, "protection_bypass") then
  74. return count
  75. else
  76. return 0
  77. end
  78. end,
  79. on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
  80. local meta = minetest.get_meta(pos)
  81. local playername = clicker:get_player_name()
  82. if minetest.check_player_privs(playername, "protection_bypass") then
  83. minetest.show_formspec(clicker:get_player_name(),
  84. node.name, meta:get_string("formspec_admin"))
  85. else
  86. local inv = clicker:get_inventory()
  87. local chestname = "quest_chest:chest"..meta:get_int("chestid")
  88. if inv:get_size(chestname)==0 then
  89. inv:set_size(chestname, 8*2)
  90. inv:set_list(chestname, meta:get_inventory():get_list("main"))
  91. end
  92. minetest.show_formspec(clicker:get_player_name(),
  93. node.name, meta:get_string("formspec"))
  94. end
  95. end,
  96. on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
  97. minetest.log("action", player:get_player_name()..
  98. " moves stuff in quest chest at "..minetest.pos_to_string(pos))
  99. end,
  100. on_metadata_inventory_put = function(pos, listname, index, stack, player)
  101. minetest.log("action", player:get_player_name()..
  102. " moves stuff to quest chest at "..minetest.pos_to_string(pos))
  103. end,
  104. on_metadata_inventory_take = function(pos, listname, index, stack, player)
  105. minetest.log("action", player:get_player_name()..
  106. " takes stuff from quest chest at "..minetest.pos_to_string(pos))
  107. end,
  108. })
  109. minetest.register_on_player_inventory_action(
  110. function(player, action, inventory, inventory_info)
  111. local inv = player:get_inventory()
  112. if inventory_info.from_list and inventory_info.from_index then
  113. local stack = inv:get_stack(
  114. inventory_info.from_list,
  115. inventory_info.from_index
  116. )
  117. end
  118. end)
  119. minetest.register_allow_player_inventory_action(
  120. function(player, action, inventory, inventory_info)
  121. local inv = player:get_inventory()
  122. if inventory_info.from_list and inventory_info.from_index then
  123. local stack = inv:get_stack(
  124. inventory_info.from_list,
  125. inventory_info.from_index
  126. )
  127. if string.sub(inventory_info.to_list,1,11)=="quest_chest" then
  128. return 0
  129. else
  130. return stack:get_count()
  131. end
  132. end
  133. return
  134. end)