doors_chest.lua 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740
  1. -- Since the doors mod has changed in the latest daily builds I have taken the
  2. -- WTFPL licenced code from the old doors mod and included an edited version
  3. -- within this mod for local use.
  4. local S = protector.intllib
  5. local F = minetest.formspec_escape
  6. -- MineClone2 support
  7. local mcl = not minetest.registered_items["default:steel_ingot"]
  8. -- Registers a door
  9. function register_door(name, def)
  10. def.groups.not_in_creative_inventory = 1
  11. local box = {{-0.5, -0.5, -0.5, 0.5, 0.5, -0.5+1.5/16}}
  12. def.node_box_bottom = box
  13. def.node_box_top = box
  14. def.selection_box_bottom = box
  15. def.selection_box_top = box
  16. def.sound_close_door = "doors_door_close"
  17. def.sound_open_door = "doors_door_open"
  18. minetest.register_craftitem(name, {
  19. description = def.description,
  20. inventory_image = def.inventory_image,
  21. on_place = function(itemstack, placer, pointed_thing)
  22. if not pointed_thing.type == "node" then
  23. return itemstack
  24. end
  25. local ptu = pointed_thing.under
  26. local nu = minetest.get_node(ptu)
  27. if minetest.registered_nodes[nu.name]
  28. and minetest.registered_nodes[nu.name].on_rightclick then
  29. return minetest.registered_nodes[nu.name].on_rightclick(ptu, nu, placer, itemstack)
  30. end
  31. local pt = pointed_thing.above
  32. local pt2 = {x=pt.x, y=pt.y, z=pt.z}
  33. pt2.y = pt2.y+1
  34. if
  35. not minetest.registered_nodes[minetest.get_node(pt).name].buildable_to or
  36. not minetest.registered_nodes[minetest.get_node(pt2).name].buildable_to or
  37. not placer or
  38. not placer:is_player()
  39. then
  40. return itemstack
  41. end
  42. if minetest.is_protected(pt, placer:get_player_name()) or
  43. minetest.is_protected(pt2, placer:get_player_name()) then
  44. minetest.record_protection_violation(pt, placer:get_player_name())
  45. return itemstack
  46. end
  47. local p2 = minetest.dir_to_facedir(placer:get_look_dir())
  48. local pt3 = {x=pt.x, y=pt.y, z=pt.z}
  49. if p2 == 0 then
  50. pt3.x = pt3.x-1
  51. elseif p2 == 1 then
  52. pt3.z = pt3.z+1
  53. elseif p2 == 2 then
  54. pt3.x = pt3.x+1
  55. elseif p2 == 3 then
  56. pt3.z = pt3.z-1
  57. end
  58. if minetest.get_item_group(minetest.get_node(pt3).name, "door") == 0 then
  59. minetest.set_node(pt, {name=name.."_b_1", param2=p2})
  60. minetest.set_node(pt2, {name=name.."_t_1", param2=p2})
  61. else
  62. minetest.set_node(pt, {name=name.."_b_2", param2=p2})
  63. minetest.set_node(pt2, {name=name.."_t_2", param2=p2})
  64. minetest.get_meta(pt):set_int("right", 1)
  65. minetest.get_meta(pt2):set_int("right", 1)
  66. end
  67. if not minetest.setting_getbool("creative_mode") then
  68. itemstack:take_item()
  69. end
  70. return itemstack
  71. end,
  72. })
  73. local tt = def.tiles_top
  74. local tb = def.tiles_bottom
  75. local function after_dig_node(pos, name, digger)
  76. local node = minetest.get_node(pos)
  77. if node.name == name then
  78. minetest.node_dig(pos, node, digger)
  79. end
  80. end
  81. local function on_rightclick(pos, dir, check_name, replace, replace_dir, params)
  82. pos.y = pos.y+dir
  83. if minetest.get_node(pos).name ~= check_name then
  84. return
  85. end
  86. local p2 = minetest.get_node(pos).param2
  87. p2 = params[p2+1]
  88. minetest.swap_node(pos, {name=replace_dir, param2=p2})
  89. pos.y = pos.y-dir
  90. minetest.swap_node(pos, {name=replace, param2=p2})
  91. local snd_1 = def.sound_close_door
  92. local snd_2 = def.sound_open_door
  93. if params[1] == 3 then
  94. snd_1 = def.sound_open_door
  95. snd_2 = def.sound_close_door
  96. end
  97. if minetest.get_meta(pos):get_int("right") ~= 0 then
  98. minetest.sound_play(snd_1, {pos = pos, gain = 0.3, max_hear_distance = 10})
  99. else
  100. minetest.sound_play(snd_2, {pos = pos, gain = 0.3, max_hear_distance = 10})
  101. end
  102. end
  103. local function on_rotate(pos, node, dir, user, check_name, mode, new_param2)
  104. if mode ~= screwdriver.ROTATE_FACE then
  105. return false
  106. end
  107. pos.y = pos.y + dir
  108. if not minetest.get_node(pos).name == check_name then
  109. return false
  110. end
  111. if minetest.is_protected(pos, user:get_player_name()) then
  112. minetest.record_protection_violation(pos, user:get_player_name())
  113. return false
  114. end
  115. local node2 = minetest.get_node(pos)
  116. node2.param2 = (node2.param2 + 1) % 4
  117. minetest.swap_node(pos, node2)
  118. pos.y = pos.y - dir
  119. node.param2 = (node.param2 + 1) % 4
  120. minetest.swap_node(pos, node)
  121. return true
  122. end
  123. minetest.register_node(name.."_b_1", {
  124. tiles = {tb[2], tb[2], tb[2], tb[2], tb[1], tb[1].."^[transformfx"},
  125. paramtype = "light",
  126. paramtype2 = "facedir",
  127. is_ground_content = false,
  128. drop = name,
  129. drawtype = "nodebox",
  130. node_box = {
  131. type = "fixed",
  132. fixed = def.node_box_bottom
  133. },
  134. selection_box = {
  135. type = "fixed",
  136. fixed = def.selection_box_bottom
  137. },
  138. groups = def.groups,
  139. after_dig_node = function(pos, oldnode, oldmetadata, digger)
  140. pos.y = pos.y+1
  141. after_dig_node(pos, name.."_t_1", digger)
  142. end,
  143. on_rightclick = function(pos, node, clicker)
  144. if not minetest.is_protected(pos, clicker:get_player_name()) then
  145. on_rightclick(pos, 1, name.."_t_1", name.."_b_2", name.."_t_2", {1,2,3,0})
  146. end
  147. end,
  148. on_rotate = function(pos, node, user, mode, new_param2)
  149. return on_rotate(pos, node, 1, user, name.."_t_1", mode)
  150. end,
  151. sounds = def.sounds,
  152. sunlight_propagates = def.sunlight,
  153. on_blast = function() end,
  154. })
  155. minetest.register_node(name.."_t_1", {
  156. tiles = {tt[2], tt[2], tt[2], tt[2], tt[1], tt[1].."^[transformfx"},
  157. paramtype = "light",
  158. paramtype2 = "facedir",
  159. is_ground_content = false,
  160. drop = "",
  161. drawtype = "nodebox",
  162. node_box = {
  163. type = "fixed",
  164. fixed = def.node_box_top
  165. },
  166. selection_box = {
  167. type = "fixed",
  168. fixed = def.selection_box_top
  169. },
  170. groups = def.groups,
  171. after_dig_node = function(pos, oldnode, oldmetadata, digger)
  172. pos.y = pos.y-1
  173. after_dig_node(pos, name.."_b_1", digger)
  174. end,
  175. on_rightclick = function(pos, node, clicker)
  176. if not minetest.is_protected(pos, clicker:get_player_name()) then
  177. on_rightclick(pos, -1, name.."_b_1", name.."_t_2", name.."_b_2", {1,2,3,0})
  178. end
  179. end,
  180. on_rotate = function(pos, node, user, mode, new_param2)
  181. return on_rotate(pos, node, -1, user, name.."_b_1", mode)
  182. end,
  183. sounds = def.sounds,
  184. sunlight_propagates = def.sunlight,
  185. on_blast = function() end,
  186. })
  187. minetest.register_node(name.."_b_2", {
  188. tiles = {tb[2], tb[2], tb[2], tb[2], tb[1].."^[transformfx", tb[1]},
  189. paramtype = "light",
  190. paramtype2 = "facedir",
  191. is_ground_content = false,
  192. drop = name,
  193. drawtype = "nodebox",
  194. node_box = {
  195. type = "fixed",
  196. fixed = def.node_box_bottom
  197. },
  198. selection_box = {
  199. type = "fixed",
  200. fixed = def.selection_box_bottom
  201. },
  202. groups = def.groups,
  203. after_dig_node = function(pos, oldnode, oldmetadata, digger)
  204. pos.y = pos.y+1
  205. after_dig_node(pos, name.."_t_2", digger)
  206. end,
  207. on_rightclick = function(pos, node, clicker)
  208. if not minetest.is_protected(pos, clicker:get_player_name()) then
  209. on_rightclick(pos, 1, name.."_t_2", name.."_b_1", name.."_t_1", {3,0,1,2})
  210. end
  211. end,
  212. on_rotate = function(pos, node, user, mode, new_param2)
  213. return on_rotate(pos, node, 1, user, name.."_t_2", mode)
  214. end,
  215. sounds = def.sounds,
  216. sunlight_propagates = def.sunlight,
  217. on_blast = function() end,
  218. })
  219. minetest.register_node(name.."_t_2", {
  220. tiles = {tt[2], tt[2], tt[2], tt[2], tt[1].."^[transformfx", tt[1]},
  221. paramtype = "light",
  222. paramtype2 = "facedir",
  223. is_ground_content = false,
  224. drop = "",
  225. drawtype = "nodebox",
  226. node_box = {
  227. type = "fixed",
  228. fixed = def.node_box_top
  229. },
  230. selection_box = {
  231. type = "fixed",
  232. fixed = def.selection_box_top
  233. },
  234. groups = def.groups,
  235. after_dig_node = function(pos, oldnode, oldmetadata, digger)
  236. pos.y = pos.y-1
  237. after_dig_node(pos, name.."_b_2", digger)
  238. end,
  239. on_rightclick = function(pos, node, clicker)
  240. if not minetest.is_protected(pos, clicker:get_player_name()) then
  241. on_rightclick(pos, -1, name.."_b_2", name.."_t_1", name.."_b_1", {3,0,1,2})
  242. end
  243. end,
  244. on_rotate = function(pos, node, user, mode, new_param2)
  245. return on_rotate(pos, node, -1, user, name.."_b_2", mode)
  246. end,
  247. sounds = def.sounds,
  248. sunlight_propagates = def.sunlight,
  249. on_blast = function() end,
  250. })
  251. end
  252. -- Protected Wooden Door
  253. local name = "protector:door_wood"
  254. register_door(name, {
  255. description = S("Protected Wooden Door"),
  256. inventory_image = "doors_wood.png^protector_logo.png",
  257. groups = {
  258. snappy = 1, choppy = 2, oddly_breakable_by_hand = 2,
  259. unbreakable = 1, --door = 1
  260. },
  261. tiles_bottom = {"doors_wood_b.png^protector_logo.png", "doors_brown.png"},
  262. tiles_top = {"doors_wood_a.png", "doors_brown.png"},
  263. sounds = default.node_sound_wood_defaults(),
  264. sunlight = false,
  265. })
  266. if mcl then
  267. minetest.register_craft({
  268. output = name,
  269. recipe = {
  270. {"mcl_doors:wooden_door", "mcl_core:gold_ingot"}
  271. }
  272. })
  273. else
  274. minetest.register_craft({
  275. output = name,
  276. recipe = {
  277. {"group:wood", "group:wood"},
  278. {"group:wood", "default:copper_ingot"},
  279. {"group:wood", "group:wood"}
  280. }
  281. })
  282. minetest.register_craft({
  283. output = name,
  284. recipe = {
  285. {"doors:door_wood", "default:copper_ingot"}
  286. }
  287. })
  288. end
  289. -- Protected Steel Door
  290. local name = "protector:door_steel"
  291. register_door(name, {
  292. description = S("Protected Steel Door"),
  293. inventory_image = "doors_steel.png^protector_logo.png",
  294. groups = {
  295. snappy = 1, bendy = 2, cracky = 1,
  296. level = 2, unbreakable = 1, -- door = 1
  297. },
  298. tiles_bottom = {"doors_steel_b.png^protector_logo.png", "doors_grey.png"},
  299. tiles_top = {"doors_steel_a.png", "doors_grey.png"},
  300. sounds = default.node_sound_wood_defaults(),
  301. sunlight = false,
  302. })
  303. if mcl then
  304. minetest.register_craft({
  305. output = name,
  306. recipe = {
  307. {"mcl_doors:iron_door", "mcl_core:gold_ingot"}
  308. }
  309. })
  310. else
  311. minetest.register_craft({
  312. output = name,
  313. recipe = {
  314. {"default:steel_ingot", "default:steel_ingot"},
  315. {"default:steel_ingot", "default:copper_ingot"},
  316. {"default:steel_ingot", "default:steel_ingot"}
  317. }
  318. })
  319. minetest.register_craft({
  320. output = name,
  321. recipe = {
  322. {"doors:door_steel", "default:copper_ingot"}
  323. }
  324. })
  325. end
  326. ----trapdoor----
  327. function register_trapdoor(name, def)
  328. local name_closed = name
  329. local name_opened = name.."_open"
  330. def.on_rightclick = function (pos, node, clicker, itemstack, pointed_thing)
  331. if minetest.is_protected(pos, clicker:get_player_name()) then
  332. return
  333. end
  334. local newname = node.name == name_closed and name_opened or name_closed
  335. local sound = false
  336. if node.name == name_closed then sound = "doors_door_open" end
  337. if node.name == name_opened then sound = "doors_door_close" end
  338. if sound then
  339. minetest.sound_play(sound, {pos = pos, gain = 0.3, max_hear_distance = 10})
  340. end
  341. minetest.swap_node(pos, {name = newname, param1 = node.param1, param2 = node.param2})
  342. end
  343. -- Common trapdoor configuration
  344. def.drawtype = "nodebox"
  345. def.paramtype = "light"
  346. def.paramtype2 = "facedir"
  347. def.is_ground_content = false
  348. local def_opened = table.copy(def)
  349. local def_closed = table.copy(def)
  350. def_closed.node_box = {
  351. type = "fixed",
  352. fixed = {-0.5, -0.5, -0.5, 0.5, -6/16, 0.5}
  353. }
  354. def_closed.selection_box = {
  355. type = "fixed",
  356. fixed = {-0.5, -0.5, -0.5, 0.5, -6/16, 0.5}
  357. }
  358. def_closed.tiles = { def.tile_front, def.tile_front, def.tile_side, def.tile_side,
  359. def.tile_side, def.tile_side }
  360. def_opened.node_box = {
  361. type = "fixed",
  362. fixed = {-0.5, -0.5, 6/16, 0.5, 0.5, 0.5}
  363. }
  364. def_opened.selection_box = {
  365. type = "fixed",
  366. fixed = {-0.5, -0.5, 6/16, 0.5, 0.5, 0.5}
  367. }
  368. def_opened.tiles = { def.tile_side, def.tile_side,
  369. def.tile_side .. "^[transform3",
  370. def.tile_side .. "^[transform1",
  371. def.tile_front, def.tile_front }
  372. def_opened.drop = name_closed
  373. def_opened.groups.not_in_creative_inventory = 1
  374. minetest.register_node(name_opened, def_opened)
  375. minetest.register_node(name_closed, def_closed)
  376. end
  377. -- Protected Wooden Trapdoor
  378. register_trapdoor("protector:trapdoor", {
  379. description = S("Protected Trapdoor"),
  380. inventory_image = "doors_trapdoor.png^protector_logo.png",
  381. wield_image = "doors_trapdoor.png^protector_logo.png",
  382. tile_front = "doors_trapdoor.png^protector_logo.png",
  383. tile_side = "doors_trapdoor_side.png",
  384. groups = {
  385. snappy = 1, choppy = 2, oddly_breakable_by_hand = 2,
  386. unbreakable = 1, --door = 1
  387. },
  388. sounds = default.node_sound_wood_defaults(),
  389. })
  390. if mcl then
  391. minetest.register_craft({
  392. output = "protector:trapdoor",
  393. recipe = {
  394. {"mcl_doors:trapdoor", "mcl_core:gold_ingot"}
  395. }
  396. })
  397. else
  398. minetest.register_craft({
  399. output = "protector:trapdoor 2",
  400. recipe = {
  401. {"group:wood", "default:copper_ingot", "group:wood"},
  402. {"group:wood", "group:wood", "group:wood"},
  403. }
  404. })
  405. minetest.register_craft({
  406. output = "protector:trapdoor",
  407. recipe = {
  408. {"doors:trapdoor", "default:copper_ingot"}
  409. }
  410. })
  411. end
  412. -- Protected Steel Trapdoor
  413. register_trapdoor("protector:trapdoor_steel", {
  414. description = S("Protected Steel Trapdoor"),
  415. inventory_image = "doors_trapdoor_steel.png^protector_logo.png",
  416. wield_image = "doors_trapdoor_steel.png^protector_logo.png",
  417. tile_front = "doors_trapdoor_steel.png^protector_logo.png",
  418. tile_side = "doors_trapdoor_steel_side.png",
  419. groups = {
  420. snappy = 1, bendy = 2, cracky = 1, melty = 2, level = 2,
  421. unbreakable = 1, --door = 1
  422. },
  423. sounds = default.node_sound_wood_defaults(),
  424. })
  425. if mcl then
  426. minetest.register_craft({
  427. output = "protector:trapdoor_steel",
  428. recipe = {
  429. {"mcl_doors:iron_trapdoor", "mcl_core:gold_ingot"}
  430. }
  431. })
  432. else
  433. minetest.register_craft({
  434. output = "protector:trapdoor_steel",
  435. recipe = {
  436. {"default:copper_ingot", "default:steel_ingot"},
  437. {"default:steel_ingot", "default:steel_ingot"},
  438. }
  439. })
  440. minetest.register_craft({
  441. output = "protector:trapdoor_steel",
  442. recipe = {
  443. {"doors:trapdoor_steel", "default:copper_ingot"}
  444. }
  445. })
  446. end
  447. -- Protected Chest
  448. minetest.register_node("protector:chest", {
  449. description = S("Protected Chest"),
  450. tiles = {
  451. "default_chest_top.png", "default_chest_top.png",
  452. "default_chest_side.png", "default_chest_side.png",
  453. "default_chest_side.png", "default_chest_front.png^protector_logo.png"
  454. },
  455. paramtype2 = "facedir",
  456. groups = {choppy = 2, oddly_breakable_by_hand = 2, unbreakable = 1},
  457. legacy_facedir_simple = true,
  458. is_ground_content = false,
  459. sounds = default.node_sound_wood_defaults(),
  460. on_construct = function(pos)
  461. local meta = minetest.get_meta(pos)
  462. local inv = meta:get_inventory()
  463. meta:set_string("infotext", S("Protected Chest"))
  464. meta:set_string("name", "")
  465. inv:set_size("main", 8 * 4)
  466. end,
  467. can_dig = function(pos,player)
  468. local meta = minetest.get_meta(pos)
  469. local inv = meta:get_inventory()
  470. if inv:is_empty("main") then
  471. if not minetest.is_protected(pos, player:get_player_name()) then
  472. return true
  473. end
  474. end
  475. end,
  476. on_metadata_inventory_put = function(pos, listname, index, stack, player)
  477. minetest.log("action", player:get_player_name() ..
  478. " moves stuff to protected chest at " ..
  479. minetest.pos_to_string(pos))
  480. end,
  481. on_metadata_inventory_take = function(pos, listname, index, stack, player)
  482. minetest.log("action", player:get_player_name() ..
  483. " takes stuff from protected chest at " ..
  484. minetest.pos_to_string(pos))
  485. end,
  486. on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
  487. minetest.log("action", player:get_player_name() ..
  488. " moves stuff inside protected chest at " ..
  489. minetest.pos_to_string(pos))
  490. end,
  491. allow_metadata_inventory_put = function(pos, listname, index, stack, player)
  492. if minetest.is_protected(pos, player:get_player_name()) then
  493. return 0
  494. end
  495. return stack:get_count()
  496. end,
  497. allow_metadata_inventory_take = function(pos, listname, index, stack, player)
  498. if minetest.is_protected(pos, player:get_player_name()) then
  499. return 0
  500. end
  501. return stack:get_count()
  502. end,
  503. allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
  504. if minetest.is_protected(pos, player:get_player_name()) then
  505. return 0
  506. end
  507. return count
  508. end,
  509. on_rightclick = function(pos, node, clicker)
  510. if minetest.is_protected(pos, clicker:get_player_name()) then
  511. return
  512. end
  513. local meta = minetest.get_meta(pos)
  514. if not meta then
  515. return
  516. end
  517. local spos = pos.x .. "," .. pos.y .. "," ..pos.z
  518. local formspec = "size[8,9]"
  519. .. default.gui_bg
  520. .. default.gui_bg_img
  521. .. default.gui_slots
  522. .. "list[nodemeta:".. spos .. ";main;0,0.3;8,4;]"
  523. .. "button[0,4.5;2,0.25;toup;" .. F(S("To Chest")) .. "]"
  524. .. "field[2.3,4.8;4,0.25;chestname;;"
  525. .. meta:get_string("name") .. "]"
  526. .. "button[6,4.5;2,0.25;todn;" .. F(S("To Inventory")) .. "]"
  527. .. "list[current_player;main;0,5;8,1;]"
  528. .. "list[current_player;main;0,6.08;8,3;8]"
  529. .. "listring[nodemeta:" .. spos .. ";main]"
  530. .. "listring[current_player;main]"
  531. minetest.show_formspec(
  532. clicker:get_player_name(),
  533. "protector:chest_" .. minetest.pos_to_string(pos),
  534. formspec)
  535. end,
  536. on_blast = function() end,
  537. })
  538. -- Protected Chest formspec buttons
  539. minetest.register_on_player_receive_fields(function(player, formname, fields)
  540. if string.sub(formname, 0, string.len("protector:chest_")) ~= "protector:chest_" then
  541. return
  542. end
  543. local pos_s = string.sub(formname,string.len("protector:chest_") + 1)
  544. local pos = minetest.string_to_pos(pos_s)
  545. if minetest.is_protected(pos, player:get_player_name()) then
  546. return
  547. end
  548. local meta = minetest.get_meta(pos) ; if not meta then return end
  549. local chest_inv = meta:get_inventory() ; if not chest_inv then return end
  550. local player_inv = player:get_inventory()
  551. local leftover
  552. if fields.toup then
  553. -- copy contents of players inventory to chest
  554. for i, v in ipairs(player_inv:get_list("main") or {}) do
  555. if chest_inv:room_for_item("main", v) then
  556. leftover = chest_inv:add_item("main", v)
  557. player_inv:remove_item("main", v)
  558. if leftover
  559. and not leftover:is_empty() then
  560. player_inv:add_item("main", v)
  561. end
  562. end
  563. end
  564. elseif fields.todn then
  565. -- copy contents of chest to players inventory
  566. for i, v in ipairs(chest_inv:get_list("main") or {}) do
  567. if player_inv:room_for_item("main", v) then
  568. leftover = player_inv:add_item("main", v)
  569. chest_inv:remove_item("main", v)
  570. if leftover
  571. and not leftover:is_empty() then
  572. chest_inv:add_item("main", v)
  573. end
  574. end
  575. end
  576. elseif fields.chestname then
  577. -- change chest infotext to display name
  578. if fields.chestname ~= "" then
  579. meta:set_string("name", fields.chestname)
  580. meta:set_string("infotext",
  581. S("Protected Chest (@1)", fields.chestname))
  582. else
  583. meta:set_string("infotext", S("Protected Chest"))
  584. end
  585. end
  586. end)
  587. -- Protected Chest recipes
  588. if mcl then
  589. minetest.register_craft({
  590. output = "protector:chest",
  591. recipe = {
  592. {"mcl_chests:chest", "mcl_core:gold_ingot"},
  593. }
  594. })
  595. else
  596. minetest.register_craft({
  597. output = "protector:chest",
  598. recipe = {
  599. {"group:wood", "group:wood", "group:wood"},
  600. {"group:wood", "default:copper_ingot", "group:wood"},
  601. {"group:wood", "group:wood", "group:wood"},
  602. }
  603. })
  604. minetest.register_craft({
  605. output = "protector:chest",
  606. recipe = {
  607. {"default:chest", "default:copper_ingot"},
  608. }
  609. })
  610. end