mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-25 10:14:42 +02:00
Start reimplementing chunk generation.
This would either need to be one WorldEdit operation or (preferable) WorldEdit allows Extents (including EditSessions) into the regenerate adapter method
This commit is contained in:
@ -25,7 +25,6 @@
|
||||
*/
|
||||
package com.plotsquared.core.inject.factory;
|
||||
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
import com.plotsquared.core.queue.ChunkCoordinator;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
@ -37,12 +36,9 @@ import java.util.function.Consumer;
|
||||
|
||||
public interface ChunkCoordinatorFactory {
|
||||
|
||||
@Nonnull ChunkCoordinator create(@Assisted final long maxIterationTime,
|
||||
@Assisted final int initialBatchSize,
|
||||
@NotNull @Assisted final Consumer<BlockVector2> chunkConsumer,
|
||||
@NotNull @Assisted final World world,
|
||||
@NotNull @Assisted final Collection<BlockVector2> requestedChunks,
|
||||
@NotNull @Assisted final Runnable whenDone,
|
||||
@NotNull @Assisted final Consumer<Throwable> throwableConsumer);
|
||||
@Nonnull ChunkCoordinator create(final long maxIterationTime, final int initialBatchSize,
|
||||
@NotNull final Consumer<BlockVector2> chunkConsumer, @NotNull final World world,
|
||||
@NotNull final Collection<BlockVector2> requestedChunks, @NotNull final Runnable whenDone,
|
||||
@NotNull final Consumer<Throwable> throwableConsumer);
|
||||
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ package com.plotsquared.core.plot;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.collection.QuadMap;
|
||||
import com.plotsquared.core.configuration.CaptionUtility;
|
||||
import com.plotsquared.core.configuration.Captions;
|
||||
|
@ -49,6 +49,9 @@ public abstract class BasicQueueCoordinator extends QueueCoordinator {
|
||||
private int lastZ = Integer.MIN_VALUE;
|
||||
private boolean settingBiomes = false;
|
||||
private boolean settingTiles = false;
|
||||
private boolean regen = false;
|
||||
private int[] regenStart;
|
||||
private int[] regenEnd;
|
||||
private Consumer<BlockVector2> consumer = null;
|
||||
|
||||
private GlobalBlockQueue globalBlockQueue;
|
||||
@ -129,6 +132,40 @@ public abstract class BasicQueueCoordinator extends QueueCoordinator {
|
||||
return this.settingTiles;
|
||||
}
|
||||
|
||||
@Override public void regenChunk(int x, int z) {
|
||||
regen = true;
|
||||
// There will never only be one nullified coordinate pair
|
||||
if (regenStart == null) {
|
||||
regenStart = new int[]{x, z};
|
||||
regenEnd = new int[]{x, z};
|
||||
return;
|
||||
}
|
||||
if (x < regenStart[0]) {
|
||||
regenStart[0] = x;
|
||||
}
|
||||
if (z < regenStart[1]) {
|
||||
regenStart[1] = z;
|
||||
}
|
||||
if (x > regenEnd[0]) {
|
||||
regenEnd[0] = x;
|
||||
}
|
||||
if (z > regenEnd[1]) {
|
||||
regenEnd[1] = z;
|
||||
}
|
||||
}
|
||||
|
||||
public int[] getRegenStart() {
|
||||
return regenStart;
|
||||
}
|
||||
|
||||
public int[] getRegenEnd() {
|
||||
return regenEnd;
|
||||
}
|
||||
|
||||
public boolean isRegen() {
|
||||
return regen;
|
||||
}
|
||||
|
||||
public ConcurrentHashMap<BlockVector2, LocalChunk> getBlockChunks() {
|
||||
return this.blockChunks;
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import com.google.common.base.Preconditions;
|
||||
import com.google.inject.Inject;
|
||||
import com.plotsquared.core.inject.factory.ChunkCoordinatorFactory;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -18,6 +19,7 @@ import java.util.function.Consumer;
|
||||
public class ChunkCoordinatorBuilder {
|
||||
|
||||
private final List<BlockVector2> requestedChunks = new LinkedList<>();
|
||||
private final ChunkCoordinatorFactory chunkCoordinatorFactory;
|
||||
private Consumer<Throwable> throwableConsumer = Throwable::printStackTrace;
|
||||
private World world;
|
||||
private Consumer<BlockVector2> chunkConsumer;
|
||||
@ -25,9 +27,9 @@ public class ChunkCoordinatorBuilder {
|
||||
};
|
||||
private long maxIterationTime = 60; // A little over 1 tick;
|
||||
private int initialBatchSize = 4;
|
||||
private final ChunkCoordinatorFactory chunkCoordinatorFactory;
|
||||
|
||||
@Inject public ChunkCoordinatorBuilder(@Nonnull ChunkCoordinatorFactory chunkCoordinatorFactory) {
|
||||
@Inject
|
||||
public ChunkCoordinatorBuilder(@Nonnull ChunkCoordinatorFactory chunkCoordinatorFactory) {
|
||||
this.chunkCoordinatorFactory = chunkCoordinatorFactory;
|
||||
}
|
||||
|
||||
@ -105,9 +107,9 @@ public class ChunkCoordinatorBuilder {
|
||||
Preconditions.checkNotNull(this.chunkConsumer, "No chunk consumer was supplied");
|
||||
Preconditions.checkNotNull(this.whenDone, "No final action was supplied");
|
||||
Preconditions.checkNotNull(this.throwableConsumer, "No throwable consumer was supplied");
|
||||
return chunkCoordinatorFactory.create(this.maxIterationTime, this.initialBatchSize,
|
||||
this.chunkConsumer, this.world, this.requestedChunks, this.whenDone,
|
||||
this.throwableConsumer);
|
||||
return chunkCoordinatorFactory
|
||||
.create(this.maxIterationTime, this.initialBatchSize, this.chunkConsumer, this.world,
|
||||
this.requestedChunks, this.whenDone, this.throwableConsumer);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -65,43 +65,79 @@ public class DelegateQueueCoordinator extends QueueCoordinator {
|
||||
}
|
||||
|
||||
@Override public boolean setBlock(int x, int y, int z, Pattern pattern) {
|
||||
return parent.setBlock(x, y, z, pattern);
|
||||
if (parent != null) {
|
||||
return parent.setBlock(x, y, z, pattern);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override public boolean setBlock(int x, int y, int z, BaseBlock id) {
|
||||
return parent.setBlock(x, y, z, id);
|
||||
if (parent != null) {
|
||||
return parent.setBlock(x, y, z, id);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override public boolean setBlock(int x, int y, int z, BlockState id) {
|
||||
return parent.setBlock(x, y, z, id);
|
||||
if (parent != null) {
|
||||
return parent.setBlock(x, y, z, id);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override public BlockState getBlock(int x, int y, int z) {
|
||||
return parent.getBlock(x, y, z);
|
||||
if (parent != null) {
|
||||
return parent.getBlock(x, y, z);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override public boolean setBiome(int x, int z, BiomeType biome) {
|
||||
return parent.setBiome(x, z, biome);
|
||||
if (parent != null) {
|
||||
return parent.setBiome(x, z, biome);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override public boolean setBiome(int x, int y, int z, BiomeType biome) {
|
||||
return parent.setBiome(x, y, z, biome);
|
||||
if (parent != null) {
|
||||
return parent.setBiome(x, y, z, biome);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override public boolean isSettingBiomes() {
|
||||
return parent.isSettingBiomes();
|
||||
if (parent != null) {
|
||||
return parent.isSettingBiomes();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override public void regenChunk(int x, int z) {
|
||||
if (parent != null) {
|
||||
parent.regenChunk(x, z);
|
||||
}
|
||||
}
|
||||
|
||||
@Override public World getWorld() {
|
||||
return parent.getWorld();
|
||||
if (parent != null) {
|
||||
return parent.getWorld();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override public boolean setTile(int x, int y, int z, CompoundTag tag) {
|
||||
return parent.setTile(x, y, z, tag);
|
||||
if (parent != null) {
|
||||
return parent.setTile(x, y, z, tag);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override public boolean isSettingTiles() {
|
||||
return parent.isSettingTiles();
|
||||
if (parent != null) {
|
||||
return parent.isSettingTiles();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override public boolean enqueue() {
|
||||
@ -111,11 +147,27 @@ public class DelegateQueueCoordinator extends QueueCoordinator {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override public void start() {
|
||||
if (parent != null) {
|
||||
parent.start();
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void cancel() {
|
||||
if (parent != null) {
|
||||
parent.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void setCompleteTask(Runnable whenDone) {
|
||||
parent.setCompleteTask(whenDone);
|
||||
if (parent != null) {
|
||||
parent.setCompleteTask(whenDone);
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void setChunkConsumer(Consumer<BlockVector2> consumer) {
|
||||
parent.setChunkConsumer(consumer);
|
||||
if (parent != null) {
|
||||
parent.setChunkConsumer(consumer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -58,20 +58,23 @@ public class GlobalBlockQueue {
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Documentation needed.
|
||||
* Place an instance of {@link QueueCoordinator} into a list incase access is needed
|
||||
* and then start it.
|
||||
*
|
||||
* @param queue todo
|
||||
* @param queue {@link QueueCoordinator} instance to start.
|
||||
* @return true if added to queue, false otherwise
|
||||
*/
|
||||
public boolean enqueue(QueueCoordinator queue) {
|
||||
boolean success = false;
|
||||
if (queue.size() > 0 && !activeQueues.contains(queue)) {
|
||||
success = activeQueues.add(queue);
|
||||
queue.start();
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
public void dequeue(QueueCoordinator queue) {
|
||||
queue.cancel();
|
||||
activeQueues.remove(queue);
|
||||
}
|
||||
|
||||
|
@ -108,6 +108,8 @@ public abstract class QueueCoordinator {
|
||||
|
||||
public abstract boolean isSettingBiomes();
|
||||
|
||||
public abstract void regenChunk(int x, int z);
|
||||
|
||||
public abstract World getWorld();
|
||||
|
||||
public final void setModified() {
|
||||
@ -118,6 +120,10 @@ public abstract class QueueCoordinator {
|
||||
return blockQueue.enqueue(this);
|
||||
}
|
||||
|
||||
public abstract void start();
|
||||
|
||||
public abstract void cancel();
|
||||
|
||||
public abstract void setCompleteTask(Runnable whenDone);
|
||||
|
||||
public abstract void setChunkConsumer(Consumer<BlockVector2> consumer);
|
||||
|
Reference in New Issue
Block a user