Created Anvil API (markdown)

Jesse Boyd 2016-08-25 17:22:19 +10:00
parent 2f78922777
commit 653a963cd1

96
Anvil-API.md Normal file

@ -0,0 +1,96 @@
Relevant package:
https://github.com/boy0001/FastAsyncWorldedit/tree/master/core/src/main/java/com/boydti/fawe/jnbt/anvil
# Using with a FaweQueue
```Java
String worldName = "world";
boolean hasSky = true;
File root = new File(worldName + File.separator + "region");
MCAWorld world = new MCAWorld(worldName, root, hasSky);
MCAQueue queue = world.getQueue();
// Do stuff here with the FaweQueue
```
# Using with an EditSession
```Java
String worldName = "world";
boolean hasSky = true;
File root = new File(worldName + File.separator + "region");
MCAWorld world = new MCAWorld(worldName, root, hasSky);
EditSession editSession = new EditSessionBuilder(world)
.checkMemory(false)
.allowedRegionsEverywhere()
.fastmode(true)
.changeSetNull()
.limitUnlimited()
.build();
// Do stuff here with the editSession (non generated sections of the world cannot be modified)
```
# Replacing blocks
```Java
String worldName = "world";
File root = new File(worldName + File.separator + "region");
MCAQueue queue = new MCAQueue(worldName, root, true);
final LongAdder changes = new LongAdder();
queue.filterWorld(new MCAFilter() {
@Override
public void applyBlock(int x, int y, int z, BaseBlock block) {
if (block.getId() == 5) { // Change the id if it's 5
block.setId(7);
changes.add(1);
}
}
});
// See: FaweBlockMatcher.fromBlocks(...) which returns true if a block matches
// See: FaweBlockMatcher.setBlocks(...) which will modify a provided block
```
# Deleting chunks outside a radius
```Java
MCAQueue queue = new MCAQueue(worldName, root, true);
final LongAdder changes = new LongAdder();
final int radius = 4000;
final int radiusSquared = radius * radius;
queue.filterWorld(new MCAFilter() {
@Override
public MCAFile applyFile(MCAFile mca) {
int distanceX = Math.abs((mca.getX() << 9) + 256) - 256;
int distanceZ = Math.abs((mca.getZ() << 9) + 256) - 256;
int distanceSquared = distanceX * distanceX + distanceZ * distanceZ;
if (distanceSquared > radius) {
// Delete this file since it's outside the radius
mca.close();
mca.getFile().delete();
return null;
} else if (distanceSquared + 512 < radiusSquared) {
// Don't filter this MCAFile since it's well within the radius
return null;
} else {
return mca;
}
}
@Override
public boolean appliesChunk(int cx, int cz) {
int distanceX = Math.abs((cx << 9) + 8) - 8;
int distanceZ = Math.abs((cz << 9) + 8) - 8;
int distanceSquared = distanceX * distanceX + distanceZ * distanceZ;
if (distanceSquared > radiusSquared) {
// Chunk is outside the radius
return true;
} else {
// We don't care about chunks inside the radius
return false;
}
}
@Override
public MCAChunk applyChunk(MCAChunk chunk) {
chunk.setDeleted(true);
// We don't want to filter blocks
return null;
}
});
```