storage.lua 16 KB

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