Skip to content

Commit

Permalink
Add a -c flag to the biome brush to set entire column (#2235)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
me4502 authored May 21, 2023
1 parent 4fc62d9 commit 856aaa6
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* 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 <https://www.gnu.org/licenses/>.
*/

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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* 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 <https://www.gnu.org/licenses/>.
*/

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);
}
}
1 change: 1 addition & 0 deletions worldedit-core/src/main/resources/lang/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",

Expand Down

0 comments on commit 856aaa6

Please sign in to comment.