fix startup crashes; crashes in cloudwand

This commit is contained in:
Starbeamrainbowlabs 2022-09-19 17:27:59 +01:00
parent 7a688969b2
commit 1024b19629
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
14 changed files with 102 additions and 121 deletions

View file

@ -1,4 +1,4 @@
local wea_c = worldeditadditions_commands local wea_c = worldeditadditions_core
local Vector3 = wea_c.Vector3 local Vector3 = wea_c.Vector3
--- Counts the nodes in a given area. --- Counts the nodes in a given area.

View file

@ -1,4 +1,4 @@
local wea_c = worldeditadditions_commands local wea_c = worldeditadditions_core
local Vector3 = wea_c.Vector3 local Vector3 = wea_c.Vector3
--- Generates a maze. --- Generates a maze.

View file

@ -1,4 +1,4 @@
local wea_c = worldeditadditions_commands local wea_c = worldeditadditions_core
local Vector3 = wea_c.Vector3 local Vector3 = wea_c.Vector3
--- Generates a maze. --- Generates a maze.

View file

@ -1,4 +1,4 @@
local wea_c = worldeditadditions_commands local wea_c = worldeditadditions_core
local Vector3 = wea_c.Vector3 local Vector3 = wea_c.Vector3
-- ███ ██ ██████ ██ ███████ ███████ █████ ██████ ██████ ██ ██ ██ ██████ ██████ -- ███ ██ ██████ ██ ███████ ███████ █████ ██████ ██████ ██ ██ ██ ██████ ██████

View file

@ -1,4 +1,4 @@
local wea_c = worldeditadditions_commands local wea_c = worldeditadditions_core
local Vector3 = wea_c.Vector3 local Vector3 = wea_c.Vector3
--- Overlap command. Places a specified node on top of each column. --- Overlap command. Places a specified node on top of each column.

View file

@ -1,4 +1,4 @@
local wea_c = worldeditadditions_commands local wea_c = worldeditadditions_core
local Vector3 = wea_c.Vector3 local Vector3 = wea_c.Vector3
--- Like //mix, but replaces a given node instead. --- Like //mix, but replaces a given node instead.

View file

@ -17,16 +17,16 @@ function selection.add_point(name, pos)
if pos ~= nil then if pos ~= nil then
local created_new = not worldedit.pos1[name] or not worldedit.pos2[name] local created_new = not worldedit.pos1[name] or not worldedit.pos2[name]
-- print("[set_pos1]", name, "("..pos.x..", "..pos.y..", "..pos.z..")") -- print("[set_pos1]", name, "("..pos.x..", "..pos.y..", "..pos.z..")")
if not worldedit.pos1[name] then worldedit.pos1[name] = Vector3.new(pos) end if not worldedit.pos1[name] then worldedit.pos1[name] = Vector3.clone(pos) end
if not worldedit.pos2[name] then worldedit.pos2[name] = Vector3.new(pos) end if not worldedit.pos2[name] then worldedit.pos2[name] = Vector3.clone(pos) end
worldedit.marker_update(name) worldedit.marker_update(name)
local volume_before = worldedit.volume(worldedit.pos1[name], worldedit.pos2[name]) local volume_before = worldedit.volume(worldedit.pos1[name], worldedit.pos2[name])
worldedit.pos1[name], worldedit.pos2[name] = Vector3.expand_region( worldedit.pos1[name], worldedit.pos2[name] = Vector3.expand_region(
Vector3.new(worldedit.pos1[name]), Vector3.clone(worldedit.pos1[name]),
Vector3.new(worldedit.pos2[name]), Vector3.clone(worldedit.pos2[name]),
pos pos
) )

View file

@ -100,7 +100,7 @@ end
-- --
-- @param command_str str The command string to operate on. -- @param command_str str The command string to operate on.
-- @returns bool,(string[]|string) If the operation was successful, then true followed by a table of strings is returned. If the operation was not successful, then false followed by an error message (as a single string) is returned instead. -- @returns bool,(string[]|string) If the operation was successful, then true followed by a table of strings is returned. If the operation was not successful, then false followed by an error message (as a single string) is returned instead.
function worldeditadditions.parse.tokenise_commands(command_str) function worldeditadditions_core.parse.tokenise_commands(command_str)
local success, result = tokenise(command_str) local success, result = tokenise(command_str)
if not success then return success, result end if not success then return success, result end
return true, recombine(result) return true, recombine(result)

View file

@ -1,4 +1,5 @@
local wea_c = worldeditadditions_core local wea_c = worldeditadditions_core
local Vector3 = wea_c.Vector3
--- Raycasts to find a node in the direction the given player is looking. --- Raycasts to find a node in the direction the given player is looking.
-- @param player Player The player object to raycast from. -- @param player Player The player object to raycast from.
-- @param maxdist number The maximum distance to raycast. -- @param maxdist number The maximum distance to raycast.
@ -7,27 +8,20 @@ local wea_c = worldeditadditions_core
function wea_c.raycast(player, maxdist, skip_liquid) function wea_c.raycast(player, maxdist, skip_liquid)
if maxdist == nil then maxdist = 100 end if maxdist == nil then maxdist = 100 end
if skip_liquid == nil then skip_liquid = false end if skip_liquid == nil then skip_liquid = false end
local look_dir = player:get_look_dir() local look_dir = Vector3.clone(player:get_look_dir())
local node_id_ignore = minetest.get_content_id("ignore") local node_id_ignore = minetest.get_content_id("ignore")
local cur_pos = {} local cur_pos
local player_pos = player:getpos() local player_pos = player:get_pos()
player_pos.y = player_pos.y + 1.5 -- Calculate from the eye position player_pos.y = player_pos.y + 1.5 -- Calculate from the eye position
local divisor = 5 local divisor = 5
for i = 1, maxdist do for i = 1, maxdist do
local j = i / divisor local j = i / divisor
cur_pos.x = (look_dir.x*j) + player_pos.x cur_pos = (look_dir * j) + player_pos
cur_pos.y = (look_dir.y*j) + player_pos.y
cur_pos.z = (look_dir.z*j) + player_pos.z local node_pos = cur_pos:round()
local node_pos = {
x = math.floor(0.5+cur_pos.x),
y = math.floor(0.5+cur_pos.y),
z = math.floor(0.5+cur_pos.z)
}
-- Don't bother if this is the same position we were looking at before -- Don't bother if this is the same position we were looking at before
if not (node_pos.x == math.floor(0.5+look_dir.x*(j-divisor)) if not (node_pos.x == math.floor(0.5+look_dir.x*(j-divisor))
@ -39,7 +33,7 @@ function wea_c.raycast(player, maxdist, skip_liquid)
local node = minetest.get_node_or_nil(node_pos) local node = minetest.get_node_or_nil(node_pos)
if node ~= nil then if node ~= nil then
local node_id = minetest.get_content_id(node.name) local node_id = minetest.get_content_id(node.name)
local is_air = worldeditadditions.is_airlike(node_id) local is_air = wea_c.is_airlike(node_id)
-- ignore = unloaded chunks, as far as I can tell -- ignore = unloaded chunks, as far as I can tell
if node_id == node_id_ignore then if node_id == node_id_ignore then
@ -50,7 +44,7 @@ function wea_c.raycast(player, maxdist, skip_liquid)
if skip_liquid == false then if skip_liquid == false then
return node_pos, node_id return node_pos, node_id
else else
local is_liquid = worldeditadditions.is_liquidlike(node_id) local is_liquid = wea_c.is_liquidlike(node_id)
if is_liquid == false then if is_liquid == false then
return node_pos, node_id return node_pos, node_id
end end

View file

@ -1,19 +1,19 @@
worldeditadditions.vector = {} worldeditadditions_core.vector = {}
-- @deprecated Use Vector3 instead. -- -- @deprecated Use Vector3 instead.
function worldeditadditions.vector.tostring(v) -- function worldeditadditions_core.vector.tostring(v)
if not v then return "(nil)" end -- if not v then return "(nil)" end
return "(" .. v.x ..", " .. v.y ..", " .. v.z ..")" -- return "(" .. v.x ..", " .. v.y ..", " .. v.z ..")"
end -- end
--- Calculates the length squared of the given vector. -- --- Calculates the length squared of the given vector.
-- @deprecated Use Vector3 instead. -- -- @deprecated Use Vector3 instead.
-- @param v Vector The vector to operate on -- -- @param v Vector The vector to operate on
-- @return number The length of the given vector squared -- -- @return number The length of the given vector squared
function worldeditadditions.vector.lengthsquared(v) -- function worldeditadditions_core.vector.lengthsquared(v)
if not v.y then return v.x*v.x + v.z*v.z end -- if not v.y then return v.x*v.x + v.z*v.z end
return v.x*v.x + v.y*v.y + v.z*v.z -- return v.x*v.x + v.y*v.y + v.z*v.z
end -- end
--- Normalises the given vector such that its length is 1. --- Normalises the given vector such that its length is 1.
-- Also known as calculating the unit vector. -- Also known as calculating the unit vector.
@ -21,54 +21,54 @@ end
-- @deprecated Use Vector3 instead. -- @deprecated Use Vector3 instead.
-- @param v Vector The vector to calculate from. -- @param v Vector The vector to calculate from.
-- @return Vector A new normalised vector. -- @return Vector A new normalised vector.
function worldeditadditions.vector.normalize(v) -- function worldeditadditions_core.vector.normalize(v)
local length = math.sqrt(worldeditadditions.vector.lengthsquared(v)) -- local length = math.sqrt(worldeditadditions_core.vector.lengthsquared(v))
if not v.y then return { -- if not v.y then return {
x = v.x / length, -- x = v.x / length,
z = v.z / length -- z = v.z / length
} end -- } end
return { -- return {
x = v.x / length, -- x = v.x / length,
y = v.y / length, -- y = v.y / length,
z = v.z / length -- z = v.z / length
} -- }
end -- end
--- Rounds the values in a vector down. --- Rounds the values in a vector down.
-- Warning: This MUTATES the given vector! -- Warning: This MUTATES the given vector!
-- @deprecated Use Vector3 instead. -- @deprecated Use Vector3 instead.
-- @param v Vector The vector to operate on -- @param v Vector The vector to operate on
function worldeditadditions.vector.floor(v) -- function worldeditadditions_core.vector.floor(v)
if v.x then v.x = math.floor(v.x) end -- if v.x then v.x = math.floor(v.x) end
-- Some vectors are 2d, but on the x / z axes -- -- Some vectors are 2d, but on the x / z axes
if v.y then v.y = math.floor(v.y) end -- if v.y then v.y = math.floor(v.y) end
-- Some vectors are 2d -- -- Some vectors are 2d
if v.z then v.z = math.floor(v.z) end -- if v.z then v.z = math.floor(v.z) end
end -- end
--- Rounds the values in a vector up. --- Rounds the values in a vector up.
-- Warning: This MUTATES the given vector! -- Warning: This MUTATES the given vector!
-- @deprecated Use Vector3 instead. -- @deprecated Use Vector3 instead.
-- @param v Vector The vector to operate on -- @param v Vector The vector to operate on
function worldeditadditions.vector.ceil(v) -- function worldeditadditions_core.vector.ceil(v)
if v.x then v.x = math.ceil(v.x) end -- if v.x then v.x = math.ceil(v.x) end
-- Some vectors are 2d, but on the x / z axes -- -- Some vectors are 2d, but on the x / z axes
if v.y then v.y = math.ceil(v.y) end -- if v.y then v.y = math.ceil(v.y) end
-- Some vectors are 2d -- -- Some vectors are 2d
if v.z then v.z = math.ceil(v.z) end -- if v.z then v.z = math.ceil(v.z) end
end -- end
--- Sets the values in a vector to their absolute values. --- Sets the values in a vector to their absolute values.
-- Warning: This MUTATES the given vector! -- Warning: This MUTATES the given vector!
-- @deprecated Use Vector3 instead. -- @deprecated Use Vector3 instead.
-- @param v Vector The vector to operate on -- @param v Vector The vector to operate on
function worldeditadditions.vector.abs(v) -- function worldeditadditions_core.vector.abs(v)
if v.x then v.x = math.abs(v.x) end -- if v.x then v.x = math.abs(v.x) end
-- Some vectors are 2d, but on the x / z axes -- -- Some vectors are 2d, but on the x / z axes
if v.y then v.y = math.abs(v.y) end -- if v.y then v.y = math.abs(v.y) end
-- Some vectors are 2d -- -- Some vectors are 2d
if v.z then v.z = math.abs(v.z) end -- if v.z then v.z = math.abs(v.z) end
end -- end
--- Determines if the target point is contained within the defined worldedit region. --- Determines if the target point is contained within the defined worldedit region.
-- @deprecated Use Vector3 instead. -- @deprecated Use Vector3 instead.
@ -76,41 +76,41 @@ end
-- @param pos2 Vector pos2 of the defined region. -- @param pos2 Vector pos2 of the defined region.
-- @param target Vector The target vector to check. -- @param target Vector The target vector to check.
-- @return boolean Whether the given target is contained within the defined worldedit region. -- @return boolean Whether the given target is contained within the defined worldedit region.
function worldeditadditions.vector.is_contained(pos1, pos2, target) -- function worldeditadditions_core.vector.is_contained(pos1, pos2, target)
local pos1, pos2 = worldedit.sort_pos(pos1, pos2) -- local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
return pos1.x >= target.x -- return pos1.x >= target.x
and pos1.y >= target.y -- and pos1.y >= target.y
and pos1.z >= target.z -- and pos1.z >= target.z
and pos2.x <= target.x -- and pos2.x <= target.x
and pos2.y <= target.y -- and pos2.y <= target.y
and pos2.z <= target.z -- and pos2.z <= target.z
end -- end
--- Expands the defined region to include the given point. --- Expands the defined region to include the given point.
-- @deprecated Use Vector3 instead. -- @deprecated Use Vector3 instead.
-- @param pos1 Vector pos1 of the defined region. -- @param pos1 Vector pos1 of the defined region.
-- @param pos2 Vector pos2 of the defined region. -- @param pos2 Vector pos2 of the defined region.
-- @param target Vector The target vector to include. -- @param target Vector The target vector to include.
function worldeditadditions.vector.expand_region(pos1, pos2, target) -- function worldeditadditions_core.vector.expand_region(pos1, pos2, target)
local pos1, pos2 = worldedit.sort_pos(pos1, pos2) -- local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
if target.x < pos1.x then pos1.x = target.x end -- if target.x < pos1.x then pos1.x = target.x end
if target.y < pos1.y then pos1.y = target.y end -- if target.y < pos1.y then pos1.y = target.y end
if target.z < pos1.z then pos1.z = target.z end -- if target.z < pos1.z then pos1.z = target.z end
if target.x > pos2.x then pos2.x = target.x end -- if target.x > pos2.x then pos2.x = target.x end
if target.y > pos2.y then pos2.y = target.y end -- if target.y > pos2.y then pos2.y = target.y end
if target.z > pos2.z then pos2.z = target.z end -- if target.z > pos2.z then pos2.z = target.z end
return pos1, pos2 -- return pos1, pos2
end -- end
--- Returns the mean (average) of 2 positions to give you the centre. --- Returns the mean (average) of 2 positions to give you the centre.
-- @deprecated Use Vector3 instead. -- @deprecated Use Vector3 instead.
-- @param pos1 Vector pos1 of the defined region. -- @param pos1 Vector pos1 of the defined region.
-- @param pos2 Vector pos2 of the defined region. -- @param pos2 Vector pos2 of the defined region.
-- @param target Vector Centre coordinates. -- @param target Vector Centre coordinates.
function worldeditadditions.vector.mean(pos1, pos2) function worldeditadditions_core.vector.mean(pos1, pos2)
return vector.new((pos1.x + pos2.x)/2, (pos1.y + pos2.y)/2, (pos1.z + pos2.z)/2) return vector.new((pos1.x + pos2.x)/2, (pos1.y + pos2.y)/2, (pos1.z + pos2.z)/2)
end end
@ -119,15 +119,15 @@ end
-- @param pos1 Vector pos1 of the defined region. -- @param pos1 Vector pos1 of the defined region.
-- @param pos2 Vector pos2 of the defined region. -- @param pos2 Vector pos2 of the defined region.
-- @return Vector Min values from input vectors. -- @return Vector Min values from input vectors.
function worldeditadditions.vector.min(pos1, pos2) -- function worldeditadditions_core.vector.min(pos1, pos2)
return vector.new(math.min(pos1.x, pos2.x), math.min(pos1.y, pos2.y), math.min(pos1.z, pos2.z)) -- return vector.new(math.min(pos1.x, pos2.x), math.min(pos1.y, pos2.y), math.min(pos1.z, pos2.z))
end -- end
--- Returns a vector of the max values of 2 positions. --- Returns a vector of the max values of 2 positions.
-- @deprecated Use Vector3 instead. -- @deprecated Use Vector3 instead.
-- @param pos1 Vector pos1 of the defined region. -- @param pos1 Vector pos1 of the defined region.
-- @param pos2 Vector pos2 of the defined region. -- @param pos2 Vector pos2 of the defined region.
-- @return Vector Max values from input vectors. -- @return Vector Max values from input vectors.
function worldeditadditions.vector.max(pos1, pos2) -- function worldeditadditions_core.vector.max(pos1, pos2)
return vector.new(math.max(pos1.x, pos2.x), math.max(pos1.y, pos2.y), math.max(pos1.z, pos2.z)) -- return vector.new(math.max(pos1.x, pos2.x), math.max(pos1.y, pos2.y), math.max(pos1.z, pos2.z))
end -- end

View file

@ -1,10 +1,11 @@
local wea_c = worldeditadditions_core
local farwand = worldeditadditions.farwand -- Convenience shurtcut local farwand = worldeditadditions.farwand -- Convenience shurtcut
local function parse_params_farwand(params_text) local function parse_params_farwand(params_text)
if params_text == nil then if params_text == nil then
return false, "Can't parse nil value" return false, "Can't parse nil value"
end end
local parts = worldeditadditions.split(params_text, "%s+", false) local parts = wea_c.split(params_text, "%s+", false)
local key = nil local key = nil
local value = nil local value = nil

View file

@ -1,4 +1,5 @@
local wea = worldeditadditions local wea = worldeditadditions
-- local wea_c = worldeditadditions_core
minetest.register_tool(":worldeditadditions:cloudwand", { minetest.register_tool(":worldeditadditions:cloudwand", {
description = "WorldEditAdditions far-reaching additive selectior wand", description = "WorldEditAdditions far-reaching additive selectior wand",
@ -16,6 +17,7 @@ minetest.register_tool(":worldeditadditions:cloudwand", {
local name = player:get_player_name() local name = player:get_player_name()
-- print("[farwand] on_use", name) -- print("[farwand] on_use", name)
local looking_pos, node_id = worldeditadditions.farwand.do_raycast(player) local looking_pos, node_id = worldeditadditions.farwand.do_raycast(player)
print("DEBUG cloudwand:looking_pos", looking_pos)
wea.selection.add_point(name, looking_pos) wea.selection.add_point(name, looking_pos)
-- Left click when pointing at something or nothing -- Left click when pointing at something or nothing
end, end,

View file

@ -1,4 +1,4 @@
local wea_c = worldeditadditions_core
--- worldeditadditions.raycast() wrapper --- worldeditadditions.raycast() wrapper
function worldeditadditions.farwand.do_raycast(player) function worldeditadditions.farwand.do_raycast(player)
if player == nil then return nil end if player == nil then return nil end
@ -8,7 +8,7 @@ function worldeditadditions.farwand.do_raycast(player)
worldeditadditions.farwand.player_data[player_name] = { maxdist = 1000, skip_liquid = true } worldeditadditions.farwand.player_data[player_name] = { maxdist = 1000, skip_liquid = true }
end end
local looking_pos, node_id = worldeditadditions.raycast( local looking_pos, node_id = wea_c.raycast(
player, player,
worldeditadditions.farwand.player_data[player_name].maxdist, worldeditadditions.farwand.player_data[player_name].maxdist,
worldeditadditions.farwand.player_data[player_name].skip_liquid worldeditadditions.farwand.player_data[player_name].skip_liquid

View file

@ -21,22 +21,6 @@ local function set_pos2(name, pos)
end end
end end
local function do_raycast(player)
if player == nil then return nil end
local player_name = player:get_player_name()
if worldeditadditions.farwand.player_data[player_name] == nil then
worldeditadditions.farwand.player_data[player_name] = { maxdist = 1000, skip_liquid = true }
end
local looking_pos, node_id = worldeditadditions.raycast(
player,
worldeditadditions.farwand.player_data[player_name].maxdist,
worldeditadditions.farwand.player_data[player_name].skip_liquid
)
return looking_pos, node_id
end
minetest.register_tool(":worldeditadditions:farwand", { minetest.register_tool(":worldeditadditions:farwand", {
description = "WorldEditAdditions far-reaching wand", description = "WorldEditAdditions far-reaching wand",
inventory_image = "worldeditadditions_farwand.png", inventory_image = "worldeditadditions_farwand.png",
@ -46,14 +30,14 @@ minetest.register_tool(":worldeditadditions:farwand", {
-- print("[farwand] on_place", name) -- print("[farwand] on_place", name)
-- Right click when pointing at something -- Right click when pointing at something
-- Pointed thing: https://rubenwardy.com/minetest_modding_book/lua_api.html#pointed_thing -- Pointed thing: https://rubenwardy.com/minetest_modding_book/lua_api.html#pointed_thing
local looking_pos, node_id = do_raycast(player) local looking_pos, node_id = worldeditadditions.farwand.do_raycast(player)
set_pos2(name, looking_pos) set_pos2(name, looking_pos)
end, end,
on_use = function(itemstack, player, pointed_thing) on_use = function(itemstack, player, pointed_thing)
local name = player:get_player_name() local name = player:get_player_name()
-- print("[farwand] on_use", name) -- print("[farwand] on_use", name)
local looking_pos, node_id = do_raycast(player) local looking_pos, node_id = worldeditadditions.farwand.do_raycast(player)
set_pos1(name, looking_pos) set_pos1(name, looking_pos)
-- Left click when pointing at something or nothing -- Left click when pointing at something or nothing
end, end,
@ -63,7 +47,7 @@ minetest.register_tool(":worldeditadditions:farwand", {
-- Right click when pointing at nothing -- Right click when pointing at nothing
-- print("[farwand] on_secondary_use", name) -- print("[farwand] on_secondary_use", name)
local looking_pos, node_id = do_raycast(player) local looking_pos, node_id = worldeditadditions.farwand.do_raycast(player)
set_pos2(name, looking_pos) set_pos2(name, looking_pos)
end end
}) })