-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
89 lines (74 loc) · 2.31 KB
/
init.lua
File metadata and controls
89 lines (74 loc) · 2.31 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
local tool_wear = core.settings:get_bool("tool_wear", true)
local weapon_wear = core.settings:get_bool("weapon_wear", true)
local armor_wear = core.settings:get_bool("armor_wear", true)
core.register_on_mods_loaded(function()
-- hook into ItemStack meta table method
if not weapon_wear then
local mt = getmetatable(ItemStack(""))
local add_wear_old = mt.add_wear
mt.add_wear = function(self, ...)
local r_item = core.registered_items[self:get_name()]
if r_item and r_item.subtype == "weapon" then
return true
end
return add_wear_old(self, ...)
end
end
-- hook into 3d_armor API
--[[ doesn't seem to be necessary if "armor_use" set to "0" or "nil"
if not armor_wear and core.global_exists("armor") then
local armor_damage_old, armor_punch_old = armor.damage, armor.punch
armor.damage = function(self, player, index, stack, use)
return armor_damage_old(self, player, index, stack, 0)
end
armor.punch = function(self, player, hitter, time_from_last_punch, tool_capabilities)
return armor_punch_old(self, player, hitter, time_from_last_punch, tool_capabilities)
end
end
]]
-- override items
for tname, tdef in pairs(core.registered_tools) do
local new_def = table.copy(tdef)
local override = false
if new_def.tool_capabilities then
if new_def.tool_capabilities.punch_attack_uses then
new_def.subtype = "weapon"
override = true
end
if not weapon_wear then
new_def.tool_capabilities.punch_attack_uses = nil
override = true
end
if new_def.tool_capabilities.groupcaps then
for k, v in pairs(new_def.tool_capabilities.groupcaps) do
-- FIXME: should "fleshy" only be modified for weapon wear?
if not tool_wear then
new_def.tool_capabilities.groupcaps[k].uses = 0
override = true
end
end
end
--[[ NOTE: anything useful here?
for t, tc in pairs(new_def.tool_capabilities) do
end
]]
--[[ NOTE: should we check for "fleshy" here to set "weapon" sub-type?
if new_def.tool_capabilities.damage_groups then
end
]]
end
if new_def.groups then
if new_def.groups.armor_use then
new_def.subtype = "armor"
override = true
if not armor_wear then
new_def.groups.armor_use = 0
end
end
end
if override then
core.unregister_item(tname)
core.register_tool(":" .. tname, new_def)
end
end
end)