forked from LizzyFleckenstein03/Memeclone
Fix creation of broken Nether portals
This commit is contained in:
parent
e9b2a26cd4
commit
3857ff43ef
|
@ -130,7 +130,7 @@ minetest.register_node("mcl_portals:portal", {
|
||||||
|
|
||||||
-- Functions
|
-- Functions
|
||||||
--Build arrival portal
|
--Build arrival portal
|
||||||
local function build_portal(pos, target, is_rebuilding)
|
local function build_portal(pos, target)
|
||||||
local p = {x = pos.x - 1, y = pos.y - 1, z = pos.z}
|
local p = {x = pos.x - 1, y = pos.y - 1, z = pos.z}
|
||||||
local p1 = {x = pos.x - 1, y = pos.y - 1, z = pos.z}
|
local p1 = {x = pos.x - 1, y = pos.y - 1, z = pos.z}
|
||||||
local p2 = {x = p1.x + 3, y = p1.y + 4, z = p1.z}
|
local p2 = {x = p1.x + 3, y = p1.y + 4, z = p1.z}
|
||||||
|
@ -165,7 +165,7 @@ local function build_portal(pos, target, is_rebuilding)
|
||||||
meta:set_string("portal_target", minetest.pos_to_string(target))
|
meta:set_string("portal_target", minetest.pos_to_string(target))
|
||||||
end
|
end
|
||||||
|
|
||||||
if y ~= p1.y and not is_rebuilding then
|
if y ~= p1.y then
|
||||||
for z = -2, 2 do
|
for z = -2, 2 do
|
||||||
if z ~= 0 then
|
if z ~= 0 then
|
||||||
p.z = p.z + z
|
p.z = p.z + z
|
||||||
|
@ -281,7 +281,9 @@ local function is_portal(pos)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Light Nether portal and create target portal
|
||||||
local function make_portal(pos)
|
local function make_portal(pos)
|
||||||
|
-- Create Nether portal nodes
|
||||||
local p1, p2 = is_portal(pos)
|
local p1, p2 = is_portal(pos)
|
||||||
if not p1 or not p2 then
|
if not p1 or not p2 then
|
||||||
return false
|
return false
|
||||||
|
@ -308,6 +310,8 @@ local function make_portal(pos)
|
||||||
param2 = 1
|
param2 = 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Find target
|
||||||
|
|
||||||
local target = {x = p1.x, y = p1.y, z = p1.z}
|
local target = {x = p1.x, y = p1.y, z = p1.z}
|
||||||
target.x = target.x + 1
|
target.x = target.x + 1
|
||||||
if target.y < mcl_vars.mg_nether_max and target.y > mcl_vars.mg_nether_min then
|
if target.y < mcl_vars.mg_nether_max and target.y > mcl_vars.mg_nether_min then
|
||||||
|
@ -330,7 +334,9 @@ local function make_portal(pos)
|
||||||
else
|
else
|
||||||
p = {x = p1.x, y = y, z = p1.z + d}
|
p = {x = p1.x, y = y, z = p1.z + d}
|
||||||
end
|
end
|
||||||
|
if d ~= dmin and d ~= dmax and y ~= ymin and y ~= ymax then
|
||||||
minetest.set_node(p, {name = "mcl_portals:portal", param2 = param2})
|
minetest.set_node(p, {name = "mcl_portals:portal", param2 = param2})
|
||||||
|
end
|
||||||
local meta = minetest.get_meta(p)
|
local meta = minetest.get_meta(p)
|
||||||
|
|
||||||
-- Portal frame corners
|
-- Portal frame corners
|
||||||
|
@ -403,22 +409,17 @@ minetest.register_abm({
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Build target portal
|
-- Build target portal (if there isn't already one)
|
||||||
local function check_and_build_portal(pos, target, is_rebuilding)
|
|
||||||
-- FIXME: This is a horrible hack and a desparate attempt to make sure
|
|
||||||
-- the portal has *really* been placed. Replace this hack!
|
|
||||||
local n = minetest.get_node_or_nil(target)
|
local n = minetest.get_node_or_nil(target)
|
||||||
if n and n.name ~= "mcl_portals:portal" then
|
if n and n.name ~= "mcl_portals:portal" then
|
||||||
build_portal(target, pos, is_rebuilding)
|
local emerge_callback = function(blockpos, action, calls_remaining, param)
|
||||||
is_rebuilding = true
|
if calls_remaining <= 0 then
|
||||||
minetest.after(2, check_and_build_portal, pos, target, is_rebuilding)
|
build_portal(param.target, param.pos, false)
|
||||||
elseif not n then
|
|
||||||
is_rebuilding = true
|
|
||||||
minetest.after(1, check_and_build_portal, pos, target, is_rebuilding)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
minetest.emerge_area(vector.subtract(target, 7), vector.add(target, 7), emerge_callback, { pos = pos, target = target })
|
||||||
check_and_build_portal(pos, target, false)
|
end
|
||||||
|
|
||||||
-- Teleport
|
-- Teleport
|
||||||
obj:setpos(target)
|
obj:setpos(target)
|
||||||
|
|
Loading…
Reference in New Issue