-
Notifications
You must be signed in to change notification settings - Fork 7
/
microblocks.lua
263 lines (233 loc) · 9.52 KB
/
microblocks.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
local get_modpath = minetest.get_modpath
local global_exists = minetest.global_exists
local registered_nodes = minetest.registered_nodes
local has_stairsplus = global_exists("stairsplus")
local has_facade = global_exists("facade")
local has_letters = minetest.get_modpath("letters")
local function most_common_in_table(t)
local counts = {}
for _, item in ipairs(t) do
counts[item] = (counts[item] or 0) + 1
end
local most_common
local count = 0
for item, item_count in pairs(counts) do
if item_count > count then
most_common = item
count = item_count
end
end
return most_common
end
local function register_letters(recipe_item)
local modname, subname = recipe_item:match("^([^:]+):([^:]+)$")
local def = registered_nodes[recipe_item]
if not def then
bls.log("warning", "microblocks: No def for %s", recipe_item)
return
end
if def.drawtype == "normal" and not registered_nodes[("%s:%s_letter_au"):format(modname, subname)] then
local tiles
if type(def.tiles) == "string" then
tiles = def.tiles
elseif type(def.tiles) == "table" and #def.tiles > 0 then
tiles = most_common_in_table(def.tiles)
end
if tiles then
letters.register_letters(modname, subname, recipe_item, def.description, tiles)
end
end
end
local function register(recipe_item, make_stairs, make_facade, make_letters, stairs_subname)
local modname, subname = recipe_item:match("^([^:]+):([^:]+)$")
if not (modname and subname) then
bls.log("warning", "microblocks: %s is not a valid name", recipe_item)
return
end
local def = registered_nodes[recipe_item]
if not def then
bls.log("warning", "microblocks: No def for %s", recipe_item)
return
end
if make_stairs == nil then make_stairs = true end
if make_facade == nil then make_facade = true end
if make_letters == nil then make_letters = false end
if has_stairsplus and make_stairs then
-- TODO: figure out a check to see if these are already registered?
stairsplus:register_all(modname, subname, recipe_item, def, stairs_subname)
end
if has_facade and make_facade then
if def.drawtype == "normal" and not registered_nodes[("facade:%s_bannerstone"):format(subname)] then
facade.register_facade_nodes(modname, subname, recipe_item, def.description or subname)
end
end
-- letter cutter: adding letters increases lag (and load time) hugely
if has_letters and make_letters then
register_letters(recipe_item)
end
end
local COLORS = {
"black", "blue", "brown", "cyan", "dark_green", "dark_grey", "green", "grey",
"magenta", "orange", "pink", "red", "violet", "white", "yellow"
}
local function register_colors(name_pattern, make_stairs, make_facade, make_letters, stairs_subname)
for _, color in ipairs(COLORS) do
register(name_pattern:format(color), make_stairs, make_facade, make_letters, stairs_subname and stairs_subname:format(color))
end
end
if get_modpath("asteroid") or get_modpath("other_worlds") then
register("asteroid:cobble", nil, false)
register("asteroid:dust", nil, false)
register("asteroid:gravel", nil, false)
register("asteroid:redcobble", nil, false)
register("asteroid:reddust", nil, false)
register("asteroid:redgravel", nil, false)
end
if get_modpath("bakedclay") then
for _, color in ipairs(COLORS) do
register_letters("bakedclay:" .. color, nil, false)
end
end
if get_modpath("basic_materials") then
register("basic_materials:brass_block", nil, false)
register("basic_materials:cement_block", nil, false)
register("basic_materials:concrete_block", nil, false)
end
if get_modpath("caverealms") then
register("caverealms:coal_dust", nil, false)
register("caverealms:glow_amethyst", nil, false)
register("caverealms:glow_amethyst_ore", nil, false)
register("caverealms:glow_crystal", nil, false)
register("caverealms:glow_emerald", nil, false)
register("caverealms:glow_emerald_ore", nil, false)
register("caverealms:glow_mese", nil, false)
-- Prevously called glow_obsidian_2, this is bad
-- Rename both to allow seamless switchover
minetest.register_node(":caverealms:glow_obsidian_hot", minetest.registered_nodes["caverealms:glow_obsidian_2"])
minetest.register_alias_force("caverealms:glow_obsidian_2", "caverealms:glow_obsidian_hot")
minetest.register_node(":caverealms:glow_obsidian_cold", minetest.registered_nodes["caverealms:glow_obsidian"])
minetest.register_alias_force("caverealms:glow_obsidian", "caverealms:glow_obsidian_cold")
register("caverealms:glow_obsidian_cold", nil, false)
register("caverealms:glow_obsidian_hot", nil, false)
stairsplus:register_alias_force_all("caverealms", "glow_obsidian", "caverealms", "glow_obsidian_cold")
stairsplus:register_alias_force_all("caverealms", "glow_obsidian_2", "caverealms", "glow_obsidian_hot")
register("caverealms:glow_ore", nil, false)
register("caverealms:glow_ruby", nil, false)
register("caverealms:glow_ruby_ore", nil, false)
register("caverealms:hot_cobble", nil, false)
register("caverealms:mushroom_cap", nil, false)
register("caverealms:mushroom_stem", nil, false)
register("caverealms:salt_crystal", nil, false)
register("caverealms:stone_with_salt", nil, false)
register("caverealms:thin_ice", nil, false)
end
if get_modpath("cblocks") then
register_colors("cblocks:glass_%s")
end
if get_modpath("cottages") then
register("cottages:hay", nil, false)
register("cottages:loam")
register("cottages:reet", nil, false)
register("cottages:slate_vertical", nil, false)
end
if get_modpath("default") then
-- for some reason, moreblocks doesn't register ice, so do this the "default" way
-- stairsplus:register_all("moreblocks", "ice", "default:ice", minetest.registered_nodes["default:ice"])
stairsplus:register_alias_force_all("default", "ice", "moreblocks", "ice")
end
if get_modpath("extra") then
register("extra:cobble_condensed", nil, false)
end
if get_modpath("farming") then
register("farming:chocolate_block", nil, false)
register("farming:hemp_block", nil, false)
end
if get_modpath("mahogany") then
local def = registered_nodes["mahogany:leaves"]
local def_copy = table.copy(def)
def_copy.drop = nil
def_copy.wield_image = nil
def_copy.inventory_image = nil
def_copy.after_place_node = function(pos, placer, itemstack, pointed_thing)
if placer and placer:is_player() then
local vertical_correction = {
[12]=15,
[14]=15,
[7]=6,
[5]=6,
[18]=17,
[16]=17,
[9]=8,
[11]=8
}
local node = minetest.get_node(pos)
local correction = vertical_correction[node.param2]
if correction then
node.param2 = correction
minetest.set_node(pos, node)
end
end
end
stairsplus:register_all("mahogany", "leaves", "mahogany:leaves", def_copy)
end
if get_modpath("mobs_animal") then
register("mobs:cheeseblock", nil, false)
register("mobs:honey_block", nil, false)
end
if get_modpath("moreores") then
register("moreores:mithril_block")
register("moreores:silver_block")
end
if get_modpath("nether") then
register("nether:glowstone")
register("nether:obsidian_enchanted")
register("nether:rack")
end
if get_modpath("redtrees") then
register("redtrees:rtree", nil, false)
register("redtrees:rwood", nil, false)
end
if get_modpath("sakuragi") then
register("sakuragi:stree", nil, false)
register("sakuragi:swood", nil, false)
end
if get_modpath("terumet") then
register("terumet:block_asphalt", nil, false, nil, "asphalt")
register("terumet:block_ceramic", nil, false)
register("terumet:block_cgls", nil, false)
register("terumet:block_coke", nil, false)
register_colors("terumet:block_con_%s", nil, false, nil, "con_%s")
register("terumet:block_dust_bio", nil, false)
register("terumet:block_entropy", nil, false)
register("terumet:block_pwood", nil, false, nil, "terumet_pwood")
register("terumet:block_raw", nil, false)
register("terumet:block_tar", nil, false)
register("terumet:block_tcha", nil, false)
register("terumet:block_tcop", nil, false)
register("terumet:block_tglass", nil, false)
register("terumet:block_tglassglow", nil, false)
register("terumet:block_tgol", nil, false)
register("terumet:block_thermese", nil, false)
register("terumet:block_tste", nil, false)
register("terumet:block_ttin", nil, false)
end
if get_modpath("titanium") then
register("titanium:block", nil, false)
register("titanium:glass", nil, false)
register("titanium:titanium_plate", nil, false)
end
if get_modpath("xdecor") then
register("xdecor:iron_lightbox", nil, false)
register("xdecor:wooden_lightbox", nil, false)
-- Already registered by xdecor:
-- register("xdecor:cactusbrick", nil, false)
-- register("xdecor:coalstone_tile", nil, false)
-- register("xdecor:desertstone_tile", nil, false)
-- register("xdecor:hard_clay", nil, false)
-- register("xdecor:moonbrick", nil, false)
-- register("xdecor:packed_ice", nil, false)
-- register("xdecor:stone_tile", nil, false)
-- register("xdecor:stone_rune", nil, false)
-- register("xdecor:woodframed_glass", nil, false)
-- register("xdecor:wood_tile", nil, false)
end