Skip to content

Commit 1ec09a6

Browse files
me4502dordsor21
authored andcommitted
Add a -c flag to the biome brush to set entire column (#2235)
* Add a -c flag to the biome brush to set entire column * Use new region factories that take fixed positions * Rename to FixedHeight from just Fixed
1 parent 9d2a254 commit 1ec09a6

File tree

4 files changed

+115
-10
lines changed

4 files changed

+115
-10
lines changed

worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,12 @@
107107
import com.sk89q.worldedit.internal.expression.Expression;
108108
import com.sk89q.worldedit.math.BlockVector3;
109109
import com.sk89q.worldedit.math.Vector3;
110+
import com.sk89q.worldedit.regions.factory.CuboidRegionFactory;
110111
import com.sk89q.worldedit.regions.factory.CylinderRegionFactory;
112+
import com.sk89q.worldedit.regions.factory.FixedHeightCuboidRegionFactory;
113+
import com.sk89q.worldedit.regions.factory.FixedHeightCylinderRegionFactory;
111114
import com.sk89q.worldedit.regions.factory.RegionFactory;
115+
import com.sk89q.worldedit.regions.factory.SphereRegionFactory;
112116
import com.sk89q.worldedit.session.ClipboardHolder;
113117
import com.sk89q.worldedit.util.HandSide;
114118
import com.sk89q.worldedit.util.TreeGenerator;
@@ -1561,19 +1565,31 @@ public void butcherBrush(
15611565
desc = "Biome brush, sets biomes in the area"
15621566
)
15631567
@CommandPermissions("worldedit.brush.biome")
1564-
public void biome(
1565-
Player player, LocalSession localSession,
1566-
@Arg(desc = "The shape of the region")
1568+
public void biome(Player player, LocalSession localSession,
1569+
@Arg(desc = "The shape of the region")
15671570
RegionFactory shape,
1568-
@Arg(desc = "The size of the brush", def = "5")
1571+
@Arg(desc = "The size of the brush", def = "5")
15691572
double radius,
1570-
@Arg(desc = "The biome type")
1571-
BiomeType biomeType
1573+
@Arg(desc = "The biome type")
1574+
BiomeType biomeType,
1575+
@Switch(name = 'c', desc = "Whether to set the full column")
1576+
boolean column
15721577
) throws WorldEditException {
1573-
setOperationBasedBrush(
1574-
player, localSession, radius,
1575-
new ApplyRegion(new BiomeFactory(biomeType)), shape, "worldedit.brush.biome"
1576-
);
1578+
if (column) {
1579+
// Convert this shape factory to a column-based one, if possible
1580+
if (shape instanceof CylinderRegionFactory || shape instanceof SphereRegionFactory) {
1581+
// Sphere regions that are Y-expended are just cylinders
1582+
shape = new FixedHeightCylinderRegionFactory(player.getWorld().getMinY(), player.getWorld().getMaxY());
1583+
} else if (shape instanceof CuboidRegionFactory) {
1584+
shape = new FixedHeightCuboidRegionFactory(player.getWorld().getMinY(), player.getWorld().getMaxY());
1585+
} else {
1586+
player.printError(TranslatableComponent.of("worldedit.brush.biome.column-supported-types"));
1587+
return;
1588+
}
1589+
}
1590+
1591+
setOperationBasedBrush(player, localSession, radius,
1592+
new ApplyRegion(new BiomeFactory(biomeType)), shape, "worldedit.brush.biome");
15771593
player.printInfo(TranslatableComponent.of("worldedit.setbiome.warning"));
15781594
}
15791595

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* WorldEdit, a Minecraft world manipulation toolkit
3+
* Copyright (C) sk89q <http://www.sk89q.com>
4+
* Copyright (C) WorldEdit team and contributors
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
20+
package com.sk89q.worldedit.regions.factory;
21+
22+
import com.sk89q.worldedit.math.BlockVector3;
23+
import com.sk89q.worldedit.regions.CuboidRegion;
24+
import com.sk89q.worldedit.regions.Region;
25+
26+
/**
27+
* A factory for a cuboid region, with a fixed minimum and maximum Y position.
28+
*/
29+
public class FixedHeightCuboidRegionFactory implements RegionFactory {
30+
private final int minY;
31+
private final int maxY;
32+
33+
public FixedHeightCuboidRegionFactory(int minY, int maxY) {
34+
this.minY = minY;
35+
this.maxY = maxY;
36+
}
37+
38+
@Override
39+
public Region createCenteredAt(BlockVector3 position, double size) {
40+
CuboidRegion region = CuboidRegion.fromCenter(position, (int) size);
41+
region.setPos1(region.getPos1().withY(minY));
42+
region.setPos2(region.getPos2().withY(maxY));
43+
return region;
44+
}
45+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* WorldEdit, a Minecraft world manipulation toolkit
3+
* Copyright (C) sk89q <http://www.sk89q.com>
4+
* Copyright (C) WorldEdit team and contributors
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
20+
package com.sk89q.worldedit.regions.factory;
21+
22+
import com.sk89q.worldedit.math.BlockVector3;
23+
import com.sk89q.worldedit.math.Vector2;
24+
import com.sk89q.worldedit.regions.CylinderRegion;
25+
import com.sk89q.worldedit.regions.Region;
26+
27+
/**
28+
* A factory for a cylinder region, with a fixed minimum and maximum Y position.
29+
*/
30+
public class FixedHeightCylinderRegionFactory implements RegionFactory {
31+
private final int minY;
32+
private final int maxY;
33+
34+
public FixedHeightCylinderRegionFactory(int minY, int maxY) {
35+
this.minY = minY;
36+
this.maxY = maxY;
37+
}
38+
39+
@Override
40+
public Region createCenteredAt(BlockVector3 position, double size) {
41+
return new CylinderRegion(position, Vector2.at(size, size), minY, maxY);
42+
}
43+
}

worldedit-core/src/main/resources/lang/strings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@
296296
"worldedit.brush.butcher.equip": "Butcher brush equipped ({0}).",
297297
"worldedit.brush.operation.equip": "Set brush to {0}.",
298298
"worldedit.brush.morph.equip": "Morph brush shape equipped: {0}.",
299+
"worldedit.brush.biome.column-supported-types": "This brush shape is not supported with whole-column brushing, try the cylinder shape.",
299300
"worldedit.brush.none.equip": "Brush unbound from your current item.",
300301
"worldedit.brush.none.equipped": "You have no brush bound to your current item. Try /brush sphere for a basic brush.",
301302
"worldedit.setbiome.changed": "Biomes were changed in {0} columns. You may have to rejoin your game (or close and reopen your world) to see a change.",

0 commit comments

Comments
 (0)