mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-12-22 19:45:02 +00:00
fix startup crashes; crashes in cloudwand
This commit is contained in:
parent
7a688969b2
commit
1024b19629
14 changed files with 102 additions and 121 deletions
|
@ -1,4 +1,4 @@
|
|||
local wea_c = worldeditadditions_commands
|
||||
local wea_c = worldeditadditions_core
|
||||
local Vector3 = wea_c.Vector3
|
||||
|
||||
--- Counts the nodes in a given area.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local wea_c = worldeditadditions_commands
|
||||
local wea_c = worldeditadditions_core
|
||||
local Vector3 = wea_c.Vector3
|
||||
|
||||
--- Generates a maze.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local wea_c = worldeditadditions_commands
|
||||
local wea_c = worldeditadditions_core
|
||||
local Vector3 = wea_c.Vector3
|
||||
|
||||
--- Generates a maze.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local wea_c = worldeditadditions_commands
|
||||
local wea_c = worldeditadditions_core
|
||||
local Vector3 = wea_c.Vector3
|
||||
|
||||
-- ███ ██ ██████ ██ ███████ ███████ █████ ██████ ██████ ██ ██ ██ ██████ ██████
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local wea_c = worldeditadditions_commands
|
||||
local wea_c = worldeditadditions_core
|
||||
local Vector3 = wea_c.Vector3
|
||||
|
||||
--- Overlap command. Places a specified node on top of each column.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local wea_c = worldeditadditions_commands
|
||||
local wea_c = worldeditadditions_core
|
||||
local Vector3 = wea_c.Vector3
|
||||
|
||||
--- Like //mix, but replaces a given node instead.
|
||||
|
|
|
@ -17,16 +17,16 @@ function selection.add_point(name, pos)
|
|||
if pos ~= nil then
|
||||
local created_new = not worldedit.pos1[name] or not worldedit.pos2[name]
|
||||
-- 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.pos2[name] then worldedit.pos2[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.clone(pos) end
|
||||
|
||||
worldedit.marker_update(name)
|
||||
|
||||
local volume_before = worldedit.volume(worldedit.pos1[name], worldedit.pos2[name])
|
||||
|
||||
worldedit.pos1[name], worldedit.pos2[name] = Vector3.expand_region(
|
||||
Vector3.new(worldedit.pos1[name]),
|
||||
Vector3.new(worldedit.pos2[name]),
|
||||
Vector3.clone(worldedit.pos1[name]),
|
||||
Vector3.clone(worldedit.pos2[name]),
|
||||
pos
|
||||
)
|
||||
|
||||
|
|
|
@ -100,7 +100,7 @@ end
|
|||
--
|
||||
-- @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.
|
||||
function worldeditadditions.parse.tokenise_commands(command_str)
|
||||
function worldeditadditions_core.parse.tokenise_commands(command_str)
|
||||
local success, result = tokenise(command_str)
|
||||
if not success then return success, result end
|
||||
return true, recombine(result)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
local wea_c = worldeditadditions_core
|
||||
local Vector3 = wea_c.Vector3
|
||||
--- Raycasts to find a node in the direction the given player is looking.
|
||||
-- @param player Player The player object to raycast from.
|
||||
-- @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)
|
||||
if maxdist == nil then maxdist = 100 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 cur_pos = {}
|
||||
local player_pos = player:getpos()
|
||||
local cur_pos
|
||||
local player_pos = player:get_pos()
|
||||
player_pos.y = player_pos.y + 1.5 -- Calculate from the eye position
|
||||
|
||||
local divisor = 5
|
||||
for i = 1, maxdist do
|
||||
local j = i / divisor
|
||||
|
||||
cur_pos.x = (look_dir.x*j) + player_pos.x
|
||||
cur_pos.y = (look_dir.y*j) + player_pos.y
|
||||
cur_pos.z = (look_dir.z*j) + player_pos.z
|
||||
|
||||
|
||||
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)
|
||||
}
|
||||
cur_pos = (look_dir * j) + player_pos
|
||||
|
||||
local node_pos = cur_pos:round()
|
||||
|
||||
-- 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))
|
||||
|
@ -39,7 +33,7 @@ function wea_c.raycast(player, maxdist, skip_liquid)
|
|||
local node = minetest.get_node_or_nil(node_pos)
|
||||
if node ~= nil then
|
||||
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
|
||||
if node_id == node_id_ignore then
|
||||
|
@ -50,7 +44,7 @@ function wea_c.raycast(player, maxdist, skip_liquid)
|
|||
if skip_liquid == false then
|
||||
return node_pos, node_id
|
||||
else
|
||||
local is_liquid = worldeditadditions.is_liquidlike(node_id)
|
||||
local is_liquid = wea_c.is_liquidlike(node_id)
|
||||
if is_liquid == false then
|
||||
return node_pos, node_id
|
||||
end
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
worldeditadditions.vector = {}
|
||||
worldeditadditions_core.vector = {}
|
||||
|
||||
-- @deprecated Use Vector3 instead.
|
||||
function worldeditadditions.vector.tostring(v)
|
||||
if not v then return "(nil)" end
|
||||
return "(" .. v.x ..", " .. v.y ..", " .. v.z ..")"
|
||||
end
|
||||
-- -- @deprecated Use Vector3 instead.
|
||||
-- function worldeditadditions_core.vector.tostring(v)
|
||||
-- if not v then return "(nil)" end
|
||||
-- return "(" .. v.x ..", " .. v.y ..", " .. v.z ..")"
|
||||
-- end
|
||||
|
||||
--- Calculates the length squared of the given vector.
|
||||
-- @deprecated Use Vector3 instead.
|
||||
-- @param v Vector The vector to operate on
|
||||
-- @return number The length of the given vector squared
|
||||
function worldeditadditions.vector.lengthsquared(v)
|
||||
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
|
||||
end
|
||||
-- --- Calculates the length squared of the given vector.
|
||||
-- -- @deprecated Use Vector3 instead.
|
||||
-- -- @param v Vector The vector to operate on
|
||||
-- -- @return number The length of the given vector squared
|
||||
-- function worldeditadditions_core.vector.lengthsquared(v)
|
||||
-- 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
|
||||
-- end
|
||||
|
||||
--- Normalises the given vector such that its length is 1.
|
||||
-- Also known as calculating the unit vector.
|
||||
|
@ -21,54 +21,54 @@ end
|
|||
-- @deprecated Use Vector3 instead.
|
||||
-- @param v Vector The vector to calculate from.
|
||||
-- @return Vector A new normalised vector.
|
||||
function worldeditadditions.vector.normalize(v)
|
||||
local length = math.sqrt(worldeditadditions.vector.lengthsquared(v))
|
||||
if not v.y then return {
|
||||
x = v.x / length,
|
||||
z = v.z / length
|
||||
} end
|
||||
return {
|
||||
x = v.x / length,
|
||||
y = v.y / length,
|
||||
z = v.z / length
|
||||
}
|
||||
end
|
||||
-- function worldeditadditions_core.vector.normalize(v)
|
||||
-- local length = math.sqrt(worldeditadditions_core.vector.lengthsquared(v))
|
||||
-- if not v.y then return {
|
||||
-- x = v.x / length,
|
||||
-- z = v.z / length
|
||||
-- } end
|
||||
-- return {
|
||||
-- x = v.x / length,
|
||||
-- y = v.y / length,
|
||||
-- z = v.z / length
|
||||
-- }
|
||||
-- end
|
||||
|
||||
--- Rounds the values in a vector down.
|
||||
-- Warning: This MUTATES the given vector!
|
||||
-- @deprecated Use Vector3 instead.
|
||||
-- @param v Vector The vector to operate on
|
||||
function worldeditadditions.vector.floor(v)
|
||||
if v.x then v.x = math.floor(v.x) end
|
||||
-- Some vectors are 2d, but on the x / z axes
|
||||
if v.y then v.y = math.floor(v.y) end
|
||||
-- Some vectors are 2d
|
||||
if v.z then v.z = math.floor(v.z) end
|
||||
end
|
||||
-- function worldeditadditions_core.vector.floor(v)
|
||||
-- if v.x then v.x = math.floor(v.x) end
|
||||
-- -- Some vectors are 2d, but on the x / z axes
|
||||
-- if v.y then v.y = math.floor(v.y) end
|
||||
-- -- Some vectors are 2d
|
||||
-- if v.z then v.z = math.floor(v.z) end
|
||||
-- end
|
||||
|
||||
--- Rounds the values in a vector up.
|
||||
-- Warning: This MUTATES the given vector!
|
||||
-- @deprecated Use Vector3 instead.
|
||||
-- @param v Vector The vector to operate on
|
||||
function worldeditadditions.vector.ceil(v)
|
||||
if v.x then v.x = math.ceil(v.x) end
|
||||
-- Some vectors are 2d, but on the x / z axes
|
||||
if v.y then v.y = math.ceil(v.y) end
|
||||
-- Some vectors are 2d
|
||||
if v.z then v.z = math.ceil(v.z) end
|
||||
end
|
||||
-- function worldeditadditions_core.vector.ceil(v)
|
||||
-- if v.x then v.x = math.ceil(v.x) end
|
||||
-- -- Some vectors are 2d, but on the x / z axes
|
||||
-- if v.y then v.y = math.ceil(v.y) end
|
||||
-- -- Some vectors are 2d
|
||||
-- if v.z then v.z = math.ceil(v.z) end
|
||||
-- end
|
||||
|
||||
--- Sets the values in a vector to their absolute values.
|
||||
-- Warning: This MUTATES the given vector!
|
||||
-- @deprecated Use Vector3 instead.
|
||||
-- @param v Vector The vector to operate on
|
||||
function worldeditadditions.vector.abs(v)
|
||||
if v.x then v.x = math.abs(v.x) end
|
||||
-- Some vectors are 2d, but on the x / z axes
|
||||
if v.y then v.y = math.abs(v.y) end
|
||||
-- Some vectors are 2d
|
||||
if v.z then v.z = math.abs(v.z) end
|
||||
end
|
||||
-- function worldeditadditions_core.vector.abs(v)
|
||||
-- if v.x then v.x = math.abs(v.x) end
|
||||
-- -- Some vectors are 2d, but on the x / z axes
|
||||
-- if v.y then v.y = math.abs(v.y) end
|
||||
-- -- Some vectors are 2d
|
||||
-- if v.z then v.z = math.abs(v.z) end
|
||||
-- end
|
||||
|
||||
--- Determines if the target point is contained within the defined worldedit region.
|
||||
-- @deprecated Use Vector3 instead.
|
||||
|
@ -76,41 +76,41 @@ end
|
|||
-- @param pos2 Vector pos2 of the defined region.
|
||||
-- @param target Vector The target vector to check.
|
||||
-- @return boolean Whether the given target is contained within the defined worldedit region.
|
||||
function worldeditadditions.vector.is_contained(pos1, pos2, target)
|
||||
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
||||
return pos1.x >= target.x
|
||||
and pos1.y >= target.y
|
||||
and pos1.z >= target.z
|
||||
and pos2.x <= target.x
|
||||
and pos2.y <= target.y
|
||||
and pos2.z <= target.z
|
||||
end
|
||||
-- function worldeditadditions_core.vector.is_contained(pos1, pos2, target)
|
||||
-- local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
||||
-- return pos1.x >= target.x
|
||||
-- and pos1.y >= target.y
|
||||
-- and pos1.z >= target.z
|
||||
-- and pos2.x <= target.x
|
||||
-- and pos2.y <= target.y
|
||||
-- and pos2.z <= target.z
|
||||
-- end
|
||||
|
||||
--- Expands the defined region to include the given point.
|
||||
-- @deprecated Use Vector3 instead.
|
||||
-- @param pos1 Vector pos1 of the defined region.
|
||||
-- @param pos2 Vector pos2 of the defined region.
|
||||
-- @param target Vector The target vector to include.
|
||||
function worldeditadditions.vector.expand_region(pos1, pos2, target)
|
||||
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
||||
-- function worldeditadditions_core.vector.expand_region(pos1, pos2, target)
|
||||
-- local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
||||
|
||||
if target.x < pos1.x then pos1.x = target.x 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.x < pos1.x then pos1.x = target.x 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.x > pos2.x then pos2.x = target.x 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.x > pos2.x then pos2.x = target.x end
|
||||
-- if target.y > pos2.y then pos2.y = target.y end
|
||||
-- if target.z > pos2.z then pos2.z = target.z end
|
||||
|
||||
return pos1, pos2
|
||||
end
|
||||
-- return pos1, pos2
|
||||
-- end
|
||||
|
||||
--- Returns the mean (average) of 2 positions to give you the centre.
|
||||
-- @deprecated Use Vector3 instead.
|
||||
-- @param pos1 Vector pos1 of the defined region.
|
||||
-- @param pos2 Vector pos2 of the defined region.
|
||||
-- @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)
|
||||
end
|
||||
|
||||
|
@ -119,15 +119,15 @@ end
|
|||
-- @param pos1 Vector pos1 of the defined region.
|
||||
-- @param pos2 Vector pos2 of the defined region.
|
||||
-- @return Vector Min values from input vectors.
|
||||
function worldeditadditions.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))
|
||||
end
|
||||
-- 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))
|
||||
-- end
|
||||
|
||||
--- Returns a vector of the max values of 2 positions.
|
||||
-- @deprecated Use Vector3 instead.
|
||||
-- @param pos1 Vector pos1 of the defined region.
|
||||
-- @param pos2 Vector pos2 of the defined region.
|
||||
-- @return Vector Max values from input vectors.
|
||||
function worldeditadditions.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))
|
||||
end
|
||||
-- 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))
|
||||
-- end
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
local wea_c = worldeditadditions_core
|
||||
local farwand = worldeditadditions.farwand -- Convenience shurtcut
|
||||
|
||||
local function parse_params_farwand(params_text)
|
||||
if params_text == nil then
|
||||
return false, "Can't parse nil value"
|
||||
end
|
||||
local parts = worldeditadditions.split(params_text, "%s+", false)
|
||||
local parts = wea_c.split(params_text, "%s+", false)
|
||||
|
||||
local key = nil
|
||||
local value = nil
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
local wea = worldeditadditions
|
||||
-- local wea_c = worldeditadditions_core
|
||||
|
||||
minetest.register_tool(":worldeditadditions:cloudwand", {
|
||||
description = "WorldEditAdditions far-reaching additive selectior wand",
|
||||
|
@ -16,6 +17,7 @@ minetest.register_tool(":worldeditadditions:cloudwand", {
|
|||
local name = player:get_player_name()
|
||||
-- print("[farwand] on_use", name)
|
||||
local looking_pos, node_id = worldeditadditions.farwand.do_raycast(player)
|
||||
print("DEBUG cloudwand:looking_pos", looking_pos)
|
||||
wea.selection.add_point(name, looking_pos)
|
||||
-- Left click when pointing at something or nothing
|
||||
end,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
|
||||
local wea_c = worldeditadditions_core
|
||||
--- worldeditadditions.raycast() wrapper
|
||||
function worldeditadditions.farwand.do_raycast(player)
|
||||
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 }
|
||||
end
|
||||
|
||||
local looking_pos, node_id = worldeditadditions.raycast(
|
||||
local looking_pos, node_id = wea_c.raycast(
|
||||
player,
|
||||
worldeditadditions.farwand.player_data[player_name].maxdist,
|
||||
worldeditadditions.farwand.player_data[player_name].skip_liquid
|
||||
|
|
|
@ -21,22 +21,6 @@ local function set_pos2(name, pos)
|
|||
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", {
|
||||
description = "WorldEditAdditions far-reaching wand",
|
||||
inventory_image = "worldeditadditions_farwand.png",
|
||||
|
@ -46,14 +30,14 @@ minetest.register_tool(":worldeditadditions:farwand", {
|
|||
-- print("[farwand] on_place", name)
|
||||
-- Right click when pointing at something
|
||||
-- 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)
|
||||
end,
|
||||
|
||||
on_use = function(itemstack, player, pointed_thing)
|
||||
local name = player:get_player_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)
|
||||
-- Left click when pointing at something or nothing
|
||||
end,
|
||||
|
@ -63,7 +47,7 @@ minetest.register_tool(":worldeditadditions:farwand", {
|
|||
-- Right click when pointing at nothing
|
||||
-- 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)
|
||||
end
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue