diff --git a/enchants.lua b/enchants.lua index 37b393e..ae84769 100644 --- a/enchants.lua +++ b/enchants.lua @@ -1,3 +1,5 @@ +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 @@ -6,6 +8,7 @@ function tool_level_enchanting.set_enchantment(itemstack,enchantment_name,level) itemmeta:set_string(enchantment_name,level) return itemstack end + -- Unbreaking -- 10% chance per level of not using durability each use -- (Level 10, tool takes no durability usage) @@ -32,4 +35,31 @@ end -- Auto repairs every few seconds -- Max Level 5 -- Will work simularly to a compass/clock does --- Not sure how much per level to repair yet \ No newline at end of file +-- Not sure how much per level to repair yet + +-- TODO: +-- Make sure enchantment is an enchantment +-- Make sure level is a number +minetest.register_chatcommand("enchant", { + description = S("Enchant an item"), + params = S(" []"), + privs = {give = true}, + func = function(_, param) + local sparam = param:split(" ") + local player = sparam[1] + local enchantment = sparam[2] + local level = sparam[3] + -- Makes sure target name or enchant is not null + if not player or not enchantment then + return false, S("Usage: /enchant @1", params) + end + local target = minetest.get_player_by_name(player) + -- Makes sure player exists + if not target then + return false, S("Player @1 can not be found.", player) + end + local itemstack = target:get_wielded_item() + target:set_wielded_item(tool_level_enchanting.set_enchantment(itemstack,enchantment,level or 1)) + return true, S("Enchantment Successful") + end +}) \ No newline at end of file