mirror of
https://github.com/boy0001/FastAsyncWorldedit.git
synced 2024-06-25 22:24:54 +02:00
Updated API (markdown)
parent
be0e3bab0b
commit
6aaddc952a
40
API.md
40
API.md
|
@ -8,11 +8,13 @@
|
|||
|
||||
# The FaweAPI
|
||||
The FaweAPI has some various methods that may be useful:
|
||||
- getNewEditSession
|
||||
- getEditSessionBuilder
|
||||
- getTaskManager
|
||||
- wrapPlayer
|
||||
- createQueue
|
||||
- getWorld
|
||||
- upload
|
||||
- load
|
||||
- getMaskManagers
|
||||
- isMemoryLimited
|
||||
- getFastRandom
|
||||
|
@ -24,7 +26,6 @@ The FaweAPI has some various methods that may be useful:
|
|||
- getChangeSetFromDisk
|
||||
- checkVersion
|
||||
- fixLighting
|
||||
- streamSchematic
|
||||
- addTask
|
||||
- addMemoryLimitedTask
|
||||
- addMemoryPlentifulTask
|
||||
|
@ -38,10 +39,11 @@ See also:
|
|||
# Wrappers for Bukkit API
|
||||
FAWE offers some async wrappers for the Bukkit API:
|
||||
```Java
|
||||
final AsyncWorld world = AsyncWorld.wrap(bukkitWorld);
|
||||
TaskManager.IMP.async(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
AsyncWorld world = AsyncWorld.wrap(bukkitWorld);
|
||||
// AsyncWorld world = AsyncWorld.create(new WorldCreator("MyWorld")); // Or create a new world
|
||||
Block block = world.getBlockAt(0, 0, 0);
|
||||
block.setType(Material.BEDROCK);
|
||||
// When you are done
|
||||
|
@ -56,10 +58,9 @@ See also:
|
|||
- https://github.com/boy0001/FastAsyncWorldedit/blob/master/core/src/main/java/com/boydti/fawe/wrappers/WorldWrapper.java
|
||||
|
||||
# The FaweQueue
|
||||
The FaweQueue is a basic queue for modifying the world:
|
||||
- Use it to modify whole chunks or individual blocks
|
||||
- It is very implementation specific i.e. it relies heavily on chunks and block ids
|
||||
- Can be used from an async thread
|
||||
The FaweQueue is a basic queue for modifying the world from async threads
|
||||
- Use it to modify whole chunks or individual blocks efficiently
|
||||
- See EditSession or AsyncWorld which will be easier to use but slower
|
||||
|
||||
```Java
|
||||
// Auto queuing will mean blocks start to place before it is flushed
|
||||
|
@ -77,7 +78,7 @@ chunk.addToQueue();
|
|||
```
|
||||
|
||||
# Quickly run something on the main thread
|
||||
With FAWE you can temporarily switch to the main thread to do something
|
||||
With the FAWE TaskManager you can temporarily switch to the main thread to do something
|
||||
```Java
|
||||
// E.g. Get a player's inventory but you are on an async thread.
|
||||
PlayerInventory inventory = TaskManager.IMP.sync(new RunnableVal<PlayerInventory>() {
|
||||
|
@ -87,6 +88,7 @@ PlayerInventory inventory = TaskManager.IMP.sync(new RunnableVal<PlayerInventory
|
|||
}
|
||||
});
|
||||
```
|
||||
See: https://github.com/boy0001/FastAsyncWorldedit/blob/master/core/src/main/java/com/boydti/fawe/util/TaskManager.java
|
||||
|
||||
# WE uses its own player and world objects
|
||||
Getting the WE World object
|
||||
|
@ -103,8 +105,8 @@ WorldEditPlugin worldEdit = (WorldEditPlugin) Bukkit.getServer().getPluginManage
|
|||
worldedit.wrapPlayer(bukkitPlayer);
|
||||
// Forge
|
||||
ForgeWorldEdit.inst.wrap(entityPlayer);
|
||||
// Or with FAWE
|
||||
FawePlayer.wrap(uuid or username or actor or player object).getPlayer();
|
||||
// Alternative
|
||||
FawePlayer.wrap(uuid or username or actor or player object here).getPlayer();
|
||||
```
|
||||
|
||||
# Creating an EditSession:
|
||||
|
@ -112,14 +114,14 @@ The EditSession is a WE class which is used to make and record changes to a worl
|
|||
- If you just want to make simple block changes without history, see the FaweQueue or AsyncWorld example above
|
||||
- With FAWE, the EditSession (and most other WE classes) can be used off the main thread
|
||||
```Java
|
||||
// Without FAWE
|
||||
// If no player is doing the changes
|
||||
EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(worldEditWorld, -1);
|
||||
// Or for a specific player
|
||||
// For a specific player
|
||||
editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(worldEditWorld, -1, actor);
|
||||
// With FAWE
|
||||
editSession = FaweAPI.getNewEditSession(worldEditWorld);
|
||||
// Or for a specific player
|
||||
editSession = FaweAPI.getNewEditSession(fawePlayer);
|
||||
// If you have FAWE, the EditSessionBuilder is preferred as you can specify what functionality you need
|
||||
editSession = new EditSessionBuilder(world)
|
||||
// Any settings you want here
|
||||
.build();
|
||||
|
||||
// Do stuff with the EditSession
|
||||
editSession.setBlock(new Vector(x, y, z), new BaseBlock(id, data));
|
||||
|
@ -127,6 +129,8 @@ editSession.setBlock(new Vector(x, y, z), new BaseBlock(id, data));
|
|||
editSession.flushQueue();
|
||||
```
|
||||
|
||||
See: https://github.com/boy0001/FastAsyncWorldedit/blob/master/core/src/main/java/com/boydti/fawe/util/EditSessionBuilder.java
|
||||
|
||||
# Pasting a schematic
|
||||
```Java
|
||||
File file = new File("path/to/schematic");
|
||||
|
@ -135,6 +139,10 @@ boolean entities = true;
|
|||
Vector position = new Vector(0, 0, 0);
|
||||
SchematicFormat.getFormat(file).load(file).paste(editSession, position, noAir, entities);
|
||||
editSession.flushQueue();
|
||||
|
||||
// If you have FAWE you could instead use this:
|
||||
boolean allowUndo = true;
|
||||
EditSession editSession = SCHEMATIC.load(file).paste(world, position, allowUndo, !noAir, (Transform) null);
|
||||
```
|
||||
|
||||
# Undoing an EditSession
|
||||
|
|
Loading…
Reference in New Issue
Block a user