From 18a63e2b74faf93be98190b7c4a451f5c197477a Mon Sep 17 00:00:00 2001 From: MysticTempest Date: Sun, 6 Nov 2022 03:08:58 -0600 Subject: [PATCH] Add a basic hardcore_mode that's enabled via the game menu settings. --- mods/HUD/mcl_inventory/init.lua | 7 +- mods/ITEMS/mcl_potions/functions.lua | 34 +++-- mods/PLAYER/mcl_hardcore/README.md | 32 +++++ mods/PLAYER/mcl_hardcore/init.lua | 129 ++++++++++++++++++ mods/PLAYER/mcl_hardcore/mod.conf | 4 + .../hbhunger_icon_health_poison_hardcore.png | Bin 0 -> 281 bytes .../hbhunger_icon_regen_poison_hardcore.png | Bin 0 -> 299 bytes .../textures/hudbars_icon_health_hardcore.png | Bin 0 -> 948 bytes .../hudbars_icon_regenerate_hardcore.png | Bin 0 -> 292 bytes settingtypes.txt | 10 ++ 10 files changed, 207 insertions(+), 9 deletions(-) create mode 100644 mods/PLAYER/mcl_hardcore/README.md create mode 100644 mods/PLAYER/mcl_hardcore/init.lua create mode 100644 mods/PLAYER/mcl_hardcore/mod.conf create mode 100644 mods/PLAYER/mcl_hardcore/textures/hbhunger_icon_health_poison_hardcore.png create mode 100644 mods/PLAYER/mcl_hardcore/textures/hbhunger_icon_regen_poison_hardcore.png create mode 100644 mods/PLAYER/mcl_hardcore/textures/hudbars_icon_health_hardcore.png create mode 100644 mods/PLAYER/mcl_hardcore/textures/hudbars_icon_regenerate_hardcore.png diff --git a/mods/HUD/mcl_inventory/init.lua b/mods/HUD/mcl_inventory/init.lua index 2c7c64860..9cdc5557d 100644 --- a/mods/HUD/mcl_inventory/init.lua +++ b/mods/HUD/mcl_inventory/init.lua @@ -233,7 +233,8 @@ end local gamemodes = { "survival", - "creative" + "creative", + "spectator" } function mcl_inventory.player_set_gamemode(p,g) @@ -242,8 +243,12 @@ function mcl_inventory.player_set_gamemode(p,g) if g == "survival" then mcl_experience.setup_hud(p) mcl_experience.update(p) + mcl_hardcore.spectator_mode_disabled(p) elseif g == "creative" then mcl_experience.remove_hud(p) + mcl_hardcore.spectator_mode_disabled(p) + elseif g == "spectator" then + mcl_hardcore.spectator_mode(p) end set_inventory(p) end diff --git a/mods/ITEMS/mcl_potions/functions.lua b/mods/ITEMS/mcl_potions/functions.lua index 15be8a90c..c7291e53b 100644 --- a/mods/ITEMS/mcl_potions/functions.lua +++ b/mods/ITEMS/mcl_potions/functions.lua @@ -17,18 +17,36 @@ end local icon_ids = {} +-- Hardcore mode Healthbar change +local file = io.open(minetest.get_worldpath().."/hardcore_mode.txt", "r") +if file ~= nil then + hardcore_world = true +end + local function potions_set_hudbar(player) + if hardcore_world then - if EF.poisoned[player] and EF.regenerating[player] then - hb.change_hudbar(player, "health", nil, nil, "hbhunger_icon_regen_poison.png", nil, "hudbars_bar_health.png") - elseif EF.poisoned[player] then - hb.change_hudbar(player, "health", nil, nil, "hbhunger_icon_health_poison.png", nil, "hudbars_bar_health.png") - elseif EF.regenerating[player] then - hb.change_hudbar(player, "health", nil, nil, "hudbars_icon_regenerate.png", nil, "hudbars_bar_health.png") + if EF.poisoned[player] and EF.regenerating[player] then + hb.change_hudbar(player, "health", nil, nil, "hbhunger_icon_regen_poison_hardcore.png", nil, "hudbars_bar_health.png") + elseif EF.poisoned[player] then + hb.change_hudbar(player, "health", nil, nil, "hbhunger_icon_health_poison_hardcore.png", nil, "hudbars_bar_health.png") + elseif EF.regenerating[player] then + hb.change_hudbar(player, "health", nil, nil, "hudbars_icon_regenerate_hardcore.png", nil, "hudbars_bar_health.png") + else + hb.change_hudbar(player, "health", nil, nil, "hudbars_icon_health_hardcore.png", nil, "hudbars_bar_health.png") + end else - hb.change_hudbar(player, "health", nil, nil, "hudbars_icon_health.png", nil, "hudbars_bar_health.png") - end + if EF.poisoned[player] and EF.regenerating[player] then + hb.change_hudbar(player, "health", nil, nil, "hbhunger_icon_regen_poison.png", nil, "hudbars_bar_health.png") + elseif EF.poisoned[player] then + hb.change_hudbar(player, "health", nil, nil, "hbhunger_icon_health_poison.png", nil, "hudbars_bar_health.png") + elseif EF.regenerating[player] then + hb.change_hudbar(player, "health", nil, nil, "hudbars_icon_regenerate.png", nil, "hudbars_bar_health.png") + else + hb.change_hudbar(player, "health", nil, nil, "hudbars_icon_health.png", nil, "hudbars_bar_health.png") + end + end end local function potions_init_icons(player) diff --git a/mods/PLAYER/mcl_hardcore/README.md b/mods/PLAYER/mcl_hardcore/README.md new file mode 100644 index 000000000..6b2d91a0e --- /dev/null +++ b/mods/PLAYER/mcl_hardcore/README.md @@ -0,0 +1,32 @@ + +## mcl_hardcore + + +A fork of: YOLO - You Only Live Once by sofar +Heavily modified by MysticTempest for MineClone2 + +A simple player-based hardcore mod. + +Players will only have one life in hardcore mode, after dying they will be placed into spectator mode. +As spectators, they will be be: unable to interact with the world, immortal, invisible, have noclip and fly, and health/hunger hudbars will be hidden. + + +Enabling: +Enabled via a "Settings" option; newly created worlds will be set to Hardcore Mode. + +Extra Note: +You only need to toggle it on when creating a hardcore world. + +After doing so; you may 'disable' it again to create non-hardcore worlds. +Hardcore mode for that world will persist after world creation, and across any "Settings" change. + + + +--------- +Code: + Author: Copyright (C) 2019 - Auke Kok + Copyright (C) 2022 - MysticTempest + License: LGPL-2.1-or-later + +Texture: + "*_hardcore.png" - derivative of PixelPerfection heart textures: CC-By SA 4.0 diff --git a/mods/PLAYER/mcl_hardcore/init.lua b/mods/PLAYER/mcl_hardcore/init.lua new file mode 100644 index 000000000..47d1c6f7b --- /dev/null +++ b/mods/PLAYER/mcl_hardcore/init.lua @@ -0,0 +1,129 @@ +--[[ +Copyright (C) 2019 - Auke Kok +Copyright (C) 2022 - MysticTempest + +"mcl_hardcore" is a fork of "yolo", is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as +published by the Free Software Foundation; either version 2.1 +of the license, or (at your option) any later version. + +--]] + +-- 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 + hardcore_world = true +end + + +-- Spectator mode +function mcl_hardcore.spectator_mode(player) + local meta = player:get_meta() + local player_name = player:get_player_name() + + meta:set_int("mcl_privs:interact_revoked", 1) + player:set_armor_groups({immortal=1}) + minetest.set_player_privs(player_name, {fly=true,fast=true,noclip=true,interact=nil}) + + -- Have to wait since mcl_potions clears old effects on startup. + minetest.after(3, function(player) + mcl_potions._reset_player_effects(player) -- Fix some cases of not clearing. + mcl_potions.invisiblility_func(player, null, 86400) -- Invisible for 24 hours. + hb.hide_hudbar(player, "hunger") + hb.change_hudbar(player, "health", nil, nil, "blank.png", nil, "hudbars_bar_health.png") + mcl_experience.remove_hud(player) + end, player) + if meta:get_string("gamemode") ~= "spectator" then + meta:set_string("gamemode","spectator") + end +end + +function mcl_hardcore.spectator_mode_disabled(player) + local meta = player:get_meta() + local player_name = player:get_player_name() + local privs = minetest.get_player_privs(player_name) + + + if meta:get_int("dead") == 1 and hardcore_world==true then + meta:set_string("gamemode","spectator") + minetest.chat_send_player(player_name, "You died in hardcore mode; spectator mode not disabled.") + return + else + minetest.after(3, function(player) -- Fix startup crash conflict by waiting slightly. + mcl_potions._reset_player_effects(player) + mcl_potions.invisiblility_func(player, null, 0) + hb.unhide_hudbar(player, "hunger") + meta:set_int("mcl_privs:interact_revoked", 0) + player:set_armor_groups({immortal=0}) + + -- Try to preserve privs somewhat + if meta:get_string("gamemode") == "spectator" then + meta:set_string("gamemode","") + 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 + minetest.set_player_privs(player_name, {basic_privs=true}) + end + end, player) + end +end + + +-- 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.") + end + + minetest.register_on_dieplayer(function(player, reason) + local name = player:get_player_name() + local meta = player:get_meta() + meta:set_int("dead", 1) + end) + + -- Make player a spectator on respawn in hardcore mode. + minetest.register_on_respawnplayer(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; respawning as a spectator.") + end + end) +end + + +local hardcore_mode = minetest.settings:get_bool("enable_hardcore_mode", 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_world then + mcl_hardcore.hardcore_mode(player) + end + +end) diff --git a/mods/PLAYER/mcl_hardcore/mod.conf b/mods/PLAYER/mcl_hardcore/mod.conf new file mode 100644 index 000000000..b760103f5 --- /dev/null +++ b/mods/PLAYER/mcl_hardcore/mod.conf @@ -0,0 +1,4 @@ +name = mcl_hardcore +license = LGPL-2.1 +description = Hardcore mode - death is permanent. A fork of sofar's YOLO mod. +depends = mcl_potions, hudbars, mcl_inventory diff --git a/mods/PLAYER/mcl_hardcore/textures/hbhunger_icon_health_poison_hardcore.png b/mods/PLAYER/mcl_hardcore/textures/hbhunger_icon_health_poison_hardcore.png new file mode 100644 index 0000000000000000000000000000000000000000..b1983b8c0ce92f0c0e5d70136d1d013234815879 GIT binary patch literal 281 zcmeAS@N?(olHy`uVBq!ia0vp^oFL4>1|%O$WD@{VY)RhkE)4%caKYZ?lR?r29+AZi z4BWyX%*Zfnjs#GUy~NYkmHinv8=Iwo=b5|nfI`bWT^vIsE+;1_Fc}yb7#KvbuKwH3 zDHC1YeNijo?f?Gs^^y`maPIA{(tNC~O0L$b% zCJ)(~Cv-5x99+g}E@AOA0;EfzYeVDv`E|-7duuSvc2v9#sKofsk3Zs%3T9*}n?L>EbV;TlJAvzgnxb~g#zZcV^$Z$n4*OHg8y$cy OX7F_Nb6Mw<&;$T3P-H6r literal 0 HcmV?d00001 diff --git a/mods/PLAYER/mcl_hardcore/textures/hbhunger_icon_regen_poison_hardcore.png b/mods/PLAYER/mcl_hardcore/textures/hbhunger_icon_regen_poison_hardcore.png new file mode 100644 index 0000000000000000000000000000000000000000..fb1e979f9de21acdfc0fa5cb8bba2c9b92826f52 GIT binary patch literal 299 zcmeAS@N?(olHy`uVBq!ia0vp^oFL4>1|%O$WD@{VY)RhkE)4%caKYZ?lR?r29+AZi z4BWyX%*Zfnjs#GUy~NYkmHinv8=IvlIYEks# zWs^Tpej&pka%*G_gW-%Cro%UscW6a?WAbM9W$T{7+jN58IU-^Q+uwGb4)eQ*f4+Md z^COwXq2G$xE8f3?Zy1eEw3UJzMK!q z7G?0-ziWx-w??IkJM(&;#hR_Iop)(=3D;5E#m&L;4QaO@7FJJEll++1wn5~lUd}<2 olO1!Jg?3C*f12>HboYLSW6`d$7g(O|0{Vf$)78&qol`;+0KRc?=l}o! literal 0 HcmV?d00001 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{v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