mirror of
https://github.com/minetest-mods/nether.git
synced 2024-12-28 03:40:28 +01:00
Avoid storing the playerRef
See https://rubenwardy.com/minetest_modding_book/en/quality/common_mistakes.html#never-store-objectrefs-ie-players-or-entities Related: https://github.com/minetest-mods/nether/pull/12
This commit is contained in:
parent
40913ee841
commit
363872c760
@ -1167,13 +1167,14 @@ local function ignite_portal(ignition_pos, ignition_node_name)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- invoked when a player is standing in a portal
|
-- invoked when a player is standing in a portal
|
||||||
local function ensure_remote_portal_then_teleport(player, portal_definition, local_anchorPos, local_orientation, destination_wormholePos)
|
local function ensure_remote_portal_then_teleport(playerName, portal_definition, local_anchorPos, local_orientation, destination_wormholePos)
|
||||||
|
|
||||||
|
local player = minetest.get_player_by_name(playerName)
|
||||||
|
if player == nil then return end -- player quit the game while teleporting
|
||||||
|
local playerPos = player:get_pos()
|
||||||
|
if playerPos == nil then return end -- player quit the game while teleporting
|
||||||
|
|
||||||
-- check player is still standing in a portal
|
-- check player is still standing in a portal
|
||||||
local playerPos = player:get_pos()
|
|
||||||
if playerPos == nil then
|
|
||||||
return -- player quit the game while teleporting
|
|
||||||
end
|
|
||||||
playerPos.y = playerPos.y + 0.1 -- Fix some glitches at -8000
|
playerPos.y = playerPos.y + 0.1 -- Fix some glitches at -8000
|
||||||
if minetest.get_node(playerPos).name ~= portal_definition.wormhole_node_name then
|
if minetest.get_node(playerPos).name ~= portal_definition.wormhole_node_name then
|
||||||
return -- the player has moved out of the portal
|
return -- the player has moved out of the portal
|
||||||
@ -1193,7 +1194,7 @@ local function ensure_remote_portal_then_teleport(player, portal_definition, loc
|
|||||||
if dest_wormhole_node == nil then
|
if dest_wormhole_node == nil then
|
||||||
-- area not emerged yet, delay and retry
|
-- area not emerged yet, delay and retry
|
||||||
if DEBUG then minetest.chat_send_all("ensure_remote_portal_then_teleport() could not find anything yet at " .. minetest.pos_to_string(destination_wormholePos)) end
|
if DEBUG then minetest.chat_send_all("ensure_remote_portal_then_teleport() could not find anything yet at " .. minetest.pos_to_string(destination_wormholePos)) end
|
||||||
minetest.after(1, ensure_remote_portal_then_teleport, player, portal_definition, local_anchorPos, local_orientation, destination_wormholePos)
|
minetest.after(1, ensure_remote_portal_then_teleport, playerName, portal_definition, local_anchorPos, local_orientation, destination_wormholePos)
|
||||||
else
|
else
|
||||||
local local_wormholePos = portal_definition.shape.get_wormholePos_from_anchorPos(local_anchorPos, local_orientation)
|
local local_wormholePos = portal_definition.shape.get_wormholePos_from_anchorPos(local_anchorPos, local_orientation)
|
||||||
|
|
||||||
@ -1225,7 +1226,7 @@ local function ensure_remote_portal_then_teleport(player, portal_definition, loc
|
|||||||
|
|
||||||
-- play the teleport sound
|
-- play the teleport sound
|
||||||
if portal_definition.sounds.teleport ~= nil then
|
if portal_definition.sounds.teleport ~= nil then
|
||||||
minetest.sound_play(portal_definition.sounds.teleport, {to_player = player.name})
|
minetest.sound_play(portal_definition.sounds.teleport, {to_player = playerName})
|
||||||
end
|
end
|
||||||
|
|
||||||
-- rotate the player if the destination portal is a different orientation
|
-- rotate the player if the destination portal is a different orientation
|
||||||
@ -1265,7 +1266,7 @@ local function ensure_remote_portal_then_teleport(player, portal_definition, loc
|
|||||||
destination_wormholePos
|
destination_wormholePos
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
minetest.after(0.1, ensure_remote_portal_then_teleport, player, portal_definition, local_anchorPos, local_orientation, destination_wormholePos)
|
minetest.after(0.1, ensure_remote_portal_then_teleport, playerName, portal_definition, local_anchorPos, local_orientation, destination_wormholePos)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -1315,11 +1316,12 @@ function run_wormhole(timerPos, time_elapsed)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local local_anchorPos, local_orientation = portal_definition.shape.get_anchorPos_and_orientation_from_p1_and_p2(local_p1, local_p2)
|
local local_anchorPos, local_orientation = portal_definition.shape.get_anchorPos_and_orientation_from_p1_and_p2(local_p1, local_p2)
|
||||||
|
local playerName = obj:get_player_name()
|
||||||
minetest.after(
|
minetest.after(
|
||||||
3, -- hopefully target area is emerged in 3 seconds
|
3, -- hopefully target area is emerged in 3 seconds
|
||||||
function()
|
function()
|
||||||
ensure_remote_portal_then_teleport(
|
ensure_remote_portal_then_teleport(
|
||||||
obj,
|
playerName,
|
||||||
portal_definition,
|
portal_definition,
|
||||||
local_anchorPos,
|
local_anchorPos,
|
||||||
local_orientation,
|
local_orientation,
|
||||||
|
@ -16,7 +16,8 @@ Optionally decorate by choosing portal colors, particles, media etc.
|
|||||||
See `init.lua` and `portal_examples.lua` for examples of 3 different portals.
|
See `init.lua` and `portal_examples.lua` for examples of 3 different portals.
|
||||||
|
|
||||||
Portal code is more efficient when each type of portal uses a different type
|
Portal code is more efficient when each type of portal uses a different type
|
||||||
of node to build its frame out of, however it is possible to register more than
|
of node to build its frame out of - consider creating your own node for
|
||||||
|
players to build portals from. However it is possible to register more than
|
||||||
one kind of portal with the same frame material — such as obsidian — provided
|
one kind of portal with the same frame material — such as obsidian — provided
|
||||||
the size of the PortalShape is distinct from any other type of portal that is
|
the size of the PortalShape is distinct from any other type of portal that is
|
||||||
using the same node for its frame, and portal sizes remain small.
|
using the same node for its frame, and portal sizes remain small.
|
||||||
|
Loading…
Reference in New Issue
Block a user