From 48f46d29852305786291f2e7e02004e2dd4c13f6 Mon Sep 17 00:00:00 2001 From: Oversword Date: Fri, 28 Jan 2022 19:29:04 +0000 Subject: [PATCH] Load the travelnet node before performing teleport logic on it (#27) * Move load retrying from the rotate_player method to outside of the existance check --- functions.lua | 12 ++---------- on_receive_fields.lua | 37 +++++++++++++++++-------------------- 2 files changed, 19 insertions(+), 30 deletions(-) diff --git a/functions.lua b/functions.lua index a41b96b..ad3f4fe 100644 --- a/functions.lua +++ b/functions.lua @@ -227,16 +227,9 @@ function travelnet.open_close_door(pos, player, mode) end end - -travelnet.rotate_player = function(target_pos, player, tries) - -- try later when the box is loaded +travelnet.rotate_player = function(target_pos, player) local target_node = minetest.get_node_or_nil(target_pos) - if target_node == nil then - if tries < 30 then - minetest.after(0, travelnet.rotate_player, target_pos, player, tries+1) - end - return - end + if target_node == nil then return end -- play sound at the target position as well if travelnet.travelnet_sound_enabled then @@ -598,4 +591,3 @@ travelnet.can_dig = function() -- forbid digging of the travelnet return false end - diff --git a/on_receive_fields.lua b/on_receive_fields.lua index aa5cc67..6b19936 100644 --- a/on_receive_fields.lua +++ b/on_receive_fields.lua @@ -190,30 +190,27 @@ function travelnet.on_receive_fields(pos, _, fields, player) end end - player:move_to(vector.add(target_pos, player_model_vec), false) + minetest.load_area(target_pos) -- check if the box has at the other end has been removed. - local target_node = minetest.get_node_or_nil(target_pos) - if target_node ~= nil then - local target_node_def = minetest.registered_nodes[target_node.name] - local has_travelnet_group = target_node_def.groups.travelnet or target_node_def.groups.elevator + local target_node = minetest.get_node(target_pos) + local target_node_def = minetest.registered_nodes[target_node.name] + local has_travelnet_group = target_node_def.groups.travelnet or target_node_def.groups.elevator - if not has_travelnet_group then - -- provide information necessary to identify the removed box - local oldmetadata = { - fields = { - owner = owner_name, - station_name = fields.target, - station_network = station_network - } + if not has_travelnet_group then + -- provide information necessary to identify the removed box + local oldmetadata = { + fields = { + owner = owner_name, + station_name = fields.target, + station_network = station_network } + } - travelnet.remove_box(target_pos, nil, oldmetadata, player) - -- send the player back as there's no receiving travelnet - player:move_to(pos, false) - else - travelnet.rotate_player(target_pos, player, 0) - end + travelnet.remove_box(target_pos, nil, oldmetadata, player) + else + player:move_to(vector.add(target_pos, player_model_vec), false) + travelnet.rotate_player(target_pos, player) end -end +end