37
37
38
38
local function update_nearby (pos , node )
39
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 )
40
+ local name = node .name
41
+ if not name or node .name :sub (1 , 7 ) ~= " xpanes:" then
42
+ return
43
+ end
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
48
+ name = name :sub (8 )
49
+ else
50
+ name = name :sub (8 , underscore_pos - 1 )
51
+ end
43
52
for i , dir in pairs (directions ) do
44
53
update_pane ({
45
54
x = pos .x + dir .x ,
@@ -105,7 +114,7 @@ function xpanes.register_pane(name, def)
105
114
if cnt == 1 then
106
115
texture = def .textures [1 ].. " ^" .. def .textures [2 ]
107
116
end
108
- minetest .register_node (" xpanes:" .. name .. " _" .. i , {
117
+ minetest .register_node (" : xpanes:" .. name .. " _" .. i , {
109
118
drawtype = " nodebox" ,
110
119
tiles = {def .textures [3 ], def .textures [3 ], texture },
111
120
paramtype = " light" ,
@@ -123,7 +132,11 @@ function xpanes.register_pane(name, def)
123
132
})
124
133
end
125
134
126
- minetest .register_node (" xpanes:" .. name , def )
135
+ def .on_construct = function (pos )
136
+ update_pane (pos , name )
137
+ end
138
+
139
+ minetest .register_node (" :xpanes:" .. name , def )
127
140
128
141
minetest .register_craft ({
129
142
output = " xpanes:" .. name .. " 16" ,
@@ -150,9 +163,6 @@ xpanes.register_pane("pane", {
150
163
wield_image = " default_glass.png" ,
151
164
sounds = default .node_sound_glass_defaults (),
152
165
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
166
recipe = {
157
167
{' default:glass' , ' default:glass' , ' default:glass' },
158
168
{' default:glass' , ' default:glass' , ' default:glass' }
@@ -175,9 +185,6 @@ xpanes.register_pane("bar", {
175
185
wield_image = " xpanes_bar.png" ,
176
186
groups = {snappy = 2 , cracky = 3 , oddly_breakable_by_hand = 3 , pane = 1 },
177
187
sounds = default .node_sound_stone_defaults (),
178
- on_construct = function (pos )
179
- update_pane (pos , " bar" )
180
- end ,
181
188
recipe = {
182
189
{' default:steel_ingot' , ' default:steel_ingot' , ' default:steel_ingot' },
183
190
{' default:steel_ingot' , ' default:steel_ingot' , ' default:steel_ingot' }
0 commit comments