Repository navigation
Expand file tree
/
Copy pathrectifications.lua
More file actions
345 lines (298 loc) · 11.5 KB
/
Copy pathrectifications.lua
File metadata and controls
345 lines (298 loc) · 11.5 KB
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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
-- Generalist file for rectifying the sins of mods.
local function enable_citadella_for_containers()
-- global: containers should be Citadella aware.
if not minetest.get_modpath("citadella") then
return
end
local containers = {
"xdecor:mailbox", "xdecor:multishelf", "xdecor:cabinet_half",
"xdecor:empty_shelf", "xdecor:cabinet", "bones:bones", "citadella:chest"
}
for _,name in ipairs(containers) do
local olddef = core.registered_nodes[name]
if olddef then
local def = ct.override_definition(olddef)
minetest.register_node(":"..name, def)
end
end
end
local function enable_prisonpearl_tracking_for_containers()
-- global: containers should be PrisonPearl aware.
if not minetest.get_modpath("prisonpearl") then
return
end
local containers = {
"xdecor:hive", "xdecor:enchantment_table", "xdecor:mailbox", "xdecor:workbench",
"xdecor:itemframe",
"xdecor:multishelf", "xdecor:cabinet_half",
"xdecor:empty_shelf", "xdecor:cabinet", "xdecor:workbench", "bones:bones",
"citadella:furnace", "citadella:chest"
}
for k,_ in pairs(simplecrafting_lib.type) do
local node_name = "civindustry:" .. k
local node_def = minetest.registered_nodes[node_name]
if node_def then
containers[#containers + 1] = node_name
end
end
for _,name in ipairs(containers) do
local olddef = core.registered_nodes[name]
if olddef then
local def = pp.override_definition(olddef)
minetest.register_node(":"..name, def)
end
end
end
local function disable_xdecor_hammer()
-- xdecor: disable the hammer recipe so that players can't repair their tools in
-- an xdecor:workbench.
if minetest.get_modpath("xdecor") then
minetest.clear_craft({ output = "xdecor:hammer" })
end
end
local function disable_xdecor_enderchest()
-- xdecor: disable the enderchest. No config variable, nice.
if minetest.get_modpath("xdecor") then
minetest.unregister_item("xdecor:enderchest")
end
end
local function disable_xdecor_cauldron()
-- xdecor: disable the cauldron. Again, no config variable, nice.
-- At least we might want this one in the future.
if minetest.get_modpath("xdecor") then
minetest.unregister_item("xdecor:cauldron_empty")
end
end
local function enable_diggable_containers()
-- global: containers should always be breakable, and should always drop
-- their contents, and should not allow transfer of items with the
-- 'undroppable' group.
--
-- We prioritise this at all costs, even if it's hamfisted; we NEVER want
-- players placing indestructible nodes. EVER.
local sinners = {
"xdecor:hive", "xdecor:enchantment_table", "xdecor:mailbox", "xdecor:workbench",
"xdecor:itemframe", "default:bookshelf",
"xdecor:multishelf",
"xdecor:cabinet_half", "xdecor:empty_shelf", "xdecor:cabinet", "xdecor:workbench",
"bones:bones", "vessels:shelf", "citadella:chest", "default:chest",
"fancy_vend:player_vendor"
}
for k,_ in pairs(simplecrafting_lib.type) do
local node_name = "civindustry:" .. k
local node_def = minetest.registered_nodes[node_name]
if node_def then
sinners[#sinners + 1] = node_name
end
local node_name_active = node_name .. "_active"
local node_def_active = minetest.registered_nodes[node_name_active]
if node_def_active then
sinners[#sinners + 1] = node_name_active
end
end
for _,name in ipairs(sinners) do
local olddef = core.registered_nodes[name]
if olddef then
local def = table.copy(olddef)
def.can_dig = function(pos)
return true
end
if def.name ~= "fancy_vend:player_vendor" then
def.on_dig = minetest.node_dig
end
def.after_dig_node = function(pos, old, meta, digger)
local drops = {}
for inv_name, inv_contents in pairs(meta.inventory) do
if inv_name == "forms" and def.name == "xdecor:workbench" then
-- "forms" is used by xdecor:workbench as an output preview,
-- so we don't want to drop them
goto continue
end
if (inv_name == "wanted_item" or inv_name == "given_item")
and def.name == "fancy_vend:player_vendor"
then
-- fancy_vend uses some inventories for presentation purposes,
-- but they don't store actual items. So, don't drop 'em.
goto continue
end
for _, stack in ipairs(inv_contents) do
local item = stack:to_string()
if item ~= "" then
drops[#drops + 1] = item
end
end
::continue::
end
minetest.handle_node_drops(pos, drops, digger)
end
local old_amip = def.allow_metadata_inventory_put
def.allow_metadata_inventory_put = function(pos, listname, index,
stack, player)
local idef = stack:get_definition()
if idef and idef.groups and idef.groups.undroppable then
return 0
end
if old_amip then
return old_amip(pos, listname, index, stack, player)
else
return stack:get_count()
end
end
local old_amit = def.allow_metadata_inventory_take
def.allow_metadata_inventory_take = function(pos, listname, index,
stack, player)
local idef = stack:get_definition()
if idef and idef.groups and idef.groups.undroppable then
return 0
end
if old_amit then
return old_amit(pos, listname, index, stack, player)
else
return stack:get_count()
end
end
minetest.register_node(":" .. name, def)
end
end
end
local function fix_xdecor_breakable_chairs()
-- xdecor: Fix chair invincibility, and fix the consequences of vincibility.
-- Specifically, reset player physics overrides, animations, and eye locations.
if not minetest.get_modpath("xdecor") then
return
end
local new_sit_dig = function(pos, digger)
for _, player in pairs(minetest.get_objects_inside_radius(pos, 0.1)) do
if player:is_player()
and default.player_attached[player:get_player_name()]
then
default.player_attached[player:get_player_name()] = false
default.player_set_animation(player, "stand", 30)
player:set_eye_offset({x=0,y=0,z=0},{x=0,y=0,z=0})
player:set_physics_override({speed = 1, jump = 1, gravity = 1})
end
end
return true
end
core.registered_nodes["xdecor:chair"].can_dig = new_sit_dig
core.registered_nodes["xdecor:cushion"].can_dig = new_sit_dig
end
local function enable_ore_infotexts()
-- global: ores should announce what they are.
local ores = {
"default:stone_with_coal", "default:stone_with_copper",
"default:stone_with_tin", "default:stone_with_iron",
"default:stone_with_gold", "default:stone_with_diamond",
"default:stone_with_mese"
}
for _,name in ipairs(ores) do
local olddef = core.registered_nodes[name]
if olddef then
local def = table.copy(olddef)
def.on_rightclick = function(pos, node, clicker)
if clicker:is_player() then
local pname = clicker:get_player_name()
minetest.chat_send_player(
pname, "This is a block of " .. def.description .. "."
)
end
end
minetest.register_node(":" .. name, def)
end
end
end
local function enable_floodable_flora()
for name,def in pairs(core.registered_nodes) do
local groups = def.groups
if groups.flora
or groups.food_mushroom
then
local newdef = table.copy(def)
newdef.floodable = true
newdef.on_flood = function(pos, oldnode, newnode)
if not minetest.is_protected(pos) then
minetest.dig_node(pos)
return false
else
return true
end
end
minetest.register_node(":" .. name, newdef)
end
end
end
-- ties into xdecor things above but applicable globally. Players, if damaged,
-- should have physics/attachment/anim/camera state reverted to vanilla.
--
-- We also want to close any formspecs they have open. The docs suggest that
-- this is dangerous though. We'll see.
--
minetest.register_on_player_hpchange(function(player, hp_change, reason)
if default.player_attached[player:get_player_name()] then
player:set_physics_override({speed = 1, jump = 1, gravity = 1})
default.player_attached[player:get_player_name()] = false
default.player_set_animation(player, "stand", 30)
player:set_eye_offset({x=0,y=0,z=0},{x=0,y=0,z=0})
minetest.close_formspec(player:get_player_name(), "")
end
end, false)
minetest.register_on_respawnplayer(function(player)
default.player_attached[player:get_player_name()] = false
player:set_physics_override({speed = 1, jump = 1, gravity = 1})
default.player_set_animation(player, "stand", 30)
player:set_eye_offset({x=0,y=0,z=0},{x=0,y=0,z=0})
end)
minetest.register_on_mods_loaded(function()
disable_xdecor_hammer()
disable_xdecor_enderchest()
disable_xdecor_cauldron()
enable_diggable_containers()
enable_citadella_for_containers()
enable_prisonpearl_tracking_for_containers()
fix_xdecor_breakable_chairs()
enable_ore_infotexts()
enable_floodable_flora()
minetest.debug("[CivMisc] Rectifications initialised.")
end)
-- Transform all chests into Citadella ones.
if minetest.get_modpath("citadella") then
minetest.register_lbm({
label = "civmisc:chest fixer",
name = "civmisc:chest_fixer2",
nodenames = { "default:chest" },
action = function(pos, node)
local old_meta = minetest.get_meta(pos)
local old_inv = old_meta:get_inventory()
local old_invlist_main = table.copy(old_inv:get_list("main"))
minetest.remove_node(pos)
minetest.set_node(
pos, { name = "citadella:chest", param1 = 0, param2 = 0}
)
local new_meta = minetest.get_meta(pos)
local new_inv = new_meta:get_inventory()
new_inv:set_list("main", old_invlist_main)
end
})
minetest.register_lbm({
label = "civmisc:chest locked fixer",
name = "civmisc:chest_locked_fixer",
nodenames = { "default:chest_locked" },
run_at_every_load = true,
action = function(pos, node)
local old_meta = minetest.get_meta(pos)
local old_inv = old_meta:get_inventory()
local old_invlist_main = table.copy(old_inv:get_list("main"))
minetest.remove_node(pos)
minetest.set_node(
pos, { name = "citadella:chest", param1 = 0, param2 = 0}
)
local new_meta = minetest.get_meta(pos)
local new_inv = new_meta:get_inventory()
new_inv:set_list("main", old_invlist_main)
new_inv:add_item("main", "default:steel_ingot")
end
})
minetest.log(
"[CivMisc] default:chest --> citadella:chest transformer LBM is active!"
)
end