2 local function is_pane(pos)
3 return minetest.get_item_group(minetest.get_node(pos).name, "pane") > 0
6 local function connects_dir(pos, name, dir)
7 local aside = vector.add(pos, minetest.facedir_to_dir(dir))
12 local connects_to = minetest.registered_nodes[name].connects_to
13 if not connects_to then
16 local list = minetest.find_nodes_in_area(aside, aside, connects_to)
25 local function swap(pos, node, name, param2)
26 if node.name == name and node.param2 == param2 then
30 minetest.set_node(pos, {name = name, param2 = param2})
33 local function update_pane(pos)
34 if not is_pane(pos) then
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)
43 local any = node.param2
47 c[dir] = connects_dir(pos, name, dir)
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)
62 swap(pos, node, name, 0)
65 swap(pos, node, name, 0)
69 minetest.register_on_placenode(function(pos, node)
70 if minetest.get_item_group(node, "pane") then
74 local dir = minetest.facedir_to_dir(i)
75 update_pane(vector.add(pos, dir))
79 minetest.register_on_dignode(function(pos)
81 local dir = minetest.facedir_to_dir(i)
82 update_pane(vector.add(pos, dir))
87 function xpanes.register_pane(name, def)
89 minetest.register_alias("xpanes:" .. name .. "_" .. i, "xpanes:" .. name .. "_flat")
92 local flatgroups = table.copy(def.groups)
94 minetest.register_node(":xpanes:" .. name .. "_flat", {
95 description = def.description,
98 is_ground_content = false,
99 sunlight_propagates = true,
100 inventory_image = def.inventory_image,
101 wield_image = def.wield_image,
102 paramtype2 = "facedir",
103 tiles = {def.textures[3], def.textures[3], def.textures[1]},
105 drop = "xpanes:" .. name .. "_flat",
109 fixed = {{-1/2, -1/2, -1/32, 1/2, 1/2, 1/32}},
113 fixed = {{-1/2, -1/2, -1/32, 1/2, 1/2, 1/32}},
115 connect_sides = { "left", "right" },
118 local groups = table.copy(def.groups)
120 groups.not_in_creative_inventory = 1
121 minetest.register_node(":xpanes:" .. name, {
122 drawtype = "nodebox",
124 is_ground_content = false,
125 sunlight_propagates = true,
126 description = def.description,
127 tiles = {def.textures[3], def.textures[3], def.textures[1]},
129 drop = "xpanes:" .. name .. "_flat",
133 fixed = {{-1/32, -1/2, -1/32, 1/32, 1/2, 1/32}},
134 connect_front = {{-1/32, -1/2, -1/2, 1/32, 1/2, -1/32}},
135 connect_left = {{-1/2, -1/2, -1/32, -1/32, 1/2, 1/32}},
136 connect_back = {{-1/32, -1/2, 1/32, 1/32, 1/2, 1/2}},
137 connect_right = {{1/32, -1/2, -1/32, 1/2, 1/2, 1/32}},
139 connects_to = {"group:pane", "group:stone", "group:glass", "group:wood", "group:tree"},
142 minetest.register_craft({
143 output = "xpanes:" .. name .. "_flat 16",
148 xpanes.register_pane("pane", {
149 description = "Glass Pane",
150 textures = {"default_glass.png","xpanes_pane_half.png","xpanes_white.png"},
151 inventory_image = "default_glass.png",
152 wield_image = "default_glass.png",
153 sounds = default.node_sound_glass_defaults(),
154 groups = {snappy=2, cracky=3, oddly_breakable_by_hand=3},
156 {"default:glass", "default:glass", "default:glass"},
157 {"default:glass", "default:glass", "default:glass"}
161 xpanes.register_pane("bar", {
162 description = "Iron bar",
163 textures = {"xpanes_bar.png","xpanes_bar.png","xpanes_bar_top.png"},
164 inventory_image = "xpanes_bar.png",
165 wield_image = "xpanes_bar.png",
167 sounds = default.node_sound_metal_defaults(),
169 {"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"},
170 {"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"}
174 minetest.register_lbm({
175 name = "xpanes:gen2",
176 nodenames = {"group:pane"},
177 action = function(pos, node)
180 local dir = minetest.facedir_to_dir(i)
181 update_pane(vector.add(pos, dir))