- for _, x in pairs(enchtools) do
- local t, e, g = x[1], x[2], x[3]
- minetest.register_tool("xdecor:enchanted_"..t.."_"..m.."_"..e, {
- description = "Enchanted "..m:gsub("%l", string.upper, 1).." "..
- t:gsub("%l", string.upper, 1).." ("..e:gsub("%l", string.upper, 1)..")",
- inventory_image = minetest.registered_tools["default:"..t.."_"..m].inventory_image,
- groups = {not_in_creative_inventory=1},
- tool_capabilities = {groupcaps = g, damage_groups = def.dmg}
- })
+}
+
+for mod, defs in pairs(tools) do
+for _, mat in pairs(defs[1]) do
+for _, tooldef in next, defs, 1 do
+for _, ench in pairs(tooldef[3]) do
+ local tool, group, material, enchant = tooldef[1], tooldef[2], mat, ench
+ local original_tool = minetest.registered_tools[mod..":"..tool.."_"..material]
+
+ if original_tool then
+ if mod == "default" then
+ local original_damage_groups = original_tool.tool_capabilities.damage_groups
+ local original_groupcaps = original_tool.tool_capabilities.groupcaps
+ local groupcaps = table.copy(original_groupcaps)
+ local fleshy = original_damage_groups.fleshy
+ local full_punch_interval = original_tool.tool_capabilities.full_punch_interval
+ local max_drop_level = original_tool.tool_capabilities.max_drop_level
+
+ if enchant == "durable" then
+ groupcaps[group].uses = math.ceil(original_groupcaps[group].uses * enchanting.uses)
+ elseif enchant == "fast" then
+ for i = 1, 3 do
+ groupcaps[group].times[i] = original_groupcaps[group].times[i] - enchanting.times
+ end
+ elseif enchant == "sharp" then
+ fleshy = fleshy + enchanting.damages
+ end
+
+ minetest.register_tool(":"..mod..":enchanted_"..tool.."_"..material.."_"..enchant, {
+ description = "Enchanted "..cap(material).." "..cap(tool).." ("..cap(enchant)..")",
+ inventory_image = original_tool.inventory_image.."^[colorize:violet:50",
+ wield_image = original_tool.wield_image,
+ groups = {not_in_creative_inventory=1},
+ tool_capabilities = {
+ groupcaps = groupcaps, damage_groups = {fleshy = fleshy},
+ full_punch_interval = full_punch_interval, max_drop_level = max_drop_level
+ }
+ })
+ end
+
+ if mod == "3d_armor" then
+ local original_armor_groups = original_tool.groups
+ local armorcaps = table.copy(original_armor_groups)
+ local armorcaps = {}
+ armorcaps.not_in_creative_inventory = 1
+
+ for armor_group, value in pairs(original_armor_groups) do
+ if enchant == "strong" then
+ armorcaps[armor_group] = math.ceil(value * enchanting.strength)
+ elseif enchant == "speed" then
+ armorcaps[armor_group] = value
+ armorcaps.physics_speed = enchanting.speed
+ armorcaps.physics_jump = enchanting.jump
+ end
+ end
+
+ minetest.register_tool(":"..mod..":enchanted_"..tool.."_"..material.."_"..enchant, {
+ description = "Enchanted "..cap(material).." "..cap(tool).." ("..cap(enchant)..")",
+ inventory_image = original_tool.inventory_image,
+ texture = "3d_armor_"..tool.."_"..material,
+ wield_image = original_tool.wield_image,
+ groups = armorcaps,
+ wear = 0
+ })
+ end