diff --git a/ChatCommands.md b/ChatCommands.md index 10668ce..3a91e0e 100644 --- a/ChatCommands.md +++ b/ChatCommands.md @@ -485,11 +485,13 @@ Note that this functionality requires the `worldedit_brush` mod enabled. //brush spr 12 glass //brush none -### `//cubeapply [parameters]` +### `//cubeapply /( ) [parameters]` Selects a cube with side length of `` around the WorldEdit position 1 and runs the given `` on the newly selected region. +If ``, `` and `` are given, they instead specify the length of the cuboid in X, Y, Z direction. This is mostly useful for brushes since it allows commands such as `//replace` to be ran, but it can also be used standalone. //cubeapply 10 replaceinverse air default:water_source //brush cubeapply 15 drain + //brush cubeapply 12 3 12 drain //brush cubeapply 1 deleteblocks diff --git a/worldedit_commands/cuboid.lua b/worldedit_commands/cuboid.lua index 6da3929..61e74ca 100644 --- a/worldedit_commands/cuboid.lua +++ b/worldedit_commands/cuboid.lua @@ -209,17 +209,25 @@ worldedit.register_command("contract", { }) worldedit.register_command("cubeapply", { - params = " [parameters]", + params = "/( ) [parameters]", description = "Select a cube with side length around position 1 and run on region", privs = {worldedit=true}, require_pos = 1, parse = function(param) - local found, _, side_length, cmd, args = param:find("^(%d+)%s+([^%s]+)%s*(.*)$") + local found, _, sidex, sidey, sidez, cmd, args = + param:find("^(%d+)%s+(%d+)%s+(%d+)%s+([^%s]+)%s*(.*)$") if found == nil then - return false + found, _, sidex, cmd, args = param:find("^(%d+)%s+([^%s]+)%s*(.*)$") + if found == nil then + return false + end + sidey = sidex + sidez = sidex end - side_length = tonumber(side_length) - if side_length < 1 then + sidex = tonumber(sidex) + sidey = tonumber(sidey) + sidez = tonumber(sidez) + if sidex < 1 or sidey < 1 or sidez < 1 then return false end local cmddef = worldedit.registered_commands[cmd] @@ -231,13 +239,13 @@ worldedit.register_command("cubeapply", { if not table.remove(parsed, 1) then return false, parsed[1] end - return true, side_length, cmd, parsed + return true, sidex, sidey, sidez, cmd, parsed end, - nodes_needed = function(name, side_length, cmd, parsed) + nodes_needed = function(name, sidex, sidey, sidez, cmd, parsed) -- its not possible to defer to the target command at this point - return side_length * side_length * side_length + return sidex * sidey * sidez end, - func = function(name, side_length, cmd, parsed) + func = function(name, sidex, sidey, sidez, cmd, parsed) local cmddef = assert(worldedit.registered_commands[cmd]) local success, missing_privs = minetest.check_player_privs(name, cmddef.privs) if not success then @@ -246,11 +254,12 @@ worldedit.register_command("cubeapply", { return end - -- update region to be the cube the user wanted - local sizea, sizeb = math.floor(side_length / 2), math.ceil(side_length / 2) + -- update region to be the cuboid the user wanted + local half = vector.divide(vector.new(sidex, sidey, sidez), 2) + local sizea, sizeb = vector.apply(half, math.floor), vector.apply(half, math.ceil) local center = worldedit.pos1[name] worldedit.pos1[name] = vector.subtract(center, sizea) - worldedit.pos2[name] = vector.add(center, sizeb - 1) + worldedit.pos2[name] = vector.add(center, vector.subtract(sizeb, 1)) worldedit.marker_update(name) -- actually run target command