forked from minetest-mods/nether
Trim trailing spaces
This eliminates most luacheck formatting warnings
This commit is contained in:
parent
d0ce9dd633
commit
58da96549a
8
init.lua
8
init.lua
@ -24,13 +24,13 @@ if minetest.get_translator ~= nil then
|
|||||||
S = minetest.get_translator("nether")
|
S = minetest.get_translator("nether")
|
||||||
else
|
else
|
||||||
-- mock the translator function for MT 0.4
|
-- mock the translator function for MT 0.4
|
||||||
S = function(str, ...)
|
S = function(str, ...)
|
||||||
local args={...}
|
local args={...}
|
||||||
return str:gsub(
|
return str:gsub(
|
||||||
"@%d+",
|
"@%d+",
|
||||||
function(match) return args[tonumber(match:sub(2))] end
|
function(match) return args[tonumber(match:sub(2))] end
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Global Nether namespace
|
-- Global Nether namespace
|
||||||
@ -131,7 +131,7 @@ if nether.NETHER_REALM_ENABLED then
|
|||||||
local existing_portal_location, existing_portal_orientation = nether.find_nearest_working_portal("nether_portal", destination_pos, 8 * nether.FASTTRAVEL_FACTOR, 0)
|
local existing_portal_location, existing_portal_orientation = nether.find_nearest_working_portal("nether_portal", destination_pos, 8 * nether.FASTTRAVEL_FACTOR, 0)
|
||||||
if existing_portal_location ~= nil then
|
if existing_portal_location ~= nil then
|
||||||
return existing_portal_location, existing_portal_orientation
|
return existing_portal_location, existing_portal_orientation
|
||||||
else
|
else
|
||||||
destination_pos.y = nether.find_surface_target_y(destination_pos.x, destination_pos.z, "nether_portal")
|
destination_pos.y = nether.find_surface_target_y(destination_pos.x, destination_pos.z, "nether_portal")
|
||||||
return destination_pos
|
return destination_pos
|
||||||
end
|
end
|
||||||
@ -166,6 +166,6 @@ if nether.NETHER_REALM_ENABLED then
|
|||||||
})
|
})
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
})
|
})
|
||||||
end
|
end
|
@ -27,7 +27,7 @@ nether.register_wormhole_node("nether:portal", {
|
|||||||
description = S("Nether Portal"),
|
description = S("Nether Portal"),
|
||||||
post_effect_color = {
|
post_effect_color = {
|
||||||
-- post_effect_color can't be changed dynamically in Minetest like the portal colour is.
|
-- post_effect_color can't be changed dynamically in Minetest like the portal colour is.
|
||||||
-- If you need a different post_effect_color then use register_wormhole_node to create
|
-- If you need a different post_effect_color then use register_wormhole_node to create
|
||||||
-- another wormhole node and set it as the wormhole_node_name in your portaldef.
|
-- another wormhole node and set it as the wormhole_node_name in your portaldef.
|
||||||
-- Hopefully this colour is close enough to magenta to work with the traditional magenta
|
-- Hopefully this colour is close enough to magenta to work with the traditional magenta
|
||||||
-- portals, close enough to red to work for a red portal, and also close enough to red to
|
-- portals, close enough to red to work for a red portal, and also close enough to red to
|
||||||
|
134
portal_api.lua
134
portal_api.lua
@ -42,8 +42,8 @@ nether.portals_palette = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if minetest.get_mod_storage == nil then
|
if minetest.get_mod_storage == nil then
|
||||||
error(nether.modname .. " does not support Minetest versions earlier than 0.4.16", 0)
|
error(nether.modname .. " does not support Minetest versions earlier than 0.4.16", 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
@ -57,20 +57,20 @@ p1 & p2 p1 and p2 is the system used by earlier versions of the nether mod
|
|||||||
they define the bounding volume for the portal.
|
they define the bounding volume for the portal.
|
||||||
The value of p1 and p2 is kept in the metadata of every node in the portal
|
The value of p1 and p2 is kept in the metadata of every node in the portal
|
||||||
|
|
||||||
WormholePos The location of the node that a portal's target is set to, and a player is teleported
|
WormholePos The location of the node that a portal's target is set to, and a player is teleported
|
||||||
to. It can also be used to test whether a portal is active.
|
to. It can also be used to test whether a portal is active.
|
||||||
|
|
||||||
AnchorPos Introduced by the portal_api. Coordinates for portals are normally given in terms of
|
AnchorPos Introduced by the portal_api. Coordinates for portals are normally given in terms of
|
||||||
the AnchorPos. The AnchorPos does not change with portal orientation - portals rotate
|
the AnchorPos. The AnchorPos does not change with portal orientation - portals rotate
|
||||||
around the AnchorPos. Ideally an AnchorPos would be near the bottom center of a portal
|
around the AnchorPos. Ideally an AnchorPos would be near the bottom center of a portal
|
||||||
shape, but this is not the case with PortalShape_Traditional to keep comptaibility with
|
shape, but this is not the case with PortalShape_Traditional to keep comptaibility with
|
||||||
earlier versions of the nether mod.
|
earlier versions of the nether mod.
|
||||||
Usually an orientation is required with an AnchorPos.
|
Usually an orientation is required with an AnchorPos.
|
||||||
|
|
||||||
Orientation is yaw, either 0 or 90, 0 meaning a portal that faces north/south - i.e. obsidian
|
Orientation is yaw, either 0 or 90, 0 meaning a portal that faces north/south - i.e. obsidian
|
||||||
running east/west.
|
running east/west.
|
||||||
|
|
||||||
TimerPos The portal_api replaces ABMs with a single node timer per portal, and the TimerPos is the
|
TimerPos The portal_api replaces ABMs with a single node timer per portal, and the TimerPos is the
|
||||||
node in which that timer is located. Extra metadata is also kept in the TimerPos node.
|
node in which that timer is located. Extra metadata is also kept in the TimerPos node.
|
||||||
|
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ Portal shapes
|
|||||||
=============
|
=============
|
||||||
|
|
||||||
|
|
||||||
For the PortalShape_Traditional implementation, p1, p2, anchorPos, wormholdPos and TimerPos are defined
|
For the PortalShape_Traditional implementation, p1, p2, anchorPos, wormholdPos and TimerPos are defined
|
||||||
as follows:
|
as follows:
|
||||||
.
|
.
|
||||||
+--------+--------+--------+--------+
|
+--------+--------+--------+--------+
|
||||||
@ -351,9 +351,9 @@ nether.PortalShape_Circular = {
|
|||||||
local zRange = 0
|
local zRange = 0
|
||||||
if orientation ~= 0 then
|
if orientation ~= 0 then
|
||||||
xRange = 0
|
xRange = 0
|
||||||
zRange = 2
|
zRange = 2
|
||||||
end
|
end
|
||||||
|
|
||||||
local xEdge, yEdge, zEdge
|
local xEdge, yEdge, zEdge
|
||||||
local pos = {}
|
local pos = {}
|
||||||
for x = -xRange, xRange do
|
for x = -xRange, xRange do
|
||||||
@ -363,7 +363,7 @@ nether.PortalShape_Circular = {
|
|||||||
zEdge = z == -zRange or z == zRange
|
zEdge = z == -zRange or z == zRange
|
||||||
pos.z = anchorPos.z + z
|
pos.z = anchorPos.z + z
|
||||||
for y = 1, 5 do
|
for y = 1, 5 do
|
||||||
yEdge = y == 1 or y == 5
|
yEdge = y == 1 or y == 5
|
||||||
if not (yEdge and xEdge and zEdge) then
|
if not (yEdge and xEdge and zEdge) then
|
||||||
pos.y = anchorPos.y + y
|
pos.y = anchorPos.y + y
|
||||||
if func(pos) then
|
if func(pos) then
|
||||||
@ -542,7 +542,7 @@ local function get_colorfacedir_from_color_and_orientation(color, orientation, p
|
|||||||
axis_direction = 0 -- 0 is up, or +Y
|
axis_direction = 0 -- 0 is up, or +Y
|
||||||
rotation = dir
|
rotation = dir
|
||||||
end
|
end
|
||||||
|
|
||||||
-- wormhole nodes have a paramtype2 of colorfacedir, which means the
|
-- wormhole nodes have a paramtype2 of colorfacedir, which means the
|
||||||
-- high 3 bits are palette, followed by 3 direction bits and 2 rotation bits.
|
-- high 3 bits are palette, followed by 3 direction bits and 2 rotation bits.
|
||||||
-- We set the palette bits and rotation
|
-- We set the palette bits and rotation
|
||||||
@ -576,8 +576,8 @@ local function get_orientation_from_colorfacedir(param2)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- We want wormhole nodes to only emit mesecon energy orthogonally to the
|
-- We want wormhole nodes to only emit mesecon energy orthogonally to the
|
||||||
-- wormhole surface so that the wormhole will not send power to the frame,
|
-- wormhole surface so that the wormhole will not send power to the frame,
|
||||||
-- this allows the portal frame to listen for mesecon energy from external switches/wires etc.
|
-- this allows the portal frame to listen for mesecon energy from external switches/wires etc.
|
||||||
function get_mesecon_emission_rules_from_colorfacedir(param2)
|
function get_mesecon_emission_rules_from_colorfacedir(param2)
|
||||||
|
|
||||||
@ -647,9 +647,9 @@ end
|
|||||||
-- Add portal information to mod storage, so new portals may find existing portals near the target location.
|
-- Add portal information to mod storage, so new portals may find existing portals near the target location.
|
||||||
-- Do this whenever a portal is created or changes its ignition state
|
-- Do this whenever a portal is created or changes its ignition state
|
||||||
local function store_portal_location_info(portal_name, anchorPos, orientation, ignited)
|
local function store_portal_location_info(portal_name, anchorPos, orientation, ignited)
|
||||||
if not DEBUG_IGNORE_MODSTORAGE then
|
if not DEBUG_IGNORE_MODSTORAGE then
|
||||||
mod_storage:set_string(
|
mod_storage:set_string(
|
||||||
minetest.pos_to_string(anchorPos) .. " is " .. portal_name,
|
minetest.pos_to_string(anchorPos) .. " is " .. portal_name,
|
||||||
minetest.serialize({orientation = orientation, active = ignited})
|
minetest.serialize({orientation = orientation, active = ignited})
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
@ -658,7 +658,7 @@ end
|
|||||||
-- Remove portal information from mod storage.
|
-- Remove portal information from mod storage.
|
||||||
-- Do this if a portal frame is destroyed such that it cannot be ignited anymore.
|
-- Do this if a portal frame is destroyed such that it cannot be ignited anymore.
|
||||||
local function remove_portal_location_info(portal_name, anchorPos)
|
local function remove_portal_location_info(portal_name, anchorPos)
|
||||||
if not DEBUG_IGNORE_MODSTORAGE then
|
if not DEBUG_IGNORE_MODSTORAGE then
|
||||||
mod_storage:set_string(minetest.pos_to_string(anchorPos) .. " is " .. portal_name, "")
|
mod_storage:set_string(minetest.pos_to_string(anchorPos) .. " is " .. portal_name, "")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -677,7 +677,7 @@ local function list_closest_portals(portal_definition, anchorPos, distance_limit
|
|||||||
|
|
||||||
local result = {}
|
local result = {}
|
||||||
|
|
||||||
if not DEBUG_IGNORE_MODSTORAGE then
|
if not DEBUG_IGNORE_MODSTORAGE then
|
||||||
|
|
||||||
local isRealm = portal_definition.is_within_realm(anchorPos)
|
local isRealm = portal_definition.is_within_realm(anchorPos)
|
||||||
if distance_limit == nil then distance_limit = -1 end
|
if distance_limit == nil then distance_limit = -1 end
|
||||||
@ -685,7 +685,7 @@ local function list_closest_portals(portal_definition, anchorPos, distance_limit
|
|||||||
|
|
||||||
for key, value in pairs(mod_storage:to_table().fields) do
|
for key, value in pairs(mod_storage:to_table().fields) do
|
||||||
local closingBrace = key:find(")", 6, true)
|
local closingBrace = key:find(")", 6, true)
|
||||||
if closingBrace ~= nil then
|
if closingBrace ~= nil then
|
||||||
local found_anchorPos = minetest.string_to_pos(key:sub(0, closingBrace))
|
local found_anchorPos = minetest.string_to_pos(key:sub(0, closingBrace))
|
||||||
if found_anchorPos ~= nil and portal_definition.is_within_realm(found_anchorPos) == isRealm then
|
if found_anchorPos ~= nil and portal_definition.is_within_realm(found_anchorPos) == isRealm then
|
||||||
local found_name = key:sub(closingBrace + 5)
|
local found_name = key:sub(closingBrace + 5)
|
||||||
@ -721,7 +721,7 @@ function ambient_sound_play(portal_definition, soundPos, timerNodeMeta)
|
|||||||
-- Using "os.time() % soundLength == 0" is lightweight but means delayed starts, so trying a stored lastPlayed
|
-- Using "os.time() % soundLength == 0" is lightweight but means delayed starts, so trying a stored lastPlayed
|
||||||
if os.time() >= lastPlayed + soundLength then
|
if os.time() >= lastPlayed + soundLength then
|
||||||
local soundHandle = minetest.sound_play(portal_definition.sounds.ambient, {pos = soundPos, max_hear_distance = 8})
|
local soundHandle = minetest.sound_play(portal_definition.sounds.ambient, {pos = soundPos, max_hear_distance = 8})
|
||||||
if timerNodeMeta ~= nil then
|
if timerNodeMeta ~= nil then
|
||||||
timerNodeMeta:set_int("ambient_sound_handle", soundHandle)
|
timerNodeMeta:set_int("ambient_sound_handle", soundHandle)
|
||||||
timerNodeMeta:set_int("ambient_sound_last_played", os.time())
|
timerNodeMeta:set_int("ambient_sound_last_played", os.time())
|
||||||
end
|
end
|
||||||
@ -735,7 +735,7 @@ function ambient_sound_stop(timerNodeMeta)
|
|||||||
if timerNodeMeta ~= nil then
|
if timerNodeMeta ~= nil then
|
||||||
local soundHandle = timerNodeMeta:get_int("ambient_sound_handle")
|
local soundHandle = timerNodeMeta:get_int("ambient_sound_handle")
|
||||||
minetest.sound_fade(soundHandle, -3, 0)
|
minetest.sound_fade(soundHandle, -3, 0)
|
||||||
|
|
||||||
-- clear the metadata
|
-- clear the metadata
|
||||||
timerNodeMeta:set_string("ambient_sound_handle", "")
|
timerNodeMeta:set_string("ambient_sound_handle", "")
|
||||||
timerNodeMeta:set_string("ambient_sound_last_played", "")
|
timerNodeMeta:set_string("ambient_sound_last_played", "")
|
||||||
@ -763,7 +763,7 @@ function extinguish_portal(pos, node_name, frame_was_destroyed)
|
|||||||
minetest.log("error", "extinguish_portal() invoked on " .. node_name .. " but no registered portal is constructed from " .. node_name)
|
minetest.log("error", "extinguish_portal() invoked on " .. node_name .. " but no registered portal is constructed from " .. node_name)
|
||||||
return -- no portal frames are made from this type of node
|
return -- no portal frames are made from this type of node
|
||||||
end
|
end
|
||||||
|
|
||||||
if portal_definition.sounds.extinguish ~= nil then
|
if portal_definition.sounds.extinguish ~= nil then
|
||||||
minetest.sound_play(portal_definition.sounds.extinguish, {pos = p1})
|
minetest.sound_play(portal_definition.sounds.extinguish, {pos = p1})
|
||||||
end
|
end
|
||||||
@ -775,7 +775,7 @@ function extinguish_portal(pos, node_name, frame_was_destroyed)
|
|||||||
|
|
||||||
-- update the ignition state in the portal location info
|
-- update the ignition state in the portal location info
|
||||||
local anchorPos, orientation = portal_definition.shape.get_anchorPos_and_orientation_from_p1_and_p2(p1, p2)
|
local anchorPos, orientation = portal_definition.shape.get_anchorPos_and_orientation_from_p1_and_p2(p1, p2)
|
||||||
if frame_was_destroyed then
|
if frame_was_destroyed then
|
||||||
remove_portal_location_info(portal_definition.name, anchorPos)
|
remove_portal_location_info(portal_definition.name, anchorPos)
|
||||||
else
|
else
|
||||||
store_portal_location_info(portal_definition.name, anchorPos, orientation, false)
|
store_portal_location_info(portal_definition.name, anchorPos, orientation, false)
|
||||||
@ -807,10 +807,10 @@ function extinguish_portal(pos, node_name, frame_was_destroyed)
|
|||||||
|
|
||||||
if target ~= nil then
|
if target ~= nil then
|
||||||
if DEBUG then minetest.chat_send_all(" attempting to also extinguish target with wormholePos " .. minetest.pos_to_string(target)) end
|
if DEBUG then minetest.chat_send_all(" attempting to also extinguish target with wormholePos " .. minetest.pos_to_string(target)) end
|
||||||
extinguish_portal(target, node_name)
|
extinguish_portal(target, node_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
if portal_definition.on_extinguish ~= nil then
|
if portal_definition.on_extinguish ~= nil then
|
||||||
portal_definition.on_extinguish(portal_definition, anchorPos, orientation)
|
portal_definition.on_extinguish(portal_definition, anchorPos, orientation)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -987,7 +987,7 @@ local function build_portal(portal_definition, anchorPos, orientation, destinati
|
|||||||
portal_definition.schematic_filename,
|
portal_definition.schematic_filename,
|
||||||
orientation,
|
orientation,
|
||||||
{ -- node replacements
|
{ -- node replacements
|
||||||
["default:obsidian"] = portal_definition.frame_node_name,
|
["default:obsidian"] = portal_definition.frame_node_name,
|
||||||
["nether:portal"] = portal_definition.wormhole_node_name
|
["nether:portal"] = portal_definition.wormhole_node_name
|
||||||
},
|
},
|
||||||
true
|
true
|
||||||
@ -998,7 +998,7 @@ local function build_portal(portal_definition, anchorPos, orientation, destinati
|
|||||||
param2 = get_colorfacedir_from_color_and_orientation(portal_definition.wormhole_node_color, orientation, portal_definition.shape.is_horizontal)
|
param2 = get_colorfacedir_from_color_and_orientation(portal_definition.wormhole_node_color, orientation, portal_definition.shape.is_horizontal)
|
||||||
}
|
}
|
||||||
portal_definition.shape.apply_func_to_wormhole_nodes(
|
portal_definition.shape.apply_func_to_wormhole_nodes(
|
||||||
anchorPos,
|
anchorPos,
|
||||||
orientation,
|
orientation,
|
||||||
function(pos) minetest.swap_node(pos, wormholeNode) end
|
function(pos) minetest.swap_node(pos, wormholeNode) end
|
||||||
)
|
)
|
||||||
@ -1042,7 +1042,7 @@ end
|
|||||||
-- Used to find or build the remote twin after a portal is opened.
|
-- Used to find or build the remote twin after a portal is opened.
|
||||||
-- If a portal is found that is already lit then it will be extinguished first and its destination_wormholePos updated,
|
-- If a portal is found that is already lit then it will be extinguished first and its destination_wormholePos updated,
|
||||||
-- this is to enforce that portals only link together in mutual pairs. It would be better for gameplay if I didn't apply
|
-- this is to enforce that portals only link together in mutual pairs. It would be better for gameplay if I didn't apply
|
||||||
-- that restriction, but it would require maintaining an accurate list of every portal that links to a portal so they
|
-- that restriction, but it would require maintaining an accurate list of every portal that links to a portal so they
|
||||||
-- could be updated if the portal is destroyed. To keep the code simple I'm going to limit portals to only being the
|
-- could be updated if the portal is destroyed. To keep the code simple I'm going to limit portals to only being the
|
||||||
-- destination of one lit portal at a time.
|
-- destination of one lit portal at a time.
|
||||||
-- * suggested_wormholePos indicates where the portal should be built - note this not an anchorPos!
|
-- * suggested_wormholePos indicates where the portal should be built - note this not an anchorPos!
|
||||||
@ -1112,22 +1112,22 @@ local function ignite_portal(ignition_pos, ignition_node_name)
|
|||||||
if meta ~= nil then
|
if meta ~= nil then
|
||||||
local p1, p2, target = meta:get_string("p1"), meta:get_string("p2"), meta:get_string("target")
|
local p1, p2, target = meta:get_string("p1"), meta:get_string("p2"), meta:get_string("target")
|
||||||
if p1 == "" or p2 == "" or target == "" then
|
if p1 == "" or p2 == "" or target == "" then
|
||||||
-- metadata is missing, the portal frame node must have been removed without calling
|
-- metadata is missing, the portal frame node must have been removed without calling
|
||||||
-- on_destruct - perhaps by an ABM, then replaced - presumably by a player.
|
-- on_destruct - perhaps by an ABM, then replaced - presumably by a player.
|
||||||
-- allowing reigniting will repair the portal
|
-- allowing reigniting will repair the portal
|
||||||
if DEBUG then minetest.chat_send_all("Broken portal detected, allowing reignition/repair") end
|
if DEBUG then minetest.chat_send_all("Broken portal detected, allowing reignition/repair") end
|
||||||
repair = true
|
repair = true
|
||||||
else
|
else
|
||||||
if DEBUG then minetest.chat_send_all("This portal links to " .. meta:get_string("target") .. ". p1=" .. meta:get_string("p1") .. " p2=" .. meta:get_string("p2")) end
|
if DEBUG then minetest.chat_send_all("This portal links to " .. meta:get_string("target") .. ". p1=" .. meta:get_string("p1") .. " p2=" .. meta:get_string("p2")) end
|
||||||
|
|
||||||
-- Check the portal's timer is running, and fix if it's not.
|
-- Check the portal's timer is running, and fix if it's not.
|
||||||
-- A portal's timer can stop running if the game is played without that portal type being
|
-- A portal's timer can stop running if the game is played without that portal type being
|
||||||
-- registered, e.g. enabling one of the example portals then later disabling it, then enabling it again.
|
-- registered, e.g. enabling one of the example portals then later disabling it, then enabling it again.
|
||||||
-- (if this is a frequent problem, then change the value of "run_at_every_load" in the lbm)
|
-- (if this is a frequent problem, then change the value of "run_at_every_load" in the lbm)
|
||||||
local timer = minetest.get_node_timer(get_timerPos_from_p1_and_p2(minetest.string_to_pos(p1), minetest.string_to_pos(p2)))
|
local timer = minetest.get_node_timer(get_timerPos_from_p1_and_p2(minetest.string_to_pos(p1), minetest.string_to_pos(p2)))
|
||||||
if timer ~= nil and timer:get_timeout() == 0 then
|
if timer ~= nil and timer:get_timeout() == 0 then
|
||||||
if DEBUG then minetest.chat_send_all("Portal timer was not running: restarting the timer.") end
|
if DEBUG then minetest.chat_send_all("Portal timer was not running: restarting the timer.") end
|
||||||
timer:start(1)
|
timer:start(1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -1145,7 +1145,7 @@ local function ignite_portal(ignition_pos, ignition_node_name)
|
|||||||
end
|
end
|
||||||
if DEBUG and destination_orientation == nil then minetest.chat_send_all("No destination_orientation given") end
|
if DEBUG and destination_orientation == nil then minetest.chat_send_all("No destination_orientation given") end
|
||||||
if destination_orientation == nil then destination_orientation = orientation end
|
if destination_orientation == nil then destination_orientation = orientation end
|
||||||
|
|
||||||
local destination_wormholePos = portal_definition.shape.get_wormholePos_from_anchorPos(destination_anchorPos, destination_orientation)
|
local destination_wormholePos = portal_definition.shape.get_wormholePos_from_anchorPos(destination_anchorPos, destination_orientation)
|
||||||
if DEBUG then minetest.chat_send_all("Destination set to " .. minetest.pos_to_string(destination_anchorPos)) end
|
if DEBUG then minetest.chat_send_all("Destination set to " .. minetest.pos_to_string(destination_anchorPos)) end
|
||||||
|
|
||||||
@ -1160,7 +1160,7 @@ local function ignite_portal(ignition_pos, ignition_node_name)
|
|||||||
if portal_definition.on_ignite ~= nil then
|
if portal_definition.on_ignite ~= nil then
|
||||||
portal_definition.on_ignite(portal_definition, anchorPos, orientation)
|
portal_definition.on_ignite(portal_definition, anchorPos, orientation)
|
||||||
end
|
end
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -1171,9 +1171,9 @@ local function ensure_remote_portal_then_teleport(player, portal_definition, loc
|
|||||||
|
|
||||||
-- check player is still standing in a portal
|
-- check player is still standing in a portal
|
||||||
local playerPos = player:get_pos()
|
local playerPos = player:get_pos()
|
||||||
if playerPos == nil then
|
if playerPos == nil then
|
||||||
return -- player quit the game while teleporting
|
return -- player quit the game while teleporting
|
||||||
end
|
end
|
||||||
playerPos.y = playerPos.y + 0.1 -- Fix some glitches at -8000
|
playerPos.y = playerPos.y + 0.1 -- Fix some glitches at -8000
|
||||||
if minetest.get_node(playerPos).name ~= portal_definition.wormhole_node_name then
|
if minetest.get_node(playerPos).name ~= portal_definition.wormhole_node_name then
|
||||||
return -- the player has moved out of the portal
|
return -- the player has moved out of the portal
|
||||||
@ -1204,7 +1204,7 @@ local function ensure_remote_portal_then_teleport(player, portal_definition, loc
|
|||||||
local destination_anchorPos = portal_definition.shape.get_anchorPos_from_wormholePos(destination_wormholePos, destination_orientation)
|
local destination_anchorPos = portal_definition.shape.get_anchorPos_from_wormholePos(destination_wormholePos, destination_orientation)
|
||||||
portal_definition.shape.disable_portal_trap(destination_anchorPos, destination_orientation)
|
portal_definition.shape.disable_portal_trap(destination_anchorPos, destination_orientation)
|
||||||
|
|
||||||
-- if the portal is already linked to a different portal then extinguish the other portal and
|
-- if the portal is already linked to a different portal then extinguish the other portal and
|
||||||
-- update the target portal to point back at this one.
|
-- update the target portal to point back at this one.
|
||||||
local remoteMeta = minetest.get_meta(destination_wormholePos)
|
local remoteMeta = minetest.get_meta(destination_wormholePos)
|
||||||
local remoteTarget = minetest.string_to_pos(remoteMeta:get_string("target"))
|
local remoteTarget = minetest.string_to_pos(remoteMeta:get_string("target"))
|
||||||
@ -1241,12 +1241,12 @@ local function ensure_remote_portal_then_teleport(player, portal_definition, loc
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
-- no wormhole node at destination - destination portal either needs to be built or ignited.
|
-- no wormhole node at destination - destination portal either needs to be built or ignited.
|
||||||
-- Note: A very rare edge-case that is difficult to set up:
|
-- Note: A very rare edge-case that is difficult to set up:
|
||||||
-- If the destination portal is unlit and its frame shares a node with a lit portal that is linked to this
|
-- If the destination portal is unlit and its frame shares a node with a lit portal that is linked to this
|
||||||
-- portal (but has not been travelled through, thus not linking this portal back to it), then igniting
|
-- portal (but has not been travelled through, thus not linking this portal back to it), then igniting
|
||||||
-- the destination portal will extinguish the portal it's touching, which will extinguish this portal
|
-- the destination portal will extinguish the portal it's touching, which will extinguish this portal
|
||||||
-- which will leave a confused player.
|
-- which will leave a confused player.
|
||||||
-- I don't think this is worth preventing, but I document it incase someone describes entering a portal
|
-- I don't think this is worth preventing, but I document it incase someone describes entering a portal
|
||||||
-- and then the portal turning off.
|
-- and then the portal turning off.
|
||||||
if DEBUG then minetest.chat_send_all("ensure_remote_portal_then_teleport() saw " .. dest_wormhole_node.name .. " at " .. minetest.pos_to_string(destination_wormholePos) .. " rather than a wormhole. Calling locate_or_build_portal()") end
|
if DEBUG then minetest.chat_send_all("ensure_remote_portal_then_teleport() saw " .. dest_wormhole_node.name .. " at " .. minetest.pos_to_string(destination_wormholePos) .. " rather than a wormhole. Calling locate_or_build_portal()") end
|
||||||
|
|
||||||
@ -1355,7 +1355,7 @@ function run_wormhole(timerPos, time_elapsed)
|
|||||||
local anchorPos, orientation = portal_definition.shape.get_anchorPos_and_orientation_from_p1_and_p2(p1, p2)
|
local anchorPos, orientation = portal_definition.shape.get_anchorPos_and_orientation_from_p1_and_p2(p1, p2)
|
||||||
portal_definition.shape.apply_func_to_wormhole_nodes(anchorPos, orientation, run_wormhole_node_func)
|
portal_definition.shape.apply_func_to_wormhole_nodes(anchorPos, orientation, run_wormhole_node_func)
|
||||||
|
|
||||||
if portal_definition.on_run_wormhole ~= nil then
|
if portal_definition.on_run_wormhole ~= nil then
|
||||||
portal_definition.on_run_wormhole(portal_definition, anchorPos, orientation)
|
portal_definition.on_run_wormhole(portal_definition, anchorPos, orientation)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1479,7 +1479,7 @@ local function create_book_of_portals()
|
|||||||
page2_text
|
page2_text
|
||||||
)
|
)
|
||||||
|
|
||||||
if not previouslyRegistered and nether.PORTAL_BOOK_LOOT_WEIGHTING > 0 and portalCount > 0 then
|
if not previouslyRegistered and nether.PORTAL_BOOK_LOOT_WEIGHTING > 0 and portalCount > 0 then
|
||||||
add_book_as_treasure()
|
add_book_as_treasure()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -1491,7 +1491,7 @@ function get_malleated_schematic_filename(portal_definition)
|
|||||||
local result
|
local result
|
||||||
|
|
||||||
if portal_definition.shape ~= nil and portal_definition.shape.schematic_filename ~= nil then
|
if portal_definition.shape ~= nil and portal_definition.shape.schematic_filename ~= nil then
|
||||||
|
|
||||||
local schematicFileName = portal_definition.shape.schematic_filename
|
local schematicFileName = portal_definition.shape.schematic_filename
|
||||||
local uniqueId = portal_definition.frame_node_name .. " " .. portal_definition.wormhole_node_name
|
local uniqueId = portal_definition.frame_node_name .. " " .. portal_definition.wormhole_node_name
|
||||||
|
|
||||||
@ -1679,8 +1679,8 @@ local wormhole_nodedef_default = {
|
|||||||
palette = "nether_portals_palette.png",
|
palette = "nether_portals_palette.png",
|
||||||
post_effect_color = {
|
post_effect_color = {
|
||||||
-- post_effect_color can't be changed dynamically in Minetest like the portal colour is.
|
-- post_effect_color can't be changed dynamically in Minetest like the portal colour is.
|
||||||
-- If you need a different post_effect_color then use register_wormhole_node() to create
|
-- If you need a different post_effect_color then use register_wormhole_node() to create
|
||||||
-- another wormhole node with the right post_effect_color and set it as the wormhole_node_name
|
-- another wormhole node with the right post_effect_color and set it as the wormhole_node_name
|
||||||
-- in your portaldef.
|
-- in your portaldef.
|
||||||
-- Hopefully this colour is close enough to magenta to work with the traditional magenta
|
-- Hopefully this colour is close enough to magenta to work with the traditional magenta
|
||||||
-- portals, close enough to red to work for a red portal, and also close enough to red to
|
-- portals, close enough to red to work for a red portal, and also close enough to red to
|
||||||
@ -1705,9 +1705,9 @@ local wormhole_nodedef_default = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
groups = {not_in_creative_inventory = 1},
|
groups = {not_in_creative_inventory = 1},
|
||||||
mesecons = {receptor = {
|
mesecons = {receptor = {
|
||||||
state = "on",
|
state = "on",
|
||||||
rules = function(node)
|
rules = function(node)
|
||||||
return nether.get_mesecon_emission_rules_from_colorfacedir(node.param2)
|
return nether.get_mesecon_emission_rules_from_colorfacedir(node.param2)
|
||||||
end
|
end
|
||||||
}}
|
}}
|
||||||
@ -1718,10 +1718,10 @@ function nether.register_wormhole_node(name, nodedef)
|
|||||||
assert(name ~= nil, "Unable to register wormhole node: Name is nil")
|
assert(name ~= nil, "Unable to register wormhole node: Name is nil")
|
||||||
assert(nodedef ~= nil, "Unable to register wormhole node ''" .. name .. "'': nodedef is nil")
|
assert(nodedef ~= nil, "Unable to register wormhole node ''" .. name .. "'': nodedef is nil")
|
||||||
|
|
||||||
for key, value in pairs(wormhole_nodedef_default) do
|
for key, value in pairs(wormhole_nodedef_default) do
|
||||||
if nodedef[key] == nil then nodedef[key] = value end
|
if nodedef[key] == nil then nodedef[key] = value end
|
||||||
end
|
end
|
||||||
minetest.register_node(name, nodedef)
|
minetest.register_node(name, nodedef)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -1779,13 +1779,13 @@ function nether.register_portal(name, portaldef)
|
|||||||
|
|
||||||
if portaldef.find_surface_anchorPos == nil then -- default to using find_surface_target_y()
|
if portaldef.find_surface_anchorPos == nil then -- default to using find_surface_target_y()
|
||||||
portaldef.find_surface_anchorPos = function(pos)
|
portaldef.find_surface_anchorPos = function(pos)
|
||||||
|
|
||||||
local destination_pos = {x = pos.x, y = 0, z = pos.z}
|
local destination_pos = {x = pos.x, y = 0, z = pos.z}
|
||||||
local existing_portal_location, existing_portal_orientation =
|
local existing_portal_location, existing_portal_orientation =
|
||||||
nether.find_nearest_working_portal(name, destination_pos, 10, 0) -- a y_factor of 0 makes the search ignore the altitude of the portals (as long as they are outside the realm)
|
nether.find_nearest_working_portal(name, destination_pos, 10, 0) -- a y_factor of 0 makes the search ignore the altitude of the portals (as long as they are outside the realm)
|
||||||
if existing_portal_location ~= nil then
|
if existing_portal_location ~= nil then
|
||||||
return existing_portal_location, existing_portal_orientation
|
return existing_portal_location, existing_portal_orientation
|
||||||
else
|
else
|
||||||
destination_pos.y = nether.find_surface_target_y(destination_pos.x, destination_pos.z, name)
|
destination_pos.y = nether.find_surface_target_y(destination_pos.x, destination_pos.z, name)
|
||||||
return destination_pos
|
return destination_pos
|
||||||
end
|
end
|
||||||
@ -1798,8 +1798,8 @@ function nether.register_portal(name, portaldef)
|
|||||||
local p1, p2 = portaldef.shape:get_p1_and_p2_from_anchorPos(vector.new(), 0)
|
local p1, p2 = portaldef.shape:get_p1_and_p2_from_anchorPos(vector.new(), 0)
|
||||||
local existing_portaldef = get_portal_definition(portaldef.frame_node_name, p1, p2)
|
local existing_portaldef = get_portal_definition(portaldef.frame_node_name, p1, p2)
|
||||||
if existing_portaldef ~= nil then
|
if existing_portaldef ~= nil then
|
||||||
minetest.log("error",
|
minetest.log("error",
|
||||||
portaldef.mod_name .." tried to register a portal '" .. portaldef.name .. "' made of " .. portaldef.frame_node_name ..
|
portaldef.mod_name .." tried to register a portal '" .. portaldef.name .. "' made of " .. portaldef.frame_node_name ..
|
||||||
", but it is the same material and shape as the portal '" .. existing_portaldef.name .. "' already registered by " .. existing_portaldef.mod_name ..
|
", but it is the same material and shape as the portal '" .. existing_portaldef.name .. "' already registered by " .. existing_portaldef.mod_name ..
|
||||||
". Edit the values one of those mods uses in its call to nether.register_portal() if you wish to resolve this clash.")
|
". Edit the values one of those mods uses in its call to nether.register_portal() if you wish to resolve this clash.")
|
||||||
else
|
else
|
||||||
@ -1865,7 +1865,7 @@ function nether.register_portal_ignition_item(item_name, ignition_failure_sound)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- use this when determining where to spawn a portal, to avoid overwriting player builds
|
-- use this when determining where to spawn a portal, to avoid overwriting player builds
|
||||||
-- It checks the area for any nodes that aren't ground or trees.
|
-- It checks the area for any nodes that aren't ground or trees.
|
||||||
-- (Water also fails this test, unless it is unemerged)
|
-- (Water also fails this test, unless it is unemerged)
|
||||||
function nether.volume_is_natural(minp, maxp)
|
function nether.volume_is_natural(minp, maxp)
|
||||||
local c_air = minetest.get_content_id("air")
|
local c_air = minetest.get_content_id("air")
|
||||||
@ -1909,7 +1909,7 @@ end
|
|||||||
-- portal_name is optional, providing it allows existing portals on the surface to be reused.
|
-- portal_name is optional, providing it allows existing portals on the surface to be reused.
|
||||||
function nether.find_surface_target_y(target_x, target_z, portal_name)
|
function nether.find_surface_target_y(target_x, target_z, portal_name)
|
||||||
|
|
||||||
-- default to starting the search at -16 (probably underground) if we don't know the
|
-- default to starting the search at -16 (probably underground) if we don't know the
|
||||||
-- surface, like paramat's original code from before get_spawn_level() was available:
|
-- surface, like paramat's original code from before get_spawn_level() was available:
|
||||||
-- https://github.com/minetest-mods/nether/issues/5#issuecomment-506983676
|
-- https://github.com/minetest-mods/nether/issues/5#issuecomment-506983676
|
||||||
local start_y = -16
|
local start_y = -16
|
||||||
@ -1917,16 +1917,16 @@ function nether.find_surface_target_y(target_x, target_z, portal_name)
|
|||||||
-- try to spawn on surface first
|
-- try to spawn on surface first
|
||||||
if minetest.get_spawn_level ~= nil then -- older versions of Minetest don't have this
|
if minetest.get_spawn_level ~= nil then -- older versions of Minetest don't have this
|
||||||
local surface_level = minetest.get_spawn_level(target_x, target_z)
|
local surface_level = minetest.get_spawn_level(target_x, target_z)
|
||||||
if surface_level ~= nil then -- test this since get_spawn_level() can return nil over water or steep/high terrain
|
if surface_level ~= nil then -- test this since get_spawn_level() can return nil over water or steep/high terrain
|
||||||
|
|
||||||
-- get_spawn_level() tends to err on the side of caution and spawns the player a
|
-- get_spawn_level() tends to err on the side of caution and spawns the player a
|
||||||
-- block higher than the ground level. The implementation is mapgen specific
|
-- block higher than the ground level. The implementation is mapgen specific
|
||||||
-- and -2 seems to be the right correction for v6, v5, carpathian, valleys, and flat,
|
-- and -2 seems to be the right correction for v6, v5, carpathian, valleys, and flat,
|
||||||
-- but v7 only needs -1.
|
-- but v7 only needs -1.
|
||||||
-- Perhaps this was not always the case, and -2 may be too much in older versions
|
-- Perhaps this was not always the case, and -2 may be too much in older versions
|
||||||
-- of minetest, but half-buried portals are perferable to floating ones, and they
|
-- of minetest, but half-buried portals are perferable to floating ones, and they
|
||||||
-- will clear a suitable hole around themselves.
|
-- will clear a suitable hole around themselves.
|
||||||
if minetest.get_mapgen_setting("mg_name") == "v7" then
|
if minetest.get_mapgen_setting("mg_name") == "v7" then
|
||||||
surface_level = surface_level - 1
|
surface_level = surface_level - 1
|
||||||
else
|
else
|
||||||
surface_level = surface_level - 2
|
surface_level = surface_level - 2
|
||||||
@ -1964,19 +1964,19 @@ function nether.find_nearest_working_portal(portal_name, anchorPos, distance_lim
|
|||||||
|
|
||||||
local portal_definition = nether.registered_portals[portal_name]
|
local portal_definition = nether.registered_portals[portal_name]
|
||||||
assert(portal_definition ~= nil, "find_nearest_working_portal() called with portal_name '" .. portal_name .. "', but no portal is registered with that name.")
|
assert(portal_definition ~= nil, "find_nearest_working_portal() called with portal_name '" .. portal_name .. "', but no portal is registered with that name.")
|
||||||
|
|
||||||
local contenders = list_closest_portals(portal_definition, anchorPos, distance_limit, y_factor)
|
local contenders = list_closest_portals(portal_definition, anchorPos, distance_limit, y_factor)
|
||||||
|
|
||||||
-- sort by distance
|
-- sort by distance
|
||||||
local dist_list = {}
|
local dist_list = {}
|
||||||
for dist, _ in pairs(contenders) do table.insert(dist_list, dist) end
|
for dist, _ in pairs(contenders) do table.insert(dist_list, dist) end
|
||||||
table.sort(dist_list)
|
table.sort(dist_list)
|
||||||
|
|
||||||
for _, dist in ipairs(dist_list) do
|
for _, dist in ipairs(dist_list) do
|
||||||
local portal_info = contenders[dist]
|
local portal_info = contenders[dist]
|
||||||
if DEBUG then minetest.chat_send_all("checking portal from mod_storage at " .. minetest.pos_to_string(portal_info.anchorPos) .. " orientation " .. portal_info.orientation) end
|
if DEBUG then minetest.chat_send_all("checking portal from mod_storage at " .. minetest.pos_to_string(portal_info.anchorPos) .. " orientation " .. portal_info.orientation) end
|
||||||
|
|
||||||
-- the mod_storage list of portals is unreliable - e.g. it won't know if inactive portals have been
|
-- the mod_storage list of portals is unreliable - e.g. it won't know if inactive portals have been
|
||||||
-- destroyed, so check the portal is still there
|
-- destroyed, so check the portal is still there
|
||||||
local portalFound, portalIsActive = is_portal_at_anchorPos(portal_definition, portal_info.anchorPos, portal_info.orientation, true)
|
local portalFound, portalIsActive = is_portal_at_anchorPos(portal_definition, portal_info.anchorPos, portal_info.orientation, true)
|
||||||
|
|
||||||
|
@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
Nether mod portal examples for Minetest
|
Nether mod portal examples for Minetest
|
||||||
|
|
||||||
These portal API examples work independently of the Nether realm
|
These portal API examples work independently of the Nether realm
|
||||||
and Nether portal. To try these examples, enable them in:
|
and Nether portal. To try these examples, enable them in:
|
||||||
Mintest -> Settings -> All settings -> Mods -> nether
|
Mintest -> Settings -> All settings -> Mods -> nether
|
||||||
Once enabled, details on how to build them can be found in dungeon
|
Once enabled, details on how to build them can be found in dungeon
|
||||||
chests in the book of portals.
|
chests in the book of portals.
|
||||||
|
|
||||||
--
|
--
|
||||||
@ -33,10 +33,10 @@ local ENABLE_PORTAL_EXAMPLE_FLOATLANDS = false
|
|||||||
local ENABLE_PORTAL_EXAMPLE_SURFACETRAVEL = false
|
local ENABLE_PORTAL_EXAMPLE_SURFACETRAVEL = false
|
||||||
|
|
||||||
-- Sets how far a Surface Portal will travel, measured in cells along the Moore curve,
|
-- Sets how far a Surface Portal will travel, measured in cells along the Moore curve,
|
||||||
-- which are about 117 nodes square each. Larger numbers will generally mean further distance
|
-- which are about 117 nodes square each. Larger numbers will generally mean further distance
|
||||||
-- as-the-crow-flies, but this will not always be true due to the how the Moore curve
|
-- as-the-crow-flies, but this will not always be true due to the how the Moore curve
|
||||||
-- frequently doubles back upon itself.
|
-- frequently doubles back upon itself.
|
||||||
-- This doubling-back prevents the surface portal from taking players easily accross the
|
-- This doubling-back prevents the surface portal from taking players easily accross the
|
||||||
-- map - the curve is 262144 cells long!
|
-- map - the curve is 262144 cells long!
|
||||||
local SURFACE_TRAVEL_DISTANCE = 26
|
local SURFACE_TRAVEL_DISTANCE = 26
|
||||||
|
|
||||||
@ -53,9 +53,9 @@ if minetest.settings:get_bool("nether_enable_portal_example_floatlands", ENABLE_
|
|||||||
if minetest.get_mapgen_setting("mg_name") == "v7" then
|
if minetest.get_mapgen_setting("mg_name") == "v7" then
|
||||||
local mgv7_spflags = minetest.get_mapgen_setting("mgv7_spflags")
|
local mgv7_spflags = minetest.get_mapgen_setting("mgv7_spflags")
|
||||||
FLOATLANDS_ENABLED = mgv7_spflags ~= nil and mgv7_spflags:find("floatlands") ~= nil and mgv7_spflags:find("nofloatlands") == nil
|
FLOATLANDS_ENABLED = mgv7_spflags ~= nil and mgv7_spflags:find("floatlands") ~= nil and mgv7_spflags:find("nofloatlands") == nil
|
||||||
FLOATLAND_LEVEL = minetest.get_mapgen_setting("mgv7_floatland_level") or 1280
|
FLOATLAND_LEVEL = minetest.get_mapgen_setting("mgv7_floatland_level") or 1280
|
||||||
|
|
||||||
if FLOATLANDS_ENABLED then
|
if FLOATLANDS_ENABLED then
|
||||||
floatlands_flavortext = S("There is a floating land of hills and forests up there, over the edges of which is a perilous drop all the way back down to sea level. We have not found how far these strange pristine lands extend. I have half a mind to retire there one day.")
|
floatlands_flavortext = S("There is a floating land of hills and forests up there, over the edges of which is a perilous drop all the way back down to sea level. We have not found how far these strange pristine lands extend. I have half a mind to retire there one day.")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -120,7 +120,7 @@ end
|
|||||||
-- Surface-travel portal, playable code example --
|
-- Surface-travel portal, playable code example --
|
||||||
--==============================================--
|
--==============================================--
|
||||||
|
|
||||||
-- These Moore Curve functions requred by surface_portal's find_surface_anchorPos() will
|
-- These Moore Curve functions requred by surface_portal's find_surface_anchorPos() will
|
||||||
-- be assigned later in this file.
|
-- be assigned later in this file.
|
||||||
local get_moore_distance -- will be function get_moore_distance(cell_count, x, y): integer
|
local get_moore_distance -- will be function get_moore_distance(cell_count, x, y): integer
|
||||||
local get_moore_coords -- will be function get_moore_coords(cell_count, distance): pos2d
|
local get_moore_coords -- will be function get_moore_coords(cell_count, distance): pos2d
|
||||||
@ -147,7 +147,7 @@ if minetest.settings:get_bool("nether_enable_portal_example_surfacetravel", ENAB
|
|||||||
These travel a distance along the ground, and even when constructed deep underground they link back up to the surface, but we were never able to predict where the matching twin portal would appear. Coudreau believes it works in epicycles, but I am not convinced.
|
These travel a distance along the ground, and even when constructed deep underground they link back up to the surface, but we were never able to predict where the matching twin portal would appear. Coudreau believes it works in epicycles, but I am not convinced.
|
||||||
]]),
|
]]),
|
||||||
|
|
||||||
is_within_realm = function(pos)
|
is_within_realm = function(pos)
|
||||||
-- Always return true, because these portals always just take you around the surface
|
-- Always return true, because these portals always just take you around the surface
|
||||||
-- rather than taking you to a different realm
|
-- rather than taking you to a different realm
|
||||||
return true
|
return true
|
||||||
@ -162,12 +162,12 @@ if minetest.settings:get_bool("nether_enable_portal_example_surfacetravel", ENAB
|
|||||||
find_surface_anchorPos = function(realm_anchorPos)
|
find_surface_anchorPos = function(realm_anchorPos)
|
||||||
-- A portal definition doesn't normally need to provide a find_surface_anchorPos() function,
|
-- A portal definition doesn't normally need to provide a find_surface_anchorPos() function,
|
||||||
-- since find_surface_target_y() will be used by default, but these portals travel around the
|
-- since find_surface_target_y() will be used by default, but these portals travel around the
|
||||||
-- surface (following a Moore curve) so will be calculating a different x and z to realm_anchorPos.
|
-- surface (following a Moore curve) so will be calculating a different x and z to realm_anchorPos.
|
||||||
|
|
||||||
local cellCount = 512
|
local cellCount = 512
|
||||||
local maxDistFromOrigin = 30000 -- the world edges are at X=30927, X=−30912, Z=30927 and Z=−30912
|
local maxDistFromOrigin = 30000 -- the world edges are at X=30927, X=−30912, Z=30927 and Z=−30912
|
||||||
|
|
||||||
-- clip realm_anchorPos to maxDistFromOrigin, and move the origin so that all values are positive
|
-- clip realm_anchorPos to maxDistFromOrigin, and move the origin so that all values are positive
|
||||||
local x = math.min(maxDistFromOrigin, math.max(-maxDistFromOrigin, realm_anchorPos.x)) + maxDistFromOrigin
|
local x = math.min(maxDistFromOrigin, math.max(-maxDistFromOrigin, realm_anchorPos.x)) + maxDistFromOrigin
|
||||||
local z = math.min(maxDistFromOrigin, math.max(-maxDistFromOrigin, realm_anchorPos.z)) + maxDistFromOrigin
|
local z = math.min(maxDistFromOrigin, math.max(-maxDistFromOrigin, realm_anchorPos.z)) + maxDistFromOrigin
|
||||||
|
|
||||||
@ -181,27 +181,27 @@ if minetest.settings:get_bool("nether_enable_portal_example_surfacetravel", ENAB
|
|||||||
local search_radius = divisor / 2 - 5 -- any portal within this area will do
|
local search_radius = divisor / 2 - 5 -- any portal within this area will do
|
||||||
|
|
||||||
-- a y_factor of 0 makes the search ignore the altitude of the portals
|
-- a y_factor of 0 makes the search ignore the altitude of the portals
|
||||||
local existing_portal_location, existing_portal_orientation =
|
local existing_portal_location, existing_portal_orientation =
|
||||||
nether.find_nearest_working_portal("surface_portal", {x = target_x, y = 0, z = target_z}, search_radius, 0)
|
nether.find_nearest_working_portal("surface_portal", {x = target_x, y = 0, z = target_z}, search_radius, 0)
|
||||||
|
|
||||||
if existing_portal_location ~= nil then
|
if existing_portal_location ~= nil then
|
||||||
-- use the existing portal that was found near target_x, target_z
|
-- use the existing portal that was found near target_x, target_z
|
||||||
return existing_portal_location, existing_portal_orientation
|
return existing_portal_location, existing_portal_orientation
|
||||||
else
|
else
|
||||||
-- find a good location for the new portal, or if that isn't possible then at
|
-- find a good location for the new portal, or if that isn't possible then at
|
||||||
-- least adjust the coords a little so portals don't line up in a grid
|
-- least adjust the coords a little so portals don't line up in a grid
|
||||||
local adj_x, adj_z = 0, 0
|
local adj_x, adj_z = 0, 0
|
||||||
|
|
||||||
if minetest.get_spawn_level ~= nil then -- older versions of Minetest don't have this
|
if minetest.get_spawn_level ~= nil then -- older versions of Minetest don't have this
|
||||||
-- Deterministically look for a location in the cell where get_spawn_level() can give
|
-- Deterministically look for a location in the cell where get_spawn_level() can give
|
||||||
-- us a surface height, since nether.find_surface_target_y() works *much* better when
|
-- us a surface height, since nether.find_surface_target_y() works *much* better when
|
||||||
-- it can use get_spawn_level()
|
-- it can use get_spawn_level()
|
||||||
local prng = PcgRandom( -- seed the prng so that all portals for these Moore Curve coords will use the same random location
|
local prng = PcgRandom( -- seed the prng so that all portals for these Moore Curve coords will use the same random location
|
||||||
moore_pos.x * 65732 +
|
moore_pos.x * 65732 +
|
||||||
moore_pos.y * 729 +
|
moore_pos.y * 729 +
|
||||||
minetest.get_mapgen_setting("seed") * 3
|
minetest.get_mapgen_setting("seed") * 3
|
||||||
)
|
)
|
||||||
|
|
||||||
local attemptLimit = 15 -- how many attempts we'll make at finding a good location
|
local attemptLimit = 15 -- how many attempts we'll make at finding a good location
|
||||||
for attempt = 1, attemptLimit do
|
for attempt = 1, attemptLimit do
|
||||||
adj_x = math.floor(prng:rand_normal_dist(-search_radius, search_radius, 2) + 0.5)
|
adj_x = math.floor(prng:rand_normal_dist(-search_radius, search_radius, 2) + 0.5)
|
||||||
@ -212,7 +212,7 @@ if minetest.settings:get_bool("nether_enable_portal_example_surfacetravel", ENAB
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local destination_pos = {x = target_x + adj_x, y = 0, z = target_z + adj_z}
|
local destination_pos = {x = target_x + adj_x, y = 0, z = target_z + adj_z}
|
||||||
destination_pos.y = nether.find_surface_target_y(destination_pos.x, destination_pos.z, "surface_portal")
|
destination_pos.y = nether.find_surface_target_y(destination_pos.x, destination_pos.z, "surface_portal")
|
||||||
|
|
||||||
@ -227,7 +227,7 @@ end
|
|||||||
-- Hilbert curve and Moore curve functions --
|
-- Hilbert curve and Moore curve functions --
|
||||||
--=========================================--
|
--=========================================--
|
||||||
|
|
||||||
-- These are space-filling curves, used by the surface_portal example as a way to determine where
|
-- These are space-filling curves, used by the surface_portal example as a way to determine where
|
||||||
-- to place portals. https://en.wikipedia.org/wiki/Moore_curve
|
-- to place portals. https://en.wikipedia.org/wiki/Moore_curve
|
||||||
|
|
||||||
|
|
||||||
@ -242,7 +242,7 @@ local function hilbert_flip(cell_count, pos, flip_direction, flip_twice)
|
|||||||
pos.x = (cell_count - 1) - pos.x;
|
pos.x = (cell_count - 1) - pos.x;
|
||||||
pos.y = (cell_count - 1) - pos.y;
|
pos.y = (cell_count - 1) - pos.y;
|
||||||
end
|
end
|
||||||
|
|
||||||
local temp_x = pos.x;
|
local temp_x = pos.x;
|
||||||
pos.x = pos.y;
|
pos.x = pos.y;
|
||||||
pos.y = temp_x;
|
pos.y = temp_x;
|
||||||
@ -306,7 +306,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
-- Converts (x,y) to distance
|
-- Converts (x,y) to distance
|
||||||
-- A Moore curve is a variation of the Hilbert curve that has the start and
|
-- A Moore curve is a variation of the Hilbert curve that has the start and
|
||||||
-- end next to each other.
|
-- end next to each other.
|
||||||
-- Top middle point is the start/end location
|
-- Top middle point is the start/end location
|
||||||
get_moore_distance = function(cell_count, x, y)
|
get_moore_distance = function(cell_count, x, y)
|
||||||
@ -324,7 +324,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
-- Converts distance to (x,y)
|
-- Converts distance to (x,y)
|
||||||
-- A Moore curve is a variation of the Hilbert curve that has the start and
|
-- A Moore curve is a variation of the Hilbert curve that has the start and
|
||||||
-- end next to each other.
|
-- end next to each other.
|
||||||
-- Top middle point is the start/end location
|
-- Top middle point is the start/end location
|
||||||
get_moore_coords = function(cell_count, distance)
|
get_moore_coords = function(cell_count, distance)
|
||||||
|
Loading…
Reference in New Issue
Block a user