1
0
mirror of https://github.com/HybridDog/nether-pack.git synced 2024-12-27 03:00:24 +01:00

cache used portals instead of always teleporting to 100 etc

This commit is contained in:
HybridDog 2015-12-28 20:04:38 +01:00
parent 624cf7243d
commit a0995f18f8

View File

@ -522,11 +522,22 @@ local function netherport(pos)
return true return true
end end
-- cache known portals
local known_portals_d = {}
local known_portals_u = {}
local function get_portal(t, z,x)
return t[z] and t[z][x]
end
local function set_portal(t, z,x, y)
t[z] = t[z] or {}
t[z][x] = y
end
function nether_port(player, pos) function nether_port(player, pos)
if not player if not player
or not pos or not pos
or not pos.x then or not pos.x then
print("[nether] something failed.") minetest.log("error", "[nether] nether_port: something failed.")
return return
end end
if not netherport(pos) then if not netherport(pos) then
@ -534,11 +545,13 @@ function nether_port(player, pos)
end end
minetest.sound_play("nether_teleporter", {pos=pos}) minetest.sound_play("nether_teleporter", {pos=pos})
if pos.y < nether.start then if pos.y < nether.start then
set_portal(known_portals_d, pos.z,pos.x, pos.y)
player_from_nether(player) player_from_nether(player)
pos.y = 100 pos.y = get_portal(known_portals_u, pos.z,pos.x) or 100
player:moveto(pos) player:moveto(pos)
else else
pos.y = portal_target+math.random(4) set_portal(known_portals_u, pos.z,pos.x, pos.y)
pos.y = get_portal(known_portals_d, pos.z,pos.x) or portal_target+math.random(4)
player:moveto(pos) player:moveto(pos)
player_to_nether(player, true) player_to_nether(player, true)
end end