From 9c70dc9c0988d7e20f0afadeae4ca2aa08372cd9 Mon Sep 17 00:00:00 2001 From: jasonl8446 Date: Tue, 16 Apr 2024 20:24:47 -0400 Subject: [PATCH] Added sharpness --- enchants.lua | 26 ++++++++++++++++++-------- init.lua | 31 +++++++++++++++++++++---------- 2 files changed, 39 insertions(+), 18 deletions(-) diff --git a/enchants.lua b/enchants.lua index aae0af1..25c1e5e 100644 --- a/enchants.lua +++ b/enchants.lua @@ -1,9 +1,6 @@ local modname = minetest.get_current_modname() local S = minetest.get_translator(modname) --- TODO: --- Make sure enchantment is an enchantment --- Make sure level is a number --- Make sure enchantment is possible (correct tool) + function tool_level_enchanting.set_enchantment(itemstack,enchantment_name,level) local itemmeta = itemstack:get_meta() local itemdef = itemstack:get_definition() @@ -14,6 +11,9 @@ function tool_level_enchanting.set_enchantment(itemstack,enchantment_name,level) if enchantment_name == "efficiency" then itemstack = tool_level_enchanting.efficiency_change(itemstack,level) end + if enchantment_name == "sharpness" then + itemstack = tool_level_enchanting.sharpness_change(itemstack,level) + end return itemstack end @@ -36,7 +36,6 @@ end function tool_level_enchanting.efficiency_change(itemstack, enchant_level) local itemmeta = itemstack:get_meta() local itemdef = itemstack:get_definition() - print(ItemStack("default:pick_diamond"):get_tool_capabilities()) if itemdef.tool_capabilities then local speed_multiplier = 1 - (0.1 * tonumber(enchant_level)) local cap = table.copy(itemdef.tool_capabilities) @@ -136,12 +135,23 @@ minetest.register_globalstep(function(dtime) end) -- Sharpness? --- 10% per level? idk --- max level 10 - +-- 10% per level? +-- max level 5 +function tool_level_enchanting.sharpness_change(itemstack, enchant_level) + local itemmeta = itemstack:get_meta() + local itemdef = itemstack:get_definition() + if itemdef.tool_capabilities.damage_groups.fleshy then + local damage_multiplier = 1 - (0.1 * tonumber(enchant_level)) + local cap = table.copy(itemdef.tool_capabilities) + cap.damage_groups.fleshy = cap.damage_groups.fleshy * damage_multiplier + itemmeta:set_tool_capabilities(cap) + end + return itemstack +end -- TODO: -- Make sure enchantment is an enchantment -- Make sure level is a number +-- Make sure enchantment on tool is possible minetest.register_chatcommand("enchant", { description = S("Enchant an item"), params = S(" []"), diff --git a/init.lua b/init.lua index 87f6af9..98682fb 100644 --- a/init.lua +++ b/init.lua @@ -1,16 +1,27 @@ local path = minetest.get_modpath('tool_level_enchanting') local S = minetest.get_translator("tool_level_enchanting") -tool_level_enchanting = { - registered_ores = { - ['default:stone_with_coal'] = true, - ['default:stone_with_copper'] = true, - ['default:stone_with_diamond'] = true, - ['default:stone_with_gold'] = true, - ['default:stone_with_iron'] = true, - ['default:stone_with_mese'] = true, - ['default:stone_with_tin'] = true, - } +tool_level_enchanting = {} + +-- List of ores that work with fortune +tool_level_enchanting.registered_ores = { + ['default:stone_with_coal'] = true, + ['default:stone_with_copper'] = true, + ['default:stone_with_diamond'] = true, + ['default:stone_with_gold'] = true, + ['default:stone_with_iron'] = true, + ['default:stone_with_mese'] = true, + ['default:stone_with_tin'] = true, +} + +-- List of enchantments and max levels +tool_level_enchanting.registered_enchantments = { + ['unbreaking'] = 10, + ['efficiency'] = 5, + ['silk_touch'] = 10, + ['fortune'] = 10, + ['auto_repair'] = 10, + ['sharpness'] = 5 } dofile(path .. '/enchants.lua')