+end
+
+
+local function generate_nether_portal_in_nether(pos)
+ if pos.y > -10033 then
+ --center the location to the lava height
+ pos.y = -15000--+math.random(-30,30)
+ nether_origin_pos = pos
+
+ local min = vector.subtract(nether_origin_pos,30)
+ local max = vector.add(nether_origin_pos,30)
+
+ --force load the area
+ minetest.emerge_area(min, max, spawn_portal_into_nether_callback)
+ else
+ --center the location to the water height
+ pos.y = 0--+math.random(-30,30)
+ nether_origin_pos = pos
+ --prefer height for mountains
+ local min = vector.subtract(nether_origin_pos,vector.new(30,30,30))
+ local max = vector.add(nether_origin_pos,vector.new(30,120,30))
+
+ --force load the area
+ minetest.emerge_area(min, max, spawn_portal_into_overworld_callback)
+ end
+end
+
+
+--modify the map with the collected data
+local function portal_modify_map(n_copy)
+ local sorted_table = {}
+ local created_portal = false
+ for x,datax in pairs(n_copy) do
+ for y,datay in pairs(datax) do
+ for z,index in pairs(datay) do
+ --try to create a return side nether portal
+ if created_portal == false then
+ created_portal = true
+ generate_nether_portal_in_nether(vector.new(x,y,z))
+ end
+ table.insert(sorted_table, vector.new(x,y,z))
+ end
+ end
+ end
+ minetest.bulk_set_node(sorted_table, {name="nether:portal"})
+end
+
+-------------------------------------------------------------------------------------------
+--the teleporter parts - stored here for now so I can read from other functions
+local teleporting_player = nil
+local function teleport_to_overworld(blockpos, action, calls_remaining, param)
+ if calls_remaining == 0 then
+ local portal_exists = minetest.find_node_near(nether_origin_pos, 30, {"nether:portal"})
+ if portal_exists then
+ --print(teleporting_player)
+ if teleporting_player then
+ teleporting_player:set_pos(vector.new(portal_exists.x,portal_exists.y-0.5,portal_exists.z))
+ end
+ end
+ teleporting_player = nil
+ end
+end
+local function teleport_to_nether(blockpos, action, calls_remaining, param)
+ if calls_remaining == 0 then
+ local portal_exists = minetest.find_node_near(nether_origin_pos, 30, {"nether:portal"})
+ if portal_exists then
+ --print(teleporting_player)
+ if teleporting_player then
+ teleporting_player:set_pos(vector.new(portal_exists.x,portal_exists.y-0.5,portal_exists.z))
+ end
+ end
+ teleporting_player = nil
+ end
+end
+
+--this initializes all teleporter commands from the client
+minetest.register_on_modchannel_message(function(channel_name, sender, message)
+ local channel_decyphered = channel_name:gsub(sender,"")
+ if channel_decyphered == ":nether_teleporters" then
+ local player = minetest.get_player_by_name(sender)
+ local pos = player:get_pos()
+
+ if pos.y > -10033 then
+ --center the location to the lava height
+ pos.y = -15000--+math.random(-30,30)
+ nether_origin_pos = pos
+
+ local min = vector.subtract(nether_origin_pos,30)
+ local max = vector.add(nether_origin_pos,30)
+
+ --force load the area
+ teleporting_player = player
+ minetest.emerge_area(min, max, teleport_to_nether)
+ else
+ --center the location to the water height
+ pos.y = 0--+math.random(-30,30)
+ nether_origin_pos = pos
+ --prefer height for mountains
+ local min = vector.subtract(nether_origin_pos,vector.new(30,30,30))
+ local max = vector.add(nether_origin_pos,vector.new(30,120,30))
+
+ --force load the area
+ teleporting_player = player
+ minetest.emerge_area(min, max, teleport_to_overworld)
+ end
+ end
+end)
+-------------------------------------------------------------------------------------------
+
+-------------------------------------------------------------------------------
+
+local destroy_n_index = {}
+local destroy_portal_failure = false
+local destroy_x_failed = false
+
+--this can be used globally to create nether portals from obsidian
+function destroy_nether_portal(pos,origin,axis)
+ --create the origin node for stored memory
+ if not origin then
+ origin = pos
+ end
+ --3d virtual memory map creation (x axis)
+ for x = -1,1 do
+ for z = -1,1 do
+ for y = -1,1 do
+ --index only direct neighbors
+ if (math.abs(x)+math.abs(z)+math.abs(y) == 1) then
+ local i = vector.add(pos,vector.new(x,y,z))
+
+ local execute_collection = true
+
+ if destroy_n_index[i.x] and destroy_n_index[i.x][i.y] then
+ if destroy_n_index[i.x][i.y][i.z] then
+ execute_collection = false
+ end
+ end
+
+ if execute_collection == true then
+ --print(minetest.get_node(i).name)
+ --index air
+ if minetest.get_node(i).name == "nether:portal" then
+ if vector.distance(i,origin) < 50 then
+ --add data to both maps
+ if not destroy_n_index[i.x] then destroy_n_index[i.x] = {} end
+ if not destroy_n_index[i.x][i.y] then destroy_n_index[i.x][i.y] = {} end
+ destroy_n_index[i.x][i.y][i.z] = {nether_portal=1} --get_group(i,"redstone_power")}
+ --the data to the 3d array must be written to memory before this is executed
+ --or a stack overflow occurs!!!
+ --pass down info for activators
+ destroy_nether_portal(i,origin,"z")
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+end
+
+--modify the map with the collected data
+local function destroy_portal_modify_map(destroy_n_copy)
+ local destroy_sorted_table = {}
+ for x,datax in pairs(destroy_n_copy) do
+ for y,datay in pairs(datax) do
+ for z,index in pairs(datay) do
+ table.insert(destroy_sorted_table, vector.new(x,y,z))
+ end
+ end
+ end
+ minetest.bulk_set_node(destroy_sorted_table, {name="air"})
+end
+
+minetest.register_globalstep(function(dtime)
+ --if indexes exist then calculate redstone
+ if n_index and next(n_index) and portal_failure == false then
+ --create the old version to help with deactivation calculation
+ local n_copy = table.copy(n_index)
+ portal_modify_map(n_copy)
+ portal_failure = false
+ end
+ if x_failed == true then
+ x_failed = false
+ end
+ if portal_failure == true then
+ portal_failure = false
+ end
+ --clear the index to avoid cpu looping wasting processing power
+ n_index = {}