init.lua 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. --[[
  2. Stained Glass
  3. This mod provides luminescent stained glass blocks for Minetest 0.4.7+
  4. Depends:
  5. [moreblocks] by Calinou
  6. [unifieddyes] by VanessaE
  7. ==============================================================================
  8. Sat 04 May 2013 01:52:35 PM EDT
  9. Copyright (C) 2013, Eli Innis
  10. Email: doyousketch2 @ yahoo.com
  11. Unified Dyes was released under GNU-GPL 2.0, see LICENSE for info.
  12. More Blocks was released under zlib/libpng for code and CC BY-SA 3.0 Unported for textures, see LICENSE.txt for info.
  13. Additional changes by VanessaEzekowitz in July 2013 to take all items
  14. out of creative inventory.
  15. August 2013 -- Jeremy Anderson tries to get this working after the new color
  16. changes, and to resurrect the craft recipes. Still GPL'd as far as I'm concerned.
  17. August 2013 -- rewritten a bit by VanessaEzekowitz to further condense the code.
  18. January 2017 -- rewritten a bit more by Vanessa E. to use engine param2 colorization
  19. and place-then-paint creation of colors. To get the pastel colors,
  20. place super glow glass, right-click with dye to color it, then right-
  21. click with Moreblocks' "sweeper" to "brush off" some of the color. Do
  22. it again to change pastel to faint. Right click a pastel or faint with
  23. some dye to re-color it (you have to dig and re-place if you want to
  24. darken it). Crafting is no longer used to create the colors.
  25. August 2018 -- altered to use proper colored itemstacks with crafting
  26. ==============================================================================
  27. ]]--
  28. stainedglass = {}
  29. stainedglass.old_static_nodes = {}
  30. local myglow = LIGHT_MAX-3
  31. minetest.register_node("stained_glass:stained_glass", {
  32. description = "Stained Glass",
  33. drawtype = "glasslike_framed_optional",
  34. tiles = { "stained_glass.png", "stained_glass_detail.png" },
  35. paramtype = "light",
  36. paramtype2 = "color",
  37. palette = "unifieddyes_palette_extended.png",
  38. sunlight_propagates = true,
  39. use_texture_alpha = "blend",
  40. light_source = myglow,
  41. is_ground_content = true,
  42. walkable = true,
  43. groups = {snappy=2,cracky=3,oddly_breakable_by_hand=3, not_in_creative_inventory=1, ud_param2_colorable = 1},
  44. sounds = default.node_sound_glass_defaults(),
  45. on_construct = unifieddyes.on_construct,
  46. on_dig = unifieddyes.on_dig,
  47. })
  48. minetest.override_item("moreblocks:super_glow_glass", {
  49. palette = "unifieddyes_palette_extended.png",
  50. airbrush_replacement_node = "stained_glass:stained_glass",
  51. groups = {snappy = 2, cracky = 3, oddly_breakable_by_hand = 3, ud_param2_colorable = 1},
  52. })
  53. -- trap glass
  54. minetest.register_node("stained_glass:stained_trap_glass", {
  55. description = "Stained Trap-glass",
  56. drawtype = "glasslike_framed_optional",
  57. tiles = { "stained_glass.png", "stained_glass_detail.png" },
  58. paramtype = "light",
  59. paramtype2 = "color",
  60. palette = "unifieddyes_palette_extended.png",
  61. sunlight_propagates = true,
  62. use_texture_alpha = "blend",
  63. light_source = myglow,
  64. is_ground_content = true,
  65. walkable = false,
  66. groups = {snappy=2,cracky=3,oddly_breakable_by_hand=3, not_in_creative_inventory=1, ud_param2_colorable = 1},
  67. sounds = default.node_sound_glass_defaults(),
  68. on_construct = unifieddyes.on_construct,
  69. on_dig = unifieddyes.on_dig,
  70. })
  71. minetest.override_item("moreblocks:trap_super_glow_glass", {
  72. palette = "unifieddyes_palette_extended.png",
  73. airbrush_replacement_node = "stained_glass:stained_trap_glass",
  74. groups = {snappy=2,cracky=3,oddly_breakable_by_hand=3, ud_param2_colorable = 1},
  75. })
  76. -- crafting
  77. unifieddyes.register_color_craft({
  78. output = "stained_glass:stained_glass",
  79. palette = "extended",
  80. type = "shapeless",
  81. neutral_node = "moreblocks:super_glow_glass",
  82. recipe = {
  83. "NEUTRAL_NODE",
  84. "MAIN_DYE"
  85. }
  86. })
  87. unifieddyes.register_color_craft({
  88. output = "stained_glass:stained_trap_glass",
  89. palette = "extended",
  90. type = "shapeless",
  91. neutral_node = "moreblocks:trap_super_glow_glass",
  92. recipe = {
  93. "NEUTRAL_NODE",
  94. "MAIN_DYE"
  95. }
  96. })
  97. -- old static stuff
  98. function stainedglass.makenode(arg)
  99. local name=arg.blockname
  100. local myglow=arg.glow
  101. local myprefix=arg.prefix
  102. local imagename=arg.imagename
  103. local safe=arg.walkflag
  104. local function tchelper(first, rest)
  105. return first:upper()..rest:lower()
  106. end -- from lua-users.org/wiki/StringRecipes
  107. table.insert(stainedglass.old_static_nodes, "stained_glass:"..name)
  108. end
  109. -- maybe someday, I can cleanly combine these two functions.
  110. function stained_trapglass_define(arg)
  111. local code=arg.colorcode
  112. local name=arg.colorname
  113. local rawdyename=arg.recipe
  114. local mydye=arg.recipe
  115. local myshadename=arg.shade
  116. local imagename=name
  117. local stained_glass_blocktype = { }
  118. local stained_glass_lightlevel = { }
  119. if stained_glass.trap_full_light then
  120. stained_glass_lightlevel[""] = LIGHT_MAX
  121. stained_glass_blocktype[""] = "moreblocks:trap_super_glow_glass"
  122. end -- see settings.txt for these settings.
  123. if stained_glass.trap_med_light then
  124. stained_glass_lightlevel["lowglow_"] = LIGHT_MAX-3
  125. stained_glass_blocktype["lowglow_"] = "moreblocks:trap_glow_glass"
  126. end
  127. if stained_glass.trap_no_light then
  128. stained_glass_lightlevel["noglow_"] = 0
  129. stained_glass_blocktype["noglow_"] = "moreblocks:trap_glass"
  130. end
  131. for myprefix,myglow in pairs(stained_glass_lightlevel) do
  132. local glasstype = stained_glass_blocktype[myprefix]
  133. local name="trap_" .. name
  134. -- define myrecipe as a table, pass it in.
  135. local myrecipe = { mydye, glasstype, glasstype, glasstype }
  136. -- those four items will ALWAYS be there. For faint and pastel, we
  137. -- need to add additional dyes. If you have defined a new shade, then
  138. -- you should probably handle it here.
  139. if myshadename == "pastel_" then
  140. myrecipe[5] = "dye:white"
  141. end
  142. if myshadename == "faint_" then
  143. myrecipe[5] = "dye:white"
  144. myrecipe[6] = "dye:white"
  145. end
  146. stainedglass.makenode{blockname=name, glow=myglow, prefix=myprefix, imagename=imagename, walkflag=false}
  147. end
  148. end
  149. function stained_glass_define(arg)
  150. local code=arg.colorcode
  151. local name=arg.colorname
  152. local rawdyename=arg.recipe
  153. local mydye=arg.recipe
  154. local myshadename=arg.shade
  155. local imagename=name
  156. local stained_glass_blocktype = { }
  157. local stained_glass_lightlevel = { }
  158. if stained_glass.full_light then
  159. stained_glass_lightlevel[""] = LIGHT_MAX
  160. stained_glass_blocktype[""] = "moreblocks:super_glow_glass"
  161. end -- see settings.txt for these settings.
  162. if stained_glass.med_light then
  163. stained_glass_lightlevel["lowglow_"] = LIGHT_MAX-3
  164. stained_glass_blocktype["lowglow_"] = "moreblocks:glow_glass"
  165. end
  166. if stained_glass.no_light then
  167. stained_glass_lightlevel["noglow_"] = 0
  168. stained_glass_blocktype["noglow_"] = "default:glass"
  169. end
  170. for myprefix,myglow in pairs(stained_glass_lightlevel) do
  171. local glasstype = stained_glass_blocktype[myprefix]
  172. -- define myrecipe as a table, pass it in.
  173. local myrecipe = { mydye, glasstype, glasstype, glasstype }
  174. -- those four items will ALWAYS be there. For faint and pastel, we
  175. -- need to add additional dyes. If you have defined a new shade, then
  176. -- you should probably handle it here.
  177. if myshadename == "pastel_" then
  178. myrecipe[5] = "dye:white"
  179. end
  180. if myshadename == "faint_" then
  181. myrecipe[5] = "dye:white"
  182. myrecipe[6] = "dye:white"
  183. end
  184. stainedglass.makenode{blockname=name, glow=myglow, prefix=myprefix, imagename=name, walkflag=true}
  185. if myprefix == "" then
  186. local aliasname
  187. minetest.register_alias( "stained_glass:" .. code, "stained_glass:" .. name)
  188. if string.match(name,"redviolet") then
  189. local oldname=name
  190. aliasname=string.gsub(name, "redviolet","red_violet") -- need to support red_violet existence, too.
  191. minetest.register_alias( "stained_glass:" .. aliasname, "stained_glass:" .. oldname)
  192. end
  193. end
  194. -- and an alias from the numeric to the named block
  195. -- we need to keep the numeric block for all the people that used
  196. -- pre-v1.4 blocks in their worlds.
  197. -- no aliases for noglow- and lowglow- blocks, because they didn't
  198. -- exist until v1.5
  199. end
  200. end
  201. -- true means this color's recipe must use a direct "dye:xxxxx" item name
  202. -- (perhaps because the related groups overlap two or more distinct colors)
  203. -- false means the recipe uses "group:dye,unicolor_xxxxx"
  204. stained_glass= {}
  205. local worldpath=minetest.get_worldpath()
  206. local modpath=minetest.get_modpath("stained_glass")
  207. dofile(modpath .. "/settings.txt")
  208. -- the new settings.txt file has a variety of possible settings.
  209. -- see the file for examples. We'll access those settings where its important, in
  210. -- the stained glass module, where we'll build up the tables to contain
  211. -- only what we need.
  212. stained_glass_hues = {
  213. { "yellow", true },
  214. { "lime", false },
  215. { "green", true },
  216. { "aqua", false },
  217. { "cyan", false },
  218. { "skyblue", true },
  219. { "blue", false },
  220. { "violet", false },
  221. { "magenta", true },
  222. { "redviolet", true },
  223. { "red", true },
  224. { "orange", false },
  225. -- please note that these only apply when our shadelevel is ""
  226. }
  227. stained_glass_shades = {
  228. {"dark_", 3 },
  229. {"medium_", 4 },
  230. {"", 5 }, -- full brightness
  231. {"light_", 8 },
  232. {"pastel_", 9 },
  233. {"faint_", 91 }
  234. -- note that dark_ medium_ and plain also have a half-saturation
  235. -- equivalent automatically defined in the code
  236. }
  237. for i in ipairs(stained_glass_hues) do
  238. local huename = stained_glass_hues[i][1]
  239. local huenumber = i
  240. for j in ipairs(stained_glass_shades) do
  241. local shadename = stained_glass_shades[j][1]
  242. local shadenumber = stained_glass_shades[j][2]
  243. local recipevalue = nil
  244. recipevalue = "group:dye,unicolor_"..shadename..huename
  245. if (shadename == "" and stained_glass_hues[i][2]) then
  246. recipevalue = "dye:"..huename
  247. elseif (shadename=="pastel_" or shadename=="faint_") then
  248. -- force light_dye for pastel and faint colors
  249. recipevalue = "group:dye,unicolor_light_"..huename
  250. else -- default case
  251. recipevalue = "group:dye,unicolor_"..shadename..huename
  252. end
  253. if shadename == "dark_" or shadename == "medium_" or shadename == "" then
  254. stained_glass_define({
  255. colorcode = huenumber.."_"..shadenumber.."_7",
  256. colorname = shadename..huename,
  257. recipe = recipevalue,
  258. shade = shadename,
  259. })
  260. stained_trapglass_define({
  261. colorcode = huenumber.."_"..shadenumber.."_7",
  262. colorname = shadename..huename,
  263. recipe = recipevalue,
  264. shade = shadename,
  265. }) -- only defines something if the trap is enabled.
  266. -- below is the automatic "half saturation" block
  267. -- which was mentioned previously
  268. -- this is unicolor only, so switch dyename
  269. -- back to unicolor...
  270. recipevalue="group:dye,unicolor_"..shadename..huename
  271. stained_glass_define({
  272. colorcode = huenumber.."_"..shadenumber.."_6",
  273. colorname = shadename..huename.."_s50",
  274. recipe = recipevalue.."_s50",
  275. shade = shadename,
  276. })
  277. stained_trapglass_define({
  278. colorcode = huenumber.."_"..shadenumber.."_6",
  279. colorname = shadename..huename.."_s50",
  280. recipe = recipevalue.."_s50",
  281. shade = shadename,
  282. }) -- only defines something if the trap is enabled.
  283. -- because we define two blocks inside this chunk of
  284. -- code, we can't just define the relevant vars and
  285. -- move the proc_call after the if-then loop.
  286. elseif shadename == "light_" or shadename == "pastel_" or shadename == "faint_" then
  287. stained_glass_define({
  288. colorcode = huenumber.."_"..shadenumber,
  289. colorname = shadename..huename,
  290. recipe = recipevalue,
  291. shade = shadename,
  292. })
  293. stained_trapglass_define({
  294. colorcode = huenumber.."_"..shadenumber,
  295. colorname = shadename..huename,
  296. recipe = recipevalue,
  297. shade = shadename,
  298. }) -- only defines something if the trap is enabled.
  299. end
  300. end
  301. end
  302. -- convert in-map static nodes to use param2 coloring
  303. minetest.register_lbm({
  304. name = "stained_glass:convert_glass",
  305. label = "Convert static glass blocks to use param2 color",
  306. run_at_every_load = false,
  307. nodenames = stainedglass.old_static_nodes,
  308. action = function(pos, node)
  309. local name = node.name
  310. name = string.gsub(name, "aqua", "spring")
  311. name = string.gsub(name, "skyblue", "azure")
  312. name = string.gsub(name, "redviolet", "rose")
  313. local n = string.find(name, ":")
  314. local color = string.sub(name, n + 1)
  315. local h,s,v = unifieddyes.get_hsv(name)
  316. if string.find(name, "trap") then
  317. n = string.find(color, "_")
  318. color = string.sub(color, n + 1)
  319. local paletteidx = unifieddyes.getpaletteidx("unifieddyes:"..color, "extended")
  320. minetest.set_node(pos, { name = "stained_glass:stained_trap_glass", param2 = paletteidx })
  321. else
  322. local paletteidx = unifieddyes.getpaletteidx("unifieddyes:"..color, "extended")
  323. minetest.set_node(pos, { name = "stained_glass:stained_glass", param2 = paletteidx })
  324. end
  325. local meta = minetest.get_meta(pos)
  326. meta:set_string("dye", "unifieddyes:"..v..h..s)
  327. meta:set_string("palette", "ext")
  328. end
  329. })
  330. print("[stained_glass] Loaded!")