mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-23 01:37:37 +00:00
Docs, command, and formatting changes.
This commit is contained in:
parent
21a8899ba8
commit
5c6c41a95a
@ -42,6 +42,10 @@ import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
public class BukkitQueue extends SimpleCharQueueExtent {
|
||||
@ -94,7 +98,7 @@ public class BukkitQueue extends SimpleCharQueueExtent {
|
||||
// };
|
||||
|
||||
@Override
|
||||
public IChunk create(boolean full) {
|
||||
public IChunk create(boolean isFull) {
|
||||
// if (full) {
|
||||
// //TODO implement
|
||||
// return FULL_CHUNKS.get();
|
||||
|
@ -5,18 +5,19 @@ import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class ArrayFilterBlock extends SimpleFilterBlock {
|
||||
|
||||
private final char[] blocks;
|
||||
private final byte[] heights;
|
||||
private final int yOffset;
|
||||
private final int width, length;
|
||||
private int x, z, index;
|
||||
private char ordinal;
|
||||
private final int width, length;
|
||||
|
||||
public ArrayFilterBlock(Extent extent, char[] blocks, byte[] heights, int width, int length, int yOffset) {
|
||||
public ArrayFilterBlock(Extent extent, char[] blocks, byte[] heights, int width, int length,
|
||||
int yOffset) {
|
||||
super(extent);
|
||||
this.blocks = blocks;
|
||||
this.width = width;
|
||||
@ -34,43 +35,44 @@ public class ArrayFilterBlock extends SimpleFilterBlock {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOrdinal(int ordinal) {
|
||||
blocks[index] = (char) ordinal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlock(BlockState state) {
|
||||
blocks[index] = state.getOrdinalChar();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFullBlock(BaseBlock block) {
|
||||
blocks[index] = block.getOrdinalChar();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrdinal() {
|
||||
return ordinal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOrdinal(int ordinal) {
|
||||
blocks[index] = (char) ordinal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getBlock() {
|
||||
return BlockTypes.states[ordinal];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlock(BlockState state) {
|
||||
blocks[index] = state.getOrdinalChar();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBlock getFullBlock() {
|
||||
return getBlock().toBaseBlock();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFullBlock(BaseBlock block) {
|
||||
blocks[index] = block.getOrdinalChar();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag getNbtData() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNbtData(@Nullable CompoundTag nbtData) {}
|
||||
public void setNbtData(@Nullable CompoundTag nbtData) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getX() {
|
||||
|
@ -12,39 +12,54 @@ import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
import com.sk89q.worldedit.world.registry.BlockMaterial;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class CharFilterBlock extends ChunkFilterBlock {
|
||||
|
||||
private static final SetDelegate FULL = new SetDelegate() {
|
||||
@Override
|
||||
public final void set(CharFilterBlock block, char value) {
|
||||
block.setArr[block.index] = value;
|
||||
}
|
||||
};
|
||||
private static final SetDelegate NULL = new SetDelegate() {
|
||||
@Override
|
||||
public void set(CharFilterBlock block, char value) {
|
||||
block.initSet().set(block, value);
|
||||
}
|
||||
};
|
||||
private CharGetBlocks get;
|
||||
private IChunkSet set;
|
||||
|
||||
private char[] getArr;
|
||||
private @Nullable char[] setArr;
|
||||
private @Nullable
|
||||
char[] setArr;
|
||||
private SetDelegate delegate;
|
||||
|
||||
// local
|
||||
private int layer, index, x, y, z, xx, yy, zz, X, Z;
|
||||
private int layer, index, x, y, z, xx, yy, zz, chunkX, chunkZ;
|
||||
|
||||
public CharFilterBlock(IQueueExtent queueExtent) {
|
||||
super(queueExtent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final ChunkFilterBlock init(final int chunkX, final int chunkZ, final IChunkGet chunk) {
|
||||
public final ChunkFilterBlock init(int chunkX, int chunkZ, IChunkGet chunk) {
|
||||
this.get = (CharGetBlocks) chunk;
|
||||
this.X = chunkX;
|
||||
this.Z = chunkZ;
|
||||
this.chunkX = chunkX;
|
||||
this.chunkZ = chunkZ;
|
||||
this.xx = chunkX << 4;
|
||||
this.zz = chunkZ << 4;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void flood(final IChunkGet iget, final IChunkSet iset, final int layer, Flood flood, FilterBlockMask mask) {
|
||||
@Override
|
||||
public void flood(IChunkGet iget, IChunkSet iset, int layer, Flood flood,
|
||||
FilterBlockMask mask) {
|
||||
final int maxDepth = flood.getMaxDepth();
|
||||
final boolean checkDepth = maxDepth < Character.MAX_VALUE;
|
||||
if (init(iget, iset, layer) != null) {
|
||||
while ((index = flood.poll()) != -1) {
|
||||
x = index & 15;
|
||||
z = (index >> 4) & 15;
|
||||
y = (index >> 8) & 15;
|
||||
z = index >> 4 & 15;
|
||||
y = index >> 8 & 15;
|
||||
|
||||
if (mask.applyBlock(this)) {
|
||||
int depth = index >> 12;
|
||||
@ -60,10 +75,13 @@ public class CharFilterBlock extends ChunkFilterBlock {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final ChunkFilterBlock init(final IChunkGet iget, final IChunkSet iset, final int layer) {
|
||||
public final ChunkFilterBlock init(IChunkGet iget, IChunkSet iset,
|
||||
int layer) {
|
||||
this.layer = layer;
|
||||
final CharGetBlocks get = (CharGetBlocks) iget;
|
||||
if (!get.hasSection(layer)) return null;
|
||||
if (!get.hasSection(layer)) {
|
||||
return null;
|
||||
}
|
||||
this.set = iset;
|
||||
getArr = get.sections[layer].get(get, layer);
|
||||
if (set.hasSection(layer)) {
|
||||
@ -82,13 +100,13 @@ public class CharFilterBlock extends ChunkFilterBlock {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.index = x | (z << 4) | (y << 8);
|
||||
this.index = x | z << 4 | y << 8;
|
||||
filter.applyBlock(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void filter(Filter filter, int yStart, int yEnd) {
|
||||
for (y = yStart, index = (yStart << 8); y < yEnd; y++) {
|
||||
for (y = yStart, index = yStart << 8; y < yEnd; y++) {
|
||||
for (z = 0; z < 16; z++) {
|
||||
for (x = 0; x < 16; x++, index++) {
|
||||
filter.applyBlock(this);
|
||||
@ -99,8 +117,8 @@ public class CharFilterBlock extends ChunkFilterBlock {
|
||||
|
||||
@Override
|
||||
public void filter(Filter filter, int minX, int minY, int minZ, int maxX, int maxY, int maxZ) {
|
||||
int yis = (minY << 8);
|
||||
int zis = (minZ << 4);
|
||||
int yis = minY << 8;
|
||||
int zis = minZ << 4;
|
||||
for (y = minY, index = yis; y <= maxY; y++) {
|
||||
for (z = minZ, index += zis; z <= maxZ; z++) {
|
||||
for (x = minX, index += minX; x <= maxX; x++, index++) {
|
||||
@ -111,7 +129,7 @@ public class CharFilterBlock extends ChunkFilterBlock {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void filter(final Filter filter, final Region region) {
|
||||
public final void filter(Filter filter, Region region) {
|
||||
for (y = 0, index = 0; y < 16; y++) {
|
||||
int absY = yy + y;
|
||||
for (z = 0; z < 16; z++) {
|
||||
@ -127,7 +145,7 @@ public class CharFilterBlock extends ChunkFilterBlock {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void filter(final Filter filter) {
|
||||
public final void filter(Filter filter) {
|
||||
for (y = 0, index = 0; y < 16; y++) {
|
||||
for (z = 0; z < 16; z++) {
|
||||
for (x = 0; x < 16; x++, index++) {
|
||||
@ -142,25 +160,6 @@ public class CharFilterBlock extends ChunkFilterBlock {
|
||||
set.setBiome(x, y, z, biome);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOrdinal(final int ordinal) {
|
||||
delegate.set(this, (char) ordinal);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlock(final BlockState state) {
|
||||
delegate.set(this, state.getOrdinalChar());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFullBlock(final BaseBlock block) {
|
||||
delegate.set(this, block.getOrdinalChar());
|
||||
final CompoundTag nbt = block.getNbtData();
|
||||
if (nbt != null) { // TODO optimize check via ImmutableBaseBlock
|
||||
set.setTile(x, yy + y, z, nbt);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int getX() {
|
||||
return xx + x;
|
||||
@ -193,12 +192,12 @@ public class CharFilterBlock extends ChunkFilterBlock {
|
||||
|
||||
@Override
|
||||
public final int getChunkX() {
|
||||
return X;
|
||||
return chunkX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int getChunkZ() {
|
||||
return Z;
|
||||
return chunkZ;
|
||||
}
|
||||
|
||||
public final char getOrdinalChar() {
|
||||
@ -210,12 +209,22 @@ public class CharFilterBlock extends ChunkFilterBlock {
|
||||
return getArr[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOrdinal(int ordinal) {
|
||||
delegate.set(this, (char) ordinal);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final BlockState getBlock() {
|
||||
final int ordinal = getArr[index];
|
||||
return BlockTypes.states[ordinal];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlock(BlockState state) {
|
||||
delegate.set(this, state.getOrdinalChar());
|
||||
}
|
||||
|
||||
@Override
|
||||
public final BaseBlock getFullBlock() {
|
||||
final BlockState state = getBlock();
|
||||
@ -227,10 +236,25 @@ public class CharFilterBlock extends ChunkFilterBlock {
|
||||
return state.toBaseBlock();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFullBlock(BaseBlock block) {
|
||||
delegate.set(this, block.getOrdinalChar());
|
||||
final CompoundTag nbt = block.getNbtData();
|
||||
if (nbt != null) { // TODO optimize check via ImmutableBaseBlock
|
||||
set.setTile(x, yy + y, z, nbt);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final CompoundTag getNbtData() {
|
||||
return get.getTag(x, y + (layer << 4), z);
|
||||
}
|
||||
/*
|
||||
NORTH(Vector3.at(0, 0, -1), Flag.CARDINAL, 3, 1),
|
||||
EAST(Vector3.at(1, 0, 0), Flag.CARDINAL, 0, 2),
|
||||
SOUTH(Vector3.at(0, 0, 1), Flag.CARDINAL, 1, 3),
|
||||
WEST(Vector3.at(-1, 0, 0), Flag.CARDINAL, 2, 0),
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void setNbtData(CompoundTag tag) {
|
||||
@ -245,12 +269,6 @@ public class CharFilterBlock extends ChunkFilterBlock {
|
||||
final BlockMaterial material = state.getMaterial();
|
||||
return material.hasContainer();
|
||||
}
|
||||
/*
|
||||
NORTH(Vector3.at(0, 0, -1), Flag.CARDINAL, 3, 1),
|
||||
EAST(Vector3.at(1, 0, 0), Flag.CARDINAL, 0, 2),
|
||||
SOUTH(Vector3.at(0, 0, 1), Flag.CARDINAL, 1, 3),
|
||||
WEST(Vector3.at(-1, 0, 0), Flag.CARDINAL, 2, 0),
|
||||
*/
|
||||
|
||||
@Override
|
||||
public final BlockState getBlockNorth() {
|
||||
@ -311,7 +329,7 @@ public class CharFilterBlock extends ChunkFilterBlock {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final BlockState getBlockRelativeY(final int y) {
|
||||
public final BlockState getBlockRelativeY(int y) {
|
||||
final int newY = this.y + y;
|
||||
final int layerAdd = newY >> 4;
|
||||
switch (layerAdd) {
|
||||
@ -353,7 +371,7 @@ public class CharFilterBlock extends ChunkFilterBlock {
|
||||
case -12:
|
||||
case -13:
|
||||
case -14:
|
||||
case -15: {
|
||||
case -15:
|
||||
final int newLayer = layer + layerAdd;
|
||||
if (newLayer >= 0) {
|
||||
final int index = this.index + ((y & 15) << 8);
|
||||
@ -361,7 +379,6 @@ public class CharFilterBlock extends ChunkFilterBlock {
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return BlockTypes.__RESERVED__.getDefaultState();
|
||||
}
|
||||
|
||||
@ -383,7 +400,7 @@ public class CharFilterBlock extends ChunkFilterBlock {
|
||||
|
||||
@Override
|
||||
public BiomeType getBiomeType(int x, int z) {
|
||||
if ((x >> 4) == X && (z >> 4) == Z) {
|
||||
if (x >> 4 == chunkX && z >> 4 == chunkZ) {
|
||||
return get.getBiomeType(x & 15, z & 15);
|
||||
}
|
||||
return getExtent().getBiomeType(x, z);
|
||||
@ -391,27 +408,14 @@ public class CharFilterBlock extends ChunkFilterBlock {
|
||||
|
||||
@Override
|
||||
public boolean setBiome(int x, int y, int z, BiomeType biome) {
|
||||
if ((x >> 4) == X && (z >> 4) == Z) {
|
||||
if (x >> 4 == chunkX && z >> 4 == chunkZ) {
|
||||
return set.setBiome(x & 15, y, z & 15, biome);
|
||||
}
|
||||
return getExtent().setBiome(x, y, z, biome);
|
||||
}
|
||||
|
||||
private interface SetDelegate {
|
||||
|
||||
void set(CharFilterBlock block, char value);
|
||||
}
|
||||
|
||||
private static final SetDelegate NULL = new SetDelegate() {
|
||||
@Override
|
||||
public void set(final CharFilterBlock block, final char value) {
|
||||
block.initSet().set(block, value);
|
||||
}
|
||||
};
|
||||
|
||||
private static final SetDelegate FULL = new SetDelegate() {
|
||||
@Override
|
||||
public final void set(final CharFilterBlock block, final char value) {
|
||||
block.setArr[block.index] = value;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -4,24 +4,28 @@ import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
|
||||
public abstract class ChunkFilterBlock extends SimpleFilterBlock {
|
||||
|
||||
public ChunkFilterBlock(Extent extent) {
|
||||
super(extent);
|
||||
}
|
||||
|
||||
public abstract ChunkFilterBlock init(int chunkX, int chunkZ, IChunkGet chunk);
|
||||
|
||||
public abstract ChunkFilterBlock init(final IChunkGet iget, final IChunkSet iset, final int layer);
|
||||
public abstract ChunkFilterBlock init(IChunkGet iget, IChunkSet iset,
|
||||
int layer);
|
||||
|
||||
public abstract void flood(final IChunkGet iget, final IChunkSet iset, final int layer, Flood flood, FilterBlockMask mask);
|
||||
public abstract void flood(IChunkGet iget, IChunkSet iset, int layer,
|
||||
Flood flood, FilterBlockMask mask);
|
||||
|
||||
|
||||
public abstract void filter(Filter filter, int x, int y, int z);
|
||||
|
||||
public abstract void filter(Filter filter, int minX, int minY, int minZ, int maxX, int maxY, int maxZ);
|
||||
public abstract void filter(Filter filter, int minX, int minY, int minZ, int maxX, int maxY,
|
||||
int maxZ);
|
||||
|
||||
public abstract void filter(Filter filter);
|
||||
|
||||
public abstract void filter(Filter filter, int yStart, int yEnd);
|
||||
|
||||
public abstract void filter(final Filter filter, final Region region);
|
||||
public abstract void filter(Filter filter, Region region);
|
||||
}
|
||||
|
@ -6,11 +6,12 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
public class ChunkFuture implements Future<Void> {
|
||||
|
||||
private final IChunk chunk;
|
||||
private volatile boolean cancelled;
|
||||
private volatile boolean done;
|
||||
|
||||
public ChunkFuture(final IChunk chunk) {
|
||||
public ChunkFuture(IChunk chunk) {
|
||||
this.chunk = chunk;
|
||||
}
|
||||
|
||||
@ -19,10 +20,9 @@ public class ChunkFuture implements Future<Void> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean cancel(final boolean mayInterruptIfRunning) {
|
||||
public boolean cancel(boolean mayInterruptIfRunning) {
|
||||
cancelled = true;
|
||||
if (done) return false;
|
||||
return true;
|
||||
return !done;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -46,7 +46,8 @@ public class ChunkFuture implements Future<Void> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void get(final long timeout, final TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
|
||||
public Void get(long timeout, TimeUnit unit)
|
||||
throws InterruptedException, ExecutionException, TimeoutException {
|
||||
synchronized (chunk) {
|
||||
if (!done) {
|
||||
this.wait(unit.toMillis(timeout));
|
||||
|
@ -1,11 +1,13 @@
|
||||
package com.boydti.fawe.beta;
|
||||
|
||||
public class DelegateFilter<T extends Filter> implements IDelegateFilter {
|
||||
|
||||
private final Filter parent;
|
||||
|
||||
public DelegateFilter(T parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getParent() {
|
||||
return (T) parent;
|
||||
|
@ -24,43 +24,35 @@ import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class DelegateFilterBlock extends FilterBlock {
|
||||
|
||||
private final FilterBlock parent;
|
||||
|
||||
public DelegateFilterBlock(FilterBlock parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public static BlockVector3 at(double x, double y, double z) {
|
||||
return BlockVector3.at(x, y, z);
|
||||
}
|
||||
|
||||
public static BlockVector3 at(int x, int y, int z) {
|
||||
return BlockVector3.at(x, y, z);
|
||||
}
|
||||
|
||||
public static Comparator<BlockVector3> sortByCoordsYzx() {
|
||||
return BlockVector3.sortByCoordsYzx();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Extent getExtent() {
|
||||
return parent.getExtent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOrdinal(int ordinal) {
|
||||
parent.setOrdinal(ordinal);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlock(BlockState state) {
|
||||
parent.setBlock(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFullBlock(BaseBlock block) {
|
||||
parent.setFullBlock(block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNbtData(@Nullable CompoundTag nbtData) {
|
||||
parent.setNbtData(nbtData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNbtData() {
|
||||
return parent.hasNbtData();
|
||||
@ -76,21 +68,41 @@ public class DelegateFilterBlock extends FilterBlock {
|
||||
return parent.getOrdinal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOrdinal(int ordinal) {
|
||||
parent.setOrdinal(ordinal);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getBlock() {
|
||||
return parent.getBlock();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlock(BlockState state) {
|
||||
parent.setBlock(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBlock getFullBlock() {
|
||||
return parent.getFullBlock();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFullBlock(BaseBlock block) {
|
||||
parent.setFullBlock(block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag getNbtData() {
|
||||
return parent.getNbtData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNbtData(@Nullable CompoundTag nbtData) {
|
||||
parent.setNbtData(nbtData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockVector3 getMinimumPoint() {
|
||||
return parent.getMinimumPoint();
|
||||
@ -241,18 +253,6 @@ public class DelegateFilterBlock extends FilterBlock {
|
||||
return parent.getStateRelativeY(orDefault, y);
|
||||
}
|
||||
|
||||
public static BlockVector3 at(double x, double y, double z) {
|
||||
return BlockVector3.at(x, y, z);
|
||||
}
|
||||
|
||||
public static BlockVector3 at(int x, int y, int z) {
|
||||
return BlockVector3.at(x, y, z);
|
||||
}
|
||||
|
||||
public static Comparator<BlockVector3> sortByCoordsYzx() {
|
||||
return BlockVector3.sortByCoordsYzx();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MutableBlockVector3 setComponents(double x, double y, double z) {
|
||||
return parent.setComponents(x, y, z);
|
||||
@ -479,7 +479,8 @@ public class DelegateFilterBlock extends FilterBlock {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockVector3 transform2D(double angle, double aboutX, double aboutZ, double translateX, double translateZ) {
|
||||
public BlockVector3 transform2D(double angle, double aboutX, double aboutZ, double translateX,
|
||||
double translateZ) {
|
||||
return parent.transform2D(angle, aboutX, aboutZ, translateX, translateZ);
|
||||
}
|
||||
|
||||
@ -560,7 +561,8 @@ public class DelegateFilterBlock extends FilterBlock {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY, boolean ignoreAir) {
|
||||
public int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY,
|
||||
boolean ignoreAir) {
|
||||
return parent.getNearestSurfaceTerrainBlock(x, z, y, minY, maxY, ignoreAir);
|
||||
}
|
||||
|
||||
@ -570,18 +572,23 @@ public class DelegateFilterBlock extends FilterBlock {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY, int failedMin, int failedMax) {
|
||||
public int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY, int failedMin,
|
||||
int failedMax) {
|
||||
return parent.getNearestSurfaceTerrainBlock(x, z, y, minY, maxY, failedMin, failedMax);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY, int failedMin, int failedMax, Mask mask) {
|
||||
return parent.getNearestSurfaceTerrainBlock(x, z, y, minY, maxY, failedMin, failedMax, mask);
|
||||
public int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY, int failedMin,
|
||||
int failedMax, Mask mask) {
|
||||
return parent
|
||||
.getNearestSurfaceTerrainBlock(x, z, y, minY, maxY, failedMin, failedMax, mask);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY, int failedMin, int failedMax, boolean ignoreAir) {
|
||||
return parent.getNearestSurfaceTerrainBlock(x, z, y, minY, maxY, failedMin, failedMax, ignoreAir);
|
||||
public int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY, int failedMin,
|
||||
int failedMax, boolean ignoreAir) {
|
||||
return parent
|
||||
.getNearestSurfaceTerrainBlock(x, z, y, minY, maxY, failedMin, failedMax, ignoreAir);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -595,12 +602,14 @@ public class DelegateFilterBlock extends FilterBlock {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSchems(Region region, Mask mask, List<ClipboardHolder> clipboards, int rarity, boolean rotate) throws WorldEditException {
|
||||
public void addSchems(Region region, Mask mask, List<ClipboardHolder> clipboards, int rarity,
|
||||
boolean rotate) throws WorldEditException {
|
||||
parent.addSchems(region, mask, clipboards, rarity, rotate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void spawnResource(Region region, Resource gen, int rarity, int frequency) throws WorldEditException {
|
||||
public void spawnResource(Region region, Resource gen, int rarity, int frequency)
|
||||
throws WorldEditException {
|
||||
parent.spawnResource(region, gen, rarity, frequency);
|
||||
}
|
||||
|
||||
@ -610,7 +619,8 @@ public class DelegateFilterBlock extends FilterBlock {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addOre(Region region, Mask mask, Pattern material, int size, int frequency, int rarity, int minY, int maxY) throws WorldEditException {
|
||||
public void addOre(Region region, Mask mask, Pattern material, int size, int frequency,
|
||||
int rarity, int minY, int maxY) throws WorldEditException {
|
||||
parent.addOre(region, mask, material, size, frequency, rarity, minY, maxY);
|
||||
}
|
||||
|
||||
@ -671,12 +681,14 @@ public class DelegateFilterBlock extends FilterBlock {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends BlockStateHolder<T>> boolean setBlock(BlockVector3 position, T block) throws WorldEditException {
|
||||
public <T extends BlockStateHolder<T>> boolean setBlock(BlockVector3 position, T block)
|
||||
throws WorldEditException {
|
||||
return parent.setBlock(position, block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends BlockStateHolder<T>> boolean setBlock(int x, int y, int z, T block) throws WorldEditException {
|
||||
public <T extends BlockStateHolder<T>> boolean setBlock(int x, int y, int z, T block)
|
||||
throws WorldEditException {
|
||||
return parent.setBlock(x, y, z, block);
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.boydti.fawe.beta;
|
||||
|
||||
public interface DirectionMask {
|
||||
|
||||
boolean apply(int fromX, int fromY, int fromZ, int toX, int toY, int toZ);
|
||||
}
|
||||
|
@ -2,31 +2,33 @@ package com.boydti.fawe.beta;
|
||||
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import javax.annotation.Nullable;
|
||||
import org.jetbrains.annotations.Range;
|
||||
|
||||
/**
|
||||
* A filter is an interface used for setting blocks
|
||||
* A filter is an interface used for setting blocks.
|
||||
*/
|
||||
public interface Filter {
|
||||
|
||||
/**
|
||||
* Checks whether a chunk should be read.
|
||||
*
|
||||
* @param chunkX
|
||||
* @param chunkZ
|
||||
* @param chunkX the x coordinate in the chunk
|
||||
* @param chunkZ the z coordinate in the chunk
|
||||
* @return
|
||||
*/
|
||||
default boolean appliesChunk(final int chunkX, final int chunkZ) {
|
||||
default boolean appliesChunk(@Range(from = 0, to = 15) int chunkX,
|
||||
@Range(from = 0, to = 15) int chunkZ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Do something with the IChunk<br>
|
||||
* - Return null if you don't want to filter blocks<br>
|
||||
* - Return the chunk if you do want to filter blocks<br>
|
||||
* Do something with the IChunk<br> - Return null if you don't want to filter blocks<br> -
|
||||
* Return the chunk if you do want to filter blocks<br>
|
||||
*
|
||||
* @param chunk
|
||||
* @return
|
||||
*/
|
||||
default IChunk applyChunk(final IChunk chunk, @Nullable Region region) {
|
||||
default IChunk applyChunk(IChunk chunk, @Nullable Region region) {
|
||||
return chunk;
|
||||
}
|
||||
|
||||
@ -35,27 +37,27 @@ public interface Filter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Make changes to the block here<br>
|
||||
* - e.g. block.setId(...)<br>
|
||||
* - Note: Performance is critical here<br>
|
||||
* Make changes to the block here<br> - e.g. block.setId(...)<br> - Note: Performance is
|
||||
* critical here<br>
|
||||
*
|
||||
* @param block
|
||||
*/
|
||||
default void applyBlock(final FilterBlock block) {
|
||||
default void applyBlock(FilterBlock block) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Do something with the IChunk after block filtering<br>
|
||||
* Do something with the IChunk after block filtering.
|
||||
*
|
||||
* @param chunk
|
||||
* @return
|
||||
*/
|
||||
default void finishChunk(final IChunk chunk) {
|
||||
default void finishChunk(IChunk chunk) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Fork this for use by another thread
|
||||
* - Typically filters are simple and don't need to create another copy to be thread safe here
|
||||
* Fork this for use by another thread - Typically filters are simple and don't need to create
|
||||
* another copy to be thread safe here
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
default Filter fork() {
|
||||
|
@ -7,34 +7,35 @@ import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static com.sk89q.worldedit.world.block.BlockTypes.states;
|
||||
|
||||
public abstract class FilterBlock extends BlockVector3 implements Extent, TileEntityBlock {
|
||||
|
||||
public abstract Extent getExtent();
|
||||
|
||||
public abstract void setOrdinal(int ordinal);
|
||||
|
||||
public abstract void setBlock(BlockState state);
|
||||
|
||||
public abstract void setFullBlock(BaseBlock block);
|
||||
|
||||
public void setBiome(BiomeType biome) {
|
||||
setBiome(getX(), getY(), getZ(), biome);
|
||||
}
|
||||
|
||||
public abstract int getOrdinal();
|
||||
|
||||
public abstract void setOrdinal(int ordinal);
|
||||
|
||||
public abstract BlockState getBlock();
|
||||
|
||||
public abstract void setBlock(BlockState state);
|
||||
|
||||
public abstract BaseBlock getFullBlock();
|
||||
|
||||
public abstract void setFullBlock(BaseBlock block);
|
||||
|
||||
@Override
|
||||
public abstract CompoundTag getNbtData();
|
||||
|
||||
@Override
|
||||
public abstract void setNbtData(@Nullable CompoundTag nbtData);
|
||||
|
||||
@Override
|
||||
public boolean hasNbtData() {
|
||||
return getNbtData() != null;
|
||||
}
|
||||
@ -83,8 +84,8 @@ public abstract class FilterBlock extends BlockVector3 implements Extent, TileEn
|
||||
return getBlock(getX() - 1, getY(), getZ());
|
||||
}
|
||||
|
||||
public BlockState getBlockRelativeY(final int y) {
|
||||
return getBlock(getX(), getY() + y , getZ());
|
||||
public BlockState getBlockRelativeY(int y) {
|
||||
return getBlock(getX(), getY() + y, getZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -119,51 +120,62 @@ public abstract class FilterBlock extends BlockVector3 implements Extent, TileEn
|
||||
/*
|
||||
Extent
|
||||
*/
|
||||
@Override
|
||||
public boolean setOrdinal(Extent orDefault, int ordinal) {
|
||||
setOrdinal(ordinal);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBlock(Extent orDefault, BlockState state) {
|
||||
setBlock(state);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setFullBlock(Extent orDefault, BaseBlock block) {
|
||||
setFullBlock(block);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBiome(Extent orDefault, BiomeType biome) {
|
||||
setBiome(biome);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrdinal(Extent orDefault) {
|
||||
return getOrdinal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getBlock(Extent orDefault) {
|
||||
return getBlock();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBlock getFullBlock(Extent orDefault) {
|
||||
return getFullBlock();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag getNbtData(Extent orDefault) {
|
||||
return getNbtData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getOrdinalBelow(Extent orDefault) {
|
||||
return getBlockBelow();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getStateAbove(Extent orDefault) {
|
||||
return getBlockAbove();
|
||||
}
|
||||
|
||||
public BlockState getStateRelativeY(Extent orDefault, final int y) {
|
||||
@Override
|
||||
public BlockState getStateRelativeY(Extent orDefault, int y) {
|
||||
return getBlockRelativeY(y);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.boydti.fawe.beta;
|
||||
|
||||
public interface FilterBlockMask {
|
||||
boolean applyBlock(final FilterBlock block);
|
||||
|
||||
boolean applyBlock(FilterBlock block);
|
||||
}
|
@ -6,27 +6,23 @@ import com.boydti.fawe.util.MathMan;
|
||||
import com.sk89q.worldedit.util.Direction;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap;
|
||||
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
public class Flood {
|
||||
|
||||
private final int maxBranch;
|
||||
private final int maxDepth;
|
||||
private final Direction[] directions;
|
||||
|
||||
private final Long2ObjectLinkedOpenHashMap<long[][]> chunkVisits;
|
||||
private final Long2ObjectLinkedOpenHashMap<int[][]> chunkQueues;
|
||||
private int[] queue;
|
||||
private long[] visit;
|
||||
|
||||
private int[][] queues;
|
||||
private long[][] visits;
|
||||
|
||||
private int chunkX;
|
||||
private int chunkYLayer;
|
||||
private int chunkZ;
|
||||
|
||||
private ConcurrentLinkedQueue<int[]> queuePool = new ConcurrentLinkedQueue<>();
|
||||
private final Long2ObjectLinkedOpenHashMap<long[][]> chunkVisits;
|
||||
private final Long2ObjectLinkedOpenHashMap<int[][]> chunkQueues;
|
||||
|
||||
public Flood(int maxBranch, int maxDepth, Direction[] directions) {
|
||||
this.maxBranch = maxBranch;
|
||||
@ -171,12 +167,12 @@ public class Flood {
|
||||
}
|
||||
|
||||
public void set(long[] bits, int i) {
|
||||
bits[i >> 6] |= (1L << (i & 0x3F));
|
||||
bits[i >> 6] |= 1L << (i & 0x3F);
|
||||
}
|
||||
|
||||
public final boolean getAndSet(long[] bits, int i) {
|
||||
int index = i >> 6;
|
||||
long offset = (1L << (i & 0x3F));
|
||||
long offset = 1L << (i & 0x3F);
|
||||
long val = bits[index];
|
||||
if ((val & offset) != 0) {
|
||||
return true;
|
||||
@ -186,7 +182,7 @@ public class Flood {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean get(long[] bits, final int i) {
|
||||
return (bits[i >> 6] & (1L << (i & 0x3F))) != 0;
|
||||
public boolean get(long[] bits, int i) {
|
||||
return (bits[i >> 6] & 1L << (i & 0x3F)) != 0;
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ package com.boydti.fawe.beta;
|
||||
* Shared interface for IGetBlocks and ISetBlocks
|
||||
*/
|
||||
public interface IBlocks extends Trimable {
|
||||
|
||||
boolean hasSection(int layer);
|
||||
|
||||
IBlocks reset();
|
||||
|
@ -12,12 +12,14 @@ import java.util.concurrent.Future;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Represents a chunk in the queue {@link IQueueExtent}
|
||||
* Used for getting and setting blocks / biomes / entities
|
||||
* Represents a chunk in the queue {@link IQueueExtent} Used for getting and setting blocks / biomes
|
||||
* / entities
|
||||
*/
|
||||
public interface IChunk<T extends Future<T>> extends Trimable, Callable<T>, IChunkGet {
|
||||
|
||||
/**
|
||||
* Initialize at the location
|
||||
*
|
||||
* @param extent
|
||||
* @param x
|
||||
* @param z
|
||||
@ -31,7 +33,8 @@ public interface IChunk<T extends Future<T>> extends Trimable, Callable<T>, IChu
|
||||
int getZ();
|
||||
|
||||
/**
|
||||
* If the chunk is a delegate, returns it's paren'ts root
|
||||
* If the chunk is a delegate, returns it's parent's root
|
||||
*
|
||||
* @return root IChunk
|
||||
*/
|
||||
default IChunk getRoot() {
|
||||
@ -39,20 +42,25 @@ public interface IChunk<T extends Future<T>> extends Trimable, Callable<T>, IChu
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if there are any queued changes for this chunk.
|
||||
*
|
||||
* @return true if no changes are queued for this chunk
|
||||
*/
|
||||
boolean isEmpty();
|
||||
|
||||
/**
|
||||
* Apply the queued changes to the world<br>
|
||||
* The future returned may return another future<br>
|
||||
* To ensure completion keep calling {@link Future#get()} on each result
|
||||
* Apply the queued changes to the world containing this chunk.
|
||||
* <p>The future returned may return another future. To ensure completion keep calling {@link
|
||||
* Future#get()} on each result.</p>
|
||||
*
|
||||
* @return Futures
|
||||
*/
|
||||
@Override
|
||||
T call();
|
||||
|
||||
/**
|
||||
* Call and join
|
||||
*
|
||||
* @throws ExecutionException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
@ -66,11 +74,10 @@ public interface IChunk<T extends Future<T>> extends Trimable, Callable<T>, IChu
|
||||
|
||||
/**
|
||||
* Filter
|
||||
*
|
||||
* @param filter the filter
|
||||
* @param block The filter block
|
||||
* @param region The region allowed to filter (may be null)
|
||||
* @param unitialized a mutable block vector (buffer)
|
||||
* @param unitialized2 a mutable block vector (buffer)
|
||||
*/
|
||||
void filterBlocks(Filter filter, ChunkFilterBlock block, @Nullable Region region);
|
||||
|
||||
@ -81,13 +88,16 @@ public interface IChunk<T extends Future<T>> extends Trimable, Callable<T>, IChu
|
||||
|
||||
boolean setBlock(int x, int y, int z, BlockStateHolder block);
|
||||
|
||||
/* get - from the world */
|
||||
@Override
|
||||
BiomeType getBiomeType(int x, int z);
|
||||
|
||||
@Override
|
||||
BlockState getBlock(int x, int y, int z);
|
||||
|
||||
@Override
|
||||
BaseBlock getFullBlock(int x, int y, int z);
|
||||
|
||||
@Override
|
||||
CompoundTag getTag(int x, int y, int z);
|
||||
|
||||
@Override
|
||||
|
@ -7,9 +7,10 @@ import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
|
||||
/**
|
||||
* Interface for getting blocks
|
||||
* An interface for getting blocks.
|
||||
*/
|
||||
public interface IChunkGet extends IBlocks, Trimable, InputExtent {
|
||||
|
||||
@Override
|
||||
BaseBlock getFullBlock(int x, int y, int z);
|
||||
|
||||
|
@ -6,16 +6,16 @@ import com.sk89q.worldedit.function.operation.Operation;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Interface for setting blocks
|
||||
*/
|
||||
public interface IChunkSet extends IBlocks, OutputExtent {
|
||||
|
||||
@Override
|
||||
boolean setBiome(int x, int y, int z, BiomeType biome);
|
||||
|
||||
|
@ -6,18 +6,20 @@ 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.BlockStateHolder;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Delegate for IChunk
|
||||
*
|
||||
* @param <U> parent class
|
||||
*/
|
||||
public interface IDelegateChunk<U extends IChunk> extends IChunk {
|
||||
|
||||
U getParent();
|
||||
|
||||
@Override
|
||||
default IChunk getRoot() {
|
||||
IChunk root = getParent();
|
||||
while (root instanceof IDelegateChunk) {
|
||||
@ -48,32 +50,32 @@ public interface IDelegateChunk<U extends IChunk> extends IChunk {
|
||||
}
|
||||
|
||||
@Override
|
||||
default boolean setBiome(final int x, final int y, final int z, final BiomeType biome) {
|
||||
default boolean setBiome(int x, int y, int z, BiomeType biome) {
|
||||
return getParent().setBiome(x, y, z, biome);
|
||||
}
|
||||
|
||||
@Override
|
||||
default boolean setBlock(final int x, final int y, final int z, final BlockStateHolder holder) {
|
||||
default boolean setBlock(int x, int y, int z, BlockStateHolder holder) {
|
||||
return getParent().setBlock(x, y, z, holder);
|
||||
}
|
||||
|
||||
@Override
|
||||
default BiomeType getBiomeType(final int x, final int z) {
|
||||
default BiomeType getBiomeType(int x, int z) {
|
||||
return getParent().getBiomeType(x, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
default BlockState getBlock(final int x, final int y, final int z) {
|
||||
default BlockState getBlock(int x, int y, int z) {
|
||||
return getParent().getBlock(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
default BaseBlock getFullBlock(final int x, final int y, final int z) {
|
||||
default BaseBlock getFullBlock(int x, int y, int z) {
|
||||
return getParent().getFullBlock(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
default void init(final IQueueExtent extent, final int chunkX, final int chunkZ) {
|
||||
default void init(IQueueExtent extent, int chunkX, int chunkZ) {
|
||||
getParent().init(extent, chunkX, chunkZ);
|
||||
}
|
||||
|
||||
@ -89,7 +91,7 @@ public interface IDelegateChunk<U extends IChunk> extends IChunk {
|
||||
|
||||
|
||||
@Override
|
||||
default boolean trim(final boolean aggressive) {
|
||||
default boolean trim(boolean aggressive) {
|
||||
return getParent().trim(aggressive);
|
||||
}
|
||||
|
||||
@ -113,12 +115,16 @@ public interface IDelegateChunk<U extends IChunk> extends IChunk {
|
||||
return getParent().isEmpty();
|
||||
}
|
||||
|
||||
default <T extends IChunk> T findParent(final Class<T> clazz) {
|
||||
default <T extends IChunk> T findParent(Class<T> clazz) {
|
||||
IChunk root = getParent();
|
||||
if (clazz.isAssignableFrom(root.getClass())) return (T) root;
|
||||
if (clazz.isAssignableFrom(root.getClass())) {
|
||||
return (T) root;
|
||||
}
|
||||
while (root instanceof IDelegateChunk) {
|
||||
root = ((IDelegateChunk) root).getParent();
|
||||
if (clazz.isAssignableFrom(root.getClass())) return (T) root;
|
||||
if (clazz.isAssignableFrom(root.getClass())) {
|
||||
return (T) root;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
package com.boydti.fawe.beta;
|
||||
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public interface IDelegateFilter extends Filter {
|
||||
|
||||
Filter getParent();
|
||||
|
||||
@Override
|
||||
|
@ -1,37 +1,37 @@
|
||||
package com.boydti.fawe.beta;
|
||||
|
||||
import com.boydti.fawe.beta.implementation.WorldChunkCache;
|
||||
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
/**
|
||||
* Delegate for IQueueExtent
|
||||
*/
|
||||
public interface IDelegateQueueExtent extends IQueueExtent {
|
||||
|
||||
IQueueExtent getParent();
|
||||
|
||||
@Override
|
||||
default void init(final WorldChunkCache cache) {
|
||||
default void init(WorldChunkCache cache) {
|
||||
getParent().init(cache);
|
||||
}
|
||||
|
||||
@Override
|
||||
default IChunk getCachedChunk(final int x, final int z) {
|
||||
default IChunk getCachedChunk(int x, int z) {
|
||||
return getParent().getCachedChunk(x, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
default Future<?> submit(final IChunk chunk) {
|
||||
default Future<?> submit(IChunk chunk) {
|
||||
return getParent().submit(chunk);
|
||||
}
|
||||
|
||||
@Override
|
||||
default IChunk create(final boolean full) {
|
||||
return getParent().create(full);
|
||||
default IChunk create(boolean isFull) {
|
||||
return getParent().create(isFull);
|
||||
}
|
||||
|
||||
@Override
|
||||
default IChunk wrap(final IChunk root) {
|
||||
default IChunk wrap(IChunk root) {
|
||||
return getParent().wrap(root);
|
||||
}
|
||||
|
||||
@ -41,7 +41,7 @@ public interface IDelegateQueueExtent extends IQueueExtent {
|
||||
}
|
||||
|
||||
@Override
|
||||
default boolean trim(final boolean aggressive) {
|
||||
default boolean trim(boolean aggressive) {
|
||||
return getParent().trim(aggressive);
|
||||
}
|
||||
}
|
||||
|
@ -8,14 +8,13 @@ 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.BlockStateHolder;
|
||||
|
||||
import java.io.Flushable;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* TODO: implement Extent (need to refactor Extent first)
|
||||
* Interface for a queue based extent which uses chunks
|
||||
* TODO: implement Extent (need to refactor Extent first) Interface for a queue based extent which
|
||||
* uses chunks
|
||||
*/
|
||||
public interface IQueueExtent extends Flushable, Trimable, Extent {
|
||||
|
||||
@ -40,12 +39,14 @@ public interface IQueueExtent extends Flushable, Trimable, Extent {
|
||||
|
||||
/**
|
||||
* Get the {@link WorldChunkCache}
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
IChunkGet getCachedGet(int x, int z, Supplier<IChunkGet> supplier);
|
||||
|
||||
/**
|
||||
* Get the IChunk at a position (and cache it if it's not already)
|
||||
*
|
||||
* @param x
|
||||
* @param z
|
||||
* @return IChunk
|
||||
@ -54,24 +55,26 @@ public interface IQueueExtent extends Flushable, Trimable, Extent {
|
||||
|
||||
/**
|
||||
* Submit the chunk so that it's changes are applied to the world
|
||||
*
|
||||
* @param chunk
|
||||
* @return result
|
||||
*/
|
||||
<T extends Future<T>> T submit(IChunk<T> chunk);
|
||||
|
||||
@Override
|
||||
default boolean setBlock(final int x, final int y, final int z, final BlockStateHolder state) {
|
||||
default boolean setBlock(int x, int y, int z, BlockStateHolder state) {
|
||||
final IChunk chunk = getCachedChunk(x >> 4, z >> 4);
|
||||
return chunk.setBlock(x & 15, y, z & 15, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
default boolean setBiome(final int x, final int y, final int z, final BiomeType biome) {
|
||||
default boolean setBiome(int x, int y, int z, BiomeType biome) {
|
||||
final IChunk chunk = getCachedChunk(x >> 4, z >> 4);
|
||||
return chunk.setBiome(x & 15, y, z & 15, biome);
|
||||
}
|
||||
|
||||
default BlockState getBlock(final int x, final int y, final int z) {
|
||||
@Override
|
||||
default BlockState getBlock(int x, int y, int z) {
|
||||
final IChunk chunk = getCachedChunk(x >> 4, z >> 4);
|
||||
return chunk.getBlock(x & 15, y, z & 15);
|
||||
}
|
||||
@ -82,7 +85,7 @@ public interface IQueueExtent extends Flushable, Trimable, Extent {
|
||||
return chunk.getFullBlock(x & 15, y, z & 15);
|
||||
}
|
||||
|
||||
default BiomeType getBiome(final int x, final int z) {
|
||||
default BiomeType getBiome(int x, int z) {
|
||||
final IChunk chunk = getCachedChunk(x >> 4, z >> 4);
|
||||
return chunk.getBiomeType(x & 15, z & 15);
|
||||
}
|
||||
@ -98,26 +101,27 @@ public interface IQueueExtent extends Flushable, Trimable, Extent {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new root IChunk object<br>
|
||||
* - Full chunks will be reused, so a more optimized chunk can be returned in that case<br>
|
||||
* - Don't wrap the chunk, that should be done in {@link #wrap(IChunk)}
|
||||
* @param full
|
||||
* Create a new root IChunk object<br> - Full chunks will be reused, so a more optimized chunk
|
||||
* can be returned in that case<br> - Don't wrap the chunk, that should be done in {@link
|
||||
* #wrap(IChunk)}
|
||||
*
|
||||
* @param isFull true if a more optimized chunk should be returned
|
||||
* @return
|
||||
*/
|
||||
IChunk create(boolean full);
|
||||
IChunk create(boolean isFull);
|
||||
|
||||
/**
|
||||
* Wrap the chunk object (i.e. for region restrictions / limits etc.)
|
||||
*
|
||||
* @param root
|
||||
* @return wrapped chunk
|
||||
*/
|
||||
default IChunk wrap(final IChunk root) {
|
||||
default IChunk wrap(IChunk root) {
|
||||
return root;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush all changes to the world
|
||||
* - Best to call this async so it doesn't hang the server
|
||||
* Flush all changes to the world - Best to call this async so it doesn't hang the server
|
||||
*/
|
||||
@Override
|
||||
void flush();
|
||||
|
@ -8,6 +8,7 @@ import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
|
||||
public class NorthVector extends BlockVector3 {
|
||||
|
||||
private final BlockVector3 parent;
|
||||
|
||||
public NorthVector(BlockVector3 parent) {
|
||||
@ -34,55 +35,67 @@ public class NorthVector extends BlockVector3 {
|
||||
return parent.getZ();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setOrdinal(Extent orDefault, int ordinal) {
|
||||
return orDefault.setBlock(this, BlockState.getFromOrdinal(ordinal));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBlock(Extent orDefault, BlockState state) {
|
||||
return orDefault.setBlock(this, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setFullBlock(Extent orDefault, BaseBlock block) {
|
||||
return orDefault.setBlock(this, block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBiome(Extent orDefault, BiomeType biome) {
|
||||
return orDefault.setBiome(getX(), getY(), getZ(), biome);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrdinal(Extent orDefault) {
|
||||
return getBlock(orDefault).getOrdinal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public char getOrdinalChar(Extent orDefault) {
|
||||
return (char) getOrdinal(orDefault);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getBlock(Extent orDefault) {
|
||||
return orDefault.getBlock(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBlock getFullBlock(Extent orDefault) {
|
||||
return orDefault.getFullBlock(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag getNbtData(Extent orDefault) {
|
||||
return orDefault.getFullBlock(getX(), getY(), getZ()).getNbtData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getOrdinalBelow(Extent orDefault) {
|
||||
return getStateRelative(orDefault, 0, -1, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getStateAbove(Extent orDefault) {
|
||||
return getStateRelative(orDefault, 0, 1, 0);
|
||||
}
|
||||
|
||||
public BlockState getStateRelativeY(Extent orDefault, final int y) {
|
||||
@Override
|
||||
public BlockState getStateRelativeY(Extent orDefault, int y) {
|
||||
return getStateRelative(orDefault, 0, y, 0);
|
||||
}
|
||||
|
||||
public BlockState getStateRelative(Extent orDefault, final int x, final int y, final int z) {
|
||||
public BlockState getStateRelative(Extent orDefault, int x, int y, int z) {
|
||||
return getFullBlockRelative(orDefault, x, y, z).toBlockState();
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ package com.boydti.fawe.beta;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
|
||||
public abstract class SimpleFilterBlock extends FilterBlock {
|
||||
|
||||
private final Extent extent;
|
||||
|
||||
public SimpleFilterBlock(Extent extent) {
|
||||
|
@ -5,7 +5,6 @@ import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class SingleFilterBlock extends FilterBlock {
|
||||
@ -26,29 +25,29 @@ public class SingleFilterBlock extends FilterBlock {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrdinal() {
|
||||
return block.getOrdinal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOrdinal(int ordinal) {
|
||||
setBlock(BlockState.getFromOrdinal(ordinal));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getBlock() {
|
||||
return block.toBlockState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlock(BlockState state) {
|
||||
setFullBlock(state.toBaseBlock(block.getNbtData()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFullBlock(BaseBlock block) {
|
||||
this.block = block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNbtData(@Nullable CompoundTag nbtData) {
|
||||
block = block.toBaseBlock(nbtData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrdinal() {
|
||||
return block.getOrdinal();
|
||||
public BaseBlock getFullBlock() {
|
||||
return block;
|
||||
}
|
||||
|
||||
// @Override
|
||||
@ -57,13 +56,8 @@ public class SingleFilterBlock extends FilterBlock {
|
||||
// }
|
||||
|
||||
@Override
|
||||
public BlockState getBlock() {
|
||||
return block.toBlockState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBlock getFullBlock() {
|
||||
return block;
|
||||
public void setFullBlock(BaseBlock block) {
|
||||
this.block = block;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -71,6 +65,11 @@ public class SingleFilterBlock extends FilterBlock {
|
||||
return block.getNbtData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNbtData(@Nullable CompoundTag nbtData) {
|
||||
block = block.toBaseBlock(nbtData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getX() {
|
||||
return x;
|
||||
|
@ -1,13 +1,16 @@
|
||||
package com.boydti.fawe.beta;
|
||||
|
||||
/**
|
||||
* Interface for objects that can be trimmed (memory related)<br>
|
||||
* - Trimming will reduce it's memory footprint
|
||||
* Interface for objects that can be trimmed (memory related)<br> - Trimming will reduce it's memory
|
||||
* footprint
|
||||
*/
|
||||
public interface Trimable {
|
||||
|
||||
/**
|
||||
* Trim the object, reducing it's memory footprint
|
||||
* @param aggressive if trimming should be aggressive e.g. Not return early when the first element cannot be trimmed
|
||||
*
|
||||
* @param aggressive if trimming should be aggressive e.g. Not return early when the first
|
||||
* element cannot be trimmed
|
||||
* @return if this object is empty at the end of the trim, and can therefore be deleted
|
||||
*/
|
||||
boolean trim(boolean aggressive);
|
||||
|
@ -2,11 +2,11 @@ package com.boydti.fawe.beta.filters;
|
||||
|
||||
import com.boydti.fawe.beta.FilterBlock;
|
||||
import com.boydti.fawe.beta.FilterBlockMask;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class ArrayImageMask implements FilterBlockMask {
|
||||
|
||||
private final ThreadLocalRandom random;
|
||||
private final boolean white;
|
||||
private final BufferedImage image;
|
||||
@ -16,9 +16,10 @@ public class ArrayImageMask implements FilterBlockMask {
|
||||
this.white = white;
|
||||
this.random = ThreadLocalRandom.current();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean applyBlock(FilterBlock block) {
|
||||
int height = image.getRGB(block.getX(), block.getZ()) & 0xFF;
|
||||
return ((height == 255 || height > 0 && !white && random.nextInt(256) <= height));
|
||||
return height == 255 || height > 0 && !white && random.nextInt(256) <= height;
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package com.boydti.fawe.beta.filters;
|
||||
import com.boydti.fawe.beta.FilterBlock;
|
||||
|
||||
public class CountFilter extends ForkedFilter<CountFilter> {
|
||||
|
||||
private int total;
|
||||
|
||||
public CountFilter() {
|
||||
@ -23,12 +24,8 @@ public class CountFilter extends ForkedFilter<CountFilter> {
|
||||
this.total += filter.getTotal();
|
||||
}
|
||||
|
||||
/*
|
||||
Implementation
|
||||
*/
|
||||
|
||||
@Override
|
||||
public final void applyBlock(final FilterBlock block) {
|
||||
public final void applyBlock(FilterBlock block) {
|
||||
total++;
|
||||
}
|
||||
|
||||
|
@ -8,10 +8,12 @@ import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class DistrFilter extends ForkedFilter<DistrFilter> {
|
||||
|
||||
private final int[] counter = new int[BlockTypes.states.length];
|
||||
|
||||
public DistrFilter() {
|
||||
@ -34,12 +36,8 @@ public class DistrFilter extends ForkedFilter<DistrFilter> {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Implementation
|
||||
*/
|
||||
|
||||
@Override
|
||||
public final void applyBlock(final FilterBlock block) {
|
||||
public final void applyBlock(FilterBlock block) {
|
||||
counter[block.getOrdinal()]++;
|
||||
}
|
||||
|
||||
@ -55,9 +53,7 @@ public class DistrFilter extends ForkedFilter<DistrFilter> {
|
||||
}
|
||||
|
||||
public int getTotal() {
|
||||
int total = 0;
|
||||
for (int value : counter) total += value;
|
||||
return total;
|
||||
return Arrays.stream(counter).sum();
|
||||
}
|
||||
|
||||
public List<Countable<BlockState>> getDistribution() {
|
||||
@ -92,7 +88,7 @@ public class DistrFilter extends ForkedFilter<DistrFilter> {
|
||||
return distribution;
|
||||
}
|
||||
|
||||
public void print(final Actor actor, final long size) {
|
||||
public void print(Actor actor, long size) {
|
||||
for (Countable c : getDistribution()) {
|
||||
final String name = c.getID().toString();
|
||||
final String str = String.format("%-7s (%.3f%%) %s",
|
||||
|
@ -1,20 +1,11 @@
|
||||
package com.boydti.fawe.beta.filters;
|
||||
|
||||
import com.boydti.fawe.beta.Filter;
|
||||
import com.boydti.fawe.beta.FilterBlock;
|
||||
import com.boydti.fawe.config.BBC;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.util.Countable;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public abstract class ForkedFilter<T extends ForkedFilter<T>> implements Filter {
|
||||
|
||||
protected final Map<Thread, T> children;
|
||||
|
||||
public ForkedFilter(T root) {
|
||||
|
@ -5,14 +5,15 @@ import com.boydti.fawe.beta.FilterBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
|
||||
public class SetFilter implements Filter {
|
||||
|
||||
private final BlockState state;
|
||||
|
||||
public SetFilter(final BlockState state) {
|
||||
public SetFilter(BlockState state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyBlock(final FilterBlock block) {
|
||||
public void applyBlock(FilterBlock block) {
|
||||
block.setBlock(state);
|
||||
}
|
||||
}
|
||||
|
@ -9,13 +9,13 @@ import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public interface DelegateChunkSet extends IChunkSet {
|
||||
|
||||
IChunkSet getParent();
|
||||
|
||||
@Override
|
||||
@ -102,7 +102,8 @@ public interface DelegateChunkSet extends IChunkSet {
|
||||
}
|
||||
|
||||
@Override
|
||||
default <T extends BlockStateHolder<T>> boolean setBlock(BlockVector3 position, T block) throws WorldEditException {
|
||||
default <T extends BlockStateHolder<T>> boolean setBlock(BlockVector3 position, T block)
|
||||
throws WorldEditException {
|
||||
return getParent().setBlock(position, block);
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ package com.boydti.fawe.beta.implementation;
|
||||
import com.boydti.fawe.beta.IQueueExtent;
|
||||
|
||||
public interface IQueueWrapper {
|
||||
|
||||
default IQueueExtent wrapQueue(IQueueExtent queue) {
|
||||
return queue;
|
||||
}
|
||||
|
@ -19,13 +19,14 @@ import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ForkJoinTask;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class MultiThreadedQueue extends AbstractDelegateExtent implements IQueueWrapper {
|
||||
|
||||
private final World world;
|
||||
private final QueueHandler handler;
|
||||
|
||||
@ -39,18 +40,14 @@ public class MultiThreadedQueue extends AbstractDelegateExtent implements IQueue
|
||||
return handler.getQueue(this.world);
|
||||
}
|
||||
|
||||
public <T extends Filter> T apply(final Region region, final T filter) {
|
||||
public <T extends Filter> T apply(Region region, T filter) {
|
||||
// The chunks positions to iterate over
|
||||
final Set<BlockVector2> chunks = region.getChunks();
|
||||
final Iterator<BlockVector2> chunksIter = chunks.iterator();
|
||||
|
||||
// Get a pool, to operate on the chunks in parallel
|
||||
final int size = Math.min(chunks.size(), Settings.IMP.QUEUE.PARALLEL_THREADS);
|
||||
final ForkJoinTask[] tasks = new ForkJoinTask[size];
|
||||
for (int i = 0; i < size; i++) {
|
||||
tasks[i] = handler.submit(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final ForkJoinTask[] tasks = IntStream.range(0, size).mapToObj(i -> handler.submit(() -> {
|
||||
final Filter newFilter = filter.fork();
|
||||
// Create a chunk that we will reuse/reset for each operation
|
||||
final IQueueExtent queue = wrapQueue(getQueue());
|
||||
@ -61,7 +58,9 @@ public class MultiThreadedQueue extends AbstractDelegateExtent implements IQueue
|
||||
// Get the next chunk posWeakChunk
|
||||
final int X, Z;
|
||||
synchronized (chunksIter) {
|
||||
if (!chunksIter.hasNext()) break;
|
||||
if (!chunksIter.hasNext()) {
|
||||
break;
|
||||
}
|
||||
final BlockVector2 pos = chunksIter.next();
|
||||
X = pos.getX();
|
||||
Z = pos.getZ();
|
||||
@ -76,19 +75,18 @@ public class MultiThreadedQueue extends AbstractDelegateExtent implements IQueue
|
||||
IChunk newChunk = newFilter.applyChunk(chunk, region);
|
||||
if (newChunk != null) {
|
||||
chunk = newChunk;
|
||||
if (block == null) block = queue.initFilterBlock();
|
||||
if (block == null) {
|
||||
block = queue.initFilterBlock();
|
||||
}
|
||||
chunk.filterBlocks(newFilter, block, region);
|
||||
}
|
||||
queue.submit(chunk);
|
||||
}
|
||||
queue.flush();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
})).toArray(ForkJoinTask[]::new);
|
||||
// Join filters
|
||||
for (int i = 0; i < tasks.length; i++) {
|
||||
final ForkJoinTask task = tasks[i];
|
||||
for (ForkJoinTask task : tasks) {
|
||||
if (task != null) {
|
||||
task.quietlyJoin();
|
||||
}
|
||||
@ -102,7 +100,7 @@ public class MultiThreadedQueue extends AbstractDelegateExtent implements IQueue
|
||||
}
|
||||
|
||||
@Override
|
||||
public int countBlocks(final Region region, final Mask searchMask) {
|
||||
public int countBlocks(Region region, Mask searchMask) {
|
||||
return
|
||||
// Apply a filter over a region
|
||||
apply(region, searchMask
|
||||
@ -112,7 +110,8 @@ public class MultiThreadedQueue extends AbstractDelegateExtent implements IQueue
|
||||
}
|
||||
|
||||
@Override
|
||||
public <B extends BlockStateHolder<B>> int setBlocks(Region region, B block) throws MaxChangedBlocksException {
|
||||
public <B extends BlockStateHolder<B>> int setBlocks(Region region, B block)
|
||||
throws MaxChangedBlocksException {
|
||||
apply(region, block);
|
||||
return getChanges();
|
||||
}
|
||||
@ -135,7 +134,8 @@ public class MultiThreadedQueue extends AbstractDelegateExtent implements IQueue
|
||||
}
|
||||
|
||||
@Override
|
||||
public int replaceBlocks(Region region, Mask mask, Pattern pattern) throws MaxChangedBlocksException {
|
||||
public int replaceBlocks(Region region, Mask mask, Pattern pattern)
|
||||
throws MaxChangedBlocksException {
|
||||
apply(region, mask.toFilter(pattern));
|
||||
return getChanges();
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ import com.boydti.fawe.util.TaskManager;
|
||||
import com.boydti.fawe.wrappers.WorldWrapper;
|
||||
import com.google.common.util.concurrent.Futures;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
@ -31,6 +30,7 @@ import java.util.function.Supplier;
|
||||
* Class which handles all the queues {@link IQueueExtent}
|
||||
*/
|
||||
public abstract class QueueHandler implements Trimable, Runnable {
|
||||
|
||||
private ForkJoinPool forkJoinPoolPrimary = new ForkJoinPool();
|
||||
private ForkJoinPool forkJoinPoolSecondary = new ForkJoinPool();
|
||||
private ThreadPoolExecutor blockingExecutor = FaweCache.newBlockingExecutor();
|
||||
@ -43,17 +43,16 @@ public abstract class QueueHandler implements Trimable, Runnable {
|
||||
return create();
|
||||
}
|
||||
};
|
||||
|
||||
public QueueHandler() {
|
||||
TaskManager.IMP.repeat(this, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to calculate elapsed time in milliseconds and ensure block placement doesn't lag the server
|
||||
* Used to calculate elapsed time in milliseconds and ensure block placement doesn't lag the
|
||||
* server
|
||||
*/
|
||||
private long last;
|
||||
private long allocate = 50;
|
||||
private double targetTPS = 18;
|
||||
public QueueHandler() {
|
||||
TaskManager.IMP.repeat(this, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
@ -63,7 +62,7 @@ public abstract class QueueHandler implements Trimable, Runnable {
|
||||
if (!syncTasks.isEmpty()) {
|
||||
long now = System.currentTimeMillis();
|
||||
targetTPS = 18 - Math.max(Settings.IMP.QUEUE.EXTRA_TIME_MS * 0.05, 0);
|
||||
long diff = (50 + this.last) - (this.last = now);
|
||||
long diff = 50 + this.last - (this.last = now);
|
||||
long absDiff = Math.abs(diff);
|
||||
if (diff == 0) {
|
||||
allocate = Math.min(50, allocate + 1);
|
||||
@ -105,7 +104,9 @@ public abstract class QueueHandler implements Trimable, Runnable {
|
||||
}
|
||||
while (!syncTasks.isEmpty()) {
|
||||
final FutureTask task = syncTasks.poll();
|
||||
if (task != null) task.run();
|
||||
if (task != null) {
|
||||
task.run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -119,23 +120,23 @@ public abstract class QueueHandler implements Trimable, Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
public <T> Future<T> async(final Runnable run, final T value) {
|
||||
public <T> Future<T> async(Runnable run, T value) {
|
||||
return forkJoinPoolSecondary.submit(run, value);
|
||||
}
|
||||
|
||||
public Future<?> async(final Runnable run) {
|
||||
public Future<?> async(Runnable run) {
|
||||
return forkJoinPoolSecondary.submit(run);
|
||||
}
|
||||
|
||||
public <T> Future<T> async(final Callable<T> call) {
|
||||
public <T> Future<T> async(Callable<T> call) {
|
||||
return forkJoinPoolSecondary.submit(call);
|
||||
}
|
||||
|
||||
public ForkJoinTask submit(final Runnable call) {
|
||||
public ForkJoinTask submit(Runnable call) {
|
||||
return forkJoinPoolPrimary.submit(call);
|
||||
}
|
||||
|
||||
public <T> Future<T> sync(final Runnable run, final T value) {
|
||||
public <T> Future<T> sync(Runnable run, T value) {
|
||||
if (Fawe.isMainThread()) {
|
||||
run.run();
|
||||
return Futures.immediateFuture(value);
|
||||
@ -146,7 +147,7 @@ public abstract class QueueHandler implements Trimable, Runnable {
|
||||
return result;
|
||||
}
|
||||
|
||||
public <T> Future<T> sync(final Runnable run) {
|
||||
public <T> Future<T> sync(Runnable run) {
|
||||
if (Fawe.isMainThread()) {
|
||||
run.run();
|
||||
return Futures.immediateCancelledFuture();
|
||||
@ -157,7 +158,7 @@ public abstract class QueueHandler implements Trimable, Runnable {
|
||||
return result;
|
||||
}
|
||||
|
||||
public <T> Future<T> sync(final Callable<T> call) throws Exception {
|
||||
public <T> Future<T> sync(Callable<T> call) throws Exception {
|
||||
if (Fawe.isMainThread()) {
|
||||
return Futures.immediateFuture(call.call());
|
||||
}
|
||||
@ -167,7 +168,7 @@ public abstract class QueueHandler implements Trimable, Runnable {
|
||||
return result;
|
||||
}
|
||||
|
||||
public <T> Future<T> sync(final Supplier<T> call) {
|
||||
public <T> Future<T> sync(Supplier<T> call) {
|
||||
if (Fawe.isMainThread()) {
|
||||
return Futures.immediateFuture(call.get());
|
||||
}
|
||||
@ -183,7 +184,7 @@ public abstract class QueueHandler implements Trimable, Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
public <T extends Future<T>> T submit(final IChunk<T> chunk) {
|
||||
public <T extends Future<T>> T submit(IChunk<T> chunk) {
|
||||
// if (MemUtil.isMemoryFree()) { TODO NOT IMPLEMENTED - optimize this
|
||||
// return (T) forkJoinPoolSecondary.submit(chunk);
|
||||
// }
|
||||
@ -192,6 +193,7 @@ public abstract class QueueHandler implements Trimable, Runnable {
|
||||
|
||||
/**
|
||||
* Get or create the WorldChunkCache for a world
|
||||
*
|
||||
* @param world
|
||||
* @return
|
||||
*/
|
||||
@ -218,17 +220,18 @@ public abstract class QueueHandler implements Trimable, Runnable {
|
||||
|
||||
public abstract void endSet(boolean parallel);
|
||||
|
||||
public IQueueExtent getQueue(final World world) {
|
||||
public IQueueExtent getQueue(World world) {
|
||||
final IQueueExtent queue = queuePool.get();
|
||||
queue.init(getOrCreate(world));
|
||||
return queue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean trim(final boolean aggressive) {
|
||||
public boolean trim(boolean aggressive) {
|
||||
boolean result = true;
|
||||
synchronized (chunkCache) {
|
||||
final Iterator<Map.Entry<World, WeakReference<WorldChunkCache>>> iter = chunkCache.entrySet().iterator();
|
||||
final Iterator<Map.Entry<World, WeakReference<WorldChunkCache>>> iter = chunkCache
|
||||
.entrySet().iterator();
|
||||
while (iter.hasNext()) {
|
||||
final Map.Entry<World, WeakReference<WorldChunkCache>> entry = iter.next();
|
||||
final WeakReference<WorldChunkCache> value = entry.getValue();
|
||||
|
@ -2,9 +2,9 @@ package com.boydti.fawe.beta.implementation;
|
||||
|
||||
import com.boydti.fawe.beta.CharFilterBlock;
|
||||
import com.boydti.fawe.beta.ChunkFilterBlock;
|
||||
import com.boydti.fawe.beta.FilterBlock;
|
||||
|
||||
public abstract class SimpleCharQueueExtent extends SingleThreadQueueExtent {
|
||||
|
||||
@Override
|
||||
public ChunkFilterBlock initFilterBlock() {
|
||||
return new CharFilterBlock(this);
|
||||
|
@ -18,23 +18,32 @@ import java.util.concurrent.Future;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Single threaded implementation for IQueueExtent (still abstract)
|
||||
* - Does not implement creation of chunks (that has to implemented by the platform e.g. Bukkit)
|
||||
*
|
||||
* Single threaded implementation for IQueueExtent (still abstract) - Does not implement creation of
|
||||
* chunks (that has to implemented by the platform e.g. Bukkit)
|
||||
* <p>
|
||||
* This queue is reusable {@link #init(WorldChunkCache)}
|
||||
*/
|
||||
public abstract class SingleThreadQueueExtent implements IQueueExtent {
|
||||
|
||||
// Pool discarded chunks for reuse (can safely be cleared by another thread)
|
||||
private static final ConcurrentLinkedQueue<IChunk> CHUNK_POOL = new ConcurrentLinkedQueue<>();
|
||||
// Chunks currently being queued / worked on
|
||||
private final Long2ObjectLinkedOpenHashMap<IChunk> chunks = new Long2ObjectLinkedOpenHashMap<>();
|
||||
private WorldChunkCache cache;
|
||||
private Thread currentThread;
|
||||
private ConcurrentLinkedQueue<Future> submissions = new ConcurrentLinkedQueue<>();
|
||||
// Last access pointers
|
||||
private IChunk lastChunk;
|
||||
private long lastPair = Long.MAX_VALUE;
|
||||
|
||||
/**
|
||||
* Safety check to ensure that the thread being used matches the one being initialized on.
|
||||
* - Can be removed later
|
||||
* Safety check to ensure that the thread being used matches the one being initialized on. - Can
|
||||
* be removed later
|
||||
*/
|
||||
private void checkThread() {
|
||||
if (Thread.currentThread() != currentThread && currentThread != null) {
|
||||
throw new UnsupportedOperationException("This class must be used from a single thread. Use multiple queues for concurrent operations");
|
||||
throw new UnsupportedOperationException(
|
||||
"This class must be used from a single thread. Use multiple queues for concurrent operations");
|
||||
}
|
||||
}
|
||||
|
||||
@ -60,10 +69,11 @@ public abstract class SingleThreadQueueExtent implements IQueueExtent {
|
||||
|
||||
/**
|
||||
* Initialize the queue
|
||||
*
|
||||
* @param cache
|
||||
*/
|
||||
@Override
|
||||
public synchronized void init(final WorldChunkCache cache) {
|
||||
public synchronized void init(WorldChunkCache cache) {
|
||||
if (this.cache != null) {
|
||||
reset();
|
||||
}
|
||||
@ -72,15 +82,7 @@ public abstract class SingleThreadQueueExtent implements IQueueExtent {
|
||||
this.cache = cache;
|
||||
}
|
||||
|
||||
// Last access pointers
|
||||
private IChunk lastChunk;
|
||||
private long lastPair = Long.MAX_VALUE;
|
||||
// Chunks currently being queued / worked on
|
||||
private final Long2ObjectLinkedOpenHashMap<IChunk> chunks = new Long2ObjectLinkedOpenHashMap<>();
|
||||
// Pool discarded chunks for reuse (can safely be cleared by another thread)
|
||||
private static final ConcurrentLinkedQueue<IChunk> CHUNK_POOL = new ConcurrentLinkedQueue<>();
|
||||
|
||||
public void returnToPool(final IChunk chunk) {
|
||||
public void returnToPool(IChunk chunk) {
|
||||
CHUNK_POOL.add(chunk);
|
||||
}
|
||||
|
||||
@ -95,7 +97,7 @@ public abstract class SingleThreadQueueExtent implements IQueueExtent {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends Future<T>> T submit(final IChunk<T> chunk) {
|
||||
public <T extends Future<T>> T submit(IChunk<T> chunk) {
|
||||
if (lastChunk == chunk) {
|
||||
lastPair = Long.MAX_VALUE;
|
||||
lastChunk = null;
|
||||
@ -107,11 +109,12 @@ public abstract class SingleThreadQueueExtent implements IQueueExtent {
|
||||
|
||||
/**
|
||||
* Submit without first checking that it has been removed from the chunk map
|
||||
*
|
||||
* @param chunk
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
private <T extends Future<T>> T submitUnchecked(final IChunk<T> chunk) {
|
||||
private <T extends Future<T>> T submitUnchecked(IChunk<T> chunk) {
|
||||
if (chunk.isEmpty()) {
|
||||
CHUNK_POOL.add(chunk);
|
||||
return (T) (Future) Futures.immediateFuture(null);
|
||||
@ -125,7 +128,7 @@ public abstract class SingleThreadQueueExtent implements IQueueExtent {
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean trim(final boolean aggressive) {
|
||||
public synchronized boolean trim(boolean aggressive) {
|
||||
// TODO trim individial chunk sections
|
||||
CHUNK_POOL.clear();
|
||||
if (Thread.currentThread() == currentThread) {
|
||||
@ -146,13 +149,14 @@ public abstract class SingleThreadQueueExtent implements IQueueExtent {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a new IChunk from either the pool, or create a new one<br>
|
||||
* + Initialize it at the coordinates
|
||||
* Get a new IChunk from either the pool, or create a new one<br> + Initialize it at the
|
||||
* coordinates
|
||||
*
|
||||
* @param X
|
||||
* @param Z
|
||||
* @return IChunk
|
||||
*/
|
||||
private IChunk poolOrCreate(final int X, final int Z) {
|
||||
private IChunk poolOrCreate(int X, int Z) {
|
||||
IChunk next = CHUNK_POOL.poll();
|
||||
if (next == null) {
|
||||
next = create(false);
|
||||
@ -162,21 +166,23 @@ public abstract class SingleThreadQueueExtent implements IQueueExtent {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final IChunk getCachedChunk(final int x, final int z) {
|
||||
final long pair = (((long) x) << 32) | (z & 0xffffffffL);
|
||||
public final IChunk getCachedChunk(int x, int z) {
|
||||
final long pair = (long) x << 32 | z & 0xffffffffL;
|
||||
if (pair == lastPair) {
|
||||
return lastChunk;
|
||||
}
|
||||
|
||||
IChunk chunk = chunks.get(pair);
|
||||
if (chunk instanceof ReferenceChunk) {
|
||||
chunk = ((ReferenceChunk) (chunk)).getParent();
|
||||
chunk = ((ReferenceChunk) chunk).getParent();
|
||||
}
|
||||
if (chunk != null) {
|
||||
lastPair = pair;
|
||||
lastChunk = chunk;
|
||||
}
|
||||
if (chunk != null) return chunk;
|
||||
if (chunk != null) {
|
||||
return chunk;
|
||||
}
|
||||
|
||||
checkThread();
|
||||
final int size = chunks.size();
|
||||
@ -205,14 +211,15 @@ public abstract class SingleThreadQueueExtent implements IQueueExtent {
|
||||
return chunk;
|
||||
}
|
||||
|
||||
private void pollSubmissions(final int targetSize, final boolean aggressive) {
|
||||
private void pollSubmissions(int targetSize, boolean aggressive) {
|
||||
final int overflow = submissions.size() - targetSize;
|
||||
if (aggressive) {
|
||||
for (int i = 0; i < overflow; i++) {
|
||||
Future first = submissions.poll();
|
||||
try {
|
||||
while ((first = (Future) first.get()) != null) ;
|
||||
} catch (final InterruptedException | ExecutionException e) {
|
||||
while ((first = (Future) first.get()) != null) {
|
||||
}
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@ -223,7 +230,7 @@ public abstract class SingleThreadQueueExtent implements IQueueExtent {
|
||||
if (next.isDone()) {
|
||||
try {
|
||||
next = (Future) next.get();
|
||||
} catch (final InterruptedException | ExecutionException e) {
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
@ -240,7 +247,7 @@ public abstract class SingleThreadQueueExtent implements IQueueExtent {
|
||||
checkThread();
|
||||
if (!chunks.isEmpty()) {
|
||||
if (MemUtil.isMemoryLimited()) {
|
||||
for (final IChunk chunk : chunks.values()) {
|
||||
for (IChunk chunk : chunks.values()) {
|
||||
final Future future = submitUnchecked(chunk);
|
||||
if (future != null && !future.isDone()) {
|
||||
pollSubmissions(Settings.IMP.QUEUE.PARALLEL_THREADS, true);
|
||||
@ -248,7 +255,7 @@ public abstract class SingleThreadQueueExtent implements IQueueExtent {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (final IChunk chunk : chunks.values()) {
|
||||
for (IChunk chunk : chunks.values()) {
|
||||
final Future future = submitUnchecked(chunk);
|
||||
if (future != null && !future.isDone()) {
|
||||
submissions.add(future);
|
||||
|
@ -6,19 +6,19 @@ import com.sk89q.worldedit.world.World;
|
||||
import it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectIterator;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* IGetBlocks may be cached by the WorldChunkCache so that it can be used between multiple IQueueExtents
|
||||
* - avoids conversion between palette and raw data on every block get
|
||||
* IGetBlocks may be cached by the WorldChunkCache so that it can be used between multiple
|
||||
* IQueueExtents - avoids conversion between palette and raw data on every block get
|
||||
*/
|
||||
public class WorldChunkCache implements Trimable {
|
||||
|
||||
protected final Long2ObjectLinkedOpenHashMap<WeakReference<IChunkGet>> getCache;
|
||||
private final World world;
|
||||
|
||||
protected WorldChunkCache(final World world) {
|
||||
protected WorldChunkCache(World world) {
|
||||
this.world = world;
|
||||
this.getCache = new Long2ObjectLinkedOpenHashMap<>();
|
||||
}
|
||||
@ -33,15 +33,18 @@ public class WorldChunkCache implements Trimable {
|
||||
|
||||
/**
|
||||
* Get or create the IGetBlocks
|
||||
*
|
||||
* @param index chunk index {@link com.boydti.fawe.util.MathMan#pairInt(int, int)}
|
||||
* @param provider used to create if it isn't already cached
|
||||
* @return cached IGetBlocks
|
||||
*/
|
||||
public synchronized IChunkGet get(final long index, final Supplier<IChunkGet> provider) {
|
||||
public synchronized IChunkGet get(long index, Supplier<IChunkGet> provider) {
|
||||
final WeakReference<IChunkGet> ref = getCache.get(index);
|
||||
if (ref != null) {
|
||||
final IChunkGet blocks = ref.get();
|
||||
if (blocks != null) return blocks;
|
||||
if (blocks != null) {
|
||||
return blocks;
|
||||
}
|
||||
}
|
||||
final IChunkGet blocks = provider.get();
|
||||
getCache.put(index, new WeakReference<>(blocks));
|
||||
@ -49,18 +52,22 @@ public class WorldChunkCache implements Trimable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean trim(final boolean aggressive) {
|
||||
public synchronized boolean trim(boolean aggressive) {
|
||||
boolean result = true;
|
||||
if (!getCache.isEmpty()) {
|
||||
final ObjectIterator<Long2ObjectMap.Entry<WeakReference<IChunkGet>>> iter = getCache.long2ObjectEntrySet().fastIterator();
|
||||
final ObjectIterator<Long2ObjectMap.Entry<WeakReference<IChunkGet>>> iter = getCache
|
||||
.long2ObjectEntrySet().fastIterator();
|
||||
while (iter.hasNext()) {
|
||||
final Long2ObjectMap.Entry<WeakReference<IChunkGet>> entry = iter.next();
|
||||
final WeakReference<IChunkGet> value = entry.getValue();
|
||||
final IChunkGet igb = value.get();
|
||||
if (igb == null) iter.remove();
|
||||
else {
|
||||
if (igb == null) {
|
||||
iter.remove();
|
||||
} else {
|
||||
result = false;
|
||||
if (!aggressive) return result;
|
||||
if (!aggressive) {
|
||||
return result;
|
||||
}
|
||||
synchronized (igb) {
|
||||
igb.trim(aggressive);
|
||||
}
|
||||
|
@ -1,22 +1,17 @@
|
||||
package com.boydti.fawe.beta.implementation.blocks;
|
||||
|
||||
import com.boydti.fawe.FaweCache;
|
||||
import com.boydti.fawe.beta.IChunkSet;
|
||||
import com.boydti.fawe.object.collection.BitArray4096;
|
||||
import com.boydti.fawe.object.collection.BlockSet;
|
||||
import com.boydti.fawe.object.collection.MemBlockSet;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
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.BlockStateHolder;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public class BitSetBlocks implements IChunkSet {
|
||||
|
||||
private final MemBlockSet.RowZ row;
|
||||
private final BlockState blockState;
|
||||
|
||||
@ -43,13 +38,16 @@ public class BitSetBlocks implements IChunkSet {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTile(int x, int y, int z, CompoundTag tile) {}
|
||||
public void setTile(int x, int y, int z, CompoundTag tile) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEntity(CompoundTag tag) {}
|
||||
public void setEntity(CompoundTag tag) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeEntity(UUID uuid) {}
|
||||
public void removeEntity(UUID uuid) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getBlock(int x, int y, int z) {
|
||||
|
@ -4,6 +4,26 @@ import com.boydti.fawe.beta.IBlocks;
|
||||
import com.boydti.fawe.beta.IChunkSet;
|
||||
|
||||
public class CharBlocks implements IBlocks {
|
||||
|
||||
public static final Section FULL = new Section() {
|
||||
@Override
|
||||
public final char[] get(CharBlocks blocks, int layer) {
|
||||
return blocks.blocks[layer];
|
||||
}
|
||||
};
|
||||
public static final Section EMPTY = new Section() {
|
||||
@Override
|
||||
public final char[] get(CharBlocks blocks, int layer) {
|
||||
blocks.sections[layer] = FULL;
|
||||
char[] arr = blocks.blocks[layer];
|
||||
if (arr == null) {
|
||||
arr = blocks.blocks[layer] = blocks.load(layer);
|
||||
} else {
|
||||
blocks.blocks[layer] = blocks.load(layer, arr);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
};
|
||||
public final char[][] blocks;
|
||||
public final Section[] sections;
|
||||
|
||||
@ -15,11 +35,13 @@ public class CharBlocks implements IBlocks {
|
||||
public CharBlocks() {
|
||||
blocks = new char[16][];
|
||||
sections = new Section[16];
|
||||
for (int i = 0; i < 16; i++) sections[i] = EMPTY;
|
||||
for (int i = 0; i < 16; i++) {
|
||||
sections[i] = EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean trim(final boolean aggressive) {
|
||||
public boolean trim(boolean aggressive) {
|
||||
boolean result = true;
|
||||
for (int i = 0; i < 16; i++) {
|
||||
if (sections[i] == EMPTY) {
|
||||
@ -33,82 +55,67 @@ public class CharBlocks implements IBlocks {
|
||||
|
||||
@Override
|
||||
public IChunkSet reset() {
|
||||
for (int i = 0; i < 16; i++) sections[i] = EMPTY;
|
||||
for (int i = 0; i < 16; i++) {
|
||||
sections[i] = EMPTY;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void reset(final int layer) {
|
||||
public void reset(int layer) {
|
||||
sections[layer] = EMPTY;
|
||||
}
|
||||
|
||||
public char[] load(final int layer) {
|
||||
public char[] load(int layer) {
|
||||
return new char[4096];
|
||||
}
|
||||
|
||||
public char[] load(final int layer, final char[] data) {
|
||||
for (int i = 0; i < 4096; i++) data[i] = 0;
|
||||
public char[] load(int layer, char[] data) {
|
||||
for (int i = 0; i < 4096; i++) {
|
||||
data[i] = 0;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSection(final int layer) {
|
||||
public boolean hasSection(int layer) {
|
||||
return sections[layer] == FULL;
|
||||
}
|
||||
|
||||
public char get(final int x, final int y, final int z) {
|
||||
public char get(int x, int y, int z) {
|
||||
final int layer = y >> 4;
|
||||
final int index = ((y & 15) << 8) | (z << 4) | (x);
|
||||
final int index = (y & 15) << 8 | z << 4 | x;
|
||||
return sections[layer].get(this, layer, index);
|
||||
}
|
||||
|
||||
public void set(final int x, final int y, final int z, final char value) {
|
||||
public void set(int x, int y, int z, char value) {
|
||||
final int layer = y >> 4;
|
||||
final int index = ((y & 15) << 8) | (z << 4) | (x);
|
||||
final int index = (y & 15) << 8 | z << 4 | x;
|
||||
set(layer, index, value);
|
||||
}
|
||||
|
||||
public final char get(final int layer, final int index) {
|
||||
return sections[layer].get(this, layer, index);
|
||||
}
|
||||
|
||||
public final void set(final int layer, final int index, final char value) {
|
||||
sections[layer].set(this, layer, index, value);
|
||||
}
|
||||
|
||||
/*
|
||||
Section
|
||||
*/
|
||||
|
||||
public final char get(int layer, int index) {
|
||||
return sections[layer].get(this, layer, index);
|
||||
}
|
||||
|
||||
public final void set(int layer, int index, char value) {
|
||||
sections[layer].set(this, layer, index, value);
|
||||
}
|
||||
|
||||
public static abstract class Section {
|
||||
|
||||
public abstract char[] get(CharBlocks blocks, int layer);
|
||||
|
||||
public final char get(final CharBlocks blocks, final int layer, final int index) {
|
||||
public final char get(CharBlocks blocks, int layer, int index) {
|
||||
return get(blocks, layer)[index];
|
||||
}
|
||||
|
||||
public final void set(final CharBlocks blocks, final int layer, final int index, final char value) {
|
||||
public final void set(CharBlocks blocks, int layer, int index,
|
||||
char value) {
|
||||
get(blocks, layer)[index] = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static final Section EMPTY = new Section() {
|
||||
@Override
|
||||
public final char[] get(final CharBlocks blocks, final int layer) {
|
||||
blocks.sections[layer] = FULL;
|
||||
char[] arr = blocks.blocks[layer];
|
||||
if (arr == null) {
|
||||
arr = blocks.blocks[layer] = blocks.load(layer);
|
||||
} else {
|
||||
blocks.blocks[layer] = blocks.load(layer, arr);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
};
|
||||
|
||||
public static final Section FULL = new Section() {
|
||||
@Override
|
||||
public final char[] get(final CharBlocks blocks, final int layer) {
|
||||
return blocks.blocks[layer];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -7,18 +7,19 @@ import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
public abstract class CharGetBlocks extends CharBlocks implements IChunkGet {
|
||||
|
||||
@Override
|
||||
public BaseBlock getFullBlock(final int x, final int y, final int z) {
|
||||
public BaseBlock getFullBlock(int x, int y, int z) {
|
||||
return BlockTypes.states[get(x, y, z)].toBaseBlock();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getBlock(final int x, final int y, final int z) {
|
||||
public BlockState getBlock(int x, int y, int z) {
|
||||
return BlockTypes.states[get(x, y, z)];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean trim(final boolean aggressive) {
|
||||
public boolean trim(boolean aggressive) {
|
||||
for (int i = 0; i < 16; i++) {
|
||||
sections[i] = EMPTY;
|
||||
blocks[i] = null;
|
||||
|
@ -7,7 +7,6 @@ import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
@ -15,6 +14,7 @@ import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public class CharSetBlocks extends CharBlocks implements IChunkSet {
|
||||
|
||||
public BiomeType[] biomes;
|
||||
public HashMap<Short, CompoundTag> tiles;
|
||||
public HashSet<CompoundTag> entities;
|
||||
@ -57,7 +57,7 @@ public class CharSetBlocks extends CharBlocks implements IChunkSet {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBiome(final int x, final int y, final int z, final BiomeType biome) {
|
||||
public boolean setBiome(int x, int y, int z, BiomeType biome) {
|
||||
if (biomes == null) {
|
||||
biomes = new BiomeType[256];
|
||||
}
|
||||
@ -71,13 +71,13 @@ public class CharSetBlocks extends CharBlocks implements IChunkSet {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBlock(final int x, final int y, final int z, final BlockStateHolder holder) {
|
||||
public boolean setBlock(int x, int y, int z, BlockStateHolder holder) {
|
||||
set(x, y, z, holder.getOrdinalChar());
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTile(final int x, final int y, final int z, final CompoundTag tile) {
|
||||
public void setTile(int x, int y, int z, CompoundTag tile) {
|
||||
if (tiles == null) {
|
||||
tiles = new HashMap<>();
|
||||
}
|
||||
@ -86,7 +86,7 @@ public class CharSetBlocks extends CharBlocks implements IChunkSet {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEntity(final CompoundTag tag) {
|
||||
public void setEntity(CompoundTag tag) {
|
||||
if (entities == null) {
|
||||
entities = new HashSet<>();
|
||||
}
|
||||
@ -94,7 +94,7 @@ public class CharSetBlocks extends CharBlocks implements IChunkSet {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeEntity(final UUID uuid) {
|
||||
public void removeEntity(UUID uuid) {
|
||||
if (entityRemoves == null) {
|
||||
entityRemoves = new HashSet<>();
|
||||
}
|
||||
@ -103,7 +103,9 @@ public class CharSetBlocks extends CharBlocks implements IChunkSet {
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
if (biomes != null) return false;
|
||||
if (biomes != null) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < 16; i++) {
|
||||
if (hasSection(i)) {
|
||||
return false;
|
||||
|
@ -16,14 +16,150 @@ 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.BlockStateHolder;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.function.Supplier;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Abstract IChunk class that implements basic get/set blocks
|
||||
* An abstract {@link IChunk} class that implements basic get/set blocks
|
||||
*/
|
||||
public abstract class ChunkHolder implements IChunk, Supplier<IChunkGet> {
|
||||
|
||||
public static final IBlockDelegate BOTH = new IBlockDelegate() {
|
||||
@Override
|
||||
public boolean setBiome(ChunkHolder chunk, int x, int y, int z,
|
||||
BiomeType biome) {
|
||||
return chunk.set.setBiome(x, y, z, biome);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBlock(ChunkHolder chunk, int x, int y, int z,
|
||||
BlockStateHolder block) {
|
||||
return chunk.set.setBlock(x, y, z, block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeType getBiome(ChunkHolder chunk, int x, int z) {
|
||||
return chunk.get.getBiomeType(x, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getBlock(ChunkHolder chunk, int x, int y, int z) {
|
||||
return chunk.get.getBlock(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBlock getFullBlock(ChunkHolder chunk, int x, int y,
|
||||
int z) {
|
||||
return chunk.get.getFullBlock(x, y, z);
|
||||
}
|
||||
};
|
||||
public static final IBlockDelegate GET = new IBlockDelegate() {
|
||||
@Override
|
||||
public boolean setBiome(ChunkHolder chunk, int x, int y, int z,
|
||||
BiomeType biome) {
|
||||
chunk.getOrCreateSet();
|
||||
chunk.delegate = BOTH;
|
||||
return chunk.setBiome(x, y, z, biome);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBlock(ChunkHolder chunk, int x, int y, int z,
|
||||
BlockStateHolder block) {
|
||||
chunk.getOrCreateSet();
|
||||
chunk.delegate = BOTH;
|
||||
return chunk.setBlock(x, y, z, block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeType getBiome(ChunkHolder chunk, int x, int z) {
|
||||
return chunk.get.getBiomeType(x, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getBlock(ChunkHolder chunk, int x, int y, int z) {
|
||||
return chunk.get.getBlock(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBlock getFullBlock(ChunkHolder chunk, int x, int y,
|
||||
int z) {
|
||||
return chunk.get.getFullBlock(x, y, z);
|
||||
}
|
||||
};
|
||||
public static final IBlockDelegate SET = new IBlockDelegate() {
|
||||
@Override
|
||||
public boolean setBiome(ChunkHolder chunk, int x, int y, int z,
|
||||
BiomeType biome) {
|
||||
return chunk.set.setBiome(x, y, z, biome);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBlock(ChunkHolder chunk, int x, int y, int z,
|
||||
BlockStateHolder block) {
|
||||
return chunk.set.setBlock(x, y, z, block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeType getBiome(ChunkHolder chunk, int x, int z) {
|
||||
chunk.getOrCreateGet();
|
||||
chunk.delegate = BOTH;
|
||||
return chunk.getBiomeType(x, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getBlock(ChunkHolder chunk, int x, int y, int z) {
|
||||
chunk.getOrCreateGet();
|
||||
chunk.delegate = BOTH;
|
||||
return chunk.getBlock(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBlock getFullBlock(ChunkHolder chunk, int x, int y,
|
||||
int z) {
|
||||
chunk.getOrCreateGet();
|
||||
chunk.delegate = BOTH;
|
||||
return chunk.getFullBlock(x, y, z);
|
||||
}
|
||||
};
|
||||
public static final IBlockDelegate NULL = new IBlockDelegate() {
|
||||
@Override
|
||||
public boolean setBiome(ChunkHolder chunk, int x, int y, int z,
|
||||
BiomeType biome) {
|
||||
chunk.getOrCreateSet();
|
||||
chunk.delegate = SET;
|
||||
return chunk.setBiome(x, y, z, biome);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBlock(ChunkHolder chunk, int x, int y, int z,
|
||||
BlockStateHolder block) {
|
||||
chunk.getOrCreateSet();
|
||||
chunk.delegate = SET;
|
||||
return chunk.setBlock(x, y, z, block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeType getBiome(ChunkHolder chunk, int x, int z) {
|
||||
chunk.getOrCreateGet();
|
||||
chunk.delegate = GET;
|
||||
return chunk.getBiomeType(x, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getBlock(ChunkHolder chunk, int x, int y, int z) {
|
||||
chunk.getOrCreateGet();
|
||||
chunk.delegate = GET;
|
||||
return chunk.getBlock(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBlock getFullBlock(ChunkHolder chunk, int x, int y,
|
||||
int z) {
|
||||
chunk.getOrCreateGet();
|
||||
chunk.delegate = GET;
|
||||
return chunk.getFullBlock(x, y, z);
|
||||
}
|
||||
};
|
||||
private IChunkGet get;
|
||||
private IChunkSet set;
|
||||
private IBlockDelegate delegate;
|
||||
@ -35,7 +171,7 @@ public abstract class ChunkHolder implements IChunk, Supplier<IChunkGet> {
|
||||
this.delegate = NULL;
|
||||
}
|
||||
|
||||
public ChunkHolder(final IBlockDelegate delegate) {
|
||||
public ChunkHolder(IBlockDelegate delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@ -46,7 +182,8 @@ public abstract class ChunkHolder implements IChunk, Supplier<IChunkGet> {
|
||||
|
||||
@Override
|
||||
public CompoundTag getTag(int x, int y, int z) {
|
||||
return delegate.getFullBlock(this, x, y, z).getNbtData(); // TODO NOT IMPLEMENTED (add getTag delegate)
|
||||
return delegate.getFullBlock(this, x, y, z)
|
||||
.getNbtData(); // TODO NOT IMPLEMENTED (add getTag delegate)
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -55,7 +192,7 @@ public abstract class ChunkHolder implements IChunk, Supplier<IChunkGet> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void filterBlocks(final Filter filter, ChunkFilterBlock block, @Nullable Region region) {
|
||||
public void filterBlocks(Filter filter, ChunkFilterBlock block, @Nullable Region region) {
|
||||
final IChunkGet get = getOrCreateGet();
|
||||
final IChunkSet set = getOrCreateSet();
|
||||
try {
|
||||
@ -64,7 +201,9 @@ public abstract class ChunkHolder implements IChunk, Supplier<IChunkGet> {
|
||||
} else {
|
||||
block = block.init(chunkX, chunkZ, get);
|
||||
for (int layer = 0; layer < 16; layer++) {
|
||||
if (!get.hasSection(layer) || !filter.appliesLayer(this, layer)) continue;
|
||||
if (!get.hasSection(layer) || !filter.appliesLayer(this, layer)) {
|
||||
continue;
|
||||
}
|
||||
block.init(get, set, layer);
|
||||
block.filter(filter);
|
||||
}
|
||||
@ -75,7 +214,7 @@ public abstract class ChunkHolder implements IChunk, Supplier<IChunkGet> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean trim(final boolean aggressive) {
|
||||
public boolean trim(boolean aggressive) {
|
||||
if (set != null) {
|
||||
final boolean result = set.trim(aggressive);
|
||||
if (result) {
|
||||
@ -104,12 +243,16 @@ public abstract class ChunkHolder implements IChunk, Supplier<IChunkGet> {
|
||||
}
|
||||
|
||||
public final IChunkGet getOrCreateGet() {
|
||||
if (get == null) get = newGet();
|
||||
if (get == null) {
|
||||
get = newGet();
|
||||
}
|
||||
return get;
|
||||
}
|
||||
|
||||
public final IChunkSet getOrCreateSet() {
|
||||
if (set == null) set = set();
|
||||
if (set == null) {
|
||||
set = set();
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
@ -128,7 +271,7 @@ public abstract class ChunkHolder implements IChunk, Supplier<IChunkGet> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(final IQueueExtent extent, final int chunkX, final int chunkZ) {
|
||||
public void init(IQueueExtent extent, int chunkX, int chunkZ) {
|
||||
this.extent = extent;
|
||||
this.chunkX = chunkX;
|
||||
this.chunkZ = chunkZ;
|
||||
@ -156,167 +299,42 @@ public abstract class ChunkHolder implements IChunk, Supplier<IChunkGet> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBiome(final int x, final int y, final int z, final BiomeType biome) {
|
||||
public boolean setBiome(int x, int y, int z, BiomeType biome) {
|
||||
return delegate.setBiome(this, x, y, z, biome);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBlock(final int x, final int y, final int z, final BlockStateHolder block) {
|
||||
public boolean setBlock(int x, int y, int z, BlockStateHolder block) {
|
||||
return delegate.setBlock(this, x, y, z, block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeType getBiomeType(final int x, final int z) {
|
||||
public BiomeType getBiomeType(int x, int z) {
|
||||
return delegate.getBiome(this, x, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getBlock(final int x, final int y, final int z) {
|
||||
public BlockState getBlock(int x, int y, int z) {
|
||||
return delegate.getBlock(this, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBlock getFullBlock(final int x, final int y, final int z) {
|
||||
public BaseBlock getFullBlock(int x, int y, int z) {
|
||||
return delegate.getFullBlock(this, x, y, z);
|
||||
}
|
||||
|
||||
public interface IBlockDelegate {
|
||||
boolean setBiome(final ChunkHolder chunk, final int x, final int y, final int z, final BiomeType biome);
|
||||
|
||||
boolean setBlock(final ChunkHolder chunk, final int x, final int y, final int z, final BlockStateHolder holder);
|
||||
boolean setBiome(ChunkHolder chunk, int x, int y, int z,
|
||||
BiomeType biome);
|
||||
|
||||
BiomeType getBiome(final ChunkHolder chunk, final int x, final int z);
|
||||
boolean setBlock(ChunkHolder chunk, int x, int y, int z,
|
||||
BlockStateHolder holder);
|
||||
|
||||
BlockState getBlock(final ChunkHolder chunk, final int x, final int y, final int z);
|
||||
BiomeType getBiome(ChunkHolder chunk, int x, int z);
|
||||
|
||||
BaseBlock getFullBlock(final ChunkHolder chunk, final int x, final int y, final int z);
|
||||
BlockState getBlock(ChunkHolder chunk, int x, int y, int z);
|
||||
|
||||
BaseBlock getFullBlock(ChunkHolder chunk, int x, int y, int z);
|
||||
}
|
||||
|
||||
public static final IBlockDelegate NULL = new IBlockDelegate() {
|
||||
@Override
|
||||
public boolean setBiome(final ChunkHolder chunk, final int x, final int y, final int z, final BiomeType biome) {
|
||||
chunk.getOrCreateSet();
|
||||
chunk.delegate = SET;
|
||||
return chunk.setBiome(x, y, z, biome);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBlock(final ChunkHolder chunk, final int x, final int y, final int z, final BlockStateHolder block) {
|
||||
chunk.getOrCreateSet();
|
||||
chunk.delegate = SET;
|
||||
return chunk.setBlock(x, y, z, block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeType getBiome(final ChunkHolder chunk, final int x, final int z) {
|
||||
chunk.getOrCreateGet();
|
||||
chunk.delegate = GET;
|
||||
return chunk.getBiomeType(x, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getBlock(final ChunkHolder chunk, final int x, final int y, final int z) {
|
||||
chunk.getOrCreateGet();
|
||||
chunk.delegate = GET;
|
||||
return chunk.getBlock(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBlock getFullBlock(final ChunkHolder chunk, final int x, final int y, final int z) {
|
||||
chunk.getOrCreateGet();
|
||||
chunk.delegate = GET;
|
||||
return chunk.getFullBlock(x, y, z);
|
||||
}
|
||||
};
|
||||
|
||||
public static final IBlockDelegate GET = new IBlockDelegate() {
|
||||
@Override
|
||||
public boolean setBiome(final ChunkHolder chunk, final int x, final int y, final int z, final BiomeType biome) {
|
||||
chunk.getOrCreateSet();
|
||||
chunk.delegate = BOTH;
|
||||
return chunk.setBiome(x, y, z, biome);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBlock(final ChunkHolder chunk, final int x, final int y, final int z, final BlockStateHolder block) {
|
||||
chunk.getOrCreateSet();
|
||||
chunk.delegate = BOTH;
|
||||
return chunk.setBlock(x, y, z, block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeType getBiome(final ChunkHolder chunk, final int x, final int z) {
|
||||
return chunk.get.getBiomeType(x, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getBlock(final ChunkHolder chunk, final int x, final int y, final int z) {
|
||||
return chunk.get.getBlock(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBlock getFullBlock(final ChunkHolder chunk, final int x, final int y, final int z) {
|
||||
return chunk.get.getFullBlock(x, y, z);
|
||||
}
|
||||
};
|
||||
|
||||
public static final IBlockDelegate SET = new IBlockDelegate() {
|
||||
@Override
|
||||
public boolean setBiome(final ChunkHolder chunk, final int x, final int y, final int z, final BiomeType biome) {
|
||||
return chunk.set.setBiome(x, y, z, biome);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBlock(final ChunkHolder chunk, final int x, final int y, final int z, final BlockStateHolder block) {
|
||||
return chunk.set.setBlock(x, y, z, block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeType getBiome(final ChunkHolder chunk, final int x, final int z) {
|
||||
chunk.getOrCreateGet();
|
||||
chunk.delegate = BOTH;
|
||||
return chunk.getBiomeType(x, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getBlock(final ChunkHolder chunk, final int x, final int y, final int z) {
|
||||
chunk.getOrCreateGet();
|
||||
chunk.delegate = BOTH;
|
||||
return chunk.getBlock(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBlock getFullBlock(final ChunkHolder chunk, final int x, final int y, final int z) {
|
||||
chunk.getOrCreateGet();
|
||||
chunk.delegate = BOTH;
|
||||
return chunk.getFullBlock(x, y, z);
|
||||
}
|
||||
};
|
||||
|
||||
public static final IBlockDelegate BOTH = new IBlockDelegate() {
|
||||
@Override
|
||||
public boolean setBiome(final ChunkHolder chunk, final int x, final int y, final int z, final BiomeType biome) {
|
||||
return chunk.set.setBiome(x, y, z, biome);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBlock(final ChunkHolder chunk, final int x, final int y, final int z, final BlockStateHolder block) {
|
||||
return chunk.set.setBlock(x, y, z, block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeType getBiome(final ChunkHolder chunk, final int x, final int z) {
|
||||
return chunk.get.getBiomeType(x, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getBlock(final ChunkHolder chunk, final int x, final int y, final int z) {
|
||||
return chunk.get.getBlock(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBlock getFullBlock(final ChunkHolder chunk, final int x, final int y, final int z) {
|
||||
return chunk.get.getFullBlock(x, y, z);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -1,33 +1,27 @@
|
||||
package com.boydti.fawe.beta.implementation.holder;
|
||||
|
||||
import com.boydti.fawe.beta.ChunkFilterBlock;
|
||||
import com.boydti.fawe.beta.Filter;
|
||||
import com.boydti.fawe.beta.FilterBlock;
|
||||
import com.boydti.fawe.beta.FilterBlockMask;
|
||||
import com.boydti.fawe.beta.Flood;
|
||||
import com.boydti.fawe.beta.IChunk;
|
||||
import com.boydti.fawe.beta.IDelegateChunk;
|
||||
import com.sk89q.worldedit.math.MutableBlockVector3;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Implementation of IDelegateChunk
|
||||
*
|
||||
* @param <T>
|
||||
*/
|
||||
public class DelegateChunk<T extends IChunk> implements IDelegateChunk {
|
||||
|
||||
private T parent;
|
||||
|
||||
public DelegateChunk(final T parent) {
|
||||
public DelegateChunk(T parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final T getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public final void setParent(final T parent) {
|
||||
public final void setParent(T parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
}
|
@ -1,22 +1,24 @@
|
||||
package com.boydti.fawe.beta.implementation.holder;
|
||||
|
||||
import com.boydti.fawe.beta.IQueueExtent;
|
||||
import com.boydti.fawe.beta.IChunk;
|
||||
import com.boydti.fawe.beta.IQueueExtent;
|
||||
|
||||
/**
|
||||
* Used by {@link ReferenceChunk} to allow the chunk to be garbage collected
|
||||
* - When the object is finalized, add it to the queue
|
||||
* Used by {@link ReferenceChunk} to allow the chunk to be garbage collected. - When the object is
|
||||
* finalized, add it to the queue
|
||||
*/
|
||||
public class FinalizedChunk extends DelegateChunk {
|
||||
|
||||
private final IQueueExtent queueExtent;
|
||||
|
||||
public FinalizedChunk(final IChunk parent, final IQueueExtent queueExtent) {
|
||||
public FinalizedChunk(IChunk parent, IQueueExtent queueExtent) {
|
||||
super(parent);
|
||||
this.queueExtent = queueExtent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit the chunk to the queue
|
||||
*
|
||||
* @throws Throwable
|
||||
*/
|
||||
@Override
|
||||
|
@ -3,26 +3,26 @@ package com.boydti.fawe.beta.implementation.holder;
|
||||
import com.boydti.fawe.beta.IChunk;
|
||||
import com.boydti.fawe.beta.IDelegateChunk;
|
||||
import com.boydti.fawe.beta.IQueueExtent;
|
||||
|
||||
import java.lang.ref.Reference;
|
||||
|
||||
/**
|
||||
* An IChunk may be wrapped by a ReferenceChunk if there is low memory<br>
|
||||
* A reference chunk stores a reference (for garbage collection purposes)<br>
|
||||
* - If it is garbage collected, the {@link FinalizedChunk} logic is run
|
||||
* An {@link IChunk} may be wrapped by a ReferenceChunk if there is low memory. This class stores a
|
||||
* reference for garbage collection purposes. If it cleaned by garbage collection, the {@link
|
||||
* FinalizedChunk} logic is run.
|
||||
*/
|
||||
public abstract class ReferenceChunk implements IDelegateChunk {
|
||||
private final Reference<FinalizedChunk> ref;
|
||||
|
||||
public ReferenceChunk(final IChunk parent, final IQueueExtent queueExtent) {
|
||||
this.ref = toRef(new FinalizedChunk(parent, queueExtent));
|
||||
private final Reference<FinalizedChunk> reference;
|
||||
|
||||
public ReferenceChunk(IChunk parent, IQueueExtent queueExtent) {
|
||||
this.reference = toReference(new FinalizedChunk(parent, queueExtent));
|
||||
}
|
||||
|
||||
protected abstract Reference<FinalizedChunk> toRef(FinalizedChunk parent);
|
||||
protected abstract Reference<FinalizedChunk> toReference(FinalizedChunk parent);
|
||||
|
||||
@Override
|
||||
public IChunk getParent() {
|
||||
final FinalizedChunk finalized = ref.get();
|
||||
final FinalizedChunk finalized = reference.get();
|
||||
return finalized != null ? finalized.getParent() : null;
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package com.boydti.fawe.beta.implementation.holder;
|
||||
|
||||
import com.boydti.fawe.beta.IChunk;
|
||||
import com.boydti.fawe.beta.IQueueExtent;
|
||||
|
||||
import java.lang.ref.Reference;
|
||||
import java.lang.ref.SoftReference;
|
||||
|
||||
@ -11,12 +10,12 @@ import java.lang.ref.SoftReference;
|
||||
*/
|
||||
public class SoftChunk extends ReferenceChunk {
|
||||
|
||||
public SoftChunk(final IChunk parent, final IQueueExtent queueExtent) {
|
||||
public SoftChunk(IChunk parent, IQueueExtent queueExtent) {
|
||||
super(parent, queueExtent);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Reference<FinalizedChunk> toRef(final FinalizedChunk parent) {
|
||||
protected Reference<FinalizedChunk> toReference(FinalizedChunk parent) {
|
||||
return new SoftReference<>(parent);
|
||||
}
|
||||
}
|
||||
|
@ -2,21 +2,20 @@ package com.boydti.fawe.beta.implementation.holder;
|
||||
|
||||
import com.boydti.fawe.beta.IChunk;
|
||||
import com.boydti.fawe.beta.IQueueExtent;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
|
||||
import java.lang.ref.Reference;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
/**
|
||||
* Weak reference implementation of {@link ReferenceChunk}
|
||||
* A {@link ReferenceChunk} using {@link WeakReference} to hold the chunk.
|
||||
*/
|
||||
public class WeakChunk extends ReferenceChunk {
|
||||
public WeakChunk(final IChunk parent, final IQueueExtent queueExtent) {
|
||||
|
||||
public WeakChunk(IChunk parent, IQueueExtent queueExtent) {
|
||||
super(parent, queueExtent);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Reference<FinalizedChunk> toRef(final FinalizedChunk parent) {
|
||||
protected Reference<FinalizedChunk> toReference(FinalizedChunk parent) {
|
||||
return new WeakReference<>(parent);
|
||||
}
|
||||
}
|
||||
|
@ -80,6 +80,7 @@ import java.util.List;
|
||||
import org.enginehub.piston.annotation.Command;
|
||||
import org.enginehub.piston.annotation.CommandContainer;
|
||||
import org.enginehub.piston.annotation.param.Arg;
|
||||
import org.enginehub.piston.annotation.param.ArgFlag;
|
||||
import org.enginehub.piston.annotation.param.Switch;
|
||||
import org.enginehub.piston.inject.InjectedValueAccess;
|
||||
|
||||
@ -547,7 +548,7 @@ public class RegionCommands {
|
||||
boolean skipEntities,
|
||||
@Switch(name = 'a', desc = "Ignore air blocks")
|
||||
boolean ignoreAirBlocks,
|
||||
@ArgFlag(name = "m", desc = "Source mask")
|
||||
@ArgFlag(name = 'm', desc = "Source mask")
|
||||
Mask sourceMask,
|
||||
InjectedValueAccess context) throws WorldEditException {
|
||||
player.checkConfirmationStack(() -> {
|
||||
@ -677,7 +678,7 @@ public class RegionCommands {
|
||||
int thickness,
|
||||
@Arg(desc = "The pattern of blocks to replace the hollowed area with", def = "air")
|
||||
Pattern pattern,
|
||||
@ArgFlag(name = "m", desc = "Mask to hollow with") Mask mask,
|
||||
@ArgFlag(name = 'm', desc = "Mask to hollow with") Mask mask,
|
||||
InjectedValueAccess context) throws WorldEditException {
|
||||
checkCommandArgument(thickness >= 0, "Thickness must be >= 0");
|
||||
Mask finalMask = mask == null ? new SolidBlockMask(editSession) : mask;
|
||||
|
Loading…
Reference in New Issue
Block a user