|
1 | 1 | xpanes = {}
|
2 | 2 |
|
3 | 3 | local function rshift(x, by)
|
4 |
| - return math.floor(x / 2 ^ by) |
| 4 | + return math.floor(x / 2 ^ by) |
5 | 5 | end
|
6 | 6 |
|
7 | 7 | local directions = {
|
8 |
| - {x = 1, y = 0, z = 0}, |
9 |
| - {x = 0, y = 0, z = 1}, |
10 |
| - {x = -1, y = 0, z = 0}, |
11 |
| - {x = 0, y = 0, z = -1}, |
| 8 | + {x = 1, y = 0, z = 0}, |
| 9 | + {x = 0, y = 0, z = 1}, |
| 10 | + {x = -1, y = 0, z = 0}, |
| 11 | + {x = 0, y = 0, z = -1}, |
12 | 12 | }
|
13 | 13 |
|
14 |
| -local function update_pane(pos,name) |
15 |
| - if minetest.get_node(pos).name:find("xpanes:"..name) == nil then |
16 |
| - return |
17 |
| - end |
18 |
| - local sum = 0 |
19 |
| - for i = 1, 4 do |
20 |
| - local node = minetest.get_node({x = pos.x + directions[i].x, y = pos.y + directions[i].y, z = pos.z + directions[i].z}) |
21 |
| - local pane_num = minetest.registered_nodes[node.name].groups.pane or 0 |
22 |
| - if (minetest.registered_nodes[node.name].walkable ~= false and minetest.registered_nodes[node.name].drawtype ~= "nodebox") or pane_num > 0 then |
23 |
| - sum = sum + 2 ^ (i - 1) |
24 |
| - end |
25 |
| - end |
26 |
| - if sum == 0 then |
27 |
| - sum = 15 |
28 |
| - end |
29 |
| - minetest.set_node(pos, {name = "xpanes:"..name.."_"..sum}) |
| 14 | +local function update_pane(pos, name) |
| 15 | + if not minetest.get_node(pos).name:find("^xpanes:"..name) then |
| 16 | + return |
| 17 | + end |
| 18 | + local sum = 0 |
| 19 | + for i, dir in pairs(directions) do |
| 20 | + local node = minetest.get_node({ |
| 21 | + x = pos.x + dir.x, |
| 22 | + y = pos.y + dir.y, |
| 23 | + z = pos.z + dir.z |
| 24 | + }) |
| 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) |
| 30 | + end |
| 31 | + end |
| 32 | + if sum == 0 then |
| 33 | + sum = 15 |
| 34 | + end |
| 35 | + minetest.set_node(pos, {name = "xpanes:"..name.."_"..sum}) |
30 | 36 | end
|
31 | 37 |
|
32 |
| -local function update_nearby(pos,n) |
33 |
| - if n == nil then n = minetest.get_node(pos) end |
34 |
| - if not n or not n.name then return end |
35 |
| - local name = string.sub(n.name,8,10) |
36 |
| - if name ~= "bar" then name = "pane" end |
37 |
| - for i = 1,4 do |
38 |
| - update_pane({x = pos.x + directions[i].x, y = pos.y + directions[i].y, z = pos.z + directions[i].z}, name) |
39 |
| - end |
| 38 | +local function update_nearby(pos, node) |
| 39 | + node = node or minetest.get_node(pos) |
| 40 | + if node.name:sub(1, 7) ~= "xpanes:" then return end |
| 41 | + local underscore_pos = node.name:find("_") or 0 |
| 42 | + local name = node.name:sub(8, underscore_pos - 1) |
| 43 | + for i, dir in pairs(directions) do |
| 44 | + update_pane({ |
| 45 | + x = pos.x + dir.x, |
| 46 | + y = pos.y + dir.y, |
| 47 | + z = pos.z + dir.z |
| 48 | + }, name) |
| 49 | + end |
40 | 50 | end
|
41 | 51 |
|
42 |
| -local half_blocks = { |
43 |
| - {0, -0.5, -1/32, 0.5, 0.5, 1/32}, |
44 |
| - {-1/32, -0.5, 0, 1/32, 0.5, 0.5}, |
45 |
| - {-0.5, -0.5, -1/32, 0, 0.5, 1/32}, |
46 |
| - {-1/32, -0.5, -0.5, 1/32, 0.5, 0} |
| 52 | +local half_boxes = { |
| 53 | + {0, -0.5, -1/32, 0.5, 0.5, 1/32}, |
| 54 | + {-1/32, -0.5, 0, 1/32, 0.5, 0.5}, |
| 55 | + {-0.5, -0.5, -1/32, 0, 0.5, 1/32}, |
| 56 | + {-1/32, -0.5, -0.5, 1/32, 0.5, 0} |
47 | 57 | }
|
48 | 58 |
|
49 |
| -local full_blocks = { |
50 |
| - {-0.5, -0.5, -1/32, 0.5, 0.5, 1/32}, |
51 |
| - {-1/32, -0.5, -0.5, 1/32, 0.5, 0.5} |
| 59 | +local full_boxes = { |
| 60 | + {-0.5, -0.5, -1/32, 0.5, 0.5, 1/32}, |
| 61 | + {-1/32, -0.5, -0.5, 1/32, 0.5, 0.5} |
52 | 62 | }
|
53 | 63 |
|
54 |
| -local sb_half_blocks = { |
55 |
| - {0, -0.5, -0.06, 0.5, 0.5, 0.06}, |
56 |
| - {-0.06, -0.5, 0, 0.06, 0.5, 0.5}, |
57 |
| - {-0.5, -0.5, -0.06, 0, 0.5, 0.06}, |
58 |
| - {-0.06, -0.5, -0.5, 0.06, 0.5, 0} |
| 64 | +local sb_half_boxes = { |
| 65 | + {0, -0.5, -0.06, 0.5, 0.5, 0.06}, |
| 66 | + {-0.06, -0.5, 0, 0.06, 0.5, 0.5}, |
| 67 | + {-0.5, -0.5, -0.06, 0, 0.5, 0.06}, |
| 68 | + {-0.06, -0.5, -0.5, 0.06, 0.5, 0} |
59 | 69 | }
|
60 | 70 |
|
61 |
| -local sb_full_blocks = { |
62 |
| - {-0.5, -0.5, -0.06, 0.5, 0.5, 0.06}, |
63 |
| - {-0.06, -0.5, -0.5, 0.06, 0.5, 0.5} |
| 71 | +local sb_full_boxes = { |
| 72 | + {-0.5, -0.5, -0.06, 0.5, 0.5, 0.06}, |
| 73 | + {-0.06, -0.5, -0.5, 0.06, 0.5, 0.5} |
64 | 74 | }
|
65 |
| ---register panes and bars |
| 75 | + |
66 | 76 | function xpanes.register_pane(name, def)
|
67 |
| -for i = 1, 15 do |
68 |
| - local need = {} |
69 |
| - local cnt = 0 |
70 |
| - for j = 1, 4 do |
71 |
| - if rshift(i, j - 1) % 2 == 1 then |
72 |
| - need[j] = true |
73 |
| - cnt = cnt + 1 |
74 |
| - end |
75 |
| - end |
76 |
| - local take = {} |
77 |
| - local take2 = {} |
78 |
| - if need[1] == true and need[3] == true then |
79 |
| - need[1] = nil |
80 |
| - need[3] = nil |
81 |
| - table.insert(take, full_blocks[1]) |
82 |
| - table.insert(take2, sb_full_blocks[1]) |
83 |
| - end |
84 |
| - if need[2] == true and need[4] == true then |
85 |
| - need[2] = nil |
86 |
| - need[4] = nil |
87 |
| - table.insert(take, full_blocks[2]) |
88 |
| - table.insert(take2, sb_full_blocks[2]) |
89 |
| - end |
90 |
| - for k in pairs(need) do |
91 |
| - table.insert(take, half_blocks[k]) |
92 |
| - table.insert(take2, sb_half_blocks[k]) |
93 |
| - end |
94 |
| - local texture = def.textures[1] |
95 |
| - if cnt == 1 then |
96 |
| - texture = def.textures[1].."^"..def.textures[2] |
97 |
| - end |
98 |
| - minetest.register_node("xpanes:"..name.."_"..i, { |
99 |
| - drawtype = "nodebox", |
100 |
| - tiles = {def.textures[3], def.textures[3], texture}, |
101 |
| - paramtype = "light", |
102 |
| - groups = def.groups, |
103 |
| - drop = "xpanes:"..name, |
104 |
| - sounds = def.sounds, |
105 |
| - node_box = { |
106 |
| - type = "fixed", |
107 |
| - fixed = take |
108 |
| - }, |
109 |
| - selection_box = { |
110 |
| - type = "fixed", |
111 |
| - fixed = take2 |
112 |
| - } |
113 |
| - }) |
114 |
| -end |
| 77 | + for i = 1, 15 do |
| 78 | + local need = {} |
| 79 | + local cnt = 0 |
| 80 | + for j = 1, 4 do |
| 81 | + if rshift(i, j - 1) % 2 == 1 then |
| 82 | + need[j] = true |
| 83 | + cnt = cnt + 1 |
| 84 | + end |
| 85 | + end |
| 86 | + local take = {} |
| 87 | + local take2 = {} |
| 88 | + if need[1] == true and need[3] == true then |
| 89 | + need[1] = nil |
| 90 | + need[3] = nil |
| 91 | + table.insert(take, full_boxes[1]) |
| 92 | + table.insert(take2, sb_full_boxes[1]) |
| 93 | + end |
| 94 | + if need[2] == true and need[4] == true then |
| 95 | + need[2] = nil |
| 96 | + need[4] = nil |
| 97 | + table.insert(take, full_boxes[2]) |
| 98 | + table.insert(take2, sb_full_boxes[2]) |
| 99 | + end |
| 100 | + for k in pairs(need) do |
| 101 | + table.insert(take, half_boxes[k]) |
| 102 | + table.insert(take2, sb_half_boxes[k]) |
| 103 | + end |
| 104 | + local texture = def.textures[1] |
| 105 | + if cnt == 1 then |
| 106 | + texture = def.textures[1].."^"..def.textures[2] |
| 107 | + end |
| 108 | + minetest.register_node("xpanes:"..name.."_"..i, { |
| 109 | + drawtype = "nodebox", |
| 110 | + tiles = {def.textures[3], def.textures[3], texture}, |
| 111 | + paramtype = "light", |
| 112 | + groups = def.groups, |
| 113 | + drop = "xpanes:"..name, |
| 114 | + sounds = def.sounds, |
| 115 | + node_box = { |
| 116 | + type = "fixed", |
| 117 | + fixed = take |
| 118 | + }, |
| 119 | + selection_box = { |
| 120 | + type = "fixed", |
| 121 | + fixed = take2 |
| 122 | + } |
| 123 | + }) |
| 124 | + end |
115 | 125 |
|
116 |
| -minetest.register_node("xpanes:"..name, def) |
| 126 | + minetest.register_node("xpanes:"..name, def) |
117 | 127 |
|
118 |
| -minetest.register_craft({ |
119 |
| - output = "xpanes:"..name.." 16", |
120 |
| - recipe = def.recipe |
121 |
| -}) |
| 128 | + minetest.register_craft({ |
| 129 | + output = "xpanes:"..name.." 16", |
| 130 | + recipe = def.recipe |
| 131 | + }) |
122 | 132 | end
|
123 | 133 |
|
124 | 134 | minetest.register_on_placenode(update_nearby)
|
125 | 135 | minetest.register_on_dignode(update_nearby)
|
126 | 136 |
|
127 | 137 | xpanes.register_pane("pane", {
|
128 |
| - description = "Glass Pane", |
129 |
| - tiles = {"xpanes_space.png"}, |
130 |
| - drawtype = "airlike", |
131 |
| - paramtype = "light", |
132 |
| - sunlight_propagates = true, |
133 |
| - walkable = false, |
134 |
| - pointable = false, |
135 |
| - diggable = false, |
136 |
| - buildable_to = true, |
137 |
| - air_equivalent = true, |
138 |
| - textures = {"default_glass.png","xpanes_pane_half.png","xpanes_white.png"}, |
139 |
| - inventory_image = "default_glass.png", |
140 |
| - wield_image = "default_glass.png", |
141 |
| - sounds = default.node_sound_glass_defaults(), |
142 |
| - groups = {snappy=2,cracky=3,oddly_breakable_by_hand=3,pane=1}, |
143 |
| - on_construct = function(pos) |
144 |
| - update_pane(pos, "pane") |
145 |
| - end, |
146 |
| - recipe = { |
| 138 | + description = "Glass Pane", |
| 139 | + tiles = {"xpanes_space.png"}, |
| 140 | + drawtype = "airlike", |
| 141 | + paramtype = "light", |
| 142 | + sunlight_propagates = true, |
| 143 | + walkable = false, |
| 144 | + pointable = false, |
| 145 | + diggable = false, |
| 146 | + buildable_to = true, |
| 147 | + air_equivalent = true, |
| 148 | + textures = {"default_glass.png","xpanes_pane_half.png","xpanes_white.png"}, |
| 149 | + inventory_image = "default_glass.png", |
| 150 | + wield_image = "default_glass.png", |
| 151 | + sounds = default.node_sound_glass_defaults(), |
| 152 | + groups = {snappy=2, cracky=3, oddly_breakable_by_hand=3, pane=1}, |
| 153 | + on_construct = function(pos) |
| 154 | + update_pane(pos, "pane") |
| 155 | + end, |
| 156 | + recipe = { |
147 | 157 | {'default:glass', 'default:glass', 'default:glass'},
|
148 |
| - {'default:glass', 'default:glass', 'default:glass'} |
| 158 | + {'default:glass', 'default:glass', 'default:glass'} |
149 | 159 | }
|
150 | 160 | })
|
151 | 161 |
|
152 | 162 | xpanes.register_pane("bar", {
|
153 |
| - description = "Iron bar", |
154 |
| - tiles = {"xpanes_space.png"}, |
155 |
| - drawtype = "airlike", |
156 |
| - paramtype = "light", |
157 |
| - sunlight_propagates = true, |
158 |
| - walkable = false, |
159 |
| - pointable = false, |
160 |
| - diggable = false, |
161 |
| - buildable_to = true, |
162 |
| - air_equivalent = true, |
163 |
| - textures = {"xpanes_bar.png","xpanes_bar.png","xpanes_space.png"}, |
164 |
| - inventory_image = "xpanes_bar.png", |
165 |
| - wield_image = "xpanes_bar.png", |
166 |
| - groups = {snappy=2,cracky=3,oddly_breakable_by_hand=3,pane=1}, |
167 |
| - sounds = default.node_sound_stone_defaults(), |
168 |
| - on_construct = function(pos) |
169 |
| - update_pane(pos, "bar") |
170 |
| - end, |
171 |
| - recipe = { |
| 163 | + description = "Iron bar", |
| 164 | + tiles = {"xpanes_space.png"}, |
| 165 | + drawtype = "airlike", |
| 166 | + paramtype = "light", |
| 167 | + sunlight_propagates = true, |
| 168 | + walkable = false, |
| 169 | + pointable = false, |
| 170 | + diggable = false, |
| 171 | + buildable_to = true, |
| 172 | + air_equivalent = true, |
| 173 | + textures = {"xpanes_bar.png","xpanes_bar.png","xpanes_space.png"}, |
| 174 | + inventory_image = "xpanes_bar.png", |
| 175 | + wield_image = "xpanes_bar.png", |
| 176 | + groups = {snappy=2, cracky=3, oddly_breakable_by_hand=3, pane=1}, |
| 177 | + sounds = default.node_sound_stone_defaults(), |
| 178 | + on_construct = function(pos) |
| 179 | + update_pane(pos, "bar") |
| 180 | + end, |
| 181 | + recipe = { |
172 | 182 | {'default:steel_ingot', 'default:glass', 'default:glass'},
|
173 |
| - {'default:glass', 'default:glass', 'default:glass'} |
| 183 | + {'default:glass', 'default:glass', 'default:glass'} |
174 | 184 | }
|
175 | 185 | })
|
| 186 | + |
0 commit comments