use of com.fastasyncworldedit.core.history.changeset.AbstractChangeSet in project FastAsyncWorldEdit by IntellectualSites.
the class EditSession method regenerate.
public boolean regenerate(Region region, BiomeType biome, Long seed) {
// TODO Optimize - avoid Vector2D creation (make mutable)
final AbstractChangeSet fcs = (AbstractChangeSet) this.getChangeSet();
this.setChangeSet(null);
final FaweRegionExtent fe = this.getRegionExtent();
final boolean cuboid = region instanceof CuboidRegion;
if (fe != null && cuboid) {
BlockVector3 max = region.getMaximumPoint();
BlockVector3 min = region.getMinimumPoint();
if (!fe.contains(max.getBlockX(), max.getBlockY(), max.getBlockZ()) && !fe.contains(min.getBlockX(), min.getBlockY(), min.getBlockZ())) {
throw FaweCache.OUTSIDE_REGION;
}
}
final Set<BlockVector2> chunks = region.getChunks();
MutableBlockVector3 mutable = new MutableBlockVector3();
MutableBlockVector3 mutable2 = new MutableBlockVector3();
MutableBlockVector2 mutable2D = new MutableBlockVector2();
for (BlockVector2 chunk : chunks) {
final int cx = chunk.getBlockX();
final int cz = chunk.getBlockZ();
final int bx = cx << 4;
final int bz = cz << 4;
final BlockVector3 cmin = BlockVector3.at(bx, 0, bz);
final BlockVector3 cmax = cmin.add(15, maxY, 15);
final boolean containsBot1 = fe == null || fe.contains(cmin.getBlockX(), cmin.getBlockY(), cmin.getBlockZ());
final boolean containsBot2 = region.contains(cmin);
final boolean containsTop1 = fe == null || fe.contains(cmax.getBlockX(), cmax.getBlockY(), cmax.getBlockZ());
final boolean containsTop2 = region.contains(cmax);
if (containsBot2 && containsTop2 && !containsBot1 && !containsTop1) {
continue;
}
boolean conNextX = chunks.contains(mutable2D.setComponents(cx + 1, cz));
boolean conNextZ = chunks.contains(mutable2D.setComponents(cx, cz + 1));
boolean containsAny = false;
if (cuboid && containsBot1 && containsBot2 && containsTop1 && containsTop2 && conNextX && conNextZ) {
containsAny = true;
if (fcs != null) {
for (int x = 0; x < 16; x++) {
int xx = x + bx;
for (int z = 0; z < 16; z++) {
int zz = z + bz;
for (int y = minY; y < maxY + 1; y++) {
BaseBlock block = getFullBlock(mutable.setComponents(xx, y, zz));
fcs.add(mutable, block, BlockTypes.AIR.getDefaultState().toBaseBlock());
}
}
}
}
} else {
if (!conNextX) {
setExistingBlocks(mutable.setComponents(bx + 16, 0, bz), mutable2.setComponents(bx + 31, maxY, bz + 15));
}
if (!conNextZ) {
setExistingBlocks(mutable.setComponents(bx, 0, bz + 16), mutable2.setComponents(bx + 15, maxY, bz + 31));
}
if (!chunks.contains(mutable2D.setComponents(cx + 1, cz + 1)) && !conNextX && !conNextZ) {
setExistingBlocks(mutable.setComponents(bx + 16, 0, bz + 16), mutable2.setComponents(bx + 31, maxY, bz + 31));
}
for (int x = 0; x < 16; x++) {
int xx = x + bx;
mutable.mutX(xx);
for (int z = 0; z < 16; z++) {
int zz = z + bz;
mutable.mutZ(zz);
for (int y = minY; y < maxY + 1; y++) {
mutable.mutY(y);
boolean contains = (fe == null || fe.contains(xx, y, zz)) && region.contains(mutable);
if (contains) {
containsAny = true;
if (fcs != null) {
BaseBlock block = getFullBlock(mutable);
fcs.add(mutable, block, BlockTypes.AIR.getDefaultState().toBaseBlock());
}
} else {
BaseBlock block = getFullBlock(mutable);
try {
setBlock(mutable, block);
} catch (MaxChangedBlocksException e) {
throw new RuntimeException(e);
}
}
}
}
}
}
if (containsAny) {
changes++;
TaskManager.taskManager().sync(new RunnableVal<Object>() {
@Override
public void run(Object value) {
regenerateChunk(cx, cz, biome, seed);
}
});
}
}
if (changes != 0) {
flushQueue();
return true;
}
return false;
}
use of com.fastasyncworldedit.core.history.changeset.AbstractChangeSet in project FastAsyncWorldEdit by IntellectualSites.
the class EditSession method flushQueue.
// FAWE start
/**
* Finish off the queue.
*/
public void flushQueue() {
Operations.completeBlindly(commit());
// Check fails
FaweLimit used = getLimitUsed();
if (used.MAX_FAILS > 0) {
if (used.MAX_CHANGES > 0 || used.MAX_ENTITIES > 0) {
actor.print(Caption.of("fawe.error.worldedit.some.fails", used.MAX_FAILS));
} else if (new ExtentTraverser<>(getExtent()).findAndGet(FaweRegionExtent.class) != null) {
actor.print(Caption.of("fawe.cancel.reason.outside.region"));
} else {
actor.print(Caption.of("fawe.cancel.reason.outside.level"));
}
}
if (wnaMode) {
getWorld().flush();
}
// Reset limit
limit.set(originalLimit);
try {
if (relighter != null && !(relighter instanceof NullRelighter)) {
// Don't relight twice!
if (!relighter.isFinished() && relighter.getLock().tryLock()) {
try {
if (Settings.settings().LIGHTING.REMOVE_FIRST) {
relighter.removeAndRelight(true);
} else {
relighter.fixLightingSafe(true);
}
} finally {
relighter.getLock().unlock();
}
}
}
} catch (Throwable e) {
actor.print(Caption.of("fawe.error.lighting"));
e.printStackTrace();
}
// Cancel any preloader associated with the actor if present
if (getActor() instanceof Player) {
Preloader preloader = Fawe.platform().getPreloader(false);
if (preloader != null) {
preloader.cancel(getActor());
}
}
// Enqueue it
if (getChangeSet() != null) {
if (Settings.settings().HISTORY.COMBINE_STAGES) {
((AbstractChangeSet) getChangeSet()).closeAsync();
} else {
try {
getChangeSet().close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
}
Aggregations