1
0
mirror of https://github.com/HybridDog/nether-pack.git synced 2024-11-16 15:30:20 +01:00

Implemented HybridDog's change request.

- Modifications to `nether.is_player_in_nether()` and `nether.external_nether_teleport()`
- Renamed `players_in_nether[]` to `players_trapped_in_nether[]`
- Fixed punctuation in a comment. =D
This commit is contained in:
Deathwing777 2024-02-27 12:50:35 -08:00 committed by GitHub
parent 242a32e1ad
commit 2951813d2c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -11,7 +11,7 @@ minetest.after(5, function()
end) end)
local save_path = minetest.get_worldpath() .. "/nether_players" local save_path = minetest.get_worldpath() .. "/nether_players"
local players_in_nether = {} local players_trapped_in_nether = {}
-- Load the list of players which are trapped in the nether -- Load the list of players which are trapped in the nether
-- (or would be trapped if nether.trap_players was true) -- (or would be trapped if nether.trap_players was true)
@ -23,7 +23,7 @@ do
if contents then if contents then
local playernames = string.split(contents, " ") local playernames = string.split(contents, " ")
for i = 1,#playernames do for i = 1,#playernames do
players_in_nether[playernames[i]] = true players_trapped_in_nether[playernames[i]] = true
end end
end end
end end
@ -31,7 +31,7 @@ end
local function save_nether_players() local function save_nether_players()
local playernames,n = {},1 local playernames,n = {},1
for name in pairs(players_in_nether) do for name in pairs(players_trapped_in_nether) do
playernames[n] = name playernames[n] = name
n = n+1 n = n+1
end end
@ -43,20 +43,26 @@ end
-- Nether aware mods will need to know if a player is in the nether. -- Nether aware mods will need to know if a player is in the nether.
function nether.is_player_in_nether(player) function nether.is_player_in_nether(player)
return players_in_nether[player:get_player_name()] 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 end
-- Nether aware mods may have other means of moving players between the Nether -- 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 -- and Overworld, and if so, they should tell us about it so we can keep track
-- of the player state. -- of the player state.
function nether.external_nether_teleport(player) function nether.external_nether_teleport(player, pos)
local pos = player:get_pos() if not nether.trap_players then
local pname = player:get_player_name() player:set_pos(pos)
if (pos.y < nether.start) and (pos.y >= nether.bottom) then return
players_in_nether[pname] = true
else
players_in_nether[pname] = nil
end end
local destination_in_nether = (pos.y < nether.start) and (pos.y >= nether.bottom)
update_background(player, destination_in_nether)
local pname = player:get_player_name()
players_trapped_in_nether[pname] = destination_in_nether or nil
player:set_pos(pos)
end end
local update_background local update_background
@ -99,7 +105,7 @@ end
local function obsidian_teleport(player, pname, target) 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 any reason you arrived here. Type " ..
"/nether_help to find out things like craft recipes.") "/nether_help to find out things like craft recipes.")
players_in_nether[pname] = true players_trapped_in_nether[pname] = true
save_nether_players() save_nether_players()
update_background(player, true) update_background(player, true)
@ -113,7 +119,7 @@ end
-- teleports players to nether or helps it -- teleports players to nether or helps it
local function player_to_nether(player, pos) local function player_to_nether(player, pos)
local pname = player:get_player_name() local pname = player:get_player_name()
players_in_nether[pname] = true players_trapped_in_nether[pname] = true
save_nether_players() save_nether_players()
update_background(player, true) update_background(player, true)
if pos then if pos then
@ -132,8 +138,8 @@ end
local function player_from_nether(player, pos) local function player_from_nether(player, pos)
local pname = player:get_player_name() local pname = player:get_player_name()
if players_in_nether[pname] then if players_trapped_in_nether[pname] then
players_in_nether[pname] = nil players_trapped_in_nether[pname] = nil
save_nether_players() save_nether_players()
end end
update_background(player, false) update_background(player, false)
@ -257,7 +263,7 @@ if nether.trap_players then
-- randomly set player position when he/she dies in nether -- randomly set player position when he/she dies in nether
minetest.register_on_respawnplayer(function(player) minetest.register_on_respawnplayer(function(player)
local pname = player:get_player_name() local pname = player:get_player_name()
if not players_in_nether[pname] then if not players_trapped_in_nether[pname] then
return return
end end
local target = get_player_died_target(player) local target = get_player_died_target(player)
@ -272,14 +278,14 @@ if nether.trap_players then
return true return true
end) end)
-- override set_pos etc. to disallow player teleportion by e.g. travelnet -- override set_pos etc, to disallow player teleportion by e.g. travelnet
local function can_teleport(player, pos) local function can_teleport(player, pos)
if not player:is_player() then if not player:is_player() then
-- the same metatable is used for entities -- the same metatable is used for entities
return true return true
end end
local pname = player:get_player_name() local pname = player:get_player_name()
local in_nether = players_in_nether[pname] == true local in_nether = players_trapped_in_nether[pname] == true
-- test if the target is valid -- test if the target is valid
if pos.y < nether.start then if pos.y < nether.start then
@ -374,7 +380,7 @@ local particledef = {
-- teleports player to neter (obsidian portal) -- teleports player to neter (obsidian portal)
local function obsi_teleport_player(player, pos, target) local function obsi_teleport_player(player, pos, target)
local pname = player:get_player_name() local pname = player:get_player_name()
if players_in_nether[pname] then if players_trapped_in_nether[pname] then
return return
end end