From f350fa6272a341d7ba28aab0aa75e7ba9bbd5b43 Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Tue, 6 Apr 2021 14:50:34 +0200 Subject: [PATCH] Add bossbars --- mods/CORE/mcl_util/init.lua | 2 +- mods/ENTITIES/mcl_mobs/api.lua | 16 +-- mods/ENTITIES/mobs_mc/ender_dragon.lua | 3 + mods/ENTITIES/mobs_mc/wither.lua | 3 +- mods/HUD/mcl_bossbars/init.lua | 124 ++++++++++++++++++ mods/HUD/mcl_bossbars/mod.conf | 4 + .../mcl_bossbars/textures/mcl_bossbars.png | Bin 0 -> 3689 bytes .../textures/mcl_bossbars_empty.png | Bin 0 -> 3369 bytes 8 files changed, 142 insertions(+), 10 deletions(-) create mode 100644 mods/HUD/mcl_bossbars/init.lua create mode 100644 mods/HUD/mcl_bossbars/mod.conf create mode 100644 mods/HUD/mcl_bossbars/textures/mcl_bossbars.png create mode 100644 mods/HUD/mcl_bossbars/textures/mcl_bossbars_empty.png diff --git a/mods/CORE/mcl_util/init.lua b/mods/CORE/mcl_util/init.lua index a43c3d5d0b..ac913de390 100644 --- a/mods/CORE/mcl_util/init.lua +++ b/mods/CORE/mcl_util/init.lua @@ -410,7 +410,7 @@ function mcl_util.get_color(colorstr) local mc_color = mcl_colors[colorstr:upper()] if mc_color then colorstr = mc_color - elseif #colorstr ~= 7 or colorstr:sub(1, 1) ~= "#"then + elseif #colorstr ~= 7 or colorstr:sub(1, 1) ~= "#" then return end local hex = tonumber(colorstr:sub(2, 7), 16) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 6e932ed5e5..e599f21277 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -3526,14 +3526,6 @@ local mob_step = function(self, dtime) -- end rotation - -- knockback timer - if self.pause_timer > 0 then - - self.pause_timer = self.pause_timer - dtime - - return - end - -- run custom function (defined in mob lua file) if self.do_custom then @@ -3543,6 +3535,14 @@ local mob_step = function(self, dtime) end end + -- knockback timer + if self.pause_timer > 0 then + + self.pause_timer = self.pause_timer - dtime + + return + end + -- attack timer self.timer = self.timer + dtime diff --git a/mods/ENTITIES/mobs_mc/ender_dragon.lua b/mods/ENTITIES/mobs_mc/ender_dragon.lua index ddaea360f8..509409a2e2 100644 --- a/mods/ENTITIES/mobs_mc/ender_dragon.lua +++ b/mods/ENTITIES/mobs_mc/ender_dragon.lua @@ -59,6 +59,9 @@ mobs:register_mob("mobs_mc:enderdragon", { run_start = 0, run_end = 20, }, ignores_nametag = true, + do_custom = function(self) + mcl_bossbars.update_boss(self, "Ender Dragon", "light_purple") + end, on_die = function(self, pos) if not self._respawned then mcl_experience.throw_experience(pos, 11500) -- 500 + 11500 = 12000 diff --git a/mods/ENTITIES/mobs_mc/wither.lua b/mods/ENTITIES/mobs_mc/wither.lua index caf5a248d3..8e7f7eb95d 100644 --- a/mods/ENTITIES/mobs_mc/wither.lua +++ b/mods/ENTITIES/mobs_mc/wither.lua @@ -73,6 +73,7 @@ mobs:register_mob("mobs_mc:wither", { self.object:set_properties({textures={self.base_texture}}) self.armor = {undead = 80, fleshy = 80} end + mcl_bossbars.update_boss(self, "Wither", "dark_purple") end, on_spawn = function(self) minetest.sound_play("mobs_mc_wither_spawn", {object=self.object, gain=1.0, max_hear_distance=64}) @@ -115,4 +116,4 @@ mobs:register_arrow("mobs_mc:wither_skull", { --Spawn egg mobs:register_egg("mobs_mc:wither", S("Wither"), "mobs_mc_spawn_icon_wither.png", 0, true) -mcl_wip.register_wip_item("mobs_mc:wither") \ No newline at end of file +mcl_wip.register_wip_item("mobs_mc:wither") diff --git a/mods/HUD/mcl_bossbars/init.lua b/mods/HUD/mcl_bossbars/init.lua new file mode 100644 index 0000000000..38dbbe3762 --- /dev/null +++ b/mods/HUD/mcl_bossbars/init.lua @@ -0,0 +1,124 @@ +mcl_bossbars = { + bars = {}, + huds = {}, + colors = {"light_purple", "blue", "red", "green", "yellow", "dark_purple", "white"}, +} + +function mcl_bossbars.recalculate_colors() + local sorted = {} + local colors = mcl_bossbars.colors + local color_count = #colors + local frame_count = color_count * 2 + for i, color in ipairs(colors) do + local idx = i * 2 - 1 + local image = "mcl_bossbars.png" + .. "^[transformR270" + .. "^[verticalframe:" .. frame_count .. ":" .. (idx - 1) + .. "^(mcl_bossbars_empty.png" + .. "^[lowpart:%d:mcl_bossbars.png" + .. "^[transformR270" + .. "^[verticalframe:" .. frame_count .. ":" .. idx .. ")" + local _, hex = mcl_util.get_color(color) + sorted[color] = { + image = image, + hex = hex, + } + end + mcl_bossbars.colors_sorted = sorted +end + +function mcl_bossbars.update_bar(player, text, color, percentage) + local cdef = mcl_bossbars.colors_sorted[color] + table.insert(mcl_bossbars.bars[player:get_player_name()], {color = cdef.hex, text = text, image = string.format(cdef.image, percentage)}) +end + +function mcl_bossbars.update_boss(luaentity, name, color) + local object = luaentity.object + local text = luaentity.nametag + if not text or text == "" then + text = name + end + local percentage = math.floor(luaentity.health / luaentity.hp_max * 100) + for _, obj in pairs(minetest.get_objects_inside_radius(object:get_pos(), 128)) do + if obj:is_player() then + mcl_bossbars.update_bar(obj, text, color, percentage) + end + end +end + +minetest.register_on_joinplayer(function(player) + local name = player:get_player_name() + mcl_bossbars.huds[name] = {} + mcl_bossbars.bars[name] = {} +end) + +minetest.register_on_leaveplayer(function(player) + local name = player:get_player_name() + mcl_bossbars.huds[name] = nil + mcl_bossbars.bars[name] = nil +end) + +minetest.register_globalstep(function() + for _, player in pairs(minetest.get_connected_players()) do + local name = player:get_player_name() + local bars = mcl_bossbars.bars[name] + local huds = mcl_bossbars.huds[name] + local huds_new = {} + local i = 0 + + while #huds > 0 or #bars > 0 do + local bar = table.remove(bars, 1) + local hud = table.remove(huds, 1) + + if bar and not hud then + hud = { + color = bar.color, + image = bar.image, + text = bar.text, + text_id = player:hud_add({ + hud_elem_type = "text", + text = bar.text, + number = bar.color, + position = {x = 0.5, y = 0}, + alignment = {x = 0, y = 1}, + offset = {x = 0, y = i * 40}, + }), + image_id = player:hud_add({ + hud_elem_type = "image", + text = bar.image, + position = {x = 0.5, y = 0}, + alignment = {x = 0, y = 1}, + offset = {x = 0, y = i * 40 + 25}, + scale = {x = 3, y = 3}, + }), + } + elseif hud and not bar then + player:hud_remove(hud.text_id) + player:hud_remove(hud.image_id) + hud = nil + else + if bar.text ~= hud.text then + player:hud_change(hud.text_id, "text", bar.text) + hud.text = bar.text + end + + if bar.color ~= hud.color then + player:hud_change(hud.text_id, "number", bar.color) + hud.color = bar.color + end + + if bar.image ~= hud.image then + player:hud_change(hud.image_id, "text", bar.image) + hud.image = bar.image + end + end + + table.insert(huds_new, hud) + i = i + 1 + end + + mcl_bossbars.huds[name] = huds_new + end +end) + +mcl_bossbars.recalculate_colors() diff --git a/mods/HUD/mcl_bossbars/mod.conf b/mods/HUD/mcl_bossbars/mod.conf new file mode 100644 index 0000000000..64cbd4c9f7 --- /dev/null +++ b/mods/HUD/mcl_bossbars/mod.conf @@ -0,0 +1,4 @@ +name = mcl_bossbars +author = Fleckenstein +description = Show enderdragon & wither boss bars. Also allows custom bars. +depends = mcl_util, mcl_colors diff --git a/mods/HUD/mcl_bossbars/textures/mcl_bossbars.png b/mods/HUD/mcl_bossbars/textures/mcl_bossbars.png new file mode 100644 index 0000000000000000000000000000000000000000..55bf36dc288f271d12228a67a6a39c98c6ca18e9 GIT binary patch literal 3689 zcmai1cT^L~(hnlii#!lDfPhF-E?s(&5`qv2Ni-w~NC^-rL3-~BB1NKfNB}`XuK{TR z6hx^4f{m&IN{e(sFfaGr``zpHy>q@jXLn|2W`8sDJNw7(9jLi6C);T@006*g0yc!v zC5S#7Ss3Xn+=0Cs0AN=NMp*g6>;pu+ym8K0cZ`T{kQYV-6Nq&N00Q4t=Ggm-OIO{Z zx$)P>0;2T#85kDZga$Si6TnF173A?4ae|NVnR?cMl-(2jl8?3Xrk@-t6^XBA#!K zIJST7+v$5@3yJr)+f!YKaUn9qDBljr!uBxS(g1ZtN2p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0=NMJSS~PqY$8(KcnjpCDn%tkxoXM%%F>JNS7Vl}xge+Se zhW7+(o!Pan=->9%5prDP{%(_a!`fq_w(m;wweCL2y};P6>+&Z#j>Y`HVxc38pd)th fnwk(!NepGcs%U*f-ravruNYurWNuice?9u&V{+xc literal 0 HcmV?d00001 diff --git a/mods/HUD/mcl_bossbars/textures/mcl_bossbars_empty.png b/mods/HUD/mcl_bossbars/textures/mcl_bossbars_empty.png new file mode 100644 index 0000000000000000000000000000000000000000..1e50b6afc2a8dddc0748ae7763a5975ef6956b24 GIT binary patch literal 3369 zcmbVPS5Om-(hVh)P=!eEO{qeVUZoSHg-+-gYUm|EKuDC1fRsp+Dr%^Lpr4@h-jR+- zmk!bdGzgb(=70Sk?maVS&zv*6v#+~}CPun6AT|&H0HD#=(}LZo&J90Mkla)=7phtS z02CTwZXFDBM)CLu`nh=`5j?@+{s65H`OLH%%1~rM=t)qe&%abJhT4o__Co zmn3t)n|-g{{KDZGZCL>gv0&22CQ^|53X4`2*~$e0{s7wf4(v zQ>8m_akR28N<7MkZf%XYM0icw(b2n=fND6YWmnzMTk}Sb5kT82V^J%vZF|y;Mtd@P z4HHv^11cu)nZ*0mwI#Gos+-@Bo(5hIhs33B7Y?x0Lts;-g1EvmjiU9Oh0>+mz0$Q=~=Dy}?|T0qTF?^61L zeDy`*NfguA<&Ta7{53-1d};ADy4E}73k7{P+*B&EIEZXc77(ubkuo(&ttVVXx3i?K zmvTUSMBaaBk^z&=3Dd_#%zM5Z%@xuRYk0ew>4ClLH(`e#9~v<`;`gcegct;k2vr0A zKwpnqf6e{)^0ymo2uW!#?ELO2{4x4zYxBh&-C4Avmhet&W~G==U@-TQAZG%P%@6sG<= zSvqF2ITV{4E9$-6V_y$;zJ*^En(?kF56rf$oVILs6CV(})NKLp;_^$>>-^wmiy=``mH;W^OMPzwPPZXk?vTrY7@#Wp`lBs_Mh~D-5jQ zQJUULKkLH>Yv8DFe={3{-|U~S(ODbFc?ahlKmL^|(-3E?7N_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