diff --git a/LICENSE b/LICENSE index fc2d19b..ae124df 100644 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,6 @@ Code : GPLv3 Textures : WTFPL (credits: Gambit, Cisoun, kilbith) +Armor textures : Copyright (C) 2013 Ryan Jones - CC-BY-SA ============================================================== diff --git a/depends.txt b/depends.txt index 8ca3bd9..ff71542 100644 --- a/depends.txt +++ b/depends.txt @@ -3,3 +3,4 @@ doors xpanes bucket oresplus? +3d_armor? diff --git a/enchanting.lua b/enchanting.lua index 3ba2898..a16aac9 100644 --- a/enchanting.lua +++ b/enchanting.lua @@ -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() diff --git a/textures/3d_armor_enchanted_boots_bronze_speed.png b/textures/3d_armor_enchanted_boots_bronze_speed.png new file mode 100644 index 0000000..e3c27cf Binary files /dev/null and b/textures/3d_armor_enchanted_boots_bronze_speed.png differ diff --git a/textures/3d_armor_enchanted_boots_bronze_speed_preview.png b/textures/3d_armor_enchanted_boots_bronze_speed_preview.png new file mode 100644 index 0000000..d0f3bad Binary files /dev/null and b/textures/3d_armor_enchanted_boots_bronze_speed_preview.png differ diff --git a/textures/3d_armor_enchanted_boots_bronze_strong.png b/textures/3d_armor_enchanted_boots_bronze_strong.png new file mode 100644 index 0000000..e3c27cf Binary files /dev/null and b/textures/3d_armor_enchanted_boots_bronze_strong.png differ diff --git a/textures/3d_armor_enchanted_boots_bronze_strong_preview.png b/textures/3d_armor_enchanted_boots_bronze_strong_preview.png new file mode 100644 index 0000000..d0f3bad Binary files /dev/null and b/textures/3d_armor_enchanted_boots_bronze_strong_preview.png differ diff --git a/textures/3d_armor_enchanted_boots_diamond_speed.png b/textures/3d_armor_enchanted_boots_diamond_speed.png new file mode 100644 index 0000000..eca0feb Binary files /dev/null and b/textures/3d_armor_enchanted_boots_diamond_speed.png differ diff --git a/textures/3d_armor_enchanted_boots_diamond_speed_preview.png b/textures/3d_armor_enchanted_boots_diamond_speed_preview.png new file mode 100644 index 0000000..d178a54 Binary files /dev/null and b/textures/3d_armor_enchanted_boots_diamond_speed_preview.png differ diff --git a/textures/3d_armor_enchanted_boots_diamond_strong.png b/textures/3d_armor_enchanted_boots_diamond_strong.png new file mode 100644 index 0000000..eca0feb Binary files /dev/null and b/textures/3d_armor_enchanted_boots_diamond_strong.png differ diff --git a/textures/3d_armor_enchanted_boots_diamond_strong_preview.png b/textures/3d_armor_enchanted_boots_diamond_strong_preview.png new file mode 100644 index 0000000..d178a54 Binary files /dev/null and b/textures/3d_armor_enchanted_boots_diamond_strong_preview.png differ diff --git a/textures/3d_armor_enchanted_boots_gold_speed.png b/textures/3d_armor_enchanted_boots_gold_speed.png new file mode 100644 index 0000000..b62bf93 Binary files /dev/null and b/textures/3d_armor_enchanted_boots_gold_speed.png differ diff --git a/textures/3d_armor_enchanted_boots_gold_speed_preview.png b/textures/3d_armor_enchanted_boots_gold_speed_preview.png new file mode 100644 index 0000000..e6d07e1 Binary files /dev/null and b/textures/3d_armor_enchanted_boots_gold_speed_preview.png differ diff --git a/textures/3d_armor_enchanted_boots_gold_strong.png b/textures/3d_armor_enchanted_boots_gold_strong.png new file mode 100644 index 0000000..b62bf93 Binary files /dev/null and b/textures/3d_armor_enchanted_boots_gold_strong.png differ diff --git a/textures/3d_armor_enchanted_boots_gold_strong_preview.png b/textures/3d_armor_enchanted_boots_gold_strong_preview.png new file mode 100644 index 0000000..e6d07e1 Binary files /dev/null and b/textures/3d_armor_enchanted_boots_gold_strong_preview.png differ diff --git a/textures/3d_armor_enchanted_boots_steel_speed.png b/textures/3d_armor_enchanted_boots_steel_speed.png new file mode 100644 index 0000000..47bdb13 Binary files /dev/null and b/textures/3d_armor_enchanted_boots_steel_speed.png differ diff --git a/textures/3d_armor_enchanted_boots_steel_speed_preview.png b/textures/3d_armor_enchanted_boots_steel_speed_preview.png new file mode 100644 index 0000000..1aefd84 Binary files /dev/null and b/textures/3d_armor_enchanted_boots_steel_speed_preview.png differ diff --git a/textures/3d_armor_enchanted_boots_steel_strong.png.png b/textures/3d_armor_enchanted_boots_steel_strong.png.png new file mode 100644 index 0000000..a7d041a Binary files /dev/null and b/textures/3d_armor_enchanted_boots_steel_strong.png.png differ diff --git a/textures/3d_armor_enchanted_boots_steel_strong_preview.png b/textures/3d_armor_enchanted_boots_steel_strong_preview.png new file mode 100644 index 0000000..1aefd84 Binary files /dev/null and b/textures/3d_armor_enchanted_boots_steel_strong_preview.png differ diff --git a/textures/3d_armor_enchanted_chestplate_bronze_strong.png b/textures/3d_armor_enchanted_chestplate_bronze_strong.png new file mode 100644 index 0000000..d06313e Binary files /dev/null and b/textures/3d_armor_enchanted_chestplate_bronze_strong.png differ diff --git a/textures/3d_armor_enchanted_chestplate_bronze_strong_preview.png b/textures/3d_armor_enchanted_chestplate_bronze_strong_preview.png new file mode 100644 index 0000000..15cca70 Binary files /dev/null and b/textures/3d_armor_enchanted_chestplate_bronze_strong_preview.png differ diff --git a/textures/3d_armor_enchanted_chestplate_diamond_strong.png b/textures/3d_armor_enchanted_chestplate_diamond_strong.png new file mode 100644 index 0000000..e880f39 Binary files /dev/null and b/textures/3d_armor_enchanted_chestplate_diamond_strong.png differ diff --git a/textures/3d_armor_enchanted_chestplate_diamond_strong_preview.png b/textures/3d_armor_enchanted_chestplate_diamond_strong_preview.png new file mode 100644 index 0000000..bed2a02 Binary files /dev/null and b/textures/3d_armor_enchanted_chestplate_diamond_strong_preview.png differ diff --git a/textures/3d_armor_enchanted_chestplate_gold_strong.png b/textures/3d_armor_enchanted_chestplate_gold_strong.png new file mode 100644 index 0000000..cf06017 Binary files /dev/null and b/textures/3d_armor_enchanted_chestplate_gold_strong.png differ diff --git a/textures/3d_armor_enchanted_chestplate_gold_strong_preview.png b/textures/3d_armor_enchanted_chestplate_gold_strong_preview.png new file mode 100644 index 0000000..229d3fd Binary files /dev/null and b/textures/3d_armor_enchanted_chestplate_gold_strong_preview.png differ diff --git a/textures/3d_armor_enchanted_chestplate_steel_strong.png b/textures/3d_armor_enchanted_chestplate_steel_strong.png new file mode 100644 index 0000000..62fe16e Binary files /dev/null and b/textures/3d_armor_enchanted_chestplate_steel_strong.png differ diff --git a/textures/3d_armor_enchanted_chestplate_steel_strong_preview.png b/textures/3d_armor_enchanted_chestplate_steel_strong_preview.png new file mode 100644 index 0000000..6d9dfb4 Binary files /dev/null and b/textures/3d_armor_enchanted_chestplate_steel_strong_preview.png differ diff --git a/textures/3d_armor_enchanted_helmet_bronze_strong.png b/textures/3d_armor_enchanted_helmet_bronze_strong.png new file mode 100644 index 0000000..a550a1b Binary files /dev/null and b/textures/3d_armor_enchanted_helmet_bronze_strong.png differ diff --git a/textures/3d_armor_enchanted_helmet_bronze_strong_preview.png b/textures/3d_armor_enchanted_helmet_bronze_strong_preview.png new file mode 100644 index 0000000..323a51f Binary files /dev/null and b/textures/3d_armor_enchanted_helmet_bronze_strong_preview.png differ diff --git a/textures/3d_armor_enchanted_helmet_diamond_strong.png b/textures/3d_armor_enchanted_helmet_diamond_strong.png new file mode 100644 index 0000000..083e981 Binary files /dev/null and b/textures/3d_armor_enchanted_helmet_diamond_strong.png differ diff --git a/textures/3d_armor_enchanted_helmet_diamond_strong_preview.png b/textures/3d_armor_enchanted_helmet_diamond_strong_preview.png new file mode 100644 index 0000000..c427c13 Binary files /dev/null and b/textures/3d_armor_enchanted_helmet_diamond_strong_preview.png differ diff --git a/textures/3d_armor_enchanted_helmet_gold_strong.png b/textures/3d_armor_enchanted_helmet_gold_strong.png new file mode 100644 index 0000000..0a10446 Binary files /dev/null and b/textures/3d_armor_enchanted_helmet_gold_strong.png differ diff --git a/textures/3d_armor_enchanted_helmet_gold_strong_preview.png b/textures/3d_armor_enchanted_helmet_gold_strong_preview.png new file mode 100644 index 0000000..ddda870 Binary files /dev/null and b/textures/3d_armor_enchanted_helmet_gold_strong_preview.png differ diff --git a/textures/3d_armor_enchanted_helmet_steel_strong.png b/textures/3d_armor_enchanted_helmet_steel_strong.png new file mode 100644 index 0000000..ff98024 Binary files /dev/null and b/textures/3d_armor_enchanted_helmet_steel_strong.png differ diff --git a/textures/3d_armor_enchanted_helmet_steel_strong_preview.png b/textures/3d_armor_enchanted_helmet_steel_strong_preview.png new file mode 100644 index 0000000..8286abf Binary files /dev/null and b/textures/3d_armor_enchanted_helmet_steel_strong_preview.png differ diff --git a/textures/ench_ui.png b/textures/ench_ui.png index 41f180c..1413b7b 100644 Binary files a/textures/ench_ui.png and b/textures/ench_ui.png differ