Fix augmented generation

This commit is contained in:
Alexander Söderberg 2020-04-08 04:10:22 +02:00
parent 1522632f5a
commit ef04ed9151
5 changed files with 47 additions and 10 deletions

View file

@ -518,7 +518,7 @@ public class BukkitUtil extends WorldUtil {
}
private static void ensureLoaded(final String world, final int x, final int z, final Consumer<Chunk> chunkConsumer) {
PaperLib.getChunkAtAsync(getWorld(world), x << 4, z << 4, true).thenAccept(chunk ->
PaperLib.getChunkAtAsync(getWorld(world), x >> 4, z >> 4, true).thenAccept(chunk ->
ensureMainThread(chunkConsumer, chunk));
}

View file

@ -142,13 +142,17 @@ public class BukkitLocalQueue extends BasicLocalBlockQueue {
}
private Chunk getChunk(final World world, final LocalChunk localChunk) {
Chunk chunk = null;
if (this.getChunkObject() != null && this.getChunkObject() instanceof Chunk) {
final Chunk chunk = (Chunk) this.getChunkObject();
if (chunk.getWorld().equals(world) && chunk.getX() == localChunk.getX() && chunk.getZ() == localChunk.getZ()) {
return chunk;
}
chunk = (Chunk) this.getChunkObject();
}
return world.getChunkAt(localChunk.getX(), localChunk.getZ());
if (chunk == null) {
chunk = world.getChunkAt(localChunk.getX(), localChunk.getZ());
}
if (!chunk.isLoaded()) {
chunk.load(true);
}
return chunk;
}
private void setMaterial(@NonNull final BlockState plotBlock, @NonNull final Block block) {

View file

@ -11,8 +11,11 @@ import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue
import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue;
import com.github.intellectualsites.plotsquared.plot.util.block.ScopedLocalBlockQueue;
import com.github.intellectualsites.plotsquared.plot.util.world.RegionUtil;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypes;
import org.jetbrains.annotations.NotNull;
@ -121,6 +124,24 @@ public class AugmentedUtils {
return false;
}
@Override public boolean setBlock(int x, int y, int z, BaseBlock id) {
try {
if (canPlace[x - blockX][z - blockZ]) {
return super.setBlock(x, y, z, id);
}
} catch (final Exception e) {
PlotSquared.debug(String.format("Failed to set block at: %d;%d;%d (to = %s) with offset %d;%d."
+ " Translated to: %d;%d", x, y, z, id, blockX, blockZ, x - blockX, z - blockZ));
throw e;
}
return false;
}
@Override public boolean setBlock(int x, int y, int z, Pattern pattern) {
final BlockVector3 blockVector3 = BlockVector3.at(x + blockX, y, z + blockZ);
return this.setBlock(x, y, z, pattern.apply(blockVector3));
}
@Override public boolean setBiome(int x, int y, BiomeType biome) {
return super.setBiome(x, y, biome);
}
@ -141,9 +162,8 @@ public class AugmentedUtils {
secondaryMask.setChunkObject(chunkObject);
secondaryMask.setForceSync(true);
ScopedLocalBlockQueue scoped = new ScopedLocalBlockQueue(secondaryMask,
new Location(area.getWorldName(), blockX, 0, blockZ),
new Location(area.getWorldName(), blockX + 15, 255, blockZ + 15));
ScopedLocalBlockQueue scoped = new ScopedLocalBlockQueue(secondaryMask, new Location(world, blockX, 0, blockZ),
new Location(world, blockX + 15, 255, blockZ + 15));
generator.generateChunk(scoped, area);
generator.populateChunk(scoped, area);
}

View file

@ -12,6 +12,11 @@ public class DelegateLocalBlockQueue extends LocalBlockQueue {
public DelegateLocalBlockQueue(LocalBlockQueue parent) {
super(parent == null ? null : parent.getWorld());
this.parent = parent;
if (parent != null) {
this.setForceSync(parent.isForceSync());
this.setChunkObject(parent.getChunkObject());
}
}
public LocalBlockQueue getParent() {

View file

@ -6,6 +6,7 @@ import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
import com.github.intellectualsites.plotsquared.plot.object.PlotManager;
import com.github.intellectualsites.plotsquared.plot.object.RunnableVal3;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
@ -36,8 +37,10 @@ public class ScopedLocalBlockQueue extends DelegateLocalBlockQueue {
this.dx = maxX - minX;
this.dy = maxY - minY;
this.dz = maxZ - minZ;
}
this.setForceSync(parent.isForceSync());
this.setChunkObject(parent.getChunkObject());
}
@Override public boolean setBiome(int x, int z, BiomeType biome) {
return x >= 0 && x <= dx && z >= 0 && z <= dz && super.setBiome(x + minX, z + minZ, biome);
@ -61,6 +64,11 @@ public class ScopedLocalBlockQueue extends DelegateLocalBlockQueue {
.setBlock(x + minX, y + minY, z + minZ, id);
}
@Override public boolean setBlock(int x, int y, int z, Pattern pattern) {
return x >= 0 && x <= dx && y >= 0 && y <= dy && z >= 0 && z <= dz && super
.setBlock(x + minX, y + minY, z + minZ, pattern);
}
public Location getMin() {
return new Location(getWorld(), minX, minY, minZ);
}