]> git.lizzy.rs Git - worldedit.git/commitdiff
Implement //cubeapply with three side lengths
authorsfan5 <sfan5@live.de>
Sun, 26 Apr 2020 14:01:07 +0000 (16:01 +0200)
committersfan5 <sfan5@live.de>
Sun, 26 Apr 2020 14:01:07 +0000 (16:01 +0200)
ChatCommands.md
worldedit_commands/cuboid.lua

index 10668ce27b0e83d0161b850bdfd2146b58f5876a..3a91e0e454c364f05270e445d8a57eba37ca6c35 100644 (file)
@@ -485,11 +485,13 @@ Note that this functionality requires the `worldedit_brush` mod enabled.
                //brush spr 12 glass\r
                //brush none\r
 \r
-### `//cubeapply <size> <command> [parameters]`\r
+### `//cubeapply <size>/(<sizex> <sizey> <sizez>) <command> [parameters]`\r
 \r
 Selects a cube with side length of `<size>` around the WorldEdit position 1 and runs the given `<command>` on the newly selected region.\r
+If `<sizex>`, `<sizey>` and `<sizez>` are given, they instead specify the length of the cuboid in X, Y, Z direction.\r
 This is mostly useful for brushes since it allows commands such as `//replace` to be ran, but it can also be used standalone.\r
 \r
                //cubeapply 10 replaceinverse air default:water_source\r
                //brush cubeapply 15 drain\r
+               //brush cubeapply 12 3 12 drain\r
                //brush cubeapply 1 deleteblocks\r
index 6da392919eea9d23ec96985405a297e2591dca4e..61e74ca4c35e776e4b0eaf447dfd532e97993805 100644 (file)
@@ -209,17 +209,25 @@ worldedit.register_command("contract", {
 })
 
 worldedit.register_command("cubeapply", {
-       params = "<size> <command> [parameters]",
+       params = "<size>/(<sizex> <sizey> <sizez>) <command> [parameters]",
        description = "Select a cube with side length <size> around position 1 and run <command> 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