From 605f1b4cc9836931e2a40274eea1ac5f2689e9c7 Mon Sep 17 00:00:00 2001 From: MysticTempest Date: Thu, 28 Jul 2022 05:27:48 -0500 Subject: [PATCH] Cleanup, and add a flag on world creation to remember Hardcore mode. --- mods/HUD/hudbars/init.lua | 10 +-- mods/ITEMS/mcl_potions/functions.lua | 7 +- mods/PLAYER/mcl_hardcore/init.lua | 66 ++++++++++++------ .../textures/hudbars_icon_health_hardcore.png | Bin 0 -> 948 bytes settingtypes.txt | 2 +- 5 files changed, 53 insertions(+), 32 deletions(-) create mode 100644 mods/PLAYER/mcl_hardcore/textures/hudbars_icon_health_hardcore.png diff --git a/mods/HUD/hudbars/init.lua b/mods/HUD/hudbars/init.lua index 955375fa2d..505ff403b8 100644 --- a/mods/HUD/hudbars/init.lua +++ b/mods/HUD/hudbars/init.lua @@ -486,17 +486,9 @@ function hb.get_hudbar_identifiers() return ids end - -local hardcore_mode = minetest.settings:get_bool("hardcore_mode_enabled", false) -if hardcore_mode then - heart_texture_fg = "hudbars_icon_health_hardcore.png" -else - heart_texture_fg = "hudbars_icon_health.png" -end - --register built-in HUD bars if minetest.settings:get_bool("enable_damage") or hb.settings.forceload_default_hudbars then - hb.register_hudbar("health", 0xFFFFFF, S("Health"), { bar = "hudbars_bar_health.png", icon = heart_texture_fg, bgicon = "hudbars_bgicon_health.png" }, 0, 20, 20, false) + hb.register_hudbar("health", 0xFFFFFF, S("Health"), { bar = "hudbars_bar_health.png", icon = "hudbars_icon_health.png", bgicon = "hudbars_bgicon_health.png" }, 0, 20, 20, false) hb.register_hudbar("breath", 0xFFFFFF, S("Breath"), { bar = "hudbars_bar_breath.png", icon = "hudbars_icon_breath.png", bgicon = "hudbars_bgicon_breath.png" }, 1, 10, 10, true) end diff --git a/mods/ITEMS/mcl_potions/functions.lua b/mods/ITEMS/mcl_potions/functions.lua index fb8e2194db..6a1c1ef87c 100644 --- a/mods/ITEMS/mcl_potions/functions.lua +++ b/mods/ITEMS/mcl_potions/functions.lua @@ -17,9 +17,14 @@ end local icon_ids = {} +-- Hardcore mode Healthbar change local hardcore_mode = minetest.settings:get_bool("hardcore_mode_enabled", false) +local file = io.open(minetest.get_worldpath().."/hardcore_mode.txt", "r") +if file ~= nil then + hardcore_world = true +end -if hardcore_mode then +if hardcore_mode or hardcore_world then heart_texture_fg = "hudbars_icon_health_hardcore.png" else heart_texture_fg = "hudbars_icon_health.png" diff --git a/mods/PLAYER/mcl_hardcore/init.lua b/mods/PLAYER/mcl_hardcore/init.lua index 04902b258f..326a7e63ca 100644 --- a/mods/PLAYER/mcl_hardcore/init.lua +++ b/mods/PLAYER/mcl_hardcore/init.lua @@ -8,13 +8,24 @@ of the license, or (at your option) any later version. --]] ---Spectator mode: +-- Spectator mode: -- Players are unable to interact with the world, invisible, have fast, fly & noclip, are immortal and their health/hunger hudbars are hidden. +-- +-- + +mcl_hardcore = {} + +-- Write Hardcore mode state to world. +function mcl_hardcore.save() + local file = io.open(minetest.get_worldpath().."/hardcore_mode.txt", "w") + if file then + file:write("Enabled") + file:close() + end +end -- Spectator mode -mcl_hardcore = {} - function mcl_hardcore.spectator_mode(player) local meta = player:get_meta() local player_name = player:get_player_name() @@ -53,6 +64,7 @@ function mcl_hardcore.spectator_mode_disabled(player) elseif meta:get_string("gamemode") == "creative" then privs.fast = nil privs.noclip = nil + privs.fly = true privs.interact = true minetest.set_player_privs(player_name, privs) else -- survival; only basic privs @@ -62,8 +74,18 @@ function mcl_hardcore.spectator_mode_disabled(player) end -local hardcore_mode = minetest.settings:get_bool("hardcore_mode_enabled", false) -if hardcore_mode then +-- Hardcore mode +function mcl_hardcore.hardcore_mode(player) + local meta = player:get_meta() + local player_name = player:get_player_name() + if meta:get_int("dead") == 1 then + mcl_hardcore.spectator_mode(player) + minetest.chat_send_player(player_name, "You died in hardcore mode; rejoining as a spectator.") + else + minetest.after(4, function(player) + hb.change_hudbar(player, "health", nil, nil, "hudbars_icon_health_hardcore.png", nil, "hudbars_bar_health.png") + end, player) + end minetest.register_on_dieplayer(function(player, reason) local name = player:get_player_name() @@ -80,20 +102,22 @@ if hardcore_mode then minetest.chat_send_player(player_name, "You died in hardcore mode; respawning as a spectator.") end end) - - -- If hardcore is enabled or re-enabled, & you've already died once; ensure that you're a spectator when rejoining. - minetest.register_on_joinplayer(function(player) - local meta = player:get_meta() - local player_name = player:get_player_name() - if meta:get_int("dead") == 1 then - mcl_hardcore.spectator_mode(player) - minetest.chat_send_player(player_name, "You died in hardcore mode; rejoining as a spectator.") - end - end) - -else - -- If hardcore disabled, make sure settings are back to basics via the 'spectator_mode_disabled' function. - minetest.register_on_joinplayer(function(player) - mcl_hardcore.spectator_mode_disabled(player) - end) end + + +local hardcore_mode = minetest.settings:get_bool("hardcore_mode_enabled", false) +--Set world state: +minetest.register_on_joinplayer(function(player) + if minetest.get_gametime() <= 5 and hardcore_mode then + mcl_hardcore.save() + else + local file = io.open(minetest.get_worldpath().."/hardcore_mode.txt", "r") + if file ~= nil then + hardcore_world = true + end + end + if hardcore_mode or hardcore_world then + mcl_hardcore.hardcore_mode(player) + end + +end) diff --git a/mods/PLAYER/mcl_hardcore/textures/hudbars_icon_health_hardcore.png b/mods/PLAYER/mcl_hardcore/textures/hudbars_icon_health_hardcore.png new file mode 100644 index 0000000000000000000000000000000000000000..47e8b326a745f6a173ea771a9edd424a4a4bac10 GIT binary patch literal 948 zcmV;l155mgP)cL{9cp}r&({*iUR8db>KPX5zD6g!g<>cU*Y(R2QEy>5hf?PH;CK-f&cax5Y z0LdW$hY!&6{Cm3KFp9q&WUv`wtPDMt5nQ8NTU&<78aOyOS%(h}PMwKpQ%*WEWo;Wc zDkR&zj8#$@+ih9Ss(polC;zGdgk=E#T>yMG0EcaCXi-p6KR$$gWN2kjQBOWrN=iaF zI5R6Nx{NAGGcid=F)bq_{{R4j000&i78@HI4Gj$(9VkaiR3s)d2ni1~Sw(Z6Yd&U7 z96B&OAumrjKSU@tFc&C}FhI3UO`ADHa3MD>PLWJ{vN>g&Av%04EG%bIL{UIBNl8gP zJw07XJaJk_K{YEG85sah{{Sh1|NsAVbaZufb#``kcXxMqczAhvd3t(!dwY9)e0+U< zeSUs^e}8{~fPjI4fr5g9gM)*FgoK5Kg@%TPhlhuVh=_@aiHeGfi;IhljEs$qjgF3v zkB^U#kdTp)k&=>Cc=sHmx_sj8}~tE;Q5tgNlAt*)-FudlDLu&}YQ zv9hwVv$M0bw6wLgwYIjlx3{;rxVX8wxw^W#ySux*yu7`=y}rJ_zrVl0z`()5!NS7A z!^6YG#KgtL#m2_Q$H&LW$jHgb$;!&g%gf8m%*@Tr&Cbrw&(F`$(9qG*(bCe=)6>(` z)YR40)z;S5*VotB*x1?G+1lFL+uPgR+}z#W-QM2b-{0Th;Naom;o{=ruz*=jZ3>=;-O`>FVn0>+9?6?CkCB?e6aG@9*#M@bK~R@$&NW^Yioc^z`-h_4fAm z_xJbs`1twx`TF|$`}_O+{QUj>{r>*`|Ns9YD?md40004WQchCPx#Hc3Q5 zR0!8a%*zP?FbD(Cc+90)F8j~YsL%?5=LdmbwkI&jq|(wS)>F@vrB!_>aWGu$AK(Jf W)Cx#JrCHVh0000