init.lua 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. local function is_pane(pos)
  2. return minetest.get_item_group(minetest.get_node(pos).name, "pane") > 0
  3. end
  4. local function connects_dir(pos, name, dir)
  5. local aside = vector.add(pos, minetest.facedir_to_dir(dir))
  6. if is_pane(aside) then
  7. return true
  8. end
  9. local ndef = minetest.reg_ns_nodes[name]
  10. if not ndef or not ndef.connects_to then
  11. return false
  12. end
  13. local list = minetest.find_nodes_in_area(aside, aside, ndef.connects_to)
  14. if #list > 0 then
  15. return true
  16. end
  17. return false
  18. end
  19. local function swap(pos, node, name, param2)
  20. if node.name == name and node.param2 == param2 then
  21. return
  22. end
  23. -- Use swap_node to avoid infinite callbacks.
  24. minetest.swap_node(pos, {name = name, param2 = param2})
  25. end
  26. local function update_pane(pos)
  27. if not is_pane(pos) then
  28. return
  29. end
  30. local node = minetest.get_node(pos)
  31. local name = node.name
  32. if name:sub(-5) == "_flat" then
  33. name = name:sub(1, -6)
  34. end
  35. local any = node.param2
  36. local c = {}
  37. local count = 0
  38. for dir = 0, 3 do
  39. c[dir] = connects_dir(pos, name, dir)
  40. if c[dir] then
  41. any = dir
  42. count = count + 1
  43. end
  44. end
  45. if count == 0 then
  46. swap(pos, node, name .. "_flat", any)
  47. elseif count == 1 then
  48. swap(pos, node, name .. "_flat", (any + 1) % 4)
  49. elseif count == 2 then
  50. if (c[0] and c[2]) or (c[1] and c[3]) then
  51. swap(pos, node, name .. "_flat", (any + 1) % 4)
  52. else
  53. swap(pos, node, name, 0)
  54. end
  55. else
  56. swap(pos, node, name, 0)
  57. end
  58. end
  59. --[[
  60. minetest.register_on_placenode(function(pos, node)
  61. if minetest.get_item_group(node, "pane") then
  62. update_pane(pos)
  63. end
  64. for i = 0, 3 do
  65. local dir = minetest.facedir_to_dir(i)
  66. update_pane(vector.add(pos, dir))
  67. end
  68. end)
  69. minetest.register_on_dignode(function(pos)
  70. for i = 0, 3 do
  71. local dir = minetest.facedir_to_dir(i)
  72. update_pane(vector.add(pos, dir))
  73. end
  74. end)
  75. --]]
  76. xpanes = {}
  77. function xpanes.register_pane(name, def)
  78. for i = 1, 15 do
  79. minetest.register_alias("xpanes:" .. name .. "_" .. i, "xpanes:" .. name .. "_flat")
  80. end
  81. local on_construct = function(pos)
  82. update_pane(pos)
  83. for i = 0, 3 do
  84. local dir = minetest.facedir_to_dir(i)
  85. update_pane(vector.add(pos, dir))
  86. end
  87. end
  88. local after_destruct = function(pos)
  89. for i = 0, 3 do
  90. local dir = minetest.facedir_to_dir(i)
  91. update_pane(vector.add(pos, dir))
  92. end
  93. end
  94. local flatgroups = table.copy(def.groups or {})
  95. flatgroups.pane = 1
  96. minetest.register_node(":xpanes:" .. name .. "_flat", {
  97. description = def.description,
  98. drawtype = "nodebox",
  99. paramtype = "light",
  100. is_ground_content = false,
  101. sunlight_propagates = true,
  102. inventory_image = def.inventory_image,
  103. use_texture_alpha = def.use_texture_alpha,
  104. wield_image = def.wield_image,
  105. paramtype2 = "facedir",
  106. tiles = {def.textures[3], def.textures[3], def.textures[1]},
  107. groups = flatgroups,
  108. drop = "xpanes:" .. name .. "_flat",
  109. sounds = def.sounds,
  110. light_source = def.light_source,
  111. node_box = {
  112. type = "fixed",
  113. fixed = {{-1/2, -1/2, -1/32, 1/2, 1/2, 1/32}},
  114. },
  115. selection_box = {
  116. type = "fixed",
  117. fixed = {{-1/2, -1/2, -1/32, 1/2, 1/2, 1/32}},
  118. },
  119. connect_sides = { "left", "right" },
  120. on_construct = on_construct,
  121. after_destruct = after_destruct,
  122. })
  123. local groups = table.copy(def.groups or {})
  124. groups.pane = 1
  125. groups.not_in_creative_inventory = 1
  126. minetest.register_node(":xpanes:" .. name, {
  127. drawtype = "nodebox",
  128. paramtype = "light",
  129. is_ground_content = false,
  130. sunlight_propagates = true,
  131. description = def.description,
  132. tiles = {def.textures[3], def.textures[3], def.textures[1]},
  133. groups = groups,
  134. drop = "xpanes:" .. name .. "_flat",
  135. sounds = def.sounds,
  136. light_source = def.light_source,
  137. node_box = {
  138. type = "connected",
  139. fixed = {{-1/32, -1/2, -1/32, 1/32, 1/2, 1/32}},
  140. connect_front = {{-1/32, -1/2, -1/2, 1/32, 1/2, -1/32}},
  141. connect_left = {{-1/2, -1/2, -1/32, -1/32, 1/2, 1/32}},
  142. connect_back = {{-1/32, -1/2, 1/32, 1/32, 1/2, 1/2}},
  143. connect_right = {{1/32, -1/2, -1/32, 1/2, 1/2, 1/32}},
  144. },
  145. connects_to = {"group:pane", "group:stone", "group:glass", "group:brick", "group:wood", "group:tree"},
  146. on_construct = on_construct,
  147. after_destruct = after_destruct,
  148. })
  149. minetest.register_craft({
  150. output = "xpanes:" .. name .. "_flat " .. (def.amount or 16),
  151. recipe = def.recipe
  152. })
  153. end
  154. xpanes.register_pane("pane", {
  155. description = "Glass Pane",
  156. textures = {"default_glass.png","xpanes_pane_half.png","xpanes_white.png"},
  157. inventory_image = "default_glass.png",
  158. wield_image = "default_glass.png",
  159. sounds = default.node_sound_glass_defaults(),
  160. groups = utility.dig_groups("pane_glass"),
  161. recipe = {
  162. {"default:glass", "default:glass", "default:glass"},
  163. {"default:glass", "default:glass", "default:glass"}
  164. }
  165. })
  166. ----[[
  167. xpanes.register_pane("obsidian_glass", {
  168. description = "Obsidian Glass Pane",
  169. textures = {"default_obsidian_glass.png","xpanes_pane_half.png","xpanes_white.png"},
  170. inventory_image = "default_obsidian_glass.png",
  171. wield_image = "default_obsidian_glass.png",
  172. sounds = default.node_sound_glass_defaults(),
  173. groups = utility.dig_groups("pane_glass"),
  174. recipe = {
  175. {"default:obsidian_glass", "default:obsidian_glass", "default:obsidian_glass"},
  176. {"default:obsidian_glass", "default:obsidian_glass", "default:obsidian_glass"}
  177. }
  178. })
  179. --]]
  180. xpanes.register_pane("bar", {
  181. description = "Iron Bars",
  182. textures = {"xpanes_bar.png","xpanes_bar.png","xpanes_bar_top.png"},
  183. inventory_image = "xpanes_bar.png",
  184. wield_image = "xpanes_bar.png",
  185. groups = utility.dig_groups("pane_metal"),
  186. sounds = default.node_sound_metal_defaults(),
  187. recipe = {
  188. {"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"},
  189. {"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"}
  190. }
  191. })
  192. xpanes.register_pane("wood", {
  193. description = "Wood Pane",
  194. textures = {"doors_trapdoor.png", "xpanes_brown.png", "xpanes_brown.png"},
  195. inventory_image = "doors_trapdoor.png",
  196. wield_image = "doors_trapdoor.png",
  197. groups = utility.dig_groups("pane_wood"),
  198. sounds = default.node_sound_wood_defaults(),
  199. recipe = {
  200. {"default:wood", "default:wood"},
  201. {"default:wood", "default:wood"}
  202. }
  203. })
  204. xpanes.register_pane("iron", {
  205. description = "Wrought Iron Pane",
  206. textures = {"doors_trapdoor_iron.png", "xpanes_gray2.png", "xpanes_gray2.png"},
  207. inventory_image = "doors_trapdoor_iron.png",
  208. wield_image = "doors_trapdoor_iron.png",
  209. groups = utility.dig_groups("pane_metal"),
  210. sounds = default.node_sound_metal_defaults(),
  211. amount = 1,
  212. recipe = {
  213. {"default:iron_lump", "default:iron_lump", "default:iron_lump"},
  214. }
  215. })
  216. xpanes.register_pane("akalin", {
  217. description = "Akalin Glass Pane",
  218. textures = {"glooptest_akalin_crystal_glass.png", "xpanes_pane_half.png", "xpanes_white.png"},
  219. inventory_image = "glooptest_akalin_crystal_glass.png",
  220. wield_image = "glooptest_akalin_crystal_glass.png",
  221. sounds = default.node_sound_glass_defaults(),
  222. groups = utility.dig_groups("pane_glass"),
  223. recipe = {
  224. {"akalin:glass", "akalin:glass", "akalin:glass"},
  225. {"akalin:glass", "akalin:glass", "akalin:glass"}
  226. }
  227. })
  228. xpanes.register_pane("alatro", {
  229. description = "Alatro Glass Pane",
  230. textures = {"glooptest_alatro_crystal_glass.png", "xpanes_pane_half.png", "xpanes_white.png"},
  231. inventory_image = "glooptest_alatro_crystal_glass.png",
  232. wield_image = "glooptest_alatro_crystal_glass.png",
  233. sounds = default.node_sound_glass_defaults(),
  234. groups = utility.dig_groups("pane_glass"),
  235. recipe = {
  236. {"alatro:glass", "alatro:glass", "alatro:glass"},
  237. {"alatro:glass", "alatro:glass", "alatro:glass"}
  238. }
  239. })
  240. xpanes.register_pane("arol", {
  241. description = "Arol Glass Pane",
  242. textures = {"glooptest_arol_crystal_glass.png", "xpanes_pane_half.png", "xpanes_white.png"},
  243. inventory_image = "glooptest_arol_crystal_glass.png",
  244. wield_image = "glooptest_arol_crystal_glass.png",
  245. sounds = default.node_sound_glass_defaults(),
  246. groups = utility.dig_groups("pane_glass"),
  247. recipe = {
  248. {"arol:glass", "arol:glass", "arol:glass"},
  249. {"arol:glass", "arol:glass", "arol:glass"}
  250. }
  251. })
  252. xpanes.register_pane("talinite", {
  253. description = "Talinite Glass Pane",
  254. textures = {"glooptest_talinite_crystal_glass.png", "xpanes_pane_half.png", "xpanes_white.png"},
  255. inventory_image = "glooptest_talinite_crystal_glass.png",
  256. wield_image = "glooptest_talinite_crystal_glass.png",
  257. sounds = default.node_sound_glass_defaults(),
  258. groups = utility.dig_groups("pane_glass"),
  259. light_source = 10,
  260. recipe = {
  261. {"talinite:glass", "talinite:glass", "talinite:glass"},
  262. {"talinite:glass", "talinite:glass", "talinite:glass"}
  263. }
  264. })
  265. xpanes.register_pane("dk_glass", {
  266. description = "Clean Medieval Glass Pane",
  267. textures = {"darkage_glass.png", "xpanes_pane_half.png", "xpanes_white.png"},
  268. inventory_image = "darkage_glass.png",
  269. use_texture_alpha = "blend",
  270. wield_image = "darkage_glass.png",
  271. sounds = default.node_sound_glass_defaults(),
  272. groups = utility.dig_groups("pane_glass"),
  273. recipe = {
  274. {"darkage:glass", "darkage:glass", "darkage:glass"},
  275. {"darkage:glass", "darkage:glass", "darkage:glass"}
  276. }
  277. })
  278. xpanes.register_pane("dk_mglass", {
  279. description = "Milky Medieval Glass Pane",
  280. textures = {"darkage_milk_glass.png", "xpanes_pane_half.png", "xpanes_white.png"},
  281. inventory_image = "darkage_milk_glass.png",
  282. use_texture_alpha = "blend",
  283. wield_image = "darkage_milk_glass.png",
  284. sounds = default.node_sound_glass_defaults(),
  285. groups = utility.dig_groups("pane_glass"),
  286. recipe = {
  287. {"darkage:milk_glass", "darkage:milk_glass", "darkage:milk_glass"},
  288. {"darkage:milk_glass", "darkage:milk_glass", "darkage:milk_glass"}
  289. }
  290. })
  291. xpanes.register_pane("dk_woodframe", {
  292. description = "Wooden Framed Glass Pane",
  293. textures = {"darkage_wood_frame.png", "xpanes_pane_half.png", "xpanes_white.png"},
  294. inventory_image = "darkage_wood_frame.png",
  295. wield_image = "darkage_wood_frame.png",
  296. sounds = default.node_sound_glass_defaults(),
  297. groups = utility.dig_groups("pane_wood"),
  298. recipe = {
  299. {"darkage:wood_frame", "darkage:wood_frame", "darkage:wood_frame"},
  300. {"darkage:wood_frame", "darkage:wood_frame", "darkage:wood_frame"}
  301. }
  302. })
  303. xpanes.register_pane("dk_glass_round", {
  304. description = "Round Glass Pane",
  305. textures = {"darkage_glass_round.png", "xpanes_pane_half.png", "xpanes_white.png"},
  306. inventory_image = "darkage_glass_round.png",
  307. wield_image = "darkage_glass_round.png",
  308. sounds = default.node_sound_glass_defaults(),
  309. groups = utility.dig_groups("pane_glass"),
  310. recipe = {
  311. {"darkage:glass_round", "darkage:glass_round", "darkage:glass_round"},
  312. {"darkage:glass_round", "darkage:glass_round", "darkage:glass_round"}
  313. }
  314. })
  315. xpanes.register_pane("dk_mglass_round", {
  316. description = "Milky Medieval Round Glass Pane",
  317. textures = {"darkage_milk_glass_round.png", "xpanes_pane_half.png", "xpanes_white.png"},
  318. inventory_image = "darkage_milk_glass_round.png",
  319. wield_image = "darkage_milk_glass_round.png",
  320. sounds = default.node_sound_glass_defaults(),
  321. groups = utility.dig_groups("pane_glass"),
  322. recipe = {
  323. {"darkage:milk_glass_round", "darkage:milk_glass_round", "darkage:milk_glass_round"},
  324. {"darkage:milk_glass_round", "darkage:milk_glass_round", "darkage:milk_glass_round"}
  325. }
  326. })
  327. xpanes.register_pane("dk_glass_square", {
  328. description = "Square Glass Pane",
  329. textures = {"darkage_glass_square.png", "xpanes_pane_half.png", "xpanes_white.png"},
  330. inventory_image = "darkage_glass_square.png",
  331. wield_image = "darkage_glass_square.png",
  332. sounds = default.node_sound_glass_defaults(),
  333. groups = utility.dig_groups("pane_glass"),
  334. recipe = {
  335. {"darkage:glass_square", "darkage:glass_square", "darkage:glass_square"},
  336. {"darkage:glass_square", "darkage:glass_square", "darkage:glass_square"}
  337. }
  338. })
  339. xpanes.register_pane("dk_mglass_square", {
  340. description = "Milky Medieval Square Glass Pane",
  341. textures = {"darkage_milk_glass_square.png", "xpanes_pane_half.png", "xpanes_white.png"},
  342. inventory_image = "darkage_milk_glass_square.png",
  343. use_texture_alpha = "blend",
  344. wield_image = "darkage_milk_glass_square.png",
  345. sounds = default.node_sound_glass_defaults(),
  346. groups = utility.dig_groups("pane_glass"),
  347. recipe = {
  348. {"darkage:milk_glass_square", "darkage:milk_glass_square", "darkage:milk_glass_square"},
  349. {"darkage:milk_glass_square", "darkage:milk_glass_square", "darkage:milk_glass_square"}
  350. }
  351. })