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 0000000000..55bf36dc28 Binary files /dev/null and b/mods/HUD/mcl_bossbars/textures/mcl_bossbars.png differ 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 0000000000..1e50b6afc2 Binary files /dev/null and b/mods/HUD/mcl_bossbars/textures/mcl_bossbars_empty.png differ