storage.lua 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. minetest.register_node('furniture:chest_small', {
  2. _doc_items_crafting = 'This is crafted in the Woodworking Station.',
  3. description = 'Small Chest',
  4. drawtype = 'mesh',
  5. mesh = 'furniture_chest_small.obj',
  6. tiles = {'furniture_chest_small.png'},
  7. overlay_tiles = {{name='furniture_chest_small_overlay.png', color='white'}},
  8. paramtype = 'light',
  9. paramtype2 = 'colorfacedir',
  10. palette = 'furniture_stain_palette.png',
  11. selection_box = {
  12. type = 'fixed',
  13. fixed = {-.4, -.5, -.3, .4, .2, .4},
  14. },
  15. collision_box = {
  16. type = 'fixed',
  17. fixed = {-.4, -.5, -.3, .4, .2, .4},
  18. },
  19. groups = {oddly_breakable_by_hand = 2, choppy=3, stainable=1},
  20. on_construct = function(pos)
  21. local meta = minetest.get_meta(pos)
  22. meta:set_string('formspec', furniture.storage_24_form(pos, ''))
  23. local inv = meta:get_inventory()
  24. inv:set_size('main', 24)
  25. end,
  26. can_dig = function(pos,player)
  27. local meta = minetest.get_meta(pos)
  28. local inv = meta:get_inventory()
  29. return inv:is_empty('main')
  30. end,
  31. on_receive_fields = function(pos, formname, fields, sender)
  32. local player_name = sender:get_player_name()
  33. if minetest.is_protected(pos, player_name) and not minetest.check_player_privs(sender, 'protection_bypass') then
  34. return
  35. end
  36. local meta = minetest.get_meta(pos)
  37. if fields ['save'] then
  38. meta:set_string('infotext', fields.description)
  39. meta:set_string('formspec', furniture.storage_24_form(pos, fields.description))
  40. elseif fields ['sort'] then
  41. furniture.sort_inventory(meta:get_inventory())
  42. end
  43. end,
  44. allow_metadata_inventory_put = furniture.inv_take_put,
  45. allow_metadata_inventory_take = furniture.inv_take_put,
  46. allow_metadata_inventory_move = furniture.inv_manipulate,
  47. on_metadata_inventory_put = furniture.inv_put,
  48. on_metadata_inventory_take = furniture.inv_take,
  49. })
  50. minetest.register_node('furniture:chest', {
  51. _doc_items_crafting = 'This is crafted in the Woodworking Station.',
  52. description = 'Chest',
  53. drawtype = 'mesh',
  54. mesh = 'furniture_chest.obj',
  55. tiles = {'furniture_chest.png'},
  56. overlay_tiles = {{name='furniture_chest_overlay.png', color='white'}},
  57. paramtype = 'light',
  58. paramtype2 = 'colorfacedir',
  59. palette = 'furniture_stain_palette.png',
  60. selection_box = {
  61. type = 'fixed',
  62. fixed = {-.45, -.5, -.4, .45, .4, .5},
  63. },
  64. collision_box = {
  65. type = 'fixed',
  66. fixed = {-.45, -.5, -.4, .45, .4, .5},
  67. },
  68. groups = {oddly_breakable_by_hand = 2, choppy=3, stainable=1},
  69. on_construct = function(pos)
  70. local meta = minetest.get_meta(pos)
  71. meta:set_string('formspec', furniture.storage_32_form(pos, ''))
  72. local inv = meta:get_inventory()
  73. inv:set_size('main', 32)
  74. end,
  75. can_dig = function(pos,player)
  76. local meta = minetest.get_meta(pos)
  77. local inv = meta:get_inventory()
  78. return inv:is_empty('main')
  79. end,
  80. on_receive_fields = function(pos, formname, fields, sender)
  81. local player_name = sender:get_player_name()
  82. if minetest.is_protected(pos, player_name) and not minetest.check_player_privs(sender, 'protection_bypass') then
  83. return
  84. end
  85. local meta = minetest.get_meta(pos)
  86. if fields ['save'] then
  87. meta:set_string('infotext', fields.description)
  88. meta:set_string('formspec', furniture.storage_32_form(pos, fields.description))
  89. elseif fields ['sort'] then
  90. furniture.sort_inventory(meta:get_inventory())
  91. end
  92. end,
  93. allow_metadata_inventory_put = furniture.inv_take_put,
  94. allow_metadata_inventory_take = furniture.inv_take_put,
  95. allow_metadata_inventory_move = furniture.inv_manipulate,
  96. on_metadata_inventory_put = furniture.inv_put,
  97. on_metadata_inventory_take = furniture.inv_take,
  98. })
  99. minetest.register_node('furniture:chest_large', {
  100. _doc_items_crafting = 'This is crafted in the Woodworking Station.',
  101. description = 'Large Chest',
  102. drawtype = 'mesh',
  103. mesh = 'furniture_chest_large.obj',
  104. tiles = {'furniture_chest_large.png'},
  105. overlay_tiles = {{name='furniture_chest_large_overlay.png', color='white'}},
  106. paramtype = 'light',
  107. paramtype2 = 'colorfacedir',
  108. palette = 'furniture_stain_palette.png',
  109. selection_box = {
  110. type = 'fixed',
  111. fixed = {-.5, -.5, -.4, 1.5, .3, .5},
  112. },
  113. collision_box = {
  114. type = 'fixed',
  115. fixed = {-.5, -.5, -.4, 1.5, .3, .5},
  116. },
  117. groups = {oddly_breakable_by_hand = 2, choppy=3, stainable=1},
  118. after_place_node = function(pos, placer, itemstack)
  119. if not epic.space_to_side(pos) then
  120. minetest.remove_node(pos)
  121. return itemstack
  122. end
  123. end,
  124. on_construct = function(pos)
  125. local meta = minetest.get_meta(pos)
  126. meta:set_string('formspec', furniture.storage_60_form(pos, ''))
  127. local inv = meta:get_inventory()
  128. inv:set_size('main', 60)
  129. end,
  130. after_dig_node = function(pos, oldnode, oldmetadata, digger)
  131. epic.remove_side_node(pos, oldnode)
  132. end,
  133. can_dig = function(pos,player)
  134. local meta = minetest.get_meta(pos)
  135. local inv = meta:get_inventory()
  136. return inv:is_empty('main')
  137. end,
  138. on_receive_fields = function(pos, formname, fields, sender)
  139. local player_name = sender:get_player_name()
  140. if minetest.is_protected(pos, player_name) and not minetest.check_player_privs(sender, 'protection_bypass') then
  141. return
  142. end
  143. local meta = minetest.get_meta(pos)
  144. if fields ['save'] then
  145. meta:set_string('infotext', fields.description)
  146. meta:set_string('formspec', furniture.storage_60_form(pos, fields.description))
  147. elseif fields ['sort'] then
  148. furniture.sort_inventory(meta:get_inventory())
  149. end
  150. end,
  151. on_rotate = function(pos, node)
  152. return false
  153. end,
  154. allow_metadata_inventory_put = furniture.inv_take_put,
  155. allow_metadata_inventory_take = furniture.inv_take_put,
  156. allow_metadata_inventory_move = furniture.inv_manipulate,
  157. on_metadata_inventory_put = furniture.inv_put,
  158. on_metadata_inventory_take = furniture.inv_take,
  159. })
  160. minetest.register_node('furniture:cabinet_wall', {
  161. _doc_items_crafting = 'This is crafted in the Woodworking Station.',
  162. description = 'Wall Mounted Cabinet',
  163. drawtype = 'mesh',
  164. mesh = 'furniture_cabinet_wall.obj',
  165. tiles = {'furniture_cabinet_wall.png'},
  166. paramtype = 'light',
  167. paramtype2 = 'colorfacedir',
  168. palette = 'furniture_stain_palette.png',
  169. selection_box = {
  170. type = 'fixed',
  171. fixed = {-.5, -.5, -.3, .5, .5, .5},
  172. },
  173. collision_box = {
  174. type = 'fixed',
  175. fixed = {-.5, -.5, -.3, .5, .5, .5},
  176. },
  177. groups = {oddly_breakable_by_hand = 2, choppy=3, stainable=1},
  178. on_construct = function(pos)
  179. local meta = minetest.get_meta(pos)
  180. meta:set_string('formspec', furniture.storage_24_form(pos, ''))
  181. local inv = meta:get_inventory()
  182. inv:set_size('main', 24)
  183. end,
  184. can_dig = function(pos,player)
  185. local meta = minetest.get_meta(pos)
  186. local inv = meta:get_inventory()
  187. return inv:is_empty('main')
  188. end,
  189. on_receive_fields = function(pos, formname, fields, sender)
  190. local player_name = sender:get_player_name()
  191. if minetest.is_protected(pos, player_name) and not minetest.check_player_privs(sender, 'protection_bypass') then
  192. return
  193. end
  194. local meta = minetest.get_meta(pos)
  195. if fields ['save'] then
  196. meta:set_string('infotext', fields.description)
  197. meta:set_string('formspec', furniture.storage_24_form(pos, fields.description))
  198. elseif fields ['sort'] then
  199. furniture.sort_inventory(meta:get_inventory())
  200. end
  201. end,
  202. allow_metadata_inventory_put = furniture.inv_take_put,
  203. allow_metadata_inventory_take = furniture.inv_take_put,
  204. allow_metadata_inventory_move = furniture.inv_manipulate,
  205. on_metadata_inventory_put = furniture.inv_put,
  206. on_metadata_inventory_take = furniture.inv_take,
  207. })
  208. minetest.register_node('furniture:cabinet_counter', {
  209. _doc_items_crafting = 'This is crafted in the Woodworking Station.',
  210. description = 'Cabinet with Countertop',
  211. drawtype = 'mesh',
  212. mesh = 'furniture_cabinet_counter.obj',
  213. tiles = {'furniture_cabinet_counter.png'},
  214. paramtype = 'light',
  215. paramtype2 = 'colorfacedir',
  216. palette = 'furniture_stain_palette.png',
  217. selection_box = {
  218. type = 'fixed',
  219. fixed = {-.5, -.5, -.5, .5, .5, .5},
  220. },
  221. collision_box = {
  222. type = 'fixed',
  223. fixed = {-.5, -.5, -.5, .5, .5, .5},
  224. },
  225. groups = {oddly_breakable_by_hand = 2, choppy=3, stainable=1},
  226. on_construct = function(pos)
  227. local meta = minetest.get_meta(pos)
  228. meta:set_string('formspec', furniture.storage_24_form(pos, ''))
  229. local inv = meta:get_inventory()
  230. inv:set_size('main', 24)
  231. end,
  232. can_dig = function(pos,player)
  233. local meta = minetest.get_meta(pos)
  234. local inv = meta:get_inventory()
  235. return inv:is_empty('main')
  236. end,
  237. on_receive_fields = function(pos, formname, fields, sender)
  238. local player_name = sender:get_player_name()
  239. if minetest.is_protected(pos, player_name) and not minetest.check_player_privs(sender, 'protection_bypass') then
  240. return
  241. end
  242. local meta = minetest.get_meta(pos)
  243. if fields ['save'] then
  244. meta:set_string('infotext', fields.description)
  245. meta:set_string('formspec', furniture.storage_24_form(pos, fields.description))
  246. elseif fields ['sort'] then
  247. furniture.sort_inventory(meta:get_inventory())
  248. end
  249. end,
  250. allow_metadata_inventory_put = furniture.inv_take_put,
  251. allow_metadata_inventory_take = furniture.inv_take_put,
  252. allow_metadata_inventory_move = furniture.inv_manipulate,
  253. on_metadata_inventory_put = furniture.inv_put,
  254. on_metadata_inventory_take = furniture.inv_take,
  255. })
  256. local bookshelf_formspec =
  257. "size[8,7;]" ..
  258. "list[context;books;0,0.3;8,2;]" ..
  259. "list[current_player;main;0,2.85;8,1;]" ..
  260. "list[current_player;main;0,4.08;8,3;8]" ..
  261. "listring[context;books]" ..
  262. "listring[current_player;main]" ..
  263. default.get_hotbar_bg(0,2.85)
  264. local function update_bookshelf(pos)
  265. local meta = minetest.get_meta(pos)
  266. local inv = meta:get_inventory()
  267. local invlist = inv:get_list("books")
  268. local formspec = bookshelf_formspec
  269. -- Inventory slots overlay
  270. local bx, by = 0, 0.3
  271. local n_written, n_empty = 0, 0
  272. for i = 1, 16 do
  273. if i == 9 then
  274. bx = 0
  275. by = by + 1
  276. end
  277. local stack = invlist[i]
  278. if stack:is_empty() then
  279. formspec = formspec ..
  280. "image[" .. bx .. "," .. by .. ";1,1;default_bookshelf_slot.png]"
  281. else
  282. local metatable = stack:get_meta():to_table() or {}
  283. if metatable.fields and metatable.fields.text then
  284. n_written = n_written + stack:get_count()
  285. else
  286. n_empty = n_empty + stack:get_count()
  287. end
  288. end
  289. bx = bx + 1
  290. end
  291. meta:set_string("formspec", formspec)
  292. if n_written + n_empty == 0 then
  293. meta:set_string("infotext", "Empty Locked Bookshelf")
  294. else
  295. meta:set_string("infotext", "Locked Bookshelf ("..n_written.." written, "..n_empty.." empty books)")
  296. end
  297. end
  298. minetest.register_node("furniture:bookshelf_locked", {
  299. description = 'Locked Bookshelf',
  300. tiles = {"default_wood.png", "default_wood.png", "default_wood.png",
  301. "default_wood.png", "default_bookshelf.png", "default_bookshelf.png"},
  302. paramtype2 = "facedir",
  303. is_ground_content = false,
  304. groups = {choppy = 3, oddly_breakable_by_hand = 2, flammable = 3},
  305. sounds = default.node_sound_wood_defaults(),
  306. on_construct = function(pos)
  307. local meta = minetest.get_meta(pos)
  308. local inv = meta:get_inventory()
  309. inv:set_size("books", 8 * 2)
  310. update_bookshelf(pos)
  311. end,
  312. can_dig = function(pos,player)
  313. local inv = minetest.get_meta(pos):get_inventory()
  314. return inv:is_empty("books")
  315. end,
  316. allow_metadata_inventory_put = function(pos, listname, index, stack, player)
  317. local player_name = player:get_player_name()
  318. if minetest.is_protected(pos, player_name) and not minetest.check_player_privs(player, 'protection_bypass') then
  319. return 0
  320. else
  321. if minetest.get_item_group(stack:get_name(), "book") ~= 0 then
  322. return stack:get_count()
  323. else
  324. return 0
  325. end
  326. end
  327. end,
  328. allow_metadata_inventory_take = furniture.inv_take_put,
  329. allow_metadata_inventory_move = furniture.inv_manipulate,
  330. on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
  331. minetest.log("action", player:get_player_name() ..
  332. " moves stuff in bookshelf at " .. minetest.pos_to_string(pos))
  333. update_bookshelf(pos)
  334. end,
  335. on_metadata_inventory_put = function(pos, listname, index, stack, player)
  336. minetest.log("action", player:get_player_name() ..
  337. " puts stuff to bookshelf at " .. minetest.pos_to_string(pos))
  338. update_bookshelf(pos)
  339. end,
  340. on_metadata_inventory_take = function(pos, listname, index, stack, player)
  341. minetest.log("action", player:get_player_name() ..
  342. " takes stuff from bookshelf at " .. minetest.pos_to_string(pos))
  343. update_bookshelf(pos)
  344. end,
  345. on_blast = function(pos)
  346. local drops = {}
  347. default.get_inventory_drops(pos, "books", drops)
  348. drops[#drops+1] = "furniture:bookshelf_locked"
  349. minetest.remove_node(pos)
  350. return drops
  351. end,
  352. })
  353. local vessels_shelf_formspec =
  354. "size[8,7;]" ..
  355. "list[context;vessels;0,0.3;8,2;]" ..
  356. "list[current_player;main;0,2.85;8,1;]" ..
  357. "list[current_player;main;0,4.08;8,3;8]" ..
  358. "listring[context;vessels]" ..
  359. "listring[current_player;main]" ..
  360. default.get_hotbar_bg(0, 2.85)
  361. local function update_vessels_shelf(pos)
  362. local meta = minetest.get_meta(pos)
  363. local inv = meta:get_inventory()
  364. local invlist = inv:get_list("vessels")
  365. local formspec = vessels_shelf_formspec
  366. -- Inventory slots overlay
  367. local vx, vy = 0, 0.3
  368. local n_items = 0
  369. for i = 1, 16 do
  370. if i == 9 then
  371. vx = 0
  372. vy = vy + 1
  373. end
  374. if not invlist or invlist[i]:is_empty() then
  375. formspec = formspec ..
  376. "image[" .. vx .. "," .. vy .. ";1,1;vessels_shelf_slot.png]"
  377. else
  378. local stack = invlist[i]
  379. if not stack:is_empty() then
  380. n_items = n_items + stack:get_count()
  381. end
  382. end
  383. vx = vx + 1
  384. end
  385. meta:set_string("formspec", formspec)
  386. if n_items == 0 then
  387. meta:set_string("infotext", "Empty Locked Vessels Shelf")
  388. else
  389. meta:set_string("infotext", "Locked Vessels Shelf ("..n_items.." items)")
  390. end
  391. end
  392. minetest.register_node("furniture:shelf_vessel_locked", {
  393. description = "Locked Vessels Shelf",
  394. tiles = {"default_wood.png", "default_wood.png", "default_wood.png",
  395. "default_wood.png", "vessels_shelf.png", "vessels_shelf.png"},
  396. paramtype2 = "facedir",
  397. is_ground_content = false,
  398. groups = {choppy = 3, oddly_breakable_by_hand = 2, flammable = 3},
  399. sounds = default.node_sound_wood_defaults(),
  400. on_construct = function(pos)
  401. local meta = minetest.get_meta(pos)
  402. update_vessels_shelf(pos)
  403. local inv = meta:get_inventory()
  404. inv:set_size("vessels", 8 * 2)
  405. end,
  406. can_dig = function(pos,player)
  407. local inv = minetest.get_meta(pos):get_inventory()
  408. return inv:is_empty("vessels")
  409. end,
  410. allow_metadata_inventory_take = furniture.inv_take_put,
  411. allow_metadata_inventory_move = furniture.inv_manipulate,
  412. allow_metadata_inventory_put = function(pos, listname, index, stack, player)
  413. local player_name = player:get_player_name()
  414. if minetest.is_protected(pos, player_name) and not minetest.check_player_privs(player, 'protection_bypass') then
  415. return 0
  416. else
  417. if minetest.get_item_group(stack:get_name(), "vessel") ~= 0 then
  418. return stack:get_count()
  419. else
  420. return 0
  421. end
  422. end
  423. end,
  424. on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
  425. minetest.log("action", player:get_player_name() ..
  426. " moves stuff in vessels shelf at ".. minetest.pos_to_string(pos))
  427. update_vessels_shelf(pos)
  428. end,
  429. on_metadata_inventory_put = function(pos, listname, index, stack, player)
  430. minetest.log("action", player:get_player_name() ..
  431. " moves stuff to vessels shelf at ".. minetest.pos_to_string(pos))
  432. update_vessels_shelf(pos)
  433. end,
  434. on_metadata_inventory_take = function(pos, listname, index, stack, player)
  435. minetest.log("action", player:get_player_name() ..
  436. " takes stuff from vessels shelf at ".. minetest.pos_to_string(pos))
  437. update_vessels_shelf(pos)
  438. end,
  439. on_blast = function(pos)
  440. local drops = {}
  441. default.get_inventory_drops(pos, "vessels", drops)
  442. drops[#drops + 1] = "vessels:shelf"
  443. minetest.remove_node(pos)
  444. return drops
  445. end,
  446. })
  447. minetest.register_node("furniture:multishelf_locked", {
  448. description = "Locked Multishelf",
  449. tiles = {
  450. "default_wood.png", "default_wood.png", "default_wood.png",
  451. "default_wood.png", "default_wood.png^xdecor_multishelf.png"},
  452. paramtype2 = "facedir",
  453. is_ground_content = false,
  454. groups = {choppy = 3, oddly_breakable_by_hand = 2, flammable = 3},
  455. sounds = default.node_sound_wood_defaults(),
  456. on_construct = function(pos)
  457. local meta = minetest.get_meta(pos)
  458. update_vessels_shelf(pos)
  459. local inv = meta:get_inventory()
  460. inv:set_size("vessels", 8 * 2)
  461. end,
  462. can_dig = function(pos,player)
  463. local inv = minetest.get_meta(pos):get_inventory()
  464. return inv:is_empty("vessels")
  465. end,
  466. allow_metadata_inventory_take = furniture.inv_take_put,
  467. allow_metadata_inventory_move = furniture.inv_manipulate,
  468. allow_metadata_inventory_put = function(pos, listname, index, stack, player)
  469. local player_name = player:get_player_name()
  470. if minetest.is_protected(pos, player_name) and not minetest.check_player_privs(player, 'protection_bypass') then
  471. return 0
  472. else return stack:get_count()
  473. end
  474. end,
  475. on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
  476. minetest.log("action", player:get_player_name() ..
  477. " moves stuff in multi shelf at ".. minetest.pos_to_string(pos))
  478. end,
  479. on_metadata_inventory_put = function(pos, listname, index, stack, player)
  480. minetest.log("action", player:get_player_name() ..
  481. " moves stuff to multi shelf at ".. minetest.pos_to_string(pos))
  482. end,
  483. on_metadata_inventory_take = function(pos, listname, index, stack, player)
  484. minetest.log("action", player:get_player_name() ..
  485. " takes stuff from multi shelf at ".. minetest.pos_to_string(pos))
  486. end,
  487. on_blast = function(pos)
  488. local drops = {}
  489. default.get_inventory_drops(pos, "vessels", drops)
  490. drops[#drops + 1] = "vessels:shelf"
  491. minetest.remove_node(pos)
  492. return drops
  493. end,
  494. })