- --- Pickaxes ---
-
- minetest.register_tool("xdecor:enchanted_pick_"..m.."_durable", {
- description = "Enchanted "..string.sub(string.upper(m), 0, 1)..string.sub(m, 2).." Pickaxe (Durable)",
- inventory_image = minetest.registered_tools["default:pick_"..m]["inventory_image"],
- groups = {not_in_creative_inventory=1},
- tool_capabilities = {
- groupcaps = {
- cracky = {times=times, uses=use_longer, maxlevel=maxlvl}
- },
- damage_groups = dmg
- }
- })
-
- minetest.register_tool("xdecor:enchanted_pick_"..m.."_fast", {
- description = "Enchanted "..string.sub(string.upper(m), 0, 1)..string.sub(m, 2).." Pickaxe (Fast)",
- inventory_image = minetest.registered_tools["default:pick_"..m]["inventory_image"],
- groups = {not_in_creative_inventory=1},
- tool_capabilities = {
- groupcaps = {
- cracky = {times=dig_faster, uses=uses, maxlevel=maxlvl}
- },
- damage_groups = dmg
- }
- })
-
- --- Axes ---
-
- minetest.register_tool("xdecor:enchanted_axe_"..m.."_durable", {
- description = "Enchanted "..string.sub(string.upper(m), 0, 1)..string.sub(m, 2).." Axe (Durable)",
- inventory_image = minetest.registered_tools["default:axe_"..m]["inventory_image"],
- groups = {not_in_creative_inventory=1},
- tool_capabilities = {
- groupcaps = {
- choppy = {times=times, uses=use_longer, maxlevel=maxlvl}
- },
- damage_groups = dmg
- }
- })
-
- minetest.register_tool("xdecor:enchanted_axe_"..m.."_fast", {
- description = "Enchanted "..string.sub(string.upper(m), 0, 1)..string.sub(m, 2).." Axe (Fast)",
- inventory_image = minetest.registered_tools["default:axe_"..m]["inventory_image"],
- groups = {not_in_creative_inventory=1},
- tool_capabilities = {
- groupcaps = {
- choppy = {times=dig_faster, uses=uses, maxlevel=maxlvl}
- },
- damage_groups = dmg
- }
- })
-
- --- Shovels ---
-
- minetest.register_tool("xdecor:enchanted_shovel_"..m.."_durable", {
- description = "Enchanted "..string.sub(string.upper(m), 0, 1)..string.sub(m, 2).." Shovel (Durable)",
- inventory_image = minetest.registered_tools["default:shovel_"..m]["inventory_image"],
- groups = {not_in_creative_inventory=1},
- tool_capabilities = {
- groupcaps = {
- crumbly = {times=times, uses=use_longer, maxlevel=maxlvl}
- },
- damage_groups = dmg
- }
- })
-
- minetest.register_tool("xdecor:enchanted_shovel_"..m.."_fast", {
- description = "Enchanted "..string.sub(string.upper(m), 0, 1)..string.sub(m, 2).." Shovel (Fast)",
- inventory_image = minetest.registered_tools["default:shovel_"..m]["inventory_image"],
- groups = {not_in_creative_inventory=1},
- tool_capabilities = {
- groupcaps = {
- crumbly = {times=dig_faster, uses=uses, maxlevel=maxlvl}
- },
- damage_groups = dmg
- }
- })
-end
+local function cap(S) return S:gsub("^%l", string.upper) end
+
+function enchanting:register_tools(mod, def)
+ for tool in pairs(def.tools) do
+ for material in def.materials:gmatch("[%w_]+") do
+ for enchant in def.tools[tool].enchants:gmatch("[%w_]+") do
+ local original_tool = minetest.registered_tools[mod..":"..tool.."_"..material]
+ if not original_tool then return end
+
+ if original_tool.tool_capabilities 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
+ local group = next(original_groupcaps)
+
+ if enchant == "durable" then
+ groupcaps[group].uses = math.ceil(original_groupcaps[group].uses * enchanting.uses)
+ elseif enchant == "fast" then
+ for i, time in pairs(original_groupcaps[group].times) do
+ groupcaps[group].times[i] = time - 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 = {}
+ 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
+ end
+ end
+ end