Made changes after testing previous commit.

init.lua:
- Added `nether.bottom`

portal.lua:
- Reverted `nether.is_player_in_nether(player)` to previous state.
- Added `nether.is_player_trapped_in_nether(player)`
- Added 2 new chat functions for debugging purposes.
- Tested that chat function `/update_hells_registry` indeed works to check if a player has dug their way out of the nether.
- Moved the functional code from `/update_hells_registry` to `nether.registry_update(player)`
- Fixed some English grammar in automated chat messages.
This commit is contained in:
Deathwing777 2024-02-27 17:49:30 -08:00 committed by GitHub
parent 2951813d2c
commit 84d5e1ce3c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 59 additions and 10 deletions

View File

@ -52,6 +52,9 @@ nether.start = f_h_max+100
-- Height of the nether (bottom of the nether is nether_middle - NETHER_HEIGHT)
local NETHER_HEIGHT = 30
-- bottom height of the nether.
nether.bottom = nether_middle - NETHER_HEIGHT
-- Maximum amount of randomness in the map generation
local NETHER_RANDOM = 2

View File

@ -43,13 +43,15 @@ end
-- Nether aware mods will need to know if a player is in the nether.
function nether.is_player_in_nether(player)
if nether.trap_players then
return players_trapped_in_nether[player:get_player_name()]
end
local pos = player:get_pos()
return (pos.y < nether.start) and (pos.y >= nether.bottom)
end
-- For testing nether trap state tracking.
function nether.is_player_trapped_in_nether(player)
return players_trapped_in_nether[player:get_player_name()]
end
-- Nether aware mods may have other means of moving players between the Nether
-- and Overworld, and if so, they should tell us about it so we can keep track
-- of the player state.
@ -65,6 +67,21 @@ function nether.external_nether_teleport(player, pos)
player:set_pos(pos)
end
-- Has the player dug their way out of the nether?
-- Has nether.trap_players been disabled?
function nether.registry_update(player)
local pos = player:get_pos()
local in_nether = (pos.y < nether.start) and (pos.y >= nether.bottom)
local pname = player:get_player_name()
if nether.trap_players then
players_trapped_in_nether[pname] = in_nether
update_background(player, in_nether)
else if players_trapped_in_nether[pname]
players_trapped_in_nether[pname] = nil
update_background(player, false)
end
end
local update_background
if nether.trap_players then
function update_background(player, down)
@ -103,7 +120,7 @@ end
-- used for obsidian portal
local function obsidian_teleport(player, pname, target)
minetest.chat_send_player(pname, "For any reason you arrived here. Type " ..
minetest.chat_send_player(pname, "For some reason you arrived here. Type " ..
"/nether_help to find out things like craft recipes.")
players_trapped_in_nether[pname] = true
save_nether_players()
@ -126,7 +143,7 @@ local function player_to_nether(player, pos)
player:set_pos(pos)
return
end
minetest.chat_send_player(pname, "For any reason you arrived here. " ..
minetest.chat_send_player(pname, "For some reason you arrived here. " ..
"Type /nether_help to find out things like craft recipes.")
if nether.trap_players then
player:set_hp(0)
@ -229,6 +246,35 @@ minetest.register_chatcommand("in_hell", {
end
})
-- Useful for debugging Nether player state tracking. Written by Deathwing777
minetest.register_chatcommand("trapped_in_hell", {
params = "[<player_name>]",
description = "Is the player trapped in hell?",
func = function(name, pname)
if not minetest.check_player_privs(name, {nether=true}) then
return false,
"You need the nether priv to execute this chatcommand."
end
if not player_exists(pname) then
pname = name
end
local player = minetest.get_player_by_name(pname)
if not player then
return false, "Something went wrong."
end
local status = pname
if nether.is_player_trapped_in_nether(player) then
status = status.." is TRAPPED in nether!"
else
status = status.." is NOT trapped in nether!"
end
return true, status
end
})
-- Useful for debugging Nether player state tracking. Written by Deathwing777
minetest.register_chatcommand("update_hells_registry", {
params = "[<player_name>]",
description = "Update player state if they got to or from the nether in another way.",
@ -245,12 +291,12 @@ minetest.register_chatcommand("update_hells_registry", {
return false, "Something went wrong."
end
nether.external_nether_teleport(player)
local status = pname.." is in the "
if nether.is_player_in_nether(player) then
status = status.."NETHER!"
nether.registry_update(player)
local status = pname
if nether.is_player_trapped_in_nether(player) then
status = status.." is TRAPPED in nether!"
else
status = status.."OVERWORLD!"
status = status.." is NOT trapped in nether!"
end
return true, status