diff --git a/mods/HUD/hudbars/init.lua b/mods/HUD/hudbars/init.lua index fa04cdcbe..505ff403b 100644 --- a/mods/HUD/hudbars/init.lua +++ b/mods/HUD/hudbars/init.lua @@ -486,16 +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 3810acf59..155c31931 100644 --- a/mods/ITEMS/mcl_potions/functions.lua +++ b/mods/ITEMS/mcl_potions/functions.lua @@ -16,9 +16,15 @@ for _,_ in pairs(EF) do end local icon_ids = {} -local hardcore_mode = minetest.settings:get_bool("hardcore_mode_enabled", false) -if hardcore_mode then +-- 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 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 2c0004499..326a7e63c 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() @@ -63,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() @@ -81,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/HUD/hudbars/textures/hudbars_icon_health_hardcore.png b/mods/PLAYER/mcl_hardcore/textures/hudbars_icon_health_hardcore.png similarity index 100% rename from mods/HUD/hudbars/textures/hudbars_icon_health_hardcore.png rename to mods/PLAYER/mcl_hardcore/textures/hudbars_icon_health_hardcore.png diff --git a/settingtypes.txt b/settingtypes.txt index 7b36195ea..fc3863a34 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -39,7 +39,7 @@ mcl_doTileDrops (Blocks have drops) bool true # If enabled, TNT explosions destroy blocks. mcl_tnt_griefing (TNT destroys blocks) bool true -# If enabled, you will only have 1 life to use. After death you will be dropped into spectator mode, and unable to interact with the world while 'hardcore_mode' is enabled. +# If enabled, you will only have 1 life to use. After death you will be dropped into spectator mode, and unable to interact with the world. hardcore_mode_enabled (Enable Hardcore mode) bool false [Players]