mirror of
https://github.com/minetest-mods/nether.git
synced 2025-07-17 15:50:46 +02:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
59
init.lua
59
init.lua
@ -19,6 +19,13 @@
|
||||
|
||||
]]--
|
||||
|
||||
-- Set DEBUG_FLAGS to determine the behavior of nether.debug():
|
||||
-- 0 = off
|
||||
-- 1 = print(...)
|
||||
-- 2 = minetest.chat_send_all(...)
|
||||
-- 4 = minetest.log("info", ...)
|
||||
local DEBUG_FLAGS = 0
|
||||
|
||||
local S
|
||||
if minetest.get_translator ~= nil then
|
||||
S = minetest.get_translator("nether")
|
||||
@ -58,11 +65,53 @@ nether.NETHER_REALM_ENABLED = minetest.settings:get_bool("nether_realm_ena
|
||||
nether.DEPTH_CEILING = tonumber(minetest.settings:get("nether_depth_ymax") or nether.DEPTH_CEILING)
|
||||
nether.DEPTH_FLOOR = tonumber(minetest.settings:get("nether_depth_ymin") or nether.DEPTH_FLOOR)
|
||||
|
||||
if nether.DEPTH_FLOOR + 1000 > nether.DEPTH_CEILING then
|
||||
if nether.DEPTH_FLOOR + 1000 > nether.DEPTH_CEILING then
|
||||
error("The lower limit of the Nether must be set at least 1000 lower than the upper limit, and more than 3000 is recommended. Set settingtypes.txt, or 'All Settings' -> 'Mods' -> 'nether' -> 'Nether depth'", 0)
|
||||
end
|
||||
nether.DEPTH = nether.DEPTH_CEILING -- Deprecated, use nether.DEPTH_CEILING instead.
|
||||
|
||||
|
||||
-- A debug-print function that understands vectors etc. and does not
|
||||
-- evaluate when debugging is turned off.
|
||||
-- Works like string.format(), treating the message as a format string.
|
||||
-- nils, tables, and vectors passed as arguments to nether.debug() are
|
||||
-- converted to strings and can be included inside the message with %s
|
||||
function nether.debug(message, ...)
|
||||
|
||||
local args = {...}
|
||||
local argCount = select("#", ...)
|
||||
|
||||
for i = 1, argCount do
|
||||
local arg = args[i]
|
||||
if arg == nil then
|
||||
-- convert nils to strings
|
||||
args[i] = '<nil>'
|
||||
elseif type(arg) == "table" then
|
||||
local tableCount = 0
|
||||
for _,_ in pairs(arg) do tableCount = tableCount + 1 end
|
||||
if tableCount == 3 and arg.x ~= nil and arg.y ~= nil and arg.z ~= nil then
|
||||
-- convert vectors to strings
|
||||
args[i] = minetest.pos_to_string(arg)
|
||||
else
|
||||
-- convert tables to strings
|
||||
-- (calling function can use dump() if a multi-line listing is desired)
|
||||
args[i] = string.gsub(dump(arg, ""), "\n", " ")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local composed_message = string.format(message, unpack(args))
|
||||
|
||||
if math.floor(DEBUG_FLAGS / 1) % 2 == 1 then print(composed_message) end
|
||||
if math.floor(DEBUG_FLAGS / 2) % 2 == 1 then minetest.chat_send_all(composed_message) end
|
||||
if math.floor(DEBUG_FLAGS / 4) % 2 == 1 then minetest.log("info", composed_message) end
|
||||
end
|
||||
if DEBUG_FLAGS == 0 then
|
||||
-- do as little evaluation as possible
|
||||
nether.debug = function() end
|
||||
end
|
||||
|
||||
|
||||
-- Load files
|
||||
dofile(nether.path .. "/portal_api.lua")
|
||||
dofile(nether.path .. "/nodes.lua")
|
||||
@ -101,7 +150,7 @@ The expedition parties have found no diamonds or gold, and after an experienced
|
||||
return pos.y < nether.DEPTH_CEILING
|
||||
end,
|
||||
|
||||
find_realm_anchorPos = function(surface_anchorPos)
|
||||
find_realm_anchorPos = function(surface_anchorPos, player_name)
|
||||
-- divide x and z by a factor of 8 to implement Nether fast-travel
|
||||
local destination_pos = vector.divide(surface_anchorPos, nether.FASTTRAVEL_FACTOR)
|
||||
destination_pos.x = math.floor(0.5 + destination_pos.x) -- round to int
|
||||
@ -116,12 +165,12 @@ The expedition parties have found no diamonds or gold, and after an experienced
|
||||
return existing_portal_location, existing_portal_orientation
|
||||
else
|
||||
local start_y = nether.DEPTH_CEILING - math.random(500, 1500) -- Search starting altitude
|
||||
destination_pos.y = nether.find_nether_ground_y(destination_pos.x, destination_pos.z, start_y)
|
||||
destination_pos.y = nether.find_nether_ground_y(destination_pos.x, destination_pos.z, start_y, player_name)
|
||||
return destination_pos
|
||||
end
|
||||
end,
|
||||
|
||||
find_surface_anchorPos = function(realm_anchorPos)
|
||||
find_surface_anchorPos = function(realm_anchorPos, player_name)
|
||||
-- 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 Nether portals also scale position
|
||||
-- to create fast-travel.
|
||||
@ -140,7 +189,7 @@ The expedition parties have found no diamonds or gold, and after an experienced
|
||||
if existing_portal_location ~= nil then
|
||||
return existing_portal_location, existing_portal_orientation
|
||||
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", player_name)
|
||||
return destination_pos
|
||||
end
|
||||
end,
|
||||
|
Reference in New Issue
Block a user