function enchanting.formspec(pos, tooltype)
local meta = minetest.get_meta(pos)
- local formspec = "size[9,9;]"..default.gui_slots..default.get_hotbar_bg(0.5,4.5)..
- "bgcolor[#080808BB;true]background[0,0;9,9;ench_ui.png]list[context;tool;0.9,2.9;1,1;]list[context;mese;2,2.9;1,1;]image[2,2.9;1,1;mese_layout.png]list[current_player;main;0.5,4.5;8,4;]tooltip[sharp;Your sword kills faster]tooltip[durable;Your tool lasts longer]tooltip[fast;Your tool digs faster]tooltip[strong;Your armor is more resistant]tooltip[speed;Your speed is increased]"
+ local formspec = [[ size[9,9;]
+ bgcolor[#080808BB;true]
+ background[0,0;9,9;ench_ui.png]
+ list[context;tool;0.9,2.9;1,1;]
+ list[context;mese;2,2.9;1,1;]
+ list[current_player;main;0.5,4.5;8,4;]
+ image[2,2.9;1,1;mese_layout.png]
+ tooltip[sharp;Your sword kills faster]
+ tooltip[durable;Your tool lasts longer]
+ tooltip[fast;Your tool digs faster]
+ tooltip[strong;Your armor is more resistant]
+ tooltip[speed;Your speed is increased] ]]
+ ..default.gui_slots..default.get_hotbar_bg(0.5,4.5)
if tooltype == "sword" then
formspec = formspec.."image_button[3.9,2.9;4,0.92;bg_btn.png;sharp;Sharpness]"
elseif tooltype == "tool" then
- formspec = formspec.."image_button[3.9,0.85;4,0.92;bg_btn.png;fast;Efficiency]image_button[3.9,1.77;4,1.12;bg_btn.png;durable;Durability]"
+ formspec = formspec..
+ [[ image_button[3.9,0.85;4,0.92;bg_btn.png;fast;Efficiency]
+ image_button[3.9,1.77;4,1.12;bg_btn.png;durable;Durability] ]]
elseif tooltype == "armor" then
formspec = formspec.."image_button[3.9,0.85;4,0.92;bg_btn.png;strong;Strength]"
elseif tooltype == "boots" then
- formspec = formspec.."image_button[3.9,0.85;4,0.92;bg_btn.png;strong;Strength]image_button[3.9,1.77;4,1.12;bg_btn.png;speed;Speed]"
+ formspec = formspec..
+ [[ image_button[3.9,0.85;4,0.92;bg_btn.png;strong;Strength]
+ image_button[3.9,1.77;4,1.12;bg_btn.png;speed;Speed] ]]
end
meta:set_string("formspec", formspec)
local toolstack = inv:get_stack("tool", 1)
local toolstack_name = toolstack:get_name()
local mesestack = inv:get_stack("mese", 1)
- local modname, toolname = toolstack_name:match("([%w_]+):([%w_]+)")
+ local mod, tool = toolstack_name:match("([%w_]+):([%w_]+)")
local toolwear = toolstack:get_wear()
local mese = mesestack:get_count()
local ench = dump(fields):match("%w+")
if ench == "quit" then return end
-
- if mese > 0 and fields[ench] then
- local enchanted_tool = modname..":enchanted_"..toolname.."_"..ench
- local tdef = minetest.registered_tools[enchanted_tool]
-
- if tdef then
- toolstack:replace(enchanted_tool)
- toolstack:add_wear(toolwear)
- mesestack:take_item()
- inv:set_stack("mese", 1, mesestack)
- inv:set_stack("tool", 1, toolstack)
- end
+ local enchanted_tool = mod..":enchanted_"..tool.."_"..ench
+
+ if mese > 0 and fields[ench] and
+ minetest.registered_tools[enchanted_tool] then
+ toolstack:replace(enchanted_tool)
+ toolstack:add_wear(toolwear)
+ mesestack:take_item()
+ inv:set_stack("mese", 1, mesestack)
+ inv:set_stack("tool", 1, toolstack)
end
end
return inv:is_empty("tool") and inv:is_empty("mese")
end
+local function allowed(tool)
+ for item in pairs(minetest.registered_tools) do
+ if item:match("enchanted_"..tool) then
+ return true
+ end
+ end
+
+ return false
+end
+
function enchanting.put(_, listname, _, stack, _)
local toolstack = stack:get_name()
local toolname = toolstack:match("[%w_]+:([%w_]+)")
- local count = stack:get_count()
- local enchanted_tool = minetest.serialize(minetest.registered_tools):match("enchanted_"..toolname)
- if listname == "mese" and toolstack ~= "default:mese_crystal" then
- return 0
- elseif listname == "tool" and not enchanted_tool then
- return 0
+ if listname == "mese" and toolstack == "default:mese_crystal" then
+ return stack:get_count()
+ elseif listname == "tool" and allowed(toolname) then
+ return 1
end
- return count
+
+ return 0
end
xdecor.register("enchantment_table", {
on_receive_fields = enchanting.fields,
on_metadata_inventory_put = enchanting.on_put,
allow_metadata_inventory_put = enchanting.put,
- allow_metadata_inventory_move = function(...) return 0 end,
+ allow_metadata_inventory_move = function() return 0 end,
on_metadata_inventory_take = function(pos, listname, _, _, _)
- if listname == "tool" then enchanting.formspec(pos, nil) end
+ if listname == "tool" then
+ enchanting.formspec(pos, nil)
+ end
end
})
-local function cap(str) return str:gsub("^%l", string.upper) end
+local function cap(str)
+ return str:gsub("^%l", string.upper)
+end
-- Higher number = stronger enchant.
local use_factor = 1.2
local times_subtractor = 0.1
local damage_adder = 1
-local strenght_factor = 1.2
+local strength_factor = 1.2
+local speed_factor = 0.2
+local jump_factor = 0.2
local tools = {
--[[ Registration format :
end
minetest.register_tool(":"..mod..":enchanted_"..tool.."_"..material.."_"..enchant, {
- description = string.format("Enchanted %s %s (%s)", cap(material), cap(tool), cap(enchant)),
+ description = "Enchanted "..cap(material).." "..cap(tool).." ("..cap(enchant)..")",
inventory_image = original_tool.inventory_image.."^[colorize:violet:50",
wield_image = original_tool.wield_image,
groups = {not_in_creative_inventory=1},
for armor_group, value in pairs(original_armor_groups) do
if enchant == "strong" then
- armorcaps[armor_group] = math.ceil(value * 1.2)
+ armorcaps[armor_group] = math.ceil(value * strength_factor)
elseif enchant == "speed" then
armorcaps[armor_group] = value
- armorcaps.physics_speed = 0.3
- armorcaps.physics_jump = 0.2
+ armorcaps.physics_speed = speed_factor
+ armorcaps.physics_jump = jump_factor
end
end
minetest.register_tool(":"..mod..":enchanted_"..tool.."_"..material.."_"..enchant, {
- description = string.format("Enchanted %s %s (%s)", cap(material), cap(tool), cap(enchant)),
- inventory_image = original_tool.inventory_image.."^[colorize:blue:20",
+ description = "Enchanted "..cap(material).." "..cap(tool).." ("..cap(enchant)..")",
+ inventory_image = original_tool.inventory_image,
+ texture = "3d_armor_"..tool.."_"..material,
wield_image = original_tool.wield_image,
groups = armorcaps,
wear = 0
})
end
end
- minetest.register_alias("xdecor:enchanted_"..tool.."_"..material.."_"..enchant, mod..":enchanted_"..tool.."_"..material.."_"..enchant)
- minetest.register_alias(":"..mod..":enchanted_"..tool.."_"..material.."_"..enchant, mod..":enchanted_"..tool.."_"..material.."_"..enchant)
+ minetest.register_alias("xdecor:enchanted_"..tool.."_"..material.."_"..enchant, mod..
+ ":enchanted_"..tool.."_"..material.."_"..enchant) -- legacy code
end
end
end