wip on 1.14

This commit is contained in:
Jesse Boyd
2019-07-09 17:18:51 +10:00
229 changed files with 9489 additions and 3025 deletions

View File

@ -1,94 +0,0 @@
/*
* 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.blocks;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.jnbt.CompoundTag;
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 com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector3;
/**
* A implementation of a lazy block for {@link Extent#getLazyBlock(Vector)}
* that takes the block's ID and metadata, but will defer loading of NBT
* data until time of access.
*
* <p>NBT data is later loaded using a call to {@link Extent#getBlock(Vector)}
* with a stored {@link Extent} and location.</p>
*
* <p>All mutators on this object will throw an
* {@link UnsupportedOperationException}.</p>
*/
public class LazyBlock extends BaseBlock {
private final Extent extent;
private final BlockVector3 position;
private boolean loaded = false;
/**
* Create a new lazy block.
*
* @param type the block type
* @param extent the extent to later load the full block data from
* @param position the position to later load the full block data from
*/
public LazyBlock(BlockType type, Extent extent, BlockVector3 position) {
super(type);
checkNotNull(extent);
checkNotNull(position);
this.extent = extent;
this.position = position;
}
/**
* Create a new lazy block.
*
* @param state the block state
* @param extent the extent to later load the full block data from
* @param position the position to later load the full block data from
*/
public LazyBlock(BlockState state, Extent extent, BlockVector3 position) {
super(state);
checkNotNull(extent);
checkNotNull(position);
this.extent = extent;
this.position = position;
}
@Override
public CompoundTag getNbtData() {
if (!loaded) {
BaseBlock loadedBlock = extent.getFullBlock(position);
this.nbtData = loadedBlock.getNbtData();
loaded = true;
}
return super.getNbtData();
}
@Override
public void setNbtData(CompoundTag nbtData) {
throw new UnsupportedOperationException("This object is immutable");
}
}

View File

@ -1,5 +1,6 @@
package com.boydti.fawe;
import com.boydti.fawe.beta.implementation.QueueHandler;
import com.boydti.fawe.config.BBC;
import com.boydti.fawe.config.Commands;
import com.boydti.fawe.config.Settings;
@ -30,22 +31,22 @@ import static com.google.common.base.Preconditions.checkNotNull;
/**
* [ WorldEdit action]
* |
* |
* \|/
* [ EditSession ] - The change is processed (area restrictions, change limit, block type)
* |
* |
* \|/
* [Block change] - A block change from some location
* |
* |
* \|/
* [ Set Queue ] - The SetQueue manages the implementation specific queue
* |
* |
* \|/
* [ Fawe Queue] - A queue of chunks - check if the queue has the chunk for a change
* |
* |
* \|/
* [ Fawe Chunk Implementation ] - Otherwise create a new FaweChunk object which is a wrapper around the Chunk object
* |
* |
* \|/
* [ Execution ] - When done, the queue then sets the blocks for the chunk, performs lighting updates and sends the chunk packet to the clients
* <p>
@ -81,6 +82,8 @@ public class Fawe {
private DefaultTransformParser transformParser;
private ChatManager chatManager = new PlainChatManager();
private QueueHandler queueHandler;
/**
* Get the implementation specific class
*
@ -183,6 +186,17 @@ public class Fawe {
public void onDisable() {
}
public QueueHandler getQueueHandler() {
if (queueHandler == null) {
synchronized (this) {
if (queueHandler == null) {
queueHandler = IMP.getQueueHandler();
}
}
}
return queueHandler;
}
public ChatManager getChatManager() {
return chatManager;
}

View File

@ -8,6 +8,7 @@ import com.boydti.fawe.object.FawePlayer;
import com.boydti.fawe.object.FaweQueue;
import com.boydti.fawe.object.RegionWrapper;
import com.boydti.fawe.object.changeset.DiskStorageHistory;
import com.boydti.fawe.object.exception.FaweException;
import com.boydti.fawe.object.schematic.Schematic;
import com.boydti.fawe.regions.FaweMaskManager;
import com.boydti.fawe.util.EditSessionBuilder;
@ -262,7 +263,7 @@ public class FaweAPI {
*/
public static void cancelEdit(Extent extent, BBC reason) {
try {
WEManager.IMP.cancelEdit(extent, reason);
WEManager.IMP.cancelEdit(extent, new FaweException(reason));
} catch (WorldEditException ignore) {
}
}

View File

@ -1,14 +1,47 @@
package com.boydti.fawe;
import com.boydti.fawe.beta.Trimable;
import com.boydti.fawe.config.Settings;
import com.boydti.fawe.jnbt.anvil.BitArray4096;
import com.boydti.fawe.object.collection.IterableThreadLocal;
import com.boydti.fawe.util.MathMan;
import com.sk89q.jnbt.*;
import com.sk89q.worldedit.math.MutableBlockVector3;
import com.sk89q.worldedit.math.MutableVector3;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypes;
import java.lang.reflect.Field;
import java.util.*;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
public class FaweCache implements Trimable {
public static final char[] EMPTY_CHAR_4096 = new char[4096];
/*
Palette buffers / cache
*/
@Override
public boolean trim(boolean aggressive) {
BLOCK_TO_PALETTE.clean();
PALETTE_TO_BLOCK.clean();
BLOCK_STATES.clean();
SECTION_BLOCKS.clean();
PALETTE_CACHE.clean();
PALETTE_TO_BLOCK_CHAR.clean();
MUTABLE_VECTOR3.clean();
MUTABLE_BLOCKVECTOR3.clean();
return false;
}
public class FaweCache {
public static final IterableThreadLocal<int[]> BLOCK_TO_PALETTE = new IterableThreadLocal<int[]>() {
@Override
public int[] init() {
@ -21,7 +54,16 @@ public class FaweCache {
public static final IterableThreadLocal<int[]> PALETTE_TO_BLOCK = new IterableThreadLocal<int[]>() {
@Override
public int[] init() {
return new int[Character.MAX_VALUE];
return new int[Character.MAX_VALUE + 1];
}
};
public static final IterableThreadLocal<char[]> PALETTE_TO_BLOCK_CHAR = new IterableThreadLocal<char[]>() {
@Override
public char[] init() {
char[] result = new char[Character.MAX_VALUE + 1];
Arrays.fill(result, Character.MAX_VALUE);
return result;
}
};
@ -39,6 +81,141 @@ public class FaweCache {
}
};
/**
* Holds data for a palette used in a chunk section
*/
public static final class Palette {
public int paletteToBlockLength;
/**
* Reusable buffer array, MUST check paletteToBlockLength for actual length
*/
public int[] paletteToBlock;
public int blockstatesLength;
/**
* Reusable buffer array, MUST check blockstatesLength for actual length
*/
public long[] blockstates;
}
private static final IterableThreadLocal<Palette> PALETTE_CACHE = new IterableThreadLocal<Palette>() {
@Override
public Palette init() {
return new Palette();
}
};
/**
* Convert raw char array to palette
* @param layerOffset
* @param blocks
* @return palette
*/
public static Palette toPalette(int layerOffset, char[] blocks) {
return toPalette(layerOffset, null, blocks);
}
/**
* Convert raw int array to palette
* @param layerOffset
* @param blocks
* @return palette
*/
public static Palette toPalette(int layerOffset, int[] blocks) {
return toPalette(layerOffset, blocks, null);
}
private static Palette toPalette(int layerOffset, int[] blocksInts, char[] blocksChars) {
int[] blockToPalette = BLOCK_TO_PALETTE.get();
int[] paletteToBlock = PALETTE_TO_BLOCK.get();
long[] blockstates = BLOCK_STATES.get();
int[] blocksCopy = SECTION_BLOCKS.get();
int blockIndexStart = layerOffset << 12;
int blockIndexEnd = blockIndexStart + 4096;
int num_palette = 0;
try {
if (blocksChars != null) {
for (int i = blockIndexStart, j = 0; i < blockIndexEnd; i++, j++) {
int ordinal = blocksChars[i];
int palette = blockToPalette[ordinal];
if (palette == Integer.MAX_VALUE) {
// BlockState state = BlockTypes.states[ordinal];
blockToPalette[ordinal] = palette = num_palette;
paletteToBlock[num_palette] = ordinal;
num_palette++;
}
blocksCopy[j] = palette;
}
} else if (blocksInts != null) {
for (int i = blockIndexStart, j = 0; i < blockIndexEnd; i++, j++) {
int ordinal = blocksInts[i];
int palette = blockToPalette[ordinal];
if (palette == Integer.MAX_VALUE) {
BlockState state = BlockTypes.states[ordinal];
blockToPalette[ordinal] = palette = num_palette;
paletteToBlock[num_palette] = ordinal;
num_palette++;
}
blocksCopy[j] = palette;
}
} else {
throw new IllegalArgumentException();
}
for (int i = 0; i < num_palette; i++) {
blockToPalette[paletteToBlock[i]] = Integer.MAX_VALUE;
}
// BlockStates
int bitsPerEntry = MathMan.log2nlz(num_palette - 1);
int blockBitArrayEnd = (bitsPerEntry * 4096) >> 6;
if (num_palette == 1) {
// Set a value, because minecraft needs it for some reason
blockstates[0] = 0;
blockBitArrayEnd = 1;
} else {
BitArray4096 bitArray = new BitArray4096(blockstates, bitsPerEntry);
bitArray.fromRaw(blocksCopy);
}
// Construct palette
Palette palette = PALETTE_CACHE.get();
palette.paletteToBlockLength = num_palette;
palette.paletteToBlock = paletteToBlock;
palette.blockstatesLength = blockBitArrayEnd;
palette.blockstates = blockstates;
return palette;
} catch (Throwable e) {
Arrays.fill(blockToPalette, Integer.MAX_VALUE);
e.printStackTrace();
throw e;
}
}
/*
* Vector cache
*/
public static IterableThreadLocal<MutableBlockVector3> MUTABLE_BLOCKVECTOR3 = new IterableThreadLocal<MutableBlockVector3>() {
@Override
public MutableBlockVector3 init() {
return new MutableBlockVector3();
}
};
public static IterableThreadLocal<MutableVector3> MUTABLE_VECTOR3 = new IterableThreadLocal<MutableVector3>() {
@Override
public MutableVector3 init() {
return new MutableVector3();
}
};
/*
Conversion methods between JNBT tags and raw values
*/
public static Map<String, Object> asMap(Object... pairs) {
HashMap<String, Object> map = new HashMap<>(pairs.length >> 1);
for (int i = 0; i < pairs.length; i += 2) {
@ -179,4 +356,16 @@ public class FaweCache {
if (clazz == null) clazz = EndTag.class;
return new ListTag(clazz, list);
}
/*
Thread stuff
*/
public static ThreadPoolExecutor newBlockingExecutor() {
int nThreads = Settings.IMP.QUEUE.PARALLEL_THREADS;
ArrayBlockingQueue<Runnable> queue = new ArrayBlockingQueue<>(nThreads);
return new ThreadPoolExecutor(nThreads, nThreads,
0L, TimeUnit.MILLISECONDS, queue
, Executors.defaultThreadFactory(),
new ThreadPoolExecutor.CallerRunsPolicy());
}
}

View File

@ -1,5 +1,6 @@
package com.boydti.fawe;
import com.boydti.fawe.beta.implementation.QueueHandler;
import com.boydti.fawe.object.FaweCommand;
import com.boydti.fawe.object.FawePlayer;
import com.boydti.fawe.object.FaweQueue;
@ -57,4 +58,6 @@ public interface IFawe {
return "";
}
QueueHandler getQueueHandler();
}

View File

@ -0,0 +1,89 @@
package com.boydti.fawe.beta;
import com.sk89q.jnbt.CompoundTag;
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 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) {
super(extent);
this.blocks = blocks;
this.width = width;
this.length = length;
this.heights = heights;
this.yOffset = yOffset;
}
public void filter2D(Filter filter) {
for (z = 0; z < length; z++) {
for (x = 0; x < width; x++, index++) {
ordinal = blocks[ordinal];
filter.applyBlock(this);
}
}
}
@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 BlockState getBlock() {
return BlockTypes.states[ordinal];
}
@Override
public BaseBlock getFullBlock() {
return getBlock().toBaseBlock();
}
@Override
public CompoundTag getNbtData() {
return null;
}
@Override
public void setNbtData(@Nullable CompoundTag nbtData) {}
@Override
public int getX() {
return x;
}
@Override
public int getY() {
return (heights[index] & 0xFF) + yOffset;
}
@Override
public int getZ() {
return z;
}
}

View File

@ -0,0 +1,418 @@
package com.boydti.fawe.beta;
import com.boydti.fawe.beta.implementation.blocks.CharGetBlocks;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.registry.BlockMaterial;
import javax.annotation.Nullable;
import static com.sk89q.worldedit.world.block.BlockTypes.states;
public class CharFilterBlock extends ChunkFilterBlock {
private CharGetBlocks get;
private IChunkSet set;
private char[] getArr;
private @Nullable char[] setArr;
private SetDelegate delegate;
// local
private int layer, index, x, y, z, xx, yy, zz, X, Z;
public CharFilterBlock(IQueueExtent queueExtent) {
super(queueExtent);
}
@Override
public final ChunkFilterBlock init(final int X, final int Z, final IChunkGet chunk) {
this.get = (CharGetBlocks) chunk;
this.X = X;
this.Z = Z;
this.xx = X << 4;
this.zz = Z << 4;
return this;
}
public void flood(final IChunkGet iget, final IChunkSet iset, final 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;
if (mask.applyBlock(this)) {
int depth = index >> 12;
if (checkDepth && depth > maxDepth) {
continue;
}
flood.apply(x, y, z, depth);
}
}
}
}
@Override
public final ChunkFilterBlock init(final IChunkGet iget, final IChunkSet iset, final int layer) {
this.layer = layer;
final CharGetBlocks get = (CharGetBlocks) iget;
if (!get.hasSection(layer)) return null;
this.set = iset;
getArr = get.sections[layer].get(get, layer);
if (set.hasSection(layer)) {
setArr = set.getArray(layer);
delegate = FULL;
} else {
delegate = NULL;
setArr = null;
}
this.yy = layer << 4;
return this;
}
@Override
public void filter(Filter filter, int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
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 (z = 0; z < 16; z++) {
for (x = 0; x < 16; x++, index++) {
filter.applyBlock(this);
}
}
}
}
@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);
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++) {
filter.applyBlock(this);
}
}
}
}
@Override
public final void filter(final Filter filter, final Region region) {
for (y = 0, index = 0; y < 16; y++) {
int absY = yy + y;
for (z = 0; z < 16; z++) {
int absZ = zz + z;
for (x = 0; x < 16; x++, index++) {
int absX = xx + x;
if (region.contains(absX, absY, absZ)) {
filter.applyBlock(this);
}
}
}
}
}
@Override
public final void filter(final Filter filter) {
for (y = 0, index = 0; y < 16; y++) {
for (z = 0; z < 16; z++) {
for (x = 0; x < 16; x++, index++) {
filter.applyBlock(this);
}
}
}
}
@Override
public void setBiome(BiomeType biome) {
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;
}
@Override
public final int getY() {
return yy + y;
}
@Override
public final int getZ() {
return zz + z;
}
@Override
public final int getLocalX() {
return x;
}
@Override
public final int getLocalY() {
return y;
}
@Override
public final int getLocalZ() {
return z;
}
@Override
public final int getChunkX() {
return X;
}
@Override
public final int getChunkZ() {
return Z;
}
public final char getOrdinalChar() {
return getArr[index];
}
@Override
public final int getOrdinal() {
return getArr[index];
}
@Override
public final BlockState getBlock() {
final int ordinal = getArr[index];
return BlockTypes.states[ordinal];
}
@Override
public final BaseBlock getFullBlock() {
final BlockState state = getBlock();
final BlockMaterial material = state.getMaterial();
if (material.hasContainer()) {
final CompoundTag tag = get.getTag(x, y + yy, z);
return state.toBaseBlock(tag);
}
return state.toBaseBlock();
}
@Override
public final CompoundTag getNbtData() {
return get.getTag(x, y + (layer << 4), z);
}
@Override
public void setNbtData(CompoundTag tag) {
if (tag != null) {
set.setTile(x, y + yy, z, tag);
}
}
@Override
public boolean hasNbtData() {
final BlockState state = getBlock();
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);
}
@Override
public final BlockState getBlockEast() {
if (x < 15) {
return states[getArr[index + 1]];
}
return getExtent().getBlock(getX() + 1, getY(), getZ());
}
@Override
public final BlockState getBlockSouth() {
if (z < 15) {
return states[getArr[index + 16]];
}
return getExtent().getBlock(getX(), getY(), getZ() + 1);
}
@Override
public final BlockState getBlockWest() {
if (x > 0) {
return states[getArr[index - 1]];
}
return getExtent().getBlock(getX() - 1, getY(), getZ());
}
@Override
public final BlockState getBlockBelow() {
if (y > 0) {
return states[getArr[index - 256]];
}
if (layer > 0) {
final int newLayer = layer - 1;
final CharGetBlocks chunk = this.get;
return states[chunk.sections[newLayer].get(chunk, newLayer, index + 3840)];
}
return BlockTypes.__RESERVED__.getDefaultState();
}
@Override
public final BlockState getBlockAbove() {
if (y < 16) {
return states[getArr[index + 256]];
}
if (layer < 16) {
final int newLayer = layer + 1;
final CharGetBlocks chunk = this.get;
return states[chunk.sections[newLayer].get(chunk, newLayer, index - 3840)];
}
return BlockTypes.__RESERVED__.getDefaultState();
}
@Override
public final BlockState getBlockRelativeY(final int y) {
final int newY = this.y + y;
final int layerAdd = newY >> 4;
switch (layerAdd) {
case 0:
return states[getArr[this.index + (y << 8)]];
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
case 11:
case 12:
case 13:
case 14:
case 15: {
final int newLayer = layer + layerAdd;
if (newLayer < 16) {
final int index = this.index + ((y & 15) << 8);
return states[get.sections[newLayer].get(get, newLayer, index)];
}
break;
}
case -1:
case -2:
case -3:
case -4:
case -5:
case -6:
case -7:
case -8:
case -9:
case -10:
case -11:
case -12:
case -13:
case -14:
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();
}
/*
Extent
*/
@Override
public char getOrdinalChar(Extent orDefault) {
return getOrdinalChar();
}
/*
Set delegate
*/
private SetDelegate initSet() {
setArr = set.getArray(layer);
return delegate = FULL;
}
@Override
public BiomeType getBiomeType(int x, int z) {
if ((x >> 4) == X && (z >> 4) == Z) {
return get.getBiomeType(x & 15, z & 15);
}
return getExtent().getBiomeType(x, z);
}
@Override
public boolean setBiome(int x, int y, int z, BiomeType biome) {
if ((x >> 4) == X && (z >> 4) == Z) {
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;
}
};
}

View File

@ -0,0 +1,30 @@
package com.boydti.fawe.beta;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region;
import javax.annotation.Nullable;
public abstract class ChunkFilterBlock extends SimpleFilterBlock {
public ChunkFilterBlock(Extent extent) {
super(extent);
}
public abstract ChunkFilterBlock init(int X, int Z, IChunkGet chunk);
public abstract ChunkFilterBlock init(final IChunkGet iget, final IChunkSet iset, final int layer);
public abstract void flood(final IChunkGet iget, final IChunkSet iset, final 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);
public abstract void filter(Filter filter, int yStart, int yEnd);
public abstract void filter(final Filter filter, final Region region);
}

View File

@ -0,0 +1,60 @@
package com.boydti.fawe.beta;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
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) {
this.chunk = chunk;
}
public IChunk getChunk() {
return chunk;
}
@Override
public boolean cancel(final boolean mayInterruptIfRunning) {
cancelled = true;
if (done) return false;
return true;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public boolean isDone() {
return done;
}
@Override
public Void get() throws InterruptedException, ExecutionException {
synchronized (chunk) {
if (!done) {
this.wait();
}
}
return null;
}
@Override
public Void get(final long timeout, final TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
synchronized (chunk) {
if (!done) {
this.wait(unit.toMillis(timeout));
if (!done) {
throw new TimeoutException();
}
}
}
return null;
}
}

View File

@ -0,0 +1,13 @@
package com.boydti.fawe.beta;
public abstract class DelegateFilter implements IDelegateFilter {
private final Filter parent;
public DelegateFilter(Filter parent) {
this.parent = parent;
}
@Override
public Filter getParent() {
return parent;
}
}

View File

@ -0,0 +1,697 @@
package com.boydti.fawe.beta;
import com.boydti.fawe.jnbt.anvil.generator.GenBase;
import com.boydti.fawe.jnbt.anvil.generator.Resource;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.operation.Operation;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.MutableBlockVector3;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.session.ClipboardHolder;
import com.sk89q.worldedit.util.Countable;
import com.sk89q.worldedit.util.Location;
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 com.sk89q.worldedit.world.block.BlockType;
import javax.annotation.Nullable;
import java.util.Comparator;
import java.util.List;
public class DelegateFilterBlock extends FilterBlock {
private final FilterBlock parent;
public DelegateFilterBlock(FilterBlock parent) {
this.parent = parent;
}
@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();
}
@Override
public void setBiome(BiomeType biome) {
parent.setBiome(biome);
}
@Override
public int getOrdinal() {
return parent.getOrdinal();
}
@Override
public BlockState getBlock() {
return parent.getBlock();
}
@Override
public BaseBlock getFullBlock() {
return parent.getFullBlock();
}
@Override
public CompoundTag getNbtData() {
return parent.getNbtData();
}
@Override
public BlockVector3 getMinimumPoint() {
return parent.getMinimumPoint();
}
@Override
public BlockVector3 getMaximumPoint() {
return parent.getMaximumPoint();
}
@Override
public BlockState getBlock(int x, int y, int z) {
return parent.getBlock(x, y, z);
}
@Override
public BaseBlock getFullBlock(int x, int y, int z) {
return parent.getFullBlock(x, y, z);
}
@Override
public BlockState getBlockBelow() {
return parent.getBlockBelow();
}
@Override
public BlockState getBlockAbove() {
return parent.getBlockAbove();
}
@Override
public BlockState getBlockNorth() {
return parent.getBlockNorth();
}
@Override
public BlockState getBlockEast() {
return parent.getBlockEast();
}
@Override
public BlockState getBlockSouth() {
return parent.getBlockSouth();
}
@Override
public BlockState getBlockWest() {
return parent.getBlockWest();
}
@Override
public BlockState getBlockRelativeY(int y) {
return parent.getBlockRelativeY(y);
}
@Override
public int getX() {
return parent.getX();
}
@Override
public int getY() {
return parent.getY();
}
@Override
public int getZ() {
return parent.getZ();
}
@Override
public int getLocalX() {
return parent.getLocalX();
}
@Override
public int getLocalY() {
return parent.getLocalY();
}
@Override
public int getLocalZ() {
return parent.getLocalZ();
}
@Override
public int getChunkX() {
return parent.getChunkX();
}
@Override
public int getChunkZ() {
return parent.getChunkZ();
}
@Override
public boolean setOrdinal(Extent orDefault, int ordinal) {
return parent.setOrdinal(orDefault, ordinal);
}
@Override
public boolean setBlock(Extent orDefault, BlockState state) {
return parent.setBlock(orDefault, state);
}
@Override
public boolean setFullBlock(Extent orDefault, BaseBlock block) {
return parent.setFullBlock(orDefault, block);
}
@Override
public boolean setBiome(Extent orDefault, BiomeType biome) {
return parent.setBiome(orDefault, biome);
}
@Override
public int getOrdinal(Extent orDefault) {
return parent.getOrdinal(orDefault);
}
@Override
public BlockState getBlock(Extent orDefault) {
return parent.getBlock(orDefault);
}
@Override
public BaseBlock getFullBlock(Extent orDefault) {
return parent.getFullBlock(orDefault);
}
@Override
public CompoundTag getNbtData(Extent orDefault) {
return parent.getNbtData(orDefault);
}
@Override
public BlockState getOrdinalBelow(Extent orDefault) {
return parent.getOrdinalBelow(orDefault);
}
@Override
public BlockState getStateAbove(Extent orDefault) {
return parent.getStateAbove(orDefault);
}
@Override
public BlockState getStateRelativeY(Extent orDefault, int y) {
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);
}
@Override
public MutableBlockVector3 setComponents(int x, int y, int z) {
return parent.setComponents(x, y, z);
}
@Override
public MutableBlockVector3 mutX(double x) {
return parent.mutX(x);
}
@Override
public MutableBlockVector3 mutY(double y) {
return parent.mutY(y);
}
@Override
public MutableBlockVector3 mutZ(double z) {
return parent.mutZ(z);
}
@Override
public MutableBlockVector3 mutX(int x) {
return parent.mutX(x);
}
@Override
public MutableBlockVector3 mutY(int y) {
return parent.mutY(y);
}
@Override
public MutableBlockVector3 mutZ(int z) {
return parent.mutZ(z);
}
@Override
public BlockVector3 toImmutable() {
return parent.toImmutable();
}
// @Override
// public BlockVector3 north() {
// return parent.north();
// }
//
// @Override
// public BlockVector3 east() {
// return parent.east();
// }
//
// @Override
// public BlockVector3 south() {
// return parent.south();
// }
//
// @Override
// public BlockVector3 west() {
// return parent.west();
// }
@Override
public int getBlockX() {
return parent.getBlockX();
}
@Override
public BlockVector3 withX(int x) {
return parent.withX(x);
}
@Override
public int getBlockY() {
return parent.getBlockY();
}
@Override
public BlockVector3 withY(int y) {
return parent.withY(y);
}
@Override
public int getBlockZ() {
return parent.getBlockZ();
}
@Override
public BlockVector3 withZ(int z) {
return parent.withZ(z);
}
@Override
public BlockVector3 add(BlockVector3 other) {
return parent.add(other);
}
@Override
public BlockVector3 add(int x, int y, int z) {
return parent.add(x, y, z);
}
@Override
public BlockVector3 add(BlockVector3... others) {
return parent.add(others);
}
@Override
public BlockVector3 subtract(BlockVector3 other) {
return parent.subtract(other);
}
@Override
public BlockVector3 subtract(int x, int y, int z) {
return parent.subtract(x, y, z);
}
@Override
public BlockVector3 subtract(BlockVector3... others) {
return parent.subtract(others);
}
@Override
public BlockVector3 multiply(BlockVector3 other) {
return parent.multiply(other);
}
@Override
public BlockVector3 multiply(int x, int y, int z) {
return parent.multiply(x, y, z);
}
@Override
public BlockVector3 multiply(BlockVector3... others) {
return parent.multiply(others);
}
@Override
public BlockVector3 multiply(int n) {
return parent.multiply(n);
}
@Override
public BlockVector3 divide(BlockVector3 other) {
return parent.divide(other);
}
@Override
public BlockVector3 divide(int x, int y, int z) {
return parent.divide(x, y, z);
}
@Override
public BlockVector3 divide(int n) {
return parent.divide(n);
}
@Override
public double length() {
return parent.length();
}
@Override
public int lengthSq() {
return parent.lengthSq();
}
@Override
public double distance(BlockVector3 other) {
return parent.distance(other);
}
@Override
public int distanceSq(BlockVector3 other) {
return parent.distanceSq(other);
}
@Override
public BlockVector3 normalize() {
return parent.normalize();
}
@Override
public double dot(BlockVector3 other) {
return parent.dot(other);
}
@Override
public BlockVector3 cross(BlockVector3 other) {
return parent.cross(other);
}
@Override
public boolean containedWithin(BlockVector3 min, BlockVector3 max) {
return parent.containedWithin(min, max);
}
@Override
public BlockVector3 clampY(int min, int max) {
return parent.clampY(min, max);
}
@Override
public BlockVector3 floor() {
return parent.floor();
}
@Override
public BlockVector3 ceil() {
return parent.ceil();
}
@Override
public BlockVector3 round() {
return parent.round();
}
@Override
public BlockVector3 abs() {
return parent.abs();
}
@Override
public BlockVector3 transform2D(double angle, double aboutX, double aboutZ, double translateX, double translateZ) {
return parent.transform2D(angle, aboutX, aboutZ, translateX, translateZ);
}
@Override
public double toPitch() {
return parent.toPitch();
}
@Override
public double toYaw() {
return parent.toYaw();
}
@Override
public BlockVector3 getMinimum(BlockVector3 v2) {
return parent.getMinimum(v2);
}
@Override
public BlockVector3 getMaximum(BlockVector3 v2) {
return parent.getMaximum(v2);
}
@Override
public char getOrdinalChar(Extent orDefault) {
return parent.getOrdinalChar(orDefault);
}
@Override
public BlockVector2 toBlockVector2() {
return parent.toBlockVector2();
}
@Override
public Vector3 toVector3() {
return parent.toVector3();
}
@Override
public int hashCode() {
return parent.hashCode();
}
@Override
public String toString() {
return parent.toString();
}
@Override
public List<? extends Entity> getEntities(Region region) {
return parent.getEntities(region);
}
@Override
public List<? extends Entity> getEntities() {
return parent.getEntities();
}
@Override
@Nullable
public Entity createEntity(Location location, BaseEntity entity) {
return parent.createEntity(location, entity);
}
@Override
public int getHighestTerrainBlock(int x, int z, int minY, int maxY) {
return parent.getHighestTerrainBlock(x, z, minY, maxY);
}
@Override
public int getHighestTerrainBlock(int x, int z, int minY, int maxY, Mask filter) {
return parent.getHighestTerrainBlock(x, z, minY, maxY, filter);
}
@Override
public int getNearestSurfaceLayer(int x, int z, int y, int minY, int maxY) {
return parent.getNearestSurfaceLayer(x, z, y, minY, maxY);
}
@Override
public int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY, boolean ignoreAir) {
return parent.getNearestSurfaceTerrainBlock(x, z, y, minY, maxY, ignoreAir);
}
@Override
public int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY) {
return parent.getNearestSurfaceTerrainBlock(x, z, y, minY, maxY);
}
@Override
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);
}
@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);
}
@Override
public void addCaves(Region region) throws WorldEditException {
parent.addCaves(region);
}
@Override
public void generate(Region region, GenBase gen) throws WorldEditException {
parent.generate(region, gen);
}
@Override
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 {
parent.spawnResource(region, gen, rarity, frequency);
}
@Override
public boolean contains(BlockVector3 pt) {
return parent.contains(pt);
}
@Override
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);
}
@Override
public void addOres(Region region, Mask mask) throws WorldEditException {
parent.addOres(region, mask);
}
@Override
public List<Countable<BlockType>> getBlockDistribution(Region region) {
return parent.getBlockDistribution(region);
}
@Override
public List<Countable<BlockState>> getBlockDistributionWithData(Region region) {
return parent.getBlockDistributionWithData(region);
}
@Override
public BlockArrayClipboard lazyCopy(Region region) {
return parent.lazyCopy(region);
}
@Override
@Nullable
public Operation commit() {
return parent.commit();
}
@Override
public int getMaxY() {
return parent.getMaxY();
}
@Override
public BlockState getBlock(BlockVector3 position) {
return parent.getBlock(position);
}
@Override
public BlockType getBlockType(BlockVector3 position) {
return parent.getBlockType(position);
}
@Override
public BaseBlock getFullBlock(BlockVector3 position) {
return parent.getFullBlock(position);
}
@Override
public BiomeType getBiome(BlockVector2 position) {
return parent.getBiome(position);
}
@Override
public BiomeType getBiomeType(int x, int z) {
return parent.getBiomeType(x, z);
}
@Override
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 {
return parent.setBlock(x, y, z, block);
}
@Override
public boolean setBiome(BlockVector2 position, BiomeType biome) {
return parent.setBiome(position, biome);
}
@Override
public boolean setBiome(int x, int y, int z, BiomeType biome) {
return parent.setBiome(x, y, z, biome);
}
@Override
public String getNbtId() {
return parent.getNbtId();
}
}

View File

@ -0,0 +1,5 @@
package com.boydti.fawe.beta;
public interface DirectionMask {
boolean apply(int fromX, int fromY, int fromZ, int toX, int toY, int toZ);
}

View File

@ -0,0 +1,70 @@
package com.boydti.fawe.beta;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.world.block.BaseBlock;
import javax.annotation.Nullable;
/**
* A filter is an interface used for setting blocks
*/
public interface Filter {
/**
* Check whether a chunk should be read
*
* @param cx
* @param cz
* @return
*/
default boolean appliesChunk(final int cx, final int cz) {
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>
*
* @param chunk
* @return
*/
default IChunk applyChunk(final IChunk chunk, @Nullable Region region) {
return chunk;
}
default boolean appliesLayer(IChunk chunk, int layer) {
return true;
}
/**
* 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) {
}
/**
* Do something with the IChunk after block filtering<br>
*
* @param chunk
* @return
*/
default void finishChunk(final 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
* @return this
*/
default Filter fork() {
return this;
}
default void join() {
}
}

View File

@ -0,0 +1,169 @@
package com.boydti.fawe.beta;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.blocks.TileEntityBlock;
import com.sk89q.worldedit.extent.Extent;
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 BlockState getBlock();
public abstract BaseBlock getFullBlock();
public abstract CompoundTag getNbtData();
public abstract void setNbtData(@Nullable CompoundTag nbtData);
public boolean hasNbtData() {
return getNbtData() != null;
}
@Override
public BlockVector3 getMinimumPoint() {
return getExtent().getMinimumPoint();
}
@Override
public BlockVector3 getMaximumPoint() {
return getExtent().getMaximumPoint();
}
@Override
public BlockState getBlock(int x, int y, int z) {
return getExtent().getBlock(x, y, z);
}
@Override
public BaseBlock getFullBlock(int x, int y, int z) {
return getExtent().getFullBlock(x, y, z);
}
public BlockState getBlockBelow() {
return getBlock(getX(), getY() - 1, getZ());
}
public BlockState getBlockAbove() {
return getBlock(getX(), getY() + 1, getZ());
}
public BlockState getBlockNorth() {
return getBlock(getX(), getY(), getZ() - 1);
}
public BlockState getBlockEast() {
return getBlock(getX() + 1, getY(), getZ());
}
public BlockState getBlockSouth() {
return getBlock(getX(), getY(), getZ() + 1);
}
public BlockState getBlockWest() {
return getBlock(getX() - 1, getY(), getZ());
}
public BlockState getBlockRelativeY(final int y) {
return getBlock(getX(), getY() + y , getZ());
}
@Override
public abstract int getX();
@Override
public abstract int getY();
@Override
public abstract int getZ();
public int getLocalX() {
return getX() & 15;
}
public int getLocalY() {
return getY() & 15;
}
public int getLocalZ() {
return getZ() & 15;
}
public int getChunkX() {
return getX() >> 4;
}
public int getChunkZ() {
return getZ() >> 4;
}
/*
Extent
*/
public boolean setOrdinal(Extent orDefault, int ordinal) {
setOrdinal(ordinal);
return true;
}
public boolean setBlock(Extent orDefault, BlockState state) {
setBlock(state);
return true;
}
public boolean setFullBlock(Extent orDefault, BaseBlock block) {
setFullBlock(block);
return true;
}
public boolean setBiome(Extent orDefault, BiomeType biome) {
setBiome(biome);
return true;
}
public int getOrdinal(Extent orDefault) {
return getOrdinal();
}
public BlockState getBlock(Extent orDefault) {
return getBlock();
}
public BaseBlock getFullBlock(Extent orDefault) {
return getFullBlock();
}
public CompoundTag getNbtData(Extent orDefault) {
return getNbtData();
}
public BlockState getOrdinalBelow(Extent orDefault) {
return getBlockBelow();
}
public BlockState getStateAbove(Extent orDefault) {
return getBlockAbove();
}
public BlockState getStateRelativeY(Extent orDefault, final int y) {
return getBlockRelativeY(y);
}
}

View File

@ -0,0 +1,5 @@
package com.boydti.fawe.beta;
public interface FilterBlockMask {
boolean applyBlock(final FilterBlock block);
}

View File

@ -0,0 +1,193 @@
package com.boydti.fawe.beta;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.beta.implementation.QueueHandler;
import com.boydti.fawe.beta.implementation.WorldChunkCache;
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 it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
public class Flood {
private final int maxBranch;
private final int maxDepth;
private final Direction[] directions;
private int[] queue;
private long[] visit;
private int[][] queues;
private long[][] visits;
private int X, Y, Z;
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;
this.maxDepth = maxDepth;
this.directions = directions;
this.queues = new int[27][];
this.visits = new long[27][];
this.chunkVisits = new Long2ObjectLinkedOpenHashMap<>();
this.chunkQueues = new Long2ObjectLinkedOpenHashMap<>();
}
public synchronized void run(World world) {
QueueHandler queueHandler = Fawe.get().getQueueHandler();
IQueueExtent fq = queueHandler.getQueue(world);
while (!chunkQueues.isEmpty()) {
long firstKey = chunkQueues.firstLongKey();
int X = MathMan.unpairIntX(firstKey);
int Z = MathMan.unpairIntY(firstKey);
int[][] chunkQueue = chunkQueues.get(firstKey);
// apply
TODO
}
}
private void init(int X, int Y, int Z) {
this.X = X;
this.Y = Y;
this.Z = Z;
}
public void start(int x, int y, int z) {
push(x, y, z, 0);
}
private void push(int x, int y, int z, int depth) {
int X = x >> 4;
int Z = z >> 4;
long pair = MathMan.pairInt(X, Z);
int layer = y >> 4;
int[] section = getOrCreateQueue(pair, layer);
int val = (x & 15) + ((z & 15) << 4) + ((y & 15) << 8) + (depth << 12);
push(section, val);
}
private int[] getOrCreateQueue(long pair, int layer) {
int[][] arrs = chunkQueues.get(pair);
if (arrs == null) {
chunkQueues.put(pair, arrs = new int[16][]);
}
int[] section = arrs[layer];
if (section == null) {
arrs[layer] = section = newQueue();
}
return section;
}
private int[] newQueue() {
int[] arr = queuePool.poll();
if (arr != null) {
arr[0] = 2;
arr[1] = 2;
return arr;
}
return new int[4096];
}
public int poll() {
int index = queue[0];
if (index == queue[1]) {
return -1;
}
queue[0] = index + 1;
return queue[index];
}
private void push(int[] queue, int val) {
int indexStart = queue[0];
int indexEnd = queue[1];
push(indexStart, indexEnd, queue, val);
}
private void push(int indexStart, int indexEnd, int[] queue, int val) {
if (indexStart > 2) {
queue[0] = --indexStart;
queue[indexStart] = val;
} else {
queue[indexEnd] = val;
queue[0] = ++indexEnd;
}
}
public Direction[] getDirections() {
return directions;
}
public int getMaxBranch() {
return maxBranch;
}
public int getMaxDepth() {
return maxDepth;
}
public void apply(int x, int y, int z, int depth) {
for (int i = 0, j = 0; i < directions.length && j < maxBranch; i++) {
final Direction dir = directions[i];
final int ty = y + dir.getBlockY();
final int tx = x + dir.getBlockX();
final int tz = z + dir.getBlockZ();
int index;
long[] visit;
int[] queue;
final int or = tx | ty | tz;
if (or > 15 || or < 0) {
visit = this.visit;
queue = this.queue;
index = tx + (tz << 4) + (ty << 8);
} else {
int nextX = tx >> 4;
int nextY = ty >> 4;
int nextZ = tz >> 4;
int sectionIndex = nextX + nextZ * 3 + nextZ * 9 + 13;
visit = visits[sectionIndex];
queue = queues[sectionIndex];
if (visit == null || queue == null) {
long pair = MathMan.pairInt(X + nextX, Z + nextZ);
int layer = Y + nextY;
if (layer < 0 || layer > 15) {
continue;
}
queues[sectionIndex] = queue = getOrCreateQueue(pair, layer);
}
index = (tx & 15) + ((tz & 15) << 4) + ((ty & 15) << 8);
}
if (!getAndSet(visit, index)) {
j++;
push(queue, index + (depth << 12));
}
}
}
public void set(long[] bits, int i) {
bits[i >> 6] |= (1L << (i & 0x3F));
}
public final boolean getAndSet(long[] bits, int i) {
int index = i >> 6;
long offset = (1L << (i & 0x3F));
long val = bits[index];
if ((val & offset) != 0) {
return true;
} else {
bits[index] |= offset;
return false;
}
}
public boolean get(long[] bits, final int i) {
return (bits[i >> 6] & (1L << (i & 0x3F))) != 0;
}
}

View File

@ -0,0 +1,10 @@
package com.boydti.fawe.beta;
/**
* Shared interface for IGetBlocks and ISetBlocks
*/
public interface IBlocks extends Trimable {
boolean hasSection(int layer);
IChunkSet reset();
}

View File

@ -0,0 +1,89 @@
package com.boydti.fawe.beta;
import com.sk89q.worldedit.math.MutableBlockVector3;
import com.sk89q.worldedit.regions.Region;
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.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
/**
* 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> {
/**
* Initialize at the location
* @param extent
* @param X
* @param Z
*/
void init(IQueueExtent extent, int X, int Z);
int getX();
int getZ();
/**
* If the chunk is a delegate, returns it's paren'ts root
* @return root IChunk
*/
default IChunk getRoot() {
return this;
}
/**
* @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
* @return Futures
*/
T call();
/**
* Call and join
* @throws ExecutionException
* @throws InterruptedException
*/
default void join() throws ExecutionException, InterruptedException {
T future = call();
while (future != null) {
future = future.get();
}
return;
}
/**
* 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);
void flood(Flood flood, FilterBlockMask mask, ChunkFilterBlock block);
/* set - queues a change */
boolean setBiome(int x, int y, int z, BiomeType biome);
boolean setBlock(int x, int y, int z, BlockStateHolder block);
/* get - from the world */
BiomeType getBiome(int x, int z);
BlockState getBlock(int x, int y, int z);
BaseBlock getFullBlock(int x, int y, int z);
}

View File

@ -0,0 +1,30 @@
package com.boydti.fawe.beta;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.extent.InputExtent;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
/**
* Interface for getting blocks
*/
public interface IChunkGet extends IBlocks, Trimable, InputExtent {
@Override
BaseBlock getFullBlock(int x, int y, int z);
@Override
BiomeType getBiomeType(int x, int z);
@Override
BlockState getBlock(int x, int y, int z);
CompoundTag getTag(int x, int y, int z);
@Override
boolean trim(boolean aggressive);
default void optimize() {
}
}

View File

@ -0,0 +1,51 @@
package com.boydti.fawe.beta;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.extent.OutputExtent;
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;
/**
* Interface for setting blocks
*/
public interface IChunkSet extends IBlocks, OutputExtent {
boolean setBiome(int x, int y, int z, BiomeType biome);
boolean setBlock(int x, int y, int z, BlockStateHolder holder);
boolean isEmpty();
void setTile(int x, int y, int z, CompoundTag tile);
void setEntity(CompoundTag tag);
void removeEntity(UUID uuid);
BlockState getBlock(int x, int y, int z);
char[] getArray(int layer);
BiomeType[] getBiomes();
Map<Short, CompoundTag> getTiles();
Set<CompoundTag> getEntities();
Set<UUID> getEntityRemoves();
@Override
IChunkSet reset();
@Nullable
@Override
default Operation commit() {
return null;
}
}

View File

@ -0,0 +1,109 @@
package com.boydti.fawe.beta;
import com.sk89q.worldedit.math.MutableBlockVector3;
import com.sk89q.worldedit.regions.Region;
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;
/**
* Delegate for IChunk
* @param <U> parent class
*/
public interface IDelegateChunk<U extends IChunk> extends IChunk {
U getParent();
default IChunk getRoot() {
IChunk root = getParent();
while (root instanceof IDelegateChunk) {
root = ((IDelegateChunk) root).getParent();
}
return root;
}
@Override
default void flood(Flood flood, FilterBlockMask mask, ChunkFilterBlock block) {
getParent().flood(flood, mask, block);
}
@Override
default boolean setBiome(final int x, final int y, final int z, final 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) {
return getParent().setBlock(x, y, z, holder);
}
@Override
default BiomeType getBiome(final int x, final int z) {
return getParent().getBiome(x, z);
}
@Override
default BlockState getBlock(final int x, final int y, final int z) {
return getParent().getBlock(x, y, z);
}
@Override
default BaseBlock getFullBlock(final int x, final int y, final int z) {
return getParent().getFullBlock(x, y, z);
}
@Override
default void init(final IQueueExtent extent, final int X, final int Z) {
getParent().init(extent, X, Z);
}
@Override
default int getX() {
return getParent().getX();
}
@Override
default int getZ() {
return getParent().getZ();
}
@Override
default boolean trim(final boolean aggressive) {
return getParent().trim(aggressive);
}
@Override
default Future call() {
return getParent().call();
}
@Override
default void join() throws ExecutionException, InterruptedException {
getParent().join();
}
@Override
default void filterBlocks(Filter filter, ChunkFilterBlock block, @Nullable Region region) {
getParent().filterBlocks(filter, block, region);
}
@Override
default boolean isEmpty() {
return getParent().isEmpty();
}
default <T extends IChunk> T findParent(final Class<T> clazz) {
IChunk root = getParent();
if (clazz.isAssignableFrom(root.getClass())) return (T) root;
while (root instanceof IDelegateChunk) {
root = ((IDelegateChunk) root).getParent();
if (clazz.isAssignableFrom(root.getClass())) return (T) root;
}
return null;
}
}

View File

@ -0,0 +1,50 @@
package com.boydti.fawe.beta;
import com.sk89q.worldedit.regions.Region;
import javax.annotation.Nullable;
public interface IDelegateFilter extends Filter {
Filter getParent();
@Override
default boolean appliesChunk(int cx, int cz) {
return getParent().appliesChunk(cx, cz);
}
@Override
default IChunk applyChunk(IChunk chunk, @Nullable Region region) {
return getParent().applyChunk(chunk, region);
}
@Override
default boolean appliesLayer(IChunk chunk, int layer) {
return getParent().appliesLayer(chunk, layer);
}
@Override
default void applyBlock(FilterBlock block) {
getParent().applyBlock(block);
}
@Override
default void finishChunk(IChunk chunk) {
getParent().finishChunk(chunk);
}
@Override
default void join() {
getParent().join();
}
@Override
default Filter fork() {
Filter fork = getParent().fork();
if (fork != getParent()) {
return newInstance(fork);
}
return this;
}
Filter newInstance(Filter other);
}

View File

@ -0,0 +1,47 @@
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) {
getParent().init(cache);
}
@Override
default IChunk getCachedChunk(final int X, final int Z) {
return getParent().getCachedChunk(X, Z);
}
@Override
default Future<?> submit(final IChunk chunk) {
return getParent().submit(chunk);
}
@Override
default IChunk create(final boolean full) {
return getParent().create(full);
}
@Override
default IChunk wrap(final IChunk root) {
return getParent().wrap(root);
}
@Override
default void flush() {
getParent().flush();
}
@Override
default boolean trim(final boolean aggressive) {
return getParent().trim(aggressive);
}
}

View File

@ -0,0 +1,103 @@
package com.boydti.fawe.beta;
import com.boydti.fawe.beta.implementation.WorldChunkCache;
import com.sk89q.worldedit.extent.Extent;
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 com.sk89q.worldedit.world.block.BlockStateHolder;
import java.io.Flushable;
import java.util.concurrent.Future;
/**
* TODO: implement Extent (need to refactor Extent first)
* Interface for a queue based extent which uses chunks
*/
public interface IQueueExtent extends Flushable, Trimable, Extent {
void init(WorldChunkCache world);
/**
* Get the {@link WorldChunkCache}
* @return
*/
WorldChunkCache getCache();
/**
* Get the IChunk at a position (and cache it if it's not already)
* @param X
* @param Z
* @return IChunk
*/
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);
default boolean setBlock(final int x, final int y, final int z, final BlockStateHolder state) {
final IChunk chunk = getCachedChunk(x >> 4, z >> 4);
return chunk.setBlock(x & 15, y, z & 15, state);
}
default boolean setBiome(final int x, final int y, final int z, final 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) {
final IChunk chunk = getCachedChunk(x >> 4, z >> 4);
return chunk.getBlock(x & 15, y, z & 15);
}
@Override
default BaseBlock getFullBlock(int x, int y, int z) {
final IChunk chunk = getCachedChunk(x >> 4, z >> 4);
return chunk.getFullBlock(x & 15, y, z & 15);
}
default BiomeType getBiome(final int x, final int z) {
final IChunk chunk = getCachedChunk(x >> 4, z >> 4);
return chunk.getBiome(x & 15, z & 15);
}
@Override
default BlockVector3 getMinimumPoint() {
return getCache().getWorld().getMinimumPoint();
}
@Override
default BlockVector3 getMaximumPoint() {
return getCache().getWorld().getMaximumPoint();
}
/**
* 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
* @return
*/
IChunk create(boolean full);
/**
* Wrap the chunk object (i.e. for region restrictions / limits etc.)
* @param root
* @return wrapped chunk
*/
default IChunk wrap(final IChunk root) {
return root;
}
/**
* Flush all changes to the world
* - Best to call this async so it doesn't hang the server
*/
@Override
void flush();
ChunkFilterBlock initFilterBlock();
}

View File

@ -0,0 +1,92 @@
package com.boydti.fawe.beta;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.extent.Extent;
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;
public class NorthVector extends BlockVector3 {
private final BlockVector3 parent;
public NorthVector(BlockVector3 parent) {
this.parent = parent;
}
// @Override
// public BlockVector3 south(BlockVector3 orDefault) {
// return parent;
// }
@Override
public int getX() {
return parent.getX();
}
@Override
public int getY() {
return parent.getY();
}
@Override
public int getZ() {
return parent.getZ();
}
public boolean setOrdinal(Extent orDefault, int ordinal) {
return orDefault.setBlock(this, BlockState.getFromOrdinal(ordinal));
}
public boolean setBlock(Extent orDefault, BlockState state) {
return orDefault.setBlock(this, state);
}
public boolean setFullBlock(Extent orDefault, BaseBlock block) {
return orDefault.setBlock(this, block);
}
public boolean setBiome(Extent orDefault, BiomeType biome) {
return orDefault.setBiome(getX(), getY(), getZ(), biome);
}
public int getOrdinal(Extent orDefault) {
return getBlock(orDefault).getOrdinal();
}
public char getOrdinalChar(Extent orDefault) {
return (char) getOrdinal(orDefault);
}
public BlockState getBlock(Extent orDefault) {
return orDefault.getBlock(this);
}
public BaseBlock getFullBlock(Extent orDefault) {
return orDefault.getFullBlock(this);
}
public CompoundTag getNbtData(Extent orDefault) {
return orDefault.getFullBlock(getX(), getY(), getZ()).getNbtData();
}
public BlockState getOrdinalBelow(Extent orDefault) {
return getStateRelative(orDefault, 0, -1, 0);
}
public BlockState getStateAbove(Extent orDefault) {
return getStateRelative(orDefault, 0, 1, 0);
}
public BlockState getStateRelativeY(Extent orDefault, final int y) {
return getStateRelative(orDefault, 0, y, 0);
}
public BlockState getStateRelative(Extent orDefault, final int x, final int y, final int z) {
return getFullBlockRelative(orDefault, x, y, z).toBlockState();
}
public BaseBlock getFullBlockRelative(Extent orDefault, int x, int y, int z) {
return orDefault.getFullBlock(x + getX(), y + getY(), z + getZ());
}
}

View File

@ -0,0 +1,16 @@
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) {
this.extent = extent;
}
@Override
public final Extent getExtent() {
return extent;
}
}

View File

@ -0,0 +1,98 @@
package com.boydti.fawe.beta;
import com.sk89q.jnbt.CompoundTag;
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 {
private BaseBlock block;
private int x, y, z;
public SingleFilterBlock init(int x, int y, int z, BaseBlock block) {
this.x = x;
this.y = y;
this.z = z;
this.block = block;
return this;
}
@Override
public Extent getExtent() {
return this;
}
@Override
public void setOrdinal(int ordinal) {
setBlock(BlockState.getFromOrdinal(ordinal));
}
@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();
}
// @Override
// public BaseBlock getFullBlockRelative(int x, int y, int z) {
// return block;
// }
@Override
public BlockState getBlock() {
return block.toBlockState();
}
@Override
public BaseBlock getFullBlock() {
return block;
}
@Override
public CompoundTag getNbtData() {
return block.getNbtData();
}
@Override
public int getX() {
return x;
}
@Override
public int getY() {
return y;
}
@Override
public int getZ() {
return z;
}
@Override
public BlockVector3 getMinimumPoint() {
return BlockVector3.at(x, y, z);
}
@Override
public BlockVector3 getMaximumPoint() {
return BlockVector3.at(x, y, z);
}
}

View File

@ -0,0 +1,14 @@
package com.boydti.fawe.beta;
/**
* 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
* @return if this object is empty at the end of the trim, and can therefore be deleted
*/
boolean trim(boolean aggressive);
}

View File

@ -0,0 +1,26 @@
package com.boydti.fawe.beta.filters;
import com.boydti.fawe.beta.DelegateFilter;
import com.boydti.fawe.beta.Filter;
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 r;
private final boolean white;
private final BufferedImage img;
public ArrayImageMask(BufferedImage img, boolean white) {
this.img = img;
this.white = white;
this.r = ThreadLocalRandom.current();
}
@Override
public boolean applyBlock(FilterBlock block) {
int height = img.getRGB(block.getX(), block.getZ()) & 0xFF;
return ((height == 255 || height > 0 && !white && r.nextInt(256) <= height));
}
}

View File

@ -0,0 +1,68 @@
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.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;
public class CountFilter extends ForkedFilter<CountFilter> {
private final int[] counter = new int[BlockTypes.states.length];
public CountFilter() {
super(null);
}
private CountFilter(CountFilter root) {
super(root);
}
@Override
public CountFilter init() {
return new CountFilter(this);
}
@Override
public void join(CountFilter filter) {
for (int i = 0; i < filter.counter.length; i++) {
this.counter[i] += filter.counter[i];
}
}
/*
Implementation
*/
@Override
public final void applyBlock(final FilterBlock block) {
counter[block.getOrdinal()]++;
}
public List<Countable<BlockState>> getDistribution() {
final List<Countable<BlockState>> distribution = new ArrayList<>();
for (int i = 0; i < counter.length; i++) {
final int count = counter[i];
if (count != 0) {
distribution.add(new Countable<>(BlockTypes.states[i], count));
}
}
Collections.sort(distribution);
return distribution;
}
public void print(final Actor actor, final long size) {
for (final 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);
}
}
}

View File

@ -0,0 +1,48 @@
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) {
if (root != null) {
children = root.children;
} else {
children = new ConcurrentHashMap<>();
children.put(Thread.currentThread(), (T) this);
}
}
@Override
public final Filter fork() {
return children.computeIfAbsent(Thread.currentThread(), thread -> init());
}
public abstract T init();
@Override
public void join() {
for (Map.Entry<Thread, T> entry : children.entrySet()) {
T filter = entry.getValue();
if (filter != this) {
join(filter);
}
}
children.clear();
}
public abstract void join(T filter);
}

View File

@ -0,0 +1,18 @@
package com.boydti.fawe.beta.filters;
import com.boydti.fawe.beta.Filter;
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) {
this.state = state;
}
@Override
public void applyBlock(final FilterBlock block) {
block.setBlock(state);
}
}

View File

@ -0,0 +1,113 @@
package com.boydti.fawe.beta.implementation;
import com.boydti.fawe.beta.IChunkSet;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.function.operation.Operation;
import com.sk89q.worldedit.math.BlockVector2;
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;
public interface DelegateChunkSet extends IChunkSet {
IChunkSet getParent();
@Override
default boolean setBiome(int x, int y, int z, BiomeType biome) {
return getParent().setBiome(x, y, z, biome);
}
@Override
default boolean setBlock(int x, int y, int z, BlockStateHolder holder) {
return getParent().setBlock(x, y, z, holder);
}
@Override
default boolean isEmpty() {
return getParent().isEmpty();
}
@Override
default void setTile(int x, int y, int z, CompoundTag tile) {
getParent().setTile(x, y, z, tile);
}
@Override
default void setEntity(CompoundTag tag) {
getParent().setEntity(tag);
}
@Override
default void removeEntity(UUID uuid) {
getParent().removeEntity(uuid);
}
@Override
default BlockState getBlock(int x, int y, int z) {
return getParent().getBlock(x, y, z);
}
@Override
default char[] getArray(int layer) {
return getParent().getArray(layer);
}
@Override
default BiomeType[] getBiomes() {
return getParent().getBiomes();
}
@Override
default Map<Short, CompoundTag> getTiles() {
return getParent().getTiles();
}
@Override
default Set<CompoundTag> getEntities() {
return getParent().getEntities();
}
@Override
default Set<UUID> getEntityRemoves() {
return getParent().getEntityRemoves();
}
@Override
default IChunkSet reset() {
IChunkSet parent = getParent();
parent.reset();
return parent;
}
@Override
@Nullable
default Operation commit() {
return getParent().commit();
}
@Override
default boolean hasSection(int layer) {
return getParent().hasSection(layer);
}
@Override
default boolean trim(boolean aggressive) {
return getParent().trim(aggressive);
}
@Override
default <T extends BlockStateHolder<T>> boolean setBlock(BlockVector3 position, T block) throws WorldEditException {
return getParent().setBlock(position, block);
}
@Override
default boolean setBiome(BlockVector2 position, BiomeType biome) {
return getParent().setBiome(position, biome);
}
}

View File

@ -0,0 +1,203 @@
package com.boydti.fawe.beta.implementation;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.FaweCache;
import com.boydti.fawe.beta.ChunkFilterBlock;
import com.boydti.fawe.beta.Filter;
import com.boydti.fawe.beta.IChunk;
import com.boydti.fawe.beta.IQueueExtent;
import com.boydti.fawe.beta.Trimable;
import com.boydti.fawe.config.Settings;
import com.boydti.fawe.object.collection.IterableThreadLocal;
import com.boydti.fawe.util.MemUtil;
import com.boydti.fawe.util.TaskManager;
import com.boydti.fawe.wrappers.WorldWrapper;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.MutableBlockVector3;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.world.World;
import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinTask;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;
import java.util.concurrent.ThreadPoolExecutor;
/**
* 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();
private ConcurrentLinkedQueue<FutureTask> syncTasks = new ConcurrentLinkedQueue();
private Map<World, WeakReference<WorldChunkCache>> chunkCache = new HashMap<>();
private IterableThreadLocal<IQueueExtent> queuePool = new IterableThreadLocal<IQueueExtent>() {
@Override
public IQueueExtent init() {
return create();
}
};
public QueueHandler() {
TaskManager.IMP.repeat(this, 1);
}
@Override
public void run() {
if (!Fawe.isMainThread()) {
throw new IllegalStateException("Not main thread");
}
while (!syncTasks.isEmpty()) {
final FutureTask task = syncTasks.poll();
if (task != null) task.run();
}
}
public <T> Future<T> async(final Runnable run, final T value) {
return forkJoinPoolSecondary.submit(run, value);
}
public <T> Future<T> async(final Callable<T> call) {
return forkJoinPoolSecondary.submit(call);
}
public <T> Future<T> sync(final Runnable run, final T value) {
final FutureTask<T> result = new FutureTask<>(run, value);
syncTasks.add(result);
return result;
}
public <T> Future<T> sync(final Runnable run) {
final FutureTask<T> result = new FutureTask<>(run, null);
syncTasks.add(result);
return result;
}
public <T> Future<T> sync(final Callable<T> call) {
final FutureTask<T> result = new FutureTask<>(call);
syncTasks.add(result);
return result;
}
public <T extends Future<T>> T submit(final IChunk<T> chunk) {
if (MemUtil.isMemoryFree()) {
// return (T) forkJoinPoolSecondary.submit(chunk);
}
return (T) blockingExecutor.submit(chunk);
}
/**
* Get or create the WorldChunkCache for a world
* @param world
* @return
*/
public WorldChunkCache getOrCreate(World world) {
world = WorldWrapper.unwrap(world);
synchronized (chunkCache) {
final WeakReference<WorldChunkCache> ref = chunkCache.get(world);
if (ref != null) {
final WorldChunkCache cached = ref.get();
if (cached != null) {
return cached;
}
}
final WorldChunkCache created = new WorldChunkCache(world);
chunkCache.put(world, new WeakReference<>(created));
return created;
}
}
public abstract IQueueExtent create();
public IQueueExtent getQueue(final World world) {
final IQueueExtent queue = queuePool.get();
queue.init(getOrCreate(world));
return queue;
}
@Override
public boolean trim(final boolean aggressive) {
boolean result = true;
synchronized (chunkCache) {
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();
final WorldChunkCache cache = value.get();
if (cache == null || cache.size() == 0 || cache.trim(aggressive)) {
iter.remove();
continue;
}
result = false;
}
}
return result;
}
public void apply(final World world, final Region region, final Filter 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] = forkJoinPoolPrimary.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 = getQueue(world);
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);
}
queue.flush();
}
}
});
}
// Join filters
for (int i = 0; i < tasks.length; i++) {
final ForkJoinTask task = tasks[i];
if (task != null) {
task.quietlyJoin();
}
}
filter.join();
}
}

View File

@ -0,0 +1,12 @@
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);
}
}

View File

@ -0,0 +1,252 @@
package com.boydti.fawe.beta.implementation;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.beta.IChunk;
import com.boydti.fawe.beta.IQueueExtent;
import com.boydti.fawe.beta.implementation.holder.ReferenceChunk;
import com.boydti.fawe.config.Settings;
import com.boydti.fawe.util.MathMan;
import com.boydti.fawe.util.MemUtil;
import com.google.common.util.concurrent.Futures;
import it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Single threaded implementation for IQueueExtent (still abstract)
* - Does not implement creation of chunks (that has to implemented by the platform e.g. Bukkit)
*
* This queue is reusable {@link #init(WorldChunkCache)}
*/
public abstract class SingleThreadQueueExtent implements IQueueExtent {
private WorldChunkCache cache;
private Thread currentThread;
private ConcurrentLinkedQueue<Future> submissions = new ConcurrentLinkedQueue<>();
/**
* 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");
}
}
@Override
public WorldChunkCache getCache() {
return cache;
}
/**
* Reset the queue
*/
protected synchronized void reset() {
checkThread();
cache = null;
if (!chunks.isEmpty()) {
CHUNK_POOL.addAll(chunks.values());
chunks.clear();
}
lastChunk = null;
lastPair = Long.MAX_VALUE;
currentThread = null;
}
/**
* Initialize the queue
* @param cache
*/
@Override
public synchronized void init(final WorldChunkCache cache) {
if (this.cache != null) {
reset();
}
currentThread = Thread.currentThread();
checkNotNull(cache);
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) {
CHUNK_POOL.add(chunk);
}
@Override
public <T extends Future<T>> T submit(final IChunk<T> chunk) {
if (lastChunk == chunk) {
lastPair = Long.MAX_VALUE;
lastChunk = null;
}
final long index = MathMan.pairInt(chunk.getX(), chunk.getZ());
chunks.remove(index, chunk);
return submitUnchecked(chunk);
}
/**
* 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) {
if (chunk.isEmpty()) {
CHUNK_POOL.add(chunk);
return (T) (Future) Futures.immediateFuture(null);
}
if (Fawe.isMainThread()) {
return chunk.call();
}
return Fawe.get().getQueueHandler().submit(chunk);
}
@Override
public synchronized boolean trim(final boolean aggressive) {
// TODO trim individial chunk sections
CHUNK_POOL.clear();
if (Thread.currentThread() == currentThread) {
lastChunk = null;
lastPair = Long.MAX_VALUE;
return chunks.isEmpty();
}
if (!submissions.isEmpty()) {
if (aggressive) {
pollSubmissions(0, aggressive);
} else {
pollSubmissions(Settings.IMP.QUEUE.PARALLEL_THREADS, aggressive);
}
}
synchronized (this) {
return currentThread == null;
}
}
/**
* 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) {
IChunk next = CHUNK_POOL.poll();
if (next == null) {
next = create(false);
}
next.init(this, X, Z);
return next;
}
@Override
public final IChunk getCachedChunk(final int X, final 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();
}
if (chunk != null) {
lastPair = pair;
lastChunk = chunk;
}
if (chunk != null) return chunk;
checkThread();
final int size = chunks.size();
final boolean lowMem = MemUtil.isMemoryLimited();
if (lowMem || size > Settings.IMP.QUEUE.TARGET_SIZE) {
chunk = chunks.removeFirst();
final Future future = submitUnchecked(chunk);
if (future != null && !future.isDone()) {
final int targetSize;
if (lowMem) {
targetSize = Settings.IMP.QUEUE.PARALLEL_THREADS;
} else {
targetSize = Settings.IMP.QUEUE.TARGET_SIZE;
}
pollSubmissions(targetSize, true);
submissions.add(future);
}
}
chunk = poolOrCreate(X, Z);
chunk = wrap(chunk);
chunks.put(pair, chunk);
lastPair = pair;
lastChunk = chunk;
return chunk;
}
private void pollSubmissions(final int targetSize, final 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) {
e.printStackTrace();
}
}
} else {
for (int i = 0; i < overflow; i++) {
Future next = submissions.peek();
while (next != null) {
if (next.isDone()) {
try {
next = (Future) next.get();
} catch (final InterruptedException | ExecutionException e) {
e.printStackTrace();
}
} else {
return;
}
}
submissions.poll();
}
}
}
@Override
public synchronized void flush() {
checkThread();
if (!chunks.isEmpty()) {
if (MemUtil.isMemoryLimited()) {
for (final IChunk chunk : chunks.values()) {
final Future future = submitUnchecked(chunk);
if (future != null && !future.isDone()) {
pollSubmissions(Settings.IMP.QUEUE.PARALLEL_THREADS, true);
submissions.add(future);
}
}
} else {
for (final IChunk chunk : chunks.values()) {
final Future future = submitUnchecked(chunk);
if (future != null && !future.isDone()) {
submissions.add(future);
}
}
}
chunks.clear();
}
pollSubmissions(0, true);
reset();
}
}

View File

@ -0,0 +1,72 @@
package com.boydti.fawe.beta.implementation;
import com.boydti.fawe.beta.IChunkGet;
import com.boydti.fawe.beta.Trimable;
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
*/
public class WorldChunkCache implements Trimable {
protected final Long2ObjectLinkedOpenHashMap<WeakReference<IChunkGet>> getCache;
private final World world;
protected WorldChunkCache(final World world) {
this.world = world;
this.getCache = new Long2ObjectLinkedOpenHashMap<>();
}
public World getWorld() {
return world;
}
public synchronized int size() {
return getCache.size();
}
/**
* 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) {
final WeakReference<IChunkGet> ref = getCache.get(index);
if (ref != null) {
final IChunkGet blocks = ref.get();
if (blocks != null) return blocks;
}
final IChunkGet blocks = provider.get();
getCache.put(index, new WeakReference<>(blocks));
return blocks;
}
@Override
public synchronized boolean trim(final boolean aggressive) {
boolean result = true;
if (!getCache.isEmpty()) {
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 {
result = false;
if (!aggressive) return result;
synchronized (igb) {
igb.trim(aggressive);
}
}
}
}
return result;
}
}

View File

@ -0,0 +1,114 @@
package com.boydti.fawe.beta.implementation.blocks;
import com.boydti.fawe.beta.IBlocks;
import com.boydti.fawe.beta.IChunkSet;
public class CharBlocks implements IBlocks {
public final char[][] blocks;
public final Section[] sections;
public CharBlocks(CharBlocks other) {
this.blocks = other.blocks;
this.sections = other.sections;
}
public CharBlocks() {
blocks = new char[16][];
sections = new Section[16];
for (int i = 0; i < 16; i++) sections[i] = EMPTY;
}
@Override
public boolean trim(final boolean aggressive) {
boolean result = true;
for (int i = 0; i < 16; i++) {
if (sections[i] == EMPTY) {
blocks[i] = null;
} else {
result = false;
}
}
return result;
}
@Override
public IChunkSet reset() {
for (int i = 0; i < 16; i++) sections[i] = EMPTY;
return null;
}
public void reset(final int layer) {
sections[layer] = EMPTY;
}
public char[] load(final 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;
return data;
}
@Override
public boolean hasSection(final int layer) {
return sections[layer] == FULL;
}
public char get(final int x, final int y, final int z) {
final int layer = y >> 4;
final int index = ((y & 15) << 8) | (z << 4) | (x & 15);
return sections[layer].get(this, layer, index);
}
public void set(final int x, final int y, final int z, final char value) {
final int layer = y >> 4;
final int index = ((y & 15) << 8) | (z << 4) | (x & 15);
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 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) {
return get(blocks, layer)[index];
}
public final void set(final CharBlocks blocks, final int layer, final int index, final 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];
}
};
}

View File

@ -0,0 +1,34 @@
package com.boydti.fawe.beta.implementation.blocks;
import com.boydti.fawe.beta.IChunkGet;
import com.boydti.fawe.beta.IChunkSet;
import com.sk89q.worldedit.world.block.BaseBlock;
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) {
return BlockTypes.states[get(x, y, z)].toBaseBlock();
}
@Override
public BlockState getBlock(final int x, final int y, final int z) {
return BlockTypes.states[get(x, y, z)];
}
@Override
public boolean trim(final boolean aggressive) {
for (int i = 0; i < 16; i++) {
sections[i] = EMPTY;
blocks[i] = null;
}
return true;
}
@Override
public IChunkSet reset() {
super.reset();
return null;
}
}

View File

@ -0,0 +1,124 @@
package com.boydti.fawe.beta.implementation.blocks;
import com.boydti.fawe.beta.IChunkSet;
import com.boydti.fawe.util.MathMan;
import com.sk89q.jnbt.CompoundTag;
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;
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;
public HashSet<UUID> entityRemoves;
public CharSetBlocks(CharBlocks other) {
super(other);
if (other instanceof CharSetBlocks) {
}
}
public CharSetBlocks() {
}
@Override
public char[] getArray(int layer) {
return sections[layer].get(this, layer);
}
@Override
public BiomeType[] getBiomes() {
return biomes;
}
@Override
public Map<Short, CompoundTag> getTiles() {
return tiles;
}
@Override
public Set<CompoundTag> getEntities() {
return entities;
}
@Override
public Set<UUID> getEntityRemoves() {
return entityRemoves;
}
@Override
public boolean setBiome(final int x, final int y, final int z, final BiomeType biome) {
if (biomes == null) {
biomes = new BiomeType[256];
}
biomes[x + (z << 4)] = biome;
return true;
}
@Override
public BlockState getBlock(int x, int y, int z) {
return BlockTypes.states[get(x, y, z)];
}
@Override
public boolean setBlock(final int x, final int y, final int z, final 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) {
if (tiles == null) {
tiles = new HashMap<>();
}
final short pair = MathMan.tripleBlockCoord(x, y, z);
tiles.put(pair, tile);
}
@Override
public void setEntity(final CompoundTag tag) {
if (entities == null) {
entities = new HashSet<>();
}
entities.add(tag);
}
@Override
public void removeEntity(final UUID uuid) {
if (entityRemoves == null) {
entityRemoves = new HashSet<>();
}
entityRemoves.add(uuid);
}
@Override
public boolean isEmpty() {
if (biomes != null) return false;
for (int i = 0; i < 16; i++) {
if (hasSection(i)) {
return false;
}
}
return true;
}
@Override
public IChunkSet reset() {
biomes = null;
tiles = null;
entities = null;
entityRemoves = null;
super.reset();
return null;
}
}

View File

@ -0,0 +1,311 @@
package com.boydti.fawe.beta.implementation.holder;
import com.boydti.fawe.beta.ChunkFilterBlock;
import com.boydti.fawe.beta.Filter;
import com.boydti.fawe.beta.FilterBlockMask;
import com.boydti.fawe.beta.Flood;
import com.boydti.fawe.beta.IChunk;
import com.boydti.fawe.beta.IChunkGet;
import com.boydti.fawe.beta.IChunkSet;
import com.boydti.fawe.beta.IQueueExtent;
import com.boydti.fawe.beta.implementation.SingleThreadQueueExtent;
import com.boydti.fawe.beta.implementation.WorldChunkCache;
import com.boydti.fawe.beta.implementation.blocks.CharSetBlocks;
import com.boydti.fawe.util.MathMan;
import com.sk89q.worldedit.math.MutableBlockVector3;
import com.sk89q.worldedit.regions.Region;
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;
/**
* Abstract IChunk class that implements basic get/set blocks
*/
public abstract class ChunkHolder implements IChunk, Supplier<IChunkGet> {
private IChunkGet get;
private IChunkSet set;
private IBlockDelegate delegate;
private IQueueExtent extent;
private int X,Z;
public ChunkHolder() {
this.delegate = NULL;
}
public ChunkHolder(final IBlockDelegate delegate) {
this.delegate = delegate;
}
@Override
public void flood(Flood flood, FilterBlockMask mask, ChunkFilterBlock block) {
// block.flood(get, set, mask, block, );
}
@Override
public void filterBlocks(final Filter filter, ChunkFilterBlock block, @Nullable Region region) {
final IChunkGet get = getOrCreateGet();
final IChunkSet set = getOrCreateSet();
try {
if (region != null) {
region.filter(this, filter, block, get, set);
} else {
block = block.init(X, Z, get);
for (int layer = 0; layer < 16; layer++) {
if (!get.hasSection(layer) || !filter.appliesLayer(this, layer)) continue;
block.init(get, set, layer);
block.filter(filter);
}
}
} finally {
filter.finishChunk(this);
}
}
@Override
public boolean trim(final boolean aggressive) {
if (set != null) {
final boolean result = set.trim(aggressive);
if (result) {
delegate = NULL;
get = null;
set = null;
return true;
}
}
if (aggressive) {
get = null;
if (delegate == BOTH) {
delegate = SET;
} else if (delegate == GET) {
delegate = NULL;
}
} else {
get.trim(false);
}
return false;
}
@Override
public boolean isEmpty() {
return set == null || set.isEmpty();
}
public final IChunkGet getOrCreateGet() {
if (get == null) get = newGet();
return get;
}
public final IChunkSet getOrCreateSet() {
if (set == null) set = set();
return set;
}
public IChunkSet set() {
return new CharSetBlocks();
}
private IChunkGet newGet() {
if (extent instanceof SingleThreadQueueExtent) {
final WorldChunkCache cache = ((SingleThreadQueueExtent) extent).getCache();
return cache.get(MathMan.pairInt(X, Z), this);
}
return get();
}
@Override
public void init(final IQueueExtent extent, final int X, final int Z) {
this.extent = extent;
this.X = X;
this.Z = Z;
if (set != null) {
set.reset();
delegate = SET;
} else {
delegate = NULL;
}
get = null;
}
public IQueueExtent getExtent() {
return extent;
}
@Override
public int getX() {
return X;
}
@Override
public int getZ() {
return Z;
}
@Override
public boolean setBiome(final int x, final int y, final int z, final 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) {
return delegate.setBlock(this, x, y, z, block);
}
@Override
public BiomeType getBiome(final int x, final int z) {
return delegate.getBiome(this, x, z);
}
@Override
public BlockState getBlock(final int x, final int y, final int z) {
return delegate.getBlock(this, x, y, z);
}
@Override
public BaseBlock getFullBlock(final int x, final int y, final 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);
BiomeType getBiome(final ChunkHolder chunk, final int x, final int z);
BlockState getBlock(final ChunkHolder chunk, final int x, final int y, final int z);
BaseBlock getFullBlock(final ChunkHolder chunk, final int x, final int y, final 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.getBiome(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.getBiome(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);
}
};
}

View File

@ -0,0 +1,33 @@
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) {
this.parent = parent;
}
public final T getParent() {
return parent;
}
public final void setParent(final T parent) {
this.parent = parent;
}
}

View File

@ -0,0 +1,31 @@
package com.boydti.fawe.beta.implementation.holder;
import com.boydti.fawe.beta.IQueueExtent;
import com.boydti.fawe.beta.IChunk;
/**
* 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) {
super(parent);
this.queueExtent = queueExtent;
}
/**
* Submit the chunk to the queue
* @throws Throwable
*/
@Override
protected void finalize() throws Throwable {
if (getParent() != null) {
// TODO apply safely
// apply();
setParent(null);
}
super.finalize();
}
}

View File

@ -0,0 +1,28 @@
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
*/
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));
}
protected abstract Reference<FinalizedChunk> toRef(FinalizedChunk parent);
@Override
public IChunk getParent() {
final FinalizedChunk finalized = ref.get();
return finalized != null ? finalized.getParent() : null;
}
}

View File

@ -0,0 +1,22 @@
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;
/**
* Soft reference implementation of {@link ReferenceChunk}
*/
public class SoftChunk extends ReferenceChunk {
public SoftChunk(final IChunk parent, final IQueueExtent queueExtent) {
super(parent, queueExtent);
}
@Override
protected Reference<FinalizedChunk> toRef(final FinalizedChunk parent) {
return new SoftReference<>(parent);
}
}

View File

@ -0,0 +1,21 @@
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.WeakReference;
/**
* Weak reference implementation of {@link ReferenceChunk}
*/
public class WeakChunk extends ReferenceChunk {
public WeakChunk(final IChunk parent, final IQueueExtent queueExtent) {
super(parent, queueExtent);
}
@Override
protected Reference<FinalizedChunk> toRef(final FinalizedChunk parent) {
return new WeakReference<>(parent);
}
}

View File

@ -2,6 +2,7 @@ package com.boydti.fawe.command;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.FaweAPI;
import com.boydti.fawe.beta.SingleFilterBlock;
import com.boydti.fawe.config.BBC;
import com.boydti.fawe.config.Commands;
import com.boydti.fawe.jnbt.anvil.HeightMapMCAGenerator;
@ -9,7 +10,6 @@ import com.boydti.fawe.object.FawePlayer;
import com.boydti.fawe.object.FaweQueue;
import com.boydti.fawe.object.RunnableVal;
import com.boydti.fawe.object.clipboard.MultiClipboardHolder;
import com.boydti.fawe.object.pattern.PatternExtent;
import com.boydti.fawe.util.CleanTextureUtil;
import com.boydti.fawe.util.FilteredTextureUtil;
import com.boydti.fawe.util.ImgurUtility;
@ -37,7 +37,6 @@ import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.pattern.BlockPattern;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
@ -70,7 +69,6 @@ import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Function;
import static com.boydti.fawe.util.image.ImageUtil.load;
@ -419,9 +417,7 @@ public class CFICommands extends MethodCommands {
}
default: {
blocks = new HashSet<>();
BlockPattern pattern = new BlockPattern(BlockTypes.AIR.getDefaultState());
PatternExtent extent = new PatternExtent(pattern);
SingleFilterBlock extent = new SingleFilterBlock();
ParserContext parserContext = new ParserContext();
parserContext.setActor(player);
parserContext.setWorld(player.getWorld());
@ -432,9 +428,10 @@ public class CFICommands extends MethodCommands {
TextureUtil tu = Fawe.get().getTextureUtil();
for (int typeId : tu.getValidBlockIds()) {
BlockType type = BlockTypes.get(typeId);
BlockStateHolder block = type.getDefaultState();
pattern.setBlock(block);
if (mask.test(BlockVector3.ZERO)) blocks.add(type);
extent.init(0, 0, 0, type.getDefaultState().toBaseBlock());
if (mask.test(extent)) {
blocks.add(type);
}
}
break;
}

View File

@ -257,8 +257,8 @@ public class Settings extends Config {
public static class QUEUE {
@Comment({
"This should equal the number of processors you have",
" - Set this to 1 if you need reliable `/timings`"
})
@Final
public int PARALLEL_THREADS = Math.max(1, Runtime.getRuntime().availableProcessors());
@Create
public static PROGRESS PROGRESS;

View File

@ -42,7 +42,7 @@ public class NBTStreamer {
try {
is.readNamedTagLazy(node -> {
if (readers.isEmpty()) {
throw new FaweException(BBC.WORLDEDIT_CANCEL_REASON_MANUAL);
throw FaweException.MANUAL;
}
return readers.remove(node);
});

View File

@ -14,7 +14,6 @@ public final class BitArray4096 {
maxEntryValue = (1 << bitsPerEntry) - 1;
this.longLen = (this.bitsPerEntry * 4096) >> 6;
if (buffer.length < longLen) {
System.out.println("Invalid buffer " + buffer.length + " | " + longLen);
this.data = new long[longLen];
} else {
this.data = buffer;
@ -159,4 +158,38 @@ public final class BitArray4096 {
}
return buffer;
}
public final char[] toRaw(char[] buffer) {
final long[] data = this.data;
final int dataLength = longLen;
final int bitsPerEntry = this.bitsPerEntry;
final int maxEntryValue = this.maxEntryValue;
final int maxSeqLocIndex = this.maxSeqLocIndex;
int localStart = 0;
char lastVal;
int arrI = 0;
long l;
for (int i = 0; i < dataLength; i++) {
l = data[i];
for (; localStart <= maxSeqLocIndex; localStart += bitsPerEntry) {
lastVal = (char) (l >>> localStart & maxEntryValue);
buffer[arrI++] = lastVal;
}
if (localStart < 64) {
if (i != dataLength - 1) {
lastVal = (char) (l >>> localStart);
localStart -= maxSeqLocIndex;
l = data[i + 1];
int localShift = bitsPerEntry - localStart;
lastVal |= l << localShift;
lastVal &= maxEntryValue;
buffer[arrI++] = lastVal;
}
} else {
localStart = 0;
}
}
return buffer;
}
}

View File

@ -2,6 +2,12 @@ package com.boydti.fawe.jnbt.anvil;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.FaweCache;
import com.boydti.fawe.beta.ArrayFilterBlock;
import com.boydti.fawe.beta.DelegateFilter;
import com.boydti.fawe.beta.Filter;
import com.boydti.fawe.beta.FilterBlock;
import com.boydti.fawe.beta.SimpleFilterBlock;
import com.boydti.fawe.beta.filters.ArrayImageMask;
import com.boydti.fawe.example.SimpleIntFaweChunk;
import com.boydti.fawe.jnbt.anvil.HeightMapMCADrawer;
import com.boydti.fawe.jnbt.anvil.MCAChunk;
@ -1023,7 +1029,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
@Override
public BlockState getBlock(BlockVector3 position) {
return getLazyBlock(position);
return getBlock(position.getX(), position.getY(), position.getZ());
}
public BlockState getFloor(int x, int z) {
@ -1046,12 +1052,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
}
@Override
public BlockState getLazyBlock(BlockVector3 position) {
return getLazyBlock(position.getBlockX(), position.getBlockY(), position.getBlockZ());
}
@Override
public BlockState getLazyBlock(int x, int y, int z) {
public BlockState getBlock(int x, int y, int z) {
return BlockState.getFromInternalId(getCombinedId4Data(x, y, z));
}

View File

@ -77,9 +77,6 @@ public class MCAChunk extends FaweChunk<Void> {
}
public void write(NBTOutputStream nbtOut) throws IOException {
nbtOut.writeNamedTagName("", NBTConstants.TYPE_COMPOUND);
nbtOut.writeLazyCompoundTag("Level", out -> {
out.writeNamedTag("V", (byte) 1);

View File

@ -79,7 +79,7 @@ public class MCAFile {
this.queue = parent;
this.file = file;
if (!file.exists()) {
throw new FaweException.FaweChunkLoadException();
throw FaweException.CHUNK;
}
String[] split = file.getName().split("\\.");
X = Integer.parseInt(split[1]);

View File

@ -104,7 +104,7 @@ public class MCAWorld implements SimpleWorld {
@Override
public BlockState getBlock(BlockVector3 position) {
return extent.getLazyBlock(position);
return extent.getBlock(position);
}
@Override

View File

@ -149,7 +149,7 @@ public class CavesGen extends GenBase {
for (int local_z = i3; (!waterFound) && (local_z < i4); local_z++) {
for (int local_y = i2 + 1; (!waterFound) && (local_y >= i1 - 1); local_y--) {
if (local_y < 255) {
BlockStateHolder material = chunk.getLazyBlock(bx + local_x, local_y, bz + local_z);
BlockStateHolder material = chunk.getBlock(bx + local_x, local_y, bz + local_z);
if (material.getBlockType() == BlockTypes.WATER) {
waterFound = true;
}
@ -173,8 +173,8 @@ public class CavesGen extends GenBase {
for (int local_y = i2; local_y > i1; local_y--) {
double d11 = ((local_y - 1) + 0.5D - y) / d4;
if ((d11 > -0.7D) && (d9 * d9 + d11 * d11 + d10 * d10 < 1.0D)) {
BlockStateHolder material = chunk.getLazyBlock(bx + local_x, local_y, bz + local_z);
BlockStateHolder materialAbove = chunk.getLazyBlock(bx + local_x, local_y + 1, bz + local_z);
BlockStateHolder material = chunk.getBlock(bx + local_x, local_y, bz + local_z);
BlockStateHolder materialAbove = chunk.getBlock(bx + local_x, local_y + 1, bz + local_z);
BlockType blockType = material.getBlockType();
switch (blockType.getInternalId()) {
case BlockID.MYCELIUM:
@ -191,7 +191,7 @@ public class CavesGen extends GenBase {
// If grass was just deleted, try to
// move it down
if (grassFound) {
BlockStateHolder block = chunk.getLazyBlock(bx + local_x, local_y - 1, bz + local_z);
BlockStateHolder block = chunk.getBlock(bx + local_x, local_y - 1, bz + local_z);
if (block.getBlockType() == BlockTypes.DIRT) {
chunk.setBlock(bx + local_x, local_y - 1, bz + local_z, BlockTypes.STONE.getDefaultState());
}

View File

@ -1,15 +1,14 @@
package com.boydti.fawe.object;
import com.boydti.fawe.FaweCache;
import com.boydti.fawe.beta.FilterBlock;
import com.boydti.fawe.object.extent.ExtentHeightCacher;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.pattern.AbstractPattern;
import com.sk89q.worldedit.math.BlockVector3;
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.BlockTypes;
public class DataAnglePattern extends AbstractPattern {
public final double FACTOR;
@ -24,7 +23,7 @@ public class DataAnglePattern extends AbstractPattern {
this.FACTOR = (1D / distance) * (1D / 255);
}
public int getSlope(BlockStateHolder block, BlockVector3 vector) {
public int getSlope(BlockStateHolder block, BlockVector3 vector, Extent extent) {
int x = vector.getBlockX();
int y = vector.getBlockY();
int z = vector.getBlockZ();
@ -32,7 +31,6 @@ public class DataAnglePattern extends AbstractPattern {
return -1;
}
int slope;
boolean aboveMin;
slope = Math.abs(extent.getNearestSurfaceTerrainBlock(x + distance, z, y, 0, maxY) - extent.getNearestSurfaceTerrainBlock(x - distance, z, y, 0, maxY)) * 7;
slope += Math.abs(extent.getNearestSurfaceTerrainBlock(x, z + distance, y, 0, maxY) - extent.getNearestSurfaceTerrainBlock(x, z - distance, y, 0, maxY)) * 7;
slope += Math.abs(extent.getNearestSurfaceTerrainBlock(x + distance, z + distance, y, 0, maxY) - extent.getNearestSurfaceTerrainBlock(x - distance, z - distance, y, 0, maxY)) * 5;
@ -42,8 +40,8 @@ public class DataAnglePattern extends AbstractPattern {
@Override
public BaseBlock apply(BlockVector3 position) {
BlockStateHolder block = extent.getBlock(position);
int slope = getSlope(block, position);
BlockState block = extent.getBlock(position);
int slope = getSlope(block, position, extent);
if (slope == -1) return block.toBaseBlock();
int data = (Math.min(slope, 255)) >> 4;
return block.withPropertyId(data).toBaseBlock();
@ -52,7 +50,7 @@ public class DataAnglePattern extends AbstractPattern {
@Override
public boolean apply(Extent extent, BlockVector3 setPosition, BlockVector3 getPosition) throws WorldEditException {
BlockStateHolder block = extent.getBlock(getPosition);
int slope = getSlope(block, getPosition);
int slope = getSlope(block, getPosition, extent);
if (slope == -1) return false;
int data = (Math.min(slope, 255)) >> 4;
return extent.setBlock(setPosition, block.withPropertyId(data));

View File

@ -243,9 +243,9 @@ public abstract class FawePlayer<T> extends Metadatable {
Region[] allowed = WEManager.IMP.getMask(this, FaweMaskManager.MaskType.OWNER);
HashSet<Region> allowedSet = new HashSet<>(Arrays.asList(allowed));
if (allowed.length == 0) {
throw new FaweException(BBC.WORLDEDIT_CANCEL_REASON_NO_REGION);
throw FaweException.NO_REGION;
} else if (!WEManager.IMP.regionContains(wrappedSelection, allowedSet)) {
throw new FaweException(BBC.WORLDEDIT_CANCEL_REASON_OUTSIDE_REGION);
throw FaweException.OUTSIDE_REGION;
}
}

View File

@ -72,7 +72,7 @@ public interface FaweQueue extends HasFaweQueue, Extent {
}
@Override
default BlockState getLazyBlock(int x, int y, int z) {
default BlockState getBlock(int x, int y, int z) {
int combinedId4Data = getCachedCombinedId4Data(x, y, z, BlockTypes.AIR.getInternalId());
try {
return BlockState.getFromInternalId(combinedId4Data);

View File

@ -29,7 +29,6 @@ public class HistoryExtent extends AbstractDelegateExtent {
private FaweChangeSet changeSet;
private final FaweQueue queue;
private final EditSession session;
/**
* Create a new instance.
@ -37,12 +36,11 @@ public class HistoryExtent extends AbstractDelegateExtent {
* @param extent the extent
* @param changeSet the change set
*/
public HistoryExtent(final EditSession session, final Extent extent, final FaweChangeSet changeSet, FaweQueue queue) {
public HistoryExtent(final Extent extent, final FaweChangeSet changeSet, FaweQueue queue) {
super(extent);
checkNotNull(changeSet);
this.queue = queue;
this.changeSet = changeSet;
this.session = session;
}
public FaweChangeSet getChangeSet() {
@ -55,9 +53,9 @@ public class HistoryExtent extends AbstractDelegateExtent {
@Override
public <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block) throws WorldEditException {
BaseBlock previous = queue.getFullBlock(mutable.setComponents(x, y, z)).toBaseBlock();
BaseBlock previous = queue.getFullBlock(x, y, z);
if (previous.getInternalId() == block.getInternalId()) {
if (!previous.hasNbtData() && (block instanceof BaseBlock && !((BaseBlock)block).hasNbtData())) {
if (!previous.hasNbtData() && (block instanceof BaseBlock && !block.hasNbtData())) {
return false;
}
}

View File

@ -49,7 +49,6 @@ public class InspectBrush extends BrushTool implements DoubleActionTraceTool {
}
public Vector3 getTarget(Player player, boolean adjacent) {
Location target = null;
int range = this.range > -1 ? getRange() : MAX_RANGE;
if (adjacent) {
Location face = player.getBlockTraceFace(range, true);

View File

@ -1,5 +1,6 @@
package com.boydti.fawe.object.brush;
import com.boydti.fawe.beta.FilterBlock;
import com.boydti.fawe.object.FaweQueue;
import com.boydti.fawe.object.collection.BlockVectorSet;
import com.boydti.fawe.object.mask.AdjacentAnyMask;
@ -7,6 +8,7 @@ import com.boydti.fawe.object.mask.RadiusMask;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.command.tool.brush.Brush;
import com.sk89q.worldedit.function.mask.BlockMask;
import com.sk89q.worldedit.function.mask.BlockTypeMask;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.SolidBlockMask;
@ -34,7 +36,7 @@ public class LayerBrush implements Brush {
@Override
public void build(EditSession editSession, BlockVector3 position, Pattern ignore, double size) throws MaxChangedBlocksException {
final FaweQueue queue = editSession.getQueue();
final AdjacentAnyMask adjacent = new AdjacentAnyMask(new BlockTypeMask(editSession, BlockTypes.AIR, BlockTypes.CAVE_AIR, BlockTypes.VOID_AIR));
final AdjacentAnyMask adjacent = new AdjacentAnyMask(new BlockMask(editSession).add(BlockTypes.AIR, BlockTypes.CAVE_AIR, BlockTypes.VOID_AIR));
final SolidBlockMask solid = new SolidBlockMask(editSession);
final RadiusMask radius = new RadiusMask(0, (int) size);
visitor = new RecursiveVisitor(vector -> solid.test(vector) && radius.test(vector) && adjacent.test(vector), function -> true);
@ -42,30 +44,32 @@ public class LayerBrush implements Brush {
visitor.setDirections(Arrays.asList(BreadthFirstSearch.DIAGONAL_DIRECTIONS));
Operations.completeBlindly(visitor);
BlockVectorSet visited = visitor.getVisited();
BlockStateHolder firstPattern = layers[0];
visitor = new RecursiveVisitor((Mask) pos -> {
int depth = visitor.getDepth() + 1;
if (depth > 1) {
boolean found = false;
int previous = layers[depth - 1].getInternalId();
int previous2 = layers[depth - 2].getInternalId();
for (BlockVector3 dir : BreadthFirstSearch.DEFAULT_DIRECTIONS) {
mutable.setComponents(pos.getBlockX() + dir.getBlockX(), pos.getBlockY() + dir.getBlockY(), pos.getBlockZ() + dir.getBlockZ());
if (visitor.isVisited(mutable) && queue.getCachedCombinedId4Data(mutable.getBlockX(), mutable.getBlockY(), mutable.getBlockZ()) == previous) {
mutable.setComponents(pos.getBlockX() + dir.getBlockX() * 2, pos.getBlockY() + dir.getBlockY() * 2, pos.getBlockZ() + dir.getBlockZ() * 2);
if (visitor.isVisited(mutable) && queue.getCachedCombinedId4Data(mutable.getBlockX(), mutable.getBlockY(), mutable.getBlockZ()) == previous2) {
found = true;
break;
} else {
return false;
visitor = new RecursiveVisitor(new Mask() {
@Override
public boolean test(BlockVector3 pos) {
int depth = visitor.getDepth() + 1;
if (depth > 1) {
boolean found = false;
int previous = layers[depth - 1].getInternalId();
int previous2 = layers[depth - 2].getInternalId();
for (BlockVector3 dir : BreadthFirstSearch.DEFAULT_DIRECTIONS) {
mutable.setComponents(pos.getBlockX() + dir.getBlockX(), pos.getBlockY() + dir.getBlockY(), pos.getBlockZ() + dir.getBlockZ());
if (visitor.isVisited(mutable) && queue.getCachedCombinedId4Data(mutable.getBlockX(), mutable.getBlockY(), mutable.getBlockZ()) == previous) {
mutable.setComponents(pos.getBlockX() + dir.getBlockX() * 2, pos.getBlockY() + dir.getBlockY() * 2, pos.getBlockZ() + dir.getBlockZ() * 2);
if (visitor.isVisited(mutable) && queue.getCachedCombinedId4Data(mutable.getBlockX(), mutable.getBlockY(), mutable.getBlockZ()) == previous2) {
found = true;
break;
} else {
return false;
}
}
}
if (!found) {
return false;
}
}
if (!found) {
return false;
}
return !adjacent.test(pos);
}
return !adjacent.test(pos);
}, pos -> {
int depth = visitor.getDepth();
BlockStateHolder currentPattern = layers[depth];

View File

@ -68,7 +68,7 @@ public class SplineBrush implements Brush, ResettableTool {
this.position = position;
if (newPos) {
if (positionSets.size() >= MAX_POINTS) {
throw new FaweException(BBC.WORLDEDIT_CANCEL_REASON_MAX_CHECKS);
throw FaweException.MAX_CHECKS;
}
final ArrayList<BlockVector3> points = new ArrayList<>();
if (size > 0) {

View File

@ -50,6 +50,7 @@ public class SurfaceSpline implements Brush {
n.setContinuity(continuity);
nodes.add(n);
}
MutableBlockVector3 mutable = MutableBlockVector3.at(0, 0, 0);
interpol.setNodes(nodes);
final double splinelength = interpol.arcLength(0, 1);
for (double loop = 0; loop <= 1; loop += 1D / splinelength / quality) {
@ -60,7 +61,7 @@ public class SurfaceSpline implements Brush {
tipy = editSession.getNearestSurfaceTerrainBlock(tipx, tipz, tipy, 0, maxY);
if (tipy == -1) continue;
if (radius == 0) {
BlockVector3 set = MutableBlockVector3.get(tipx, tipy, tipz);
BlockVector3 set = mutable.setComponents(tipx, tipy, tipz);
try {
pattern.apply(editSession, set, set);
} catch (WorldEditException e) {

View File

@ -24,7 +24,12 @@ public interface VirtualWorld extends SimpleWorld, FaweQueue, Closeable {
@Override
default BaseBlock getFullBlock(BlockVector3 position) {
return getLazyBlock(position).toBaseBlock();
return getBlock(position).toBaseBlock();
}
@Override
default BaseBlock getFullBlock(int x, int y, int z) {
return getBlock(x, y, z).toBaseBlock();
}
@Override

View File

@ -40,7 +40,7 @@ public class VisualExtent extends AbstractDelegateExtent {
@Override
public boolean setBlock(int x, int y, int z, BlockStateHolder block) throws WorldEditException {
BlockStateHolder previous = super.getLazyBlock(x, y, z);
BlockStateHolder previous = super.getBlock(x, y, z);
int cx = x >> 4;
int cz = z >> 4;
long chunkPair = MathMan.pairInt(cx, cz);

View File

@ -1,6 +1,5 @@
package com.boydti.fawe.object.changeset;
import com.boydti.fawe.FaweCache;
import com.boydti.fawe.object.exception.FaweException;
import com.boydti.fawe.util.ReflectionUtils;
import com.sk89q.jnbt.CompoundTag;
@ -10,7 +9,6 @@ import com.sk89q.worldedit.extent.inventory.BlockBagException;
import com.sk89q.worldedit.extent.inventory.UnplaceableBlockException;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
@ -89,10 +87,10 @@ public class BlockBagChangeSet extends AbstractDelegateChangeSet {
try {
blockBag.fetchPlacedBlock(typeTo.getDefaultState());
} catch (UnplaceableBlockException e) {
throw new FaweException.FaweBlockBagException();
throw FaweException.BLOCK_BAG;
} catch (BlockBagException e) {
missingBlocks[typeTo.getInternalId()]++;
throw new FaweException.FaweBlockBagException();
throw FaweException.BLOCK_BAG;
}
}
if (mine) {

View File

@ -78,7 +78,7 @@ public class EmptyClipboard implements Clipboard {
}
@Override
public BlockState getLazyBlock(BlockVector3 position) {
public BlockState getBlock(BlockVector3 position) {
return BlockTypes.AIR.getDefaultState();
}

View File

@ -38,13 +38,15 @@ public class BlockVectorSet extends AbstractCollection<BlockVector3> implements
int newSize = count + size;
if (newSize > index) {
int localIndex = index - count;
BlockVector3 pos = mutable.setComponents(set.getIndex(localIndex));
int pair = entry.getIntKey();
int cx = MathMan.unpairX(pair);
int cz = MathMan.unpairY(pair);
pos = pos.mutX((cx << 11) + pos.getBlockX());
pos = pos.mutZ((cz << 11) + pos.getBlockZ());
return pos;
BlockVector3 pos = set.getIndex(localIndex);
if (pos != null) {
int pair = entry.getIntKey();
int cx = MathMan.unpairX(pair);
int cz = MathMan.unpairY(pair);
pos = pos.mutX((cx << 11) + pos.getBlockX());
pos = pos.mutZ((cz << 11) + pos.getBlockZ());
return pos;
}
}
count += newSize;
}

View File

@ -244,9 +244,9 @@ public final class DifferentialArray<T> implements DifferentialCollection<T> {
return dataBytes;
}
// public char[] getCharArray() {
// return dataChars;
// }
public char[] getCharArray() {
return dataChars;
}
public int[] getIntArray() {
return dataInts;

View File

@ -0,0 +1,213 @@
package com.boydti.fawe.object.collection;
import com.boydti.fawe.object.FaweInputStream;
import com.boydti.fawe.object.FaweOutputStream;
import java.io.IOException;
import java.lang.reflect.Array;
/**
* Records changes made through the {@link #set(int, int, int, char)} method<br/>
* Changes are not recorded if you edit the raw data
*/
public final class DifferentialCharBlockBuffer implements DifferentialCollection<char[][][][][]> {
private final int width, length;
private final int t1, t2;
private char[][][][][] data;
private char[][][][][] changes;
public DifferentialCharBlockBuffer(int width, int length) {
this.width = width;
this.length = length;
this.t1 = (length + 15) >> 4;
this.t2 = (width + 15) >> 4;
}
@Override
public char[][][][][] get() {
return data;
}
@Override
public void flushChanges(FaweOutputStream out) throws IOException {
boolean modified = isModified();
out.writeBoolean(modified);
if (modified) {
writeArray(changes, 0, 0, out);
}
clearChanges();
}
private void writeArray(Object arr, int level, int index, FaweOutputStream out) throws IOException {
if (level == 4) {
if (arr != null) {
char[] level4 = (char[]) arr;
out.writeVarInt(level4.length);
for (char c : level4) {
out.writeChar(c);
}
} else {
out.writeVarInt(0);
}
} else {
int len = arr == null ? 0 : Array.getLength(arr);
out.writeVarInt(len);
for (int i = 0; i < len; i++) {
Object elem = Array.get(arr, i);
writeArray(elem, level + 1, i, out);
}
}
}
@Override
public void undoChanges(FaweInputStream in) throws IOException {
if (changes != null && changes.length != 0) throw new IllegalStateException("There are uncommitted changes, please flush first");
boolean modified = in.readBoolean();
if (modified) {
int len = in.readVarInt();
if (len == 0) {
data = null;
} else {
for (int i = 0; i < len; i++) {
readArray(data, i, 1, in);
}
}
}
clearChanges();
}
@Override
public void redoChanges(FaweInputStream in) throws IOException {
clearChanges();
throw new UnsupportedOperationException("Not implemented");
}
private void readArray(Object dataElem, int index, int level, FaweInputStream in) throws IOException {
int len = in.readVarInt();
if (level == 4) {
char[][] castedElem = (char[][]) dataElem;
if (len == 0) {
castedElem[index] = null;
} else {
char[] current = castedElem[index];
for (int i = 0; i < len; i++) {
current[i] = in.readChar();
}
}
} else {
if (len == 0) {
Array.set(dataElem, index, null);
} else {
Object nextElem = Array.get(dataElem, index);
for (int i = 0; i < len; i++) {
readArray(nextElem, i, level + 1, in);
}
}
}
}
public boolean isModified() {
return changes != null;
}
public void clearChanges() {
changes = null;
}
public void set(int x, int y, int z, char combined) {
if (combined == 0) combined = 1;
int localX = x & 15;
int localZ = z & 15;
int chunkX = x >> 4;
int chunkZ = z >> 4;
if (data == null) {
data = new char[t1][][][][];
changes = new char[0][][][][];
}
char[][][][] arr = data[chunkZ];
if (arr == null) {
arr = data[chunkZ] = new char[t2][][][];
}
char[][][] arr2 = arr[chunkX];
if (arr2 == null) {
arr2 = arr[chunkX] = new char[256][][];
}
char[][] yMap = arr2[y];
if (yMap == null) {
arr2[y] = yMap = new char[16][];
}
boolean newSection;
char current;
char[] zMap = yMap[localZ];
if (zMap == null) {
yMap[localZ] = zMap = new char[16];
if (changes == null) {
changes = new char[t1][][][][];
} else if (changes != null && changes.length != 0) {
initialChange(changes, chunkX, chunkZ, localX, localZ, y, (char) -combined);
}
} else {
if (changes == null || changes.length == 0) changes = new char[t1][][][][];
appendChange(changes, chunkX, chunkZ, localX, localZ, y, (char) (zMap[localX] - combined));
}
zMap[localX] = combined;
}
private void initialChange(char[][][][][] src, int chunkX, int chunkZ, int localX, int localZ, int y, char combined) {
char[][][][] arr = src[chunkZ];
if (arr == null) {
src[chunkZ] = new char[0][][][];
return;
} else if (arr.length == 0) return;
char[][][] arr2 = arr[chunkX];
if (arr2 == null) {
arr[chunkX] = new char[0][][];
return;
} else if (arr2.length == 0) return;
char[][] yMap = arr2[y];
if (yMap == null) {
arr2[y] = new char[0][];
return;
} else if (yMap.length == 0) return;
char[] zMap = yMap[localZ];
if (zMap == null) {
yMap[localZ] = new char[0];
return;
} else if (zMap.length == 0) return;
char current = zMap[localX];
zMap[localX] = combined;
}
private void appendChange(char[][][][][] src, int chunkX, int chunkZ, int localX, int localZ, int y, char combined) {
char[][][][] arr = src[chunkZ];
if (arr == null || arr.length == 0) {
arr = src[chunkZ] = new char[t2][][][];
}
char[][][] arr2 = arr[chunkX];
if (arr2 == null || arr2.length == 0) {
arr2 = arr[chunkX] = new char[256][][];
}
char[][] yMap = arr2[y];
if (yMap == null || yMap.length == 0) {
arr2[y] = yMap = new char[16][];
}
char[] zMap = yMap[localZ];
if (zMap == null || zMap.length == 0) {
yMap[localZ] = zMap = new char[16];
}
zMap[localX] = combined;
}
}

View File

@ -11,8 +11,7 @@ import java.util.Iterator;
import java.util.concurrent.ConcurrentLinkedDeque;
public abstract class IterableThreadLocal<T> extends ThreadLocal<T> implements Iterable<T> {
private ThreadLocal<T> flag;
private ConcurrentLinkedDeque<T> allValues = new ConcurrentLinkedDeque<>();
private final ConcurrentLinkedDeque<T> allValues = new ConcurrentLinkedDeque<>();
public IterableThreadLocal() {
}
@ -21,7 +20,9 @@ public abstract class IterableThreadLocal<T> extends ThreadLocal<T> implements I
protected final T initialValue() {
T value = init();
if (value != null) {
allValues.add(value);
synchronized (this) {
allValues.add(value);
}
}
return value;
}
@ -36,7 +37,12 @@ public abstract class IterableThreadLocal<T> extends ThreadLocal<T> implements I
}
public void clean() {
IterableThreadLocal.clean(this);
if (!allValues.isEmpty()) {
synchronized (this) {
IterableThreadLocal.clean(this);
allValues.clear();
}
}
}
public static void clean(ThreadLocal instance) {

View File

@ -101,7 +101,7 @@ public class LocalBlockVectorSet implements Set<BlockVector3> {
this.offsetZ = z;
}
public BlockVector3 getIndex(int getIndex) {
protected BlockVector3 getIndex(int getIndex) {
int size = size();
if (getIndex > size) {
return null;

View File

@ -3,6 +3,17 @@ package com.boydti.fawe.object.exception;
import com.boydti.fawe.config.BBC;
public class FaweException extends RuntimeException {
public static final FaweChunkLoadException CHUNK = new FaweChunkLoadException();
public static final FaweBlockBagException BLOCK_BAG = new FaweBlockBagException();
public static final FaweException MANUAL = new FaweException(BBC.WORLDEDIT_CANCEL_REASON_MANUAL);
public static final FaweException NO_REGION = new FaweException(BBC.WORLDEDIT_CANCEL_REASON_NO_REGION);
public static final FaweException OUTSIDE_REGION = new FaweException(BBC.WORLDEDIT_CANCEL_REASON_OUTSIDE_REGION);
public static final FaweException MAX_CHECKS = new FaweException(BBC.WORLDEDIT_CANCEL_REASON_MAX_CHECKS);
public static final FaweException MAX_CHANGES = new FaweException(BBC.WORLDEDIT_CANCEL_REASON_MAX_CHANGES);
public static final FaweException LOW_MEMORY = new FaweException(BBC.WORLDEDIT_CANCEL_REASON_LOW_MEMORY);
public static final FaweException MAX_ENTITIES = new FaweException(BBC.WORLDEDIT_CANCEL_REASON_MAX_ENTITIES);
public static final FaweException MAX_TILES = new FaweException(BBC.WORLDEDIT_CANCEL_REASON_MAX_TILES);
private final BBC message;
public FaweException(BBC reason) {
@ -42,7 +53,7 @@ public class FaweException extends RuntimeException {
}
/**
* Faster exception throwing if you don't fill the stacktrace
* Faster exception throwing/handling if you don't fill the stacktrace
*
* @return
*/

View File

@ -52,17 +52,12 @@ public class BlockTranslateExtent extends AbstractDelegateExtent {
@Override
public BlockState getBlock(BlockVector3 location) {
return getLazyBlock(location.getBlockX(), location.getBlockY(), location.getBlockZ());
return getBlock(location.getBlockX(), location.getBlockY(), location.getBlockZ());
}
@Override
public BlockState getLazyBlock(BlockVector3 location) {
return getLazyBlock(location.getBlockX(), location.getBlockY(), location.getBlockZ());
}
@Override
public BlockState getLazyBlock(int x, int y, int z) {
return super.getLazyBlock(x + dx, y + dy, z + dz);
public BlockState getBlock(int x, int y, int z) {
return super.getBlock(x + dx, y + dy, z + dz);
}
@Override

View File

@ -126,12 +126,12 @@ public class FastWorldEditExtent extends AbstractDelegateExtent implements HasFa
}
@Override
public BlockState getLazyBlock(BlockVector3 location) {
return getLazyBlock(location.getBlockX(), location.getBlockY(), location.getBlockZ());
public BlockState getBlock(BlockVector3 location) {
return getBlock(location.getBlockX(), location.getBlockY(), location.getBlockZ());
}
@Override
public BlockState getLazyBlock(int x, int y, int z) {
public BlockState getBlock(int x, int y, int z) {
int combinedId4Data = queue.getCombinedId4Data(x, y, z, 0);
BlockType type = BlockTypes.getFromStateId(combinedId4Data);
return type.withStateId(combinedId4Data);
@ -161,11 +161,6 @@ public class FastWorldEditExtent extends AbstractDelegateExtent implements HasFa
return world.getEntities(region);
}
@Override
public BlockState getBlock(final BlockVector3 position) {
return this.getLazyBlock(position);
}
@Override
public boolean setBiome(final BlockVector2 position, final BiomeType biome) {
queue.setBiome(position.getBlockX(), position.getBlockZ(), biome);

View File

@ -2,6 +2,7 @@ package com.boydti.fawe.object.extent;
import com.boydti.fawe.config.BBC;
import com.boydti.fawe.object.FaweLimit;
import com.boydti.fawe.object.exception.FaweException;
import com.boydti.fawe.util.WEManager;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
@ -56,44 +57,22 @@ public abstract class FaweRegionExtent extends ResettableExtent {
return contains(p.getBlockX(), p.getBlockZ());
}
@Override
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 location, B block) throws WorldEditException {
if (!contains(location)) {
if (!limit.MAX_FAILS()) {
WEManager.IMP.cancelEditSafe(this, BBC.WORLDEDIT_CANCEL_REASON_OUTSIDE_REGION);
}
return false;
}
return super.setBlock(location, block);
}
@Override
public <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block) throws WorldEditException {
if (!contains(x, y, z)) {
if (!limit.MAX_FAILS()) {
WEManager.IMP.cancelEditSafe(this, BBC.WORLDEDIT_CANCEL_REASON_OUTSIDE_REGION);
WEManager.IMP.cancelEditSafe(this, FaweException.OUTSIDE_REGION);
}
return false;
}
return super.setBlock(x, y, z, block);
}
@Override
public boolean setBiome(BlockVector2 position, BiomeType biome) {
if (!contains(position)) {
if (!limit.MAX_FAILS()) {
WEManager.IMP.cancelEditSafe(this, BBC.WORLDEDIT_CANCEL_REASON_OUTSIDE_REGION);
}
return false;
}
return super.setBiome(position, biome);
}
@Override
public boolean setBiome(int x, int y, int z, BiomeType biome) {
if (!contains(x, y, z)) {
if (!limit.MAX_FAILS()) {
WEManager.IMP.cancelEditSafe(this, BBC.WORLDEDIT_CANCEL_REASON_OUTSIDE_REGION);
WEManager.IMP.cancelEditSafe(this, FaweException.OUTSIDE_REGION);
}
return false;
}
@ -104,18 +83,29 @@ public abstract class FaweRegionExtent extends ResettableExtent {
public BiomeType getBiome(BlockVector2 position) {
if (!contains(position)) {
if (!limit.MAX_FAILS()) {
WEManager.IMP.cancelEditSafe(this, BBC.WORLDEDIT_CANCEL_REASON_OUTSIDE_REGION);
WEManager.IMP.cancelEditSafe(this, FaweException.OUTSIDE_REGION);
}
return null;
}
return super.getBiome(position);
}
@Override
public BiomeType getBiomeType(int x, int z) {
if (!contains(x, z)) {
if (!limit.MAX_FAILS()) {
WEManager.IMP.cancelEditSafe(this, FaweException.OUTSIDE_REGION);
}
return null;
}
return super.getBiomeType(x, z);
}
@Override
public BaseBlock getFullBlock(BlockVector3 position) {
if (!contains(position)) {
if (!limit.MAX_FAILS()) {
WEManager.IMP.cancelEditSafe(this, BBC.WORLDEDIT_CANCEL_REASON_OUTSIDE_REGION);
WEManager.IMP.cancelEditSafe(this, FaweException.OUTSIDE_REGION);
}
return BlockTypes.AIR.getDefaultState().toBaseBlock();
}
@ -126,40 +116,18 @@ public abstract class FaweRegionExtent extends ResettableExtent {
public BlockState getBlock(BlockVector3 position) {
if (!contains(position)) {
if (!limit.MAX_FAILS()) {
WEManager.IMP.cancelEditSafe(this, BBC.WORLDEDIT_CANCEL_REASON_OUTSIDE_REGION);
WEManager.IMP.cancelEditSafe(this, FaweException.OUTSIDE_REGION);
}
return BlockTypes.AIR.getDefaultState();
}
return super.getBlock(position);
}
@Override
public BlockState getLazyBlock(BlockVector3 position) {
if (!contains(position)) {
if (!limit.MAX_FAILS()) {
WEManager.IMP.cancelEditSafe(this, BBC.WORLDEDIT_CANCEL_REASON_OUTSIDE_REGION);
}
return BlockTypes.AIR.getDefaultState();
}
return super.getLazyBlock(position);
}
@Override
public BlockState getLazyBlock(int x, int y, int z) {
if (!contains(x, y, z)) {
if (!limit.MAX_FAILS()) {
WEManager.IMP.cancelEditSafe(this, BBC.WORLDEDIT_CANCEL_REASON_OUTSIDE_REGION);
}
return BlockTypes.AIR.getDefaultState();
}
return super.getLazyBlock(x, y, z);
}
@Override
public int getBlockLight(int x, int y, int z) {
if (!contains(x, y, z)) {
if (!limit.MAX_FAILS()) {
WEManager.IMP.cancelEditSafe(this, BBC.WORLDEDIT_CANCEL_REASON_OUTSIDE_REGION);
WEManager.IMP.cancelEditSafe(this, FaweException.OUTSIDE_REGION);
}
return 0;
}
@ -170,7 +138,7 @@ public abstract class FaweRegionExtent extends ResettableExtent {
public int getBrightness(int x, int y, int z) {
if (!contains(x, y, z)) {
if (!limit.MAX_FAILS()) {
WEManager.IMP.cancelEditSafe(this, BBC.WORLDEDIT_CANCEL_REASON_OUTSIDE_REGION);
WEManager.IMP.cancelEditSafe(this, FaweException.OUTSIDE_REGION);
}
return 0;
}
@ -181,7 +149,7 @@ public abstract class FaweRegionExtent extends ResettableExtent {
public int getLight(int x, int y, int z) {
if (!contains(x, y, z)) {
if (!limit.MAX_FAILS()) {
WEManager.IMP.cancelEditSafe(this, BBC.WORLDEDIT_CANCEL_REASON_OUTSIDE_REGION);
WEManager.IMP.cancelEditSafe(this, FaweException.OUTSIDE_REGION);
}
return 0;
}
@ -192,7 +160,7 @@ public abstract class FaweRegionExtent extends ResettableExtent {
public int getOpacity(int x, int y, int z) {
if (!contains(x, y, z)) {
if (!limit.MAX_FAILS()) {
WEManager.IMP.cancelEditSafe(this, BBC.WORLDEDIT_CANCEL_REASON_OUTSIDE_REGION);
WEManager.IMP.cancelEditSafe(this, FaweException.OUTSIDE_REGION);
}
return 0;
}
@ -203,7 +171,7 @@ public abstract class FaweRegionExtent extends ResettableExtent {
public int getSkyLight(int x, int y, int z) {
if (!contains(x, y, z)) {
if (!limit.MAX_FAILS()) {
WEManager.IMP.cancelEditSafe(this, BBC.WORLDEDIT_CANCEL_REASON_OUTSIDE_REGION);
WEManager.IMP.cancelEditSafe(this, FaweException.OUTSIDE_REGION);
}
return 0;
}
@ -215,7 +183,7 @@ public abstract class FaweRegionExtent extends ResettableExtent {
public Entity createEntity(Location location, BaseEntity entity) {
if (!contains(location.getBlockX(), location.getBlockY(), location.getBlockZ())) {
if (!limit.MAX_FAILS()) {
WEManager.IMP.cancelEditSafe(this, BBC.WORLDEDIT_CANCEL_REASON_OUTSIDE_REGION);
WEManager.IMP.cancelEditSafe(this, FaweException.OUTSIDE_REGION);
}
return null;
}

View File

@ -2,6 +2,7 @@ package com.boydti.fawe.object.extent;
import com.boydti.fawe.config.BBC;
import com.boydti.fawe.object.FawePlayer;
import com.boydti.fawe.object.exception.FaweException;
import com.boydti.fawe.util.MemUtil;
import com.boydti.fawe.util.Perm;
import com.boydti.fawe.util.WEManager;
@ -30,7 +31,7 @@ public class MemoryCheckingExtent extends AbstractDelegateExtent {
BBC.WORLDEDIT_OOM_ADMIN.send(this.player);
}
}
WEManager.IMP.cancelEdit(this, BBC.WORLDEDIT_CANCEL_REASON_LOW_MEMORY);
WEManager.IMP.cancelEdit(this, FaweException.LOW_MEMORY);
return false;
}
return true;

View File

@ -25,7 +25,7 @@ import java.util.List;
public class NullExtent extends FaweRegionExtent {
private final BBC reason;
private final FaweException reason;
/**
* Create a new instance.
@ -33,13 +33,16 @@ public class NullExtent extends FaweRegionExtent {
* @param extent the extent
*/
public NullExtent(Extent extent, BBC failReason) {
this(extent, new FaweException(failReason));
}
public NullExtent(Extent extent, FaweException exception) {
super(extent, FaweLimit.MAX);
this.reason = failReason;
this.reason = exception;
}
public NullExtent() {
super(new com.sk89q.worldedit.extent.NullExtent(), FaweLimit.MAX);
this.reason = BBC.WORLDEDIT_CANCEL_REASON_MANUAL;
this(new com.sk89q.worldedit.extent.NullExtent(), FaweException.MANUAL);
}
@Override
@ -50,7 +53,7 @@ public class NullExtent extends FaweRegionExtent {
@Override
public BiomeType getBiome(final BlockVector2 arg0) {
if(reason != null) {
throw new FaweException(reason);
throw reason;
}else {
return null;
}
@ -59,25 +62,34 @@ public class NullExtent extends FaweRegionExtent {
@Override
public BlockState getBlock(final BlockVector3 arg0) {
if(reason != null) {
throw new FaweException(reason);
throw reason;
}else {
return null;
}
}
@Override
public BlockState getLazyBlock(final BlockVector3 arg0) {
public BlockState getBlock(int x, int y, int z) {
if(reason != null) {
throw new FaweException(reason);
throw reason;
}else {
return null;
}
}
@Override
public BaseBlock getFullBlock(int x, int y, int z) {
if(reason != null) {
throw reason;
}else {
return null;
}
}
@Override
public boolean setBiome(final BlockVector2 arg0, final BiomeType arg1) {
if(reason != null) {
throw new FaweException(reason);
throw reason;
}else {
return false;
}
@ -86,7 +98,7 @@ public class NullExtent extends FaweRegionExtent {
@Override
public boolean setBlock(final BlockVector3 arg0, final BlockStateHolder arg1) throws WorldEditException {
if(reason != null) {
throw new FaweException(reason);
throw reason;
}else {
return false;
}
@ -95,25 +107,16 @@ public class NullExtent extends FaweRegionExtent {
@Override
public boolean setBlock(int x, int y, int z, BlockStateHolder block) throws WorldEditException {
if(reason != null) {
throw new FaweException(reason);
throw reason;
}else {
return false;
}
}
@Override
public BlockState getLazyBlock(int x, int y, int z) {
if(reason != null) {
throw new FaweException(reason);
}else {
return null;
}
}
@Override
public Entity createEntity(final Location arg0, final BaseEntity arg1) {
if(reason != null) {
throw new FaweException(reason);
throw reason;
}else {
return null;
}
@ -142,7 +145,7 @@ public class NullExtent extends FaweRegionExtent {
@Override
public boolean contains(int x, int z) {
if(reason != null) {
throw new FaweException(reason);
throw reason;
}else {
return false;
}
@ -151,7 +154,7 @@ public class NullExtent extends FaweRegionExtent {
@Override
public boolean contains(int x, int y, int z) {
if(reason != null) {
throw new FaweException(reason);
throw reason;
}else {
return false;
}
@ -176,7 +179,7 @@ public class NullExtent extends FaweRegionExtent {
@Override
public int getNearestSurfaceLayer(int x, int z, int y, int minY, int maxY) {
if(reason != null) {
throw new FaweException(reason);
throw reason;
}else {
return -1;
}
@ -185,7 +188,7 @@ public class NullExtent extends FaweRegionExtent {
@Override
public int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY) {
if(reason != null) {
throw new FaweException(reason);
throw reason;
}else {
return -1;
}
@ -194,7 +197,7 @@ public class NullExtent extends FaweRegionExtent {
@Override
public int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY, int failedMin, int failedMax) {
if(reason != null) {
throw new FaweException(reason);
throw reason;
}else {
return -1;
}

View File

@ -46,13 +46,8 @@ public class PositionTransformExtent extends ResettableExtent {
}
@Override
public BlockState getLazyBlock(int x, int y, int z) {
return super.getLazyBlock(getPos(BlockVector3.at(x, y, z)));
}
@Override
public BlockState getLazyBlock(BlockVector3 position) {
return super.getLazyBlock(getPos(position));
public BlockState getBlock(int x, int y, int z) {
return super.getBlock(getPos(BlockVector3.at(x, y, z)));
}
@Override

View File

@ -2,6 +2,7 @@ package com.boydti.fawe.object.extent;
import com.boydti.fawe.config.BBC;
import com.boydti.fawe.object.FaweLimit;
import com.boydti.fawe.object.exception.FaweException;
import com.boydti.fawe.util.WEManager;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
@ -40,7 +41,7 @@ public class ProcessedWEExtent extends AbstractDelegateExtent {
return null;
}
if (!limit.MAX_ENTITIES()) {
WEManager.IMP.cancelEditSafe(this, BBC.WORLDEDIT_CANCEL_REASON_MAX_ENTITIES);
WEManager.IMP.cancelEditSafe(this, FaweException.MAX_ENTITIES);
return null;
}
return super.createEntity(location, entity);
@ -62,19 +63,19 @@ public class ProcessedWEExtent extends AbstractDelegateExtent {
}
@Override
public BlockState getLazyBlock(int x, int y, int z) {
public BlockState getBlock(int x, int y, int z) {
if (!limit.MAX_CHECKS()) {
WEManager.IMP.cancelEditSafe(this, BBC.WORLDEDIT_CANCEL_REASON_MAX_CHECKS);
WEManager.IMP.cancelEditSafe(this, FaweException.MAX_CHECKS);
return BlockTypes.AIR.getDefaultState();
} else {
return extent.getLazyBlock(x, y, z);
return extent.getBlock(x, y, z);
}
}
@Override
public BaseBlock getFullBlock(BlockVector3 pos) {
if (!limit.MAX_CHECKS()) {
WEManager.IMP.cancelEditSafe(this, BBC.WORLDEDIT_CANCEL_REASON_MAX_CHECKS);
WEManager.IMP.cancelEditSafe(this, FaweException.MAX_CHECKS);
return BlockTypes.AIR.getDefaultState().toBaseBlock();
} else {
return extent.getFullBlock(pos);
@ -87,8 +88,8 @@ public class ProcessedWEExtent extends AbstractDelegateExtent {
}
@Override
public BlockState getLazyBlock(BlockVector3 location) {
return getLazyBlock(location.getBlockX(), location.getBlockY(), location.getBlockZ());
public BlockState getBlock(BlockVector3 location) {
return getBlock(location.getBlockX(), location.getBlockY(), location.getBlockZ());
}
@Override
@ -96,18 +97,18 @@ public class ProcessedWEExtent extends AbstractDelegateExtent {
boolean hasNbt = block instanceof BaseBlock && ((BaseBlock)block).hasNbtData();
if (hasNbt) {
if (!limit.MAX_BLOCKSTATES()) {
WEManager.IMP.cancelEdit(this, BBC.WORLDEDIT_CANCEL_REASON_MAX_TILES);
WEManager.IMP.cancelEdit(this, FaweException.MAX_TILES);
return false;
} else {
if (!limit.MAX_CHANGES()) {
WEManager.IMP.cancelEdit(this, BBC.WORLDEDIT_CANCEL_REASON_MAX_CHANGES);
WEManager.IMP.cancelEdit(this, FaweException.MAX_CHANGES);
return false;
}
return extent.setBlock(x, y, z, block);
}
}
if (!limit.MAX_CHANGES()) {
WEManager.IMP.cancelEdit(this, BBC.WORLDEDIT_CANCEL_REASON_MAX_CHANGES);
WEManager.IMP.cancelEdit(this, FaweException.MAX_CHANGES);
return false;
} else {
return extent.setBlock(x, y, z, block);
@ -117,7 +118,7 @@ public class ProcessedWEExtent extends AbstractDelegateExtent {
@Override
public boolean setBiome(final BlockVector2 position, final BiomeType biome) {
if (!limit.MAX_CHANGES()) {
WEManager.IMP.cancelEditSafe(this, BBC.WORLDEDIT_CANCEL_REASON_MAX_CHANGES);
WEManager.IMP.cancelEditSafe(this, FaweException.MAX_CHANGES);
return false;
}
return super.setBiome(position, biome);

View File

@ -57,19 +57,11 @@ public class TemporalExtent extends AbstractDelegateExtent {
}
@Override
public BlockState getLazyBlock(BlockVector3 position) {
if (position.getX() == x && position.getY() == y && position.getZ() == z) {
return block.toImmutableState();
}
return super.getLazyBlock(position);
}
@Override
public BlockState getLazyBlock(int x, int y, int z) {
public BlockState getBlock(int x, int y, int z) {
if (this.x == x && this.y == y && this.z == z) {
return block.toImmutableState();
}
return super.getLazyBlock(x, y, z);
return super.getBlock(x, y, z);
}
@Override

View File

@ -1,6 +1,7 @@
package com.boydti.fawe.object.extent;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.extent.Extent;
@ -14,7 +15,8 @@ import com.sk89q.worldedit.world.block.BlockStateHolder;
public class TransformExtent extends BlockTransformExtent {
private final MutableBlockVector3 mutable = new MutableBlockVector3();
private final MutableVector3 mutable1 = new MutableVector3();
private final MutableBlockVector3 mutable2 = new MutableBlockVector3();
private BlockVector3 min;
public TransformExtent(Extent parent) {
@ -50,43 +52,34 @@ public class TransformExtent extends BlockTransformExtent {
if (min == null) {
min = pos;
}
mutable.mutX(((pos.getX() - min.getX())));
mutable.mutY(((pos.getY() - min.getY())));
mutable.mutZ(((pos.getZ() - min.getZ())));
MutableVector3 tmp = new MutableVector3(getTransform().apply(mutable.toVector3()));
tmp.mutX((tmp.getX() + min.getX()));
tmp.mutY((tmp.getY() + min.getY()));
tmp.mutZ((tmp.getZ() + min.getZ()));
return tmp.toBlockPoint();
mutable1.mutX(((pos.getX() - min.getX())));
mutable1.mutY(((pos.getY() - min.getY())));
mutable1.mutZ(((pos.getZ() - min.getZ())));
Vector3 tmp = getTransform().apply(mutable1);
mutable2.mutX((tmp.getX() + min.getX()));
mutable2.mutY((tmp.getY() + min.getY()));
mutable2.mutZ((tmp.getZ() + min.getZ()));
return mutable2;
}
public BlockVector3 getPos(int x, int y, int z) {
if (min == null) {
min = BlockVector3.at(x, y, z);
}
mutable.mutX(((x - min.getX())));
mutable.mutY(((y - min.getY())));
mutable.mutZ(((z - min.getZ())));
MutableVector3 tmp = new MutableVector3(getTransform().apply(mutable.toVector3()));
tmp.mutX((tmp.getX() + min.getX()));
tmp.mutY((tmp.getY() + min.getY()));
tmp.mutZ((tmp.getZ() + min.getZ()));
mutable1.mutX(((x - min.getX())));
mutable1.mutY(((y - min.getY())));
mutable1.mutZ(((z - min.getZ())));
Vector3 tmp = getTransform().apply(mutable1);
mutable2.mutX((tmp.getX() + min.getX()));
mutable2.mutY((tmp.getY() + min.getY()));
mutable2.mutZ((tmp.getZ() + min.getZ()));
return tmp.toBlockPoint();
}
@Override
public BlockState getLazyBlock(int x, int y, int z) {
return transform(super.getLazyBlock(getPos(x, y, z)));
}
@Override
public BlockState getLazyBlock(BlockVector3 position) {
return transform(super.getLazyBlock(getPos(position)));
}
@Override
public BlockState getBlock(BlockVector3 position) {
return transform(super.getBlock(getPos(position)));
public BlockState getBlock(int x, int y, int z) {
BlockVector3 p = getPos(x, y, z);
return transform(super.getBlock(p.getX(), p.getY(), p.getZ()));
}
@Override
@ -95,11 +88,9 @@ public class TransformExtent extends BlockTransformExtent {
}
@Override
public BiomeType getBiome(BlockVector2 position) {
mutable.mutX(position.getBlockX());
mutable.mutZ(position.getBlockZ());
mutable.mutY(0);
return super.getBiome(getPos(mutable).toBlockVector2());
public BiomeType getBiomeType(int x, int z) {
BlockVector3 p = getPos(x, 0, z);
return super.getBiomeType(p.getX(), p.getZ());
}
@Override
@ -114,10 +105,8 @@ public class TransformExtent extends BlockTransformExtent {
}
@Override
public boolean setBiome(BlockVector2 position, BiomeType biome) {
mutable.mutX(position.getBlockX());
mutable.mutZ(position.getBlockZ());
mutable.mutY(0);
return super.setBiome(getPos(mutable).toBlockVector2(), biome);
public boolean setBiome(int x, int y, int z, BiomeType biome) {
BlockVector3 p = getPos(x, y, z);
return super.setBiome(p.getX(), p.getY(), p.getZ(), biome);
}
}

View File

@ -0,0 +1,11 @@
package com.boydti.fawe.object.mask;
import com.sk89q.worldedit.function.mask.AbstractMask;
import com.sk89q.worldedit.math.BlockVector3;
public class AdjacentAnyMask2 extends AbstractMask {
@Override
public boolean test(BlockVector3 vector) {
return false;
}
}

View File

@ -19,9 +19,9 @@ public class DataMask extends AbstractExtentMask implements ResettableMask {
public boolean test(BlockVector3 vector) {
Extent extent = getExtent();
if (data != -1) {
return extent.getLazyBlock(vector).getInternalPropertiesId() == data;
return extent.getBlock(vector).getInternalPropertiesId() == data;
} else {
data = extent.getLazyBlock(vector).getInternalPropertiesId();
data = extent.getBlock(vector).getInternalPropertiesId();
return true;
}
}

View File

@ -19,9 +19,9 @@ public class IdDataMask extends AbstractExtentMask implements ResettableMask {
public boolean test(BlockVector3 vector) {
Extent extent = getExtent();
if (combined != -1) {
return extent.getLazyBlock(vector).getInternalId() == combined;
return extent.getBlock(vector).getInternalId() == combined;
} else {
combined = extent.getLazyBlock(vector).getInternalId();
combined = extent.getBlock(vector).getInternalId();
return true;
}
}

View File

@ -19,9 +19,9 @@ public class IdMask extends AbstractExtentMask implements ResettableMask {
public boolean test(BlockVector3 vector) {
Extent extent = getExtent();
if (id != -1) {
return extent.getLazyBlock(vector).getInternalBlockTypeId() == id;
return extent.getBlock(vector).getInternalBlockTypeId() == id;
} else {
id = extent.getLazyBlock(vector).getInternalBlockTypeId();
id = extent.getBlock(vector).getInternalBlockTypeId();
return true;
}
}

View File

@ -7,11 +7,8 @@ import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BlockTypes;
public class SurfaceMask extends AdjacentAnyMask {
private final transient Extent extent;
public SurfaceMask(Extent extent) {
super(getMask(extent));
this.extent = extent;
}
public static Mask getMask(Extent extent) {

View File

@ -1,7 +1,6 @@
package com.boydti.fawe.object.pattern;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.FaweCache;
import com.boydti.fawe.beta.FilterBlock;
import com.boydti.fawe.object.DataAnglePattern;
import com.boydti.fawe.util.TextureHolder;
import com.sk89q.worldedit.WorldEditException;
@ -12,14 +11,12 @@ import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType;
import java.io.IOException;
public class AngleColorPattern extends DataAnglePattern {
protected transient TextureHolder util;
protected transient TextureHolder holder;
public AngleColorPattern(Extent extent, TextureHolder util, int distance) {
public AngleColorPattern(Extent extent, TextureHolder holder, int distance) {
super(extent, distance);
this.util = util;
this.holder = holder.getTextureUtil();
}
public int getColor(int color, int slope) {
@ -34,24 +31,24 @@ public class AngleColorPattern extends DataAnglePattern {
@Override
public BaseBlock apply(BlockVector3 position) {
BaseBlock block = extent.getFullBlock(position);
int slope = getSlope(block, position);
int slope = getSlope(block, position, extent);
if (slope == -1) return block;
int color = util.getTextureUtil().getColor(block.getBlockType());
int color = holder.getTextureUtil().getColor(block.getBlockType());
if (color == 0) return block;
int newColor = getColor(color, slope);
return util.getTextureUtil().getNearestBlock(newColor).getDefaultState().toBaseBlock();
return holder.getTextureUtil().getNearestBlock(newColor).getDefaultState().toBaseBlock();
}
@Override
public int getSlope(BlockStateHolder block, BlockVector3 vector) {
int slope = super.getSlope(block, vector);
public int getSlope(BlockStateHolder block, BlockVector3 vector, Extent extent) {
int slope = super.getSlope(block, vector, extent);
if (slope != -1) {
int x = vector.getBlockX();
int y = vector.getBlockY();
int z = vector.getBlockZ();
int height = extent.getNearestSurfaceTerrainBlock(x, z, y, 0, maxY);
if (height > 0) {
BlockStateHolder below = extent.getLazyBlock(x, height - 1, z);
BlockStateHolder below = extent.getBlock(x, height - 1, z);
if (!below.getBlockType().getMaterial().isMovementBlocker()) {
return Integer.MAX_VALUE;
}
@ -61,20 +58,15 @@ public class AngleColorPattern extends DataAnglePattern {
}
@Override
public boolean apply(Extent extent, BlockVector3 setPosition, BlockVector3 getPosition) throws WorldEditException {
BlockStateHolder block = extent.getBlock(getPosition);
int slope = getSlope(block, getPosition);
public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException {
BlockStateHolder block = get.getBlock(extent);
int slope = getSlope(block, get, extent);
if (slope == -1) return false;
int color = util.getTextureUtil().getColor(block.getBlockType());
int color = holder.getTextureUtil().getColor(block.getBlockType());
if (color == 0) return false;
int newColor = getColor(color, slope);
BlockType newBlock = util.getTextureUtil().getNearestBlock(newColor);
BlockType newBlock = holder.getTextureUtil().getNearestBlock(newColor);
if (newBlock == null) return false;
return extent.setBlock(setPosition, newBlock.getDefaultState());
}
private void readObject(java.io.ObjectInputStream stream) throws IOException, ClassNotFoundException {
stream.defaultReadObject();
util = Fawe.get().getCachedTextureUtil(true, 0, 100);
return set.setBlock(extent, newBlock.getDefaultState());
}
}

View File

@ -1,19 +1,14 @@
package com.boydti.fawe.object.pattern;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.util.TextureHolder;
import com.boydti.fawe.util.TextureUtil;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
import java.awt.Color;
import java.io.IOException;
public class AverageColorPattern extends AbstractExtentPattern {
private transient TextureHolder holder;
@ -35,19 +30,14 @@ public class AverageColorPattern extends AbstractExtentPattern {
}
@Override
public boolean apply(Extent extent, BlockVector3 setPosition, BlockVector3 getPosition) throws WorldEditException {
BlockType blockType = extent.getBlockType(getPosition);
public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException {
BlockType blockType = get.getBlock(extent).getBlockType();
TextureUtil util = holder.getTextureUtil();
int currentColor = util.getColor(blockType);
if (currentColor == 0) return false;
int newColor = util.averageColor(currentColor, color);
BlockType newBlock = util.getNearestBlock(newColor);
if (newBlock == blockType) return false;
return extent.setBlock(setPosition, newBlock.getDefaultState());
}
private void readObject(java.io.ObjectInputStream stream) throws IOException, ClassNotFoundException {
stream.defaultReadObject();
holder = Fawe.get().getCachedTextureUtil(true, 0, 100);
return set.setBlock(extent, newBlock.getDefaultState());
}
}

View File

@ -1,5 +1,6 @@
package com.boydti.fawe.object.pattern;
import com.boydti.fawe.beta.FilterBlock;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
@ -10,7 +11,6 @@ import com.sk89q.worldedit.world.biome.BiomeType;
import java.io.IOException;
public class BiomePattern extends ExistingPattern {
private transient MutableBlockVector2 mutable = new MutableBlockVector2();
private final BiomeType biome;
public BiomePattern(Extent extent, BiomeType biome) {
@ -24,8 +24,8 @@ public class BiomePattern extends ExistingPattern {
}
@Override
public boolean apply(Extent extent, BlockVector3 set, BlockVector3 getPosition) throws WorldEditException {
return extent.setBiome(set.getBlockX(), set.getBlockY(), set.getBlockZ(), biome);
public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException {
return set.setBiome(extent, biome);
}
public class BiomePatternException extends RuntimeException {
@ -45,9 +45,4 @@ public class BiomePattern extends ExistingPattern {
return this;
}
}
private void readObject(java.io.ObjectInputStream stream) throws IOException, ClassNotFoundException {
stream.defaultReadObject();
mutable = new MutableBlockVector2();
}
}

View File

@ -1,6 +1,7 @@
package com.boydti.fawe.object.pattern;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.beta.FilterBlock;
import com.boydti.fawe.object.FawePlayer;
import com.boydti.fawe.object.collection.LocalBlockVectorSet;
import com.boydti.fawe.util.FaweTimer;
@ -17,17 +18,18 @@ import java.io.IOException;
import java.util.UUID;
public class BufferedPattern extends AbstractPattern implements ResettablePattern {
protected transient LocalBlockVectorSet set = new LocalBlockVectorSet();
protected transient FaweTimer timer;
protected transient long[] actionTime;
protected final LocalBlockVectorSet set = new LocalBlockVectorSet();
protected final FaweTimer timer;
protected final long[] actionTime;
protected final Pattern pattern;
protected final UUID uuid;
public BufferedPattern(FawePlayer fp, Pattern parent) {
this.uuid = fp.getUUID();
this.actionTime = fp.getMeta("lastActionTime");
if (actionTime == null) fp.setMeta("lastActionTime", actionTime = new long[2]);
long[] tmp = fp.getMeta("lastActionTime");
if (tmp == null) fp.setMeta("lastActionTime", tmp = new long[2]);
actionTime = tmp;
this.pattern = parent;
this.timer = Fawe.get().getTimer();
}
@ -38,16 +40,12 @@ public class BufferedPattern extends AbstractPattern implements ResettablePatter
}
@Override
public boolean apply(Extent extent, BlockVector3 setPosition, BlockVector3 getPosition) throws WorldEditException {
long now = timer.getTick();
try {
if (!set(setPosition)) {
return false;
}
return pattern.apply(extent, setPosition, getPosition);
} catch (UnsupportedOperationException ignore) {
public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException {
actionTime[1] = timer.getTick();
if (!set(get)) {
return false;
}
return false;
return pattern.apply(extent, get, set);
}
public boolean set(BlockVector3 pos) {
@ -63,17 +61,4 @@ public class BufferedPattern extends AbstractPattern implements ResettablePatter
actionTime[1] = actionTime[0];
actionTime[0] = now;
}
private void readObject(java.io.ObjectInputStream stream) throws IOException, ClassNotFoundException {
stream.defaultReadObject();
set = new LocalBlockVectorSet();
timer = Fawe.get().getTimer();
FawePlayer fp = Fawe.get().getCachedPlayer(uuid);
if (fp != null) {
this.actionTime = fp.getMeta("lastActionTime");
if (actionTime == null) fp.setMeta("lastActionTime", actionTime = new long[2]);
} else {
actionTime = new long[2];
}
}
}

View File

@ -1,14 +1,14 @@
package com.boydti.fawe.object.pattern;
import com.boydti.fawe.FaweCache;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.boydti.fawe.beta.DelegateFilterBlock;
import com.boydti.fawe.beta.FilterBlock;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector3;
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.BlockTypes;
import static com.google.common.base.Preconditions.checkNotNull;
@ -25,6 +25,24 @@ public class DataPattern extends AbstractExtentPattern {
public BaseBlock apply(BlockVector3 position) {
BaseBlock oldBlock = getExtent().getFullBlock(position);
BaseBlock newBlock = pattern.apply(position);
return oldBlock.withPropertyId(newBlock.getInternalPropertiesId()).toBaseBlock();
return oldBlock.toBlockState().withProperties(newBlock.toBlockState()).toBaseBlock(newBlock.getNbtData());
}
@Override
public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException {
BaseBlock oldBlock = get.getFullBlock(extent);
BaseBlock newBlock = pattern.apply(get);
BlockState oldState = oldBlock.toBlockState();
BlockState newState = oldState.withProperties(newBlock.toBlockState());
if (newState != oldState) {
if (oldBlock.hasNbtData()) {
set.setFullBlock(extent, newState.toBaseBlock(oldBlock.getNbtData()));
} else {
set.setBlock(extent, newState);
}
return true;
}
return false;
}
}

View File

@ -1,21 +1,16 @@
package com.boydti.fawe.object.pattern;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.util.TextureHolder;
import com.boydti.fawe.util.TextureUtil;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.pattern.AbstractPattern;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType;
import java.io.IOException;
public class DesaturatePattern extends AbstractPattern {
private transient TextureHolder holder;
private final TextureHolder holder;
private final Extent extent;
private final double value;
@ -29,7 +24,11 @@ public class DesaturatePattern extends AbstractPattern {
public BaseBlock apply(BlockVector3 position) {
BlockType block = extent.getBlockType(position);
TextureUtil util = holder.getTextureUtil();
int color = util.getColor(block);
int color = getColor(util.getColor(block));
return util.getNearestBlock(color).getDefaultState().toBaseBlock();
}
public int getColor(int color) {
int r = (color >> 16) & 0xFF;
int g = (color >> 8) & 0xFF;
int b = (color >> 0) & 0xFF;
@ -39,35 +38,22 @@ public class DesaturatePattern extends AbstractPattern {
int green = (int) (g + value * (l - g));
int blue = (int) (b + value * (l - b));
int newColor = (alpha << 24) + (red << 16) + (green << 8) + (blue << 0);
return util.getNearestBlock(newColor).getDefaultState().toBaseBlock();
return newColor;
}
@Override
public boolean apply(Extent extent, BlockVector3 setPosition, BlockVector3 getPosition) throws WorldEditException {
BlockType block = extent.getBlockType(getPosition);
public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException {
BlockType type = get.getBlock(extent).getBlockType();
TextureUtil util = holder.getTextureUtil();
int color = util.getColor(block);
int r = (color >> 16) & 0xFF;
int g = (color >> 8) & 0xFF;
int b = (color >> 0) & 0xFF;
int alpha = (color >> 24) & 0xFF;
double l = 0.3f * r + 0.6f * g + 0.1f * b;
int red = (int) (r + value * (l - r));
int green = (int) (g + value * (l - g));
int blue = (int) (b + value * (l - b));
int newColor = (alpha << 24) + (red << 16) + (green << 8) + (blue << 0);
int color = util.getColor(type);
int newColor = getColor(color);
if (newColor == color) {
return false;
}
BlockType newBlock = util.getNextNearestBlock(newColor);
if (block.equals(newBlock)) {
BlockType newType = util.getNextNearestBlock(newColor);
if (type.equals(newType)) {
return false;
}
return extent.setBlock(setPosition, newBlock.getDefaultState());
}
private void readObject(java.io.ObjectInputStream stream) throws IOException, ClassNotFoundException {
stream.defaultReadObject();
holder = Fawe.get().getCachedTextureUtil(true, 0, 100);
return set.setBlock(extent, newType.getDefaultState());
}
}

View File

@ -1,12 +1,10 @@
package com.boydti.fawe.object.pattern;
import com.boydti.fawe.beta.FilterBlock;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockTypes;
public class ExistingPattern extends AbstractExtentPattern {
public ExistingPattern(Extent extent) {
@ -19,10 +17,10 @@ public class ExistingPattern extends AbstractExtentPattern {
}
@Override
public boolean apply(Extent extent, BlockVector3 set, BlockVector3 get) throws WorldEditException {
if (set.equals(get)) {
public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException {
if (set == get || set.equals(get)) {
return false;
}
return extent.setBlock(set, extent.getBlock(get));
return set.setFullBlock(extent, get.getFullBlock(extent));
}
}

View File

@ -22,9 +22,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
* greater than {@code 0}.</p>
*/
public class ExpressionPattern extends AbstractPattern {
public String input;
private transient Expression expression;
private final Expression expression;
/**
* Create a new instance.
@ -34,7 +32,6 @@ public class ExpressionPattern extends AbstractPattern {
*/
public ExpressionPattern(String input) throws ExpressionException {
checkNotNull(input);
this.input = input;
this.expression = Expression.compile(input, "x", "y", "z");
}
@ -64,13 +61,4 @@ public class ExpressionPattern extends AbstractPattern {
throw e;
}
}
private void readObject(java.io.ObjectInputStream stream) throws IOException, ClassNotFoundException {
stream.defaultReadObject();
try {
this.expression = Expression.compile(input, "x", "y", "z");
} catch (ExpressionException e) {
e.printStackTrace();
}
}
}

View File

@ -36,9 +36,8 @@ public class FullClipboardPattern extends AbstractExtentPattern {
}
@Override
public boolean apply(Extent extent, BlockVector3 setPosition, BlockVector3 getPosition) throws WorldEditException {
Region region = clipboard.getRegion();
ForwardExtentCopy copy = new ForwardExtentCopy(clipboard, clipboard.getRegion(), clipboard.getOrigin(), extent, setPosition);
public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException {
ForwardExtentCopy copy = new ForwardExtentCopy(clipboard, clipboard.getRegion(), clipboard.getOrigin(), extent, set);
copy.setSourceMask(new ExistingBlockMask(clipboard));
Operations.completeBlindly(copy);
return true;

View File

@ -1,5 +1,6 @@
package com.boydti.fawe.object.pattern;
import com.boydti.fawe.beta.FilterBlock;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
@ -27,11 +28,11 @@ public class Linear2DBlockPattern extends AbstractPattern {
}
@Override
public boolean apply(Extent extent, BlockVector3 set, BlockVector3 get) throws WorldEditException {
public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException {
int index = (get.getBlockX() + get.getBlockZ()) % patternsArray.length;
if (index < 0) {
index += patternsArray.length;
}
return patternsArray[index].apply(extent, set, get);
return patternsArray[index].apply(extent, get, set);
}
}

View File

@ -1,5 +1,6 @@
package com.boydti.fawe.object.pattern;
import com.boydti.fawe.beta.FilterBlock;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
@ -27,11 +28,11 @@ public class Linear3DBlockPattern extends AbstractPattern {
}
@Override
public boolean apply(Extent extent, BlockVector3 set, BlockVector3 get) throws WorldEditException {
public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException {
int index = (get.getBlockX() + get.getBlockY() + get.getBlockZ()) % patternsArray.length;
if (index < 0) {
index += patternsArray.length;
}
return patternsArray[index].apply(extent, set, get);
return patternsArray[index].apply(extent, get, set);
}
}

View File

@ -27,11 +27,11 @@ public class LinearBlockPattern extends AbstractPattern implements ResettablePat
}
@Override
public boolean apply(Extent extent, BlockVector3 set, BlockVector3 get) throws WorldEditException {
public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException {
if (index == patternsArray.length) {
index = 0;
}
return patternsArray[index++].apply(extent, set, get);
return patternsArray[index++].apply(extent, get, set);
}
@Override

View File

@ -1,5 +1,7 @@
package com.boydti.fawe.object.pattern;
import com.boydti.fawe.beta.FilterBlock;
import com.boydti.fawe.beta.SingleFilterBlock;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
@ -12,32 +14,30 @@ import com.sk89q.worldedit.world.block.BlockStateHolder;
public class MaskedPattern extends AbstractPattern {
private final PatternExtent patternExtent;
private final Pattern secondaryPattern;
private final Pattern primary;
private final Pattern secondary;
private Mask mask;
public MaskedPattern(Mask mask, PatternExtent primary, Pattern secondary) {
public MaskedPattern(Mask mask, Pattern primary, Pattern secondary) {
this.mask = mask;
this.patternExtent = primary;
this.secondaryPattern = secondary;
this.primary = primary;
this.secondary = secondary;
}
@Override
public BaseBlock apply(BlockVector3 position) {
patternExtent.setTarget(position);
if (mask.test(position)) {
return patternExtent.getAndResetTarget().toBaseBlock();
return primary.apply(position);
}
return secondaryPattern.apply(position);
return secondary.apply(position);
}
@Override
public boolean apply(Extent extent, BlockVector3 set, BlockVector3 get) throws WorldEditException {
patternExtent.setTarget(get);
public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException {
if (mask.test(get)) {
return patternExtent.getAndResetTarget(extent, set, get);
return primary.apply(extent, get, set);
}
return secondaryPattern.apply(extent, set, get);
return secondary.apply(extent, get, set);
}
}

Some files were not shown because too many files have changed in this diff Show More