From 2a2cfa411399d5e2c15c5ea7f046c1c64b05e21a Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Mon, 2 Dec 2024 00:45:42 +0100 Subject: [PATCH] Move enchant registrations to separate file --- init.lua | 6 ++++- src/enchanted_tools.lua | 50 ++++++++++++++++++++++++++++++++++++++++ src/enchanting.lua | 51 ----------------------------------------- 3 files changed, 55 insertions(+), 52 deletions(-) create mode 100644 src/enchanted_tools.lua diff --git a/init.lua b/init.lua index 694ebbc..7269226 100644 --- a/init.lua +++ b/init.lua @@ -21,8 +21,12 @@ local subpart = { "mailbox", "mechanisms", "rope", - -- Workbench MUST be loaded last for the default 'cut node' registrations to work + -- Workbench MUST be loaded after all other subparts that register nodes + -- last for the default 'cut node' registrations to work "workbench", + -- Enchanted tools registered last because they depend on previous + -- subparts + "enchanted_tools", } for _, name in ipairs(subpart) do diff --git a/src/enchanted_tools.lua b/src/enchanted_tools.lua new file mode 100644 index 0000000..716ae7b --- /dev/null +++ b/src/enchanted_tools.lua @@ -0,0 +1,50 @@ +-- Register enchanted tools. + +-- Number of uses for the (normal) steel hoe from Minetest Game (as of 01/12/20224) +-- This is technically redundant because we cannot access that number +-- directly, but it's unlikely to change in future because Minetest Game is +-- unlikely to change. +local STEEL_HOE_USES = 500 + +-- Modifier of the steel hoe uses for the enchanted steel hoe +local STEEL_HOE_USES_MODIFIER = 3 + +-- Register enchantments for default tools from Minetest Game +local materials = {"steel", "bronze", "mese", "diamond"} +local tooltypes = { + { "axe", { "durable", "fast" }, "choppy" }, + { "pick", { "durable", "fast" }, "cracky" }, + { "shovel", { "durable", "fast" }, "crumbly" }, + { "sword", { "sharp" }, nil }, +} +for t=1, #tooltypes do +for m=1, #materials do + local tooltype = tooltypes[t][1] + local enchants = tooltypes[t][2] + local dig_group = tooltypes[t][3] + local material = materials[m] + xdecor.register_enchantable_tool("default:"..tooltype.."_"..material, { + enchants = enchants, + dig_group = dig_group, + }) +end +end + +-- Register enchanted steel hoe (more durability) +if farming.register_hoe then + local percent = math.round((STEEL_HOE_USES_MODIFIER - 1) * 100) + local hitem = ItemStack("farming:hoe_steel") + local hdesc = hitem:get_short_description() or "farming:hoe_steel" + local ehdesc, ehsdesc = xdecor.enchant_description(hdesc, "durable", percent) + farming.register_hoe(":farming:enchanted_hoe_steel_durable", { + description = ehdesc, + short_description = ehsdesc, + inventory_image = xdecor.enchant_texture("farming_tool_steelhoe.png"), + max_uses = STEEL_HOE_USES * STEEL_HOE_USES_MODIFIER, + groups = {hoe = 1, not_in_creative_inventory = 1} + }) + + xdecor.register_custom_enchantable_tool("farming:hoe_steel", { + durable = "farming:enchanted_hoe_steel_durable", + }) +end diff --git a/src/enchanting.lua b/src/enchanting.lua index 078140c..952deaa 100644 --- a/src/enchanting.lua +++ b/src/enchanting.lua @@ -17,15 +17,6 @@ local DEFAULT_ENCHANTING_USES = 1.2 -- Durability local DEFAULT_ENCHANTING_TIMES = 0.1 -- Efficiency local DEFAULT_ENCHANTING_DAMAGES = 1 -- Sharpness --- Number of uses for the (normal) steel hoe from Minetest Game (as of 01/12/20224) --- This is technically redundant because we cannot access that number --- directly, but it's unlikely to change in future because Minetest Game is --- unlikely to change. -local STEEL_HOE_USES = 500 - --- Modifier of the steel hoe uses for the enchanted steel hoe -local STEEL_HOE_USES_MODIFIER = 3 - local function to_percent(orig_value, final_value) return abs(ceil(((final_value - orig_value) / orig_value) * 100)) end @@ -492,45 +483,3 @@ xdecor.enchant_description = function(description, enchant, percent) return desc, short_desc end - ---[[ END OF API ]] - --- Register enchantments for default tools from Minetest Game -local materials = {"steel", "bronze", "mese", "diamond"} -local tooltypes = { - { "axe", { "durable", "fast" }, "choppy" }, - { "pick", { "durable", "fast" }, "cracky" }, - { "shovel", { "durable", "fast" }, "crumbly" }, - { "sword", { "sharp" }, nil }, -} -for t=1, #tooltypes do -for m=1, #materials do - local tooltype = tooltypes[t][1] - local enchants = tooltypes[t][2] - local dig_group = tooltypes[t][3] - local material = materials[m] - enchanting:register_tool("default:"..tooltype.."_"..material, { - enchants = enchants, - dig_group = dig_group, - }) -end -end - --- Register enchanted steel hoe (more durability) -if farming.register_hoe then - local percent = math.round((STEEL_HOE_USES_MODIFIER - 1) * 100) - local hitem = ItemStack("farming:hoe_steel") - local hdesc = hitem:get_short_description() or "farming:hoe_steel" - local ehdesc, ehsdesc = xdecor.enchant_description(hdesc, "durable", percent) - farming.register_hoe(":farming:enchanted_hoe_steel_durable", { - description = ehdesc, - short_description = ehsdesc, - inventory_image = enchanting:enchant_texture("farming_tool_steelhoe.png"), - max_uses = STEEL_HOE_USES * STEEL_HOE_USES_MODIFIER, - groups = {hoe = 1, not_in_creative_inventory = 1} - }) - - enchanting:register_custom_tool("farming:hoe_steel", { - durable = "farming:enchanted_hoe_steel_durable", - }) -end