2015-08-05 15:16:39 +03:00
|
|
|
local enchanting = {}
|
|
|
|
|
2015-09-24 21:34:59 +03:00
|
|
|
function enchanting.tools_fs()
|
2015-10-29 16:52:14 +03:00
|
|
|
return "size[9,8;]"..default.gui_slots..
|
|
|
|
"bgcolor[#080808BB;true]background[0,0;9,8;ench_ui.png]list[current_name;tool;0.9,2.9;1,1;]list[current_name;mese;2,2.9;1,1;]image[2,2.9;1,1;mese_layout.png]list[current_player;main;0.5,4.5;8,3;]"..
|
|
|
|
"image_button[3.9,0.9;4,0.9;bg_btn.png;fast;Efficiency]image_button[3.9,1.82;4,1.1;bg_btn.png;durable;Durability]"
|
2015-09-24 21:34:59 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
function enchanting.swords_fs()
|
2015-10-29 16:52:14 +03:00
|
|
|
return "size[9,8;]"..default.gui_slots..
|
|
|
|
"bgcolor[#080808BB;true]background[0,0;9,8;ench_ui.png]list[current_name;tool;0.9,2.9;1,1;]list[current_name;mese;2,2.9;1,1;]image[2,2.9;1,1;mese_layout.png]list[current_player;main;0.5,4.5;8,3;]"..
|
|
|
|
"image_button[3.9,2.95;4,0.9;bg_btn.png;sharp;Sharpness]"
|
2015-09-24 21:34:59 +03:00
|
|
|
end
|
2015-08-22 23:06:36 +03:00
|
|
|
|
2015-09-24 21:34:59 +03:00
|
|
|
function enchanting.default_fs(pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
2015-10-29 16:52:14 +03:00
|
|
|
local formspec = "size[9,8;]"..default.gui_slots..
|
|
|
|
"bgcolor[#080808BB;true]background[0,0;9,8;ench_ui.png]list[current_name;tool;0.9,2.9;1,1;]list[current_name;mese;2,2.9;1,1;]image[2,2.9;1,1;mese_layout.png]list[current_player;main;0.5,4.5;8,3;]"
|
2015-08-22 23:06:36 +03:00
|
|
|
|
|
|
|
meta:set_string("formspec", formspec)
|
2015-08-02 03:00:29 +03:00
|
|
|
meta:set_string("infotext", "Enchantment Table")
|
|
|
|
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
inv:set_size("tool", 1)
|
|
|
|
inv:set_size("mese", 1)
|
|
|
|
end
|
|
|
|
|
2015-09-24 21:34:59 +03:00
|
|
|
function enchanting.on_put(pos, listname, _, stack, _)
|
|
|
|
local stn = stack:get_name()
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
|
|
|
|
if listname == "tool" then
|
|
|
|
if stn:find("sword") then
|
|
|
|
meta:set_string("formspec", enchanting.swords_fs())
|
|
|
|
else
|
|
|
|
meta:set_string("formspec", enchanting.tools_fs())
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-08-19 23:52:16 +03:00
|
|
|
function enchanting.is_allowed(toolname)
|
2015-08-05 03:03:51 +03:00
|
|
|
local tdef = minetest.registered_tools[toolname]
|
2015-09-24 21:34:59 +03:00
|
|
|
if tdef and toolname:find("default:") and not toolname:find("stone") and not
|
|
|
|
toolname:find("wood") then
|
2015-08-05 03:03:51 +03:00
|
|
|
return 1
|
|
|
|
else return 0 end
|
|
|
|
end
|
|
|
|
|
2015-08-12 21:49:07 +03:00
|
|
|
function enchanting.fields(pos, _, fields, _)
|
2015-08-24 23:50:29 +03:00
|
|
|
local inv = minetest.get_meta(pos):get_inventory()
|
2015-08-02 18:57:30 +03:00
|
|
|
local toolstack = inv:get_stack("tool", 1)
|
|
|
|
local mesestack = inv:get_stack("mese", 1)
|
2015-08-03 00:02:56 +03:00
|
|
|
local toolname = toolstack:get_name()
|
2015-08-05 18:32:13 +03:00
|
|
|
local toolwear = toolstack:get_wear()
|
2015-08-03 00:02:56 +03:00
|
|
|
local mese = mesestack:get_count()
|
2015-08-19 23:52:16 +03:00
|
|
|
local ench = dump(fields):match("%w+")
|
2015-08-02 18:57:30 +03:00
|
|
|
|
2015-08-22 01:32:47 +03:00
|
|
|
if enchanting.is_allowed(toolname) ~= 0 and mese > 0 and
|
|
|
|
fields[ench] and ench ~= "quit" then
|
2015-08-19 23:52:16 +03:00
|
|
|
toolstack:replace("xdecor:enchanted_"..toolname:sub(9).."_"..ench)
|
|
|
|
toolstack:add_wear(toolwear)
|
|
|
|
mesestack:take_item()
|
|
|
|
inv:set_stack("mese", 1, mesestack)
|
|
|
|
inv:set_stack("tool", 1, toolstack)
|
2015-08-02 18:57:30 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-08-12 21:49:07 +03:00
|
|
|
function enchanting.dig(pos, _)
|
2015-08-24 23:50:29 +03:00
|
|
|
local inv = minetest.get_meta(pos):get_inventory()
|
2015-08-02 03:00:29 +03:00
|
|
|
if not inv:is_empty("tool") or not inv:is_empty("mese") then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2015-08-12 21:49:07 +03:00
|
|
|
function enchanting.put(_, listname, _, stack, _)
|
2015-08-03 00:02:56 +03:00
|
|
|
local toolname = stack:get_name()
|
|
|
|
local count = stack:get_count()
|
2015-08-02 03:00:29 +03:00
|
|
|
|
|
|
|
if listname == "mese" then
|
2015-08-03 00:02:56 +03:00
|
|
|
if toolname == "default:mese_crystal" then return count
|
2015-08-05 17:47:52 +03:00
|
|
|
else return 0 end
|
2015-08-02 03:00:29 +03:00
|
|
|
end
|
2015-08-24 23:50:29 +03:00
|
|
|
if listname == "tool" then return enchanting.is_allowed(toolname) end
|
2015-08-03 01:36:32 +03:00
|
|
|
return count
|
2015-08-02 03:00:29 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
xdecor.register("enchantment_table", {
|
|
|
|
description = "Enchantment Table",
|
|
|
|
tiles = {
|
2015-08-05 11:39:57 +03:00
|
|
|
"xdecor_enchantment_top.png", "xdecor_enchantment_bottom.png",
|
|
|
|
"xdecor_enchantment_side.png", "xdecor_enchantment_side.png",
|
|
|
|
"xdecor_enchantment_side.png", "xdecor_enchantment_side.png"
|
2015-08-02 03:00:29 +03:00
|
|
|
},
|
|
|
|
groups = {cracky=1},
|
2015-08-16 22:57:17 +03:00
|
|
|
sounds = default.node_sound_stone_defaults(),
|
2015-08-05 15:16:39 +03:00
|
|
|
can_dig = enchanting.dig,
|
2015-09-24 21:34:59 +03:00
|
|
|
on_construct = enchanting.default_fs,
|
2015-08-06 19:21:36 +03:00
|
|
|
on_receive_fields = enchanting.fields,
|
2015-09-24 21:34:59 +03:00
|
|
|
on_metadata_inventory_put = enchanting.on_put,
|
2015-08-08 19:29:53 +03:00
|
|
|
allow_metadata_inventory_put = enchanting.put,
|
2015-09-24 21:34:59 +03:00
|
|
|
allow_metadata_inventory_move = function(...) return 0 end,
|
|
|
|
on_metadata_inventory_take = function(pos, listname, _, _, _)
|
|
|
|
if listname == "tool" then enchanting.default_fs(pos) end
|
|
|
|
end
|
2015-08-02 03:00:29 +03:00
|
|
|
})
|
2015-08-02 18:57:30 +03:00
|
|
|
|
2015-08-24 23:50:29 +03:00
|
|
|
local function cap(str) return str:gsub("^%l", string.upper) end
|
2015-08-05 15:16:39 +03:00
|
|
|
|
2015-08-24 22:01:50 +03:00
|
|
|
-- Higher number = stronger enchant.
|
2015-08-24 21:01:57 +03:00
|
|
|
local use_factor = 1.2
|
|
|
|
local times_subtractor = 0.1
|
2015-09-25 02:00:07 +03:00
|
|
|
local damage_adder = 1
|
2015-08-24 21:01:57 +03:00
|
|
|
|
|
|
|
function enchanting.register_enchtools()
|
|
|
|
local materials = {"steel", "bronze", "mese", "diamond"}
|
2015-09-24 21:34:59 +03:00
|
|
|
local tools = { {"axe", "choppy"}, {"pick", "cracky"}, {"shovel", "crumbly"}, {"sword", "fleshy"} }
|
|
|
|
local chants = {"durable", "fast", "sharp"}
|
2015-08-24 22:01:50 +03:00
|
|
|
|
2015-08-24 23:50:29 +03:00
|
|
|
for _, m in pairs(materials) do
|
2015-09-24 21:34:59 +03:00
|
|
|
for k, t in pairs(tools) do
|
2015-08-24 23:50:29 +03:00
|
|
|
for _, c in pairs(chants) do
|
|
|
|
local original_tool = minetest.registered_tools["default:"..t[1].."_"..m]
|
2015-09-24 21:34:59 +03:00
|
|
|
local original_damage_groups = original_tool.tool_capabilities.damage_groups
|
2015-08-24 22:01:50 +03:00
|
|
|
local original_groupcaps = original_tool.tool_capabilities.groupcaps
|
|
|
|
local groupcaps = table.copy(original_groupcaps)
|
2015-09-24 23:40:32 +03:00
|
|
|
local fleshy = original_damage_groups.fleshy
|
|
|
|
|
2015-09-24 21:34:59 +03:00
|
|
|
if c == "durable" and k <= 3 then
|
2015-08-24 23:50:29 +03:00
|
|
|
groupcaps[t[2]].uses = original_groupcaps[t[2]].uses * use_factor
|
2015-09-24 21:34:59 +03:00
|
|
|
elseif c == "fast" and k <= 3 then
|
2015-08-24 22:01:50 +03:00
|
|
|
for i = 1, 3 do
|
2015-08-24 23:50:29 +03:00
|
|
|
groupcaps[t[2]].times[i] = original_groupcaps[t[2]].times[i] - times_subtractor
|
2015-08-24 21:01:57 +03:00
|
|
|
end
|
2015-09-24 21:34:59 +03:00
|
|
|
elseif c == "sharp" and k == 4 then
|
2015-09-25 02:00:07 +03:00
|
|
|
fleshy = fleshy + damage_adder
|
2015-08-24 21:01:57 +03:00
|
|
|
end
|
2015-09-24 21:41:24 +03:00
|
|
|
|
2015-09-24 23:40:32 +03:00
|
|
|
minetest.register_tool("xdecor:enchanted_"..t[1].."_"..m.."_"..c, {
|
2015-08-24 23:50:29 +03:00
|
|
|
description = string.format("Enchanted %s %s (%s)", cap(m), cap(t[1]), cap(c)),
|
2015-09-24 21:41:24 +03:00
|
|
|
inventory_image = original_tool.inventory_image.."^[colorize:violet:50",
|
2015-08-24 22:01:50 +03:00
|
|
|
wield_image = original_tool.wield_image,
|
|
|
|
groups = {not_in_creative_inventory=1},
|
2015-09-24 23:40:32 +03:00
|
|
|
tool_capabilities = {groupcaps = groupcaps, damage_groups = {fleshy = fleshy}}
|
2015-08-24 22:01:50 +03:00
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
2015-08-05 15:16:39 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-08-24 21:01:57 +03:00
|
|
|
enchanting.register_enchtools()
|