Regen using EditSession

This commit is contained in:
Jesse Boyd 2019-11-05 08:03:00 +00:00
parent 6142f30715
commit 92b34e4fa9
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F

View File

@ -183,47 +183,48 @@ public class BukkitWorld extends AbstractWorld {
@Override @Override
public boolean regenerate(Region region, EditSession editSession) { public boolean regenerate(Region region, EditSession editSession) {
BaseBlock[] history = new BaseBlock[16 * 16 * (getMaxY() + 1)]; return editSession.regenerate(region);
// BaseBlock[] history = new BaseBlock[16 * 16 * (getMaxY() + 1)];
for (BlockVector2 chunk : region.getChunks()) { //
BlockVector3 min = BlockVector3.at(chunk.getBlockX() * 16, 0, chunk.getBlockZ() * 16); // for (BlockVector2 chunk : region.getChunks()) {
// BlockVector3 min = BlockVector3.at(chunk.getBlockX() * 16, 0, chunk.getBlockZ() * 16);
// First save all the blocks inside //
for (int x = 0; x < 16; ++x) { // // First save all the blocks inside
for (int y = 0; y < (getMaxY() + 1); ++y) { // for (int x = 0; x < 16; ++x) {
for (int z = 0; z < 16; ++z) { // for (int y = 0; y < (getMaxY() + 1); ++y) {
BlockVector3 pt = min.add(x, y, z); // for (int z = 0; z < 16; ++z) {
int index = y * 16 * 16 + z * 16 + x; // BlockVector3 pt = min.add(x, y, z);
history[index] = editSession.getFullBlock(pt); // int index = y * 16 * 16 + z * 16 + x;
} // history[index] = editSession.getFullBlock(pt);
} // }
} // }
// }
try { //
getWorld().regenerateChunk(chunk.getBlockX(), chunk.getBlockZ()); // try {
} catch (Throwable t) { // getWorld().regenerateChunk(chunk.getBlockX(), chunk.getBlockZ());
logger.warn("Chunk generation via Bukkit raised an error", t); // } catch (Throwable t) {
} // logger.warn("Chunk generation via Bukkit raised an error", t);
// }
// Then restore //
for (int x = 0; x < 16; ++x) { // // Then restore
for (int y = 0; y < (getMaxY() + 1); ++y) { // for (int x = 0; x < 16; ++x) {
for (int z = 0; z < 16; ++z) { // for (int y = 0; y < (getMaxY() + 1); ++y) {
BlockVector3 pt = min.add(x, y, z); // for (int z = 0; z < 16; ++z) {
int index = y * 16 * 16 + z * 16 + x; // BlockVector3 pt = min.add(x, y, z);
// int index = y * 16 * 16 + z * 16 + x;
// We have to restore the block if it was outside //
if (!region.contains(pt)) { // // We have to restore the block if it was outside
editSession.smartSetBlock(pt, history[index]); // if (!region.contains(pt)) {
} else { // Otherwise fool with history // editSession.smartSetBlock(pt, history[index]);
editSession.getChangeSet().add(new BlockChange(pt, history[index], editSession.getFullBlock(pt))); // } else { // Otherwise fool with history
} // editSession.getChangeSet().add(new BlockChange(pt, history[index], editSession.getFullBlock(pt)));
} // }
} // }
} // }
} // }
// }
return true; //
// return true;
} }
/** /**