-
Notifications
You must be signed in to change notification settings - Fork 7
/
microblocks_cleanup.lua
304 lines (254 loc) · 9.83 KB
/
microblocks_cleanup.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
--[[
NOTE: this file is mostly to deal w/ the aftermath of a snafu involving microblock node IDs after upgrading to 5.1.
We have/had multiple mods adding various kinds of microblocks
1. stairs
2. moreblocks/stairsplus
3. xdecor workbench
Each of these registers some nodes on its own. Other mods use the above to register some
nodes as well. Most of the above have changed naming schemes at some point in time, resulting in a
big pile of aliases. the load order of some things changed, resulting in aliases loading in a
different order, causing some nodes w/ old IDs to no longer be properly aliased.
Solution: remove the xdecor workbench, and replace all the relevant node names w/ moreblocks/stairsplus names
---------------------------
:: translation from xdecor workbench names to moreblocks/stairsplus names ::
sample material: default:wood
* default:wood_nanoslab -> moreblocks:micro_wood_1
* default:wood_micropanel -> moreblocks:panel_wood_1
* default:wood_microslab -> moreblocks:slab_wood_1
* default:wood_thinstair -> moreblocks:stair_wood_alt_1
* default:wood_cube -> moreblocks:micro_wood
* default:wood_panel -> moreblocks:panel_wood
* default:wood_doublepanel -> moreblocks:stair_wood_alt
* default:wood_halfstair -> moreblocks:stair_wood_half
* moreblocks:slab_wood -> moreblocks:slab_wood
* moreblocks:stair_wood_outer -> moreblocks:stair_wood_outer
* moreblocks:stair_wood -> moreblocks:stair_wood
* moreblocks:stair_wood_inner -> moreblocks:stair_wood_inner
:: stuff outside default/moreblocks typically uses its own mod name ::
------------------------------
LIST OF KNOWN UNKNOWN NODES
bakedclay:orange_microslab
bakedclay:white_doublepanel
bakedclay:white_microslab
building_blocks:smoothglass_microslab
default:cobble_thinstair
default:diamondblock_cube
default:glass_microslab
default:ice_microslab
default:obsidianbrick_thinstair
default:pine_wood_doublepanel
default:pine_wood_thinstair
default:steelblock_panel
default:stonebrick_microslab
pkarcs:cobble_arc
pkarcs:sandstone_arc
quartz:block_doublepanel
quartz:block_microslab
xdecor:woodframed_glass_microslab
-- bakedclay
stairs:slab_black
stairs:slab_blue
stairs:slab_dark_green
stairs:slab_green
stairs:slab_grey
stairs:slab_orange
stairs:slab_red
stairs:slab_white
stairs:slab_yellow
stairs:stair_black
stairs:stair_green
stairs:stair_white
stairs:stair_yellow
-- bls
stairs:slab_Marble
stairs:stair_Marble
-- building_blocks
stairs:slab_grate
stairs:stair_hardwood
-- default
stairs:slab_oak_planks
stairs:slab_birch_planks
-- moreblocks
stairs:slab_coal_stone_bricks
stairs:slab_cobble_compressed
stairs:slab_iron_stone_bricks
stairs:slab_stone_tile
stairs:slab_wood_tile
stairs:stair_cactus_brick
stairs:stair_grey_bricks
stairs:stair_split_stone_tile
-- moretrees
stairs:stair_date_palm_planks
stairs:stair_willow_planks
stairs:stair_poplar_planks
-- nether
stairs:stair_rack
-- quartz
stairs:stair_block
stairs:slab_block
-- xdecor
stairs:slab_stone_rune
]]--
local nformat = bls.util.nformat
local affected_mods = {
bakedclay=1,
basic_materials=1,
baldcypress=1,
bamboo=1,
birch=1,
bls=1,
bridger=1,
building_blocks=1,
caverealms=1,
cblocks=1,
cherrytree=1,
chestnuttree=1,
clementinetree=1,
cottages=1,
default=1,
ebony=1,
farming=1,
gravelsieve=1,
jacaranda=1,
larch=1,
lemontree=1,
mahogany=1,
maple=1,
moreblocks=1,
moreores=1,
moretrees=1,
my_door_wood=1,
nether=1,
palm=1,
pineapple=1,
pomegranate=1,
quartz=1,
redtrees=1,
sakuragi=1,
streets=1,
xdecor=1,
}
-- predicates for filtering
local function is(...)
local mods = {...}
return function(mod_name, node_name)
for _, mod in ipairs(mods) do
if mod_name == mod then
return true
end
end
return false
end
end
local function not_(fun) return function(...) return not fun(...) end end
local is_default = is("default", "moreblocks")
local function is_any() return true end
-- param2 tweaks for replacements w/ different meshes
local function rot_180(param2)
local axis = math.floor(param2 / 4)
local rotv = param2 % 4
local new_rotv = (rotv + 2) % 4
return (4 * axis) + new_rotv
end
local function rot_270(param2)
local axis = math.floor(param2 / 4)
local rotv = param2 % 4
local new_rotv = (rotv + 3) % 4
return (4 * axis) + new_rotv
end
local variants = {
-- {predicate, source_pattern, target_pattern, param2 tweak}
-- nanoslab
{is_default, "%(mod_name)s:%(node_name)s_nanoslab", "moreblocks:micro_%(node_name)s_1", rot_270},
{not_(is_default), "%(mod_name)s:%(node_name)s_nanoslab", "%(mod_name)s:micro_%(node_name)s_1", rot_270},
-- micropanel
{is_default, "%(mod_name)s:%(node_name)s_micropanel", "moreblocks:panel_%(node_name)s_1", rot_180},
{not_(is_default), "%(mod_name)s:%(node_name)s_micropanel", "%(mod_name)s:panel_%(node_name)s_1", rot_180},
-- "microslab",
{is_default, "%(mod_name)s:%(node_name)s_microslab", "moreblocks:slab_%(node_name)s_1"},
{not_(is_default), "%(mod_name)s:%(node_name)s_microslab", "%(mod_name)s:slab_%(node_name)s_1"},
--"thinstair",
{is_default, "%(mod_name)s:%(node_name)s_thinstair", "moreblocks:stair_%(node_name)s_alt_1"},
{not_(is_default), "%(mod_name)s:%(node_name)s_thinstair", "%(mod_name)s:stair_%(node_name)s_alt_1"},
--"cube",
{is_default, "%(mod_name)s:%(node_name)s_cube", "moreblocks:micro_%(node_name)s", rot_270},
{not_(is_default), "%(mod_name)s:%(node_name)s_cube", "%(mod_name)s:micro_%(node_name)s", rot_270},
--"panel",
{is_default, "%(mod_name)s:%(node_name)s_panel", "moreblocks:panel_%(node_name)s", rot_180},
{not_(is_default), "%(mod_name)s:%(node_name)s_panel", "%(mod_name)s:panel_%(node_name)s", rot_180},
--"doublepanel",
{is_default, "%(mod_name)s:%(node_name)s_doublepanel", "moreblocks:stair_%(node_name)s_alt"},
{not_(is_default), "%(mod_name)s:%(node_name)s_doublepanel", "%(mod_name)s:stair_%(node_name)s_alt"},
--"halfstair",
{is_default, "%(mod_name)s:%(node_name)s_halfstair", "moreblocks:stair_%(node_name)s_half"},
{not_(is_default), "%(mod_name)s:%(node_name)s_halfstair", "%(mod_name)s:stair_%(node_name)s_half"},
-- pkarcs
{is_default, "pkarcs:%(node_name)s_arc", "moreblocks:stair_%(node_name)s"},
{is_default, "pkarcs:%(node_name)s_outer_arc", "moreblocks:stair_%(node_name)s_outer"},
{is_default, "pkarcs:%(node_name)s_inner_arc", "moreblocks:stair_%(node_name)s_inner"},
-- stairs
{is_any, "stairs:slab_%(node_name)s", "%(mod_name)s:slab_%(node_name)s"},
{is_any, "stairs:stair_%(node_name)s", "%(mod_name)s:stair_%(node_name)s"},
{not_(is("bakedclay")), "stairs:stair_outer_%(node_name)s", "%(mod_name)s:stair_%(node_name)s_outer"},
{is("bakedclay"), "stairs:stair_outer_%(node_name)s", "%(mod_name)s:stair_baked_clay_%(node_name)s_outer"},
{not_(is("bakedclay")), "stairs:stair_inner_%(node_name)s", "%(mod_name)s:stair_%(node_name)s_inner"},
{is("bakedclay"), "stairs:stair_inner_%(node_name)s", "%(mod_name)s:stair_baked_clay_%(node_name)s_inner"},
}
local source_ids = {}
local target_by_source = {}
local existing_aliases = {}
bls.log("action", "registering microblock cleanup")
for node_id, def in pairs(minetest.registered_nodes) do
local mod_name, node_name = node_id:match("^([^:]+):([^:]+)$")
if mod_name and node_name and affected_mods[mod_name] and xdecor.stairs_valid_def(def) then
for _, variant in ipairs(variants) do
local predicate, src_fmt, tgt_fmt, rot_func = unpack(variant)
if predicate(mod_name, node_name) then
local src = nformat(src_fmt, {mod_name=mod_name, node_name=node_name})
local tgt = nformat(tgt_fmt, {mod_name=mod_name, node_name=node_name})
tgt = minetest.registered_aliases[tgt] or tgt
if minetest.registered_aliases[src] == tgt then
existing_aliases[tgt] = src
end
if tgt and minetest.registered_nodes[tgt] and
( not minetest.registered_nodes[src] -- Do not swap nodes from other mods that may have been registered with the same name
or minetest.registered_nodes[src].mod_origin == minetest.registered_nodes[tgt].mod_origin
) then
bls.log("action", "registering alias: %q -> %q", src, tgt)
table.insert(source_ids, src)
target_by_source[src] = {tgt, rot_func}
--minetest.register_alias_force(src, tgt)
else
bls.log("warning", "FAILED alias: %q -> %q", src, tgt)
end
end
end
end
end
minetest.register_lbm({
label = "microblocks cleanup 117",
name = "bls:microblocks_cleanup_117",
nodenames = source_ids,
-- for some reason, this won't work if run_at_every_load = false
run_at_every_load = true,
action = function(pos, node)
local spos = minetest.pos_to_string(pos, 0)
local src = node.name
local target = target_by_source[src]
if not target then
if not existing_aliases[src] then
bls.log("error", "no target for src %q (node %q) @ %s", src, node.name, spos)
end
return
end
local tgt, rot = unpack(target)
bls.log("action", "microblocks cleanup: replacing @ %q; %q -> %q", spos, src, tgt)
local param2 = node.param2
if rot then
local old_param2 = param2
param2 = rot(param2)
bls.log("action", "microblocks cleanup: rotating @ %q %q -> %q", spos, old_param2, param2)
end
minetest.swap_node(pos, {name=tgt, param1=node.param1, param2=param2})
end
})