I haven't had time to test this myself yet, but the main problem that I can't fix on my end is that teleporters on different surfaces don't understand interplanetary distances and assume a short distance (maybe based on surface-relative positions).
My proposed solution for this is that you implement a remote interface call to see if any mods can return specific values for surface-to-surface distances. Something like:
-- make a cache table for distances that don't change, should be cleared on configuration changed
global.cache_surface_to_surface_distance = {}
-- when trying to find a surface to surface distance check interfaces for a surface distance implementation
-- surface_from and surface_to are the surface index numbers
if global.cache_surface_to_surface_distance
and global.cache_surface_to_surface_distance[surface_from]
and global.cache_surface_to_surface_distance[surface_from][surface_to] then
return global.cache_surface_to_surface_distance[surface_from][surface_to]
end
local result
for interface, functions in pairs(remote.interfaces) do
if functions["bulkteleport_get_surface_to_surface_distance"] then
local interface_result = remote.call(interface, "bulkteleport_get_surface_to_surface_distance", {surface_from=surface_from, surface_to=surface_to})
if interface_result and interface_result.distance then
if result == nil or interface_result.distance > result.distance then -- use higher value then
result = interface_result
end
end
end
end
local distance = 0
if result and result.distance then
distance = result.distance
if result.cache == true then
global.cache_surface_to_surface_distance[surface_from] = global.cache_surface_to_surface_distance[surface_from]
or {}
global.cache_surface_to_surface_distance[surface_from][surface_to] = distance
end
end
You could potentially extend this sort of system to store data with flags, such as whether the relative positions should be considered (for close parallel surfaces like underground).