A couple of reworks

- Redo how regeneration works a little to also take a cuboid region for regeneration off-chunk plots
 - Fix a couple of cases where we were writing to the queue instead of the world in the ChunkConsumer (dum)
 - this seems to be working.
This commit is contained in:
dordsor21 2020-07-24 15:17:42 +01:00
parent 18918eb3a3
commit 72c0021306
No known key found for this signature in database
GPG Key ID: 1E53E88969FFCF0B
9 changed files with 115 additions and 97 deletions

View File

@ -97,11 +97,18 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
@Override public boolean enqueue() {
final Clipboard regenClipboard;
if (isRegen()) {
Region region = new CuboidRegion(
BlockVector3.at(getRegenStart()[0] << 4, 0, getRegenStart()[1] << 4),
BlockVector3.at((getRegenEnd()[0] << 4) + 15, 255, (getRegenEnd()[1] << 4) + 15));
BlockVector3 start =
BlockVector3.at(getRegenStart()[0] << 4, 0, getRegenStart()[1] << 4);
BlockVector3 end =
BlockVector3.at((getRegenEnd()[0] << 4) + 15, 255, (getRegenEnd()[1] << 4) + 15);
Region region = new CuboidRegion(start, end);
regenClipboard = new BlockArrayClipboard(region);
regenClipboard.setOrigin(start);
getWorld().regenerate(region, regenClipboard);
} else if (getRegenRegion() != null) {
regenClipboard = new BlockArrayClipboard(getRegenRegion());
regenClipboard.setOrigin(getRegenRegion().getMinimumPoint());
getWorld().regenerate(getRegenRegion(), regenClipboard);
} else {
regenClipboard = null;
}
@ -121,15 +128,17 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
for (int z = 0; z < 16; z++) {
BaseBlock block =
regenClipboard.getFullBlock(BlockVector3.at(x, y, z));
setWorldBlock(x, y, z, block, blockVector2);
if (block != null) {
setWorldBlock(x, y, z, block, blockVector2);
}
}
}
}
}
}
// Allow regen and then blocks to be placed (plot schematic etc)
if (localChunk == null) {
return;
} else if (localChunk == null) {
throw new NullPointerException(
"LocalChunk cannot be null when accessed from ChunkCoordinator");
}
int sx = blockVector2.getX() << 4;
int sz = blockVector2.getZ() << 4;
@ -143,10 +152,13 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
continue;
}
BaseBlock block = blocksLayer[j];
int x = sx + ChunkUtil.getX(j);
int y = ChunkUtil.getY(layer, j);
int z = sz + ChunkUtil.getZ(j);
setWorldBlock(x, y, z, block, blockVector2);
if (block != null) {
int x = sx + ChunkUtil.getX(j);
int y = ChunkUtil.getY(layer, j);
int z = sz + ChunkUtil.getZ(j);
setWorldBlock(x, y, z, block, blockVector2);
}
}
}
for (int layer = 0; layer < localChunk.getBaseblocks().length; layer++) {
@ -159,10 +171,12 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
continue;
}
BiomeType biome = biomesLayer[j];
int x = sx + ChunkUtil.getX(j);
int y = ChunkUtil.getY(layer, j);
int z = sz + ChunkUtil.getZ(j);
getWorld().setBiome(BlockVector3.at(x, y, z), biome);
if (biome != null) {
int x = sx + ChunkUtil.getX(j);
int y = ChunkUtil.getY(layer, j);
int z = sz + ChunkUtil.getZ(j);
getWorld().setBiome(BlockVector3.at(x, y, z), biome);
}
}
}
if (localChunk.getTiles().size() > 0) {
@ -184,7 +198,6 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
}
};
}
CuboidRegion region;
Collection<BlockVector2> read = new ArrayList<>();
if (getReadChunks().size() > 0) {
read.addAll(getReadChunks());

View File

@ -76,7 +76,8 @@ public class BukkitRegionManager extends RegionManager {
LoggerFactory.getLogger("P2/" + BukkitRegionManager.class.getSimpleName());
private final GlobalBlockQueue blockQueue;
@Inject public BukkitRegionManager(@Nonnull WorldUtil worldUtil, @Nonnull GlobalBlockQueue blockQueue) {
@Inject
public BukkitRegionManager(@Nonnull WorldUtil worldUtil, @Nonnull GlobalBlockQueue blockQueue) {
super(worldUtil, blockQueue);
this.blockQueue = blockQueue;
}
@ -174,7 +175,9 @@ public class BukkitRegionManager extends RegionManager {
final int tcz = p2z >> 4;
final QueueCoordinator queue = blockQueue.getNewQueue(world);
queue.addReadChunks(new CuboidRegion(pos1.getBlockVector3(), pos2.getBlockVector3()).getChunks());
final QueueCoordinator regenQueue = blockQueue.getNewQueue(world);
queue.addReadChunks(
new CuboidRegion(pos1.getBlockVector3(), pos2.getBlockVector3()).getChunks());
queue.setChunkConsumer(chunk -> {
int x = chunk.getX();
@ -185,7 +188,7 @@ public class BukkitRegionManager extends RegionManager {
int zzt = zzb + 15;
if (xxb >= p1x && xxt <= p2x && zzb >= p1z && zzt <= p2z) {
AugmentedUtils
.bypass(ignoreAugment, () -> queue.regenChunk(chunk.getX(), chunk.getZ()));
.bypass(ignoreAugment, () -> regenQueue.regenChunk(chunk.getX(), chunk.getZ()));
return;
}
boolean checkX1 = false;
@ -285,7 +288,8 @@ public class BukkitRegionManager extends RegionManager {
//map.restoreBlocks(worldObj, 0, 0);
map.restoreEntities(Bukkit.getWorld(world.getName()), 0, 0);
});
queue.setCompleteTask(whenDone);
regenQueue.setCompleteTask(whenDone);
queue.setCompleteTask(regenQueue::enqueue);
queue.enqueue();
return true;
}

View File

@ -370,7 +370,7 @@ public class Area extends SubCommand {
blockQueue.getNewQueue(worldUtil.getWeWorld(world));
queue.setChunkConsumer(chunk -> AugmentedUtils
.generate(null, world, chunk.getX(), chunk.getZ(),
queue));
null));
queue.addReadChunks(region.getChunks());
queue.enqueue();
}
@ -681,7 +681,7 @@ public class Area extends SubCommand {
QueueCoordinator queue =
blockQueue.getNewQueue(worldUtil.getWeWorld(area.getWorldName()));
queue.setChunkConsumer(chunk -> AugmentedUtils
.generate(null, area.getWorldName(), chunk.getX(), chunk.getZ(), queue));
.generate(null, area.getWorldName(), chunk.getX(), chunk.getZ(), null));
queue.addReadChunks(area.getRegion().getChunks());
queue.setCompleteTask(() -> player.sendMessage("Regen complete"));
queue.enqueue();

View File

@ -35,7 +35,6 @@ import com.plotsquared.core.plot.PlotAreaTerrainType;
import com.plotsquared.core.plot.PlotAreaType;
import com.plotsquared.core.plot.PlotId;
import com.plotsquared.core.queue.QueueCoordinator;
import com.plotsquared.core.util.ChunkUtil;
import com.plotsquared.core.util.FileBytes;
import com.plotsquared.core.util.FileUtils;
import com.plotsquared.core.util.MathMan;
@ -248,38 +247,19 @@ public class HybridPlotManager extends ClassicPlotManager {
final BiomeType biome = hybridPlotWorld.getPlotBiome();
final QueueCoordinator queue = hybridPlotWorld.getQueue();
queue.addReadChunks(new CuboidRegion(plot.getExtendedBottomAbs().getBlockVector3(),
plot.getExtendedTopAbs().getBlockVector3()).getChunks());
queue.setChunkConsumer(blockVector2 -> {
// If the chunk isn't near the edge and it isn't an augmented world we can just regen the whole chunk
if (canRegen && ChunkUtil.isWholeChunk(pos1, pos2, blockVector2)) {
queue.regenChunk(blockVector2.getX(), blockVector2.getZ());
return;
}
/* Otherwise we need to set each component, as we don't want to regenerate the road or other plots that share the same chunk.*/
// Set the biome
int x1 = Math.max(pos1.getX(), blockVector2.getX() << 4);
int z1 = Math.max(pos1.getZ(), blockVector2.getZ() << 4);
int x2 = Math.min(pos2.getX(), blockVector2.getX() << 4);
int z2 = Math.min(pos2.getZ(), blockVector2.getZ() << 4);
WorldUtil.setBiome(world, x1, z1, x2, z2, biome);
// These two locations are for each component (e.g. bedrock, main block, floor, air)
Location bot = Location.at(world, x1, 0, z1);
Location top = Location.at(world, x2, 1, z2);
queue.setCuboid(bot, top, bedrock);
if (!canRegen) {
queue.setCuboid(pos1.withY(0), pos2.withY(0), bedrock);
// Each component has a different layer
bot = bot.withY(1);
top = top.withY(hybridPlotWorld.PLOT_HEIGHT);
queue.setCuboid(bot, top, filling);
bot = bot.withY(hybridPlotWorld.PLOT_HEIGHT);
top = top.withY(hybridPlotWorld.PLOT_HEIGHT + 1);
queue.setCuboid(bot, top, plotfloor);
bot = bot.withY(hybridPlotWorld.PLOT_HEIGHT + 1);
top = top.withY(getWorldHeight());
queue.setCuboid(bot, top, air);
// And finally set the schematic, the y value is unimportant for this function
pastePlotSchematic(queue, bot, top);
});
queue.setCuboid(pos1.withY(1), pos2.withY(hybridPlotWorld.PLOT_HEIGHT - 1), filling);
queue.setCuboid(pos1.withY(hybridPlotWorld.PLOT_HEIGHT),
pos2.withY(hybridPlotWorld.PLOT_HEIGHT), plotfloor);
queue.setCuboid(pos1.withY(hybridPlotWorld.PLOT_HEIGHT + 1),
pos2.withY(getWorldHeight()), air);
queue.setBiomeCuboid(pos1, pos2, biome);
} else {
queue.setRegenRegion(new CuboidRegion(pos1.getBlockVector3(), pos2.getBlockVector3()));
}
pastePlotSchematic(queue, pos1, pos2);
queue.setCompleteTask(whenDone);
return queue.enqueue();
}

View File

@ -30,6 +30,7 @@ import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.biome.BiomeType;
@ -59,6 +60,7 @@ public abstract class BasicQueueCoordinator extends QueueCoordinator {
private boolean regen = false;
private int[] regenStart;
private int[] regenEnd;
private CuboidRegion regenRegion = null;
private Consumer<BlockVector2> consumer = null;
private boolean unloadAfter = true;
private GlobalBlockQueue globalBlockQueue;
@ -155,6 +157,14 @@ public abstract class BasicQueueCoordinator extends QueueCoordinator {
this.readRegion.addAll(readRegion);
}
@Override public CuboidRegion getRegenRegion() {
return this.regenRegion != null ? this.regenRegion.clone() : null;
}
@Override public void setRegenRegion(CuboidRegion regenRegion) {
this.regenRegion = regenRegion;
}
@Override public void regenChunk(int x, int z) {
regen = true;
// There will never only be one nullified coordinate pair

View File

@ -29,6 +29,7 @@ import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
@ -211,6 +212,19 @@ public class DelegateQueueCoordinator extends QueueCoordinator {
if (parent != null) {
parent.setUnloadAfter(setUnloadAfter);
}
}
@Override public CuboidRegion getRegenRegion() {
if (parent != null) {
return parent.getRegenRegion();
}
return null;
}
@Override public void setRegenRegion(CuboidRegion regenRegion) {
if (parent != null) {
parent.setRegenRegion(regenRegion);
}
}
}

View File

@ -68,7 +68,6 @@ public class GlobalBlockQueue {
boolean success = false;
if (queue.size() > 0 && !activeQueues.contains(queue)) {
success = activeQueues.add(queue);
System.out.println("c");
queue.start();
}
return success;

View File

@ -33,6 +33,7 @@ import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
@ -129,6 +130,10 @@ public abstract class QueueCoordinator {
public abstract void setUnloadAfter(boolean unloadAfter);
public abstract CuboidRegion getRegenRegion();
public abstract void setRegenRegion(CuboidRegion regenRegion);
public abstract void regenChunk(int x, int z);
public abstract World getWorld();
@ -138,7 +143,6 @@ public abstract class QueueCoordinator {
}
public boolean enqueue() {
System.out.println("b");
return blockQueue.enqueue(this);
}
@ -181,4 +185,20 @@ public abstract class QueueCoordinator {
}
}
}
public void setBiomeCuboid(Location pos1, Location pos2, BiomeType biome) {
int yMin = Math.min(pos1.getY(), pos2.getY());
int yMax = Math.min(255, Math.max(pos1.getY(), pos2.getY()));
int xMin = Math.min(pos1.getX(), pos2.getX());
int xMax = Math.max(pos1.getX(), pos2.getX());
int zMin = Math.min(pos1.getZ(), pos2.getZ());
int zMax = Math.max(pos1.getZ(), pos2.getZ());
for (int y = yMin; y <= yMax; y++) {
for (int x = xMin; x <= xMax; x++) {
for (int z = zMin; z <= zMax; z++) {
setBiome(x, y, z, biome);
}
}
}
}
}

View File

@ -281,7 +281,6 @@ public abstract class SchematicHandler {
return;
}
try {
final QueueCoordinator queue = plot.getArea().getQueue();
BlockVector3 dimension = schematic.getClipboard().getDimensions();
final int WIDTH = dimension.getX();
final int LENGTH = dimension.getZ();
@ -330,50 +329,29 @@ public abstract class SchematicHandler {
final int bcz = p1z >> 4;
final int tcx = p2x >> 4;
final int tcz = p2z >> 4;
queue.addReadChunks(
new CuboidRegion(pos1.getBlockVector3(), pos2.getBlockVector3()).getChunks());
queue.setChunkConsumer(blockVector2 -> {
int x = blockVector2.getX();
int z = blockVector2.getZ();
int xxb = x << 4;
int zzb = z << 4;
int xxt = xxb + 15;
int zzt = zzb + 15;
if (x == bcx) {
xxb = p1x;
}
if (x == tcx) {
xxt = p2x;
}
if (z == bcz) {
zzb = p1z;
}
if (z == tcz) {
zzt = p2z;
}
// Paste schematic here
// Paste schematic here
final QueueCoordinator queue = plot.getArea().getQueue();
for (int ry = 0; ry < Math.min(256, HEIGHT); ry++) {
int yy = y_offset_actual + ry;
if (yy > 255) {
continue;
}
for (int rz = zzb - p1z; rz <= (zzt - p1z); rz++) {
for (int rx = xxb - p1x; rx <= (xxt - p1x); rx++) {
int xx = p1x + xOffset + rx;
int zz = p1z + zOffset + rz;
BaseBlock id =
blockArrayClipboard.getFullBlock(BlockVector3.at(rx, ry, rz));
queue.setBlock(xx, yy, zz, id);
if (ry == 0) {
BiomeType biome =
blockArrayClipboard.getBiome(BlockVector2.at(rx, rz));
queue.setBiome(xx, zz, biome);
}
for (int ry = 0; ry < Math.min(256, HEIGHT); ry++) {
int yy = y_offset_actual + ry;
if (yy > 255) {
continue;
}
for (int rz = 0; rz <= blockArrayClipboard.getDimensions().getZ(); rz++) {
for (int rx = 0; rx < blockArrayClipboard.getDimensions().getX(); rx++) {
int xx = p1x + xOffset + rx;
int zz = p1z + zOffset + rz;
BaseBlock id =
blockArrayClipboard.getFullBlock(BlockVector3.at(rx, ry, rz));
queue.setBlock(xx, yy, zz, id);
if (ry == 0) {
BiomeType biome =
blockArrayClipboard.getBiome(BlockVector3.at(rx, ry, rz));
queue.setBiome(xx, yy, zz, biome);
}
}
}
});
}
if (whenDone != null) {
whenDone.value = true;
}