From 74e68db79ca9c8c883307444722f7631d511434a Mon Sep 17 00:00:00 2001 From: Auke Kok Date: Wed, 6 Apr 2016 11:43:27 -0700 Subject: [PATCH] Attempt to emerge/mapgen areas before teleporting to them. The client will still have to actually load the mapblocks, but the server should safely teleport a player to the location, even if it wasn't even generated. --- init.lua | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/init.lua b/init.lua index 5425840..33f8964 100644 --- a/init.lua +++ b/init.lua @@ -18,24 +18,31 @@ local warps_freeze = 5 -- p = player obj -- w = warp name -local warp = function(player, dest) +local function lookup_warp(name) for i = 1,table.getn(warps) do - if warps[i].name == dest then - player:setpos({x = warps[i].x, y = warps[i].y, z = warps[i].z}) - -- MT Core FIXME - -- get functions don't output proper values for set! - -- https://github.com/minetest/minetest/issues/2658 - player:set_look_yaw(warps[i].yaw - (math.pi/2)) - player:set_look_pitch(0 - warps[i].pitch) - minetest.chat_send_player(player:get_player_name(), "Warped to \"" .. dest .. "\"") - minetest.log("action", player:get_player_name() .. " warped to \"" .. dest .. "\"") - minetest.sound_play("warps_plop", { - pos = {x = warps[i].x, y = warps[i].y, z = warps[i].z}, - }) - return + if warps[i].name == name then + return warps[i] end end - minetest.chat_send_player(player:get_player_name(), "Unknown warp \"" .. dest .. "\"") +end + +local warp = function(player, dest) + local warp = lookup_warp(dest) + if not warp then + minetest.chat_send_player(player:get_player_name(), "Unknown warp \"" .. dest .. "\"") + return + end + + local pos = {x = warp.x, y = warp.y, z = warp.z} + player:setpos(pos) + -- MT Core FIXME + -- get functions don't output proper values for set! + -- https://github.com/minetest/minetest/issues/2658 + player:set_look_yaw(warp.yaw - (math.pi/2)) + player:set_look_pitch(0 - warp.pitch) + minetest.chat_send_player(player:get_player_name(), "Warped to \"" .. dest .. "\"") + minetest.log("action", player:get_player_name() .. " warped to \"" .. dest .. "\"") + minetest.sound_play("warps_plop", {pos = pos}) end do_warp_queue = function() @@ -79,6 +86,13 @@ local warp_queue_add = function(player, dest) queue_state = 1 minetest.after(1, do_warp_queue) end + -- attempt to emerge the target area before the player gets there + local warp = lookup_warp(dest) + local pos = {x = warp.x, y = warp.y, z = warp.z} + minetest.get_voxel_manip():read_from_map(pos, pos) + if not minetest.get_node_or_nil(pos) then + minetest.emerge_area(vector.subtract(pos, 80), vector.add(pos, 80)) + end end local worldpath = minetest.get_worldpath()