tool_level_enchanting/enchants.lua

65 lines
2.1 KiB
Lua
Raw Normal View History

2024-04-13 16:30:10 -04:00
local modname = minetest.get_current_modname()
local S = minetest.get_translator(modname)
2024-04-13 16:02:22 -04:00
-- TODO:
-- Make sure enchantment is an enchantment
-- Make sure level is a number
function tool_level_enchanting.set_enchantment(itemstack,enchantment_name,level)
local itemmeta = itemstack:get_meta()
itemmeta:set_string(enchantment_name,level)
return itemstack
end
2024-04-13 16:30:10 -04:00
2024-04-13 16:02:22 -04:00
-- Unbreaking
-- 10% chance per level of not using durability each use
-- (Level 10, tool takes no durability usage)
-- This function is used in tool_level_enchanting.on_use
function tool_level_enchanting.unbreaking_proc(enchant_level)
local rand_num = math.random(1,10)
if tonumber(enchant_level) >= tonumber(rand_num) then
return false
else
return true
end
end
-- Fortune
-- 10% Chance per level of doubling ore
-- 5% Chance per level of doubling uses
-- Max level 10
-- Silk Touch
-- Return block mined
-- No idea how to implient yet
-- Auto Repair
-- Auto repairs every few seconds
-- Max Level 5
-- Will work simularly to a compass/clock does
2024-04-13 16:30:10 -04:00
-- 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("<player> <enchantment> [<level>]"),
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
})