Enchanted armor \o/

master
jp 2015-11-23 15:53:08 +01:00
parent ee03a43ce7
commit a8bb3f83fd
36 changed files with 130 additions and 59 deletions

View File

@ -1,5 +1,6 @@
Code : GPLv3
Textures : WTFPL (credits: Gambit, Cisoun, kilbith)
Armor textures : Copyright (C) 2013 Ryan Jones - CC-BY-SA
==============================================================

View File

@ -3,3 +3,4 @@ doors
xpanes
bucket
oresplus?
3d_armor?

View File

@ -3,21 +3,33 @@ screwdriver = screwdriver or {}
local xbg = default.gui_slots..default.get_hotbar_bg(0.5,4.5)
function enchanting.tools_fs()
return "size[9,8;]"..xbg..
"bgcolor[#080808BB;true]background[0,0;9,8;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,3;]"..
return "size[9,9;]"..xbg..
"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;]"..
"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]"
end
function enchanting.swords_fs()
return "size[9,8;]"..xbg..
"bgcolor[#080808BB;true]background[0,0;9,8;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,3;]"..
return "size[9,9;]"..xbg..
"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;]"..
"image_button[3.9,2.95;4,0.9;bg_btn.png;sharp;Sharpness]"
end
function enchanting.armors_fs()
return "size[9,9;]"..xbg..
"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;]"..
"image_button[3.9,0.9;4,0.9;bg_btn.png;strong;Strength]"
end
function enchanting.boots_fs()
return "size[9,9;]"..xbg..
"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;]"..
"image_button[3.9,0.9;4,0.9;bg_btn.png;strong;Strength]image_button[3.9,1.82;4,1.1;bg_btn.png;speed;Speed]"
end
function enchanting.default_fs(pos)
local meta = minetest.get_meta(pos)
local formspec = "size[9,8;]"..xbg..
"bgcolor[#080808BB;true]background[0,0;9,8;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,3;]"
local formspec = "size[9,9;]"..xbg..
"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;]"
meta:set_string("formspec", formspec)
meta:set_string("infotext", "Enchantment Table")
@ -34,38 +46,39 @@ function enchanting.on_put(pos, listname, _, stack, _)
if listname == "tool" then
if stn:find("sword") then
meta:set_string("formspec", enchanting.swords_fs())
else
elseif stn:find("pick") or stn:find("axe") or stn:find("shovel") then
meta:set_string("formspec", enchanting.tools_fs())
elseif stn:find("3d_armor:chestplate") or stn:find("3d_armor:helmet") or
stn:find("3d_armor:leggings") then
meta:set_string("formspec", enchanting.armors_fs())
elseif stn:find("3d_armor:boots") then
meta:set_string("formspec", enchanting.boots_fs())
end
end
end
function enchanting.is_allowed(toolname)
local tdef = minetest.registered_tools[toolname]
if tdef and toolname:find("default:") and not
toolname:find("stone") and not
toolname:find("wood") then
return 1
end
return 0
end
function enchanting.fields(pos, _, fields, _)
local inv = minetest.get_meta(pos):get_inventory()
local toolstack = inv:get_stack("tool", 1)
local toolstack_name = toolstack:get_name()
local mesestack = inv:get_stack("mese", 1)
local toolname = toolstack:get_name()
local modname, toolname = 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 enchanting.is_allowed(toolname) ~= 0 and mese > 0 and
fields[ench] and ench ~= "quit" then
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)
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
end
end
@ -75,15 +88,15 @@ function enchanting.dig(pos, _)
end
function enchanting.put(_, listname, _, stack, _)
local toolname = stack:get_name()
local toolstack = stack:get_name()
local count = stack:get_count()
if listname == "mese" and
toolname == "default:mese_crystal" then return count
elseif listname == "tool" then
return enchanting.is_allowed(toolname)
toolstack ~= "default:mese_crystal" then return 0
elseif listname == "tool" and not
minetest.registered_tools[toolstack] then return 0
end
return 0
return count
end
xdecor.register("enchantment_table", {
@ -113,41 +126,97 @@ local function cap(str) return str:gsub("^%l", string.upper) end
local use_factor = 1.2
local times_subtractor = 0.1
local damage_adder = 1
local strenght_factor = 1.2
function enchanting.register_enchtools()
local materials = {"steel", "bronze", "mese", "diamond"}
local tools = { {"axe", "choppy"}, {"pick", "cracky"}, {"shovel", "crumbly"}, {"sword", "fleshy"} }
local chants = {"durable", "fast", "sharp"}
local tools = {
for _, m in pairs(materials) do
for k, t in pairs(tools) do
for _, c in pairs(chants) do
local original_tool = minetest.registered_tools["default:"..t[1].."_"..m]
local original_damage_groups = original_tool.tool_capabilities.damage_groups
local original_groupcaps = original_tool.tool_capabilities.groupcaps
local groupcaps = table.copy(original_groupcaps)
local fleshy = original_damage_groups.fleshy
--[[ Format :
[Mod name] = {
{materials},
{tool name, tool group, {enchantments}}
}
--]]
if c == "durable" and k <= 3 then
groupcaps[t[2]].uses = original_groupcaps[t[2]].uses * use_factor
elseif c == "fast" and k <= 3 then
for i = 1, 3 do
groupcaps[t[2]].times[i] = original_groupcaps[t[2]].times[i] - times_subtractor
["default"] = {
{"steel", "bronze", "mese", "diamond"},
{"axe", "choppy", {"durable", "fast"}},
{"pick", "cracky", {"durable", "fast"}},
{"shovel", "crumbly", {"durable", "fast"}},
{"sword", "fleshy", {"sharp"}}
},
["3d_armor"] = {
{"steel", "bronze", "gold", "diamond"},
{"boots", nil, {"strong", "speed"}},
{"chestplate", nil, {"strong"}},
{"helmet", nil, {"strong"}},
{"leggings", nil, {"strong"}}
}
}
for mod, defs in pairs(tools) do
for _, mat in pairs(defs[1]) do
for _, tooldef in next, defs, 1 do
for _, ench in pairs(tooldef[3]) do
local tool, group, material, enchant = tooldef[1], tooldef[2], mat, ench
local original_tool = minetest.registered_tools[mod..":"..tool.."_"..material]
if original_tool then
if mod == "default" then
local original_damage_groups = original_tool.tool_capabilities.damage_groups
local original_groupcaps = original_tool.tool_capabilities.groupcaps
local groupcaps = table.copy(original_groupcaps)
local fleshy = original_damage_groups.fleshy
if enchant == "durable" then
groupcaps[group].uses = math.ceil(original_groupcaps[group].uses * use_factor)
elseif enchant == "fast" then
for i = 1, 3 do
groupcaps[group].times[i] = original_groupcaps[group].times[i] - times_subtractor
end
elseif enchant == "sharp" then
fleshy = fleshy + damage_adder
end
elseif c == "sharp" and k == 4 then
fleshy = fleshy + damage_adder
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:violet:50",
wield_image = original_tool.wield_image,
groups = {not_in_creative_inventory=1},
tool_capabilities = {groupcaps = groupcaps, damage_groups = {fleshy = fleshy}}
})
end
minetest.register_tool("xdecor:enchanted_"..t[1].."_"..m.."_"..c, {
description = string.format("Enchanted %s %s (%s)", cap(m), cap(t[1]), cap(c)),
inventory_image = original_tool.inventory_image.."^[colorize:violet:50",
wield_image = original_tool.wield_image,
groups = {not_in_creative_inventory=1},
tool_capabilities = {groupcaps = groupcaps, damage_groups = {fleshy = fleshy}}
})
end
end
if mod == "3d_armor" then
local original_protect_groups = original_tool.groups
local protectcaps = table.copy(original_protect_groups)
local protectcaps = {}
protectcaps.not_in_creative_inventory=1
if enchant == "strong" then
for protect_group, value in pairs(original_protect_groups) do
protectcaps[protect_group] = math.ceil(value * 1.2)
end
elseif enchant == "speed" then
for protect_group, value in pairs(original_protect_groups) do
protectcaps[protect_group] = value
protectcaps.physics_speed = 0.8
protectcaps.physics_jump = 0.3
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",
wield_image = original_tool.wield_image,
groups = protectcaps,
wear = 0
})
end
end
minetest.register_alias("xdecor:enchanted_"..tool.."_"..material.."_"..enchant,
":"..mod..":enchanted_"..tool.."_"..material.."_"..enchant)
end
end
end
end
enchanting.register_enchtools()

Binary file not shown.

After

Width:  |  Height:  |  Size: 261 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 297 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 261 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 297 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 228 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 334 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 228 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 334 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 231 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 344 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 231 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 344 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 221 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 245 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 234 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 245 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 446 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 564 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 392 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 436 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 389 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 404 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 420 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 408 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 399 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 334 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 367 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 382 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 359 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 345 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 381 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 346 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB