-
-
Notifications
You must be signed in to change notification settings - Fork 11
Extension of the Fawe documentation to achieve a better understanding of regions and patterns #65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
TheMeinerLP
wants to merge
7
commits into
IntellectualSites:main
Choose a base branch
from
TheMeinerLP:feature/advance-fawe-developer-examples
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c2c2c67
Add some small example for patter usage inside of the worldedit.
TheMeinerLP b0191d2
Add chess pattern
TheMeinerLP 5cbd181
Merge branch 'main' into feature/advance-fawe-developer-examples
TheMeinerLP 15c3331
Update fastasyncworldedit/API/fill-region-by-pattern.md
TheMeinerLP 9256e7d
Fix some typos and correct some wordings
TheMeinerLP e3d5619
Merge branch 'feature/advance-fawe-developer-examples' of https://git…
TheMeinerLP c197644
Fix method name
TheMeinerLP File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
# 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) | ||
|
||
## Checkerboard Pattern example | ||
Given are 3 things: | ||
- Position1: X=300, y=-64, z=300 | ||
- Position2: X=600, y=128, z=600 | ||
|
||
{% hint style="danger" %} | ||
**This code is Fawe specific and can not be used in WorldEdit in this way** | ||
{% endhint %} | ||
```java | ||
public void setCheckerBoardArea(World world, BlockVector3 position1, BlockVector3 position2) { | ||
// 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 Linear3DBlockPattern(new Pattern[]{ BlockTypes.WHITE_WOOL, BlockTypes.BLACK_WOOL }, 2, 2, 2); | ||
|
||
//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"); | ||
setCheckerBoardArea(bukkitWorld, position1, position2); | ||
} | ||
``` | ||
|
||
### Result: | ||
|
||
 | ||
|
||
|
||
## Biome Cuboid Example | ||
Given are 3 things: | ||
- Position1: X=300, y=-64, z=300 | ||
- Position2: X=600, y=128, z=600 | ||
- BiomeType: Badlands | ||
|
||
{% hint style="danger" %} | ||
**This code is Fawe specific and can not be used in WorldEdit in this way** | ||
{% endhint %} | ||
```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); | ||
} | ||
``` | ||
|
||
## 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); | ||
``` |
2 changes: 1 addition & 1 deletion
2
fastasyncworldedit/API/api-usage.md → fastasyncworldedit/API/get-started.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# API Usage | ||
# Get Started | ||
|
||
## Maven & Gradle Examples | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ | |
|
||
## API | ||
|
||
* [API Usage](./API/api-usage.md) | ||
* [API Usage](./API/get-started) | ||
|
||
## Basic Commands | ||
|
||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.