From 3df23e8086a4489802c535b850683257e398cf39 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Fri, 12 Mar 2021 15:47:10 -0800 Subject: [PATCH 01/10] scloud and cloud wand refactor --- worldeditadditions/init.lua | 1 + worldeditadditions/lib/selection/cloud.lua | 48 +++++++++++++++++++ .../commands/selectors/scloud.lua | 35 ++++++++++++++ worldeditadditions_commands/init.lua | 1 + worldeditadditions_farwand/lib/cloudwand.lua | 40 ++-------------- 5 files changed, 90 insertions(+), 35 deletions(-) create mode 100644 worldeditadditions/lib/selection/cloud.lua create mode 100644 worldeditadditions_commands/commands/selectors/scloud.lua diff --git a/worldeditadditions/init.lua b/worldeditadditions/init.lua index 9ed6be0..9799692 100644 --- a/worldeditadditions/init.lua +++ b/worldeditadditions/init.lua @@ -46,3 +46,4 @@ dofile(worldeditadditions.modpath.."/lib/ellipsoidapply.lua") dofile(worldeditadditions.modpath.."/lib/subdivide.lua") dofile(worldeditadditions.modpath.."/lib/selection/stack.lua") +dofile(worldeditadditions.modpath.."/lib/selection/cloud.lua") diff --git a/worldeditadditions/lib/selection/cloud.lua b/worldeditadditions/lib/selection/cloud.lua new file mode 100644 index 0000000..ce067dd --- /dev/null +++ b/worldeditadditions/lib/selection/cloud.lua @@ -0,0 +1,48 @@ +-- ██████ ██ ██████ ██ ██ ██████ +-- ██ ██ ██ ██ ██ ██ ██ ██ +-- ██ ██ ██ ██ ██ ██ ██ ██ +-- ██ ██ ██ ██ ██ ██ ██ ██ +-- ██████ ███████ ██████ ██████ ██████ +worldeditadditions.add_pos = {} +local wea = worldeditadditions +function worldeditadditions.add_point(name, pos) + if pos ~= nil then + -- print("[set_pos1]", name, "("..pos.x..", "..pos.y..", "..pos.z..")") + if not worldedit.pos1[name] then worldedit.pos1[name] = vector.new(pos) end + if not worldedit.pos2[name] then worldedit.pos2[name] = vector.new(pos) end + + worldedit.marker_update(name) + + local volume_before = worldedit.volume(worldedit.pos1[name], worldedit.pos2[name]) + + worldedit.pos1[name], worldedit.pos2[name] = worldeditadditions.vector.expand_region(worldedit.pos1[name], worldedit.pos2[name], pos) + + local volume_after = worldedit.volume(worldedit.pos1[name], worldedit.pos2[name]) + + local volume_difference = volume_after - volume_before + + worldedit.marker_update(name) + worldedit.player_notify(name, "Expanded region by "..volume_difference.." nodes") + else + worldedit.player_notify(name, "Error: Too far away (try raising your maxdist with //farwand maxdist )") + -- print("[set_pos1]", name, "nil") + end +end +function worldeditadditions.clear_points(name, pos) + worldedit.pos1[name] = nil + worldedit.pos2[name] = nil + worldedit.marker_update(name) + worldedit.set_pos[name] = nil + + worldedit.player_notify(name, "Region cleared") +end +minetest.register_on_punchnode(function(pos, node, puncher) + local name = puncher:get_player_name() + if name ~= "" and wea.add_pos[name] ~= nil then + if wea.add_pos[name] > 0 then + wea.add_point(name,pos) + wea.add_pos[name] = wea.add_pos[name] - 1 + worldedit.player_notify(name, "You have "..wea.add_pos[name].." nodes left to punch") + else wea.add_pos[name] = nil end + end +end) diff --git a/worldeditadditions_commands/commands/selectors/scloud.lua b/worldeditadditions_commands/commands/selectors/scloud.lua new file mode 100644 index 0000000..b0b93c3 --- /dev/null +++ b/worldeditadditions_commands/commands/selectors/scloud.lua @@ -0,0 +1,35 @@ +-- ███████ ██████ ██ ██████ ██ ██ ██████ +-- ██ ██ ██ ██ ██ ██ ██ ██ ██ +-- ███████ ██ ██ ██ ██ ██ ██ ██ ██ +-- ██ ██ ██ ██ ██ ██ ██ ██ ██ +-- ███████ ██████ ███████ ██████ ██████ ██████ +local wea = worldeditadditions +worldedit.register_command("scloud", { + params = "0-6/stop/reset", + description = "Set and add to WorldEdit region by punching put to six nodes that define the maximums of your target", + privs = {worldedit=true}, + parse = function(param) + return true, param + end, + func = function(name, param) + local que = tonumber(param) + if que then + if que > 0 then + wea.add_pos[name] = que < 7 and que or 6 + return true, "create or add to selection by punching "..wea.add_pos[name].." nodes" + else + wea.add_pos[name] = nil + return true, "0 nodes to punch: operation canceled" + end + elseif param == "stop" then + wea.add_pos[name] = nil + return true, "selection operation stopped" + elseif param == "reset" then + wea.add_pos[name] = nil + wea.clear_points(name) + return true, "selection cleared" + else + return false, (param == "" and "no input" or "invalid input: '"..param).."'! Allowed params are: 0-6/stop/reset" + end + end, +}) diff --git a/worldeditadditions_commands/init.lua b/worldeditadditions_commands/init.lua index d5cfb3f..c17fd9e 100644 --- a/worldeditadditions_commands/init.lua +++ b/worldeditadditions_commands/init.lua @@ -41,6 +41,7 @@ dofile(we_c.modpath.."/commands/meta/many.lua") dofile(we_c.modpath.."/commands/meta/subdivide.lua") dofile(we_c.modpath.."/commands/meta/ellipsoidapply.lua") +dofile(we_c.modpath.."/commands/selectors/scloud.lua") dofile(we_c.modpath.."/commands/selectors/scol.lua") dofile(we_c.modpath.."/commands/selectors/srect.lua") dofile(we_c.modpath.."/commands/selectors/scube.lua") diff --git a/worldeditadditions_farwand/lib/cloudwand.lua b/worldeditadditions_farwand/lib/cloudwand.lua index 06c0582..ea75c29 100644 --- a/worldeditadditions_farwand/lib/cloudwand.lua +++ b/worldeditadditions_farwand/lib/cloudwand.lua @@ -1,37 +1,7 @@ -local function add_point(name, pos) - if pos ~= nil then - -- print("[set_pos1]", name, "("..pos.x..", "..pos.y..", "..pos.z..")") - if not worldedit.pos1[name] then worldedit.pos1[name] = vector.new(pos) end - if not worldedit.pos2[name] then worldedit.pos2[name] = vector.new(pos) end - - worldedit.marker_update(name) - - local volume_before = worldedit.volume(worldedit.pos1[name], worldedit.pos2[name]) - - worldedit.pos1[name], worldedit.pos2[name] = worldeditadditions.vector.expand_region(worldedit.pos1[name], worldedit.pos2[name], pos) - - local volume_after = worldedit.volume(worldedit.pos1[name], worldedit.pos2[name]) - - local volume_difference = volume_after - volume_before - - worldedit.marker_update(name) - worldedit.player_notify(name, "Expanded region by "..volume_difference.." nodes") - else - worldedit.player_notify(name, "Error: Too far away (try raising your maxdist with //farwand maxdist )") - -- print("[set_pos1]", name, "nil") - end -end -local function clear_points(name, pos) - worldedit.pos1[name] = nil - worldedit.pos2[name] = nil - worldedit.marker_update(name) - worldedit.set_pos[name] = nil - - worldedit.player_notify(name, "Region cleared") -end +local wea = worldeditadditions minetest.register_tool(":worldeditadditions:cloudwand", { - description = "WorldEditAdditions far-reaching point cloud wand", + description = "WorldEditAdditions far-reaching point cloud selection wand", inventory_image = "worldeditadditions_cloudwand.png", on_place = function(itemstack, player, pointed_thing) @@ -39,14 +9,14 @@ minetest.register_tool(":worldeditadditions:cloudwand", { -- print("[farwand] on_place", name) -- Right click when pointing at something -- Pointed thing: https://rubenwardy.com/minetest_modding_book/lua_api.html#pointed_thing - clear_points(name) + wea.clear_points(name) end, on_use = function(itemstack, player, pointed_thing) local name = player:get_player_name() -- print("[farwand] on_use", name) local looking_pos, node_id = worldeditadditions.farwand.do_raycast(player) - add_point(name, looking_pos) + wea.add_point(name, looking_pos) -- Left click when pointing at something or nothing end, @@ -55,6 +25,6 @@ minetest.register_tool(":worldeditadditions:cloudwand", { -- Right click when pointing at nothing -- print("[farwand] on_secondary_use", name) - clear_points(name) + wea.clear_points(name) end }) From cc20297b889139d8812515070b573703d58f00fb Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Fri, 12 Mar 2021 17:03:37 -0800 Subject: [PATCH 02/10] scloud.lua typo fix Co-authored-by: Starbeamrainbowlabs --- worldeditadditions_commands/commands/selectors/scloud.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worldeditadditions_commands/commands/selectors/scloud.lua b/worldeditadditions_commands/commands/selectors/scloud.lua index b0b93c3..49bef97 100644 --- a/worldeditadditions_commands/commands/selectors/scloud.lua +++ b/worldeditadditions_commands/commands/selectors/scloud.lua @@ -6,7 +6,7 @@ local wea = worldeditadditions worldedit.register_command("scloud", { params = "0-6/stop/reset", - description = "Set and add to WorldEdit region by punching put to six nodes that define the maximums of your target", + description = "Set and add to WorldEdit region by punching up to six nodes that define the maximums of your target", privs = {worldedit=true}, parse = function(param) return true, param From 4777b93f6019b76c68f3070ffbb792b7c1ec69ee Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Fri, 12 Mar 2021 17:06:15 -0800 Subject: [PATCH 03/10] scloud.lua error return fix Co-authored-by: Starbeamrainbowlabs --- worldeditadditions_commands/commands/selectors/scloud.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worldeditadditions_commands/commands/selectors/scloud.lua b/worldeditadditions_commands/commands/selectors/scloud.lua index 49bef97..f804f8b 100644 --- a/worldeditadditions_commands/commands/selectors/scloud.lua +++ b/worldeditadditions_commands/commands/selectors/scloud.lua @@ -29,7 +29,7 @@ worldedit.register_command("scloud", { wea.clear_points(name) return true, "selection cleared" else - return false, (param == "" and "no input" or "invalid input: '"..param).."'! Allowed params are: 0-6/stop/reset" + return false, (param == "" and "no input" or "invalid input: '"..param).."'! Allowed params are: 0-6, stop, or reset" end end, }) From f95d7622c7ff4b6f4d07705581e42169174b74bb Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Fri, 12 Mar 2021 17:09:57 -0800 Subject: [PATCH 04/10] scloud.lua cosmetics Co-authored-by: Starbeamrainbowlabs --- worldeditadditions_commands/commands/selectors/scloud.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/worldeditadditions_commands/commands/selectors/scloud.lua b/worldeditadditions_commands/commands/selectors/scloud.lua index f804f8b..09db145 100644 --- a/worldeditadditions_commands/commands/selectors/scloud.lua +++ b/worldeditadditions_commands/commands/selectors/scloud.lua @@ -1,8 +1,8 @@ --- ███████ ██████ ██ ██████ ██ ██ ██████ +-- ██████ ██████ ██ ██████ ██ ██ ██████ -- ██ ██ ██ ██ ██ ██ ██ ██ ██ -- ███████ ██ ██ ██ ██ ██ ██ ██ ██ -- ██ ██ ██ ██ ██ ██ ██ ██ ██ --- ███████ ██████ ███████ ██████ ██████ ██████ +-- ██████ ██████ ███████ ██████ ██████ ██████ local wea = worldeditadditions worldedit.register_command("scloud", { params = "0-6/stop/reset", From 39f82c99caa0d88566995c859e6721496cc2cb40 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Fri, 12 Mar 2021 17:55:10 -0800 Subject: [PATCH 05/10] scloud.lua params change Co-authored-by: Starbeamrainbowlabs --- worldeditadditions_commands/commands/selectors/scloud.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worldeditadditions_commands/commands/selectors/scloud.lua b/worldeditadditions_commands/commands/selectors/scloud.lua index 09db145..4543c65 100644 --- a/worldeditadditions_commands/commands/selectors/scloud.lua +++ b/worldeditadditions_commands/commands/selectors/scloud.lua @@ -5,7 +5,7 @@ -- ██████ ██████ ███████ ██████ ██████ ██████ local wea = worldeditadditions worldedit.register_command("scloud", { - params = "0-6/stop/reset", + params = "<0-6|stop|reset>", description = "Set and add to WorldEdit region by punching up to six nodes that define the maximums of your target", privs = {worldedit=true}, parse = function(param) From f79871e5d1509461761c253393dc5d05c6854af9 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Fri, 12 Mar 2021 17:55:59 -0800 Subject: [PATCH 06/10] cloudwand.lua rename Co-authored-by: Starbeamrainbowlabs --- worldeditadditions_farwand/lib/cloudwand.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worldeditadditions_farwand/lib/cloudwand.lua b/worldeditadditions_farwand/lib/cloudwand.lua index ea75c29..8f07fdf 100644 --- a/worldeditadditions_farwand/lib/cloudwand.lua +++ b/worldeditadditions_farwand/lib/cloudwand.lua @@ -1,7 +1,7 @@ local wea = worldeditadditions minetest.register_tool(":worldeditadditions:cloudwand", { - description = "WorldEditAdditions far-reaching point cloud selection wand", + description = "WorldEditAdditions far-reaching additive selectior wand", inventory_image = "worldeditadditions_cloudwand.png", on_place = function(itemstack, player, pointed_thing) From 5ffa67b7ac55be072f337ca78ed817335100fa75 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Fri, 12 Mar 2021 18:01:17 -0800 Subject: [PATCH 07/10] refactor func names, move punchnode function --- worldeditadditions/lib/selection/cloud.lua | 14 ++------------ .../commands/selectors/scloud.lua | 12 +++++++++++- worldeditadditions_farwand/lib/cloudwand.lua | 6 +++--- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/worldeditadditions/lib/selection/cloud.lua b/worldeditadditions/lib/selection/cloud.lua index ce067dd..650d671 100644 --- a/worldeditadditions/lib/selection/cloud.lua +++ b/worldeditadditions/lib/selection/cloud.lua @@ -5,7 +5,7 @@ -- ██████ ███████ ██████ ██████ ██████ worldeditadditions.add_pos = {} local wea = worldeditadditions -function worldeditadditions.add_point(name, pos) +function worldeditadditions.selection.add_point(name, pos) if pos ~= nil then -- print("[set_pos1]", name, "("..pos.x..", "..pos.y..", "..pos.z..")") if not worldedit.pos1[name] then worldedit.pos1[name] = vector.new(pos) end @@ -28,7 +28,7 @@ function worldeditadditions.add_point(name, pos) -- print("[set_pos1]", name, "nil") end end -function worldeditadditions.clear_points(name, pos) +function worldeditadditions.selection.clear_points(name) worldedit.pos1[name] = nil worldedit.pos2[name] = nil worldedit.marker_update(name) @@ -36,13 +36,3 @@ function worldeditadditions.clear_points(name, pos) worldedit.player_notify(name, "Region cleared") end -minetest.register_on_punchnode(function(pos, node, puncher) - local name = puncher:get_player_name() - if name ~= "" and wea.add_pos[name] ~= nil then - if wea.add_pos[name] > 0 then - wea.add_point(name,pos) - wea.add_pos[name] = wea.add_pos[name] - 1 - worldedit.player_notify(name, "You have "..wea.add_pos[name].." nodes left to punch") - else wea.add_pos[name] = nil end - end -end) diff --git a/worldeditadditions_commands/commands/selectors/scloud.lua b/worldeditadditions_commands/commands/selectors/scloud.lua index 4543c65..f856863 100644 --- a/worldeditadditions_commands/commands/selectors/scloud.lua +++ b/worldeditadditions_commands/commands/selectors/scloud.lua @@ -4,6 +4,16 @@ -- ██ ██ ██ ██ ██ ██ ██ ██ ██ -- ██████ ██████ ███████ ██████ ██████ ██████ local wea = worldeditadditions +minetest.register_on_punchnode(function(pos, node, puncher) + local name = puncher:get_player_name() + if name ~= "" and wea.add_pos[name] ~= nil then + if wea.add_pos[name] > 0 then + wea.selection.add_point(name,pos) + wea.add_pos[name] = wea.add_pos[name] - 1 + worldedit.player_notify(name, "You have "..wea.add_pos[name].." nodes left to punch") + else wea.add_pos[name] = nil end + end +end) worldedit.register_command("scloud", { params = "<0-6|stop|reset>", description = "Set and add to WorldEdit region by punching up to six nodes that define the maximums of your target", @@ -26,7 +36,7 @@ worldedit.register_command("scloud", { return true, "selection operation stopped" elseif param == "reset" then wea.add_pos[name] = nil - wea.clear_points(name) + wea.selection.clear_points(name) return true, "selection cleared" else return false, (param == "" and "no input" or "invalid input: '"..param).."'! Allowed params are: 0-6, stop, or reset" diff --git a/worldeditadditions_farwand/lib/cloudwand.lua b/worldeditadditions_farwand/lib/cloudwand.lua index 8f07fdf..da53273 100644 --- a/worldeditadditions_farwand/lib/cloudwand.lua +++ b/worldeditadditions_farwand/lib/cloudwand.lua @@ -9,14 +9,14 @@ minetest.register_tool(":worldeditadditions:cloudwand", { -- print("[farwand] on_place", name) -- Right click when pointing at something -- Pointed thing: https://rubenwardy.com/minetest_modding_book/lua_api.html#pointed_thing - wea.clear_points(name) + wea.selection.clear_points(name) end, on_use = function(itemstack, player, pointed_thing) local name = player:get_player_name() -- print("[farwand] on_use", name) local looking_pos, node_id = worldeditadditions.farwand.do_raycast(player) - wea.add_point(name, looking_pos) + wea.selection.add_point(name, looking_pos) -- Left click when pointing at something or nothing end, @@ -25,6 +25,6 @@ minetest.register_tool(":worldeditadditions:cloudwand", { -- Right click when pointing at nothing -- print("[farwand] on_secondary_use", name) - wea.clear_points(name) + wea.selection.clear_points(name) end }) From c39fc1c9e8c52b0ef8b23326d123ede78590d585 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Fri, 12 Mar 2021 18:09:24 -0800 Subject: [PATCH 08/10] Removed unneeded local --- worldeditadditions/lib/selection/cloud.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/worldeditadditions/lib/selection/cloud.lua b/worldeditadditions/lib/selection/cloud.lua index 650d671..1d41fde 100644 --- a/worldeditadditions/lib/selection/cloud.lua +++ b/worldeditadditions/lib/selection/cloud.lua @@ -4,7 +4,6 @@ -- ██ ██ ██ ██ ██ ██ ██ ██ -- ██████ ███████ ██████ ██████ ██████ worldeditadditions.add_pos = {} -local wea = worldeditadditions function worldeditadditions.selection.add_point(name, pos) if pos ~= nil then -- print("[set_pos1]", name, "("..pos.x..", "..pos.y..", "..pos.z..")") From 18347f93bf1e18c50d10f958b1691f087ca7b4c0 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Fri, 12 Mar 2021 18:11:43 -0800 Subject: [PATCH 09/10] wea.selection declared --- worldeditadditions/lib/selection/cloud.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/worldeditadditions/lib/selection/cloud.lua b/worldeditadditions/lib/selection/cloud.lua index 1d41fde..35c261c 100644 --- a/worldeditadditions/lib/selection/cloud.lua +++ b/worldeditadditions/lib/selection/cloud.lua @@ -4,6 +4,7 @@ -- ██ ██ ██ ██ ██ ██ ██ ██ -- ██████ ███████ ██████ ██████ ██████ worldeditadditions.add_pos = {} +worldeditadditions.selection = {} function worldeditadditions.selection.add_point(name, pos) if pos ~= nil then -- print("[set_pos1]", name, "("..pos.x..", "..pos.y..", "..pos.z..")") From 0b55863d5568c5fd1bd2a2e4fbdd5ff18d61b9e8 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Fri, 12 Mar 2021 19:26:38 -0800 Subject: [PATCH 10/10] scloud.lua second typo fix Co-authored-by: Starbeamrainbowlabs --- worldeditadditions_commands/commands/selectors/scloud.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worldeditadditions_commands/commands/selectors/scloud.lua b/worldeditadditions_commands/commands/selectors/scloud.lua index f856863..06ed4f9 100644 --- a/worldeditadditions_commands/commands/selectors/scloud.lua +++ b/worldeditadditions_commands/commands/selectors/scloud.lua @@ -39,7 +39,7 @@ worldedit.register_command("scloud", { wea.selection.clear_points(name) return true, "selection cleared" else - return false, (param == "" and "no input" or "invalid input: '"..param).."'! Allowed params are: 0-6, stop, or reset" + return false, (param == "" and "no input" or "invalid input: '"..param.."'").."! Allowed params are: 0-6, stop, or reset" end end, })