1
0
mirror of https://github.com/Uberi/Minetest-WorldEdit.git synced 2024-12-26 02:30:40 +01:00

Reimplement inset/outset to make use of new marker functions

This commit is contained in:
Daniel Sosa 2015-01-03 02:51:59 -06:00
parent 6cf8b92434
commit ae29a9f064

View File

@ -2,56 +2,48 @@ minetest.register_chatcommand(
"/outset", "/outset",
{ {
params = "<amount> [h|v]", params = "<amount> [h|v]",
description = "expand the selection", description = "outset the selection",
privs = {worldedit=true}, privs = {worldedit=true},
func = function(name, param) func = function(name, param)
local find, _, amount, dir = param:find("^(%d+)[%s+]?([hv]?)$") local find, _, amount, dir = param:find("^(%d+)[%s+]?([hv]?)$")
local message
if find == nil then if find == nil then
worldedit.player_notify(name, "invalid usage: " .. param) return false, "invalid usage: " .. param
return
end end
if worldedit.pos1[name] == nil or worldedit.pos2[name] == nil then local pos1 = worldedit.pos1[name]
message = "Undefined region. Region must be defined beforehand." local pos2 = worldedit.pos2[name]
else
amount = tonumber(amount)
local curpos1 = worldedit.pos1[name]
local curpos2 = worldedit.pos2[name]
local dirs = worldedit.get_outset_directions(curpos1, curpos2) if pos1 == nil or pos2 == nil then
return false, "Undefined region. Region must be defined beforehand."
end
local dirs = worldedit.get_outset_directions(pos1, pos2)
if dir == 'h' then if dir == 'h' then
worldedit.pos1[name].x = curpos1.x + (amount * dirs.x1) worldedit.move_marker(name, 1, 'x', amount * dirs.x1)
worldedit.pos1[name].z = curpos1.z + (amount * dirs.z1) worldedit.move_marker(name, 1, 'z', amount * dirs.z1)
worldedit.pos2[name].x = curpos2.x + (amount * dirs.x2) worldedit.move_marker(name, 2, 'x', amount * dirs.x2)
worldedit.pos2[name].z = curpos2.z + (amount * dirs.z2) worldedit.move_marker(name, 2, 'z', amount * dirs.z2)
message = "area outset by " .. amount .. " blocks horizontally"
message = "area expanded by " .. amount .. " blocks horizontally"
elseif dir == 'v' then elseif dir == 'v' then
worldedit.pos1[name].y = curpos1.y + (amount * dirs.y1) worldedit.move_marker(name, 1, 'y', amount * dirs.y1)
worldedit.pos2[name].y = curpos2.y + (amount * dirs.y2) worldedit.move_marker(name, 2, 'y', amount * dirs.y2)
message = "area outset by " .. amount .. " blocks vertically"
message = "area expanded by " .. amount .. " blocks vertically"
else else
worldedit.pos1[name].x = curpos1.x + (amount * dirs.x1) worldedit.move_marker(name, 1, 'x', amount * dirs.x1)
worldedit.pos1[name].z = curpos1.z + (amount * dirs.z1) worldedit.move_marker(name, 1, 'y', amount * dirs.y1)
worldedit.pos1[name].y = curpos1.y + (amount * dirs.y1) worldedit.move_marker(name, 1, 'z', amount * dirs.z1)
worldedit.pos2[name].x = curpos2.x + (amount * dirs.x2) worldedit.move_marker(name, 2, 'x', amount * dirs.x2)
worldedit.pos2[name].z = curpos2.z + (amount * dirs.z2) worldedit.move_marker(name, 2, 'y', amount * dirs.y2)
worldedit.pos2[name].y = curpos2.y + (amount * dirs.y2) worldedit.move_marker(name, 2, 'z', amount * dirs.z2)
message = "area outset by " .. amount .. " blocks in all axes"
message = "area expanded by " .. amount .. " blocks in all axes"
end end
worldedit.mark_pos1(name) worldedit.update_markers(name)
worldedit.mark_pos2(name) return true, message
end
worldedit.player_notify(name, message)
end, end,
} }
) )
@ -60,56 +52,49 @@ minetest.register_chatcommand(
"/inset", "/inset",
{ {
params = "<amount> [h|v]", params = "<amount> [h|v]",
description = "contract", description = "inset the selection",
privs = {worldedit=true}, privs = {worldedit=true},
func = function(name, param) func = function(name, param)
local find, _, amount, dir = param:find("^(%d+)[%s+]?([hv]?)$") local find, _, amount, dir = param:find("^(%d+)[%s+]?([hv]?)$")
local message = ""
if find == nil then if find == nil then
worldedit.player_notify(name, "invalid usage: " .. param) return false, "invalid usage: " .. param
return
end end
if worldedit.pos1[name] == nil or worldedit.pos2[name] == nil then local pos1 = worldedit.pos1[name]
message = "Undefined region. Region must be defined beforehand." local pos2 = worldedit.pos2[name]
else
amount = tonumber(amount)
local curpos1 = worldedit.pos1[name]
local curpos2 = worldedit.pos2[name]
local dirs = worldedit.get_outset_directions(curpos1, curpos2) if pos1 == nil or pos2 == nil then
return false, "Undefined region. Region must be defined beforehand."
end
local dirs = worldedit.get_outset_directions(pos1, pos2)
amount = -amount
if dir == 'h' then if dir == 'h' then
worldedit.pos1[name].x = curpos1.x - (amount * dirs.x1) worldedit.move_marker(name, 1, 'x', amount * dirs.x1)
worldedit.pos1[name].z = curpos1.z - (amount * dirs.z1) worldedit.move_marker(name, 1, 'z', amount * dirs.z1)
worldedit.pos2[name].x = curpos2.x - (amount * dirs.x2) worldedit.move_marker(name, 2, 'x', amount * dirs.x2)
worldedit.pos2[name].z = curpos2.z - (amount * dirs.z2) worldedit.move_marker(name, 2, 'z', amount * dirs.z2)
message = "area inset by " .. amount .. " blocks horizontally"
message = "area contracted by " .. amount .. " blocks horizontally"
elseif dir == 'v' then elseif dir == 'v' then
worldedit.pos1[name].y = curpos1.y - (amount * dirs.y1) worldedit.move_marker(name, 1, 'y', amount * dirs.y1)
worldedit.pos2[name].y = curpos2.y - (amount * dirs.y2) worldedit.move_marker(name, 2, 'y', amount * dirs.y2)
message = "area inset by " .. amount .. " blocks vertically"
message = "area contracted by " .. amount .. " blocks vertically"
else else
worldedit.pos1[name].x = curpos1.x - (amount * dirs.x1) worldedit.move_marker(name, 1, 'x', amount * dirs.x1)
worldedit.pos1[name].z = curpos1.z - (amount * dirs.z1) worldedit.move_marker(name, 1, 'y', amount * dirs.y1)
worldedit.pos1[name].y = curpos1.y - (amount * dirs.y1) worldedit.move_marker(name, 1, 'z', amount * dirs.z1)
worldedit.pos2[name].x = curpos2.x - (amount * dirs.x2) worldedit.move_marker(name, 2, 'x', amount * dirs.x2)
worldedit.pos2[name].z = curpos2.z - (amount * dirs.z2) worldedit.move_marker(name, 2, 'y', amount * dirs.y2)
worldedit.pos2[name].y = curpos2.y - (amount * dirs.y2) worldedit.move_marker(name, 2, 'z', amount * dirs.z2)
message = "area inset by " .. amount .. " blocks in all axes"
message = "area contracted by " .. amount .. " blocks in all axes"
end end
worldedit.mark_pos1(name) worldedit.update_markers(name)
worldedit.mark_pos2(name) return true, message
end
worldedit.player_notify(name, message)
end, end,
} }
) )
@ -389,7 +374,7 @@ worldedit.move_marker = function(name, marker, axis, amount)
elseif axis == 'z' then elseif axis == 'z' then
worldedit.pos1[name].z = pos1.z + amount worldedit.pos1[name].z = pos1.z + amount
else else
minetest.debug("worldedit: Invalid axis in move_marker. Value was: " .. axis) minetest.debug("worldedit: Invalid axis in move_marker.")
end end
elseif marker == 2 then elseif marker == 2 then
if axis == 'x' then if axis == 'x' then
@ -399,7 +384,7 @@ worldedit.move_marker = function(name, marker, axis, amount)
elseif axis == 'z' then elseif axis == 'z' then
worldedit.pos2[name].z = pos2.z + amount worldedit.pos2[name].z = pos2.z + amount
else else
minetest.debug("worldedit: Invalid axis in move_marker. Value was: " .. axis) minetest.debug("worldedit: Invalid axis in move_marker.")
end end
else else
minetest.debug("Bad marker id at worldedit.move_marker") minetest.debug("Bad marker id at worldedit.move_marker")