diff --git a/sounds/i3_heavy_armor.ogg b/sounds/i3_heavy_armor.ogg new file mode 100644 index 0000000..fe89ff2 Binary files /dev/null and b/sounds/i3_heavy_armor.ogg differ diff --git a/sounds/i3_heavy_boots.ogg b/sounds/i3_heavy_boots.ogg new file mode 100644 index 0000000..f9b0965 Binary files /dev/null and b/sounds/i3_heavy_boots.ogg differ diff --git a/sounds/i3_heavy_helmet.ogg b/sounds/i3_heavy_helmet.ogg new file mode 100644 index 0000000..9755b15 Binary files /dev/null and b/sounds/i3_heavy_helmet.ogg differ diff --git a/sounds/i3_heavy_leggings.ogg b/sounds/i3_heavy_leggings.ogg new file mode 100644 index 0000000..f0ad665 Binary files /dev/null and b/sounds/i3_heavy_leggings.ogg differ diff --git a/sounds/i3_heavy_shield.ogg b/sounds/i3_heavy_shield.ogg new file mode 100644 index 0000000..65621ad Binary files /dev/null and b/sounds/i3_heavy_shield.ogg differ diff --git a/sounds/i3_light_armor.ogg b/sounds/i3_light_armor.ogg new file mode 100644 index 0000000..c9b49fa Binary files /dev/null and b/sounds/i3_light_armor.ogg differ diff --git a/sounds/i3_light_boots.ogg b/sounds/i3_light_boots.ogg new file mode 100644 index 0000000..04e2c5f Binary files /dev/null and b/sounds/i3_light_boots.ogg differ diff --git a/sounds/i3_light_helmet.ogg b/sounds/i3_light_helmet.ogg new file mode 100644 index 0000000..ca09535 Binary files /dev/null and b/sounds/i3_light_helmet.ogg differ diff --git a/sounds/i3_light_leggings.ogg b/sounds/i3_light_leggings.ogg new file mode 100644 index 0000000..b4371ee Binary files /dev/null and b/sounds/i3_light_leggings.ogg differ diff --git a/sounds/i3_light_shield.ogg b/sounds/i3_light_shield.ogg new file mode 100644 index 0000000..e461a36 Binary files /dev/null and b/sounds/i3_light_shield.ogg differ diff --git a/src/callbacks.lua b/src/callbacks.lua index b411f6d..47b5c6c 100644 --- a/src/callbacks.lua +++ b/src/callbacks.lua @@ -6,7 +6,7 @@ local init_hud = i3.files.hud() local set_fs = i3.set_fs IMPORT("slz", "min", "insert", "copy", "ItemStack") -IMPORT("spawn_item", "reset_data", "get_detached_inv") +IMPORT("spawn_item", "reset_data", "get_detached_inv", "play_sound") core.register_on_player_hpchange(function(player, hpchange) local name = player:get_player_name() @@ -66,16 +66,88 @@ core.register_on_player_inventory_action(function(player, _, _, info) end end) -if core.global_exists("armor") then +if core.global_exists"armor" then i3.modules.armor = true - armor:register_on_update(set_fs) + + local group_indexes = { + {"armor_head", "i3_heavy_helmet"}, + {"armor_torso", "i3_heavy_armor"}, + {"armor_legs", "i3_heavy_leggings"}, + {"armor_feet", "i3_heavy_boots"}, + {"armor_shield", "i3_heavy_shield"}, + } + + local function check_group(def, group) + return def.groups[group] and def.groups[group] > 0 + end + + armor:register_on_equip(function(player, idx, stack) + local _, armor_inv = armor:get_valid_player(player, "3d_armor") + local def = stack:get_definition() + local name = player:get_player_name() + local data = i3.data[name] + + for i, v in ipairs(group_indexes) do + local group, sound = unpack(v) + local stackname = stack:get_name() + + if stackname:find"wood" or stackname:find"stone" or stackname:find"cactus" then + sound = sound:gsub("heavy", "light") + end + + if i == idx and check_group(def, group) then + data.armor_allow = sound + return armor:register_on_update(set_fs) + end + end + + data.armor_disallow = true + armor_inv:remove_item("armor", stack) + end) + + armor:register_on_update(function(player) + local _, armor_inv = armor:get_valid_player(player, "3d_armor") + if not armor_inv then return end + + for i = 1, 5 do + local stack = armor_inv:get_stack("armor", i) + local def = stack:get_definition() + + for j, v in ipairs(group_indexes) do + local group = v[1] + + if check_group(def, group) and i ~= j then + armor_inv:set_stack("armor", i, armor_inv:get_stack("armor", j)) + armor_inv:set_stack("armor", j, stack) + return play_sound(name, "i3_cannot", 0.8) + end + end + end + end) + + core.register_on_player_inventory_action(function(player, action, _, info) + if action ~= "take" then return end + local name = player:get_player_name() + local data = i3.data[name] + + if data.armor_disallow then + local inv = player:get_inventory() + inv:set_stack("main", info.index, info.stack) + data.armor_disallow = nil + play_sound(name, "i3_cannot", 0.8) + + elseif data.armor_allow then + play_sound(name, data.armor_allow, 0.8) + data.armor_allow = nil + end + end) end -if core.global_exists("skins") then +if core.global_exists"skins" then i3.modules.skins = true end -if core.global_exists("awards") then +if core.global_exists"awards" then i3.modules.awards = true core.register_on_craft(function(_, player) diff --git a/src/gui.lua b/src/gui.lua index 1c30d6c..7f640ee 100644 --- a/src/gui.lua +++ b/src/gui.lua @@ -479,9 +479,39 @@ local function get_container(fs, data, player, yoffset, ctn_len, award_list, awa end local armor_def = armor.def[name] - fs(fmt("list[detached:%s_armor;armor;0,%f;3,2;]", esc_name, yextra + 0.7)) - label(3.65, yextra + 1.55, fmt("%s: %s", ES"Level", armor_def.level)) - label(3.65, yextra + 2.05, fmt("%s: %s", ES"Heal", armor_def.heal)) + fs(fmt("list[detached:%s_armor;armor;0,%f;5,1;]", esc_name, yextra + 0.7)) + + for i = 1, 5 do + local _, armor_inv = armor:get_valid_player(player, "3d_armor") + local stack = armor_inv:get_stack("armor", i) + + if stack:is_empty() then + local tips = {ES"Helmet", ES"Chest", ES"Leggings", ES"Boots", ES"Shield"} + local x = (i - 1) + ((i - 1) * 0.15) + local y = yextra + 0.7 + + image(x, y, 1, 1, fmt("i3_armor_%u.png", i)) + tooltip(x, y, 1, 1, tips[i]) + end + end + + local box_len, max_level, max_heal = 4, 85, 60 + local bar_lvl = (armor_def.level * box_len) / max_level + local bar_heal = (armor_def.heal * box_len) / max_heal + + fs"style_type[label;font_size=15]" + + box(0.8, yextra + 1.95, box_len, 0.4, "#101010") + fs"style_type[box;colors=#9dc34c80,#9dc34c,#9dc34c,#9dc34c80]" + box(0.8, yextra + 1.95, bar_lvl, 0.4, "") + label(1.1, yextra + 2.15, ES"Armor level") + + box(0.8, yextra + 2.55, box_len, 0.4, "#101010") + fs"style_type[box;colors=#4466aa80,#4466aa,#4466aa,#4466aa80]" + box(0.8, yextra + 2.55, bar_heal, 0.4, "") + label(1.1, yextra + 2.75, ES"Armor healing") + + fs"style_type[label;font_size=16]" elseif data.subcat == 3 then if not i3.modules.skins then diff --git a/textures/i3_armor_1.png b/textures/i3_armor_1.png new file mode 100644 index 0000000..af0408b Binary files /dev/null and b/textures/i3_armor_1.png differ diff --git a/textures/i3_armor_2.png b/textures/i3_armor_2.png new file mode 100644 index 0000000..4aeb3ce Binary files /dev/null and b/textures/i3_armor_2.png differ diff --git a/textures/i3_armor_3.png b/textures/i3_armor_3.png new file mode 100644 index 0000000..e80c80b Binary files /dev/null and b/textures/i3_armor_3.png differ diff --git a/textures/i3_armor_4.png b/textures/i3_armor_4.png new file mode 100644 index 0000000..f08dd7c Binary files /dev/null and b/textures/i3_armor_4.png differ diff --git a/textures/i3_armor_5.png b/textures/i3_armor_5.png new file mode 100644 index 0000000..413edb6 Binary files /dev/null and b/textures/i3_armor_5.png differ