Fixed rare bug that causes minetest to crash

master
Joel Leclerc 2012-04-18 16:59:12 -06:00
parent d8e3a0864c
commit 3f14a0061c
2 changed files with 47 additions and 41 deletions

View File

@ -589,13 +589,13 @@ end
-- Read portals to nether -- Read portals to nether
function nether:read_portals_to_nether() function nether:read_portals_to_nether()
local array = {} local array = {}
NETHER_PORTALS_TO_NETHER = {} local array2 = {}
local file = io.open(NETHER_PORTALS_TO_NETHER_FILE, "r") local file = io.open(NETHER_PORTALS_TO_NETHER_FILE, "r")
if file ~= nil then if file ~= nil then
for line in io.lines(NETHER_PORTALS_TO_NETHER_FILE) do for line in io.lines(NETHER_PORTALS_TO_NETHER_FILE) do
if not (line == "" or line == nil) then if not (line == "" or line == nil) then
if line:sub(1, 1) == "p" then if line:sub(1, 1) == "p" then
NETHER_PORTALS_TO_NETHER[table.getn(NETHER_PORTALS_TO_NETHER)+1] = array array2[table.getn(array2)+1] = array
elseif line:sub(1, 1) == "x" then elseif line:sub(1, 1) == "x" then
array.x = tonumber(split(line, "x")[1]) array.x = tonumber(split(line, "x")[1])
elseif line:sub(1, 1) == "y" then elseif line:sub(1, 1) == "y" then
@ -612,19 +612,19 @@ function nether:read_portals_to_nether()
file:close() file:close()
end end
end end
table_unique(NETHER_PORTALS_TO_NETHER) NETHER_PORTALS_TO_NETHER = table_unique(array2)
end end
-- Read portals from nether -- Read portals from nether
function nether:read_portals_from_nether() function nether:read_portals_from_nether()
local array = {} local array = {}
NETHER_PORTALS_FROM_NETHER = {} local array2 = {}
local file = io.open(NETHER_PORTALS_FROM_NETHER_FILE, "r") local file = io.open(NETHER_PORTALS_FROM_NETHER_FILE, "r")
if file ~= nil then if file ~= nil then
for line in io.lines(NETHER_PORTALS_FROM_NETHER_FILE) do for line in io.lines(NETHER_PORTALS_FROM_NETHER_FILE) do
if not (line == "" or line == nil) then if not (line == "" or line == nil) then
if line:sub(1, 1) == "p" then if line:sub(1, 1) == "p" then
NETHER_PORTALS_FROM_NETHER[table.getn(NETHER_PORTALS_FROM_NETHER)+1] = array array2[table.getn(array2)+1] = array
elseif line:sub(1, 1) == "x" then elseif line:sub(1, 1) == "x" then
array.x = tonumber(split(line, "x")[1]) array.x = tonumber(split(line, "x")[1])
elseif line:sub(1, 1) == "y" then elseif line:sub(1, 1) == "y" then
@ -641,7 +641,7 @@ function nether:read_portals_from_nether()
file:close() file:close()
end end
end end
table_unique(NETHER_PORTALS_FROM_NETHER) NETHER_PORTALS_FROM_NETHER = table_unique(array2)
end end
nether:read_portals_to_nether() nether:read_portals_to_nether()
@ -702,20 +702,24 @@ minetest.register_abm({
interval = 1.0, interval = 1.0,
chance = 1, chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider) action = function(pos, node, active_object_count, active_object_count_wider)
for i,v in ipairs(NETHER_PORTAL) do local nodemeta = minetest.env:get_meta(pos)
v.pos.x = v.pos.x + pos.x if nodemeta:get_string("generatingportal") == "" or nodemeta:get_string("generatingportal") == nil then
v.pos.y = v.pos.y + pos.y nodemeta:set_string("generatingportal", "true")
v.pos.z = v.pos.z + pos.z for i,v in ipairs(NETHER_PORTAL) do
minetest.env:add_node(v.pos, {name=v.block}) v.pos.x = v.pos.x + pos.x
end v.pos.y = v.pos.y + pos.y
if nether:inside_nether(pos) then v.pos.z = v.pos.z + pos.z
NETHER_PORTALS_FROM_NETHER[table.getn(NETHER_PORTALS_FROM_NETHER)+1] = pos minetest.env:add_node(v.pos, {name=v.block})
nether:save_portals_from_nether() end
nether:read_portals_from_nether() if nether:inside_nether(pos) then
else NETHER_PORTALS_FROM_NETHER[table.getn(NETHER_PORTALS_FROM_NETHER)+1] = pos
NETHER_PORTALS_TO_NETHER[table.getn(NETHER_PORTALS_TO_NETHER)+1] = pos nether:save_portals_from_nether()
nether:save_portals_to_nether() nether:read_portals_from_nether()
nether:read_portals_from_nether() else
NETHER_PORTALS_TO_NETHER[table.getn(NETHER_PORTALS_TO_NETHER)+1] = pos
nether:save_portals_to_nether()
nether:read_portals_from_nether()
end
end end
end end
}) })

View File

@ -277,7 +277,6 @@ for i,v in ipairs(HADES_THRONE_ABS) do
end end
end end
HADES_THRONE_ENDPOS_ABS = {x=htx, y=hty, z=htz} HADES_THRONE_ENDPOS_ABS = {x=htx, y=hty, z=htz}
print("HTY:" .. hty)
local nether = {} local nether = {}
-- Check if file exists -- Check if file exists
@ -590,13 +589,13 @@ end
-- Read portals to nether -- Read portals to nether
function nether:read_portals_to_nether() function nether:read_portals_to_nether()
local array = {} local array = {}
NETHER_PORTALS_TO_NETHER = {} local array2 = {}
local file = io.open(NETHER_PORTALS_TO_NETHER_FILE, "r") local file = io.open(NETHER_PORTALS_TO_NETHER_FILE, "r")
if file ~= nil then if file ~= nil then
for line in io.lines(NETHER_PORTALS_TO_NETHER_FILE) do for line in io.lines(NETHER_PORTALS_TO_NETHER_FILE) do
if not (line == "" or line == nil) then if not (line == "" or line == nil) then
if line:sub(1, 1) == "p" then if line:sub(1, 1) == "p" then
NETHER_PORTALS_TO_NETHER[table.getn(NETHER_PORTALS_TO_NETHER)+1] = array array2[table.getn(array2)+1] = array
elseif line:sub(1, 1) == "x" then elseif line:sub(1, 1) == "x" then
array.x = tonumber(split(line, "x")[1]) array.x = tonumber(split(line, "x")[1])
elseif line:sub(1, 1) == "y" then elseif line:sub(1, 1) == "y" then
@ -613,19 +612,19 @@ function nether:read_portals_to_nether()
file:close() file:close()
end end
end end
table_unique(NETHER_PORTALS_TO_NETHER) NETHER_PORTALS_TO_NETHER = table_unique(array2)
end end
-- Read portals from nether -- Read portals from nether
function nether:read_portals_from_nether() function nether:read_portals_from_nether()
local array = {} local array = {}
NETHER_PORTALS_FROM_NETHER = {} local array2 = {}
local file = io.open(NETHER_PORTALS_FROM_NETHER_FILE, "r") local file = io.open(NETHER_PORTALS_FROM_NETHER_FILE, "r")
if file ~= nil then if file ~= nil then
for line in io.lines(NETHER_PORTALS_FROM_NETHER_FILE) do for line in io.lines(NETHER_PORTALS_FROM_NETHER_FILE) do
if not (line == "" or line == nil) then if not (line == "" or line == nil) then
if line:sub(1, 1) == "p" then if line:sub(1, 1) == "p" then
NETHER_PORTALS_FROM_NETHER[table.getn(NETHER_PORTALS_FROM_NETHER)+1] = array array2[table.getn(array2)+1] = array
elseif line:sub(1, 1) == "x" then elseif line:sub(1, 1) == "x" then
array.x = tonumber(split(line, "x")[1]) array.x = tonumber(split(line, "x")[1])
elseif line:sub(1, 1) == "y" then elseif line:sub(1, 1) == "y" then
@ -642,7 +641,7 @@ function nether:read_portals_from_nether()
file:close() file:close()
end end
end end
table_unique(NETHER_PORTALS_FROM_NETHER) NETHER_PORTALS_FROM_NETHER = table_unique(array2)
end end
nether:read_portals_to_nether() nether:read_portals_to_nether()
@ -703,20 +702,23 @@ minetest.register_abm({
interval = 1.0, interval = 1.0,
chance = 1, chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider) action = function(pos, node, active_object_count, active_object_count_wider)
for i,v in ipairs(NETHER_PORTAL) do local nodemeta = minetest.env:get_meta(pos)
v.pos.x = v.pos.x + pos.x if nodemeta:get_string("generatingportal") == "" or nodemeta:get_string("generatingportal") == nil then
v.pos.y = v.pos.y + pos.y for i,v in ipairs(NETHER_PORTAL) do
v.pos.z = v.pos.z + pos.z v.pos.x = v.pos.x + pos.x
minetest.env:add_node(v.pos, {name=v.block}) v.pos.y = v.pos.y + pos.y
end v.pos.z = v.pos.z + pos.z
if nether:inside_nether(pos) then minetest.env:add_node(v.pos, {name=v.block})
NETHER_PORTALS_FROM_NETHER[table.getn(NETHER_PORTALS_FROM_NETHER)+1] = pos end
nether:save_portals_from_nether() if nether:inside_nether(pos) then
nether:read_portals_from_nether() NETHER_PORTALS_FROM_NETHER[table.getn(NETHER_PORTALS_FROM_NETHER)+1] = pos
else nether:save_portals_from_nether()
NETHER_PORTALS_TO_NETHER[table.getn(NETHER_PORTALS_TO_NETHER)+1] = pos nether:read_portals_from_nether()
nether:save_portals_to_nether() else
nether:read_portals_from_nether() NETHER_PORTALS_TO_NETHER[table.getn(NETHER_PORTALS_TO_NETHER)+1] = pos
nether:save_portals_to_nether()
nether:read_portals_from_nether()
end
end end
end end
}) })