Merge branch 'v6' into v7

This commit is contained in:
Alexander Brandes
2022-05-18 22:13:29 +02:00
18 changed files with 213 additions and 70 deletions

View File

@ -54,12 +54,23 @@ public class AugmentedUtils {
enabled = true;
}
public static boolean generate(
@Nullable Object chunkObject,
/**
* Generate an augmented world chunk at the given location. If a queue is given, the data will be written to it, else a new
* queue will be created and written to world. Returns true if generation occurred.
*
* @param world World name to generate data for. Must be a PlotSquared world containing one or more areas else nothing will
* happen.
* @param chunkX Chunk X position
* @param chunkZ Chunk Z position
* @param queue Queue to write to, if desired.
* @return true if generation occurred.
* @since 6.8.0
*/
public static boolean generateChunk(
final @NonNull String world,
final int chunkX,
final int chunkZ,
QueueCoordinator queue
@Nullable QueueCoordinator queue
) {
if (!enabled) {
return false;
@ -97,9 +108,6 @@ public class AugmentedUtils {
.platform()
.worldUtil()
.getWeWorld(world));
if (chunkObject != null) {
queue.setChunkObject(chunkObject);
}
}
QueueCoordinator primaryMask;
// coordinates
@ -157,13 +165,9 @@ public class AugmentedUtils {
}
generationResult = true;
}
if (chunkObject != null) {
primaryMask.setChunkObject(chunkObject);
}
if (chunkObject != null) {
secondaryMask.setChunkObject(chunkObject);
}
// This queue should not be enqueued as it is simply used to restrict block setting, and then delegate to the
// actual queue
ScopedQueueCoordinator scoped =
new ScopedQueueCoordinator(
secondaryMask,
@ -172,8 +176,6 @@ public class AugmentedUtils {
);
generator.generateChunk(scoped, area);
generator.populateChunk(scoped, area);
scoped.setForceSync(true);
scoped.enqueue();
}
if (enqueue) {
queue.enqueue();
@ -181,4 +183,19 @@ public class AugmentedUtils {
return generationResult;
}
/**
* @deprecated Use {@link AugmentedUtils#generateChunk(String, int, int, QueueCoordinator)} as chunkObject is not required
* in the above method
*/
@Deprecated(forRemoval = true, since = "6.8.0")
public static boolean generate(
@Nullable Object chunkObject,
final @NonNull String world,
final int chunkX,
final int chunkZ,
QueueCoordinator queue
) {
return generateChunk(world, chunkX, chunkZ, queue);
}
}

View File

@ -34,6 +34,7 @@ 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.util.SideEffectSet;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
@ -61,6 +62,7 @@ public abstract class BasicQueueCoordinator extends QueueCoordinator {
private int lastX = Integer.MIN_VALUE;
private int lastZ = Integer.MIN_VALUE;
private boolean settingBiomes = false;
private boolean disableBiomes = false;
private boolean settingTiles = false;
private boolean regen = false;
private int[] regenStart;
@ -68,7 +70,8 @@ public abstract class BasicQueueCoordinator extends QueueCoordinator {
private CuboidRegion regenRegion = null;
private Consumer<BlockVector2> consumer = null;
private boolean unloadAfter = true;
private Runnable whenDone;
private Runnable whenDone = null;
private SideEffectSet sideEffectSet = null;
@Nullable
private LightingMode lightingMode = LightingMode.valueOf(Settings.QUEUE.LIGHTING_MODE);
@ -120,6 +123,9 @@ public abstract class BasicQueueCoordinator extends QueueCoordinator {
@SuppressWarnings("removal")
@Override
public boolean setBiome(int x, int z, @NonNull BiomeType biomeType) {
if (disableBiomes) {
return false;
}
LocalChunk chunk = getChunk(x >> 4, z >> 4);
for (int y = world.getMinY(); y <= world.getMaxY(); y++) {
chunk.setBiome(x & 15, y, z & 15, biomeType);
@ -130,6 +136,9 @@ public abstract class BasicQueueCoordinator extends QueueCoordinator {
@Override
public final boolean setBiome(int x, int y, int z, @NonNull BiomeType biomeType) {
if (disableBiomes) {
return false;
}
LocalChunk chunk = getChunk(x >> 4, z >> 4);
chunk.setBiome(x & 15, y, z & 15, biomeType);
settingBiomes = true;
@ -141,6 +150,12 @@ public abstract class BasicQueueCoordinator extends QueueCoordinator {
return this.settingBiomes;
}
@Override
public void setBiomesEnabled(boolean settingBiomes) {
this.settingBiomes = settingBiomes;
this.disableBiomes = true;
}
@Override
public boolean setTile(int x, int y, int z, @NonNull CompoundTag tag) {
LocalChunk chunk = getChunk(x >> 4, z >> 4);
@ -315,6 +330,29 @@ public abstract class BasicQueueCoordinator extends QueueCoordinator {
this.whenDone = whenDone;
}
@Override
public SideEffectSet getSideEffectSet() {
return sideEffectSet;
}
@Override
public void setSideEffectSet(SideEffectSet sideEffectSet) {
this.sideEffectSet = sideEffectSet;
}
// Don't ask about the @NonNull placement. That's how it needs to be else it errors.
@Override
public void setBiomeCuboid(
final com.plotsquared.core.location.@NonNull Location pos1,
final com.plotsquared.core.location.@NonNull Location pos2,
@NonNull final BiomeType biome
) {
if (disableBiomes) {
return;
}
super.setBiomeCuboid(pos1, pos2, biome);
}
/**
* Get the {@link LocalChunk} from the queue at the given chunk coordinates. Returns a new instance if one doesn't exist
*/

View File

@ -64,7 +64,7 @@ public class BlockArrayCacheScopedQueueCoordinator extends ScopedQueueCoordinato
*
* @param min Inclusive location of the minimum point to limit the scope to.
* @param max Inclusive location of the maximum point to limit the scope to.
* @since TODO
* @since 6.8.0
*/
public BlockArrayCacheScopedQueueCoordinator(Location min, Location max) {
super(null, min, max);

View File

@ -41,7 +41,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
*
* @deprecated This class is poorly designed and will no longer be used in P2
*/
@Deprecated(forRemoval = true, since = "TODO")
@Deprecated(forRemoval = true, since = "6.8.0")
public class ChunkQueueCoordinator extends ScopedQueueCoordinator {
public final BiomeType[][][] biomeResult;

View File

@ -32,6 +32,7 @@ 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.SideEffectSet;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
@ -135,6 +136,13 @@ public class DelegateQueueCoordinator extends QueueCoordinator {
return false;
}
@Override
public void setBiomesEnabled(final boolean enabled) {
if (parent != null) {
parent.setBiomesEnabled(enabled);
}
}
@Override
public boolean setEntity(@NonNull Entity entity) {
if (parent != null) {
@ -248,6 +256,21 @@ public class DelegateQueueCoordinator extends QueueCoordinator {
}
}
@Override
public SideEffectSet getSideEffectSet() {
if (parent != null) {
return parent.getSideEffectSet();
}
return null;
}
@Override
public void setSideEffectSet(final SideEffectSet sideEffectSet) {
if (parent != null) {
parent.setSideEffectSet(sideEffectSet);
}
}
@Override
public @NonNull List<BlockVector2> getReadChunks() {
if (parent != null) {

View File

@ -35,6 +35,7 @@ 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.SideEffectSet;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
@ -248,6 +249,14 @@ public abstract class QueueCoordinator {
*/
public abstract boolean isSettingBiomes();
/**
* If the queue should accept biome placement
*
* @param enabled If biomes should be enabled
* @since 6.8.0
*/
public abstract void setBiomesEnabled(boolean enabled);
/**
* Add entities to be created
*
@ -413,6 +422,20 @@ public abstract class QueueCoordinator {
*/
public abstract void setLightingMode(@Nullable LightingMode mode);
/**
* Get the overriding {@link SideEffectSet} to be used by the queue if it exists, else null
*
* @return Overriding {@link SideEffectSet} or null
*/
public abstract @Nullable SideEffectSet getSideEffectSet();
/**
* Set the overriding {@link SideEffectSet} to be used by the queue. Null to use default side effects.
*
* @param sideEffectSet side effects to override with, or null to use default
*/
public abstract void setSideEffectSet(@Nullable SideEffectSet sideEffectSet);
/**
* Fill a cuboid between two positions with a BlockState
*

View File

@ -40,21 +40,18 @@ import org.checkerframework.checker.nullness.qual.Nullable;
*
* @deprecated This should be renamed to NormalizedScopedQueueCoordinator or something.
*/
@Deprecated(forRemoval = true, since = "TODO")
@Deprecated(forRemoval = true, since = "6.8.0")
public class ScopedQueueCoordinator extends DelegateQueueCoordinator {
private final Location min;
private final Location max;
private final int minX;
private final int minY;
private final int minZ;
private final int maxX;
private final int maxY;
private final int maxZ;
private final int dx;
private final int dy;
private final int dz;
/**
@ -65,15 +62,12 @@ public class ScopedQueueCoordinator extends DelegateQueueCoordinator {
this.min = min;
this.max = max;
this.minX = min.getX();
this.minY = min.getY();
this.minZ = min.getZ();
this.maxX = max.getX();
this.maxY = max.getY();
this.maxZ = max.getZ();
this.dx = maxX - minX;
this.dy = maxY - minY;
this.dz = maxZ - minZ;
}
@ -84,11 +78,11 @@ public class ScopedQueueCoordinator extends DelegateQueueCoordinator {
@Override
public boolean setBiome(int x, int y, int z, @NonNull BiomeType biome) {
return x >= 0 && x <= dx && y >= 0 && y <= dy && z >= 0 && z <= dz && super.setBiome(x + minX, y + minY, z + minZ, biome);
return x >= 0 && x <= dx && z >= 0 && z <= dz && super.setBiome(x + minX, y, z + minZ, biome);
}
public void fillBiome(BiomeType biome) {
for (int y = 0; y <= dy; y++) {
for (int y = min.getY(); y <= max.getY(); y++) {
for (int x = 0; x <= dx; x++) {
for (int z = 0; z < dz; z++) {
setBiome(x, y, z, biome);
@ -99,27 +93,22 @@ public class ScopedQueueCoordinator extends DelegateQueueCoordinator {
@Override
public boolean setBlock(int x, int y, int z, @NonNull BaseBlock id) {
return x >= 0 && x <= dx && y >= 0 && y <= dy && z >= 0 && z <= dz && super.setBlock(x + minX, y + minY, z + minZ, id);
return x >= 0 && x <= dx && z >= 0 && z <= dz && super.setBlock(x + minX, y, z + minZ, id);
}
@Override
public boolean setBlock(int x, int y, int z, @NonNull BlockState id) {
return x >= 0 && x <= dx && y >= 0 && y <= dy && z >= 0 && z <= dz && super.setBlock(x + minX, y + minY, z + minZ, id);
return x >= 0 && x <= dx && z >= 0 && z <= dz && super.setBlock(x + minX, y, z + minZ, id);
}
@Override
public boolean setBlock(int x, int y, int z, @NonNull Pattern pattern) {
return x >= 0 && x <= dx && y >= 0 && y <= dy && z >= 0 && z <= dz && super.setBlock(
x + minX,
y + minY,
z + minZ,
pattern
);
return x >= 0 && x <= dx && z >= 0 && z <= dz && super.setBlock(x + minX, y, z + minZ, pattern);
}
@Override
public boolean setTile(int x, int y, int z, @NonNull CompoundTag tag) {
return x >= 0 && x <= dx && y >= 0 && y <= dy && z >= 0 && z <= dz && super.setTile(x + minX, y + minY, z + minZ, tag);
return x >= 0 && x <= dx && z >= 0 && z <= dz && super.setTile(x + minX, y, z + minZ, tag);
}
public @NonNull Location getMin() {

View File

@ -34,6 +34,7 @@ import java.util.HashMap;
public abstract class SetupUtils {
public static HashMap<String, GeneratorWrapper<?>> generators = new HashMap<>();
protected boolean loaded = false;
/**
* @since 6.1.0