init.lua 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. --[[
  2. Minetest Mod Storage Drawers - A Mod adding storage drawers
  3. Copyright (C) 2017-2020 Linus Jahn <lnj@kaidan.im>
  4. MIT License
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11. The above copyright notice and this permission notice shall be included in all
  12. copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  19. SOFTWARE.
  20. ]]
  21. -- Load support for intllib.
  22. local MP = core.get_modpath(core.get_current_modname())
  23. local S, NS = dofile(MP.."/intllib.lua")
  24. drawers = {}
  25. drawers.drawer_visuals = {}
  26. drawers.WOOD_ITEMSTRING = "group:wood"
  27. if core.get_modpath("default") and default then
  28. drawers.WOOD_SOUNDS = default.node_sound_wood_defaults()
  29. drawers.CHEST_ITEMSTRING = "default:chest"
  30. elseif core.get_modpath("mcl_core") and mcl_core then -- MineClone 2
  31. drawers.CHEST_ITEMSTRING = "mcl_chests:chest"
  32. if core.get_modpath("mcl_sounds") and mcl_sounds then
  33. drawers.WOOD_SOUNDS = mcl_sounds.node_sound_wood_defaults()
  34. end
  35. else
  36. drawers.CHEST_ITEMSTRING = "chest"
  37. end
  38. drawers.enable_1x1 = not core.settings:get_bool("drawers_disable_1x1")
  39. drawers.enable_1x2 = not core.settings:get_bool("drawers_disable_1x2")
  40. drawers.enable_2x2 = not core.settings:get_bool("drawers_disable_2x2")
  41. drawers.CONTROLLER_RANGE = 14
  42. --
  43. -- GUI
  44. --
  45. drawers.gui_bg = "bgcolor[#080808BB;true]"
  46. drawers.gui_slots = "listcolors[#00000069;#5A5A5A;#141318;#30434C;#FFF]"
  47. if (core.get_modpath("mcl_core")) and mcl_core then -- MCL2
  48. drawers.gui_bg_img = "background[5,5;1,1;crafting_creative_bg.png;true]"
  49. else
  50. drawers.gui_bg_img = "background[5,5;1,1;gui_formbg.png;true]"
  51. end
  52. --
  53. -- Load API
  54. --
  55. dofile(MP .. "/lua/helpers.lua")
  56. dofile(MP .. "/lua/visual.lua")
  57. dofile(MP .. "/lua/api.lua")
  58. dofile(MP .. "/lua/controller.lua")
  59. --
  60. -- Register drawers
  61. --
  62. if core.get_modpath("default") and default then
  63. drawers.register_drawer("drawers:wood", {
  64. description = S("Wooden"),
  65. tiles1 = drawers.node_tiles_front_other("drawers_wood_front_1.png",
  66. "drawers_wood.png"),
  67. tiles2 = drawers.node_tiles_front_other("drawers_wood_front_2.png",
  68. "drawers_wood.png"),
  69. tiles4 = drawers.node_tiles_front_other("drawers_wood_front_4.png",
  70. "drawers_wood.png"),
  71. groups = {choppy = 3, oddly_breakable_by_hand = 2},
  72. sounds = drawers.WOOD_SOUNDS,
  73. drawer_stack_max_factor = 4 * 8, -- normal chest size
  74. material = drawers.WOOD_ITEMSTRING
  75. })
  76. drawers.register_drawer("drawers:acacia_wood", {
  77. description = S("Acacia Wood"),
  78. tiles1 = drawers.node_tiles_front_other("drawers_acacia_wood_front_1.png",
  79. "drawers_acacia_wood.png"),
  80. tiles2 = drawers.node_tiles_front_other("drawers_acacia_wood_front_2.png",
  81. "drawers_acacia_wood.png"),
  82. tiles4 = drawers.node_tiles_front_other("drawers_acacia_wood_front_4.png",
  83. "drawers_acacia_wood.png"),
  84. groups = {choppy = 3, oddly_breakable_by_hand = 2},
  85. sounds = drawers.WOOD_SOUNDS,
  86. drawer_stack_max_factor = 4 * 8, -- normal mcl chest size
  87. material = "default:acacia_wood"
  88. })
  89. drawers.register_drawer("drawers:aspen_wood", {
  90. description = S("Aspen Wood"),
  91. tiles1 = drawers.node_tiles_front_other("drawers_aspen_wood_front_1.png",
  92. "drawers_aspen_wood.png"),
  93. tiles2 = drawers.node_tiles_front_other("drawers_aspen_wood_front_2.png",
  94. "drawers_aspen_wood.png"),
  95. tiles4 = drawers.node_tiles_front_other("drawers_aspen_wood_front_4.png",
  96. "drawers_aspen_wood.png"),
  97. groups = {choppy = 3, oddly_breakable_by_hand = 2},
  98. sounds = drawers.WOOD_SOUNDS,
  99. drawer_stack_max_factor = 4 * 8, -- normal chest size
  100. material = "default:aspen_wood"
  101. })
  102. drawers.register_drawer("drawers:junglewood", {
  103. description = S("Junglewood"),
  104. tiles1 = drawers.node_tiles_front_other("drawers_junglewood_front_1.png",
  105. "drawers_junglewood.png"),
  106. tiles2 = drawers.node_tiles_front_other("drawers_junglewood_front_2.png",
  107. "drawers_junglewood.png"),
  108. tiles4 = drawers.node_tiles_front_other("drawers_junglewood_front_4.png",
  109. "drawers_junglewood.png"),
  110. groups = {choppy = 3, oddly_breakable_by_hand = 2},
  111. sounds = drawers.WOOD_SOUNDS,
  112. drawer_stack_max_factor = 4 * 8, -- normal mcl chest size
  113. material = "default:junglewood"
  114. })
  115. drawers.register_drawer("drawers:pine_wood", {
  116. description = S("Pine Wood"),
  117. tiles1 = drawers.node_tiles_front_other("drawers_pine_wood_front_1.png",
  118. "drawers_pine_wood.png"),
  119. tiles2 = drawers.node_tiles_front_other("drawers_pine_wood_front_2.png",
  120. "drawers_pine_wood.png"),
  121. tiles4 = drawers.node_tiles_front_other("drawers_pine_wood_front_4.png",
  122. "drawers_pine_wood.png"),
  123. groups = {choppy = 3, oddly_breakable_by_hand = 2},
  124. sounds = drawers.WOOD_SOUNDS,
  125. drawer_stack_max_factor = 4 * 8, -- normal chest size
  126. material = "default:pine_wood"
  127. })
  128. elseif core.get_modpath("mcl_core") and mcl_core then
  129. drawers.register_drawer("drawers:oakwood", {
  130. description = S("Oak Wood"),
  131. tiles1 = drawers.node_tiles_front_other("drawers_oak_wood_front_1.png",
  132. "drawers_oak_wood.png"),
  133. tiles2 = drawers.node_tiles_front_other("drawers_oak_wood_front_2.png",
  134. "drawers_oak_wood.png"),
  135. tiles4 = drawers.node_tiles_front_other("drawers_oak_wood_front_4.png",
  136. "drawers_oak_wood.png"),
  137. groups = {handy = 1, axey = 1, flammable = 3, wood = 1, building_block = 1, material_wood = 1},
  138. sounds = drawers.WOOD_SOUNDS,
  139. drawer_stack_max_factor = 4 * 9, -- normal mcl chest size
  140. material = drawers.WOOD_ITEMSTRING,
  141. _mcl_blast_resistance = 15,
  142. _mcl_hardness = 2,
  143. })
  144. drawers.register_drawer("drawers:acaciawood", {
  145. description = S("Acacia Wood"),
  146. tiles1 = drawers.node_tiles_front_other("drawers_acacia_wood_mcl_front_1.png",
  147. "drawers_acacia_wood_mcl.png"),
  148. tiles2 = drawers.node_tiles_front_other("drawers_acacia_wood_mcl_front_2.png",
  149. "drawers_acacia_wood_mcl.png"),
  150. tiles4 = drawers.node_tiles_front_other("drawers_acacia_wood_mcl_front_4.png",
  151. "drawers_acacia_wood_mcl.png"),
  152. groups = {handy = 1, axey = 1, flammable = 3, wood = 1, building_block = 1, material_wood = 1},
  153. sounds = drawers.WOOD_SOUNDS,
  154. drawer_stack_max_factor = 4 * 9, -- normal mcl chest size
  155. material = "mcl_core:acaciawood",
  156. _mcl_blast_resistance = 15,
  157. _mcl_hardness = 2,
  158. })
  159. drawers.register_drawer("drawers:birchwood", {
  160. description = S("Birch Wood"),
  161. tiles1 = drawers.node_tiles_front_other("drawers_birch_wood_front_1.png",
  162. "drawers_birch_wood.png"),
  163. tiles2 = drawers.node_tiles_front_other("drawers_birch_wood_front_2.png",
  164. "drawers_birch_wood.png"),
  165. tiles4 = drawers.node_tiles_front_other("drawers_birch_wood_front_4.png",
  166. "drawers_birch_wood.png"),
  167. groups = {handy = 1, axey = 1, flammable = 3, wood = 1, building_block = 1, material_wood = 1},
  168. sounds = drawers.WOOD_SOUNDS,
  169. drawer_stack_max_factor = 4 * 9, -- normal mcl chest size
  170. material = "mcl_core:birchwood",
  171. _mcl_blast_resistance = 15,
  172. _mcl_hardness = 2,
  173. })
  174. drawers.register_drawer("drawers:darkwood", {
  175. description = S("Dark Oak Wood"),
  176. tiles1 = drawers.node_tiles_front_other("drawers_dark_oak_wood_front_1.png",
  177. "drawers_dark_oak_wood.png"),
  178. tiles2 = drawers.node_tiles_front_other("drawers_dark_oak_wood_front_2.png",
  179. "drawers_dark_oak_wood.png"),
  180. tiles4 = drawers.node_tiles_front_other("drawers_dark_oak_wood_front_4.png",
  181. "drawers_dark_oak_wood.png"),
  182. groups = {handy = 1, axey = 1, flammable = 3, wood = 1, building_block = 1, material_wood = 1},
  183. sounds = drawers.WOOD_SOUNDS,
  184. drawer_stack_max_factor = 4 * 9, -- normal mcl chest size
  185. material = "mcl_core:darkwood",
  186. _mcl_blast_resistance = 15,
  187. _mcl_hardness = 2,
  188. })
  189. drawers.register_drawer("drawers:junglewood", {
  190. description = S("Junglewood"),
  191. tiles1 = drawers.node_tiles_front_other("drawers_junglewood_mcl_front_1.png",
  192. "drawers_junglewood_mcl.png"),
  193. tiles2 = drawers.node_tiles_front_other("drawers_junglewood_mcl_front_2.png",
  194. "drawers_junglewood_mcl.png"),
  195. tiles4 = drawers.node_tiles_front_other("drawers_junglewood_mcl_front_4.png",
  196. "drawers_junglewood_mcl.png"),
  197. groups = {handy = 1, axey = 1, flammable = 3, wood = 1, building_block = 1, material_wood = 1},
  198. sounds = drawers.WOOD_SOUNDS,
  199. drawer_stack_max_factor = 4 * 9, -- normal mcl chest size
  200. material = "mcl_core:junglewood",
  201. _mcl_blast_resistance = 15,
  202. _mcl_hardness = 2,
  203. })
  204. drawers.register_drawer("drawers:sprucewood", {
  205. description = S("Spruce Wood"),
  206. tiles1 = drawers.node_tiles_front_other("drawers_spruce_wood_front_1.png",
  207. "drawers_spruce_wood.png"),
  208. tiles2 = drawers.node_tiles_front_other("drawers_spruce_wood_front_2.png",
  209. "drawers_spruce_wood.png"),
  210. tiles4 = drawers.node_tiles_front_other("drawers_spruce_wood_front_4.png",
  211. "drawers_spruce_wood.png"),
  212. groups = {handy = 1, axey = 1, flammable = 3, wood = 1, building_block = 1, material_wood = 1},
  213. sounds = drawers.WOOD_SOUNDS,
  214. drawer_stack_max_factor = 4 * 9, -- normal mcl chest size
  215. material = "mcl_core:sprucewood",
  216. _mcl_blast_resistance = 15,
  217. _mcl_hardness = 2,
  218. })
  219. -- backwards compatibility
  220. core.register_alias("drawers:wood1", "drawers:oakwood1")
  221. core.register_alias("drawers:wood2", "drawers:oakwood2")
  222. core.register_alias("drawers:wood4", "drawers:oakwood4")
  223. else
  224. drawers.register_drawer("drawers:wood", {
  225. description = S("Wooden"),
  226. tiles1 = drawers.node_tiles_front_other("drawers_wood_front_1.png",
  227. "drawers_wood.png"),
  228. tiles2 = drawers.node_tiles_front_other("drawers_wood_front_2.png",
  229. "drawers_wood.png"),
  230. tiles4 = drawers.node_tiles_front_other("drawers_wood_front_4.png",
  231. "drawers_wood.png"),
  232. groups = {choppy = 3, oddly_breakable_by_hand = 2},
  233. sounds = drawers.WOOD_SOUNDS,
  234. drawer_stack_max_factor = 4 * 8, -- normal chest size
  235. material = drawers.WOOD_ITEMSTRING
  236. })
  237. end
  238. --
  239. -- Register drawer upgrades
  240. --
  241. if core.get_modpath("default") and default then
  242. drawers.register_drawer_upgrade("drawers:upgrade_steel", {
  243. description = S("Steel Drawer Upgrade (x2)"),
  244. inventory_image = "drawers_upgrade_steel.png",
  245. groups = {drawer_upgrade = 100},
  246. recipe_item = "default:steel_ingot"
  247. })
  248. drawers.register_drawer_upgrade("drawers:upgrade_gold", {
  249. description = S("Gold Drawer Upgrade (x3)"),
  250. inventory_image = "drawers_upgrade_gold.png",
  251. groups = {drawer_upgrade = 200},
  252. recipe_item = "default:gold_ingot"
  253. })
  254. drawers.register_drawer_upgrade("drawers:upgrade_obsidian", {
  255. description = S("Obsidian Drawer Upgrade (x4)"),
  256. inventory_image = "drawers_upgrade_obsidian.png",
  257. groups = {drawer_upgrade = 300},
  258. recipe_item = "default:obsidian"
  259. })
  260. drawers.register_drawer_upgrade("drawers:upgrade_diamond", {
  261. description = S("Diamond Drawer Upgrade (x8)"),
  262. inventory_image = "drawers_upgrade_diamond.png",
  263. groups = {drawer_upgrade = 700},
  264. recipe_item = "default:diamond"
  265. })
  266. elseif core.get_modpath("mcl_core") and mcl_core then
  267. drawers.register_drawer_upgrade("drawers:upgrade_iron", {
  268. description = S("Iron Drawer Upgrade (x2)"),
  269. inventory_image = "drawers_upgrade_iron.png",
  270. groups = {drawer_upgrade = 100},
  271. recipe_item = "mcl_core:iron_ingot"
  272. })
  273. drawers.register_drawer_upgrade("drawers:upgrade_gold", {
  274. description = S("Gold Drawer Upgrade (x3)"),
  275. inventory_image = "drawers_upgrade_gold.png",
  276. groups = {drawer_upgrade = 200},
  277. recipe_item = "mcl_core:gold_ingot"
  278. })
  279. drawers.register_drawer_upgrade("drawers:upgrade_obsidian", {
  280. description = S("Obsidian Drawer Upgrade (x4)"),
  281. inventory_image = "drawers_upgrade_obsidian.png",
  282. groups = {drawer_upgrade = 300},
  283. recipe_item = "mcl_core:obsidian"
  284. })
  285. drawers.register_drawer_upgrade("drawers:upgrade_diamond", {
  286. description = S("Diamond Drawer Upgrade (x8)"),
  287. inventory_image = "drawers_upgrade_diamond.png",
  288. groups = {drawer_upgrade = 700},
  289. recipe_item = "mcl_core:diamond"
  290. })
  291. drawers.register_drawer_upgrade("drawers:upgrade_emerald", {
  292. description = S("Emerald Drawer Upgrade (x13)"),
  293. inventory_image = "drawers_upgrade_emerald.png",
  294. groups = {drawer_upgrade = 1200},
  295. recipe_item = "mcl_core:emerald"
  296. })
  297. end
  298. if core.get_modpath("moreores") then
  299. drawers.register_drawer_upgrade("drawers:upgrade_mithril", {
  300. description = S("Mithril Drawer Upgrade (x13)"),
  301. inventory_image = "drawers_upgrade_mithril.png",
  302. groups = {drawer_upgrade = 1200},
  303. recipe_item = "moreores:mithril_ingot"
  304. })
  305. end
  306. --
  307. -- Register drawer trim
  308. --
  309. if core.get_modpath("mcl_core") and mcl_core then
  310. core.register_node("drawers:trim", {
  311. description = S("Wooden Trim"),
  312. tiles = {"drawers_trim.png"},
  313. groups = {drawer_connector = 1, handy = 1, axey = 1, flammable = 3, wood = 1, building_block = 1, material_wood = 1},
  314. _mcl_blast_resistance = 15,
  315. _mcl_hardness = 2,
  316. })
  317. else
  318. core.register_node("drawers:trim", {
  319. description = S("Wooden Trim"),
  320. tiles = {"drawers_trim.png"},
  321. groups = {drawer_connector = 1, choppy = 3, oddly_breakable_by_hand = 2},
  322. })
  323. end
  324. core.register_craft({
  325. output = "drawers:trim 6",
  326. recipe = {
  327. {"group:stick", "group:wood", "group:stick"},
  328. {"group:wood", "group:wood", "group:wood"},
  329. {"group:stick", "group:wood", "group:stick"}
  330. }
  331. })
  332. --
  333. -- Register drawer upgrade template
  334. --
  335. core.register_craftitem("drawers:upgrade_template", {
  336. description = S("Drawer Upgrade Template"),
  337. inventory_image = "drawers_upgrade_template.png"
  338. })
  339. core.register_craft({
  340. output = "drawers:upgrade_template 4",
  341. recipe = {
  342. {"group:stick", "group:stick", "group:stick"},
  343. {"group:stick", "group:drawer", "group:stick"},
  344. {"group:stick", "group:stick", "group:stick"}
  345. }
  346. })