init.lua 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. --Unified Bricks by Vsevolod Borislav (wowiamdiamonds)
  2. --
  3. --License: WTFPL
  4. --
  5. --Depends: default, bucket, unifieddyes, vessels
  6. --
  7. --Obviously, offers the same colors in unifieddyes.
  8. --Thanks go to VanessaE for making unifieddyes, gentextures.sh, etc.
  9. unifiedbricks = {}
  10. unifiedbricks.old_static_list = {}
  11. unifiedbricks.old_static_list_formals = {}
  12. minetest.register_alias("unifieddyes:white","unifieddyes:white_paint")
  13. minetest.register_alias("unifieddyes:lightgrey","unifieddyes:lightgrey_paint")
  14. minetest.register_alias("unifieddyes:grey","unifieddyes:grey_paint")
  15. minetest.register_alias("unifieddyes:darkgrey","unifieddyes:darkgrey_paint")
  16. HUES = {
  17. "red",
  18. "orange",
  19. "yellow",
  20. "lime",
  21. "green",
  22. "aqua",
  23. "cyan",
  24. "skyblue",
  25. "blue",
  26. "violet",
  27. "magenta",
  28. "redviolet",
  29. "black",
  30. "darkgrey",
  31. "grey",
  32. "lightgrey",
  33. "white"
  34. }
  35. TYPES = {
  36. "clayblock_",
  37. "clay_",
  38. "brick_",
  39. "brickblock_",
  40. "multicolor_"
  41. }
  42. SATURATION = {
  43. "_s50",
  44. ""
  45. }
  46. DARKNESS = {
  47. "dark_",
  48. "medium_",
  49. "",
  50. "light_"
  51. }
  52. --formal versions
  53. FORMALHUES = {
  54. "Red",
  55. "Orange",
  56. "Yellow",
  57. "Lime",
  58. "Green",
  59. "Aqua",
  60. "Cyan",
  61. "Sky blue",
  62. "Blue",
  63. "Violet",
  64. "Magenta",
  65. "Red violet",
  66. "Black",
  67. "Dark grey",
  68. "Grey",
  69. "Light grey",
  70. "White"
  71. }
  72. FORMALTYPES = {
  73. " clay",
  74. " clay lump",
  75. " brick",
  76. " bricks",
  77. " multicolor bricks"
  78. }
  79. FORMALSATURATION = {
  80. " (low saturation)",
  81. ""
  82. }
  83. FORMALDARKNESS = {
  84. "Dark ",
  85. "Medium ",
  86. "Bright ",
  87. "Light "
  88. }
  89. -- param2-coloring-enabled nodes
  90. minetest.register_node("unifiedbricks:brickblock", {
  91. description = "Brick Block",
  92. tiles = {
  93. "unifiedbricks_brickblock.png"
  94. },
  95. overlay_tiles = {
  96. { name = "unifiedbricks_mortar.png", color = "white" }
  97. },
  98. paramtype = "light",
  99. paramtype2 = "color",
  100. palette = "unifieddyes_palette_extended.png",
  101. is_ground_content = true,
  102. groups = {cracky=3, not_in_creative_inventory=1, ud_param2_colorable = 1},
  103. sounds = default.node_sound_stone_defaults(),
  104. on_construct = unifieddyes.on_construct,
  105. on_dig = unifieddyes.on_dig,
  106. })
  107. minetest.override_item("default:brick", {
  108. palette = "unifieddyes_palette_extended.png",
  109. airbrush_replacement_node = "unifiedbricks:brickblock",
  110. groups = {cracky = 3, ud_param2_colorable = 1},
  111. })
  112. minetest.register_node("unifiedbricks:clayblock", {
  113. description = "Clay Block",
  114. tiles = {
  115. "unifiedbricks_clayblock.png",
  116. },
  117. paramtype2 = "color",
  118. palette = "unifieddyes_palette_extended.png",
  119. is_ground_content = true,
  120. groups = {crumbly=3, not_in_creative_inventory=1, ud_param2_colorable = 1},
  121. sounds = default.node_sound_dirt_defaults({
  122. footstep = "",
  123. }),
  124. on_construct = unifieddyes.on_construct,
  125. on_dig = unifieddyes.on_dig,
  126. })
  127. minetest.override_item("default:clay", {
  128. palette = "unifieddyes_palette_extended.png",
  129. airbrush_replacement_node = "unifiedbricks:clayblock",
  130. groups = {crumbly = 3, ud_param2_colorable = 1},
  131. })
  132. minetest.register_node("unifiedbricks:brickblock_multicolor_dark", {
  133. description = "Brick block (dark multicolor)",
  134. tiles = {
  135. "unifiedbricks_brickblock_multicolor_dark.png",
  136. },
  137. overlay_tiles = {
  138. { name = "unifiedbricks_mortar2.png", color = "white" }
  139. },
  140. paramtype = "light",
  141. paramtype2 = "color",
  142. palette = "unifieddyes_palette_extended.png",
  143. is_ground_content = true,
  144. groups = {cracky=3, ud_param2_colorable = 1},
  145. sounds = default.node_sound_stone_defaults(),
  146. on_construct = unifieddyes.on_construct,
  147. on_dig = unifieddyes.on_dig,
  148. })
  149. minetest.register_node("unifiedbricks:brickblock_multicolor_medium", {
  150. description = "Brick block (medium multicolor)",
  151. tiles = {
  152. "unifiedbricks_brickblock_multicolor_medium.png"
  153. },
  154. overlay_tiles = {
  155. { name = "unifiedbricks_mortar3.png", color = "white" }
  156. },
  157. paramtype = "light",
  158. paramtype2 = "color",
  159. palette = "unifieddyes_palette_extended.png",
  160. is_ground_content = true,
  161. groups = {cracky=3, ud_param2_colorable = 1},
  162. sounds = default.node_sound_stone_defaults(),
  163. on_construct = unifieddyes.on_construct,
  164. on_dig = unifieddyes.on_dig,
  165. })
  166. minetest.register_node("unifiedbricks:brickblock_multicolor_light", {
  167. description = "Brick block (light multicolor)",
  168. tiles = {
  169. "unifiedbricks_brickblock_multicolor_light.png"
  170. },
  171. overlay_tiles = {
  172. { name = "unifiedbricks_mortar4.png", color = "white" }
  173. },
  174. paramtype = "light",
  175. paramtype2 = "color",
  176. palette = "unifieddyes_palette_extended.png",
  177. is_ground_content = true,
  178. groups = {cracky=3, ud_param2_colorable = 1},
  179. sounds = default.node_sound_stone_defaults(),
  180. on_construct = unifieddyes.on_construct,
  181. on_dig = unifieddyes.on_dig,
  182. })
  183. minetest.register_craft( {
  184. type = "shapeless",
  185. output = "unifiedbricks:brickblock_multicolor_dark",
  186. recipe = {
  187. "default:brick",
  188. "unifieddyes:grey",
  189. "unifieddyes:dark_grey",
  190. "unifieddyes:dark_grey"
  191. },
  192. })
  193. minetest.register_craft( {
  194. type = "shapeless",
  195. output = "unifiedbricks:brickblock_multicolor_medium",
  196. recipe = {
  197. "default:brick",
  198. "unifieddyes:white",
  199. "unifieddyes:grey",
  200. "unifieddyes:dark_grey"
  201. },
  202. })
  203. minetest.register_craft( {
  204. type = "shapeless",
  205. output = "unifiedbricks:brickblock_multicolor_light",
  206. recipe = {
  207. "default:brick",
  208. "unifieddyes:white",
  209. "unifieddyes:white",
  210. "unifieddyes:grey"
  211. },
  212. })
  213. unifieddyes.register_color_craft({
  214. output = "unifiedbricks:brickblock",
  215. palette = "extended",
  216. neutral_node = "default:brick",
  217. type = "shapeless",
  218. recipe = {
  219. "NEUTRAL_NODE",
  220. "MAIN_DYE"
  221. }
  222. })
  223. unifieddyes.register_color_craft({
  224. output = "unifiedbricks:clayblock",
  225. palette = "extended",
  226. neutral_node = "default:clay",
  227. type = "shapeless",
  228. recipe = {
  229. "NEUTRAL_NODE",
  230. "MAIN_DYE"
  231. }
  232. })
  233. unifieddyes.register_color_craft({
  234. output = "unifiedbricks:brickblock_multicolor_dark",
  235. palette = "extended",
  236. neutral_node = "unifiedbricks:brickblock_multicolor_dark",
  237. type = "shapeless",
  238. recipe = {
  239. "NEUTRAL_NODE",
  240. "MAIN_DYE"
  241. }
  242. })
  243. unifieddyes.register_color_craft({
  244. output = "unifiedbricks:brickblock_multicolor_medium",
  245. palette = "extended",
  246. neutral_node = "unifiedbricks:brickblock_multicolor_medium",
  247. type = "shapeless",
  248. recipe = {
  249. "NEUTRAL_NODE",
  250. "MAIN_DYE"
  251. }
  252. })
  253. unifieddyes.register_color_craft({
  254. output = "unifiedbricks:brickblock_multicolor_light",
  255. palette = "extended",
  256. neutral_node = "unifiedbricks:brickblock_multicolor_light",
  257. type = "shapeless",
  258. recipe = {
  259. "NEUTRAL_NODE",
  260. "MAIN_DYE"
  261. }
  262. })
  263. -- static nodes
  264. unifiedbricks.register_old_static_block = function(name, formalname, blocktype)
  265. table.insert(unifiedbricks.old_static_list, "unifiedbricks:"..blocktype.."_"..name)
  266. table.insert(unifiedbricks.old_static_list_formals, formalname)
  267. end
  268. for _, color in ipairs(HUES) do
  269. table.insert(unifiedbricks.old_static_list, "unifiedbricks:multicolor_dark_"..color)
  270. table.insert(unifiedbricks.old_static_list, "unifiedbricks:multicolor_medium_"..color)
  271. table.insert(unifiedbricks.old_static_list, "unifiedbricks:multicolor_light_"..color)
  272. end
  273. table.insert(unifiedbricks.old_static_list, "unifiedbricks:multicolor_darkgrey")
  274. table.insert(unifiedbricks.old_static_list, "unifiedbricks:multicolor_grey")
  275. table.insert(unifiedbricks.old_static_list, "unifiedbricks:multicolor_lightgrey")
  276. --REGISTERS ALL STATIC NODES EXCEPT MULTICOLOR BRICK BLOCKS
  277. for i = 1,17 do
  278. for j = 1,4 do
  279. if i > 12 then
  280. formalname = FORMALHUES[i]
  281. name = HUES[i]
  282. if j == 1 then
  283. unifiedbricks.register_old_static_block(name, formalname, "clayblock")
  284. elseif j == 4 then
  285. unifiedbricks.register_old_static_block(name, formalname, "brickblock")
  286. end
  287. else
  288. for k = 1,4 do
  289. if k == 4 then
  290. formalname = FORMALDARKNESS[k] .. FORMALHUES[i]
  291. name = DARKNESS[k] .. HUES[i]
  292. if j == 1 then
  293. unifiedbricks.register_old_static_block(name, formalname, "clayblock")
  294. elseif j == 4 then
  295. unifiedbricks.register_old_static_block(name, formalname, "brickblock")
  296. end
  297. else
  298. for l = 1,2 do
  299. formalname = FORMALDARKNESS[k] .. FORMALHUES[i] .. FORMALSATURATION[l]
  300. name = DARKNESS[k] .. HUES[i] .. SATURATION[l]
  301. if j == 1 then
  302. unifiedbricks.register_old_static_block(name, formalname, "clayblock")
  303. elseif j == 4 then
  304. unifiedbricks.register_old_static_block(name, formalname, "brickblock")
  305. end
  306. end
  307. end
  308. end
  309. end
  310. end
  311. end
  312. -- convert in-map static nodes to use param2 coloring
  313. minetest.register_lbm({
  314. name = "unifiedbricks:convert_brickblocks",
  315. label = "Convert clay blocks and single-color brick blocks to use param2 color",
  316. run_at_every_load = false,
  317. nodenames = unifiedbricks.old_static_list,
  318. action = function(pos, node)
  319. local name = node.name
  320. local t = string.find(name, "_")
  321. local type = string.sub(name, 1, t - 1)
  322. local color1 = string.sub(name, t + 1)
  323. local color2 = string.gsub(color1, "grey", "_grey")
  324. if color2 == "_grey" then color2 = "grey" end
  325. local paletteidx, hue = unifieddyes.getpaletteidx("unifieddyes:"..color2, "extended")
  326. if not paletteidx or not hue then return end
  327. if string.find(type, "multicolor") then
  328. local newpalette = (hue*8)+1
  329. local shade
  330. if string.find(name, "dark") then
  331. shade = "dark"
  332. elseif string.find(name, "medium")
  333. or name == "unifiedbricks:multicolor_grey" then
  334. shade = "medium"
  335. else
  336. shade = "light"
  337. end
  338. if string.find(name, "grey") then
  339. newpalette = 2
  340. end
  341. minetest.set_node(pos, { name = "unifiedbricks:brickblock_multicolor_"..shade, param2 = newpalette })
  342. elseif string.find(type, "brickblock") then
  343. minetest.set_node(pos, { name = "unifiedbricks:brickblock", param2 = paletteidx })
  344. elseif string.find(type, "clayblock") then
  345. minetest.set_node(pos, { name = "unifiedbricks:clayblock", param2 = paletteidx })
  346. end
  347. local meta = minetest.get_meta(pos)
  348. meta:set_string("dye", "unifieddyes:"..color1)
  349. meta:set_string("palette", "ext")
  350. end
  351. })
  352. print("[UnifiedBricks] Loaded!")