mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-21 23:13:00 +00:00
start working on converting everything to the new utils location
after we've done this, we'll rename utils → lib
This commit is contained in:
parent
6f3118036d
commit
e167fb1536
15 changed files with 156 additions and 195 deletions
8
.vscode/settings.json
vendored
Normal file
8
.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"Lua.diagnostics.disable": [
|
||||
"trailing-space",
|
||||
"undefined-global",
|
||||
"lowercase-global",
|
||||
"cast-local-type"
|
||||
]
|
||||
}
|
|
@ -21,7 +21,7 @@ local worldmt_settings = Settings(minetest.get_worldpath().."/world.mt")
|
|||
local should_override = worldmt_settings:get_bool("worldeditadditions_override_commands", false)
|
||||
if should_override then
|
||||
minetest.log("info", "[WorldEditAdditions] Enabling override aliases")
|
||||
worldeditadditions_core.register_alias("copy", "copy+", true)
|
||||
worldeditadditions_core.register_alias("move", "move+", true)
|
||||
worldeditadditions_core.register_alias("replace", "replacemix", true)
|
||||
wea_c.register_alias("copy", "copy+", true)
|
||||
wea_c.register_alias("move", "move+", true)
|
||||
wea_c.register_alias("replace", "replacemix", true)
|
||||
end
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
local wea_c = worldeditadditions_core
|
||||
local wea = worldeditadditions
|
||||
local Vector3 = wea_c.Vector3
|
||||
|
||||
-- ██████ ██ ██ ███████ ██████ ██ █████ ██ ██
|
||||
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
||||
-- ██ ██ ██ ██ █████ ██████ ██ ███████ ████
|
||||
|
@ -9,8 +13,8 @@ worldeditadditions_core.register_command("overlay", {
|
|||
privs = { worldedit = true },
|
||||
require_pos = 2,
|
||||
parse = function(params_text)
|
||||
local success, node_list = worldeditadditions.parse.weighted_nodes(
|
||||
worldeditadditions.split_shell(params_text)
|
||||
local success, node_list = wea_c.parse.weighted_nodes(
|
||||
wea_c.split_shell(params_text)
|
||||
)
|
||||
return success, node_list
|
||||
end,
|
||||
|
@ -20,11 +24,16 @@ worldeditadditions_core.register_command("overlay", {
|
|||
return (pos2.x - pos1.x) * (pos2.y - pos1.y)
|
||||
end,
|
||||
func = function(name, node_list)
|
||||
local start_time = worldeditadditions.get_ms_time()
|
||||
local changes = worldeditadditions.overlay(worldedit.pos1[name], worldedit.pos2[name], node_list)
|
||||
local time_taken = worldeditadditions.get_ms_time() - start_time
|
||||
local start_time = wea_c.get_ms_time()
|
||||
local pos1, pos2 = Vector3.sort(worldedit.pos1[name], worldedit.pos2[name])
|
||||
|
||||
minetest.log("action", name .. " used //overlay at " .. worldeditadditions.vector.tostring(worldedit.pos1[name]) .. ", replacing " .. changes.updated .. " nodes and skipping " .. changes.skipped_columns .. " columns in " .. time_taken .. "s")
|
||||
return true, changes.updated .. " nodes replaced and " .. changes.skipped_columns .. " columns skipped in " .. worldeditadditions.format.human_time(time_taken)
|
||||
local changes = wea.overlay(
|
||||
pos1, pos2,
|
||||
node_list
|
||||
)
|
||||
local time_taken = wea_c.get_ms_time() - start_time
|
||||
|
||||
minetest.log("action", name .. " used //overlay at " .. pos1 .. " - "..pos2..", replacing " .. changes.updated .. " nodes and skipping " .. changes.skipped_columns .. " columns in " .. time_taken .. "s")
|
||||
return true, changes.updated .. " nodes replaced and " .. changes.skipped_columns .. " columns skipped in " .. wea_c.format.human_time(time_taken)
|
||||
end
|
||||
})
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
local wea = worldeditadditions
|
||||
local wea_c = worldeditadditions_core
|
||||
local Vector3 = wea_c.Vector3
|
||||
|
||||
-- ██████ ███████ ██████ ██ █████ ██████ ███████ ███ ███ ██ ██ ██
|
||||
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ████ ██ ██ ██
|
||||
-- ██████ █████ ██████ ██ ███████ ██ █████ ██ ████ ██ ██ ███
|
||||
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
||||
-- ██ ██ ███████ ██ ███████ ██ ██ ██████ ███████ ██ ██ ██ ██ ██
|
||||
worldeditadditions_core.register_command("replacemix", {
|
||||
wea_c.register_command("replacemix", {
|
||||
params = "<target_node> [<chance>] <replace_node_a> [<chance_a>] [<replace_node_b> [<chance_b>]] [<replace_node_N> [<chance_N>]] ...",
|
||||
description = "Replaces target_node with a mix of other nodes. Functions simmilarly to //mix. <chance> is optional and the chance to replace the target node at all. replace_node_a is the node to replace target_node with. If multiple nodes are specified in a space separated list, then when replacing an instance of target_node one is randomly chosen from the list. Just like with //mix, if a positive integer is present after a replace_node, that adds a weighting to that particular node making it more common.",
|
||||
privs = { worldedit = true },
|
||||
|
@ -15,7 +17,7 @@ worldeditadditions_core.register_command("replacemix", {
|
|||
return false, "Error: No arguments specified"
|
||||
end
|
||||
|
||||
local parts = wea.split_shell(params_text)
|
||||
local parts = wea_c.split_shell(params_text)
|
||||
|
||||
local target_node = nil
|
||||
local target_node_chance = 1
|
||||
|
@ -30,16 +32,16 @@ worldeditadditions_core.register_command("replacemix", {
|
|||
return false, "Error: Invalid target_node name"
|
||||
end
|
||||
mode = "target_chance"
|
||||
elseif mode == "target_chance" and wea.parse.chance(part) then
|
||||
target_node_chance = wea.parse.chance(part)
|
||||
elseif mode == "target_chance" and wea_c.parse.chance(part) then
|
||||
target_node_chance = wea_c.parse.chance(part)
|
||||
mode = "replace_node"
|
||||
elseif (mode == "target_chance" and not wea.parse.chance(part, "weight")) or mode == "replace_node" then
|
||||
elseif (mode == "target_chance" and not wea_c.parse.chance(part, "weight")) or mode == "replace_node" then
|
||||
mode = "replace_node"
|
||||
if wea.parse.chance(part, "weight") then
|
||||
if wea_c.parse.chance(part, "weight") then
|
||||
if not last_node_name then
|
||||
return false, "Error: No previous node name was found (this is a probably a bug)."
|
||||
end
|
||||
replace_nodes[last_node_name] = math.floor(wea.parse.chance(part, "weight"))
|
||||
replace_nodes[last_node_name] = math.floor(wea_c.parse.chance(part, "weight"))
|
||||
else
|
||||
if last_node_name and not replace_nodes[last_node_name] then
|
||||
replace_nodes[last_node_name] = 1
|
||||
|
@ -67,9 +69,10 @@ worldeditadditions_core.register_command("replacemix", {
|
|||
return worldedit.volume(worldedit.pos1[name], worldedit.pos2[name])
|
||||
end,
|
||||
func = function(name, target_node, target_node_chance, replace_nodes)
|
||||
local start_time = worldeditadditions.get_ms_time()
|
||||
local start_time = wea_c.get_ms_time()
|
||||
local pos1, pos2 = Vector3.sort(worldedit.pos1[name], worldedit.pos2[name])
|
||||
|
||||
local success, changed, candidates, distribution = worldeditadditions.replacemix(
|
||||
local success, changed, candidates, distribution = wea.replacemix(
|
||||
worldedit.pos1[name], worldedit.pos2[name],
|
||||
target_node,
|
||||
target_node_chance,
|
||||
|
@ -79,19 +82,19 @@ worldeditadditions_core.register_command("replacemix", {
|
|||
return success, changed
|
||||
end
|
||||
|
||||
local nodes_total = worldedit.volume(worldedit.pos1[name], worldedit.pos2[name])
|
||||
local percentage_replaced = worldeditadditions.round((changed / candidates)*100, 2)
|
||||
local distribution_table = worldeditadditions.format.node_distribution(
|
||||
local nodes_total = worldedit.volume(pos1, pos2)
|
||||
local percentage_replaced = wea_c.round((changed / candidates)*100, 2)
|
||||
local distribution_table = wea_c.format.node_distribution(
|
||||
distribution,
|
||||
changed,
|
||||
true -- Add a grand total to the bottom
|
||||
)
|
||||
|
||||
local time_taken = worldeditadditions.get_ms_time() - start_time
|
||||
local time_taken = wea_c.get_ms_time() - start_time
|
||||
|
||||
|
||||
minetest.log("action", name .. " used //replacemix at "..worldeditadditions.vector.tostring(worldedit.pos1[name]).." - "..worldeditadditions.vector.tostring(worldedit.pos2[name])..", replacing " .. changed.." nodes (out of "..nodes_total.." nodes) in "..time_taken.."s")
|
||||
minetest.log("action", name .. " used //replacemix at "..pos1.." - "..pos2..", replacing " .. changed.." nodes (out of "..nodes_total.." nodes) in "..time_taken.."s")
|
||||
|
||||
return true, distribution_table..changed.." out of "..candidates.." (~"..percentage_replaced.."%) candidates replaced in "..worldeditadditions.format.human_time(time_taken)
|
||||
return true, distribution_table..changed.." out of "..candidates.." (~"..percentage_replaced.."%) candidates replaced in "..wea_c.format.human_time(time_taken)
|
||||
end
|
||||
})
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
local wea = worldeditadditions
|
||||
local wea_c = worldeditadditions_core
|
||||
local Vector3 = wea_c.Vector3
|
||||
|
||||
local function parse_scale_component(val)
|
||||
local result = tonumber(val)
|
||||
if result then return true, result end
|
||||
if string.find(val, "/") then
|
||||
local parts = worldeditadditions.split(val, "/", true)
|
||||
local parts = wea_c.split(val, "/", true)
|
||||
local a = tonumber(parts[1])
|
||||
local b = tonumber(parts[2])
|
||||
if not b then return false, "Invalid number after the forward slash in scale component." end
|
||||
|
@ -22,7 +26,7 @@ end
|
|||
-- ███████ ██ ███████ ██ █████
|
||||
-- ██ ██ ██ ██ ██ ██
|
||||
-- ███████ ██████ ██ ██ ███████ ███████
|
||||
worldeditadditions_core.register_command("scale", {
|
||||
wea_c.register_command("scale", {
|
||||
params = "<axis> <scale_factor> | <factor_x> [<factor_y> <factor_z> [<anchor_x> <anchor_y> <anchor_z>]]",
|
||||
description = "Combined scale up / down. Takes either an axis name + a scale factor (e.g. y 3 or -z 2; negative values swap the anchor point for the scale operation), or 3 scale factor values for x, y, and z respectively. In the latter mode, a set of anchors can also be specified, which indicate which size the scale operation should be anchored to.",
|
||||
privs = { worldedit = true },
|
||||
|
@ -30,10 +34,10 @@ worldeditadditions_core.register_command("scale", {
|
|||
parse = function(params_text)
|
||||
if not params_text then params_text = "" end
|
||||
|
||||
local parts = worldeditadditions.split_shell(params_text)
|
||||
local parts = wea_c.split_shell(params_text)
|
||||
|
||||
local scale = vector.new(1, 1, 1)
|
||||
local anchor = vector.new(1, 1, 1)
|
||||
local scale = Vector3.new(1, 1, 1)
|
||||
local anchor = Vector3.new(1, 1, 1)
|
||||
|
||||
if #parts == 2 then
|
||||
if not (parts[1] == "x" or parts[1] == "y" or parts[1] == "z"
|
||||
|
@ -48,7 +52,7 @@ worldeditadditions_core.register_command("scale", {
|
|||
axis = axis:sub(2, 2)
|
||||
anchor[axis] = -1
|
||||
end
|
||||
|
||||
-- BUG: POTENTIAL BUG HERE
|
||||
scale[axis] = factor
|
||||
elseif #parts >= 3 then
|
||||
local success, val = parse_scale_component(parts[1])
|
||||
|
@ -102,14 +106,13 @@ worldeditadditions_core.register_command("scale", {
|
|||
return volume * factor
|
||||
end,
|
||||
func = function(name, scale, anchor)
|
||||
-- print("initial scale: "..worldeditadditions.vector.tostring(scale)..", anchor: "..worldeditadditions.vector.tostring(anchor))
|
||||
|
||||
local start_time = wea_c.get_ms_time()
|
||||
|
||||
local start_time = worldeditadditions.get_ms_time()
|
||||
local pos1, pos2 = Vector3.sort(worldedit.pos1[name], worldedit.pos2[name])
|
||||
|
||||
local success, stats = worldeditadditions.scale(
|
||||
worldedit.pos1[name],
|
||||
worldedit.pos2[name],
|
||||
local success, stats = wea.scale(
|
||||
pos1, pos2,
|
||||
scale, anchor
|
||||
)
|
||||
if not success then return success, stats end
|
||||
|
@ -118,10 +121,10 @@ worldeditadditions_core.register_command("scale", {
|
|||
worldedit.pos2[name] = stats.pos2
|
||||
worldedit.marker_update(name)
|
||||
|
||||
local time_taken = worldeditadditions.get_ms_time() - start_time
|
||||
local time_taken = wea_c.get_ms_time() - start_time
|
||||
|
||||
|
||||
minetest.log("action", name.." used //scale at "..worldeditadditions.vector.tostring(worldedit.pos1[name]).." - "..worldeditadditions.vector.tostring(worldedit.pos2[name])..", updating "..stats.updated.." nodes in "..time_taken.."s")
|
||||
return true, stats.updated.." nodes updated in " .. worldeditadditions.format.human_time(time_taken)
|
||||
minetest.log("action", name.." used //scale at "..pos1.." - "..pos2..", updating "..stats.updated.." nodes in "..time_taken.."s")
|
||||
return true, stats.updated.." nodes updated in " .. wea_c.format.human_time(time_taken)
|
||||
end
|
||||
})
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
local we_c = worldeditadditions_commands
|
||||
local wea_c = worldeditadditions_core
|
||||
local wea = worldeditadditions
|
||||
local Vector3 = wea.Vector3
|
||||
local wea_cmd = worldeditadditions_commands
|
||||
local Vector3 = wea_c.Vector3
|
||||
|
||||
-- ███████ ██████ ██ ██ ██ ██████ ████████
|
||||
-- ██ ██ ██ ██ ██ ██ ██ ██
|
||||
|
@ -17,7 +18,7 @@ worldeditadditions_core.register_command("sculpt", {
|
|||
params_text = "circle_soft1"
|
||||
end
|
||||
|
||||
local parts = wea.split_shell(params_text)
|
||||
local parts = wea_c.split_shell(params_text)
|
||||
|
||||
local brush_name = "circle_soft1"
|
||||
local height = 5
|
||||
|
@ -53,25 +54,25 @@ worldeditadditions_core.register_command("sculpt", {
|
|||
-- This solution allows for brushes with negative values
|
||||
-- it also allows for brushes that 'break the rules' and have values
|
||||
-- that exceed the -1 to 1 range
|
||||
local brush_min = wea.min(brush)
|
||||
local brush_max = wea.max(brush)
|
||||
local brush_min = wea_c.min(brush)
|
||||
local brush_max = wea_c.max(brush)
|
||||
local range_nodes = (brush_max * height) - (brush_min * height)
|
||||
|
||||
return size_actual.x * size_actual.y * range_nodes
|
||||
end,
|
||||
func = function(name, brush_name, height, brush_size)
|
||||
local start_time = wea.get_ms_time()
|
||||
local start_time = wea_c.get_ms_time()
|
||||
|
||||
local pos1 = wea.Vector3.clone(worldedit.pos1[name])
|
||||
local pos1 = wea_c.Vector3.clone(worldedit.pos1[name])
|
||||
local success, stats = wea.sculpt.apply(
|
||||
pos1,
|
||||
brush_name, height, brush_size
|
||||
)
|
||||
if not success then return success, stats.added end
|
||||
|
||||
local time_taken = wea.get_ms_time() - start_time
|
||||
local time_taken = wea_c.get_ms_time() - start_time
|
||||
|
||||
minetest.log("action", name .. " used //sculpt at "..pos1..", adding " .. stats.added.." nodes and removing "..stats.removed.." nodes in "..time_taken.."s")
|
||||
return true, stats.added.." nodes added and "..stats.removed.." removed in "..wea.format.human_time(time_taken)
|
||||
return true, stats.added.." nodes added and "..stats.removed.." removed in "..wea_c.format.human_time(time_taken)
|
||||
end
|
||||
})
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
|
||||
local wea = worldeditadditions
|
||||
local Vector3 = wea.Vector3
|
||||
local wea_c = worldeditadditions_core
|
||||
local Vector3 = wea_c.Vector3
|
||||
|
||||
worldeditadditions_core.register_command("spiral2", {
|
||||
wea_c.register_command("spiral2", {
|
||||
params = "[circle|square] [<replace_node=dirt> [<interval=3> [<acceleration=0>] ] ]",
|
||||
description = "Generates a spiral that fills the defined region using the specified replace node. The spiral is either square (default) or circular in shape. The interval specifies the distance between the walls of the spiral, and the acceleration specifies how quickly this value should increase.",
|
||||
privs = { worldedit = true },
|
||||
require_pos = 2,
|
||||
parse = function(params_text)
|
||||
if not params_text then params_text = "" end
|
||||
params_text = wea.trim(params_text)
|
||||
params_text = wea_c.trim(params_text)
|
||||
if params_text == "" then return true, "square", "dirt", 3, 0 end
|
||||
|
||||
local parts = wea.split_shell(params_text)
|
||||
local parts = wea_c.split_shell(params_text)
|
||||
|
||||
local mode = "square"
|
||||
local target_node = "dirt"
|
||||
|
@ -59,30 +59,30 @@ worldeditadditions_core.register_command("spiral2", {
|
|||
return worldedit.volume(worldedit.pos1[name], worldedit.pos2[name])
|
||||
end,
|
||||
func = function(name, mode, target_node, interval, acceleration)
|
||||
local start_time = wea.get_ms_time()
|
||||
local start_time = wea_c.get_ms_time()
|
||||
|
||||
local pos1, pos2 = Vector3.sort(worldedit.pos1[name], worldedit.pos2[name])
|
||||
|
||||
local success, count
|
||||
|
||||
if mode == "circle" then
|
||||
success, count = wea.spiral_circle(
|
||||
success, count = worldeditadditions.spiral_circle(
|
||||
pos1, pos2,
|
||||
target_node,
|
||||
interval, acceleration
|
||||
)
|
||||
if not success then return success, count end
|
||||
else
|
||||
success, count = wea.spiral_square(
|
||||
success, count = worldeditadditions.spiral_square(
|
||||
pos1, pos2,
|
||||
target_node,
|
||||
interval, acceleration
|
||||
)
|
||||
if not success then return success, count end
|
||||
end
|
||||
local time_taken = wea.get_ms_time() - start_time
|
||||
local time_taken = wea_c.get_ms_time() - start_time
|
||||
|
||||
minetest.log("action", name .. " used //spiral at "..pos1.." - "..pos2..", adding " .. count .. " nodes in " .. time_taken .. "s")
|
||||
return true, count .. " nodes replaced in " .. wea.format.human_time(time_taken)
|
||||
return true, count .. " nodes replaced in " .. wea_c.format.human_time(time_taken)
|
||||
end
|
||||
})
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
local wea_c = worldeditadditions_core
|
||||
local Vector3 = wea_c.Vector3
|
||||
|
||||
|
||||
-- ████████ ██████ ██████ ██ ██ ███████
|
||||
-- ██ ██ ██ ██ ██ ██ ██ ██
|
||||
-- ██ ██ ██ ██████ ██ ██ ███████
|
||||
-- ██ ██ ██ ██ ██ ██ ██ ██
|
||||
-- ██ ██████ ██ ██ ██████ ███████
|
||||
local function parse_params_torus(params_text)
|
||||
local parts = worldeditadditions.split_shell(params_text)
|
||||
local parts = wea_c.split_shell(params_text)
|
||||
|
||||
if #parts < 1 then
|
||||
return false, "Error: No replace_node specified."
|
||||
|
@ -59,24 +63,25 @@ worldeditadditions_core.register_command("torus", {
|
|||
require_pos = 1,
|
||||
parse = function(params_text)
|
||||
local values = {parse_params_torus(params_text)}
|
||||
return worldeditadditions.table.unpack(values)
|
||||
return wea_c.table.unpack(values)
|
||||
end,
|
||||
nodes_needed = function(name, target_node, major_radius, minor_radius)
|
||||
return math.ceil(2 * math.pi*math.pi * major_radius * minor_radius*minor_radius)
|
||||
end,
|
||||
func = function(name, target_node, major_radius, minor_radius, axes, hollow)
|
||||
local start_time = worldeditadditions.get_ms_time()
|
||||
local start_time = wea_c.get_ms_time()
|
||||
local pos1 = Vector3.clone(worldedit.pos1[name])
|
||||
local replaced = worldeditadditions.torus(
|
||||
worldedit.pos1[name],
|
||||
pos1,
|
||||
major_radius, minor_radius,
|
||||
target_node,
|
||||
axes,
|
||||
hollow
|
||||
)
|
||||
local time_taken = worldeditadditions.get_ms_time() - start_time
|
||||
local time_taken = wea_c.get_ms_time() - start_time
|
||||
|
||||
minetest.log("action", name .. " used //torus at " .. worldeditadditions.vector.tostring(worldedit.pos1[name]) .. ", replacing " .. replaced .. " nodes in " .. time_taken .. "s")
|
||||
return true, replaced .. " nodes replaced in " .. worldeditadditions.format.human_time(time_taken)
|
||||
minetest.log("action", name .. " used //torus at " .. pos1 .. ", replacing " .. replaced .. " nodes in " .. time_taken .. "s")
|
||||
return true, replaced .. " nodes replaced in " .. wea_c.format.human_time(time_taken)
|
||||
end
|
||||
})
|
||||
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
local wea_c = worldeditadditions_core
|
||||
local Vector3 = wea_c.Vector3
|
||||
|
||||
-- ██ ██ █████ ██ ██ ███████
|
||||
-- ██ ██ ██ ██ ██ ██ ██
|
||||
-- ██ █ ██ ███████ ██ ██ ███████
|
||||
|
@ -10,7 +13,7 @@ worldeditadditions_core.register_command("walls", {
|
|||
require_pos = 2,
|
||||
parse = function(params_text)
|
||||
if not params_text or params_text == "" then params_text = "dirt" end
|
||||
local parts = worldeditadditions.split_shell(params_text)
|
||||
local parts = wea_c.split_shell(params_text)
|
||||
|
||||
local target_node
|
||||
local thickness = 1
|
||||
|
@ -42,14 +45,16 @@ worldeditadditions_core.register_command("walls", {
|
|||
return worldedit.volume(pos1, pos2) - worldedit.volume(pos1, pos3)
|
||||
end,
|
||||
func = function(name, target_node, thickness)
|
||||
local start_time = worldeditadditions.get_ms_time()
|
||||
local success, replaced = worldeditadditions.walls(
|
||||
worldedit.pos1[name], worldedit.pos2[name],
|
||||
local start_time = wea_c.get_ms_time()
|
||||
local pos1, pos2 = Vector3.sort(worldedit.pos1[name], worldedit.pos2[name])
|
||||
|
||||
local success, replaced = wea_c.walls(
|
||||
pos1, pos2,
|
||||
target_node, thickness
|
||||
)
|
||||
local time_taken = worldeditadditions.get_ms_time() - start_time
|
||||
local time_taken = wea_c.get_ms_time() - start_time
|
||||
|
||||
minetest.log("action", name .. " used //walls from "..worldeditadditions.vector.tostring(worldedit.pos1[name]).." to "..worldeditadditions.vector.tostring(worldedit.pos1[name])..", replacing " .. replaced .. " nodes in " .. time_taken .. "s")
|
||||
return true, replaced .. " nodes replaced in " .. worldeditadditions.format.human_time(time_taken)
|
||||
minetest.log("action", name .. " used //walls from "..pos1.." to "..pos2..", replacing " .. replaced .. " nodes in " .. time_taken .. "s")
|
||||
return true, replaced .. " nodes replaced in " .. wea_c.format.human_time(time_taken)
|
||||
end
|
||||
})
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
-- Long-form article descriptions: Chat-Command-Reference.md
|
||||
-- Short descriptions: Undecided, but maybe from the registered command definition?
|
||||
|
||||
worldeditadditions.doc = {}
|
||||
worldeditadditions.doc = {
|
||||
parse_reference = dofile(worldeditadditions_commands.modpath.."/doc/parse_reference.lua")
|
||||
}
|
||||
|
||||
dofile(worldeditadditions_commands.modpath.."/doc/parse_reference.lua")
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
local wea_c = worldeditadditions_core
|
||||
|
||||
local function get_reference()
|
||||
local lines = {}
|
||||
for line in io.lines(worldeditadditions_commands.modpath.."/Chat-Command-Reference.md") do
|
||||
for line in io.lines(wea_c.modpath.."/Chat-Command-Reference.md") do
|
||||
table.insert(lines, line)
|
||||
end
|
||||
return lines
|
||||
|
@ -13,7 +13,7 @@ local function group_by_heading(lines, max_level)
|
|||
local acc = {}
|
||||
|
||||
for i,line in ipairs(lines) do
|
||||
if worldeditadditions.str_starts(line, "#") then
|
||||
if wea_c.str_starts(line, "#") then
|
||||
local _, _, heading, headingtext = line:find("(#+)%s*(.*)")
|
||||
if #heading <= max_level then
|
||||
table.insert(groups, {
|
||||
|
@ -30,9 +30,9 @@ local function group_by_heading(lines, max_level)
|
|||
return groups
|
||||
end
|
||||
|
||||
function worldeditadditions.doc.parse_reference()
|
||||
local function parse_reference()
|
||||
local lines = get_reference()
|
||||
local headings = worldeditadditions.table.filter(
|
||||
local headings = wea_c.table.filter(
|
||||
group_by_heading(lines, 2),
|
||||
function(item, i) return item.level ~= 2 end
|
||||
)
|
||||
|
@ -41,5 +41,4 @@ function worldeditadditions.doc.parse_reference()
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
worldeditadditions.doc.parse_reference()
|
||||
return parse_reference
|
||||
|
|
|
@ -6,63 +6,57 @@
|
|||
-- @author Starbeamrainbowlabs
|
||||
|
||||
worldeditadditions_commands = {}
|
||||
local we_c = worldeditadditions_commands
|
||||
local wea_cmd = worldeditadditions_commands
|
||||
|
||||
we_c.modpath = minetest.get_modpath("worldeditadditions_commands")
|
||||
wea_cmd.modpath = minetest.get_modpath("worldeditadditions_commands")
|
||||
|
||||
dofile(we_c.modpath.."/player_notify_suppress.lua")
|
||||
dofile(wea_cmd.modpath.."/player_notify_suppress.lua")
|
||||
|
||||
|
||||
|
||||
-- We no longer need our own implementation of safe_region thanks to @sfan5's
|
||||
-- suggestion in issue #5 - yay!
|
||||
-- we_c.safe_region, we_c.check_region, we_c.reset_pending
|
||||
-- = dofile(we_c.modpath.."/safe.lua")
|
||||
|
||||
dofile(we_c.modpath.."/commands/convolve.lua")
|
||||
dofile(we_c.modpath.."/commands/ellipsoid.lua")
|
||||
dofile(we_c.modpath.."/commands/ellipsoid2.lua")
|
||||
dofile(we_c.modpath.."/commands/erode.lua")
|
||||
dofile(we_c.modpath.."/commands/fillcaves.lua")
|
||||
dofile(we_c.modpath.."/commands/floodfill.lua")
|
||||
dofile(we_c.modpath.."/commands/hollow.lua")
|
||||
dofile(we_c.modpath.."/commands/layers.lua")
|
||||
dofile(we_c.modpath.."/commands/line.lua")
|
||||
dofile(we_c.modpath.."/commands/maze.lua")
|
||||
dofile(we_c.modpath.."/commands/noise2d.lua")
|
||||
dofile(we_c.modpath.."/commands/overlay.lua")
|
||||
dofile(we_c.modpath.."/commands/replacemix.lua")
|
||||
dofile(we_c.modpath.."/commands/scale.lua")
|
||||
dofile(we_c.modpath.."/commands/torus.lua")
|
||||
dofile(we_c.modpath.."/commands/walls.lua")
|
||||
dofile(we_c.modpath.."/commands/spiral2.lua")
|
||||
dofile(we_c.modpath.."/commands/copy.lua")
|
||||
dofile(we_c.modpath.."/commands/move.lua")
|
||||
dofile(we_c.modpath.."/commands/dome.lua")
|
||||
dofile(we_c.modpath.."/commands/metaball.lua")
|
||||
dofile(we_c.modpath.."/commands/count.lua")
|
||||
dofile(we_c.modpath.."/commands/sculpt.lua")
|
||||
dofile(wea_cmd.modpath.."/commands/convolve.lua")
|
||||
dofile(wea_cmd.modpath.."/commands/ellipsoid.lua")
|
||||
dofile(wea_cmd.modpath.."/commands/ellipsoid2.lua")
|
||||
dofile(wea_cmd.modpath.."/commands/erode.lua")
|
||||
dofile(wea_cmd.modpath.."/commands/fillcaves.lua")
|
||||
dofile(wea_cmd.modpath.."/commands/floodfill.lua")
|
||||
dofile(wea_cmd.modpath.."/commands/hollow.lua")
|
||||
dofile(wea_cmd.modpath.."/commands/layers.lua")
|
||||
dofile(wea_cmd.modpath.."/commands/line.lua")
|
||||
dofile(wea_cmd.modpath.."/commands/maze.lua")
|
||||
dofile(wea_cmd.modpath.."/commands/noise2d.lua")
|
||||
dofile(wea_cmd.modpath.."/commands/overlay.lua")
|
||||
dofile(wea_cmd.modpath.."/commands/replacemix.lua")
|
||||
dofile(wea_cmd.modpath.."/commands/scale.lua")
|
||||
dofile(wea_cmd.modpath.."/commands/torus.lua")
|
||||
dofile(wea_cmd.modpath.."/commands/walls.lua")
|
||||
dofile(wea_cmd.modpath.."/commands/spiral2.lua")
|
||||
dofile(wea_cmd.modpath.."/commands/copy.lua")
|
||||
dofile(wea_cmd.modpath.."/commands/move.lua")
|
||||
dofile(wea_cmd.modpath.."/commands/dome.lua")
|
||||
dofile(wea_cmd.modpath.."/commands/metaball.lua")
|
||||
dofile(wea_cmd.modpath.."/commands/count.lua")
|
||||
dofile(wea_cmd.modpath.."/commands/sculpt.lua")
|
||||
|
||||
-- Meta Commands
|
||||
dofile(we_c.modpath.."/commands/meta/init.lua")
|
||||
dofile(wea_cmd.modpath.."/commands/meta/init.lua")
|
||||
|
||||
-- Selection Tools
|
||||
dofile(we_c.modpath.."/commands/selectors/init.lua")
|
||||
dofile(wea_cmd.modpath.."/commands/selectors/init.lua")
|
||||
|
||||
-- Measure Tools
|
||||
dofile(we_c.modpath.."/commands/measure/init.lua")
|
||||
dofile(wea_cmd.modpath.."/commands/measure/init.lua")
|
||||
|
||||
-- Wireframe
|
||||
dofile(we_c.modpath.."/commands/wireframe/init.lua")
|
||||
dofile(wea_cmd.modpath.."/commands/wireframe/init.lua")
|
||||
|
||||
dofile(we_c.modpath.."/commands/extra/saplingaliases.lua")
|
||||
dofile(we_c.modpath.."/commands/extra/basename.lua")
|
||||
dofile(we_c.modpath.."/commands/extra/sculptlist.lua")
|
||||
dofile(wea_cmd.modpath.."/commands/extra/saplingaliases.lua")
|
||||
dofile(wea_cmd.modpath.."/commands/extra/basename.lua")
|
||||
dofile(wea_cmd.modpath.."/commands/extra/sculptlist.lua")
|
||||
|
||||
-- Don't register the //bonemeal command if the bonemeal mod isn't present
|
||||
if minetest.global_exists("bonemeal") then
|
||||
dofile(we_c.modpath.."/commands/bonemeal.lua")
|
||||
dofile(we_c.modpath.."/commands/forest.lua")
|
||||
dofile(wea_cmd.modpath.."/commands/bonemeal.lua")
|
||||
dofile(wea_cmd.modpath.."/commands/forest.lua")
|
||||
else
|
||||
minetest.log("action", "[WorldEditAdditions] bonemeal mod not detected: //bonemeal and //forest commands not registered (if you see this message and you're using an alternative mod that provides bonemeal, please get in touch by opening an issue)")
|
||||
end
|
||||
|
@ -80,4 +74,4 @@ end
|
|||
-- end
|
||||
|
||||
|
||||
dofile(we_c.modpath.."/aliases.lua")
|
||||
dofile(wea_cmd.modpath.."/aliases.lua")
|
||||
|
|
|
@ -1,68 +0,0 @@
|
|||
local safe_region_callback = {}
|
||||
local safe_region_param = {}
|
||||
|
||||
worldeditadditions._override_safe_regions = false -- internal use ONLY!
|
||||
|
||||
local function check_region(name, param)
|
||||
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] --obtain positions
|
||||
if pos1 == nil or pos2 == nil then
|
||||
worldedit.player_notify(name, "no region selected")
|
||||
return nil
|
||||
end
|
||||
return worldedit.volume(pos1, pos2)
|
||||
end
|
||||
|
||||
--`callback` is a callback to run when the user confirms
|
||||
--`nodes_needed` is a function accepting `param`, `pos1`, and `pos2` to calculate the number of nodes needed
|
||||
local function safe_region(callback, nodes_needed)
|
||||
--default node volume calculation
|
||||
nodes_needed = nodes_needed or check_region
|
||||
|
||||
return function(name, param)
|
||||
--check if the operation applies to a safe number of nodes
|
||||
local count = nodes_needed(name, param)
|
||||
if count == nil then return end --invalid command
|
||||
if worldeditadditions._override_safe_regions or count < 10000 then
|
||||
return callback(name, param)
|
||||
end
|
||||
|
||||
--save callback to call later
|
||||
safe_region_callback[name], safe_region_param[name] = callback, param
|
||||
worldedit.player_notify(name, "WARNING: this operation could affect up to " .. count .. " nodes; type //yy to continue or //nn to cancel")
|
||||
end
|
||||
end
|
||||
|
||||
local function reset_pending(name)
|
||||
safe_region_callback[name], safe_region_param[name] = nil, nil
|
||||
end
|
||||
|
||||
minetest.register_chatcommand("/yy", {
|
||||
params = "",
|
||||
description = "Confirm a pending operation",
|
||||
func = function(name)
|
||||
local callback, param = safe_region_callback[name], safe_region_param[name]
|
||||
if not callback then
|
||||
worldedit.player_notify(name, "no operation pending")
|
||||
return
|
||||
end
|
||||
|
||||
reset_pending(name)
|
||||
callback(name, param)
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("/nn", {
|
||||
params = "",
|
||||
description = "Abort a pending operation",
|
||||
func = function(name)
|
||||
if not safe_region_callback[name] then
|
||||
worldedit.player_notify(name, "no operation pending")
|
||||
return
|
||||
end
|
||||
|
||||
reset_pending(name)
|
||||
end,
|
||||
})
|
||||
|
||||
|
||||
return safe_region, check_region, reset_pending
|
|
@ -6,7 +6,7 @@ local human_size = wea_c.format.human_size
|
|||
-- TODO: Reimplement worldedit.player_notify(player_name, msg_text)
|
||||
|
||||
local function run_command_stage2(player_name, func, parse_result)
|
||||
local success, result_message = func(player_name, unpack(parse_result))
|
||||
local success, result_message = func(player_name, wea_c.table.unpack(parse_result))
|
||||
if result_message then
|
||||
-- TODO: If we were unsuccessfull, then colour the message red
|
||||
worldedit.player_notify(player_name, result_message)
|
||||
|
@ -31,7 +31,7 @@ local function run_command(cmdname, options, player_name, paramtext)
|
|||
end
|
||||
|
||||
if options.nodes_needed then
|
||||
local potential_changes = options.nodes_needed(player_name, unpack(parse_result))
|
||||
local potential_changes = options.nodes_needed(player_name, wea_c.table.unpack(parse_result))
|
||||
|
||||
local limit = wea_c.safe_region_limit_default
|
||||
if wea_c.safe_region_limits[player_name] then
|
||||
|
|
|
@ -389,6 +389,7 @@ function Vector3.fromBearing(angle_x, angle_y, length)
|
|||
)
|
||||
end
|
||||
|
||||
-- TODO: Implement .volume() here
|
||||
|
||||
|
||||
-- ██████ ██████ ███████ ██████ █████ ████████ ██████ ██████
|
||||
|
|
Loading…
Reference in a new issue