forked from mtcontrib/nether-pack
Fixed duplicate portals issue
This commit is contained in:
parent
3f14a0061c
commit
414cc39999
|
@ -279,6 +279,8 @@ end
|
||||||
HADES_THRONE_ENDPOS_ABS = {x=htx, y=hty, z=htz}
|
HADES_THRONE_ENDPOS_ABS = {x=htx, y=hty, z=htz}
|
||||||
local nether = {}
|
local nether = {}
|
||||||
|
|
||||||
|
-- == General Utility Functions ==
|
||||||
|
|
||||||
-- Check if file exists
|
-- Check if file exists
|
||||||
function nether:fileexists(file)
|
function nether:fileexists(file)
|
||||||
file = io.open(file, "r")
|
file = io.open(file, "r")
|
||||||
|
@ -301,6 +303,18 @@ function nether:touch(file)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Print a message
|
||||||
|
function nether:printm(message)
|
||||||
|
print("[Nether] " .. message)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Print an error message
|
||||||
|
function nether:printerror(message)
|
||||||
|
nether:printm("Error! " .. message)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- == Nether related stuff ==
|
||||||
|
|
||||||
-- Find if a position is inside the Nether
|
-- Find if a position is inside the Nether
|
||||||
function nether:inside_nether(pos)
|
function nether:inside_nether(pos)
|
||||||
if pos.y >= NETHER_BOTTOM and pos.y <= NETHER_DEPTH then
|
if pos.y >= NETHER_BOTTOM and pos.y <= NETHER_DEPTH then
|
||||||
|
@ -505,18 +519,20 @@ NETHER_PORTALS_FROM_NETHER = {}
|
||||||
NETHER_PORTALS_TO_NETHER_FILE = minetest.get_worldpath() .. "/portalstonether.txt"
|
NETHER_PORTALS_TO_NETHER_FILE = minetest.get_worldpath() .. "/portalstonether.txt"
|
||||||
NETHER_PORTALS_FROM_NETHER_FILE = minetest.get_worldpath() .. "/portalsfromnether.txt"
|
NETHER_PORTALS_FROM_NETHER_FILE = minetest.get_worldpath() .. "/portalsfromnether.txt"
|
||||||
|
|
||||||
-- Count the number of times something appears in a table
|
-- Count the number of times a position appears in a table
|
||||||
function table_count(tt, item)
|
function table_count(tt, item)
|
||||||
local count
|
local count
|
||||||
count = 0
|
count = 0
|
||||||
for ii,xx in pairs(tt) do
|
for ii,xx in pairs(tt) do
|
||||||
if item == xx then count = count + 1 end
|
if (item.x == xx.x) and (item.y == xx.y) and (item.z == xx.z) then
|
||||||
|
count = count + 1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
return count
|
return count
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- Remove duplicates from table
|
-- Remove duplicate positions from table
|
||||||
function table_unique(tt)
|
function table_unique(tt)
|
||||||
local newtable
|
local newtable
|
||||||
newtable = {}
|
newtable = {}
|
||||||
|
@ -553,15 +569,22 @@ function nether:save_portal_to_nether(pos)
|
||||||
local file = io.open(NETHER_PORTALS_TO_NETHER_FILE, "a")
|
local file = io.open(NETHER_PORTALS_TO_NETHER_FILE, "a")
|
||||||
if file ~= nil then
|
if file ~= nil then
|
||||||
file:write("x" .. pos.x .. "\ny" .. pos.y .. "\nz" .. pos.z .. "\np", "\n")
|
file:write("x" .. pos.x .. "\ny" .. pos.y .. "\nz" .. pos.z .. "\np", "\n")
|
||||||
|
file:close()
|
||||||
|
else
|
||||||
|
nether:printerror("Cannot write portal to file!")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Save all nether portals
|
-- Save all nether portals
|
||||||
function nether:save_portals_to_nether()
|
function nether:save_portals_to_nether()
|
||||||
|
local array2 = NETHER_PORTALS_TO_NETHER
|
||||||
|
NETHER_PORTALS_TO_NETHER = table_unique(array2)
|
||||||
file = io.open(NETHER_PORTALS_TO_NETHER_FILE, "w")
|
file = io.open(NETHER_PORTALS_TO_NETHER_FILE, "w")
|
||||||
if file ~= nil then
|
if file ~= nil then
|
||||||
file:write("")
|
file:write("")
|
||||||
file:close()
|
file:close()
|
||||||
|
else
|
||||||
|
nether:printerror("Cannot create portal file!")
|
||||||
end
|
end
|
||||||
for i,v in ipairs(NETHER_PORTALS_TO_NETHER) do
|
for i,v in ipairs(NETHER_PORTALS_TO_NETHER) do
|
||||||
nether:save_portal_to_nether(v)
|
nether:save_portal_to_nether(v)
|
||||||
|
@ -573,14 +596,23 @@ function nether:save_portal_from_nether(pos)
|
||||||
local file = io.open(NETHER_PORTALS_FROM_NETHER_FILE, "a")
|
local file = io.open(NETHER_PORTALS_FROM_NETHER_FILE, "a")
|
||||||
if file ~= nil then
|
if file ~= nil then
|
||||||
file:write("x" .. pos.x .. "\ny" .. pos.y .. "\nz" .. pos.z .. "\np", "\n")
|
file:write("x" .. pos.x .. "\ny" .. pos.y .. "\nz" .. pos.z .. "\np", "\n")
|
||||||
|
file:close()
|
||||||
|
else
|
||||||
|
nether:printerror("Cannot write portal to file!")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Save all portals from nether
|
-- Save all portals from nether
|
||||||
function nether:save_portals_from_nether()
|
function nether:save_portals_from_nether()
|
||||||
|
local array2 = NETHER_PORTALS_FROM_NETHER
|
||||||
|
NETHER_PORTALS_FROM_NETHER = table_unique(array2)
|
||||||
file = io.open(NETHER_PORTALS_FROM_NETHER_FILE, "w")
|
file = io.open(NETHER_PORTALS_FROM_NETHER_FILE, "w")
|
||||||
|
if file ~= nil then
|
||||||
file:write("")
|
file:write("")
|
||||||
file:close()
|
file:close()
|
||||||
|
else
|
||||||
|
nether:printerror("Cannot create portal file!")
|
||||||
|
end
|
||||||
for i,v in ipairs(NETHER_PORTALS_FROM_NETHER) do
|
for i,v in ipairs(NETHER_PORTALS_FROM_NETHER) do
|
||||||
nether:save_portal_from_nether(v)
|
nether:save_portal_from_nether(v)
|
||||||
end
|
end
|
||||||
|
@ -610,6 +642,8 @@ function nether:read_portals_to_nether()
|
||||||
if file ~= nil then
|
if file ~= nil then
|
||||||
file:write("")
|
file:write("")
|
||||||
file:close()
|
file:close()
|
||||||
|
else
|
||||||
|
nether:printerror("Cannot create portal file!")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
NETHER_PORTALS_TO_NETHER = table_unique(array2)
|
NETHER_PORTALS_TO_NETHER = table_unique(array2)
|
||||||
|
@ -639,6 +673,8 @@ function nether:read_portals_from_nether()
|
||||||
if file ~= nil then
|
if file ~= nil then
|
||||||
file:write("")
|
file:write("")
|
||||||
file:close()
|
file:close()
|
||||||
|
else
|
||||||
|
nether:printerror("Cannot create portal file!")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
NETHER_PORTALS_FROM_NETHER = table_unique(array2)
|
NETHER_PORTALS_FROM_NETHER = table_unique(array2)
|
||||||
|
|
|
@ -279,6 +279,8 @@ end
|
||||||
HADES_THRONE_ENDPOS_ABS = {x=htx, y=hty, z=htz}
|
HADES_THRONE_ENDPOS_ABS = {x=htx, y=hty, z=htz}
|
||||||
local nether = {}
|
local nether = {}
|
||||||
|
|
||||||
|
-- == General Utility Functions ==
|
||||||
|
|
||||||
-- Check if file exists
|
-- Check if file exists
|
||||||
function nether:fileexists(file)
|
function nether:fileexists(file)
|
||||||
file = io.open(file, "r")
|
file = io.open(file, "r")
|
||||||
|
@ -301,6 +303,18 @@ function nether:touch(file)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Print a message
|
||||||
|
function nether:printm(message)
|
||||||
|
print("[Nether] " .. message)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Print an error message
|
||||||
|
function nether:printerror(message)
|
||||||
|
nether:printm("Error! " .. message)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- == Nether related stuff ==
|
||||||
|
|
||||||
-- Find if a position is inside the Nether
|
-- Find if a position is inside the Nether
|
||||||
function nether:inside_nether(pos)
|
function nether:inside_nether(pos)
|
||||||
if pos.y >= NETHER_BOTTOM and pos.y <= NETHER_DEPTH then
|
if pos.y >= NETHER_BOTTOM and pos.y <= NETHER_DEPTH then
|
||||||
|
@ -505,12 +519,14 @@ NETHER_PORTALS_FROM_NETHER = {}
|
||||||
NETHER_PORTALS_TO_NETHER_FILE = minetest.get_worldpath() .. "/portalstonether.txt"
|
NETHER_PORTALS_TO_NETHER_FILE = minetest.get_worldpath() .. "/portalstonether.txt"
|
||||||
NETHER_PORTALS_FROM_NETHER_FILE = minetest.get_worldpath() .. "/portalsfromnether.txt"
|
NETHER_PORTALS_FROM_NETHER_FILE = minetest.get_worldpath() .. "/portalsfromnether.txt"
|
||||||
|
|
||||||
-- Count the number of times something appears in a table
|
-- Count the number of times a position appears in a table
|
||||||
function table_count(tt, item)
|
function table_count(tt, item)
|
||||||
local count
|
local count
|
||||||
count = 0
|
count = 0
|
||||||
for ii,xx in pairs(tt) do
|
for ii,xx in pairs(tt) do
|
||||||
if item == xx then count = count + 1 end
|
if (item.x == xx.x) and (item.y == xx.y) and (item.z == xx.z) then
|
||||||
|
count = count + 1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
return count
|
return count
|
||||||
end
|
end
|
||||||
|
@ -553,15 +569,22 @@ function nether:save_portal_to_nether(pos)
|
||||||
local file = io.open(NETHER_PORTALS_TO_NETHER_FILE, "a")
|
local file = io.open(NETHER_PORTALS_TO_NETHER_FILE, "a")
|
||||||
if file ~= nil then
|
if file ~= nil then
|
||||||
file:write("x" .. pos.x .. "\ny" .. pos.y .. "\nz" .. pos.z .. "\np", "\n")
|
file:write("x" .. pos.x .. "\ny" .. pos.y .. "\nz" .. pos.z .. "\np", "\n")
|
||||||
|
file:close()
|
||||||
|
else
|
||||||
|
nether:printerror("Cannot write portal to file!")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Save all nether portals
|
-- Save all nether portals
|
||||||
function nether:save_portals_to_nether()
|
function nether:save_portals_to_nether()
|
||||||
|
local array2 = NETHER_PORTALS_TO_NETHER
|
||||||
|
NETHER_PORTALS_TO_NETHER = table_unique(array2)
|
||||||
file = io.open(NETHER_PORTALS_TO_NETHER_FILE, "w")
|
file = io.open(NETHER_PORTALS_TO_NETHER_FILE, "w")
|
||||||
if file ~= nil then
|
if file ~= nil then
|
||||||
file:write("")
|
file:write("")
|
||||||
file:close()
|
file:close()
|
||||||
|
else
|
||||||
|
nether:printerror("Cannot create portal file!")
|
||||||
end
|
end
|
||||||
for i,v in ipairs(NETHER_PORTALS_TO_NETHER) do
|
for i,v in ipairs(NETHER_PORTALS_TO_NETHER) do
|
||||||
nether:save_portal_to_nether(v)
|
nether:save_portal_to_nether(v)
|
||||||
|
@ -573,14 +596,23 @@ function nether:save_portal_from_nether(pos)
|
||||||
local file = io.open(NETHER_PORTALS_FROM_NETHER_FILE, "a")
|
local file = io.open(NETHER_PORTALS_FROM_NETHER_FILE, "a")
|
||||||
if file ~= nil then
|
if file ~= nil then
|
||||||
file:write("x" .. pos.x .. "\ny" .. pos.y .. "\nz" .. pos.z .. "\np", "\n")
|
file:write("x" .. pos.x .. "\ny" .. pos.y .. "\nz" .. pos.z .. "\np", "\n")
|
||||||
|
file:close()
|
||||||
|
else
|
||||||
|
nether:printerror("Cannot write portal to file!")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Save all portals from nether
|
-- Save all portals from nether
|
||||||
function nether:save_portals_from_nether()
|
function nether:save_portals_from_nether()
|
||||||
|
local array2 = NETHER_PORTALS_FROM_NETHER
|
||||||
|
NETHER_PORTALS_FROM_NETHER = table_unique(array2)
|
||||||
file = io.open(NETHER_PORTALS_FROM_NETHER_FILE, "w")
|
file = io.open(NETHER_PORTALS_FROM_NETHER_FILE, "w")
|
||||||
|
if file ~= nil then
|
||||||
file:write("")
|
file:write("")
|
||||||
file:close()
|
file:close()
|
||||||
|
else
|
||||||
|
nether:printerror("Cannot create portal file!")
|
||||||
|
end
|
||||||
for i,v in ipairs(NETHER_PORTALS_FROM_NETHER) do
|
for i,v in ipairs(NETHER_PORTALS_FROM_NETHER) do
|
||||||
nether:save_portal_from_nether(v)
|
nether:save_portal_from_nether(v)
|
||||||
end
|
end
|
||||||
|
@ -610,6 +642,8 @@ function nether:read_portals_to_nether()
|
||||||
if file ~= nil then
|
if file ~= nil then
|
||||||
file:write("")
|
file:write("")
|
||||||
file:close()
|
file:close()
|
||||||
|
else
|
||||||
|
nether:printerror("Cannot create portal file!")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
NETHER_PORTALS_TO_NETHER = table_unique(array2)
|
NETHER_PORTALS_TO_NETHER = table_unique(array2)
|
||||||
|
@ -639,6 +673,8 @@ function nether:read_portals_from_nether()
|
||||||
if file ~= nil then
|
if file ~= nil then
|
||||||
file:write("")
|
file:write("")
|
||||||
file:close()
|
file:close()
|
||||||
|
else
|
||||||
|
nether:printerror("Cannot create portal file!")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
NETHER_PORTALS_FROM_NETHER = table_unique(array2)
|
NETHER_PORTALS_FROM_NETHER = table_unique(array2)
|
||||||
|
@ -704,6 +740,7 @@ minetest.register_abm({
|
||||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||||
local nodemeta = minetest.env:get_meta(pos)
|
local nodemeta = minetest.env:get_meta(pos)
|
||||||
if nodemeta:get_string("generatingportal") == "" or nodemeta:get_string("generatingportal") == nil then
|
if nodemeta:get_string("generatingportal") == "" or nodemeta:get_string("generatingportal") == nil then
|
||||||
|
nodemeta:set_string("generatingportal", "true")
|
||||||
for i,v in ipairs(NETHER_PORTAL) do
|
for i,v in ipairs(NETHER_PORTAL) do
|
||||||
v.pos.x = v.pos.x + pos.x
|
v.pos.x = v.pos.x + pos.x
|
||||||
v.pos.y = v.pos.y + pos.y
|
v.pos.y = v.pos.y + pos.y
|
||||||
|
|
Loading…
Reference in New Issue
Block a user