From 856aaa62670b4cd2f2cc2fbb721bee16e4a49098 Mon Sep 17 00:00:00 2001 From: Maddy Miller Date: Sun, 21 May 2023 22:12:41 +1000 Subject: [PATCH] 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 --- .../worldedit/command/BrushCommands.java | 21 ++++++++- .../FixedHeightCuboidRegionFactory.java | 45 +++++++++++++++++++ .../FixedHeightCylinderRegionFactory.java | 43 ++++++++++++++++++ .../src/main/resources/lang/strings.json | 1 + 4 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/regions/factory/FixedHeightCuboidRegionFactory.java create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/regions/factory/FixedHeightCylinderRegionFactory.java diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java index 38bbd93eb..c5a61810c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java @@ -63,8 +63,12 @@ import com.sk89q.worldedit.internal.annotation.ClipboardMask; import com.sk89q.worldedit.internal.annotation.VertHeight; import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.regions.factory.CuboidRegionFactory; import com.sk89q.worldedit.regions.factory.CylinderRegionFactory; +import com.sk89q.worldedit.regions.factory.FixedHeightCuboidRegionFactory; +import com.sk89q.worldedit.regions.factory.FixedHeightCylinderRegionFactory; import com.sk89q.worldedit.regions.factory.RegionFactory; +import com.sk89q.worldedit.regions.factory.SphereRegionFactory; import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.session.request.RequestExtent; import com.sk89q.worldedit.util.HandSide; @@ -626,7 +630,22 @@ public void biome(Player player, LocalSession localSession, @Arg(desc = "The size of the brush", def = "5") double radius, @Arg(desc = "The biome type") - BiomeType biomeType) throws WorldEditException { + BiomeType biomeType, + @Switch(name = 'c', desc = "Whether to set the full column") + boolean column) throws WorldEditException { + + if (column) { + // Convert this shape factory to a column-based one, if possible + if (shape instanceof CylinderRegionFactory || shape instanceof SphereRegionFactory) { + // Sphere regions that are Y-expended are just cylinders + shape = new FixedHeightCylinderRegionFactory(player.getWorld().getMinY(), player.getWorld().getMaxY()); + } else if (shape instanceof CuboidRegionFactory) { + shape = new FixedHeightCuboidRegionFactory(player.getWorld().getMinY(), player.getWorld().getMaxY()); + } else { + player.printError(TranslatableComponent.of("worldedit.brush.biome.column-supported-types")); + return; + } + } setOperationBasedBrush(player, localSession, radius, new ApplyRegion(new BiomeFactory(biomeType)), shape, "worldedit.brush.biome"); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/factory/FixedHeightCuboidRegionFactory.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/factory/FixedHeightCuboidRegionFactory.java new file mode 100644 index 000000000..362d0e980 --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/factory/FixedHeightCuboidRegionFactory.java @@ -0,0 +1,45 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldedit.regions.factory; + +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.regions.CuboidRegion; +import com.sk89q.worldedit.regions.Region; + +/** + * A factory for a cuboid region, with a fixed minimum and maximum Y position. + */ +public class FixedHeightCuboidRegionFactory implements RegionFactory { + private final int minY; + private final int maxY; + + public FixedHeightCuboidRegionFactory(int minY, int maxY) { + this.minY = minY; + this.maxY = maxY; + } + + @Override + public Region createCenteredAt(BlockVector3 position, double size) { + CuboidRegion region = CuboidRegion.fromCenter(position, (int) size); + region.setPos1(region.getPos1().withY(minY)); + region.setPos2(region.getPos2().withY(maxY)); + return region; + } +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/factory/FixedHeightCylinderRegionFactory.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/factory/FixedHeightCylinderRegionFactory.java new file mode 100644 index 000000000..2fed6f1d3 --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/factory/FixedHeightCylinderRegionFactory.java @@ -0,0 +1,43 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldedit.regions.factory; + +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector2; +import com.sk89q.worldedit.regions.CylinderRegion; +import com.sk89q.worldedit.regions.Region; + +/** + * A factory for a cylinder region, with a fixed minimum and maximum Y position. + */ +public class FixedHeightCylinderRegionFactory implements RegionFactory { + private final int minY; + private final int maxY; + + public FixedHeightCylinderRegionFactory(int minY, int maxY) { + this.minY = minY; + this.maxY = maxY; + } + + @Override + public Region createCenteredAt(BlockVector3 position, double size) { + return new CylinderRegion(position, Vector2.at(size, size), minY, maxY); + } +} diff --git a/worldedit-core/src/main/resources/lang/strings.json b/worldedit-core/src/main/resources/lang/strings.json index b6c4ed18b..e9317d0b8 100644 --- a/worldedit-core/src/main/resources/lang/strings.json +++ b/worldedit-core/src/main/resources/lang/strings.json @@ -38,6 +38,7 @@ "worldedit.brush.heightmap.equip": "Heightmap brush equipped ({0}).", "worldedit.brush.heightmap.unknown": "Unknown heightmap brush: {0}.", "worldedit.brush.morph.equip": "Morph brush shape equipped: {0}.", + "worldedit.brush.biome.column-supported-types": "This brush shape is not supported with whole-column brushing, try the cylinder shape.", "worldedit.brush.none.equip": "Brush unbound from your current item.", "worldedit.brush.none.equipped": "You have no brush bound to your current item. Try /brush sphere for a basic brush.",