From c2c2c673a8c90e648f6944e1982d44536378f048 Mon Sep 17 00:00:00 2001 From: TheMeinerLP Date: Sun, 7 Apr 2024 14:37:16 +0200 Subject: [PATCH] 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. --- .../API/fill-region-by-pattern.md | 54 +++++++++++++++++++ .../API/{api-usage.md => get-started.md} | 2 +- fastasyncworldedit/SUMMARY.md | 2 +- 3 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 fastasyncworldedit/API/fill-region-by-pattern.md rename fastasyncworldedit/API/{api-usage.md => get-started.md} (99%) diff --git a/fastasyncworldedit/API/fill-region-by-pattern.md b/fastasyncworldedit/API/fill-region-by-pattern.md new file mode 100644 index 0000000..83241b0 --- /dev/null +++ b/fastasyncworldedit/API/fill-region-by-pattern.md @@ -0,0 +1,54 @@ +# Filling a region using a pattern + +## Foreword +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) + +## Biome Cuboid Example +Given are 3 things: +- Position1: X=300, y=-64, z=300 +- Position2: X=600, y=128, z=600 +- BiomeType: Badlands + +```java +public void setBiomeArea(World world, BlockVector3 position1, BlockVector3 position 2) { + // Here we must first adapt the world as in the WorldEdit example or translate it into the WorldEdit specialized object. + World faweWorld = BukkitAdapter.adapt(world); + + //Now we define a square region using our 2 positions + CuboidRegion cuboidRegion = new CuboidRegion(position1, position2); + + // Now we open an EditSession, which contains the complete process or information during an edit process in the world. + // Through the try-and-catch-with-resources we let Java automatically close the resource EditSession after use + try (EditSession editSession = WorldEdit.getInstance().newEditSession(faweWorld)) { + // Here we create our biome pattern + var pattern = new BiomeApplyingPattern(editSession, BiomeTypes.BADLANDS); + + //This sets the pattern to the region + editSession.setBlocks((Region) cuboidRegion, pattern); + } +} +// This code would be called by the plugin in the main thread +public void call() { + // Here we set our position 1 and 2 + BlockVector3 position1 = BlockVector3.at(300, -64, 300); + BlockVector3 position2 = BlockVector3.at(600, 128, 600); + World bukkitWorld = Bukkit.getWorld("world"); + setBiomeArea(bukkitWorld, position1, position2); +} +``` +_This code is still Fawe unspecific and can also be used in WorldEdit in this way_ + +### Let's set blocks async with FAWE + +Now we run the code Async to let Fawe manage server resources: +```java +// Now we wrap our code in a runnable with a functional interface and have it executed by Bukkit's scheduler system +Runnable executeCode = () -> { + // Here we set our position 1 and 2 + BlockVector3 position1 = BlockVector3.at(300, -64, 300); + BlockVector3 position2 = BlockVector3.at(600, 128, 600); + World bukkitWorld = Bukkit.getWorld("world"); + setBiomeArea(bukkitWorld, position1, position2); +}; +Bukkit.getScheduler().runTaskAsynchronously(Bukkit.getPluginManager().getPlugin("YourPluginNameHere"), executeCode); +``` diff --git a/fastasyncworldedit/API/api-usage.md b/fastasyncworldedit/API/get-started.md similarity index 99% rename from fastasyncworldedit/API/api-usage.md rename to fastasyncworldedit/API/get-started.md index 6c3ab0c..4c561e0 100644 --- a/fastasyncworldedit/API/api-usage.md +++ b/fastasyncworldedit/API/get-started.md @@ -1,4 +1,4 @@ -# API Usage +# Get Started ## Maven & Gradle Examples diff --git a/fastasyncworldedit/SUMMARY.md b/fastasyncworldedit/SUMMARY.md index e9dbf05..952ee45 100644 --- a/fastasyncworldedit/SUMMARY.md +++ b/fastasyncworldedit/SUMMARY.md @@ -22,7 +22,7 @@ ## API -* [API Usage](./API/api-usage.md) +* [API Usage](./API/get-started) ## Basic Commands