Version 0.41.3
[MineClone/MineClone2/MineClone2-Fixes.git] / mods / ITEMS / xpanes / init.lua
blob1b540ee6965b916b773243ebec45c9603bcd004f
2 local function is_pane(pos)
3 return minetest.get_item_group(minetest.get_node(pos).name, "pane") > 0
4 end
6 local function connects_dir(pos, name, dir)
7 local aside = vector.add(pos, minetest.facedir_to_dir(dir))
8 if is_pane(aside) then
9 return true
10 end
12 local connects_to = minetest.registered_nodes[name].connects_to
13 if not connects_to then
14 return false
15 end
16 local list = minetest.find_nodes_in_area(aside, aside, connects_to)
18 if #list > 0 then
19 return true
20 end
22 return false
23 end
25 local function swap(pos, node, name, param2)
26 if node.name == name and node.param2 == param2 then
27 return
28 end
30 minetest.set_node(pos, {name = name, param2 = param2})
31 end
33 local function update_pane(pos)
34 if not is_pane(pos) then
35 return
36 end
37 local node = minetest.get_node(pos)
38 local name = node.name
39 if name:sub(-5) == "_flat" then
40 name = name:sub(1, -6)
41 end
43 local any = node.param2
44 local c = {}
45 local count = 0
46 for dir = 0, 3 do
47 c[dir] = connects_dir(pos, name, dir)
48 if c[dir] then
49 any = dir
50 count = count + 1
51 end
52 end
54 if count == 0 then
55 swap(pos, node, name .. "_flat", any)
56 elseif count == 1 then
57 swap(pos, node, name .. "_flat", (any + 1) % 4)
58 elseif count == 2 then
59 if (c[0] and c[2]) or (c[1] and c[3]) then
60 swap(pos, node, name .. "_flat", (any + 1) % 4)
61 else
62 swap(pos, node, name, 0)
63 end
64 else
65 swap(pos, node, name, 0)
66 end
67 end
69 minetest.register_on_placenode(function(pos, node)
70 if minetest.get_item_group(node, "pane") then
71 update_pane(pos)
72 end
73 for i = 0, 3 do
74 local dir = minetest.facedir_to_dir(i)
75 update_pane(vector.add(pos, dir))
76 end
77 end)
79 minetest.register_on_dignode(function(pos)
80 for i = 0, 3 do
81 local dir = minetest.facedir_to_dir(i)
82 update_pane(vector.add(pos, dir))
83 end
84 end)
86 xpanes = {}
87 function xpanes.register_pane(name, def)
88 for i = 1, 15 do
89 minetest.register_alias("xpanes:" .. name .. "_" .. i, "xpanes:" .. name .. "_flat")
90 end
92 local flatgroups = table.copy(def.groups)
93 local drop = def.drop
94 if not drop then
95 drop = "xpanes:" .. name .. "_flat"
96 end
97 flatgroups.pane = 1
98 flatgroups.deco_block = 1
99 minetest.register_node(":xpanes:" .. name .. "_flat", {
100 description = def.description,
101 _doc_items_create_entry = def._doc_items_create_entry,
102 _doc_items_entry_name = def._doc_items_entry_name,
103 _doc_items_longdesc = def._doc_items_longdesc,
104 _doc_items_usagehelp = def._doc_items_usagehelp,
105 drawtype = "nodebox",
106 paramtype = "light",
107 is_ground_content = false,
108 sunlight_propagates = true,
109 inventory_image = def.inventory_image,
110 wield_image = def.wield_image,
111 paramtype2 = "facedir",
112 tiles = {def.textures[3], def.textures[2], def.textures[1]},
113 use_texture_alpha = def.use_texture_alpha,
114 groups = flatgroups,
115 drop = drop,
116 sounds = def.sounds,
117 node_box = {
118 type = "fixed",
119 fixed = {{-1/2, -1/2, -1/32, 1/2, 1/2, 1/32}},
121 selection_box = {
122 type = "fixed",
123 fixed = {{-1/2, -1/2, -1/32, 1/2, 1/2, 1/32}},
125 connect_sides = { "left", "right" },
126 _mcl_blast_resistance = def._mcl_blast_resistance,
127 _mcl_hardness = def._mcl_hardness,
130 local groups = table.copy(def.groups)
131 groups.pane = 1
132 groups.not_in_creative_inventory = 1
133 minetest.register_node(":xpanes:" .. name, {
134 drawtype = "nodebox",
135 paramtype = "light",
136 is_ground_content = false,
137 sunlight_propagates = true,
138 description = def.description,
139 _doc_items_create_entry = false,
140 tiles = {def.textures[3], def.textures[2], def.textures[1]},
141 use_texture_alpha = def.use_texture_alpha,
142 groups = groups,
143 drop = "xpanes:" .. name .. "_flat",
144 sounds = def.sounds,
145 node_box = {
146 type = "connected",
147 fixed = {{-1/32, -1/2, -1/32, 1/32, 1/2, 1/32}},
148 connect_front = {{-1/32, -1/2, -1/2, 1/32, 1/2, -1/32}},
149 connect_left = {{-1/2, -1/2, -1/32, -1/32, 1/2, 1/32}},
150 connect_back = {{-1/32, -1/2, 1/32, 1/32, 1/2, 1/2}},
151 connect_right = {{1/32, -1/2, -1/32, 1/2, 1/2, 1/32}},
153 connects_to = {"group:pane", "group:stone", "group:glass", "group:wood", "group:tree"},
154 drop = drop,
155 _mcl_blast_resistance = def._mcl_blast_resistance,
156 _mcl_hardness = def._mcl_hardness,
159 minetest.register_craft({
160 output = "xpanes:" .. name .. "_flat 16",
161 recipe = def.recipe
164 if minetest.get_modpath("doc") then
165 doc.add_entry_alias("nodes", "xpanes:" .. name .. "_flat", "nodes", "xpanes:" .. name)
169 -- Register glass pane (stained and unstained)
170 local pane = function(description, node, append)
171 local texture1
173 -- Special case: Default (unstained) glass texture
174 if append == "_natural" then
175 texture1 = "default_glass.png"
176 else
177 texture1 = "mcl_core_glass"..append..".png"
179 xpanes.register_pane("pane"..append, {
180 description = description,
181 _doc_items_longdesc = "Glass panes are thin layers of glass which neatly connect to their neighbors as you build them.",
182 textures = {texture1, texture1, "xpanes_top_glass"..append..".png"},
183 use_texture_alpha = true,
184 inventory_image = texture1,
185 wield_image = texture1,
186 sounds = mcl_sounds.node_sound_glass_defaults(),
187 groups = {handy=1, material_glass=1},
188 recipe = {
189 {node, node, node},
190 {node, node, node},
192 drop = "",
193 _mcl_blast_resistance = 1.5,
194 _mcl_hardness = 0.3,
198 -- Iron Bars
199 xpanes.register_pane("bar", {
200 description = "Iron Bars",
201 _doc_items_longdesc = "Iron bars neatly connect to their neighbors as you build them.",
202 textures = {"xpanes_pane_iron.png","xpanes_pane_iron.png","xpanes_top_iron.png"},
203 inventory_image = "xpanes_pane_iron.png",
204 wield_image = "xpanes_pane_iron.png",
205 groups = {pickaxey=1},
206 sounds = mcl_sounds.node_sound_metal_defaults(),
207 recipe = {
208 {"mcl_core:iron_ingot", "mcl_core:iron_ingot", "mcl_core:iron_ingot"},
209 {"mcl_core:iron_ingot", "mcl_core:iron_ingot", "mcl_core:iron_ingot"},
211 _mcl_blast_resistance = 30,
212 _mcl_hardness = 5,
215 -- Glass Pane
216 pane("Glass Pane", "mcl_core:glass", "_natural") -- triggers special case
218 -- Stained Glass Pane
219 pane("Red Stained Glass Pane", "mcl_core:glass_red", "_red")
220 pane("Green Stained Glass Pane", "mcl_core:glass_green", "_green")
221 pane("Blue Stained Glass Pane", "mcl_core:glass_blue", "_blue")
222 pane("Light Blue Stained Glass Pane", "mcl_core:glass_light_blue", "_light_blue")
223 pane("Black Stained Glass Pane", "mcl_core:glass_black", "_black")
224 pane("White Stained Glass Pane", "mcl_core:glass_white", "_white")
225 pane("Yellow Stained Glass Pane", "mcl_core:glass_yellow", "_yellow")
226 pane("Brown Stained Glass Pane", "mcl_core:glass_brown", "_brown")
227 pane("Orange Stained Glass Pane", "mcl_core:glass_orange", "_orange")
228 pane("Pink Stained Glass Pane", "mcl_core:glass_pink", "_pink")
229 pane("Grey Stained Glass Pane", "mcl_core:glass_gray", "_gray")
230 pane("Lime Stained Glass Pane", "mcl_core:glass_lime", "_lime")
231 pane("Light Grey Stained Glass Pane", "mcl_core:glass_silver", "_silver")
232 pane("Magenta Stained Glass Pane", "mcl_core:glass_magenta", "_magenta")
233 pane("Purple Stained Glass Pane", "mcl_core:glass_purple", "_purple")
234 pane("Cyan Stained Glass Pane", "mcl_core:glass_cyan", "_cyan")