Skip to content

Commit c2c2c67

Browse files
committed
Add some small example for patter usage inside of the worldedit.
This example describe so far it possible the edit process and the async process to edit a region with a specific biome.
1 parent ab8d3c7 commit c2c2c67

3 files changed

Lines changed: 56 additions & 2 deletions

File tree

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Filling a region using a pattern
2+
3+
## Foreword
4+
First of all, patterns usually come from the core part of WorldEdit or FAWE. You can find all existing patterns [here](https://intellectualsites.github.io/fastasyncworldedit-javadocs/worldedit-core/com/sk89q/worldedit/function/pattern/Pattern.html)
5+
6+
## Biome Cuboid Example
7+
Given are 3 things:
8+
- Position1: X=300, y=-64, z=300
9+
- Position2: X=600, y=128, z=600
10+
- BiomeType: Badlands
11+
12+
```java
13+
public void setBiomeArea(World world, BlockVector3 position1, BlockVector3 position 2) {
14+
// Here we must first adapt the world as in the WorldEdit example or translate it into the WorldEdit specialized object.
15+
World faweWorld = BukkitAdapter.adapt(world);
16+
17+
//Now we define a square region using our 2 positions
18+
CuboidRegion cuboidRegion = new CuboidRegion(position1, position2);
19+
20+
// Now we open an EditSession, which contains the complete process or information during an edit process in the world.
21+
// Through the try-and-catch-with-resources we let Java automatically close the resource EditSession after use
22+
try (EditSession editSession = WorldEdit.getInstance().newEditSession(faweWorld)) {
23+
// Here we create our biome pattern
24+
var pattern = new BiomeApplyingPattern(editSession, BiomeTypes.BADLANDS);
25+
26+
//This sets the pattern to the region
27+
editSession.setBlocks((Region) cuboidRegion, pattern);
28+
}
29+
}
30+
// This code would be called by the plugin in the main thread
31+
public void call() {
32+
// Here we set our position 1 and 2
33+
BlockVector3 position1 = BlockVector3.at(300, -64, 300);
34+
BlockVector3 position2 = BlockVector3.at(600, 128, 600);
35+
World bukkitWorld = Bukkit.getWorld("world");
36+
setBiomeArea(bukkitWorld, position1, position2);
37+
}
38+
```
39+
_This code is still Fawe unspecific and can also be used in WorldEdit in this way_
40+
41+
### Let's set blocks async with FAWE
42+
43+
Now we run the code Async to let Fawe manage server resources:
44+
```java
45+
// Now we wrap our code in a runnable with a functional interface and have it executed by Bukkit's scheduler system
46+
Runnable executeCode = () -> {
47+
// Here we set our position 1 and 2
48+
BlockVector3 position1 = BlockVector3.at(300, -64, 300);
49+
BlockVector3 position2 = BlockVector3.at(600, 128, 600);
50+
World bukkitWorld = Bukkit.getWorld("world");
51+
setBiomeArea(bukkitWorld, position1, position2);
52+
};
53+
Bukkit.getScheduler().runTaskAsynchronously(Bukkit.getPluginManager().getPlugin("YourPluginNameHere"), executeCode);
54+
```
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# API Usage
1+
# Get Started
22

33
## Maven & Gradle Examples
44

fastasyncworldedit/SUMMARY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
## API
2424

25-
* [API Usage](./API/api-usage.md)
25+
* [API Usage](./API/get-started)
2626

2727
## Basic Commands
2828

0 commit comments

Comments
 (0)