scloud and cloud wand refactor

This commit is contained in:
VorTechnix 2021-03-12 15:47:10 -08:00
parent 97f8d551cd
commit 3df23e8086
5 changed files with 90 additions and 35 deletions

View File

@ -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")

View File

@ -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 <number>)")
-- 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)

View File

@ -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,
})

View File

@ -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")

View File

@ -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 <number>)")
-- 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
})