init.lua 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. local S = minetest.get_translator("homedecor_bedroom")
  2. local sc_disallow = minetest.get_modpath("screwdriver") and screwdriver.disallow or nil
  3. local bed_sbox = {
  4. type = "wallmounted",
  5. wall_side = { -0.5, -0.5, -0.5, 0.5, 0.5, 1.5 }
  6. }
  7. local bed_cbox = {
  8. type = "wallmounted",
  9. wall_side = {
  10. { -0.5, -0.5, -0.5, 0.5, -0.05, 1.5 },
  11. { -0.5, -0.5, 1.44, 0.5, 0.5, 1.5 },
  12. { -0.5, -0.5, -0.5, 0.5, 0.18, -0.44 },
  13. }
  14. }
  15. local kbed_sbox = {
  16. type = "wallmounted",
  17. wall_side = { -0.5, -0.5, -0.5, 1.5, 0.5, 1.5 }
  18. }
  19. local kbed_cbox = {
  20. type = "wallmounted",
  21. wall_side = {
  22. { -0.5, -0.5, -0.5, 1.5, -0.05, 1.5 },
  23. { -0.5, -0.5, 1.44, 1.5, 0.5, 1.5 },
  24. { -0.5, -0.5, -0.5, 1.5, 0.18, -0.44 },
  25. }
  26. }
  27. -- local bed_on_rightclick = minetest.registered_nodes["beds:bed"].on_rightclick
  28. homedecor.register("bed_regular", {
  29. mesh = "homedecor_bed_regular.obj",
  30. tiles = {
  31. { name = "homedecor_bed_frame.png", color = 0xffffffff },
  32. { name = "default_wood.png", color = 0xffffffff },
  33. { name = "wool_white.png", color = 0xffffffff },
  34. "wool_white.png",
  35. { name = "homedecor_bed_bottom.png", color = 0xffffffff },
  36. "wool_white.png^[brighten", -- pillow
  37. },
  38. inventory_image = "homedecor_bed_inv.png",
  39. paramtype2 = "colorwallmounted",
  40. palette = "unifieddyes_palette_colorwallmounted.png",
  41. description = S("Bed"),
  42. groups = {snappy=3, ud_param2_colorable = 1},
  43. selection_box = bed_sbox,
  44. node_box = bed_cbox,
  45. sounds = default.node_sound_wood_defaults(),
  46. on_rotate = sc_disallow or nil,
  47. after_place_node = function(pos, placer, itemstack, pointed_thing)
  48. unifieddyes.fix_rotation_nsew(pos, placer, itemstack, pointed_thing)
  49. if not placer:get_player_control().sneak then
  50. return homedecor.bed_expansion(pos, placer, itemstack, pointed_thing)
  51. end
  52. end,
  53. after_dig_node = function(pos, oldnode, oldmetadata, digger)
  54. homedecor.unextend_bed(pos)
  55. end,
  56. on_dig = unifieddyes.on_dig,
  57. on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
  58. local itemname = itemstack:get_name()
  59. if itemname == "homedecor:bed_regular" then
  60. homedecor.bed_expansion(pos, clicker, itemstack, pointed_thing, true)
  61. return itemstack
  62. -- else
  63. -- bed_on_rightclick(pos, node, clicker)
  64. -- return itemstack
  65. end
  66. end
  67. })
  68. homedecor.register("bed_extended", {
  69. mesh = "homedecor_bed_extended.obj",
  70. tiles = {
  71. { name = "homedecor_bed_frame.png", color = 0xffffffff },
  72. { name = "default_wood.png", color = 0xffffffff },
  73. { name = "wool_white.png", color = 0xffffffff },
  74. "wool_white.png",
  75. { name = "homedecor_bed_bottom.png", color = 0xffffffff },
  76. "wool_white.png^[brighten",
  77. },
  78. paramtype2 = "colorwallmounted",
  79. palette = "unifieddyes_palette_colorwallmounted.png",
  80. selection_box = bed_sbox,
  81. node_box = bed_cbox,
  82. groups = {snappy=3, ud_param2_colorable = 1},
  83. sounds = default.node_sound_wood_defaults(),
  84. expand = { forward = "air" },
  85. on_rotate = sc_disallow or nil,
  86. after_dig_node = function(pos, oldnode, oldmetadata, digger)
  87. homedecor.unextend_bed(pos)
  88. end,
  89. on_dig = unifieddyes.on_dig,
  90. -- on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
  91. -- bed_on_rightclick(pos, node, clicker)
  92. -- return itemstack
  93. -- end,
  94. drop = "homedecor:bed_regular"
  95. })
  96. homedecor.register("bed_kingsize", {
  97. mesh = "homedecor_bed_kingsize.obj",
  98. tiles = {
  99. { name = "homedecor_bed_frame.png", color = 0xffffffff },
  100. { name = "default_wood.png", color = 0xffffffff },
  101. { name = "wool_white.png", color = 0xffffffff },
  102. "wool_white.png",
  103. { name = "homedecor_bed_bottom.png", color = 0xffffffff },
  104. "wool_white.png^[brighten",
  105. },
  106. paramtype2 = "colorwallmounted",
  107. palette = "unifieddyes_palette_colorwallmounted.png",
  108. inventory_image = "homedecor_bed_kingsize_inv.png",
  109. description = S("Bed (king sized)"),
  110. groups = {snappy=3, ud_param2_colorable = 1},
  111. selection_box = kbed_sbox,
  112. node_box = kbed_cbox,
  113. sounds = default.node_sound_wood_defaults(),
  114. on_rotate = sc_disallow or nil,
  115. after_place_node = function(pos, placer, itemstack, pointed_thing)
  116. unifieddyes.fix_rotation_nsew(pos, placer, itemstack, pointed_thing)
  117. end,
  118. after_dig_node = function(pos, oldnode, oldmetadata, digger)
  119. local inv = digger:get_inventory()
  120. if digger:get_player_control().sneak and inv:room_for_item("main", "homedecor:bed_regular 2") then
  121. inv:remove_item("main", "homedecor:bed_kingsize 1")
  122. inv:add_item("main", "homedecor:bed_regular 2")
  123. end
  124. end,
  125. on_dig = unifieddyes.on_dig,
  126. -- on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
  127. -- bed_on_rightclick(pos, node, clicker)
  128. -- return itemstack
  129. -- end,
  130. })
  131. for w, d in pairs({ ["mahogany"] = S("mahogany"), ["oak"] = S("oak") }) do
  132. homedecor.register("nightstand_"..w.."_one_drawer", {
  133. description = S("Nightstand with One Drawer (@1)", d),
  134. tiles = { 'homedecor_nightstand_'..w..'_tb.png',
  135. 'homedecor_nightstand_'..w..'_tb.png^[transformFY',
  136. 'homedecor_nightstand_'..w..'_lr.png^[transformFX',
  137. 'homedecor_nightstand_'..w..'_lr.png',
  138. 'homedecor_nightstand_'..w..'_back.png',
  139. 'homedecor_nightstand_'..w..'_1_drawer_front.png'},
  140. node_box = {
  141. type = "fixed",
  142. fixed = {
  143. { -8/16, 0, -30/64, 8/16, 8/16, 8/16 }, -- top half
  144. { -7/16, 1/16, -32/64, 7/16, 7/16, -29/64}, -- drawer face
  145. { -8/16, -8/16, -30/64, -7/16, 0, 8/16 }, -- left
  146. { 7/16, -8/16, -30/64, 8/16, 0, 8/16 }, -- right
  147. { -8/16, -8/16, 7/16, 8/16, 0, 8/16 }, -- back
  148. { -8/16, -8/16, -30/64, 8/16, -7/16, 8/16 } -- bottom
  149. }
  150. },
  151. groups = { snappy = 3 },
  152. sounds = default.node_sound_wood_defaults(),
  153. selection_box = { type = "regular" },
  154. infotext=S("One-drawer Nightstand"),
  155. inventory = {
  156. size=8,
  157. lockable=true,
  158. },
  159. })
  160. homedecor.register("nightstand_"..w.."_two_drawers", {
  161. description = S("Nightstand with Two Drawers (@1)", d),
  162. tiles = { 'homedecor_nightstand_'..w..'_tb.png',
  163. 'homedecor_nightstand_'..w..'_tb.png^[transformFY',
  164. 'homedecor_nightstand_'..w..'_lr.png^[transformFX',
  165. 'homedecor_nightstand_'..w..'_lr.png',
  166. 'homedecor_nightstand_'..w..'_back.png',
  167. 'homedecor_nightstand_'..w..'_2_drawer_front.png'},
  168. node_box = {
  169. type = "fixed",
  170. fixed = {
  171. { -8/16, -8/16, -30/64, 8/16, 8/16, 8/16 }, -- main body
  172. { -7/16, 1/16, -32/64, 7/16, 7/16, -29/64 }, -- top drawer face
  173. { -7/16, -7/16, -32/64, 7/16, -1/16, -29/64 }, -- bottom drawer face
  174. }
  175. },
  176. groups = { snappy = 3 },
  177. sounds = default.node_sound_wood_defaults(),
  178. selection_box = { type = "regular" },
  179. infotext=S("Two-drawer Nightstand"),
  180. inventory = {
  181. size=16,
  182. lockable=true,
  183. },
  184. })
  185. end
  186. -- convert to param2 colorization
  187. local bedcolors = {
  188. "black",
  189. "brown",
  190. "blue",
  191. "cyan",
  192. "darkgrey",
  193. "dark_green",
  194. "green",
  195. "grey",
  196. "magenta",
  197. "orange",
  198. "pink",
  199. "red",
  200. "violet",
  201. "white",
  202. "yellow"
  203. }
  204. local old_bed_nodes = {}
  205. for _, color in ipairs(bedcolors) do
  206. table.insert(old_bed_nodes, "homedecor:bed_"..color.."_regular")
  207. table.insert(old_bed_nodes, "homedecor:bed_"..color.."_extended")
  208. table.insert(old_bed_nodes, "homedecor:bed_"..color.."_kingsize")
  209. end
  210. minetest.register_lbm({
  211. name = ":homedecor:convert_beds",
  212. label = "Convert homedecor static bed nodes to use param2 color",
  213. run_at_every_load = false,
  214. nodenames = old_bed_nodes,
  215. action = function(pos, node)
  216. local name = node.name
  217. local color = string.sub(name, string.find(name, "_") + 1)
  218. -- -10 puts us near the end of the color field
  219. color = string.sub(color, 1, string.find(color, "_", -10) - 1)
  220. if color == "darkgrey" then
  221. color = "dark_grey"
  222. end
  223. local paletteidx = unifieddyes.getpaletteidx("unifieddyes:"..color, "wallmounted")
  224. local old_fdir = math.floor(node.param2 % 32)
  225. local new_fdir = 3
  226. local new_name
  227. if old_fdir == 0 then
  228. new_fdir = 3
  229. elseif old_fdir == 1 then
  230. new_fdir = 4
  231. elseif old_fdir == 2 then
  232. new_fdir = 2
  233. elseif old_fdir == 3 then
  234. new_fdir = 5
  235. end
  236. local param2 = paletteidx + new_fdir
  237. if string.find(name, "regular") then
  238. new_name = "homedecor:bed_regular"
  239. elseif string.find(name, "extended") then
  240. new_name = "homedecor:bed_extended"
  241. else
  242. new_name = "homedecor:bed_kingsize"
  243. end
  244. minetest.set_node(pos, { name = new_name, param2 = param2 })
  245. local meta = minetest.get_meta(pos)
  246. meta:set_string("dye", "unifieddyes:"..color)
  247. end
  248. })
  249. -- crafting
  250. minetest.register_craft( {
  251. output = "homedecor:nightstand_oak_one_drawer",
  252. recipe = {
  253. { "homedecor:drawer_small" },
  254. { "group:wood" },
  255. },
  256. })
  257. minetest.register_craft({
  258. type = "fuel",
  259. recipe = "homedecor:nightstand_oak_one_drawer",
  260. burntime = 30,
  261. })
  262. minetest.register_craft( {
  263. output = "homedecor:nightstand_oak_two_drawers",
  264. recipe = {
  265. { "homedecor:drawer_small" },
  266. { "homedecor:drawer_small" },
  267. { "group:wood" },
  268. },
  269. })
  270. minetest.register_craft( {
  271. output = "homedecor:nightstand_oak_two_drawers",
  272. recipe = {
  273. { "homedecor:nightstand_oak_one_drawer" },
  274. { "homedecor:drawer_small" },
  275. },
  276. })
  277. minetest.register_craft({
  278. type = "fuel",
  279. recipe = "homedecor:nightstand_oak_two_drawers",
  280. burntime = 30,
  281. })
  282. --
  283. minetest.register_craft( {
  284. type = "shapeless",
  285. output = "homedecor:nightstand_mahogany_one_drawer",
  286. recipe = {
  287. "homedecor:nightstand_oak_one_drawer",
  288. "dye:brown",
  289. },
  290. })
  291. minetest.register_craft({
  292. type = "fuel",
  293. recipe = "homedecor:nightstand_mahogany_one_drawer",
  294. burntime = 30,
  295. })
  296. minetest.register_craft( {
  297. type = "shapeless",
  298. output = "homedecor:nightstand_mahogany_two_drawers",
  299. recipe = {
  300. "homedecor:nightstand_oak_two_drawers",
  301. "dye:brown",
  302. },
  303. })
  304. minetest.register_craft({
  305. type = "fuel",
  306. recipe = "homedecor:nightstand_mahogany_two_drawers",
  307. burntime = 30,
  308. })
  309. minetest.register_craft( {
  310. output = "homedecor:bed_regular",
  311. recipe = {
  312. { "group:stick", "", "group:stick" },
  313. { "wool:white", "wool:white", "wool:white" },
  314. { "group:wood", "", "group:wood" },
  315. },
  316. })
  317. unifieddyes.register_color_craft({
  318. output = "homedecor:bed_regular",
  319. palette = "wallmounted",
  320. type = "shapeless",
  321. neutral_node = "homedecor:bed_regular",
  322. recipe = {
  323. "NEUTRAL_NODE",
  324. "MAIN_DYE"
  325. }
  326. })
  327. minetest.register_craft( {
  328. output = "homedecor:bed_kingsize",
  329. recipe = {
  330. { "homedecor:bed_regular", "homedecor:bed_regular" }
  331. },
  332. })
  333. unifieddyes.register_color_craft({
  334. output = "homedecor:bed_kingsize",
  335. palette = "wallmounted",
  336. type = "shapeless",
  337. neutral_node = "homedecor:bed_kingsize",
  338. recipe = {
  339. "NEUTRAL_NODE",
  340. "MAIN_DYE"
  341. }
  342. })
  343. unifieddyes.register_color_craft({
  344. output = "homedecor:bed_kingsize",
  345. palette = "wallmounted",
  346. type = "shapeless",
  347. neutral_node = "homedecor:bed_regular",
  348. recipe = {
  349. "NEUTRAL_NODE",
  350. "NEUTRAL_NODE",
  351. "MAIN_DYE"
  352. }
  353. })