Skip to content

Commit

Permalink
stuff I forgot to commit and the GUI changes for WorldEdit GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
blut committed Feb 18, 2025
1 parent 2c8b640 commit ed7a6c9
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 24 deletions.
11 changes: 5 additions & 6 deletions ChatCommands.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,14 +330,13 @@ Rotate the current WorldEdit positions and region along the given axis by angle
//rotate z 270
//rotate ? -90

### `//orient <angle>`
### `//orient <operation> <axis> <angle>`

Rotate oriented nodes in the current WorldEdit region around the Y axis by angle `<angle>` (90 degree increment)
Change orientation of all oriented nodes in the current WorldEdit region performing <operation> (rotate or flip) around the <axis> axis by angle <angle> (90 degree increment, unused for flip operation).

//orient 90
//orient 180
//orient 270
//orient -90
//orient rotate x 90
//orient rotate y -90
//orient flip x 0

### `//fixlight`

Expand Down
4 changes: 2 additions & 2 deletions WorldEdit API.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ Rotates a region defined by the positions `pos1` and `pos2` by `angle` degrees c

Returns the number of nodes rotated, the new position 1, and the new position 2.

### count = worldedit.orient(pos1, pos2, angle)
### count = worldedit.orient(pos1, pos2, operation, axis, angle)

Rotates all oriented nodes in a region defined by the positions `pos1` and `pos2` by `angle` degrees clockwise (90 degree increment) around the Y axis.
Change orientation of all oriented nodes in a region defined by the positions `pos1` and `pos2` performing `operation` (rotate or flip) around the `axis` axis by angle `angle` (90 degree increment, unused for flip operation).

Returns the number of nodes oriented.

Expand Down
27 changes: 15 additions & 12 deletions worldedit_commands/transform.lua
Original file line number Diff line number Diff line change
Expand Up @@ -244,25 +244,28 @@ worldedit.register_command("rotate", {
})

worldedit.register_command("orient", {
params = "<angle>",
description = S("Rotate oriented nodes in the current WorldEdit region around the Y axis by angle <angle> (90 degree increment)"),
params = "<operation> x/y/z/? [<angle>]",
description = S("Change orientation of all oriented nodes in the current WorldEdit region performing <operation> (rotate or flip) around the <axis> axis by angle <angle> (90 degree increment, unused for flip operation)"),
category = S("Transformations"),
privs = {worldedit=true},
require_pos = 2,
parse = function(param)
local found, _, angle = param:find("^([+-]?%d+)$")
if found == nil then
return false
end
angle = tonumber(angle)
if angle % 90 ~= 0 then
return false, S("invalid usage: angle must be multiple of 90")
local operation, axis, angle = unpack(param:split(" "))
--~ return true, operation, axis, angle
if (operation == 'flip' or operation == 'rotate') and (axis == 'x' or axis == 'y' or axis == 'z' or axis == '?') then
if operation == 'rotate' then
angle = tonumber(angle) or 90
if angle % 90 ~= 0 then
return false, S("invalid usage: angle must be multiple of 90")
end
end
return true, operation, axis, angle
end
return true, angle
end,
nodes_needed = check_region,
func = function(name, angle)
local count = worldedit.orient(worldedit.pos1[name], worldedit.pos2[name], angle)
func = function(name, operation, axis, angle)
if axis == "?" then axis = worldedit.player_axis(name) end
local count = worldedit.orient(worldedit.pos1[name], worldedit.pos2[name], operation, axis, angle)
return true, S("@1 nodes oriented", count)
end,
})
Expand Down
21 changes: 17 additions & 4 deletions worldedit_gui/functionality.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ local gui_count1 = {} --mapping of player names to a quantity (arbitrary strings
local gui_count2 = {} --mapping of player names to a quantity (arbitrary strings may also appear as values)
local gui_count3 = {} --mapping of player names to a quantity (arbitrary strings may also appear as values)
local gui_angle = {} --mapping of player names to an angle (one of 90, 180, 270, representing the angle in degrees clockwise)
local gui_operation = {} -- mapping of player names to operations (flip or rotate, see orient command)
local gui_filename = {} --mapping of player names to file names
local gui_param2 = {} --mapping of player names to param2 values

Expand All @@ -25,6 +26,7 @@ setmetatable(gui_count1, {__index = function() return "3" end})
setmetatable(gui_count2, {__index = function() return "6" end})
setmetatable(gui_count3, {__index = function() return "4" end})
setmetatable(gui_angle, {__index = function() return 90 end})
setmetatable(gui_operation, {__index = function() return 1 end})
setmetatable(gui_filename, {__index = function() return "building" end})
setmetatable(gui_param2, {__index = function() return "0" end})

Expand All @@ -38,6 +40,11 @@ local angle_values = {90, 180, 270}
setmetatable(angle_indices, {__index = function () return 1 end})
setmetatable(angle_values, {__index = function () return 90 end})

local operation_indices = {["Rotate"]=1, ["Flip"]=2}
local operation_values = {"rotate", "flip"}
setmetatable(operation_indices, {__index = function () return 1 end})
setmetatable(operation_values, {__index = function () return "rotate" end})

-- given multiple sets of privileges, produces a single set of privs that would have the same effect as requiring all of them at the same time
local combine_privs = function(...)
local result = {}
Expand Down Expand Up @@ -85,6 +92,8 @@ local function copy_changes(name, fields, def)
into[name] = axis_indices[value]
elseif into == gui_angle then
into[name] = angle_indices[value]
elseif into == gui_operation then
into[name] = operation_indices[value]
else
into[name] = value
end
Expand Down Expand Up @@ -703,15 +712,19 @@ worldedit.register_gui_function("worldedit_gui_orient", {
name = "Orient",
privs = we_privs("orient"),
get_formspec = function(name)
local angle = gui_angle[name]
return "size[5,3]" .. worldedit.get_formspec_header("worldedit_gui_orient") ..
string.format("dropdown[0,1;2.5;worldedit_gui_orient_angle;90 degrees,180 degrees,270 degrees;%s]", angle) ..
local operation, axis, angle = gui_operation[name], gui_axis1[name], gui_angle[name]
return "size[8.5,3]" .. worldedit.get_formspec_header("worldedit_gui_orient") ..
string.format("dropdown[0,1;2.5;worldedit_gui_orient_operation;Rotate,Flip;%d]", operation) ..
string.format("dropdown[3,1;2.5;worldedit_gui_orient_axis;X axis,Y axis,Z axis,Look direction;%d]", axis) ..
string.format("dropdown[6,1;2.5;worldedit_gui_orient_angle;90 degrees,180 degrees,270 degrees;%s]", angle) ..
"button_exit[0,2.5;3,0.8;worldedit_gui_orient_submit;Orient]"
end,
})

worldedit.register_gui_handler("worldedit_gui_orient", function(name, fields)
local cg = {
worldedit_gui_orient_operation = gui_operation,
worldedit_gui_orient_axis = gui_axis1,
worldedit_gui_orient_angle = gui_angle,
}
local ret = handle_changes(name, "worldedit_gui_orient", fields, cg)
Expand All @@ -720,7 +733,7 @@ worldedit.register_gui_handler("worldedit_gui_orient", function(name, fields)
worldedit.show_page(name, "worldedit_gui_orient")

execute_worldedit_command("orient", name,
tostring(angle_values[gui_angle[name]]))
string.format("%s %s %s", operation_values[gui_operation[name]], axis_values[gui_axis1[name]], angle_values[gui_angle[name]]))
return true
end
return ret
Expand Down

0 comments on commit ed7a6c9

Please sign in to comment.