/enchant working
@ -1,5 +1,5 @@
|
||||
minetest.register_chatcommand("enchant", {
|
||||
description = "Enchant an item."
|
||||
description = "Enchant an item.",
|
||||
params = "<player> <enchantment> [<level>]",
|
||||
privs = {give = true},
|
||||
func = function(_, param)
|
||||
@ -8,10 +8,10 @@ minetest.register_chatcommand("enchant", {
|
||||
local enchantment = sparam[2]
|
||||
local level_str = sparam[3]
|
||||
local level = tonumber(level_str or "1")
|
||||
if not name or not enchantment then
|
||||
if not target_name or not enchantment then
|
||||
return false, "Usage: /enchant <player> <enchantment> [<level>]"
|
||||
end
|
||||
local target = minetest.get_player_by_name(name)
|
||||
local target = minetest.get_player_by_name(target_name)
|
||||
if not target then
|
||||
return false, "Player '" .. target_name .. "' cannot be found"
|
||||
end
|
||||
@ -26,15 +26,16 @@ minetest.register_chatcommand("enchant", {
|
||||
return false, "The selected enchantment can't be added to the target item"
|
||||
elseif errorstring == "level invalid" then
|
||||
return false, "'" .. level_str .. "' is not a valid number"
|
||||
elseif errorstring == "level too high"
|
||||
elseif errorstring == "level too high" then
|
||||
return false, "The number you have entered (" .. level_str .. ") is too big, it must be at most " .. extra_info
|
||||
elseif errorstring == "level too small"
|
||||
elseif errorstring == "level too small" then
|
||||
return false, "The number you have entered (" .. level_str .. ") is too small, it must be at least " .. extra_info
|
||||
elseif errorstring == "incompatible" then
|
||||
return false, mcl_enchanting.get_enchantment_description(enchantment, level) .. " can't be combined with " .. extra_info
|
||||
end
|
||||
else
|
||||
target:set_wielded_item(mcl_enchanting.enchant(itemstack, enchantment, level))
|
||||
return true, "Enchanting succeded"
|
||||
end
|
||||
end
|
||||
})
|
@ -42,38 +42,43 @@ end)
|
||||
--]]
|
||||
|
||||
minetest.register_on_mods_loaded(function()
|
||||
local register_list = {}
|
||||
for toolname, tooldef in pairs(minetest.registered_tools) do
|
||||
-- quick test
|
||||
local has_enchantment = false
|
||||
if tooldef.groups.enchanted then
|
||||
break
|
||||
end
|
||||
local quick_test = false
|
||||
for group, groupv in pairs(tooldef.groups) do
|
||||
if groupv > 0 and mcl_enchanting.all_item_groups[group] then
|
||||
has_enchantment = true
|
||||
if groupv > 0 and mcl_enchanting.all_item_groups[group] then
|
||||
quick_test = true
|
||||
break
|
||||
end
|
||||
end
|
||||
if not has_enchantment then
|
||||
break
|
||||
end
|
||||
-- expensive test
|
||||
has_enchantment = false
|
||||
for enchantment in pairs(mcl_enchanting.enchantments) do
|
||||
if mcl_enchanting.item_supports_enchantment(itemname, enchantment) then
|
||||
has_enchantment = true
|
||||
break
|
||||
if quick_test then
|
||||
--print(toolname)
|
||||
local expensive_test = false
|
||||
for enchantment in pairs(mcl_enchanting.enchantments) do
|
||||
if mcl_enchanting.item_supports_enchantment(toolname, enchantment, true) then
|
||||
-- print("\tSupports " .. enchantment)
|
||||
expensive_test = true
|
||||
break
|
||||
end
|
||||
end
|
||||
if expensive_test then
|
||||
local new_name = toolname .. "_enchanted"
|
||||
minetest.override_item(toolname, {_mcl_enchanting_enchanted_tool = new_name})
|
||||
local new_def = table.copy(tooldef)
|
||||
new_def.inventory_image = tooldef.inventory_image .. "^[colorize:purple:50"
|
||||
new_def.groups.not_in_creative_inventory = 1
|
||||
new_def.groups.enchanted = 1
|
||||
new_def.texture = tooldef.texture or toolname:gsub("%:", "_")
|
||||
new_def._mcl_enchanting_enchanted_tool = new_name
|
||||
register_list[":" .. new_name] = new_def
|
||||
end
|
||||
end
|
||||
if not has_enchantment then
|
||||
break
|
||||
end
|
||||
local new_name = toolname .. "_enchanted"
|
||||
tooldef._mcl_enchanting_enchanted_tool = new_name
|
||||
local new_def = table.copy(tooldef)
|
||||
new_def.inventory_image = old_def.inventory_image .. "^[colorize:violet:50"
|
||||
new_def.groups.not_in_creative_inventory = 1
|
||||
new_def.groups.enchanted = 1
|
||||
new_def.texture = old_def.texture or toolname:gsub("%:", "_")
|
||||
new_def._mcl_enchanting_enchanted_tool = new_name
|
||||
minetest.register_tool(":" .. new_name, new_def)
|
||||
end
|
||||
for new_name, new_def in pairs(register_list) do
|
||||
minetest.register_tool(new_name, new_def)
|
||||
end
|
||||
end)
|
||||
|
||||
@ -91,15 +96,16 @@ end
|
||||
|
||||
function mcl_enchanting.get_enchantment_description(enchantment, level)
|
||||
local enchantment_def = mcl_enchanting.enchantments[enchantment]
|
||||
return enchantment_def.name .. " " .. (enchantment_def.max_level == 1 and "" or mcl_enchanting.roman_numerals.toRoman(level))
|
||||
return enchantment_def.name .. (enchantment_def.max_level == 1 and "" or " " .. mcl_enchanting.roman_numerals.toRoman(level))
|
||||
end
|
||||
|
||||
function mcl_enchanting.get_enchanted_itemstring(itemname)
|
||||
return minetest.registered_items[itemname]._mcl_enchanting_enchanted_tool
|
||||
local def = minetest.registered_items[itemname]
|
||||
return def and def._mcl_enchanting_enchanted_tool
|
||||
end
|
||||
|
||||
function mcl_enchanting.item_supports_enchantment(itemname, enchantment)
|
||||
if not mcl_enchanting.get_enchanted_itemstring(itemname) then
|
||||
function mcl_enchanting.item_supports_enchantment(itemname, enchantment, early)
|
||||
if not early and not mcl_enchanting.get_enchanted_itemstring(itemname) then
|
||||
return false
|
||||
end
|
||||
local enchantment_def = mcl_enchanting.enchantments[enchantment]
|
||||
@ -109,7 +115,7 @@ function mcl_enchanting.item_supports_enchantment(itemname, enchantment)
|
||||
end
|
||||
end
|
||||
for group in pairs(enchantment_def.all) do
|
||||
if minetest.get_item_group(itemname, group) then
|
||||
if minetest.get_item_group(itemname, group) > 0 then
|
||||
return true
|
||||
end
|
||||
end
|
||||
@ -124,7 +130,7 @@ function mcl_enchanting.can_enchant(itemstack, enchantment, level)
|
||||
if itemstack:get_name() == "" then
|
||||
return false, "item missing"
|
||||
end
|
||||
if not mcl_enchanting.item_supports_enchantment(itemdef.name, enchantment) then
|
||||
if not mcl_enchanting.item_supports_enchantment(itemstack:get_name(), enchantment) then
|
||||
return false, "item not supported"
|
||||
end
|
||||
if not level then
|
||||
@ -146,19 +152,19 @@ function mcl_enchanting.can_enchant(itemstack, enchantment, level)
|
||||
return false, "incompatible", mcl_enchanting.get_enchantment_description(incompatible, incompatible_level)
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
function mcl_enchanting.enchant(itemstack, enchantment, level)
|
||||
local enchanted_itemstack = ItemStack(mcl_enchanting.get_enchanted_itemstring(itemstack:get_name()))
|
||||
enchanted_itemstack:add_wear(itemstack:get_wear())
|
||||
enchanted_itemstack:set_meta(itemstack:get_meta())
|
||||
local enchanted_itemstack = ItemStack({name = mcl_enchanting.get_enchanted_itemstring(itemstack:get_name()), wear = itemstack:get_wear(), metadata = itemstack:get_metadata()})
|
||||
local enchantments = mcl_enchanting.get_enchantments(enchanted_itemstack)
|
||||
enchantments[enchantment] = level
|
||||
mcl_enchanting.set_enchantments(enchanted_itemstack, enchantments)
|
||||
mcl_enchanting.reload_enchantments(enchanted_itemstack, enchantments)
|
||||
return enchanted_itemstack
|
||||
end
|
||||
|
||||
function mcl_enchanting.reload_enchantments(itemstack, echantments)
|
||||
function mcl_enchanting.reload_enchantments(itemstack, enchantments)
|
||||
local itemdef = itemstack:get_definition()
|
||||
for enchantment, level in pairs(enchantments) do
|
||||
local func = mcl_enchanting.features[enchantment]
|
@ -1,6 +1,6 @@
|
||||
-- Taken from https://minecraft.gamepedia.com/Enchanting
|
||||
|
||||
mcl_enchantments.enchantments = {
|
||||
mcl_enchanting.enchantments = {
|
||||
-- unimplemented
|
||||
aqua_affinity = {
|
||||
name = "Aqua Affinity",
|
||||
@ -90,6 +90,17 @@ mcl_enchantments.enchantments = {
|
||||
description = "Reduces fall damage."
|
||||
},
|
||||
-- unimplemented
|
||||
fire_aspect = {
|
||||
name = "Fire Aspect",
|
||||
max_level = 2,
|
||||
primary = {sword = true},
|
||||
secondary = {},
|
||||
disallow = {},
|
||||
incompatible = {},
|
||||
weight = 2,
|
||||
description = "Sets target on fire."
|
||||
},
|
||||
-- unimplemented
|
||||
fire_protection = {
|
||||
name = "Fire Protection",
|
||||
max_level = 4,
|
||||
@ -101,6 +112,17 @@ mcl_enchantments.enchantments = {
|
||||
description = "Reduces fire damage."
|
||||
},
|
||||
-- unimplemented
|
||||
flame = {
|
||||
name = "Flame",
|
||||
max_level = 1,
|
||||
primary = {bow = true},
|
||||
secondary = {},
|
||||
disallow = {},
|
||||
incompatible = {},
|
||||
weight = 2,
|
||||
description = "Arrows set target on fire."
|
||||
},
|
||||
-- unimplemented
|
||||
fortune = {
|
||||
name = "Fortune",
|
||||
max_level = 4,
|
||||
@ -190,7 +212,7 @@ mcl_enchantments.enchantments = {
|
||||
},
|
||||
-- unimplemented
|
||||
power = {
|
||||
name = "Power",
|
||||
name = "Power",
|
||||
max_level = 5,
|
||||
primary = {},
|
||||
secondary = {bow = true},
|
||||
@ -267,12 +289,12 @@ mcl_enchantments.enchantments = {
|
||||
},
|
||||
-- unimplemented
|
||||
smite = {
|
||||
name = "Sharpness",
|
||||
name = "Smite",
|
||||
max_level = 5,
|
||||
primary = {sword = true},
|
||||
secondary = {axe = true},
|
||||
disallow = {},
|
||||
incompatible = {sharpness = true, smite = true},
|
||||
incompatible = {bane_of_anthropods = true, sharpness = true},
|
||||
weight = 5,
|
||||
description = "Increases damage to undead mobs."
|
||||
},
|
||||
@ -292,7 +314,7 @@ mcl_enchantments.enchantments = {
|
||||
name = "Sweeping Edge",
|
||||
max_level = 3,
|
||||
primary = {sword = true},
|
||||
secondary = {axe = true},
|
||||
secondary = {},
|
||||
disallow = {},
|
||||
incompatible = {},
|
||||
weight = 2,
|
@ -1,3 +1,6 @@
|
||||
mcl_enchanting.features = {}
|
||||
|
||||
|
||||
--[[
|
||||
local pickaxes = {"mcl_tools:pick_wood", "mcl_tools:pick_stone", "mcl_tools:pick_gold", "mcl_tools:pick_iron", "mcl_tools:pick_diamond"}
|
||||
local pickaxes_better_than_iron = {"mcl_tools:pick_iron", "mcl_tools:pick_diamond"}
|
||||
@ -118,3 +121,4 @@ end)
|
||||
end
|
||||
},
|
||||
},--]]
|
||||
|
@ -9,6 +9,7 @@ mcl_enchanting = {
|
||||
dofile(modpath .. "/enchantments.lua")
|
||||
dofile(modpath .. "/features.lua")
|
||||
dofile(modpath .. "/core.lua")
|
||||
dofile(modpath .. "/command.lua")
|
||||
-- dofile(modpath .. "/ui.lua")
|
||||
-- dofile(modpath .. "/fx.lua")
|
||||
-- dofile(modpath .. "/book.lua")
|
@ -1,5 +1,5 @@
|
||||
name = mcl_enchanting
|
||||
description = The rewrite of the Enchanting mod for MineClone2
|
||||
depends = mcl_sounds, mcl_formspec, mcl_dye
|
||||
depends = mcl_formspec, _mcl_autogroup
|
||||
optional_depends = screwdriver
|
||||
author = Fleckenstein
|
Before Width: | Height: | Size: 875 B After Width: | Height: | Size: 875 B |
Before Width: | Height: | Size: 3.3 KiB After Width: | Height: | Size: 3.3 KiB |
Before Width: | Height: | Size: 6.6 KiB After Width: | Height: | Size: 6.6 KiB |
Before Width: | Height: | Size: 875 B After Width: | Height: | Size: 875 B |
Before Width: | Height: | Size: 4.8 KiB After Width: | Height: | Size: 4.8 KiB |
Before Width: | Height: | Size: 876 B After Width: | Height: | Size: 876 B |
Before Width: | Height: | Size: 876 B After Width: | Height: | Size: 876 B |
Before Width: | Height: | Size: 161 B After Width: | Height: | Size: 161 B |
Before Width: | Height: | Size: 157 B After Width: | Height: | Size: 157 B |
Before Width: | Height: | Size: 158 B After Width: | Height: | Size: 158 B |
Before Width: | Height: | Size: 156 B After Width: | Height: | Size: 156 B |
Before Width: | Height: | Size: 159 B After Width: | Height: | Size: 159 B |
Before Width: | Height: | Size: 106 B After Width: | Height: | Size: 106 B |
Before Width: | Height: | Size: 160 B After Width: | Height: | Size: 160 B |
Before Width: | Height: | Size: 166 B After Width: | Height: | Size: 166 B |
Before Width: | Height: | Size: 145 B After Width: | Height: | Size: 145 B |
Before Width: | Height: | Size: 161 B After Width: | Height: | Size: 161 B |
Before Width: | Height: | Size: 159 B After Width: | Height: | Size: 159 B |
Before Width: | Height: | Size: 159 B After Width: | Height: | Size: 159 B |
Before Width: | Height: | Size: 105 B After Width: | Height: | Size: 105 B |
Before Width: | Height: | Size: 161 B After Width: | Height: | Size: 161 B |
Before Width: | Height: | Size: 159 B After Width: | Height: | Size: 159 B |
Before Width: | Height: | Size: 157 B After Width: | Height: | Size: 157 B |
Before Width: | Height: | Size: 158 B After Width: | Height: | Size: 158 B |
Before Width: | Height: | Size: 102 B After Width: | Height: | Size: 102 B |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 298 B After Width: | Height: | Size: 298 B |
Before Width: | Height: | Size: 315 B After Width: | Height: | Size: 315 B |
Before Width: | Height: | Size: 340 B After Width: | Height: | Size: 340 B |
@ -156,7 +156,7 @@ for level=0, 2 do
|
||||
wield_scale = { x = 1.8, y = 1.8, z = 1 },
|
||||
stack_max = 1,
|
||||
range = 0, -- Pointing range to 0 to prevent punching with bow :D
|
||||
groups = {not_in_creative_inventory=1, not_in_craft_guide=1},
|
||||
groups = {not_in_creative_inventory=1, not_in_craft_guide=1, bow=1},
|
||||
on_drop = function(itemstack, dropper, pos)
|
||||
reset_bow_state(dropper)
|
||||
itemstack:set_name("mcl_bows:bow")
|
||||
|