From: kilbith Date: Wed, 27 Jan 2016 21:19:54 +0000 (+0100) Subject: Some refactoring of enchanting code X-Git-Tag: 1.0~165 X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;ds=inline;h=e9cff1f8d3b74ced210e789648f6afd94a529cb7;p=xdecor.git Some refactoring of enchanting code --- diff --git a/enchanting.lua b/enchanting.lua index 15aaad6..d264b1f 100644 --- a/enchanting.lua +++ b/enchanting.lua @@ -13,26 +13,27 @@ enchanting.speed = 0.2 enchanting.jump = 0.2 -- Enchanted tools registration. +-- Available enchantments: durable, fast, sharp, strong, speed. enchanting.tools = { --[[ Registration format: [Mod name] = { materials, - {tool name, tool group, enchantments} + {tool name, enchantments} } - --]] + ]] ["default"] = { - "steel bronze mese diamond", - {"axe", "choppy", "durable, fast"}, - {"pick", "cracky", "durable, fast"}, - {"shovel", "crumbly", "durable, fast"}, - {"sword", "fleshy", "sharp"} + "steel, bronze, mese, diamond", + {"axe", "durable, fast"}, + {"pick", "durable, fast"}, + {"shovel", "durable, fast"}, + {"sword", "sharp"} }, ["3d_armor"] = { - "steel bronze gold diamond", - {"boots", nil, "strong, speed"}, - {"chestplate", nil, "strong"}, - {"helmet", nil, "strong"}, - {"leggings", nil, "strong"} + "steel, bronze, gold, diamond", + {"boots", "strong, speed"}, + {"chestplate", "strong"}, + {"helmet", "strong"}, + {"leggings", "strong"} } } @@ -155,18 +156,19 @@ local function cap(S) return S:gsub("^%l", string.upper) end for mod, defs in pairs(enchanting.tools) do for material in defs[1]:gmatch("[%w_]+") do for _, tooldef in next, defs, 1 do -for enchant in tooldef[3]:gmatch("[%w_]+") do - local tool, group = tooldef[1], tooldef[2] +for enchant in tooldef[2]:gmatch("[%w_]+") do + local tool, group = tooldef[1], "" local original_tool = minetest.registered_tools[mod..":"..tool.."_"..material] if original_tool then - if mod == "default" then + 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 + group = tostring(next(original_groupcaps)) if enchant == "durable" then groupcaps[group].uses = math.ceil(original_groupcaps[group].uses * enchanting.uses) @@ -192,7 +194,6 @@ for enchant in tooldef[3]:gmatch("[%w_]+") do 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 diff --git a/worktable.lua b/worktable.lua index 238a0cd..b2e1503 100644 --- a/worktable.lua +++ b/worktable.lua @@ -1,7 +1,8 @@ local worktable = {} screwdriver = screwdriver or {} --- Nodes allowed to be cut. Registration format: [mod name] = [[ node names ]]. +-- Nodes allowed to be cut. +-- Registration format: [mod name] = [[ node names ]]. worktable.nodes = { ["default"] = [[ wood tree cobble desert_stone