mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-06-11 20:13:55 +00:00
merge
This commit is contained in:
@ -135,7 +135,7 @@ public class Fawe {
|
||||
if (INSTANCE != null) {
|
||||
INSTANCE.IMP.debug(s);
|
||||
} else {
|
||||
System.out.println(BBC.stripColor(BBC.color(s)));
|
||||
System.out.println(s);
|
||||
}
|
||||
}
|
||||
|
||||
@ -147,10 +147,10 @@ public class Fawe {
|
||||
public static void debug(Object s) {
|
||||
Actor actor = Request.request().getActor();
|
||||
if (actor != null && actor.isPlayer()) {
|
||||
actor.print(BBC.color(BBC.PREFIX.original() + " " + s));
|
||||
actor.print((String)s);
|
||||
return;
|
||||
}
|
||||
debugPlain(BBC.PREFIX.original() + " " + s);
|
||||
debugPlain((String) s);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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,19 +269,13 @@ 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() {
|
||||
if (z > 0) {
|
||||
return states[getArr[index - 16]];
|
||||
}
|
||||
return getExtent().getBlock(getX(), getY(), getZ() - 1);
|
||||
return getExtent().getBlock(getX(), getY(), getZ() - 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -265,7 +283,7 @@ public class CharFilterBlock extends ChunkFilterBlock {
|
||||
if (x < 15) {
|
||||
return states[getArr[index + 1]];
|
||||
}
|
||||
return getExtent().getBlock(getX() + 1, getY(), getZ());
|
||||
return getExtent().getBlock(getX() + 1, getY(), getZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -273,7 +291,7 @@ public class CharFilterBlock extends ChunkFilterBlock {
|
||||
if (z < 15) {
|
||||
return states[getArr[index + 16]];
|
||||
}
|
||||
return getExtent().getBlock(getX(), getY(), getZ() + 1);
|
||||
return getExtent().getBlock(getX(), getY(), getZ() + 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -281,7 +299,7 @@ public class CharFilterBlock extends ChunkFilterBlock {
|
||||
if (x > 0) {
|
||||
return states[getArr[index - 1]];
|
||||
}
|
||||
return getExtent().getBlock(getX() - 1, getY(), getZ());
|
||||
return getExtent().getBlock(getX() - 1, getY(), getZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -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,14 +371,13 @@ 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);
|
||||
return states[get.sections[newLayer].get(get, newLayer, index)];
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
@ -650,6 +660,11 @@ public class DelegateFilterBlock extends FilterBlock {
|
||||
return parent.getBlock(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockType getBlockType(BlockVector3 position) {
|
||||
return parent.getBlockType(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBlock getFullBlock(BlockVector3 position) {
|
||||
return parent.getFullBlock(position);
|
||||
@ -666,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 {
|
||||
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;
|
||||
@ -68,7 +64,7 @@ public class Flood {
|
||||
long pair = MathMan.pairInt(chunkX, chunkZ);
|
||||
int layer = y >> 4;
|
||||
int[] section = getOrCreateQueue(pair, layer);
|
||||
int val = (x & 15) + ((z & 15) << 4) + ((y & 15) << 8) + (depth << 12);
|
||||
int val = (x & 15) + ((z & 15) << 4) + ((y & 15) << 8) + (depth << 12);
|
||||
push(section, val);
|
||||
}
|
||||
|
||||
@ -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,7 +4,8 @@ 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 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) {
|
||||
return getParent().getCachedChunk(X, 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,38 +39,42 @@ public interface IQueueExtent extends Flushable, Trimable, Extent {
|
||||
|
||||
/**
|
||||
* Get the {@link WorldChunkCache}
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
IChunkGet getCachedGet(int X, int Z, Supplier<IChunkGet> supplier);
|
||||
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
|
||||
*
|
||||
* @param x
|
||||
* @param z
|
||||
* @return IChunk
|
||||
*/
|
||||
IChunk getCachedChunk(int X, int Z);
|
||||
IChunk getCachedChunk(int x, int z);
|
||||
|
||||
/**
|
||||
* 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);
|
||||
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++;
|
||||
}
|
||||
|
||||
|
@ -1,19 +1,19 @@
|
||||
package com.boydti.fawe.beta.filters;
|
||||
|
||||
import com.boydti.fawe.beta.FilterBlock;
|
||||
import com.boydti.fawe.config.BBC;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.function.mask.ABlockMask;
|
||||
import com.sk89q.worldedit.util.Countable;
|
||||
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() {
|
||||
@ -36,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()]++;
|
||||
}
|
||||
|
||||
@ -57,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() {
|
||||
@ -94,14 +88,14 @@ public class DistrFilter extends ForkedFilter<DistrFilter> {
|
||||
return distribution;
|
||||
}
|
||||
|
||||
public void print(final Actor actor, final long size) {
|
||||
for (final Countable c : getDistribution()) {
|
||||
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",
|
||||
String.valueOf(c.getAmount()),
|
||||
c.getAmount() / (double) size * 100,
|
||||
name);
|
||||
actor.print(BBC.getPrefix() + str);
|
||||
String.valueOf(c.getAmount()),
|
||||
c.getAmount() / (double) size * 100,
|
||||
name);
|
||||
actor.print(str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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,56 +40,53 @@ 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 Filter newFilter = filter.fork();
|
||||
// Create a chunk that we will reuse/reset for each operation
|
||||
final IQueueExtent queue = wrapQueue(getQueue());
|
||||
synchronized (queue) {
|
||||
ChunkFilterBlock block = null;
|
||||
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());
|
||||
synchronized (queue) {
|
||||
ChunkFilterBlock block = null;
|
||||
|
||||
while (true) {
|
||||
// Get the next chunk posWeakChunk
|
||||
final int X, Z;
|
||||
synchronized (chunksIter) {
|
||||
if (!chunksIter.hasNext()) break;
|
||||
final BlockVector2 pos = chunksIter.next();
|
||||
X = pos.getX();
|
||||
Z = pos.getZ();
|
||||
}
|
||||
if (!newFilter.appliesChunk(X, Z)) {
|
||||
continue;
|
||||
}
|
||||
IChunk chunk = queue.getCachedChunk(X, Z);
|
||||
// Initialize
|
||||
chunk.init(queue, X, Z);
|
||||
|
||||
IChunk newChunk = newFilter.applyChunk(chunk, region);
|
||||
if (newChunk != null) {
|
||||
chunk = newChunk;
|
||||
if (block == null) block = queue.initFilterBlock();
|
||||
chunk.filterBlocks(newFilter, block, region);
|
||||
}
|
||||
queue.submit(chunk);
|
||||
while (true) {
|
||||
// Get the next chunk posWeakChunk
|
||||
final int X, Z;
|
||||
synchronized (chunksIter) {
|
||||
if (!chunksIter.hasNext()) {
|
||||
break;
|
||||
}
|
||||
queue.flush();
|
||||
final BlockVector2 pos = chunksIter.next();
|
||||
X = pos.getX();
|
||||
Z = pos.getZ();
|
||||
}
|
||||
if (!newFilter.appliesChunk(X, Z)) {
|
||||
continue;
|
||||
}
|
||||
IChunk chunk = queue.getCachedChunk(X, Z);
|
||||
// Initialize
|
||||
chunk.init(queue, X, Z);
|
||||
|
||||
IChunk newChunk = newFilter.applyChunk(chunk, region);
|
||||
if (newChunk != null) {
|
||||
chunk = newChunk;
|
||||
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,17 +100,18 @@ 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
|
||||
// Apply a filter over a region
|
||||
apply(region, searchMask
|
||||
.toFilter(new CountFilter())) // Adapt the mask to a filter which counts
|
||||
.getParent() // Get the counter of this mask
|
||||
.getTotal(); // Get the total from the counter
|
||||
}
|
||||
|
||||
@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);
|
||||
|
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit;
|
||||
|
||||
/**
|
||||
* Raised when a world is missing but is required.
|
||||
*/
|
||||
public class MissingWorldException extends WorldEditException {
|
||||
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.extension.platform;
|
||||
|
||||
import com.sk89q.worldedit.internal.cui.CUIEvent;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public abstract class AbstractNonPlayerActor implements Actor {
|
||||
|
||||
@Override
|
||||
public boolean canDestroyBedrock() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPlayer() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File openFileOpenDialog(String[] extensions) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File openFileSaveDialog(String[] extensions) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispatchCUIEvent(CUIEvent event) {
|
||||
}
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.extension.platform;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
|
||||
public interface Locatable {
|
||||
|
||||
/**
|
||||
* Get the location of this actor.
|
||||
*
|
||||
* @return the location of the actor
|
||||
*/
|
||||
Location getLocation();
|
||||
|
||||
/**
|
||||
* Get the location of this actor in block coordinates.
|
||||
*
|
||||
* @return the block location of the actor
|
||||
*/
|
||||
default Location getBlockLocation() {
|
||||
Location location = getLocation();
|
||||
return location.setPosition(location.toVector().floor());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the location of this actor.
|
||||
*
|
||||
* @param location the new location of the actor
|
||||
* @return if the teleport succeeded
|
||||
*/
|
||||
boolean setLocation(Location location);
|
||||
|
||||
/**
|
||||
* Sets the position of this actor.
|
||||
*
|
||||
* @param pos where to move them
|
||||
*/
|
||||
default void setPosition(Vector3 pos) {
|
||||
setLocation(new Location(getExtent(), pos));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the extent that this actor is in.
|
||||
*
|
||||
* @return the extent
|
||||
*/
|
||||
Extent getExtent();
|
||||
|
||||
}
|
Reference in New Issue
Block a user