init.lua 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  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. wield_image = def.wield_image,
  104. paramtype2 = "facedir",
  105. tiles = {def.textures[3], def.textures[3], def.textures[1]},
  106. groups = flatgroups,
  107. drop = "xpanes:" .. name .. "_flat",
  108. sounds = def.sounds,
  109. light_source = def.light_source,
  110. node_box = {
  111. type = "fixed",
  112. fixed = {{-1/2, -1/2, -1/32, 1/2, 1/2, 1/32}},
  113. },
  114. selection_box = {
  115. type = "fixed",
  116. fixed = {{-1/2, -1/2, -1/32, 1/2, 1/2, 1/32}},
  117. },
  118. connect_sides = { "left", "right" },
  119. on_construct = on_construct,
  120. after_destruct = after_destruct,
  121. })
  122. local groups = table.copy(def.groups or {})
  123. groups.pane = 1
  124. groups.not_in_creative_inventory = 1
  125. minetest.register_node(":xpanes:" .. name, {
  126. drawtype = "nodebox",
  127. paramtype = "light",
  128. is_ground_content = false,
  129. sunlight_propagates = true,
  130. description = def.description,
  131. tiles = {def.textures[3], def.textures[3], def.textures[1]},
  132. groups = groups,
  133. drop = "xpanes:" .. name .. "_flat",
  134. sounds = def.sounds,
  135. light_source = def.light_source,
  136. node_box = {
  137. type = "connected",
  138. fixed = {{-1/32, -1/2, -1/32, 1/32, 1/2, 1/32}},
  139. connect_front = {{-1/32, -1/2, -1/2, 1/32, 1/2, -1/32}},
  140. connect_left = {{-1/2, -1/2, -1/32, -1/32, 1/2, 1/32}},
  141. connect_back = {{-1/32, -1/2, 1/32, 1/32, 1/2, 1/2}},
  142. connect_right = {{1/32, -1/2, -1/32, 1/2, 1/2, 1/32}},
  143. },
  144. connects_to = {"group:pane", "group:stone", "group:glass", "group:brick", "group:wood", "group:tree"},
  145. on_construct = on_construct,
  146. after_destruct = after_destruct,
  147. })
  148. minetest.register_craft({
  149. output = "xpanes:" .. name .. "_flat " .. (def.amount or 16),
  150. recipe = def.recipe
  151. })
  152. end
  153. xpanes.register_pane("pane", {
  154. description = "Glass Pane",
  155. textures = {"default_glass.png","xpanes_pane_half.png","xpanes_white.png"},
  156. inventory_image = "default_glass.png",
  157. wield_image = "default_glass.png",
  158. sounds = default.node_sound_glass_defaults(),
  159. groups = utility.dig_groups("pane_glass"),
  160. recipe = {
  161. {"default:glass", "default:glass", "default:glass"},
  162. {"default:glass", "default:glass", "default:glass"}
  163. }
  164. })
  165. ----[[
  166. xpanes.register_pane("obsidian_glass", {
  167. description = "Obsidian Glass Pane",
  168. textures = {"default_obsidian_glass.png","xpanes_pane_half.png","xpanes_white.png"},
  169. inventory_image = "default_obsidian_glass.png",
  170. wield_image = "default_obsidian_glass.png",
  171. sounds = default.node_sound_glass_defaults(),
  172. groups = utility.dig_groups("pane_glass"),
  173. recipe = {
  174. {"default:obsidian_glass", "default:obsidian_glass", "default:obsidian_glass"},
  175. {"default:obsidian_glass", "default:obsidian_glass", "default:obsidian_glass"}
  176. }
  177. })
  178. --]]
  179. xpanes.register_pane("bar", {
  180. description = "Iron Bars",
  181. textures = {"xpanes_bar.png","xpanes_bar.png","xpanes_bar_top.png"},
  182. inventory_image = "xpanes_bar.png",
  183. wield_image = "xpanes_bar.png",
  184. groups = utility.dig_groups("pane_metal"),
  185. sounds = default.node_sound_metal_defaults(),
  186. recipe = {
  187. {"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"},
  188. {"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"}
  189. }
  190. })
  191. xpanes.register_pane("wood", {
  192. description = "Wood Pane",
  193. textures = {"doors_trapdoor.png", "xpanes_brown.png", "xpanes_brown.png"},
  194. inventory_image = "doors_trapdoor.png",
  195. wield_image = "doors_trapdoor.png",
  196. groups = utility.dig_groups("pane_wood"),
  197. sounds = default.node_sound_wood_defaults(),
  198. recipe = {
  199. {"default:wood", "default:wood"},
  200. {"default:wood", "default:wood"}
  201. }
  202. })
  203. xpanes.register_pane("iron", {
  204. description = "Wrought Iron Pane",
  205. textures = {"doors_trapdoor_iron.png", "xpanes_gray2.png", "xpanes_gray2.png"},
  206. inventory_image = "doors_trapdoor_iron.png",
  207. wield_image = "doors_trapdoor_iron.png",
  208. groups = utility.dig_groups("pane_metal"),
  209. sounds = default.node_sound_metal_defaults(),
  210. amount = 1,
  211. recipe = {
  212. {"default:iron_lump", "default:iron_lump", "default:iron_lump"},
  213. }
  214. })
  215. xpanes.register_pane("akalin", {
  216. description = "Akalin Glass Pane",
  217. textures = {"glooptest_akalin_crystal_glass.png", "xpanes_pane_half.png", "xpanes_white.png"},
  218. inventory_image = "glooptest_akalin_crystal_glass.png",
  219. wield_image = "glooptest_akalin_crystal_glass.png",
  220. sounds = default.node_sound_glass_defaults(),
  221. groups = utility.dig_groups("pane_glass"),
  222. recipe = {
  223. {"akalin:glass", "akalin:glass", "akalin:glass"},
  224. {"akalin:glass", "akalin:glass", "akalin:glass"}
  225. }
  226. })
  227. xpanes.register_pane("alatro", {
  228. description = "Alatro Glass Pane",
  229. textures = {"glooptest_alatro_crystal_glass.png", "xpanes_pane_half.png", "xpanes_white.png"},
  230. inventory_image = "glooptest_alatro_crystal_glass.png",
  231. wield_image = "glooptest_alatro_crystal_glass.png",
  232. sounds = default.node_sound_glass_defaults(),
  233. groups = utility.dig_groups("pane_glass"),
  234. recipe = {
  235. {"alatro:glass", "alatro:glass", "alatro:glass"},
  236. {"alatro:glass", "alatro:glass", "alatro:glass"}
  237. }
  238. })
  239. xpanes.register_pane("arol", {
  240. description = "Arol Glass Pane",
  241. textures = {"glooptest_arol_crystal_glass.png", "xpanes_pane_half.png", "xpanes_white.png"},
  242. inventory_image = "glooptest_arol_crystal_glass.png",
  243. wield_image = "glooptest_arol_crystal_glass.png",
  244. sounds = default.node_sound_glass_defaults(),
  245. groups = utility.dig_groups("pane_glass"),
  246. recipe = {
  247. {"arol:glass", "arol:glass", "arol:glass"},
  248. {"arol:glass", "arol:glass", "arol:glass"}
  249. }
  250. })
  251. xpanes.register_pane("talinite", {
  252. description = "Talinite Glass Pane",
  253. textures = {"glooptest_talinite_crystal_glass.png", "xpanes_pane_half.png", "xpanes_white.png"},
  254. inventory_image = "glooptest_talinite_crystal_glass.png",
  255. wield_image = "glooptest_talinite_crystal_glass.png",
  256. sounds = default.node_sound_glass_defaults(),
  257. groups = utility.dig_groups("pane_glass"),
  258. light_source = 10,
  259. recipe = {
  260. {"talinite:glass", "talinite:glass", "talinite:glass"},
  261. {"talinite:glass", "talinite:glass", "talinite:glass"}
  262. }
  263. })
  264. xpanes.register_pane("dk_glass", {
  265. description = "Clean Medieval Glass Pane",
  266. textures = {"darkage_glass.png", "xpanes_pane_half.png", "xpanes_white.png"},
  267. inventory_image = "darkage_glass.png",
  268. wield_image = "darkage_glass.png",
  269. sounds = default.node_sound_glass_defaults(),
  270. groups = utility.dig_groups("pane_glass"),
  271. recipe = {
  272. {"darkage:glass", "darkage:glass", "darkage:glass"},
  273. {"darkage:glass", "darkage:glass", "darkage:glass"}
  274. }
  275. })
  276. xpanes.register_pane("dk_mglass", {
  277. description = "Milky Medieval Glass Pane",
  278. textures = {"darkage_milk_glass.png", "xpanes_pane_half.png", "xpanes_white.png"},
  279. inventory_image = "darkage_milk_glass.png",
  280. wield_image = "darkage_milk_glass.png",
  281. sounds = default.node_sound_glass_defaults(),
  282. groups = utility.dig_groups("pane_glass"),
  283. recipe = {
  284. {"darkage:milk_glass", "darkage:milk_glass", "darkage:milk_glass"},
  285. {"darkage:milk_glass", "darkage:milk_glass", "darkage:milk_glass"}
  286. }
  287. })
  288. xpanes.register_pane("dk_woodframe", {
  289. description = "Wooden Framed Glass Pane",
  290. textures = {"darkage_wood_frame.png", "xpanes_pane_half.png", "xpanes_white.png"},
  291. inventory_image = "darkage_wood_frame.png",
  292. wield_image = "darkage_wood_frame.png",
  293. sounds = default.node_sound_glass_defaults(),
  294. groups = utility.dig_groups("pane_wood"),
  295. recipe = {
  296. {"darkage:wood_frame", "darkage:wood_frame", "darkage:wood_frame"},
  297. {"darkage:wood_frame", "darkage:wood_frame", "darkage:wood_frame"}
  298. }
  299. })
  300. xpanes.register_pane("dk_glass_round", {
  301. description = "Round Glass Pane",
  302. textures = {"darkage_glass_round.png", "xpanes_pane_half.png", "xpanes_white.png"},
  303. inventory_image = "darkage_glass_round.png",
  304. wield_image = "darkage_glass_round.png",
  305. sounds = default.node_sound_glass_defaults(),
  306. groups = utility.dig_groups("pane_glass"),
  307. recipe = {
  308. {"darkage:glass_round", "darkage:glass_round", "darkage:glass_round"},
  309. {"darkage:glass_round", "darkage:glass_round", "darkage:glass_round"}
  310. }
  311. })
  312. xpanes.register_pane("dk_mglass_round", {
  313. description = "Milky Medieval Round Glass Pane",
  314. textures = {"darkage_milk_glass_round.png", "xpanes_pane_half.png", "xpanes_white.png"},
  315. inventory_image = "darkage_milk_glass_round.png",
  316. wield_image = "darkage_milk_glass_round.png",
  317. sounds = default.node_sound_glass_defaults(),
  318. groups = utility.dig_groups("pane_glass"),
  319. recipe = {
  320. {"darkage:milk_glass_round", "darkage:milk_glass_round", "darkage:milk_glass_round"},
  321. {"darkage:milk_glass_round", "darkage:milk_glass_round", "darkage:milk_glass_round"}
  322. }
  323. })
  324. xpanes.register_pane("dk_glass_square", {
  325. description = "Square Glass Pane",
  326. textures = {"darkage_glass_square.png", "xpanes_pane_half.png", "xpanes_white.png"},
  327. inventory_image = "darkage_glass_square.png",
  328. wield_image = "darkage_glass_square.png",
  329. sounds = default.node_sound_glass_defaults(),
  330. groups = utility.dig_groups("pane_glass"),
  331. recipe = {
  332. {"darkage:glass_square", "darkage:glass_square", "darkage:glass_square"},
  333. {"darkage:glass_square", "darkage:glass_square", "darkage:glass_square"}
  334. }
  335. })
  336. xpanes.register_pane("dk_mglass_square", {
  337. description = "Milky Medieval Square Glass Pane",
  338. textures = {"darkage_milk_glass_square.png", "xpanes_pane_half.png", "xpanes_white.png"},
  339. inventory_image = "darkage_milk_glass_square.png",
  340. wield_image = "darkage_milk_glass_square.png",
  341. sounds = default.node_sound_glass_defaults(),
  342. groups = utility.dig_groups("pane_glass"),
  343. recipe = {
  344. {"darkage:milk_glass_square", "darkage:milk_glass_square", "darkage:milk_glass_square"},
  345. {"darkage:milk_glass_square", "darkage:milk_glass_square", "darkage:milk_glass_square"}
  346. }
  347. })