3 local function rshift(x, by)
4 return math.floor(x / 2 ^ by)
10 {x = -1, y = 0, z = 0},
11 {x = 0, y = 0, z = -1},
14 local function update_pane(pos, name)
15 if not minetest.get_node(pos).name:find("^xpanes:"..name) then
19 for i, dir in pairs(directions) do
20 local node = minetest.get_node({
25 local def = minetest.registered_nodes[node.name]
26 local pane_num = def and def.groups.pane or 0
27 if pane_num > 0 or not def or (def.walkable ~= false and
28 def.drawtype ~= "nodebox") then
29 sum = sum + 2 ^ (i - 1)
35 minetest.set_node(pos, {name = "xpanes:"..name.."_"..sum})
38 local function update_nearby(pos, node)
39 node = node or minetest.get_node(pos)
40 local name = node.name
41 if not name or node.name:sub(1, 7) ~= "xpanes:" then
44 local underscore_pos = string.find(name, "_[^_]*$") or 0
45 local len = name:len()
46 local num = tonumber(name:sub(underscore_pos+1, len))
47 if not num or num < 1 or num > 15 then
50 name = name:sub(8, underscore_pos - 1)
52 for i, dir in pairs(directions) do
62 {0, -0.5, -1/32, 0.5, 0.5, 1/32},
63 {-1/32, -0.5, 0, 1/32, 0.5, 0.5},
64 {-0.5, -0.5, -1/32, 0, 0.5, 1/32},
65 {-1/32, -0.5, -0.5, 1/32, 0.5, 0}
69 {-0.5, -0.5, -1/32, 0.5, 0.5, 1/32},
70 {-1/32, -0.5, -0.5, 1/32, 0.5, 0.5}
73 local sb_half_boxes = {
74 {0, -0.5, -0.06, 0.5, 0.5, 0.06},
75 {-0.06, -0.5, 0, 0.06, 0.5, 0.5},
76 {-0.5, -0.5, -0.06, 0, 0.5, 0.06},
77 {-0.06, -0.5, -0.5, 0.06, 0.5, 0}
80 local sb_full_boxes = {
81 {-0.5, -0.5, -0.06, 0.5, 0.5, 0.06},
82 {-0.06, -0.5, -0.5, 0.06, 0.5, 0.5}
85 function xpanes.register_pane(name, def)
90 if rshift(i, j - 1) % 2 == 1 then
97 if need[1] == true and need[3] == true then
100 table.insert(take, full_boxes[1])
101 table.insert(take2, sb_full_boxes[1])
103 if need[2] == true and need[4] == true then
106 table.insert(take, full_boxes[2])
107 table.insert(take2, sb_full_boxes[2])
109 for k in pairs(need) do
110 table.insert(take, half_boxes[k])
111 table.insert(take2, sb_half_boxes[k])
113 local texture = def.textures[1]
115 texture = def.textures[1].."^"..def.textures[2]
117 minetest.register_node(":xpanes:"..name.."_"..i, {
118 drawtype = "nodebox",
119 tiles = {def.textures[3], def.textures[3], texture},
122 drop = "xpanes:"..name,
135 def.on_construct = function(pos)
136 update_pane(pos, name)
139 minetest.register_node(":xpanes:"..name, def)
141 minetest.register_craft({
142 output = "xpanes:"..name.." 16",
147 minetest.register_on_placenode(update_nearby)
148 minetest.register_on_dignode(update_nearby)
150 xpanes.register_pane("pane", {
151 description = "Glass Pane",
152 tiles = {"xpanes_space.png"},
153 drawtype = "airlike",
155 is_ground_content = false,
156 sunlight_propagates = true,
161 air_equivalent = true,
162 textures = {"default_glass.png","xpanes_pane_half.png","xpanes_white.png"},
163 inventory_image = "default_glass.png",
164 wield_image = "default_glass.png",
165 sounds = default.node_sound_glass_defaults(),
166 groups = {snappy=2, cracky=3, oddly_breakable_by_hand=3, pane=1},
168 {'default:glass', 'default:glass', 'default:glass'},
169 {'default:glass', 'default:glass', 'default:glass'}
173 xpanes.register_pane("bar", {
174 description = "Iron bar",
175 tiles = {"xpanes_space.png"},
176 drawtype = "airlike",
178 is_ground_content = false,
179 sunlight_propagates = true,
184 air_equivalent = true,
185 textures = {"xpanes_bar.png","xpanes_bar.png","xpanes_space.png"},
186 inventory_image = "xpanes_bar.png",
187 wield_image = "xpanes_bar.png",
188 groups = {snappy=2, cracky=3, oddly_breakable_by_hand=3, pane=1},
189 sounds = default.node_sound_stone_defaults(),
191 {'default:steel_ingot', 'default:steel_ingot', 'default:steel_ingot'},
192 {'default:steel_ingot', 'default:steel_ingot', 'default:steel_ingot'}