Skip to content

Commit 81b7a7e

Browse files
me4502octylFractal
authored andcommitted
Added a brush for biomes (#1491)
* Added a brush for biomes * IntelliJ reformat * Move the warning * Update worldedit-core/src/main/resources/lang/strings.json Co-authored-by: Octavia Togami <[email protected]> * Use BiomeFactory instead Co-authored-by: Octavia Togami <[email protected]>
1 parent 51c4bb5 commit 81b7a7e

File tree

3 files changed

+76
-7
lines changed

3 files changed

+76
-7
lines changed

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

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@
9393
import com.sk89q.worldedit.function.Contextual;
9494
import com.sk89q.worldedit.function.factory.Apply;
9595
import com.sk89q.worldedit.function.factory.ApplyLayer;
96+
import com.sk89q.worldedit.function.factory.ApplyRegion;
97+
import com.sk89q.worldedit.function.factory.BiomeFactory;
9698
import com.sk89q.worldedit.function.factory.Deform;
9799
import com.sk89q.worldedit.function.factory.Paint;
98100
import com.sk89q.worldedit.function.factory.Snow;
@@ -111,7 +113,9 @@
111113
import com.sk89q.worldedit.util.TreeGenerator;
112114
import com.sk89q.worldedit.util.formatting.text.Component;
113115
import com.sk89q.worldedit.util.formatting.text.TextComponent;
116+
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
114117
import com.sk89q.worldedit.util.formatting.text.event.ClickEvent;
118+
import com.sk89q.worldedit.world.biome.BiomeType;
115119
import com.sk89q.worldedit.world.block.BlockStateHolder;
116120
import com.sk89q.worldedit.world.block.BlockType;
117121
import com.sk89q.worldedit.world.block.BlockTypes;
@@ -1552,6 +1556,26 @@ public void butcherBrush(
15521556
set(context, new ButcherBrush(flags), "worldedit.brush.butcher").setSize(radius);
15531557
}
15541558

1559+
@Command(name = "biome",
1560+
desc = "Biome brush, sets biomes in the area"
1561+
)
1562+
@CommandPermissions("worldedit.brush.biome")
1563+
public void biome(
1564+
Player player, LocalSession localSession,
1565+
@Arg(desc = "The shape of the region")
1566+
RegionFactory shape,
1567+
@Arg(desc = "The size of the brush", def = "5")
1568+
double radius,
1569+
@Arg(desc = "The biome type")
1570+
BiomeType biomeType
1571+
) throws WorldEditException {
1572+
setOperationBasedBrush(
1573+
player, localSession, radius,
1574+
new ApplyRegion(new BiomeFactory(biomeType)), shape, "worldedit.brush.biome"
1575+
);
1576+
player.printInfo(TranslatableComponent.of("worldedit.setbiome.warning"));
1577+
}
1578+
15551579
//FAWE start
15561580
public BrushSettings process(Player player, Arguments arguments, BrushSettings settings)
15571581
throws WorldEditException {
@@ -1596,13 +1620,12 @@ public BrushSettings set(InjectedValueAccess context, Brush brush, String permis
15961620
}
15971621
//FAWE end
15981622

1599-
static void setOperationBasedBrush(
1600-
Player player, LocalSession session, double radius,
1601-
Contextual<? extends Operation> factory,
1602-
RegionFactory shape,
1603-
String permission
1604-
) throws WorldEditException {
1605-
WorldEdit.getInstance().checkMaxBrushRadius(radius, player);
1623+
1624+
static void setOperationBasedBrush(Player player, LocalSession session, double radius,
1625+
Contextual<? extends Operation> factory,
1626+
RegionFactory shape,
1627+
String permission) throws WorldEditException {
1628+
WorldEdit.getInstance().checkMaxBrushRadius(radius);
16061629
BrushTool tool = session.getBrushTool(player.getItemInHand(HandSide.MAIN_HAND).getType());
16071630
tool.setSize(radius);
16081631
tool.setFill(null);
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.function.factory;
21+
22+
import com.sk89q.worldedit.function.Contextual;
23+
import com.sk89q.worldedit.function.EditContext;
24+
import com.sk89q.worldedit.function.RegionFunction;
25+
import com.sk89q.worldedit.function.biome.BiomeReplace;
26+
import com.sk89q.worldedit.function.pattern.BiomePattern;
27+
28+
public class BiomeFactory implements Contextual<RegionFunction> {
29+
30+
private final BiomePattern biomeType;
31+
32+
public BiomeFactory(BiomePattern biomeType) {
33+
this.biomeType = biomeType;
34+
}
35+
36+
@Override
37+
public RegionFunction createFromContext(EditContext context) {
38+
return new BiomeReplace(context.getDestination(), this.biomeType);
39+
}
40+
41+
@Override
42+
public String toString() {
43+
return "set biome";
44+
}
45+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@
298298
"worldedit.brush.none.equip": "Brush unbound from your current item.",
299299
"worldedit.brush.none.equipped": "You have no brush bound to your current item. Try /brush sphere for a basic brush.",
300300
"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.",
301+
"worldedit.setbiome.warning": "You may have to re-join your game (or close and re-open your world) to see changes.",
301302
"worldedit.setbiome.not-locatable": "Command sender must be present in the world to use the -p flag.",
302303
"worldedit.drawsel.disabled": "Server CUI disabled.",
303304
"worldedit.drawsel.enabled": "Server CUI enabled. This only supports cuboid regions, with a maximum size of {0}x{1}x{2}.",

0 commit comments

Comments
 (0)