mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-06-11 20:13:55 +00:00
.
This commit is contained in:
@ -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");
|
||||
}
|
||||
|
||||
}
|
@ -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
|
||||
*
|
||||
@ -175,6 +178,11 @@ public class Fawe {
|
||||
WEManager.IMP.managers.add(new PlotSquaredFeature());
|
||||
Fawe.debug("Plugin 'PlotSquared' found. Using it now.");
|
||||
} catch (Throwable ignored) {}
|
||||
try {
|
||||
imp().startMetrics();
|
||||
} catch (Throwable ignored) {
|
||||
debug(ignored.getMessage());
|
||||
}
|
||||
}, 0);
|
||||
|
||||
TaskManager.IMP.repeat(timer, 1);
|
||||
@ -183,6 +191,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;
|
||||
}
|
||||
|
@ -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;
|
||||
@ -17,6 +18,7 @@ import com.boydti.fawe.util.SetQueue;
|
||||
import com.boydti.fawe.util.TaskManager;
|
||||
import com.boydti.fawe.util.WEManager;
|
||||
import com.boydti.fawe.wrappers.WorldWrapper;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
@ -36,24 +38,18 @@ import com.sk89q.worldedit.internal.registry.InputParser;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldedit.world.AbstractWorld;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* The FaweAPI class offers a few useful functions.<br>
|
||||
@ -262,7 +258,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) {
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
@ -115,7 +292,7 @@ public class FaweCache {
|
||||
} else if (value instanceof String) {
|
||||
return asTag((String) value);
|
||||
} else if (value instanceof Map) {
|
||||
return asTag((Map) value);
|
||||
return asTag((Map<String, Object>) value);
|
||||
} else if (value instanceof Collection) {
|
||||
return asTag((Collection) value);
|
||||
} else if (value instanceof Object[]) {
|
||||
@ -153,7 +330,7 @@ public class FaweCache {
|
||||
}
|
||||
|
||||
public static ListTag asTag(Object... values) {
|
||||
Class clazz = null;
|
||||
Class<? extends Tag> clazz = null;
|
||||
List<Tag> list = new ArrayList<>(values.length);
|
||||
for (Object value : values) {
|
||||
Tag tag = asTag(value);
|
||||
@ -167,7 +344,7 @@ public class FaweCache {
|
||||
}
|
||||
|
||||
public static ListTag asTag(Collection values) {
|
||||
Class clazz = null;
|
||||
Class<? extends Tag> clazz = null;
|
||||
List<Tag> list = new ArrayList<>(values.size());
|
||||
for (Object value : values) {
|
||||
Tag tag = asTag(value);
|
||||
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -32,9 +32,9 @@ public class FaweVersion {
|
||||
|
||||
@Override public String toString() {
|
||||
if (hash == 0 && build == 0) {
|
||||
return "FastAsyncWorldEdit-1.13-NoVer-SNAPSHOT";
|
||||
return "FastAsyncWorldEdit-1.14-NoVer-SNAPSHOT";
|
||||
} else {
|
||||
return "FastAsyncWorldEdit-1.13" + build;
|
||||
return "FastAsyncWorldEdit-1.14" + build;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
};
|
||||
}
|
@ -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);
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.boydti.fawe.beta;
|
||||
|
||||
public class DelegateFilter<T extends Filter> implements IDelegateFilter {
|
||||
private final Filter parent;
|
||||
|
||||
public DelegateFilter(T parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
@Override
|
||||
public T getParent() {
|
||||
return (T) parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Filter newInstance(Filter other) {
|
||||
return new DelegateFilter(other);
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
@ -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() {
|
||||
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package com.boydti.fawe.beta;
|
||||
|
||||
public interface FilterBlockMask {
|
||||
boolean applyBlock(final FilterBlock block);
|
||||
}
|
192
worldedit-core/src/main/java/com/boydti/fawe/beta/Flood.java
Normal file
192
worldedit-core/src/main/java/com/boydti/fawe/beta/Flood.java
Normal file
@ -0,0 +1,192 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
@ -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);
|
||||
}
|
@ -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() {
|
||||
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
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;
|
||||
}
|
||||
|
||||
default Filter newInstance(Filter other) {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -0,0 +1,104 @@
|
||||
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;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
IChunkGet getCachedGet(int X, int Z, Supplier<IChunkGet> supplier);
|
||||
|
||||
/**
|
||||
* Get the IChunk at a position (and cache it if it's not already)
|
||||
* @param X
|
||||
* @param Z
|
||||
* @return IChunk
|
||||
*/
|
||||
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 getWorld().getMinimumPoint();
|
||||
}
|
||||
|
||||
@Override
|
||||
default BlockVector3 getMaximumPoint() {
|
||||
return 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();
|
||||
}
|
@ -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());
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
@ -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));
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package com.boydti.fawe.beta.filters;
|
||||
|
||||
import com.boydti.fawe.beta.FilterBlock;
|
||||
|
||||
public class CountFilter extends ForkedFilter<CountFilter> {
|
||||
private int total;
|
||||
|
||||
public CountFilter() {
|
||||
super(null);
|
||||
}
|
||||
|
||||
private CountFilter(CountFilter root) {
|
||||
super(root);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CountFilter init() {
|
||||
return new CountFilter(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void join(CountFilter filter) {
|
||||
this.total += filter.getTotal();
|
||||
}
|
||||
|
||||
/*
|
||||
Implementation
|
||||
*/
|
||||
|
||||
@Override
|
||||
public final void applyBlock(final FilterBlock block) {
|
||||
total++;
|
||||
}
|
||||
|
||||
public int getTotal() {
|
||||
return total;
|
||||
}
|
||||
}
|
@ -0,0 +1,107 @@
|
||||
package com.boydti.fawe.beta.filters;
|
||||
|
||||
import com.boydti.fawe.beta.FilterBlock;
|
||||
import com.boydti.fawe.config.BBC;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.function.mask.ABlockMask;
|
||||
import com.sk89q.worldedit.util.Countable;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class DistrFilter extends ForkedFilter<DistrFilter> {
|
||||
private final int[] counter = new int[BlockTypes.states.length];
|
||||
|
||||
public DistrFilter() {
|
||||
super(null);
|
||||
}
|
||||
|
||||
private DistrFilter(DistrFilter root) {
|
||||
super(root);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DistrFilter init() {
|
||||
return new DistrFilter(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void join(DistrFilter 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 int getTotal(ABlockMask mask) {
|
||||
int total = 0;
|
||||
for (int i = 0; i < counter.length; i++) {
|
||||
int value = counter[i];
|
||||
if (value != 0 && mask.test(BlockTypes.states[i])) {
|
||||
total += value;
|
||||
}
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
public int getTotal() {
|
||||
int total = 0;
|
||||
for (int value : counter) total += value;
|
||||
return total;
|
||||
}
|
||||
|
||||
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 List<Countable<BlockType>> getTypeDistribution() {
|
||||
final List<Countable<BlockType>> distribution = new ArrayList<>();
|
||||
int[] typeCounter = new int[BlockTypes.values.length];
|
||||
for (int i = 0; i < counter.length; i++) {
|
||||
final int count = counter[i];
|
||||
if (count != 0) {
|
||||
BlockState state = BlockTypes.states[i];
|
||||
typeCounter[state.getBlockType().getInternalId()] += count;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < typeCounter.length; i++) {
|
||||
final int count = typeCounter[i];
|
||||
if (count != 0) {
|
||||
distribution.add(new Countable<>(BlockTypes.values[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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package com.boydti.fawe.beta.implementation;
|
||||
|
||||
import com.boydti.fawe.beta.IQueueExtent;
|
||||
|
||||
public interface IQueueWrapper {
|
||||
default IQueueExtent wrapQueue(IQueueExtent queue) {
|
||||
return queue;
|
||||
}
|
||||
}
|
@ -0,0 +1,152 @@
|
||||
package com.boydti.fawe.beta.implementation;
|
||||
|
||||
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.filters.CountFilter;
|
||||
import com.boydti.fawe.beta.filters.DistrFilter;
|
||||
import com.boydti.fawe.config.Settings;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.extent.AbstractDelegateExtent;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.util.Countable;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ForkJoinTask;
|
||||
|
||||
public class MultiThreadedQueue extends AbstractDelegateExtent implements IQueueWrapper {
|
||||
private final World world;
|
||||
private final QueueHandler handler;
|
||||
|
||||
protected MultiThreadedQueue(QueueHandler handler, World world) {
|
||||
super(handler.getQueue(world));
|
||||
this.world = world;
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
public IQueueExtent getQueue() {
|
||||
return handler.getQueue(this.world);
|
||||
}
|
||||
|
||||
public <T extends Filter> T apply(final Region region, final T filter) {
|
||||
// The chunks positions to iterate over
|
||||
final Set<BlockVector2> chunks = region.getChunks();
|
||||
final Iterator<BlockVector2> chunksIter = chunks.iterator();
|
||||
|
||||
// Get a pool, to operate on the chunks in parallel
|
||||
final int size = Math.min(chunks.size(), Settings.IMP.QUEUE.PARALLEL_THREADS);
|
||||
final ForkJoinTask[] tasks = new ForkJoinTask[size];
|
||||
for (int i = 0; i < size; i++) {
|
||||
tasks[i] = handler.submit(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final Filter newFilter = filter.fork();
|
||||
// Create a chunk that we will reuse/reset for each operation
|
||||
final IQueueExtent queue = wrapQueue(getQueue());
|
||||
synchronized (queue) {
|
||||
ChunkFilterBlock block = null;
|
||||
|
||||
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();
|
||||
return filter;
|
||||
}
|
||||
|
||||
public int getChanges() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int countBlocks(final Region region, final Mask searchMask) {
|
||||
return
|
||||
// Apply a filter over a region
|
||||
apply(region, searchMask
|
||||
.toFilter(new CountFilter())) // Adapt the mask to a filter which counts
|
||||
.getParent() // Get the counter of this mask
|
||||
.getTotal(); // Get the total from the counter
|
||||
}
|
||||
|
||||
@Override
|
||||
public <B extends BlockStateHolder<B>> int setBlocks(Region region, B block) throws MaxChangedBlocksException {
|
||||
apply(region, block);
|
||||
return getChanges();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int setBlocks(Region region, Pattern pattern) throws MaxChangedBlocksException {
|
||||
apply(region, pattern);
|
||||
return getChanges();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int setBlocks(Set<BlockVector3> vset, Pattern pattern) {
|
||||
if (vset instanceof Region) {
|
||||
setBlocks((Region) vset, pattern);
|
||||
}
|
||||
for (BlockVector3 blockVector3 : vset) {
|
||||
pattern.apply(this, blockVector3, blockVector3);
|
||||
}
|
||||
return getChanges();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int replaceBlocks(Region region, Mask mask, Pattern pattern) throws MaxChangedBlocksException {
|
||||
apply(region, mask.toFilter(pattern));
|
||||
return getChanges();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Countable<BlockState>> getBlockDistributionWithData(Region region) {
|
||||
return apply(region, new DistrFilter()).getDistribution();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Countable<BlockType>> getBlockDistribution(Region region) {
|
||||
return apply(region, new DistrFilter()).getTypeDistribution();
|
||||
}
|
||||
}
|
@ -0,0 +1,210 @@
|
||||
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.SetQueue;
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to calculate elapsed time in milliseconds and ensure block placement doesn't lag the server
|
||||
*/
|
||||
private long last;
|
||||
private long allocate = 50;
|
||||
private double targetTPS = 18;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (!Fawe.isMainThread()) {
|
||||
throw new IllegalStateException("Not main thread");
|
||||
}
|
||||
if (!syncTasks.isEmpty()) {
|
||||
long now = System.currentTimeMillis();
|
||||
targetTPS = 18 - Math.max(Settings.IMP.QUEUE.EXTRA_TIME_MS * 0.05, 0);
|
||||
long diff = (50 + this.last) - (this.last = now);
|
||||
long absDiff = Math.abs(diff);
|
||||
if (diff == 0) {
|
||||
allocate = Math.min(50, allocate + 1);
|
||||
} else if (diff < 0) {
|
||||
allocate = Math.max(5, allocate + diff);
|
||||
} else if (!Fawe.get().getTimer().isAbove(targetTPS)) {
|
||||
allocate = Math.max(5, allocate - 1);
|
||||
}
|
||||
long currentAllocate = allocate - absDiff;
|
||||
|
||||
if (!MemUtil.isMemoryFree()) {
|
||||
// TODO reduce mem usage
|
||||
}
|
||||
|
||||
long taskAllocate = currentAllocate;
|
||||
boolean wait = false;
|
||||
do {
|
||||
Runnable task = syncTasks.poll();
|
||||
if (task == null) {
|
||||
if (wait) {
|
||||
synchronized (syncTasks) {
|
||||
try {
|
||||
syncTasks.wait(1);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
task = syncTasks.poll();
|
||||
wait = false;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (task != null) {
|
||||
task.run();
|
||||
wait = true;
|
||||
}
|
||||
} while (System.currentTimeMillis() - now < taskAllocate);
|
||||
}
|
||||
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 ForkJoinTask submit(final Runnable call) {
|
||||
return forkJoinPoolPrimary.submit(call);
|
||||
}
|
||||
|
||||
public <T> Future<T> sync(final Runnable run, final T value) {
|
||||
final FutureTask<T> result = new FutureTask<>(run, value);
|
||||
syncTasks.add(result);
|
||||
notifySync();
|
||||
return result;
|
||||
}
|
||||
|
||||
public <T> Future<T> sync(final Runnable run) {
|
||||
final FutureTask<T> result = new FutureTask<>(run, null);
|
||||
syncTasks.add(result);
|
||||
notifySync();
|
||||
return result;
|
||||
}
|
||||
|
||||
public <T> Future<T> sync(final Callable<T> call) {
|
||||
final FutureTask<T> result = new FutureTask<>(call);
|
||||
syncTasks.add(result);
|
||||
notifySync();
|
||||
return result;
|
||||
}
|
||||
|
||||
private void notifySync() {
|
||||
synchronized (syncTasks) {
|
||||
syncTasks.notifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -0,0 +1,254 @@
|
||||
package com.boydti.fawe.beta.implementation;
|
||||
|
||||
import com.boydti.fawe.Fawe;
|
||||
import com.boydti.fawe.beta.IChunk;
|
||||
import com.boydti.fawe.beta.IChunkGet;
|
||||
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 java.util.function.Supplier;
|
||||
|
||||
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 IChunkGet getCachedGet(int X, int Z, Supplier<IChunkGet> supplier) {
|
||||
return cache.get(MathMan.pairInt(X, Z), supplier);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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];
|
||||
}
|
||||
};
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -0,0 +1,313 @@
|
||||
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) {
|
||||
IChunkGet newGet = extent.getCachedGet(X, Z, this);
|
||||
if (newGet != null) {
|
||||
return newGet;
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
};
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -4,9 +4,9 @@ import com.boydti.fawe.Fawe;
|
||||
import com.boydti.fawe.object.FawePlayer;
|
||||
import com.boydti.fawe.object.extent.NullExtent;
|
||||
import com.boydti.fawe.object.extent.ResettableExtent;
|
||||
import com.boydti.fawe.util.MainUtil;
|
||||
import com.boydti.fawe.util.TextureUtil;
|
||||
import com.boydti.fawe.util.image.ImageUtil;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
@ -30,23 +30,20 @@ import com.sk89q.worldedit.util.command.binding.Text;
|
||||
import com.sk89q.worldedit.util.command.binding.Validate;
|
||||
import com.sk89q.worldedit.util.command.parametric.ArgumentStack;
|
||||
import com.sk89q.worldedit.util.command.parametric.BindingBehavior;
|
||||
import com.sk89q.worldedit.util.command.parametric.BindingHelper;
|
||||
import com.sk89q.worldedit.util.command.parametric.BindingMatch;
|
||||
import com.sk89q.worldedit.util.command.parametric.ParameterException;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class FawePrimitiveBinding {
|
||||
@BindingMatch(type = {Long.class, long.class},
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1,
|
||||
provideModifiers = true)
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1,
|
||||
provideModifiers = true)
|
||||
public Long getLong(ArgumentStack context, Annotation[] modifiers) throws ParameterException {
|
||||
try {
|
||||
Long v = Long.parseLong(context.next());
|
||||
@ -80,11 +77,15 @@ public class FawePrimitiveBinding {
|
||||
public class ImageUri {
|
||||
public final URI uri;
|
||||
private BufferedImage image;
|
||||
public ImageUri(URI uri) {
|
||||
|
||||
ImageUri(URI uri) {
|
||||
this.uri = uri;
|
||||
}
|
||||
|
||||
public BufferedImage load() throws ParameterException {
|
||||
if (image != null) return image;
|
||||
if (image != null) {
|
||||
return image;
|
||||
}
|
||||
return image = ImageUtil.load(uri);
|
||||
}
|
||||
}
|
||||
@ -105,7 +106,9 @@ public class FawePrimitiveBinding {
|
||||
)
|
||||
public TextureUtil getTexture(ArgumentStack context) {
|
||||
Actor actor = context.getContext().getLocals().get(Actor.class);
|
||||
if (actor == null) return Fawe.get().getCachedTextureUtil(true, 0, 100);
|
||||
if (actor == null) {
|
||||
return Fawe.get().getCachedTextureUtil(true, 0, 100);
|
||||
}
|
||||
LocalSession session = WorldEdit.getInstance().getSessionManager().get(actor);
|
||||
return session.getTextureUtil();
|
||||
}
|
||||
@ -117,12 +120,20 @@ public class FawePrimitiveBinding {
|
||||
)
|
||||
public Extent getExtent(ArgumentStack context) throws ParameterException {
|
||||
Extent extent = context.getContext().getLocals().get(EditSession.class);
|
||||
if (extent != null) return extent;
|
||||
if (extent != null) {
|
||||
return extent;
|
||||
}
|
||||
extent = Request.request().getExtent();
|
||||
if (extent != null) return extent;
|
||||
if (extent != null) {
|
||||
return extent;
|
||||
}
|
||||
Actor actor = context.getContext().getLocals().get(Actor.class);
|
||||
if (actor == null) throw new ParameterException("No player to get a session for");
|
||||
if (!(actor instanceof Player)) throw new ParameterException("Caller is not a player");
|
||||
if (actor == null) {
|
||||
throw new ParameterException("No player to get a session for");
|
||||
}
|
||||
if (!(actor instanceof Player)) {
|
||||
throw new ParameterException("Caller is not a player");
|
||||
}
|
||||
LocalSession session = WorldEdit.getInstance().getSessionManager().get(actor);
|
||||
EditSession editSession = session.createEditSession((Player) actor);
|
||||
editSession.enableQueue();
|
||||
@ -139,7 +150,7 @@ public class FawePrimitiveBinding {
|
||||
* @throws ParameterException on other error
|
||||
*/
|
||||
@BindingMatch(type = FawePlayer.class,
|
||||
behavior = BindingBehavior.PROVIDES)
|
||||
behavior = BindingBehavior.PROVIDES)
|
||||
public FawePlayer getFawePlayer(ArgumentStack context) throws ParameterException, InputParseException {
|
||||
Actor sender = context.getContext().getLocals().get(Actor.class);
|
||||
if (sender == null) {
|
||||
@ -157,10 +168,12 @@ public class FawePrimitiveBinding {
|
||||
* @throws ParameterException on other error
|
||||
*/
|
||||
@BindingMatch(type = ResettableExtent.class,
|
||||
behavior = BindingBehavior.PROVIDES)
|
||||
behavior = BindingBehavior.PROVIDES)
|
||||
public ResettableExtent getResettableExtent(ArgumentStack context) throws ParameterException, InputParseException {
|
||||
String input = context.next();
|
||||
if (input.equalsIgnoreCase("#null")) return new NullExtent();
|
||||
if (input.equalsIgnoreCase("#null")) {
|
||||
return new NullExtent();
|
||||
}
|
||||
DefaultTransformParser parser = Fawe.get().getTransformParser();
|
||||
Actor actor = context.getContext().getLocals().get(Actor.class);
|
||||
ParserContext parserContext = new ParserContext();
|
||||
@ -178,17 +191,17 @@ public class FawePrimitiveBinding {
|
||||
/**
|
||||
* Gets a type from a {@link ArgumentStack}.
|
||||
*
|
||||
* @param context the context
|
||||
* @param text the text annotation
|
||||
* @param context the context
|
||||
* @param text the text annotation
|
||||
* @param modifiers a list of modifiers
|
||||
* @return the requested type
|
||||
* @throws ParameterException on error
|
||||
*/
|
||||
@BindingMatch(classifier = Text.class,
|
||||
type = String.class,
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = -1,
|
||||
provideModifiers = true)
|
||||
type = String.class,
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = -1,
|
||||
provideModifiers = true)
|
||||
public String getText(ArgumentStack context, Text text, Annotation[] modifiers)
|
||||
throws ParameterException {
|
||||
String v = context.remaining();
|
||||
@ -196,9 +209,9 @@ public class FawePrimitiveBinding {
|
||||
return v;
|
||||
}
|
||||
|
||||
@BindingMatch(type = { Expression.class },
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1)
|
||||
@BindingMatch(type = {Expression.class},
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1)
|
||||
public Expression getExpression(ArgumentStack context) throws ParameterException, ExpressionException {
|
||||
String input = context.next();
|
||||
try {
|
||||
@ -222,15 +235,15 @@ public class FawePrimitiveBinding {
|
||||
/**
|
||||
* Gets a type from a {@link ArgumentStack}.
|
||||
*
|
||||
* @param context the context
|
||||
* @param context the context
|
||||
* @param modifiers a list of modifiers
|
||||
* @return the requested type
|
||||
* @throws ParameterException on error
|
||||
*/
|
||||
@BindingMatch(type = String.class,
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1,
|
||||
provideModifiers = true)
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1,
|
||||
provideModifiers = true)
|
||||
public String getString(ArgumentStack context, Annotation[] modifiers)
|
||||
throws ParameterException {
|
||||
String v = context.next();
|
||||
@ -246,8 +259,8 @@ public class FawePrimitiveBinding {
|
||||
* @throws ParameterException on error
|
||||
*/
|
||||
@BindingMatch(type = {Boolean.class, boolean.class},
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1)
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1)
|
||||
public Boolean getBoolean(ArgumentStack context) throws ParameterException {
|
||||
return context.nextBoolean();
|
||||
}
|
||||
@ -260,9 +273,9 @@ public class FawePrimitiveBinding {
|
||||
* @throws ParameterException on error
|
||||
*/
|
||||
@BindingMatch(type = Vector3.class,
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1,
|
||||
provideModifiers = true)
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1,
|
||||
provideModifiers = true)
|
||||
public Vector3 getVector3(ArgumentStack context, Annotation[] modifiers) throws ParameterException {
|
||||
String radiusString = context.next();
|
||||
String[] radii = radiusString.split(",");
|
||||
@ -293,9 +306,9 @@ public class FawePrimitiveBinding {
|
||||
* @throws ParameterException on error
|
||||
*/
|
||||
@BindingMatch(type = Vector2.class,
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1,
|
||||
provideModifiers = true)
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1,
|
||||
provideModifiers = true)
|
||||
public Vector2 getVector2(ArgumentStack context, Annotation[] modifiers) throws ParameterException {
|
||||
String radiusString = context.next();
|
||||
String[] radii = radiusString.split(",");
|
||||
@ -314,69 +327,71 @@ public class FawePrimitiveBinding {
|
||||
throw new ParameterException("You must either specify 1 or 2 radius values.");
|
||||
}
|
||||
return Vector2.at(radiusX, radiusZ);
|
||||
} /**
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a type from a {@link ArgumentStack}.
|
||||
*
|
||||
* @param context the context
|
||||
* @return the requested type
|
||||
* @throws ParameterException on error
|
||||
*/
|
||||
@BindingMatch(type = BlockVector3.class,
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1,
|
||||
provideModifiers = true)
|
||||
public BlockVector3 getBlockVector3(ArgumentStack context, Annotation[] modifiers) throws ParameterException {
|
||||
String radiusString = context.next();
|
||||
String[] radii = radiusString.split(",");
|
||||
final double radiusX, radiusY, radiusZ;
|
||||
switch (radii.length) {
|
||||
case 1:
|
||||
radiusX = radiusY = radiusZ = Math.max(1, FawePrimitiveBinding.parseNumericInput(radii[0]));
|
||||
break;
|
||||
*
|
||||
* @param context the context
|
||||
* @return the requested type
|
||||
* @throws ParameterException on error
|
||||
*/
|
||||
@BindingMatch(type = BlockVector3.class,
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1,
|
||||
provideModifiers = true)
|
||||
public BlockVector3 getBlockVector3(ArgumentStack context, Annotation[] modifiers) throws ParameterException {
|
||||
String radiusString = context.next();
|
||||
String[] radii = radiusString.split(",");
|
||||
final double radiusX, radiusY, radiusZ;
|
||||
switch (radii.length) {
|
||||
case 1:
|
||||
radiusX = radiusY = radiusZ = Math.max(1, FawePrimitiveBinding.parseNumericInput(radii[0]));
|
||||
break;
|
||||
|
||||
case 3:
|
||||
radiusX = Math.max(1, FawePrimitiveBinding.parseNumericInput(radii[0]));
|
||||
radiusY = Math.max(1, FawePrimitiveBinding.parseNumericInput(radii[1]));
|
||||
radiusZ = Math.max(1, FawePrimitiveBinding.parseNumericInput(radii[2]));
|
||||
break;
|
||||
case 3:
|
||||
radiusX = Math.max(1, FawePrimitiveBinding.parseNumericInput(radii[0]));
|
||||
radiusY = Math.max(1, FawePrimitiveBinding.parseNumericInput(radii[1]));
|
||||
radiusZ = Math.max(1, FawePrimitiveBinding.parseNumericInput(radii[2]));
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new ParameterException("You must either specify 1 or 3 radius values.");
|
||||
}
|
||||
return BlockVector3.at(radiusX, radiusY, radiusZ);
|
||||
}
|
||||
default:
|
||||
throw new ParameterException("You must either specify 1 or 3 radius values.");
|
||||
}
|
||||
return BlockVector3.at(radiusX, radiusY, radiusZ);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets a type from a {@link ArgumentStack}.
|
||||
*
|
||||
* @param context the context
|
||||
* @return the requested type
|
||||
* @throws ParameterException on error
|
||||
*/
|
||||
@BindingMatch(type = BlockVector2.class,
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1,
|
||||
provideModifiers = true)
|
||||
public BlockVector2 getBlockVector2(ArgumentStack context, Annotation[] modifiers) throws ParameterException {
|
||||
String radiusString = context.next();
|
||||
String[] radii = radiusString.split(",");
|
||||
final double radiusX, radiusZ;
|
||||
switch (radii.length) {
|
||||
case 1:
|
||||
radiusX = radiusZ = Math.max(1, FawePrimitiveBinding.parseNumericInput(radii[0]));
|
||||
break;
|
||||
/**
|
||||
* Gets a type from a {@link ArgumentStack}.
|
||||
*
|
||||
* @param context the context
|
||||
* @return the requested type
|
||||
* @throws ParameterException on error
|
||||
*/
|
||||
@BindingMatch(type = BlockVector2.class,
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1,
|
||||
provideModifiers = true)
|
||||
public BlockVector2 getBlockVector2(ArgumentStack context, Annotation[] modifiers) throws ParameterException {
|
||||
String radiusString = context.next();
|
||||
String[] radii = radiusString.split(",");
|
||||
final double radiusX, radiusZ;
|
||||
switch (radii.length) {
|
||||
case 1:
|
||||
radiusX = radiusZ = Math.max(1, FawePrimitiveBinding.parseNumericInput(radii[0]));
|
||||
break;
|
||||
|
||||
case 2:
|
||||
radiusX = Math.max(1, FawePrimitiveBinding.parseNumericInput(radii[0]));
|
||||
radiusZ = Math.max(1, FawePrimitiveBinding.parseNumericInput(radii[1]));
|
||||
break;
|
||||
case 2:
|
||||
radiusX = Math.max(1, FawePrimitiveBinding.parseNumericInput(radii[0]));
|
||||
radiusZ = Math.max(1, FawePrimitiveBinding.parseNumericInput(radii[1]));
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new ParameterException("You must either specify 1 or 2 radius values.");
|
||||
}
|
||||
return BlockVector2.at(radiusX, radiusZ);
|
||||
}
|
||||
default:
|
||||
throw new ParameterException("You must either specify 1 or 2 radius values.");
|
||||
}
|
||||
return BlockVector2.at(radiusX, radiusZ);
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to parse numeric input as either a number or a mathematical expression.
|
||||
@ -410,15 +425,15 @@ public class FawePrimitiveBinding {
|
||||
/**
|
||||
* Gets a type from a {@link ArgumentStack}.
|
||||
*
|
||||
* @param context the context
|
||||
* @param context the context
|
||||
* @param modifiers a list of modifiers
|
||||
* @return the requested type
|
||||
* @throws ParameterException on error
|
||||
*/
|
||||
@BindingMatch(type = {Integer.class, int.class},
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1,
|
||||
provideModifiers = true)
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1,
|
||||
provideModifiers = true)
|
||||
public Integer getInteger(ArgumentStack context, Annotation[] modifiers) throws ParameterException {
|
||||
Double v = parseNumericInput(context.next());
|
||||
if (v != null) {
|
||||
@ -433,15 +448,15 @@ public class FawePrimitiveBinding {
|
||||
/**
|
||||
* Gets a type from a {@link ArgumentStack}.
|
||||
*
|
||||
* @param context the context
|
||||
* @param context the context
|
||||
* @param modifiers a list of modifiers
|
||||
* @return the requested type
|
||||
* @throws ParameterException on error
|
||||
*/
|
||||
@BindingMatch(type = {Short.class, short.class},
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1,
|
||||
provideModifiers = true)
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1,
|
||||
provideModifiers = true)
|
||||
public Short getShort(ArgumentStack context, Annotation[] modifiers) throws ParameterException {
|
||||
Integer v = getInteger(context, modifiers);
|
||||
if (v != null) {
|
||||
@ -453,15 +468,15 @@ public class FawePrimitiveBinding {
|
||||
/**
|
||||
* Gets a type from a {@link ArgumentStack}.
|
||||
*
|
||||
* @param context the context
|
||||
* @param context the context
|
||||
* @param modifiers a list of modifiers
|
||||
* @return the requested type
|
||||
* @throws ParameterException on error
|
||||
*/
|
||||
@BindingMatch(type = {Double.class, double.class},
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1,
|
||||
provideModifiers = true)
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1,
|
||||
provideModifiers = true)
|
||||
public Double getDouble(ArgumentStack context, Annotation[] modifiers) throws ParameterException {
|
||||
Double v = parseNumericInput(context.next());
|
||||
if (v != null) {
|
||||
@ -475,15 +490,15 @@ public class FawePrimitiveBinding {
|
||||
/**
|
||||
* Gets a type from a {@link ArgumentStack}.
|
||||
*
|
||||
* @param context the context
|
||||
* @param context the context
|
||||
* @param modifiers a list of modifiers
|
||||
* @return the requested type
|
||||
* @throws ParameterException on error
|
||||
*/
|
||||
@BindingMatch(type = {Float.class, float.class},
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1,
|
||||
provideModifiers = true)
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1,
|
||||
provideModifiers = true)
|
||||
public Float getFloat(ArgumentStack context, Annotation[] modifiers) throws ParameterException {
|
||||
Double v = getDouble(context, modifiers);
|
||||
if (v != null) {
|
||||
@ -495,7 +510,7 @@ public class FawePrimitiveBinding {
|
||||
/**
|
||||
* Validate a number value using relevant modifiers.
|
||||
*
|
||||
* @param number the number
|
||||
* @param number the number
|
||||
* @param modifiers the list of modifiers to scan
|
||||
* @throws ParameterException on a validation error
|
||||
*/
|
||||
@ -506,14 +521,10 @@ public class FawePrimitiveBinding {
|
||||
Range range = (Range) modifier;
|
||||
if (number < range.min()) {
|
||||
throw new ParameterException(
|
||||
String.format(
|
||||
"A valid value is greater than or equal to %s " +
|
||||
"(you entered %s)", range.min(), number));
|
||||
String.format("A valid value is greater than or equal to %s (you entered %s)", range.min(), number));
|
||||
} else if (number > range.max()) {
|
||||
throw new ParameterException(
|
||||
String.format(
|
||||
"A valid value is less than or equal to %s " +
|
||||
"(you entered %s)", range.max(), number));
|
||||
String.format("A valid value is less than or equal to %s (you entered %s)", range.max(), number));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -522,7 +533,7 @@ public class FawePrimitiveBinding {
|
||||
/**
|
||||
* Validate a number value using relevant modifiers.
|
||||
*
|
||||
* @param number the number
|
||||
* @param number the number
|
||||
* @param modifiers the list of modifiers to scan
|
||||
* @throws ParameterException on a validation error
|
||||
*/
|
||||
@ -534,13 +545,11 @@ public class FawePrimitiveBinding {
|
||||
if (number < range.min()) {
|
||||
throw new ParameterException(
|
||||
String.format(
|
||||
"A valid value is greater than or equal to %s " +
|
||||
"(you entered %s)", range.min(), number));
|
||||
"A valid value is greater than or equal to %s (you entered %s)", range.min(), number));
|
||||
} else if (number > range.max()) {
|
||||
throw new ParameterException(
|
||||
String.format(
|
||||
"A valid value is less than or equal to %s " +
|
||||
"(you entered %s)", range.max(), number));
|
||||
"A valid value is less than or equal to %s (you entered %s)", range.max(), number));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -549,7 +558,7 @@ public class FawePrimitiveBinding {
|
||||
/**
|
||||
* Validate a string value using relevant modifiers.
|
||||
*
|
||||
* @param string the string
|
||||
* @param string the string
|
||||
* @param modifiers the list of modifiers to scan
|
||||
* @throws ParameterException on a validation error
|
||||
*/
|
||||
@ -567,8 +576,7 @@ public class FawePrimitiveBinding {
|
||||
if (!string.matches(validate.regex())) {
|
||||
throw new ParameterException(
|
||||
String.format(
|
||||
"The given text doesn't match the right " +
|
||||
"format (technically speaking, the 'format' is %s)",
|
||||
"The given text doesn't match the right format (technically speaking, the 'format' is %s)",
|
||||
validate.regex()));
|
||||
}
|
||||
}
|
||||
|
@ -434,7 +434,7 @@ public enum BBC {
|
||||
allNames.add(c.name());
|
||||
allCats.add(c.category.toLowerCase());
|
||||
}
|
||||
final HashSet<BBC> captions = new HashSet<>();
|
||||
final EnumSet<BBC> captions = EnumSet.noneOf(BBC.class);
|
||||
boolean changed = false;
|
||||
for (final String key : keys) {
|
||||
final Object value = yml.get(key);
|
||||
|
@ -29,7 +29,7 @@ public class Settings extends Config {
|
||||
@Comment({"Options: cn, de, es, fr, it, nl, ru, tr",
|
||||
"Create a PR to contribute a translation: https://github.com/IntellectualSites/FastAsyncWorldEdit-1.13/tree/master/worldedit-core/src/main/resources",})
|
||||
public String LANGUAGE = "";
|
||||
@Comment("Send anonymous usage statistics")
|
||||
@Comment("@deprecated - use bstats config.yml")
|
||||
public boolean METRICS = true;
|
||||
@Comment({
|
||||
"Set true to enable WorldEdit restrictions per region (e.g. PlotSquared or WorldGuard).",
|
||||
@ -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;
|
||||
|
@ -1,195 +0,0 @@
|
||||
package com.boydti.fawe.example;
|
||||
|
||||
import com.boydti.fawe.object.FaweChunk;
|
||||
import com.boydti.fawe.object.FaweQueue;
|
||||
import com.boydti.fawe.object.RunnableVal;
|
||||
import com.boydti.fawe.util.MathMan;
|
||||
import com.boydti.fawe.util.SetQueue;
|
||||
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutorCompletionService;
|
||||
import java.util.concurrent.ForkJoinPool;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class DefaultFaweQueueMap implements IFaweQueueMap {
|
||||
|
||||
private final MappedFaweQueue parent;
|
||||
|
||||
public DefaultFaweQueueMap(MappedFaweQueue parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public final Long2ObjectOpenHashMap<FaweChunk> blocks = new Long2ObjectOpenHashMap<FaweChunk>() {
|
||||
@Override
|
||||
public FaweChunk put(Long key, FaweChunk value) {
|
||||
return put((long) key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FaweChunk put(long key, FaweChunk value) {
|
||||
if (parent.getProgressTask() != null) {
|
||||
try {
|
||||
parent.getProgressTask().run(FaweQueue.ProgressType.QUEUE, size() + 1);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
synchronized (this) {
|
||||
return super.put(key, value);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public Collection<FaweChunk> getFaweChunks() {
|
||||
synchronized (blocks) {
|
||||
return new HashSet<>(blocks.values());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachChunk(RunnableVal<FaweChunk> onEach) {
|
||||
synchronized (blocks) {
|
||||
for (Map.Entry<Long, FaweChunk> entry : blocks.entrySet()) {
|
||||
onEach.run(entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public FaweChunk getFaweChunk(int cx, int cz) {
|
||||
if (cx == lastX && cz == lastZ) {
|
||||
return lastWrappedChunk;
|
||||
}
|
||||
long pair = MathMan.pairInt(cx, cz);
|
||||
FaweChunk chunk = this.blocks.get(pair);
|
||||
if (chunk == null) {
|
||||
chunk = this.getNewFaweChunk(cx, cz);
|
||||
FaweChunk previous = this.blocks.put(pair, chunk);
|
||||
if (previous != null) {
|
||||
blocks.put(pair, previous);
|
||||
return previous;
|
||||
}
|
||||
this.blocks.put(pair, chunk);
|
||||
}
|
||||
return chunk;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FaweChunk getCachedFaweChunk(int cx, int cz) {
|
||||
if (cx == lastX && cz == lastZ) {
|
||||
return lastWrappedChunk;
|
||||
}
|
||||
long pair = MathMan.pairInt(cx, cz);
|
||||
FaweChunk chunk = this.blocks.get(pair);
|
||||
lastWrappedChunk = chunk;
|
||||
return chunk;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(FaweChunk chunk) {
|
||||
long pair = MathMan.pairInt(chunk.getX(), chunk.getZ());
|
||||
FaweChunk previous = this.blocks.put(pair, chunk);
|
||||
if (previous != null) {
|
||||
blocks.put(pair, previous);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
blocks.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return blocks.size();
|
||||
}
|
||||
|
||||
private FaweChunk getNewFaweChunk(int cx, int cz) {
|
||||
return parent.getFaweChunk(cx, cz);
|
||||
}
|
||||
|
||||
private volatile FaweChunk lastWrappedChunk;
|
||||
private int lastX = Integer.MIN_VALUE;
|
||||
private int lastZ = Integer.MIN_VALUE;
|
||||
|
||||
@Override
|
||||
public boolean next(int amount, long time) {
|
||||
synchronized (blocks) {
|
||||
try {
|
||||
boolean skip = parent.getStage() == SetQueue.QueueStage.INACTIVE;
|
||||
int added = 0;
|
||||
Iterator<Map.Entry<Long, FaweChunk>> iter = blocks.entrySet().iterator();
|
||||
if (amount == 1) {
|
||||
long start = System.currentTimeMillis();
|
||||
do {
|
||||
if (iter.hasNext()) {
|
||||
FaweChunk chunk = iter.next().getValue();
|
||||
if (skip && chunk == lastWrappedChunk) {
|
||||
continue;
|
||||
}
|
||||
iter.remove();
|
||||
parent.start(chunk);
|
||||
chunk.call();
|
||||
parent.end(chunk);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} while (System.currentTimeMillis() - start < time);
|
||||
} else {
|
||||
ExecutorCompletionService service = SetQueue.IMP.getCompleterService();
|
||||
ForkJoinPool pool = SetQueue.IMP.getForkJoinPool();
|
||||
boolean result = true;
|
||||
// amount = 8;
|
||||
for (int i = 0; i < amount && (result = iter.hasNext()); i++) {
|
||||
Map.Entry<Long, FaweChunk> item = iter.next();
|
||||
FaweChunk chunk = item.getValue();
|
||||
if (skip && chunk == lastWrappedChunk) {
|
||||
i--;
|
||||
continue;
|
||||
}
|
||||
iter.remove();
|
||||
parent.start(chunk);
|
||||
service.submit(chunk);
|
||||
added++;
|
||||
}
|
||||
// if result, then submitted = amount
|
||||
if (result) {
|
||||
long start = System.currentTimeMillis();
|
||||
while (System.currentTimeMillis() - start < time && result) {
|
||||
if (result = iter.hasNext()) {
|
||||
Map.Entry<Long, FaweChunk> item = iter.next();
|
||||
FaweChunk chunk = item.getValue();
|
||||
if (skip && chunk == lastWrappedChunk) {
|
||||
continue;
|
||||
}
|
||||
iter.remove();
|
||||
parent.start(chunk);
|
||||
service.submit(chunk);
|
||||
Future future = service.poll(50, TimeUnit.MILLISECONDS);
|
||||
if (future != null) {
|
||||
FaweChunk fc = (FaweChunk) future.get();
|
||||
parent.end(fc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
pool.awaitQuiescence(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
|
||||
Future future;
|
||||
while ((future = service.poll()) != null) {
|
||||
FaweChunk fc = (FaweChunk) future.get();
|
||||
parent.end(fc);
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return !blocks.isEmpty();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
package com.boydti.fawe.example;
|
||||
|
||||
import com.boydti.fawe.object.FaweChunk;
|
||||
import com.boydti.fawe.object.RunnableVal;
|
||||
import java.util.Collection;
|
||||
|
||||
public interface IFaweQueueMap {
|
||||
|
||||
Collection<FaweChunk> getFaweChunks();
|
||||
|
||||
void forEachChunk(RunnableVal<FaweChunk> onEach);
|
||||
|
||||
FaweChunk getFaweChunk(int cx, int cz);
|
||||
|
||||
FaweChunk getCachedFaweChunk(int cx, int cz);
|
||||
|
||||
void add(FaweChunk chunk);
|
||||
|
||||
void clear();
|
||||
|
||||
int size();
|
||||
|
||||
boolean next(int size, long time);
|
||||
}
|
@ -1,244 +0,0 @@
|
||||
package com.boydti.fawe.example;
|
||||
|
||||
import com.boydti.fawe.object.FaweChunk;
|
||||
import com.boydti.fawe.object.FaweQueue;
|
||||
import com.boydti.fawe.util.MathMan;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BlockID;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public abstract class IntFaweChunk<T, V extends FaweQueue> extends FaweChunk<T> {
|
||||
|
||||
public final int[][] setBlocks;
|
||||
public final short[] count;
|
||||
public final short[] air;
|
||||
|
||||
public BiomeType[] biomes;
|
||||
public HashMap<Short, CompoundTag> tiles;
|
||||
public HashSet<CompoundTag> entities;
|
||||
public HashSet<UUID> entityRemoves;
|
||||
|
||||
public T chunk;
|
||||
|
||||
public IntFaweChunk(FaweQueue parent, int x, int z, int[][] setBlocks, short[] count, short[] air) {
|
||||
super(parent, x, z);
|
||||
this.setBlocks = setBlocks;
|
||||
this.count = count;
|
||||
this.air = air;
|
||||
}
|
||||
|
||||
/**
|
||||
* A FaweSections object represents a chunk and the blocks that you wish to change in it.
|
||||
*
|
||||
* @param parent
|
||||
* @param x
|
||||
* @param z
|
||||
*/
|
||||
public IntFaweChunk(FaweQueue parent, int x, int z) {
|
||||
super(parent, x, z);
|
||||
this.setBlocks = new int[HEIGHT >> 4][];
|
||||
this.count = new short[HEIGHT >> 4];
|
||||
this.air = new short[HEIGHT >> 4];
|
||||
}
|
||||
|
||||
@Override
|
||||
public V getParent() {
|
||||
return (V) super.getParent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getChunk() {
|
||||
if (this.chunk == null) {
|
||||
this.chunk = getNewChunk();
|
||||
}
|
||||
return this.chunk;
|
||||
}
|
||||
|
||||
public abstract T getNewChunk();
|
||||
|
||||
@Override
|
||||
public void setLoc(final FaweQueue parent, int x, int z) {
|
||||
super.setLoc(parent, x, z);
|
||||
this.chunk = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of block changes in a specified section
|
||||
*
|
||||
* @param i
|
||||
* @return
|
||||
*/
|
||||
public int getCount(final int i) {
|
||||
return this.count[i];
|
||||
}
|
||||
|
||||
public int getAir(final int i) {
|
||||
return this.air[i];
|
||||
}
|
||||
|
||||
public void setCount(final int i, final short value) {
|
||||
this.count[i] = value;
|
||||
}
|
||||
|
||||
public int getTotalCount() {
|
||||
int total = 0;
|
||||
for (short value : count) {
|
||||
total += Math.min(4096, value);
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
public int getTotalAir() {
|
||||
int total = 0;
|
||||
for (short value : air) {
|
||||
total += Math.min(4096, value);
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBitMask() {
|
||||
int bitMask = 0;
|
||||
for (int section = 0; section < setBlocks.length; section++) {
|
||||
if (setBlocks[section] != null) {
|
||||
bitMask += 1 << section;
|
||||
}
|
||||
}
|
||||
return bitMask;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the raw data for a section
|
||||
*
|
||||
* @param i
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int[] getIdArray(final int i) {
|
||||
return this.setBlocks[i];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[][] getCombinedIdArrays() {
|
||||
return this.setBlocks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeType[] getBiomeArray() {
|
||||
return this.biomes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockCombinedId(int x, int y, int z) {
|
||||
int[] array = getIdArray(y >> 4);
|
||||
if (array == null) {
|
||||
return 0;
|
||||
}
|
||||
return array[(((y & 0xF) << 8) | (z << 4) | x)];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTile(int x, int y, int z, CompoundTag tile) {
|
||||
if (tiles == null) {
|
||||
tiles = new HashMap<>();
|
||||
}
|
||||
short pair = MathMan.tripleBlockCoord(x, y, z);
|
||||
tiles.put(pair, tile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag getTile(int x, int y, int z) {
|
||||
if (tiles == null) {
|
||||
return null;
|
||||
}
|
||||
short pair = MathMan.tripleBlockCoord(x, y, z);
|
||||
return tiles.get(pair);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Short, CompoundTag> getTiles() {
|
||||
return tiles == null ? new HashMap<>() : tiles;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<CompoundTag> getEntities() {
|
||||
return entities == null ? Collections.emptySet() : entities;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEntity(CompoundTag tag) {
|
||||
if (entities == null) {
|
||||
entities = new HashSet<>();
|
||||
}
|
||||
entities.add(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeEntity(UUID uuid) {
|
||||
if (entityRemoves == null) {
|
||||
entityRemoves = new HashSet<>();
|
||||
}
|
||||
entityRemoves.add(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashSet<UUID> getEntityRemoves() {
|
||||
return entityRemoves == null ? new HashSet<>() : entityRemoves;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlock(int x, int y, int z, int combinedId) {
|
||||
final int i = y >> 4;
|
||||
int[] vs = this.setBlocks[i];
|
||||
if (vs == null) {
|
||||
vs = this.setBlocks[i] = new int[4096];
|
||||
}
|
||||
int index = (((y & 15) << 8) | (z << 4) | x);
|
||||
int existing = vs[index];
|
||||
vs[index] = combinedId;
|
||||
switch (existing) {
|
||||
case 0:
|
||||
this.count[i]++;
|
||||
switch (combinedId) {
|
||||
case 0:
|
||||
case BlockID.AIR:
|
||||
case BlockID.CAVE_AIR:
|
||||
case BlockID.VOID_AIR:
|
||||
this.air[i]++;
|
||||
}
|
||||
break;
|
||||
case BlockID.AIR:
|
||||
case BlockID.CAVE_AIR:
|
||||
case BlockID.VOID_AIR:
|
||||
switch (combinedId) {
|
||||
case 0:
|
||||
case BlockID.AIR:
|
||||
case BlockID.CAVE_AIR:
|
||||
case BlockID.VOID_AIR:
|
||||
break;
|
||||
default:
|
||||
this.air[i]--;
|
||||
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setBitMask(int ignore) {
|
||||
// Remove
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBiome(final int x, final int z, BiomeType biome) {
|
||||
if (this.biomes == null) {
|
||||
this.biomes = new BiomeType[256];
|
||||
}
|
||||
biomes[((z & 15) << 4) + (x & 15)] = biome;
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract IntFaweChunk<T, V> copy(boolean shallow);
|
||||
}
|
@ -1,216 +0,0 @@
|
||||
package com.boydti.fawe.example;
|
||||
|
||||
import com.boydti.fawe.object.FaweChunk;
|
||||
import com.boydti.fawe.util.TaskManager;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
public abstract class NMSMappedFaweQueue<WORLD, CHUNK, CHUNKSECTION, SECTION> extends MappedFaweQueue<WORLD, CHUNK, CHUNKSECTION, SECTION> {
|
||||
|
||||
private final int maxY;
|
||||
|
||||
public NMSMappedFaweQueue(World world) {
|
||||
super(world);
|
||||
this.maxY = world.getMaxY();
|
||||
}
|
||||
|
||||
public NMSMappedFaweQueue(String world) {
|
||||
super(world);
|
||||
this.maxY = 256;
|
||||
}
|
||||
|
||||
public NMSMappedFaweQueue(String world, IFaweQueueMap map) {
|
||||
super(world, map);
|
||||
this.maxY = 256;
|
||||
}
|
||||
|
||||
public NMSMappedFaweQueue(World world, IFaweQueueMap map) {
|
||||
super(world, map);
|
||||
this.maxY = world.getMaxY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runTasks() {
|
||||
super.runTasks();
|
||||
if (!getRelighter().isEmpty()) {
|
||||
TaskManager.IMP.async(() -> {
|
||||
if (getSettings().IMP.LIGHTING.REMOVE_FIRST) {
|
||||
getRelighter().removeAndRelight(hasSky());
|
||||
} else {
|
||||
getRelighter().fixLightingSafe(hasSky());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private final Relighter relighter = getSettings().IMP.LIGHTING.MODE > 0 ? new NMSRelighter(this) : NullRelighter.INSTANCE;
|
||||
|
||||
@Override
|
||||
public Relighter getRelighter() {
|
||||
return relighter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void end(FaweChunk chunk) {
|
||||
super.end(chunk);
|
||||
if (getSettings().IMP.LIGHTING.MODE == 0) {
|
||||
sendChunk(chunk);
|
||||
return;
|
||||
}
|
||||
if (!getSettings().IMP.LIGHTING.DELAY_PACKET_SENDING) {
|
||||
sendChunk(chunk);
|
||||
}
|
||||
if (getSettings().IMP.LIGHTING.MODE == 2) {
|
||||
getRelighter().addChunk(chunk.getX(), chunk.getZ(), null, chunk.getBitMask());
|
||||
return;
|
||||
}
|
||||
IntFaweChunk cfc = (IntFaweChunk) chunk;
|
||||
boolean relight = false;
|
||||
byte[] fix = new byte[(maxY + 1) >> 4];
|
||||
boolean sky = hasSky();
|
||||
if (sky) {
|
||||
int layers = FaweChunk.HEIGHT >> 4;
|
||||
for (int i = layers - 1; i >= 0; i--) {
|
||||
int air = cfc.getAir(i);
|
||||
int solid = cfc.getCount(i);
|
||||
if (air == 4096) {
|
||||
fix[i] = Relighter.SkipReason.AIR;
|
||||
} else if (air == 0 && solid == 4096) {
|
||||
fix[i] = Relighter.SkipReason.SOLID;
|
||||
} else if (solid == 0 && relight == false) {
|
||||
fix[i] = Relighter.SkipReason.AIR;
|
||||
} else {
|
||||
fix[i] = Relighter.SkipReason.NONE;
|
||||
relight = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (relight) {
|
||||
getRelighter().addChunk(chunk.getX(), chunk.getZ(), fix, chunk.getBitMask());
|
||||
} else if (getSettings().IMP.LIGHTING.DELAY_PACKET_SENDING) {
|
||||
sendChunk(chunk);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendChunk(final FaweChunk fc) {
|
||||
try {
|
||||
refreshChunk(fc);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void setFullbright(CHUNKSECTION sections);
|
||||
|
||||
public boolean removeLighting(CHUNKSECTION sections, RelightMode mode, boolean hasSky) {
|
||||
boolean result = false;
|
||||
for (int i = 0; i < 16; i++) {
|
||||
SECTION section = getCachedSection(sections, i);
|
||||
if (section != null) {
|
||||
result |= removeSectionLighting(section, i, hasSky);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public abstract boolean removeSectionLighting(SECTION sections, int layer, boolean hasSky);
|
||||
|
||||
public boolean isSurrounded(final char[][] sections, final int x, final int y, final int z) {
|
||||
return this.isSolid(this.getId(sections, x, y + 1, z))
|
||||
&& this.isSolid(this.getId(sections, x + 1, y - 1, z))
|
||||
&& this.isSolid(this.getId(sections, x - 1, y, z))
|
||||
&& this.isSolid(this.getId(sections, x, y, z + 1))
|
||||
&& this.isSolid(this.getId(sections, x, y, z - 1));
|
||||
}
|
||||
|
||||
public boolean isSolid(final int id) {
|
||||
return !BlockTypes.get(id).getMaterial().isTranslucent();
|
||||
}
|
||||
|
||||
public int getId(final char[][] sections, final int x, final int y, final int z) {
|
||||
if ((x < 0) || (x > 15) || (z < 0) || (z > 15)) {
|
||||
return BlockTypes.AIR.getInternalId();
|
||||
}
|
||||
if ((y < 0) || (y > maxY)) {
|
||||
return BlockTypes.AIR.getInternalId();
|
||||
}
|
||||
final int i = y >> 4;
|
||||
final char[] section = sections[i];
|
||||
if (section == null) {
|
||||
return 0;
|
||||
}
|
||||
return section[(((y & 0xF) << 8) | (z << 4) | x)] >> 4;
|
||||
}
|
||||
|
||||
public void saveChunk(CHUNK chunk) {
|
||||
}
|
||||
|
||||
public abstract void relight(int x, int y, int z);
|
||||
|
||||
public abstract void relightBlock(int x, int y, int z);
|
||||
|
||||
public abstract void relightSky(int x, int y, int z);
|
||||
|
||||
public void setSkyLight(int x, int y, int z, int value) {
|
||||
int cx = x >> 4;
|
||||
int cz = z >> 4;
|
||||
int cy = y >> 4;
|
||||
if (cx != lastSectionX || cz != lastSectionZ) {
|
||||
lastSectionX = cx;
|
||||
lastSectionZ = cz;
|
||||
lastChunk = ensureChunkLoaded(cx, cz);
|
||||
if (lastChunk != null) {
|
||||
lastChunkSections = getSections(lastChunk);
|
||||
lastSection = getCachedSection(lastChunkSections, cy);
|
||||
} else {
|
||||
lastChunkSections = null;
|
||||
return;
|
||||
}
|
||||
} else if (cy != lastSectionY) {
|
||||
if (lastChunkSections != null) {
|
||||
lastSection = getCachedSection(lastChunkSections, cy);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (lastSection == null) {
|
||||
return;
|
||||
}
|
||||
setSkyLight(lastSection, x, y, z, value);
|
||||
}
|
||||
|
||||
public void setBlockLight(int x, int y, int z, int value) {
|
||||
int cx = x >> 4;
|
||||
int cz = z >> 4;
|
||||
int cy = y >> 4;
|
||||
if (cx != lastSectionX || cz != lastSectionZ) {
|
||||
lastSectionX = cx;
|
||||
lastSectionZ = cz;
|
||||
lastChunk = ensureChunkLoaded(cx, cz);
|
||||
if (lastChunk != null) {
|
||||
lastChunkSections = getSections(lastChunk);
|
||||
lastSection = getCachedSection(lastChunkSections, cy);
|
||||
} else {
|
||||
lastChunkSections = null;
|
||||
return;
|
||||
}
|
||||
} else if (cy != lastSectionY) {
|
||||
if (lastChunkSections != null) {
|
||||
lastSection = getCachedSection(lastChunkSections, cy);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (lastSection == null) {
|
||||
return;
|
||||
}
|
||||
setBlockLight(lastSection, x, y, z, value);
|
||||
}
|
||||
|
||||
public abstract void setSkyLight(SECTION section, int x, int y, int z, int value);
|
||||
|
||||
public abstract void setBlockLight(SECTION section, int x, int y, int z, int value);
|
||||
|
||||
public abstract void refreshChunk(FaweChunk fs);
|
||||
}
|
@ -1,597 +0,0 @@
|
||||
package com.boydti.fawe.example;
|
||||
|
||||
import com.boydti.fawe.FaweCache;
|
||||
import com.boydti.fawe.config.Settings;
|
||||
import com.boydti.fawe.object.FaweChunk;
|
||||
import com.boydti.fawe.object.FaweQueue;
|
||||
import com.boydti.fawe.object.IntegerTrio;
|
||||
import com.boydti.fawe.object.RunnableVal;
|
||||
import com.boydti.fawe.object.collection.BlockVectorSet;
|
||||
import com.boydti.fawe.util.MathMan;
|
||||
import com.boydti.fawe.util.TaskManager;
|
||||
import com.google.common.io.LineReader;
|
||||
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public class NMSRelighter implements Relighter {
|
||||
private final NMSMappedFaweQueue queue;
|
||||
|
||||
private final Map<Long, RelightSkyEntry> skyToRelight;
|
||||
private final Object present = new Object();
|
||||
private final Map<Long, Integer> chunksToSend;
|
||||
private final ConcurrentLinkedQueue<RelightSkyEntry> queuedSkyToRelight = new ConcurrentLinkedQueue<>();
|
||||
|
||||
private final Map<Long, long[][][] /* z y x */ > lightQueue;
|
||||
private final AtomicBoolean lightLock = new AtomicBoolean(false);
|
||||
private final ConcurrentHashMap<Long, long[][][]> concurrentLightQueue;
|
||||
|
||||
private final int maxY;
|
||||
private volatile boolean relighting = false;
|
||||
|
||||
public final IntegerTrio mutableBlockPos = new IntegerTrio();
|
||||
|
||||
private static final int DISPATCH_SIZE = 64;
|
||||
private boolean removeFirst;
|
||||
|
||||
public NMSRelighter(NMSMappedFaweQueue queue) {
|
||||
this.queue = queue;
|
||||
this.skyToRelight = new Long2ObjectOpenHashMap<>();
|
||||
this.lightQueue = new Long2ObjectOpenHashMap<>();
|
||||
this.chunksToSend = new Long2ObjectOpenHashMap<>();
|
||||
this.concurrentLightQueue = new ConcurrentHashMap<>();
|
||||
this.maxY = queue.getMaxY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return skyToRelight.isEmpty() && lightQueue.isEmpty() && queuedSkyToRelight.isEmpty() && concurrentLightQueue.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void removeAndRelight(boolean sky) {
|
||||
removeFirst = true;
|
||||
fixLightingSafe(sky);
|
||||
removeFirst = false;
|
||||
}
|
||||
|
||||
private void set(int x, int y, int z, long[][][] map) {
|
||||
long[][] m1 = map[z];
|
||||
if (m1 == null) {
|
||||
m1 = map[z] = new long[16][];
|
||||
}
|
||||
long[] m2 = m1[x];
|
||||
if (m2 == null) {
|
||||
m2 = m1[x] = new long[4];
|
||||
}
|
||||
long value = m2[y >> 6] |= 1l << y;
|
||||
}
|
||||
|
||||
public void addLightUpdate(int x, int y, int z) {
|
||||
long index = MathMan.pairInt(x >> 4, z >> 4);
|
||||
if (lightLock.compareAndSet(false, true)) {
|
||||
synchronized (lightQueue) {
|
||||
try {
|
||||
long[][][] currentMap = lightQueue.get(index);
|
||||
if (currentMap == null) {
|
||||
currentMap = new long[16][][];
|
||||
this.lightQueue.put(index, currentMap);
|
||||
}
|
||||
set(x & 15, y, z & 15, currentMap);
|
||||
} finally {
|
||||
lightLock.set(false);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
long[][][] currentMap = concurrentLightQueue.get(index);
|
||||
if (currentMap == null) {
|
||||
currentMap = new long[16][][];
|
||||
this.concurrentLightQueue.put(index, currentMap);
|
||||
}
|
||||
set(x & 15, y, z & 15, currentMap);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void clear() {
|
||||
queuedSkyToRelight.clear();
|
||||
skyToRelight.clear();
|
||||
chunksToSend.clear();
|
||||
lightQueue.clear();
|
||||
concurrentLightQueue.clear();
|
||||
}
|
||||
|
||||
public boolean addChunk(int cx, int cz, byte[] fix, int bitmask) {
|
||||
RelightSkyEntry toPut = new RelightSkyEntry(cx, cz, fix, bitmask);
|
||||
queuedSkyToRelight.add(toPut);
|
||||
return true;
|
||||
}
|
||||
|
||||
private synchronized Map<Long, RelightSkyEntry> getSkyMap() {
|
||||
RelightSkyEntry entry;
|
||||
while ((entry = queuedSkyToRelight.poll()) != null) {
|
||||
long pair = MathMan.pairInt(entry.x, entry.z);
|
||||
RelightSkyEntry existing = skyToRelight.put(pair, entry);
|
||||
if (existing != null) {
|
||||
entry.bitmask |= existing.bitmask;
|
||||
if (entry.fix != null) {
|
||||
for (int i = 0; i < entry.fix.length; i++) {
|
||||
entry.fix[i] &= existing.fix[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return skyToRelight;
|
||||
}
|
||||
|
||||
public synchronized void removeLighting() {
|
||||
Iterator<Map.Entry<Long, RelightSkyEntry>> iter = getSkyMap().entrySet().iterator();
|
||||
while (iter.hasNext()) {
|
||||
Map.Entry<Long, RelightSkyEntry> entry = iter.next();
|
||||
RelightSkyEntry chunk = entry.getValue();
|
||||
long pair = entry.getKey();
|
||||
Integer existing = chunksToSend.get(pair);
|
||||
chunksToSend.put(pair, chunk.bitmask | (existing != null ? existing : 0));
|
||||
queue.ensureChunkLoaded(chunk.x, chunk.z);
|
||||
Object sections = queue.getCachedSections(queue.getWorld(), chunk.x, chunk.z);
|
||||
queue.removeLighting(sections, FaweQueue.RelightMode.ALL, queue.hasSky());
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
|
||||
public void updateBlockLight(Map<Long, long[][][]> map) {
|
||||
int size = map.size();
|
||||
if (size == 0) {
|
||||
return;
|
||||
}
|
||||
Queue<IntegerTrio> lightPropagationQueue = new ArrayDeque<>();
|
||||
Queue<Object[]> lightRemovalQueue = new ArrayDeque<>();
|
||||
Map<IntegerTrio, Object> visited = new HashMap<>();
|
||||
Map<IntegerTrio, Object> removalVisited = new HashMap<>();
|
||||
|
||||
Iterator<Map.Entry<Long, long[][][]>> iter = map.entrySet().iterator();
|
||||
while (iter.hasNext() && size-- > 0) {
|
||||
Map.Entry<Long, long[][][]> entry = iter.next();
|
||||
long index = entry.getKey();
|
||||
long[][][] blocks = entry.getValue();
|
||||
int chunkX = MathMan.unpairIntX(index);
|
||||
int chunkZ = MathMan.unpairIntY(index);
|
||||
int bx = chunkX << 4;
|
||||
int bz = chunkZ << 4;
|
||||
for (int lz = 0; lz < blocks.length; lz++) {
|
||||
long[][] m1 = blocks[lz];
|
||||
if (m1 == null) continue;
|
||||
for (int lx = 0; lx < m1.length; lx++) {
|
||||
long[] m2 = m1[lx];
|
||||
if (m2 == null) continue;
|
||||
for (int i = 0; i < m2.length; i++) {
|
||||
int yStart = i << 6;
|
||||
long value = m2[i];
|
||||
if (value != 0) {
|
||||
for (int j = 0; j < 64; j++) {
|
||||
if (((value >> j) & 1) == 1) {
|
||||
int x = lx + bx;
|
||||
int y = yStart + j;
|
||||
int z = lz + bz;
|
||||
int oldLevel = queue.getEmmittedLight(x, y, z);
|
||||
int newLevel = queue.getBrightness(x, y, z);
|
||||
if (oldLevel != newLevel) {
|
||||
queue.setBlockLight(x, y, z, newLevel);
|
||||
IntegerTrio node = new IntegerTrio(x, y, z);
|
||||
if (newLevel < oldLevel) {
|
||||
removalVisited.put(node, present);
|
||||
lightRemovalQueue.add(new Object[]{node, oldLevel});
|
||||
} else {
|
||||
visited.put(node, present);
|
||||
lightPropagationQueue.add(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
iter.remove();
|
||||
}
|
||||
|
||||
while (!lightRemovalQueue.isEmpty()) {
|
||||
Object[] val = lightRemovalQueue.poll();
|
||||
IntegerTrio node = (IntegerTrio) val[0];
|
||||
int lightLevel = (int) val[1];
|
||||
|
||||
this.computeRemoveBlockLight(node.x - 1, node.y, node.z, lightLevel, lightRemovalQueue, lightPropagationQueue, removalVisited, visited);
|
||||
this.computeRemoveBlockLight(node.x + 1, node.y, node.z, lightLevel, lightRemovalQueue, lightPropagationQueue, removalVisited, visited);
|
||||
if (node.y > 0) {
|
||||
this.computeRemoveBlockLight(node.x, node.y - 1, node.z, lightLevel, lightRemovalQueue, lightPropagationQueue, removalVisited, visited);
|
||||
}
|
||||
if (node.y < 255) {
|
||||
this.computeRemoveBlockLight(node.x, node.y + 1, node.z, lightLevel, lightRemovalQueue, lightPropagationQueue, removalVisited, visited);
|
||||
}
|
||||
this.computeRemoveBlockLight(node.x, node.y, node.z - 1, lightLevel, lightRemovalQueue, lightPropagationQueue, removalVisited, visited);
|
||||
this.computeRemoveBlockLight(node.x, node.y, node.z + 1, lightLevel, lightRemovalQueue, lightPropagationQueue, removalVisited, visited);
|
||||
}
|
||||
|
||||
while (!lightPropagationQueue.isEmpty()) {
|
||||
IntegerTrio node = lightPropagationQueue.poll();
|
||||
int lightLevel = queue.getEmmittedLight(node.x, node.y, node.z);
|
||||
if (lightLevel > 1) {
|
||||
this.computeSpreadBlockLight(node.x - 1, node.y, node.z, lightLevel, lightPropagationQueue, visited);
|
||||
this.computeSpreadBlockLight(node.x + 1, node.y, node.z, lightLevel, lightPropagationQueue, visited);
|
||||
if (node.y > 0) {
|
||||
this.computeSpreadBlockLight(node.x, node.y - 1, node.z, lightLevel, lightPropagationQueue, visited);
|
||||
}
|
||||
if (node.y < 255) {
|
||||
this.computeSpreadBlockLight(node.x, node.y + 1, node.z, lightLevel, lightPropagationQueue, visited);
|
||||
}
|
||||
this.computeSpreadBlockLight(node.x, node.y, node.z - 1, lightLevel, lightPropagationQueue, visited);
|
||||
this.computeSpreadBlockLight(node.x, node.y, node.z + 1, lightLevel, lightPropagationQueue, visited);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void computeRemoveBlockLight(int x, int y, int z, int currentLight, Queue<Object[]> queue, Queue<IntegerTrio> spreadQueue, Map<IntegerTrio, Object> visited,
|
||||
Map<IntegerTrio, Object> spreadVisited) {
|
||||
int current = this.queue.getEmmittedLight(x, y, z);
|
||||
if (current != 0 && current < currentLight) {
|
||||
this.queue.setBlockLight(x, y, z, 0);
|
||||
if (current > 1) {
|
||||
if (!visited.containsKey(mutableBlockPos)) {
|
||||
IntegerTrio index = new IntegerTrio(x, y, z);
|
||||
visited.put(index, present);
|
||||
queue.add(new Object[]{index, current});
|
||||
}
|
||||
}
|
||||
} else if (current >= currentLight) {
|
||||
mutableBlockPos.set(x, y, z);
|
||||
if (!spreadVisited.containsKey(mutableBlockPos)) {
|
||||
IntegerTrio index = new IntegerTrio(x, y, z);
|
||||
spreadVisited.put(index, present);
|
||||
spreadQueue.add(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void computeSpreadBlockLight(int x, int y, int z, int currentLight, Queue<IntegerTrio> queue, Map<IntegerTrio, Object> visited) {
|
||||
currentLight = currentLight - Math.max(1, this.queue.getOpacity(x, y, z));
|
||||
if (currentLight > 0) {
|
||||
int current = this.queue.getEmmittedLight(x, y, z);
|
||||
if (current < currentLight) {
|
||||
this.queue.setBlockLight(x, y, z, currentLight);
|
||||
mutableBlockPos.set(x, y, z);
|
||||
if (!visited.containsKey(mutableBlockPos)) {
|
||||
visited.put(new IntegerTrio(x, y, z), present);
|
||||
if (currentLight > 1) {
|
||||
queue.add(new IntegerTrio(x, y, z));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void fixLightingSafe(boolean sky) {
|
||||
if (isEmpty()) return;
|
||||
try {
|
||||
if (sky) {
|
||||
fixSkyLighting();
|
||||
} else {
|
||||
synchronized (this) {
|
||||
Map<Long, RelightSkyEntry> map = getSkyMap();
|
||||
Iterator<Map.Entry<Long, RelightSkyEntry>> iter = map.entrySet().iterator();
|
||||
while (iter.hasNext()) {
|
||||
Map.Entry<Long, RelightSkyEntry> entry = iter.next();
|
||||
chunksToSend.put(entry.getKey(), entry.getValue().bitmask);
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
fixBlockLighting();
|
||||
sendChunks();
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void fixBlockLighting() {
|
||||
synchronized (lightQueue) {
|
||||
while (!lightLock.compareAndSet(false, true));
|
||||
try {
|
||||
updateBlockLight(this.lightQueue);
|
||||
} finally {
|
||||
lightLock.set(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void sendChunks() {
|
||||
RunnableVal<Object> runnable = new RunnableVal<Object>() {
|
||||
@Override
|
||||
public void run(Object value) {
|
||||
Iterator<Map.Entry<Long, Integer>> iter = chunksToSend.entrySet().iterator();
|
||||
while (iter.hasNext()) {
|
||||
Map.Entry<Long, Integer> entry = iter.next();
|
||||
long pair = entry.getKey();
|
||||
int bitMask = entry.getValue();
|
||||
int x = MathMan.unpairIntX(pair);
|
||||
int z = MathMan.unpairIntY(pair);
|
||||
queue.sendChunk(x, z, bitMask);
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
};
|
||||
if (Settings.IMP.LIGHTING.ASYNC) {
|
||||
runnable.run();
|
||||
} else {
|
||||
TaskManager.IMP.sync(runnable);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isTransparent(int x, int y, int z) {
|
||||
return queue.getOpacity(x, y, z) < 15;
|
||||
}
|
||||
|
||||
public synchronized void fixSkyLighting() {
|
||||
// Order chunks
|
||||
Map<Long, RelightSkyEntry> map = getSkyMap();
|
||||
ArrayList<RelightSkyEntry> chunksList = new ArrayList<>(map.size());
|
||||
Iterator<Map.Entry<Long, RelightSkyEntry>> iter = map.entrySet().iterator();
|
||||
while (iter.hasNext()) {
|
||||
Map.Entry<Long, RelightSkyEntry> entry = iter.next();
|
||||
chunksToSend.put(entry.getKey(), entry.getValue().bitmask);
|
||||
chunksList.add(entry.getValue());
|
||||
iter.remove();
|
||||
}
|
||||
Collections.sort(chunksList);
|
||||
int size = chunksList.size();
|
||||
if (size > DISPATCH_SIZE) {
|
||||
int amount = (size + DISPATCH_SIZE - 1) / DISPATCH_SIZE;
|
||||
for (int i = 0; i < amount; i++) {
|
||||
int start = i * DISPATCH_SIZE;
|
||||
int end = Math.min(size, start + DISPATCH_SIZE);
|
||||
List<RelightSkyEntry> sub = chunksList.subList(start, end);
|
||||
fixSkyLighting(sub);
|
||||
}
|
||||
} else {
|
||||
fixSkyLighting(chunksList);
|
||||
}
|
||||
}
|
||||
|
||||
public void fill(byte[] mask, int chunkX, int y, int chunkZ, byte reason) {
|
||||
if (y >= FaweChunk.HEIGHT) {
|
||||
Arrays.fill(mask, (byte) 15);
|
||||
return;
|
||||
}
|
||||
switch (reason) {
|
||||
case SkipReason.SOLID: {
|
||||
Arrays.fill(mask, (byte) 0);
|
||||
return;
|
||||
}
|
||||
case SkipReason.AIR: {
|
||||
int bx = chunkX << 4;
|
||||
int bz = chunkZ << 4;
|
||||
int index = 0;
|
||||
for (int z = 0; z < 16; z++) {
|
||||
for (int x = 0; x < 16; x++) {
|
||||
mask[index++] = (byte) queue.getSkyLight(bx + x, y, bz + z);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void fixSkyLighting(List<RelightSkyEntry> sorted) {
|
||||
RelightSkyEntry[] chunks = sorted.toArray(new RelightSkyEntry[sorted.size()]);
|
||||
boolean remove = this.removeFirst;
|
||||
BlockVectorSet chunkSet = null;
|
||||
if (remove) {
|
||||
chunkSet = new BlockVectorSet();
|
||||
BlockVectorSet tmpSet = new BlockVectorSet();
|
||||
for (RelightSkyEntry chunk : chunks) {
|
||||
tmpSet.add(chunk.x, 0, chunk.z);
|
||||
}
|
||||
for (RelightSkyEntry chunk : chunks) {
|
||||
int x = chunk.x;
|
||||
int z = chunk.z;
|
||||
if (tmpSet.contains(x + 1, 0, z) && tmpSet.contains(x - 1, 0, z) && tmpSet.contains(x, 0, z + 1) && tmpSet.contains(x, 0, z - 1)) {
|
||||
chunkSet.add(x, 0, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// byte[] cacheX = FaweCache.CACHE_X[0];
|
||||
// byte[] cacheZ = FaweCache.CACHE_Z[0];
|
||||
for (int y = FaweChunk.HEIGHT - 1; y > 0; y--) {
|
||||
for (RelightSkyEntry chunk : chunks) { // Propogate skylight
|
||||
int layer = y >> 4;
|
||||
byte[] mask = chunk.mask;
|
||||
if (chunk.fix[layer] != SkipReason.NONE) {
|
||||
if ((y & 15) == 0 && layer != 0 && chunk.fix[layer - 1] == SkipReason.NONE) {
|
||||
fill(mask, chunk.x, y, chunk.z, chunk.fix[layer]);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
int bx = chunk.x << 4;
|
||||
int bz = chunk.z << 4;
|
||||
Object chunkObj = queue.ensureChunkLoaded(chunk.x, chunk.z);
|
||||
Object sections = queue.getCachedSections(queue.getWorld(), chunk.x, chunk.z);
|
||||
if (sections == null) continue;
|
||||
Object section = queue.getCachedSection(sections, layer);
|
||||
if (section == null) continue;
|
||||
chunk.smooth = false;
|
||||
|
||||
if (remove && (y & 15) == 15 && chunkSet.contains(chunk.x, 0, chunk.z)) {
|
||||
queue.removeSectionLighting(section, y >> 4, true);
|
||||
}
|
||||
|
||||
for (int z = 0, j = 0; z < 16; z++) {
|
||||
for (int x = 0; x < 16; x++, j++) {
|
||||
byte value = mask[j];
|
||||
byte pair = (byte) queue.getOpacityBrightnessPair(section, x, y, z);
|
||||
int opacity = MathMan.unpair16x(pair);
|
||||
int brightness = MathMan.unpair16y(pair);
|
||||
if (brightness > 1 && (brightness != 15 || opacity != 15)) {
|
||||
addLightUpdate(bx + x, y, bz + z);
|
||||
}
|
||||
switch (value) {
|
||||
case 0:
|
||||
if (opacity > 1) {
|
||||
queue.setSkyLight(section, x, y, z, 0);
|
||||
continue;
|
||||
}
|
||||
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:
|
||||
if (opacity >= value) {
|
||||
mask[j] = 0;
|
||||
queue.setSkyLight(section, x, y, z, 0);
|
||||
continue;
|
||||
}
|
||||
if (opacity <= 1) {
|
||||
mask[j] = --value;
|
||||
} else {
|
||||
mask[j] = value = (byte) Math.max(0, value - opacity);
|
||||
}
|
||||
break;
|
||||
case 15:
|
||||
if (opacity > 1) {
|
||||
value -= opacity;
|
||||
mask[j] = value;
|
||||
}
|
||||
queue.setSkyLight(section, x, y, z, value);
|
||||
continue;
|
||||
}
|
||||
chunk.smooth = true;
|
||||
queue.setSkyLight(section, x, y, z, value);
|
||||
}
|
||||
}
|
||||
queue.saveChunk(chunkObj);
|
||||
}
|
||||
for (RelightSkyEntry chunk : chunks) { // Smooth forwards
|
||||
if (chunk.smooth) {
|
||||
smoothSkyLight(chunk, y, true);
|
||||
}
|
||||
}
|
||||
for (int i = chunks.length - 1; i >= 0; i--) { // Smooth backwards
|
||||
RelightSkyEntry chunk = chunks[i];
|
||||
if (chunk.smooth) {
|
||||
smoothSkyLight(chunk, y, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void smoothSkyLight(RelightSkyEntry chunk, int y, boolean direction) {
|
||||
byte[] mask = chunk.mask;
|
||||
int bx = chunk.x << 4;
|
||||
int bz = chunk.z << 4;
|
||||
queue.ensureChunkLoaded(chunk.x, chunk.z);
|
||||
Object sections = queue.getCachedSections(queue.getWorld(), chunk.x, chunk.z);
|
||||
if (sections == null) return;
|
||||
Object section = queue.getCachedSection(sections, y >> 4);
|
||||
if (section == null) return;
|
||||
if (direction) {
|
||||
for (int j = 0; j < 256; j++) {
|
||||
int x = j & 15;
|
||||
int z = j >> 4;
|
||||
if (mask[j] >= 14 || (mask[j] == 0 && queue.getOpacity(section, x, y, z) > 1)) {
|
||||
continue;
|
||||
}
|
||||
byte value = mask[j];
|
||||
if ((value = (byte) Math.max(queue.getSkyLight(bx + x - 1, y, bz + z) - 1, value)) >= 14) ;
|
||||
else if ((value = (byte) Math.max(queue.getSkyLight(bx + x, y, bz + z - 1) - 1, value)) >= 14) ;
|
||||
if (value > mask[j]) queue.setSkyLight(section, x, y, z, mask[j] = value);
|
||||
}
|
||||
} else {
|
||||
for (int j = 255; j >= 0; j--) {
|
||||
int x = j & 15;
|
||||
int z = j >> 4;
|
||||
if (mask[j] >= 14 || (mask[j] == 0 && queue.getOpacity(section, x, y, z) > 1)) {
|
||||
continue;
|
||||
}
|
||||
byte value = mask[j];
|
||||
if ((value = (byte) Math.max(queue.getSkyLight(bx + x + 1, y, bz + z) - 1, value)) >= 14) ;
|
||||
else if ((value = (byte) Math.max(queue.getSkyLight(bx + x, y, bz + z + 1) - 1, value)) >= 14) ;
|
||||
if (value > mask[j]) queue.setSkyLight(section, x, y, z, mask[j] = value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isUnlit(byte[] array) {
|
||||
for (byte val : array) {
|
||||
if (val != 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private class RelightSkyEntry implements Comparable {
|
||||
public final int x;
|
||||
public final int z;
|
||||
public final byte[] mask;
|
||||
public final byte[] fix;
|
||||
public int bitmask;
|
||||
public boolean smooth;
|
||||
|
||||
public RelightSkyEntry(int x, int z, byte[] fix, int bitmask) {
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
byte[] array = new byte[256];
|
||||
Arrays.fill(array, (byte) 15);
|
||||
this.mask = array;
|
||||
this.bitmask = bitmask;
|
||||
if (fix == null) {
|
||||
this.fix = new byte[(maxY + 1) >> 4];
|
||||
Arrays.fill(this.fix, SkipReason.NONE);
|
||||
} else {
|
||||
this.fix = fix;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return x + "," + z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Object o) {
|
||||
RelightSkyEntry other = (RelightSkyEntry) o;
|
||||
if (other.x < x) {
|
||||
return 1;
|
||||
}
|
||||
if (other.x > x) {
|
||||
return -1;
|
||||
}
|
||||
if (other.z < z) {
|
||||
return 1;
|
||||
}
|
||||
if (other.z > z) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,113 +0,0 @@
|
||||
package com.boydti.fawe.example;
|
||||
|
||||
import com.boydti.fawe.object.FaweChunk;
|
||||
import com.boydti.fawe.object.FaweQueue;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
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 NullFaweChunk extends FaweChunk<Void> {
|
||||
public static final NullFaweChunk INSTANCE = new NullFaweChunk(null, 0, 0);
|
||||
|
||||
/**
|
||||
* A FaweSections object represents a chunk and the blocks that you wish to change in it.
|
||||
*
|
||||
* @param parent
|
||||
* @param x
|
||||
* @param z
|
||||
*/
|
||||
public NullFaweChunk(FaweQueue parent, int x, int z) {
|
||||
super(parent, x, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[][] getCombinedIdArrays() {
|
||||
return new int[16][];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getIdArray(int layer) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeType[] getBiomeArray() {
|
||||
return new BiomeType[256];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBitMask() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockCombinedId(int x, int y, int z) {
|
||||
return BlockTypes.AIR.getInternalId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void getChunk() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTile(int x, int y, int z, CompoundTag tile) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEntity(CompoundTag entity) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeEntity(UUID uuid) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlock(int x, int y, int z, int combinedId) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<CompoundTag> getEntities() {
|
||||
return new HashSet<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<UUID> getEntityRemoves() {
|
||||
return new HashSet<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Short, CompoundTag> getTiles() {
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag getTile(int x, int y, int z) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBiome(int x, int z, BiomeType biome) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public FaweChunk<Void> copy(boolean shallow) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FaweChunk call() {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
package com.boydti.fawe.example;
|
||||
|
||||
import com.boydti.fawe.object.FaweChunk;
|
||||
import com.boydti.fawe.util.MainUtil;
|
||||
|
||||
public class NullQueueIntFaweChunk extends IntFaweChunk {
|
||||
|
||||
public NullQueueIntFaweChunk(int cx, int cz) {
|
||||
super(null, cx, cz);
|
||||
}
|
||||
|
||||
public NullQueueIntFaweChunk(int x, int z, int[][] ids, short[] count, short[] air) {
|
||||
super(null, x, z, ids, count, air);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getNewChunk() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IntFaweChunk copy(boolean shallow) {
|
||||
if (shallow) {
|
||||
return new NullQueueIntFaweChunk(getX(), getZ(), setBlocks, count, air);
|
||||
} else {
|
||||
return new NullQueueIntFaweChunk(getX(), getZ(), (int[][]) MainUtil.copyNd(setBlocks), count.clone(), air.clone());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public FaweChunk call() {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
package com.boydti.fawe.example;
|
||||
|
||||
public class NullRelighter implements Relighter {
|
||||
|
||||
public static NullRelighter INSTANCE = new NullRelighter();
|
||||
|
||||
private NullRelighter() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addChunk(int cx, int cz, byte[] fix, int bitmask) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addLightUpdate(int x, int y, int z) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fixLightingSafe(boolean sky) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeLighting() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fixBlockLighting() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fixSkyLighting() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
package com.boydti.fawe.example;
|
||||
|
||||
public interface Relighter {
|
||||
boolean addChunk(int cx, int cz, byte[] skipReason, int bitmask);
|
||||
|
||||
void addLightUpdate(int x, int y, int z);
|
||||
|
||||
void fixLightingSafe(boolean sky);
|
||||
|
||||
default void removeAndRelight(boolean sky) {
|
||||
removeLighting();
|
||||
fixLightingSafe(sky);
|
||||
}
|
||||
|
||||
void clear();
|
||||
|
||||
void removeLighting();
|
||||
|
||||
void fixBlockLighting();
|
||||
|
||||
void fixSkyLighting();
|
||||
|
||||
boolean isEmpty();
|
||||
|
||||
public static class SkipReason {
|
||||
public static final byte NONE = 0;
|
||||
public static final byte AIR = 1;
|
||||
public static final byte SOLID = 2;
|
||||
}
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
package com.boydti.fawe.example;
|
||||
|
||||
import com.boydti.fawe.object.FaweChunk;
|
||||
import com.boydti.fawe.object.FaweQueue;
|
||||
import com.boydti.fawe.util.MainUtil;
|
||||
|
||||
public class SimpleIntFaweChunk extends IntFaweChunk {
|
||||
|
||||
public SimpleIntFaweChunk(FaweQueue parent, int x, int z) {
|
||||
super(parent, x, z);
|
||||
}
|
||||
|
||||
public SimpleIntFaweChunk(FaweQueue parent, int x, int z, int[][] ids, short[] count, short[] air) {
|
||||
super(parent, x, z, ids, count, air);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getNewChunk() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IntFaweChunk copy(boolean shallow) {
|
||||
SimpleIntFaweChunk copy;
|
||||
if (shallow) {
|
||||
copy = new SimpleIntFaweChunk(getParent(), getX(), getZ(), setBlocks, count, air);
|
||||
copy.biomes = biomes;
|
||||
} else {
|
||||
copy = new SimpleIntFaweChunk(getParent(), getX(), getZ(), (int[][]) MainUtil.copyNd(setBlocks), count.clone(), air.clone());
|
||||
copy.biomes = biomes != null ? biomes.clone() : null;
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FaweChunk call() {
|
||||
getParent().setChunk(this);
|
||||
return this;
|
||||
}
|
||||
}
|
@ -1,242 +0,0 @@
|
||||
package com.boydti.fawe.example;
|
||||
|
||||
import com.boydti.fawe.Fawe;
|
||||
import com.boydti.fawe.object.FaweChunk;
|
||||
import com.boydti.fawe.object.FaweQueue;
|
||||
import com.boydti.fawe.object.RunnableVal;
|
||||
import com.boydti.fawe.util.MathMan;
|
||||
import com.boydti.fawe.util.SetQueue;
|
||||
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
||||
import java.lang.ref.Reference;
|
||||
import java.lang.ref.SoftReference;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutorCompletionService;
|
||||
import java.util.concurrent.ForkJoinPool;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class WeakFaweQueueMap implements IFaweQueueMap {
|
||||
|
||||
private final MappedFaweQueue parent;
|
||||
|
||||
public WeakFaweQueueMap(MappedFaweQueue parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public final Long2ObjectOpenHashMap<Reference<FaweChunk>> blocks = new Long2ObjectOpenHashMap<Reference<FaweChunk>>() {
|
||||
@Override
|
||||
public Reference<FaweChunk> put(Long key, Reference<FaweChunk> value) {
|
||||
return put((long) key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Reference<FaweChunk> put(long key, Reference<FaweChunk> value) {
|
||||
if (parent.getProgressTask() != null) {
|
||||
try {
|
||||
parent.getProgressTask().run(FaweQueue.ProgressType.QUEUE, size());
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
synchronized (this) {
|
||||
return super.put(key, value);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public Collection<FaweChunk> getFaweChunks() {
|
||||
HashSet<FaweChunk> set = new HashSet<>();
|
||||
synchronized (blocks) {
|
||||
Iterator<Map.Entry<Long, Reference<FaweChunk>>> iter = blocks.entrySet().iterator();
|
||||
while (iter.hasNext()) {
|
||||
Map.Entry<Long, Reference<FaweChunk>> entry = iter.next();
|
||||
FaweChunk value = entry.getValue().get();
|
||||
if (value != null) {
|
||||
set.add(value);
|
||||
} else {
|
||||
Fawe.debug("Skipped modifying chunk due to low memory (1)");
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
return set;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachChunk(RunnableVal<FaweChunk> onEach) {
|
||||
synchronized (blocks) {
|
||||
Iterator<Map.Entry<Long, Reference<FaweChunk>>> iter = blocks.entrySet().iterator();
|
||||
while (iter.hasNext()) {
|
||||
Map.Entry<Long, Reference<FaweChunk>> entry = iter.next();
|
||||
FaweChunk value = entry.getValue().get();
|
||||
if (value != null) {
|
||||
onEach.run(value);
|
||||
} else {
|
||||
Fawe.debug("Skipped modifying chunk due to low memory (2)");
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public FaweChunk getFaweChunk(int cx, int cz) {
|
||||
if (cx == lastX && cz == lastZ) {
|
||||
return lastWrappedChunk;
|
||||
}
|
||||
long pair = MathMan.pairInt(cx, cz);
|
||||
Reference<FaweChunk> chunkReference = this.blocks.get(pair);
|
||||
FaweChunk chunk;
|
||||
if (chunkReference == null || (chunk = chunkReference.get()) == null) {
|
||||
chunk = this.getNewFaweChunk(cx, cz);
|
||||
Reference<FaweChunk> previous = this.blocks.put(pair, new SoftReference(chunk));
|
||||
if (previous != null) {
|
||||
FaweChunk tmp = previous.get();
|
||||
if (tmp != null) {
|
||||
chunk = tmp;
|
||||
this.blocks.put(pair, previous);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return chunk;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FaweChunk getCachedFaweChunk(int cx, int cz) {
|
||||
if (cx == lastX && cz == lastZ) {
|
||||
return lastWrappedChunk;
|
||||
}
|
||||
long pair = MathMan.pairInt(cx, cz);
|
||||
Reference<FaweChunk> reference = this.blocks.get(pair);
|
||||
if (reference != null) {
|
||||
return reference.get();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(FaweChunk chunk) {
|
||||
long pair = MathMan.pairInt(chunk.getX(), chunk.getZ());
|
||||
Reference<FaweChunk> previous = this.blocks.put(pair, new SoftReference<>(chunk));
|
||||
if (previous != null) {
|
||||
FaweChunk previousChunk = previous.get();
|
||||
if (previousChunk != null) {
|
||||
blocks.put(pair, previous);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
blocks.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return blocks.size();
|
||||
}
|
||||
|
||||
private FaweChunk getNewFaweChunk(int cx, int cz) {
|
||||
return parent.getFaweChunk(cx, cz);
|
||||
}
|
||||
|
||||
private FaweChunk lastWrappedChunk;
|
||||
private int lastX = Integer.MIN_VALUE;
|
||||
private int lastZ = Integer.MIN_VALUE;
|
||||
|
||||
@Override
|
||||
public boolean next(int amount, long time) {
|
||||
synchronized (blocks) {
|
||||
try {
|
||||
boolean skip = parent.getStage() == SetQueue.QueueStage.INACTIVE;
|
||||
int added = 0;
|
||||
Iterator<Map.Entry<Long, Reference<FaweChunk>>> iter = blocks.entrySet().iterator();
|
||||
if (amount == 1) {
|
||||
long start = System.currentTimeMillis();
|
||||
do {
|
||||
if (iter.hasNext()) {
|
||||
Map.Entry<Long, Reference<FaweChunk>> entry = iter.next();
|
||||
Reference<FaweChunk> chunkReference = entry.getValue();
|
||||
FaweChunk chunk = chunkReference.get();
|
||||
if (skip && chunk == lastWrappedChunk) {
|
||||
continue;
|
||||
}
|
||||
iter.remove();
|
||||
if (chunk != null) {
|
||||
parent.start(chunk);
|
||||
chunk.call();
|
||||
parent.end(chunk);
|
||||
} else {
|
||||
Fawe.debug("Skipped modifying chunk due to low memory (3)");
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} while (System.currentTimeMillis() - start < time);
|
||||
return !blocks.isEmpty();
|
||||
}
|
||||
ExecutorCompletionService service = SetQueue.IMP.getCompleterService();
|
||||
ForkJoinPool pool = SetQueue.IMP.getForkJoinPool();
|
||||
boolean result = true;
|
||||
// amount = 8;
|
||||
for (int i = 0; i < amount && (result = iter.hasNext()); ) {
|
||||
Map.Entry<Long, Reference<FaweChunk>> item = iter.next();
|
||||
Reference<FaweChunk> chunkReference = item.getValue();
|
||||
FaweChunk chunk = chunkReference.get();
|
||||
if (skip && chunk == lastWrappedChunk) {
|
||||
continue;
|
||||
}
|
||||
iter.remove();
|
||||
if (chunk != null) {
|
||||
parent.start(chunk);
|
||||
service.submit(chunk);
|
||||
added++;
|
||||
i++;
|
||||
} else {
|
||||
Fawe.debug("Skipped modifying chunk due to low memory (4)");
|
||||
}
|
||||
}
|
||||
// if result, then submitted = amount
|
||||
if (result) {
|
||||
long start = System.currentTimeMillis();
|
||||
while (System.currentTimeMillis() - start < time && result) {
|
||||
if (result = iter.hasNext()) {
|
||||
Map.Entry<Long, Reference<FaweChunk>> item = iter.next();
|
||||
Reference<FaweChunk> chunkReference = item.getValue();
|
||||
FaweChunk chunk = chunkReference.get();
|
||||
if (skip && chunk == lastWrappedChunk) {
|
||||
continue;
|
||||
}
|
||||
iter.remove();
|
||||
if (chunk != null) {
|
||||
parent.start(chunk);
|
||||
service.submit(chunk);
|
||||
Future future = service.poll(50, TimeUnit.MILLISECONDS);
|
||||
if (future != null) {
|
||||
FaweChunk fc = (FaweChunk) future.get();
|
||||
parent.end(fc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
pool.awaitQuiescence(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
|
||||
Future future;
|
||||
while ((future = service.poll()) != null) {
|
||||
FaweChunk fc = (FaweChunk) future.get();
|
||||
parent.end(fc);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return !blocks.isEmpty();
|
||||
}
|
||||
}
|
||||
}
|
@ -40,7 +40,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);
|
||||
});
|
||||
@ -55,12 +55,6 @@ public class NBTStreamer {
|
||||
readers.put(node, run);
|
||||
}
|
||||
|
||||
public <T, V> void addReader(BiConsumer<T, V> run, String... nodes) {
|
||||
for (String node : nodes) {
|
||||
addReader(node, run);
|
||||
}
|
||||
}
|
||||
|
||||
public static abstract class NBTStreamReader<T, V> implements BiConsumer<T, V> {
|
||||
private String node;
|
||||
|
||||
@ -82,7 +76,7 @@ public class NBTStreamer {
|
||||
public abstract void run(int index, int byteValue);
|
||||
}
|
||||
|
||||
public static abstract class LazyReader implements BiConsumer<Integer, DataInputStream> {}
|
||||
public interface LazyReader extends BiConsumer<Integer, DataInputStream> {}
|
||||
|
||||
public static abstract class LongReader implements BiConsumer<Integer, Long> {
|
||||
@Override
|
||||
|
@ -57,21 +57,21 @@ public class SchematicStreamer extends NBTStreamer {
|
||||
}
|
||||
|
||||
public void addBlockReaders() throws IOException {
|
||||
NBTStreamReader idInit = new NBTStreamReader<Integer, Integer>() {
|
||||
NBTStreamReader<? extends Integer, ? extends Integer> idInit = new NBTStreamReader<Integer, Integer>() {
|
||||
@Override
|
||||
public void accept(Integer length, Integer type) {
|
||||
setupClipboard(length);
|
||||
ids = new FaweOutputStream(new LZ4BlockOutputStream(idOut));
|
||||
}
|
||||
};
|
||||
NBTStreamReader dataInit = new NBTStreamReader<Integer, Integer>() {
|
||||
NBTStreamReader<? extends Integer, ? extends Integer> dataInit = new NBTStreamReader<Integer, Integer>() {
|
||||
@Override
|
||||
public void accept(Integer length, Integer type) {
|
||||
setupClipboard(length);
|
||||
datas = new FaweOutputStream(new LZ4BlockOutputStream(dataOut));
|
||||
}
|
||||
};
|
||||
NBTStreamReader addInit = new NBTStreamReader<Integer, Integer>() {
|
||||
NBTStreamReader<? extends Integer, ? extends Integer> addInit = new NBTStreamReader<Integer, Integer>() {
|
||||
@Override
|
||||
public void accept(Integer length, Integer type) {
|
||||
setupClipboard(length*2);
|
||||
@ -225,19 +225,19 @@ public class SchematicStreamer extends NBTStreamer {
|
||||
Direction left = facing.getLeft();
|
||||
Direction right = facing.getRight();
|
||||
|
||||
BlockStateHolder forwardBlock = fc.getBlock(x + forward.getBlockX(), y + forward.getBlockY(), z + forward.getBlockZ());
|
||||
BlockStateHolder<com.sk89q.worldedit.world.block.BaseBlock> forwardBlock = fc.getBlock(x + forward.getBlockX(), y + forward.getBlockY(), z + forward.getBlockZ());
|
||||
BlockType forwardType = forwardBlock.getBlockType();
|
||||
if (forwardType.hasProperty(PropertyKey.SHAPE) && forwardType.hasProperty(PropertyKey.FACING)) {
|
||||
Direction forwardFacing = (Direction) forwardBlock.getState(PropertyKey.FACING);
|
||||
if (forwardFacing == left) {
|
||||
BlockStateHolder rightBlock = fc.getBlock(x + right.toBlockVector().getBlockX(), y + right.toBlockVector().getBlockY(), z + right.toBlockVector().getBlockZ());
|
||||
BlockStateHolder<com.sk89q.worldedit.world.block.BaseBlock> rightBlock = fc.getBlock(x + right.toBlockVector().getBlockX(), y + right.toBlockVector().getBlockY(), z + right.toBlockVector().getBlockZ());
|
||||
BlockType rightType = rightBlock.getBlockType();
|
||||
if (!rightType.hasProperty(PropertyKey.SHAPE) || rightBlock.getState(PropertyKey.FACING) != facing) {
|
||||
fc.setBlock(x, y, z, block.with(PropertyKey.SHAPE, "inner_left"));
|
||||
}
|
||||
return;
|
||||
} else if (forwardFacing == right) {
|
||||
BlockStateHolder leftBlock = fc.getBlock(x + left.toBlockVector().getBlockX(), y + left.toBlockVector().getBlockY(), z + left.toBlockVector().getBlockZ());
|
||||
BlockStateHolder<com.sk89q.worldedit.world.block.BaseBlock> leftBlock = fc.getBlock(x + left.toBlockVector().getBlockX(), y + left.toBlockVector().getBlockY(), z + left.toBlockVector().getBlockZ());
|
||||
BlockType leftType = leftBlock.getBlockType();
|
||||
if (!leftType.hasProperty(PropertyKey.SHAPE) || leftBlock.getState(PropertyKey.FACING) != facing) {
|
||||
fc.setBlock(x, y, z, block.with(PropertyKey.SHAPE, "inner_right"));
|
||||
@ -246,19 +246,19 @@ public class SchematicStreamer extends NBTStreamer {
|
||||
}
|
||||
}
|
||||
|
||||
BlockStateHolder backwardsBlock = fc.getBlock(x - forward.getBlockX(), y - forward.getBlockY(), z - forward.getBlockZ());
|
||||
BlockStateHolder<com.sk89q.worldedit.world.block.BaseBlock> backwardsBlock = fc.getBlock(x - forward.getBlockX(), y - forward.getBlockY(), z - forward.getBlockZ());
|
||||
BlockType backwardsType = backwardsBlock.getBlockType();
|
||||
if (backwardsType.hasProperty(PropertyKey.SHAPE) && backwardsType.hasProperty(PropertyKey.FACING)) {
|
||||
Direction backwardsFacing = (Direction) backwardsBlock.getState(PropertyKey.FACING);
|
||||
if (backwardsFacing == left) {
|
||||
BlockStateHolder rightBlock = fc.getBlock(x + right.toBlockVector().getBlockX(), y + right.toBlockVector().getBlockY(), z + right.toBlockVector().getBlockZ());
|
||||
BlockStateHolder<com.sk89q.worldedit.world.block.BaseBlock> rightBlock = fc.getBlock(x + right.toBlockVector().getBlockX(), y + right.toBlockVector().getBlockY(), z + right.toBlockVector().getBlockZ());
|
||||
BlockType rightType = rightBlock.getBlockType();
|
||||
if (!rightType.hasProperty(PropertyKey.SHAPE) || rightBlock.getState(PropertyKey.FACING) != facing) {
|
||||
fc.setBlock(x, y, z, block.with(PropertyKey.SHAPE, "outer_left"));
|
||||
}
|
||||
return;
|
||||
} else if (backwardsFacing == right) {
|
||||
BlockStateHolder leftBlock = fc.getBlock(x + left.toBlockVector().getBlockX(), y + left.toBlockVector().getBlockY(), z + left.toBlockVector().getBlockZ());
|
||||
BlockStateHolder<com.sk89q.worldedit.world.block.BaseBlock> leftBlock = fc.getBlock(x + left.toBlockVector().getBlockX(), y + left.toBlockVector().getBlockY(), z + left.toBlockVector().getBlockZ());
|
||||
BlockType leftType = leftBlock.getBlockType();
|
||||
if (!leftType.hasProperty(PropertyKey.SHAPE) || leftBlock.getState(PropertyKey.FACING) != facing) {
|
||||
fc.setBlock(x, y, z, block.with(PropertyKey.SHAPE, "outer_right"));
|
||||
@ -298,7 +298,7 @@ public class SchematicStreamer extends NBTStreamer {
|
||||
}, true).build();
|
||||
|
||||
private boolean merge(int group, int x, int y, int z) {
|
||||
BlockStateHolder block = fc.getBlock(x, y, z);
|
||||
BlockStateHolder<com.sk89q.worldedit.world.block.BaseBlock> block = fc.getBlock(x, y, z);
|
||||
BlockType type = block.getBlockType();
|
||||
return group(type) == group || fullCube.apply(type);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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]);
|
||||
|
@ -104,7 +104,7 @@ public class MCAWorld implements SimpleWorld {
|
||||
|
||||
@Override
|
||||
public BlockState getBlock(BlockVector3 position) {
|
||||
return extent.getLazyBlock(position);
|
||||
return extent.getBlock(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -3,6 +3,7 @@ package com.boydti.fawe.jnbt.anvil;
|
||||
import com.boydti.fawe.object.collection.IterableThreadLocal;
|
||||
import com.boydti.fawe.object.io.BufferedRandomAccessFile;
|
||||
import com.boydti.fawe.util.MainUtil;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.world.block.BlockID;
|
||||
|
||||
import java.io.File;
|
||||
@ -12,7 +13,7 @@ import java.util.concurrent.ForkJoinPool;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.zip.Deflater;
|
||||
|
||||
public abstract class MCAWriter {
|
||||
public abstract class MCAWriter implements Extent {
|
||||
private File folder;
|
||||
private final int length;
|
||||
private final int width;
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import com.sk89q.worldedit.math.MutableBlockVector3;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class OreGen extends Resource {
|
||||
public class OreGen implements Resource {
|
||||
private final int maxSize;
|
||||
private final double maxSizeO8;
|
||||
private final double maxSizeO16;
|
||||
@ -21,9 +21,9 @@ public class OreGen extends Resource {
|
||||
private final Mask mask;
|
||||
private MutableBlockVector3 mutable = new MutableBlockVector3();
|
||||
|
||||
private double ONE_2 = 1 / 2F;
|
||||
private double ONE_8 = 1 / 8F;
|
||||
private double ONE_16 = 1 / 16F;
|
||||
private final double ONE_2 = 1 / 2F;
|
||||
private final double ONE_8 = 1 / 8F;
|
||||
private final double ONE_16 = 1 / 16F;
|
||||
|
||||
public int laced = 0;
|
||||
|
||||
@ -47,16 +47,13 @@ public class OreGen extends Resource {
|
||||
}
|
||||
double f = rand.nextDouble() * Math.PI;
|
||||
|
||||
int x8 = x;
|
||||
int z8 = z;
|
||||
double so8 = maxSizeO8;
|
||||
double so16 = maxSizeO16;
|
||||
double sf = MathMan.sinInexact(f) * so8;
|
||||
double cf = MathMan.cosInexact(f) * so8;
|
||||
double d1 = x8 + sf;
|
||||
double d2 = x8 - sf;
|
||||
double d3 = z8 + cf;
|
||||
double d4 = z8 - cf;
|
||||
double d1 = x + sf;
|
||||
double d2 = x - sf;
|
||||
double d3 = z + cf;
|
||||
double d4 = z - cf;
|
||||
|
||||
double d5 = y + rand.nextInt(3) - 2;
|
||||
double d6 = y + rand.nextInt(3) - 2;
|
||||
@ -71,7 +68,7 @@ public class OreGen extends Resource {
|
||||
double d8 = d5 + yd * iFactor;
|
||||
double d9 = d3 + zd * iFactor;
|
||||
|
||||
double d10 = rand.nextDouble() * so16;
|
||||
double d10 = rand.nextDouble() * maxSizeO16;
|
||||
double sif = MathMan.sinInexact(Math.PI * iFactor);
|
||||
double d11 = (sif + 1.0) * d10 + 1.0;
|
||||
double d12 = (sif + 1.0) * d10 + 1.0;
|
||||
@ -116,4 +113,4 @@ public class OreGen extends Resource {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,8 +4,7 @@ import com.sk89q.worldedit.WorldEditException;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public abstract class Resource {
|
||||
public Resource() {}
|
||||
public interface Resource {
|
||||
|
||||
public abstract boolean spawn(Random random, int x, int z) throws WorldEditException;
|
||||
boolean spawn(Random random, int x, int z) throws WorldEditException;
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class SchemGen extends Resource {
|
||||
public class SchemGen implements Resource {
|
||||
|
||||
private final Extent extent;
|
||||
private final List<ClipboardHolder> clipboards;
|
||||
|
@ -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));
|
||||
|
@ -1,310 +0,0 @@
|
||||
package com.boydti.fawe.object;
|
||||
|
||||
import com.boydti.fawe.object.visitor.FaweChunkVisitor;
|
||||
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Callable;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public abstract class FaweChunk<T> implements Callable<FaweChunk> {
|
||||
public static int HEIGHT = 256;
|
||||
|
||||
private FaweQueue parent;
|
||||
private int x, z;
|
||||
|
||||
/**
|
||||
* A FaweSections object represents a chunk and the blocks that you wish to change in it.
|
||||
*/
|
||||
public FaweChunk(FaweQueue parent, int x, int z) {
|
||||
this.parent = parent;
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the chunk's location<br>
|
||||
* - E.g. if you are cloning a chunk and want to set multiple
|
||||
*
|
||||
* @param parent
|
||||
* @param x
|
||||
* @param z
|
||||
*/
|
||||
public void setLoc(FaweQueue parent, int x, int z) {
|
||||
this.parent = parent;
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the parent queue this chunk belongs to
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public FaweQueue getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public int getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a unique hashcode for this chunk
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public long longHash() {
|
||||
return (long) x << 32 | z & 0xFFFFFFFFL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a hashcode; unique below abs(x/z) < Short.MAX_VALUE
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return x << 16 | z & 0xFFFF;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the chunk to the queue
|
||||
*/
|
||||
public void addToQueue() {
|
||||
parent.setChunk(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* The modified sections
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract int getBitMask();
|
||||
|
||||
/**
|
||||
* Get the combined block id at a location<br>
|
||||
* combined = (id <<<< 4) + data
|
||||
*
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
* @return The combined id
|
||||
*/
|
||||
public abstract int getBlockCombinedId(int x, int y, int z);
|
||||
|
||||
public <B extends BlockStateHolder<B>> void setBlock(int x, int y, int z, B block) {
|
||||
setBlock(x, y, z, block.getInternalId());
|
||||
if (block instanceof BaseBlock && ((BaseBlock)block).hasNbtData()) {
|
||||
setTile(x & 15, y, z & 15, ((BaseBlock)block).getNbtData());
|
||||
}
|
||||
}
|
||||
|
||||
public BlockState getBlock(int x, int y, int z) {
|
||||
int combined = getBlockCombinedId(x, y, z);
|
||||
// TODO FIXME optimize get nbt
|
||||
try {
|
||||
CompoundTag tile = getTile(x & 15, y, z & 15);
|
||||
if (tile != null) {
|
||||
return BaseBlock.getFromInternalId(combined, tile).toImmutableState();
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return BlockState.getFromInternalId(combined);
|
||||
}
|
||||
|
||||
public int[][] getCombinedIdArrays() {
|
||||
int[][] ids = new int[HEIGHT >> 4][];
|
||||
for (int layer = 0; layer < HEIGHT >> 4; layer++) {
|
||||
ids[layer] = getIdArray(layer);
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the combined id array at a layer or null if it does not exist
|
||||
*
|
||||
* @param layer
|
||||
* @return int[] or null
|
||||
*/
|
||||
public
|
||||
@Nullable
|
||||
int[] getIdArray(int layer) {
|
||||
int[] ids = new int[4096];
|
||||
int by = layer << 4;
|
||||
int index = 0;
|
||||
for (int y = 0; y < 16; y++) {
|
||||
int yy = by + y;
|
||||
for (int z = 0; z < 16; z++) {
|
||||
for (int x = 0; x < 16; x++) {
|
||||
ids[index++] = getBlockCombinedId(x, yy, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
||||
public byte[][] getBlockLightArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public byte[][] getSkyLightArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public abstract BiomeType[] getBiomeArray();
|
||||
|
||||
public BiomeType getBiomeType(int x, int z) {
|
||||
return getBiomeArray()[(x & 15) + ((z & 15) << 4)];
|
||||
}
|
||||
|
||||
public void forEachQueuedBlock(FaweChunkVisitor onEach) {
|
||||
for (int y = 0; y < HEIGHT; y++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
for (int x = 0; x < 16; x++) {
|
||||
int combined = getBlockCombinedId(x, y, z);
|
||||
if (combined == 0) {
|
||||
continue;
|
||||
}
|
||||
onEach.run(x, y, z, combined);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill this chunk with a block
|
||||
*
|
||||
* @param combinedId
|
||||
*/
|
||||
public void fill(int combinedId) {
|
||||
fillCuboid(0, 15, 0, HEIGHT - 1, 0, 15, combinedId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill a cuboid in this chunk with a block
|
||||
*
|
||||
* @param x1
|
||||
* @param x2
|
||||
* @param y1
|
||||
* @param y2
|
||||
* @param z1
|
||||
* @param z2
|
||||
* @param combinedId
|
||||
*/
|
||||
public void fillCuboid(int x1, int x2, int y1, int y2, int z1, int z2, int combinedId) {
|
||||
for (int x = x1; x <= x2; x++) {
|
||||
for (int y = y1; y <= y2; y++) {
|
||||
for (int z = z1; z <= z2; z++) {
|
||||
setBlock(x, y, z, combinedId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying chunk object
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract T getChunk();
|
||||
|
||||
/**
|
||||
* Set a tile entity at a location<br>
|
||||
* - May throw an error if an invalid block is at the location
|
||||
*
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
* @param tile
|
||||
*/
|
||||
public abstract void setTile(int x, int y, int z, CompoundTag tile);
|
||||
|
||||
public abstract void setEntity(CompoundTag entity);
|
||||
|
||||
public abstract void removeEntity(UUID uuid);
|
||||
|
||||
public abstract void setBlock(int x, int y, int z, int combinedId);
|
||||
|
||||
public abstract Set<CompoundTag> getEntities();
|
||||
|
||||
/**
|
||||
* Get the UUID of entities being removed
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract Set<UUID> getEntityRemoves();
|
||||
|
||||
/**
|
||||
* Get the map of location to tile entity<br>
|
||||
* - The byte pair represents the location in the chunk<br>
|
||||
*
|
||||
* @return
|
||||
* @see com.boydti.fawe.util.MathMan#unpair16x (get0) => x
|
||||
* @see com.boydti.fawe.util.MathMan#unpair16y (get0) => z
|
||||
* get1 => y
|
||||
*/
|
||||
public abstract Map<Short, CompoundTag> getTiles();
|
||||
|
||||
/**
|
||||
* Get the tile at a location
|
||||
*
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
* @return
|
||||
*/
|
||||
public abstract CompoundTag getTile(int x, int y, int z);
|
||||
|
||||
public abstract void setBiome(final int x, final int z, final BiomeType biome);
|
||||
|
||||
public void setBiome(final BiomeType biome) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
for (int x = 0; x < 16; x++) {
|
||||
setBiome(x, z, biome);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Spend time now so that the chunk can be more efficiently dispatched later<br>
|
||||
* - Modifications after this call will be ignored
|
||||
*/
|
||||
public void optimize() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if ((obj == null) || obj.hashCode() != hashCode() || !(obj instanceof FaweChunk)) {
|
||||
return false;
|
||||
}
|
||||
return longHash() != ((FaweChunk) obj).longHash();
|
||||
}
|
||||
|
||||
public abstract FaweChunk<T> copy(boolean shallow);
|
||||
|
||||
public void start() {
|
||||
}
|
||||
|
||||
;
|
||||
|
||||
public void end() {
|
||||
}
|
||||
|
||||
;
|
||||
|
||||
@Override
|
||||
public abstract FaweChunk call();
|
||||
}
|
@ -236,9 +236,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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -661,39 +661,4 @@ public abstract class FawePlayer<T> extends Metadatable {
|
||||
}
|
||||
return proxy;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the tracked EditSession(s) for this player<br>
|
||||
* - Queued or autoqueued EditSessions are considered tracked
|
||||
*
|
||||
* @param requiredStage
|
||||
* @return
|
||||
*/
|
||||
public Map<EditSession, SetQueue.QueueStage> getTrackedSessions(SetQueue.QueueStage requiredStage) {
|
||||
Map<EditSession, SetQueue.QueueStage> map = new ConcurrentHashMap<>(8, 0.9f, 1);
|
||||
if (requiredStage == null || requiredStage == SetQueue.QueueStage.ACTIVE) {
|
||||
for (FaweQueue queue : SetQueue.IMP.getActiveQueues()) {
|
||||
Collection<EditSession> sessions = queue.getEditSessions();
|
||||
for (EditSession session : sessions) {
|
||||
FawePlayer currentPlayer = session.getPlayer();
|
||||
if (currentPlayer == this) {
|
||||
map.put(session, SetQueue.QueueStage.ACTIVE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (requiredStage == null || requiredStage == SetQueue.QueueStage.INACTIVE) {
|
||||
for (FaweQueue queue : SetQueue.IMP.getInactiveQueues()) {
|
||||
Collection<EditSession> sessions = queue.getEditSessions();
|
||||
for (EditSession session : sessions) {
|
||||
FawePlayer currentPlayer = session.getPlayer();
|
||||
if (currentPlayer == this) {
|
||||
map.put(session, SetQueue.QueueStage.INACTIVE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +0,0 @@
|
||||
package com.boydti.fawe.object;
|
||||
|
||||
public interface HasFaweQueue {
|
||||
FaweQueue getQueue();
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -53,11 +53,6 @@ public class NullChangeSet extends FaweChangeSet {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addChangeTask(FaweQueue queue) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<Change> getIterator(BlockBag blockBag, int mode, boolean redo) {
|
||||
return getIterator(redo);
|
||||
|
@ -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];
|
||||
|
@ -27,8 +27,6 @@ public class ShatterBrush extends ScatterBrush {
|
||||
@Override
|
||||
public void finish(EditSession editSession, LocalBlockVectorSet placed, final BlockVector3 position, Pattern pattern, double size) {
|
||||
int radius2 = (int) (size * size);
|
||||
// Keep track of where we've visited
|
||||
LocalBlockVectorSet tmp = new LocalBlockVectorSet();
|
||||
// Individual frontier for each point
|
||||
LocalBlockVectorSet[] frontiers = new LocalBlockVectorSet[placed.size()];
|
||||
// Keep track of where each frontier has visited
|
||||
@ -51,6 +49,8 @@ public class ShatterBrush extends ScatterBrush {
|
||||
final SurfaceMask surfaceTest = new SurfaceMask(editSession);
|
||||
// Expand
|
||||
boolean notEmpty = true;
|
||||
// Keep track of where we've visited
|
||||
LocalBlockVectorSet tmp = new LocalBlockVectorSet();
|
||||
while (notEmpty) {
|
||||
notEmpty = false;
|
||||
for (i = 0; i < frontiers.length; i++) {
|
||||
@ -59,37 +59,33 @@ public class ShatterBrush extends ScatterBrush {
|
||||
final LocalBlockVectorSet frontierVisited = frontiersVisited[i];
|
||||
// This is a temporary set with the next blocks the frontier will visit
|
||||
final LocalBlockVectorSet finalTmp = tmp;
|
||||
frontier.forEach(new LocalBlockVectorSet.BlockVectorSetVisitor() {
|
||||
@Override
|
||||
public void run(int x, int y, int z, int index) {
|
||||
if (ThreadLocalRandom.current().nextInt(2) == 0) {
|
||||
finalTmp.add(x, y, z);
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < BreadthFirstSearch.DIAGONAL_DIRECTIONS.length; i++) {
|
||||
BlockVector3 direction = BreadthFirstSearch.DIAGONAL_DIRECTIONS[i];
|
||||
int x2 = x + direction.getBlockX();
|
||||
int y2 = y + direction.getBlockY();
|
||||
int z2 = z + direction.getBlockZ();
|
||||
// Check boundary
|
||||
int dx = position.getBlockX() - x2;
|
||||
int dy = position.getBlockY() - y2;
|
||||
int dz = position.getBlockZ() - z2;
|
||||
int dSqr = (dx * dx) + (dy * dy) + (dz * dz);
|
||||
if (dSqr <= radius2) {
|
||||
MutableBlockVector3 v = mutable.setComponents(x2, y2, z2);
|
||||
BlockVector3 bv = v;
|
||||
if (surfaceTest.test(bv) && finalMask.test(bv)) {
|
||||
// (collision) If it's visited and part of another frontier, set the block
|
||||
if (!placed.add(x2, y2, z2)) {
|
||||
if (!frontierVisited.contains(x2, y2, z2)) {
|
||||
editSession.setBlock(x2, y2, z2, pattern);
|
||||
}
|
||||
} else {
|
||||
// Hasn't visited and not a collision = add it
|
||||
finalTmp.add(x2, y2, z2);
|
||||
frontierVisited.add(x2, y2, z2);
|
||||
frontier.forEach((x, y, z, index) -> {
|
||||
if (ThreadLocalRandom.current().nextInt(2) == 0) {
|
||||
finalTmp.add(x, y, z);
|
||||
return;
|
||||
}
|
||||
for (int i1 = 0; i1 < BreadthFirstSearch.DIAGONAL_DIRECTIONS.length; i1++) {
|
||||
BlockVector3 direction = BreadthFirstSearch.DIAGONAL_DIRECTIONS[i1];
|
||||
int x2 = x + direction.getBlockX();
|
||||
int y2 = y + direction.getBlockY();
|
||||
int z2 = z + direction.getBlockZ();
|
||||
// Check boundary
|
||||
int dx = position.getBlockX() - x2;
|
||||
int dy = position.getBlockY() - y2;
|
||||
int dz = position.getBlockZ() - z2;
|
||||
int dSqr = (dx * dx) + (dy * dy) + (dz * dz);
|
||||
if (dSqr <= radius2) {
|
||||
BlockVector3 bv = mutable.setComponents(x2, y2, z2);
|
||||
if (surfaceTest.test(bv) && finalMask.test(bv)) {
|
||||
// (collision) If it's visited and part of another frontier, set the block
|
||||
if (!placed.add(x2, y2, z2)) {
|
||||
if (!frontierVisited.contains(x2, y2, z2)) {
|
||||
editSession.setBlock(x2, y2, z2, pattern);
|
||||
}
|
||||
} else {
|
||||
// Hasn't visited and not a collision = add it
|
||||
finalTmp.add(x2, y2, z2);
|
||||
frontierVisited.add(x2, y2, z2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
|
@ -1,14 +1,12 @@
|
||||
package com.boydti.fawe.object.brush.visualization;
|
||||
|
||||
import com.boydti.fawe.FaweCache;
|
||||
import com.boydti.fawe.example.IntFaweChunk;
|
||||
import com.boydti.fawe.example.NullQueueIntFaweChunk;
|
||||
import com.boydti.fawe.object.FawePlayer;
|
||||
import com.boydti.fawe.object.FaweQueue;
|
||||
import com.boydti.fawe.object.visitor.FaweChunkVisitor;
|
||||
import com.boydti.fawe.util.MathMan;
|
||||
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.extent.AbstractDelegateExtent;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
@ -17,7 +15,6 @@ import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectIterator;
|
||||
|
||||
public class VisualExtent extends AbstractDelegateExtent {
|
||||
|
||||
@ -40,7 +37,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);
|
||||
@ -67,9 +64,7 @@ public class VisualExtent extends AbstractDelegateExtent {
|
||||
}
|
||||
|
||||
public void clear(VisualExtent other, FawePlayer... players) {
|
||||
ObjectIterator<Long2ObjectMap.Entry<VisualChunk>> iter = chunks.long2ObjectEntrySet().iterator();
|
||||
while (iter.hasNext()) {
|
||||
Long2ObjectMap.Entry<VisualChunk> entry = iter.next();
|
||||
for (Long2ObjectMap.Entry<VisualChunk> entry : chunks.long2ObjectEntrySet()) {
|
||||
long pair = entry.getLongKey();
|
||||
int cx = MathMan.unpairIntX(pair);
|
||||
int cz = MathMan.unpairIntY(pair);
|
||||
@ -79,21 +74,15 @@ public class VisualExtent extends AbstractDelegateExtent {
|
||||
final int bx = cx << 4;
|
||||
final int bz = cz << 4;
|
||||
if (otherChunk == null) {
|
||||
chunk.forEachQueuedBlock(new FaweChunkVisitor() {
|
||||
@Override
|
||||
public void run(int localX, int y, int localZ, int combined) {
|
||||
combined = queue.getCombinedId4Data(bx + localX, y, bz + localZ, 0);
|
||||
newChunk.setBlock(localX, y, localZ, combined);
|
||||
}
|
||||
chunk.forEachQueuedBlock((localX, y, localZ, combined) -> {
|
||||
combined = queue.getCombinedId4Data(bx + localX, y, bz + localZ, 0);
|
||||
newChunk.setBlock(localX, y, localZ, combined);
|
||||
});
|
||||
} else {
|
||||
chunk.forEachQueuedBlock(new FaweChunkVisitor() {
|
||||
@Override
|
||||
public void run(int localX, int y, int localZ, int combined) {
|
||||
if (combined != otherChunk.getBlockCombinedId(localX, y, localZ)) {
|
||||
combined = queue.getCombinedId4Data(bx + localX, y, bz + localZ, 0);
|
||||
newChunk.setBlock(localX, y, localZ, combined);
|
||||
}
|
||||
chunk.forEachQueuedBlock((localX, y, localZ, combined) -> {
|
||||
if (combined != otherChunk.getBlockCombinedId(localX, y, localZ)) {
|
||||
combined = queue.getCombinedId4Data(bx + localX, y, bz + localZ, 0);
|
||||
newChunk.setBlock(localX, y, localZ, combined);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -1,15 +1,14 @@
|
||||
package com.boydti.fawe.object.clipboard;
|
||||
|
||||
import com.boydti.fawe.jnbt.NBTStreamer;
|
||||
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
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.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -1,21 +1,18 @@
|
||||
package com.boydti.fawe.object.clipboard;
|
||||
|
||||
import com.boydti.fawe.FaweCache;
|
||||
import com.boydti.fawe.jnbt.NBTStreamer;
|
||||
import com.boydti.fawe.object.IntegerTrio;
|
||||
import com.boydti.fawe.util.ReflectionUtils;
|
||||
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.jnbt.IntTag;
|
||||
import com.sk89q.jnbt.Tag;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
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.BlockState;
|
||||
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;
|
||||
@ -239,9 +236,9 @@ public class CPUOptimizedClipboard extends FaweClipboard {
|
||||
@Override
|
||||
public <B extends BlockStateHolder<B>> boolean setBlock(int index, B block) {
|
||||
states[index] = block.getInternalId();
|
||||
boolean hasNbt = block instanceof BaseBlock && ((BaseBlock)block).hasNbtData();
|
||||
boolean hasNbt = block instanceof BaseBlock && block.hasNbtData();
|
||||
if (hasNbt) {
|
||||
setTile(index, ((BaseBlock)block).getNbtData());
|
||||
setTile(index, block.getNbtData());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ public class EmptyClipboard implements Clipboard {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getLazyBlock(BlockVector3 position) {
|
||||
public BlockState getBlock(BlockVector3 position) {
|
||||
return BlockTypes.AIR.getDefaultState();
|
||||
}
|
||||
|
||||
|
@ -2,27 +2,24 @@ package com.boydti.fawe.object.clipboard;
|
||||
|
||||
import com.boydti.fawe.jnbt.NBTStreamer;
|
||||
import com.boydti.fawe.util.ReflectionUtils;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.jnbt.IntTag;
|
||||
import com.sk89q.jnbt.Tag;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
public abstract class FaweClipboard {
|
||||
public abstract BaseBlock getBlock(int x, int y, int z);
|
||||
@ -66,8 +63,8 @@ public abstract class FaweClipboard {
|
||||
*/
|
||||
public abstract void forEach(BlockReader task, boolean air);
|
||||
|
||||
public static abstract class BlockReader {
|
||||
public abstract <B extends BlockStateHolder<B>> void run(int x, int y, int z, B block);
|
||||
public interface BlockReader {
|
||||
<B extends BlockStateHolder<B>> void run(int x, int y, int z, B block);
|
||||
}
|
||||
|
||||
public abstract void streamBiomes(final NBTStreamer.ByteReader task);
|
||||
@ -86,7 +83,6 @@ public abstract class FaweClipboard {
|
||||
public List<CompoundTag> getTileEntities() {
|
||||
final List<CompoundTag> tiles = new ArrayList<>();
|
||||
forEach(new BlockReader() {
|
||||
private int index = 0;
|
||||
|
||||
@Override
|
||||
public <B extends BlockStateHolder<B>> void run(int x, int y, int z, B block) {
|
||||
|
@ -3,7 +3,6 @@ package com.boydti.fawe.object.clipboard;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
|
||||
public class OffsetFaweClipboard extends AbstractDelegateFaweClipboard {
|
||||
|
@ -1,17 +1,15 @@
|
||||
package com.boydti.fawe.object.clipboard;
|
||||
|
||||
import com.boydti.fawe.jnbt.NBTStreamer;
|
||||
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -79,22 +79,19 @@ public class WorldCopyClipboard extends ReadOnlyClipboard {
|
||||
if (region instanceof CuboidRegion) {
|
||||
if (air) {
|
||||
((CuboidRegion) region).setUseOldIterator(true);
|
||||
RegionVisitor visitor = new RegionVisitor(region, new RegionFunction() {
|
||||
@Override
|
||||
public boolean apply(BlockVector3 pos) throws WorldEditException {
|
||||
BaseBlock block = getBlockAbs(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ());
|
||||
int x = pos.getBlockX() - mx;
|
||||
int y = pos.getBlockY() - my;
|
||||
int z = pos.getBlockZ() - mz;
|
||||
if (block.hasNbtData()) {
|
||||
Map<String, Tag> values = ReflectionUtils.getMap(block.getNbtData().getValue());
|
||||
values.put("x", new IntTag(x));
|
||||
values.put("y", new IntTag(y));
|
||||
values.put("z", new IntTag(z));
|
||||
}
|
||||
task.run(x, y, z, block);
|
||||
return true;
|
||||
RegionVisitor visitor = new RegionVisitor(region, pos1 -> {
|
||||
BaseBlock block = getBlockAbs(pos1.getBlockX(), pos1.getBlockY(), pos1.getBlockZ());
|
||||
int x = pos1.getBlockX() - mx;
|
||||
int y = pos1.getBlockY() - my;
|
||||
int z = pos1.getBlockZ() - mz;
|
||||
if (block.hasNbtData()) {
|
||||
Map<String, Tag> values = ReflectionUtils.getMap(block.getNbtData().getValue());
|
||||
values.put("x", new IntTag(x));
|
||||
values.put("y", new IntTag(y));
|
||||
values.put("z", new IntTag(z));
|
||||
}
|
||||
task.run(x, y, z, block);
|
||||
return true;
|
||||
}, extent instanceof EditSession ? (EditSession) extent : null);
|
||||
Operations.completeBlindly(visitor);
|
||||
} else {
|
||||
@ -107,7 +104,6 @@ public class WorldCopyClipboard extends ReadOnlyClipboard {
|
||||
int y = pos.getBlockY() - my;
|
||||
int z = pos.getBlockZ() - mz;
|
||||
if (region.contains(pos)) {
|
||||
// BlockState block = getBlockAbs(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ());
|
||||
BaseBlock block = extent.getFullBlock(pos);
|
||||
if (block.hasNbtData()) {
|
||||
Map<String, Tag> values = ReflectionUtils.getMap(block.getNbtData().getValue());
|
||||
@ -118,9 +114,8 @@ public class WorldCopyClipboard extends ReadOnlyClipboard {
|
||||
if (!block.getBlockType().getMaterial().isAir()) {
|
||||
task.run(x, y, z, block);
|
||||
}
|
||||
} else {
|
||||
// task.run(x, y, z, EditSession.nullBlock);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}, extent instanceof EditSession ? (EditSession) extent : null);
|
||||
|
@ -25,6 +25,7 @@ public class WorldCutClipboard extends WorldCopyClipboard {
|
||||
return block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBlock getBlockAbs(int x, int y, int z) {
|
||||
BaseBlock block = extent.getFullBlock(BlockVector3.at(x, y, z));
|
||||
extent.setBlock(x, y, z, BlockTypes.AIR.getDefaultState());
|
||||
|
@ -1,72 +0,0 @@
|
||||
package com.boydti.fawe.object.clipboard.remap;
|
||||
|
||||
import com.boydti.fawe.jnbt.NBTStreamer;
|
||||
import com.boydti.fawe.object.clipboard.AbstractDelegateFaweClipboard;
|
||||
import com.boydti.fawe.object.clipboard.FaweClipboard;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
|
||||
// TODO FIXME
|
||||
public class RemappedClipboard extends AbstractDelegateFaweClipboard {
|
||||
private final ClipboardRemapper remapper;
|
||||
|
||||
public RemappedClipboard(FaweClipboard parent, ClipboardRemapper remapper) {
|
||||
super(parent);
|
||||
this.remapper = remapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBlock getBlock(int x, int y, int z) {
|
||||
return remapper.remap(super.getBlock(x, y, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBlock getBlock(int index) {
|
||||
return remapper.remap(super.getBlock(index));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(BlockReader task, boolean air) {
|
||||
super.forEach(new BlockReader() {
|
||||
@Override
|
||||
public <B extends BlockStateHolder<B>> void run(int x, int y, int z, B block) {
|
||||
task.run(x, y, z, remapper.remap(block));
|
||||
}
|
||||
}, air);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void streamCombinedIds(NBTStreamer.ByteReader task) {
|
||||
super.streamCombinedIds(task);
|
||||
}
|
||||
//
|
||||
// @Override
|
||||
// public void streamIds(NBTStreamer.ByteReader task) {
|
||||
// super.streamIds(new NBTStreamer.ByteReader() {
|
||||
// @Override
|
||||
// public void run(int index, int byteValue) {
|
||||
// if (remapper.hasRemapId(byteValue)) {
|
||||
// int result = remapper.remapId(byteValue);
|
||||
// if (result != byteValue) {
|
||||
// task.run(index, result);
|
||||
// } else {
|
||||
// task.run(index, getBlock(index).getId());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void streamDatas(NBTStreamer.ByteReader task) {
|
||||
// super.streamDatas(new NBTStreamer.ByteReader() {
|
||||
// @Override
|
||||
// public void run(int index, int byteValue) {
|
||||
// if (remapper.hasRemapData(byteValue)) {
|
||||
// task.run(index, getBlock(index).getData());
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
}
|
@ -2,14 +2,18 @@ package com.boydti.fawe.object.clipboard.remap;
|
||||
|
||||
|
||||
import com.boydti.fawe.util.MainUtil;
|
||||
|
||||
import com.google.common.io.Resources;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@ -23,7 +27,7 @@ public class WikiScraper {
|
||||
Wiki(String url) {this.url = url;}
|
||||
}
|
||||
|
||||
private Map<Wiki, Map<String, Integer>> cache = new HashMap<>();
|
||||
private EnumMap<Wiki, Map<String, Integer>> cache = new EnumMap<>(WikiScraper.Wiki.class);
|
||||
|
||||
public Map<String, Integer> expand(Map<String, Integer> map) {
|
||||
HashMap<String, Integer> newMap = new HashMap<>(map);
|
||||
@ -50,8 +54,8 @@ public class WikiScraper {
|
||||
String str = Resources.toString(file.toURL(), Charset.defaultCharset());
|
||||
return gson.fromJson(str, new TypeToken<Map<String, Integer>>() {
|
||||
}.getType());
|
||||
} catch (Throwable ignore) {
|
||||
ignore.printStackTrace();
|
||||
} catch (JsonSyntaxException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
map = scrape(wiki);
|
||||
@ -94,15 +98,15 @@ public class WikiScraper {
|
||||
return map;
|
||||
} else {
|
||||
String header = wiki == Wiki.ITEM_MAPPINGS_PE ? "=== Item IDs ===" : "{{";
|
||||
String footer = "{{-}}";
|
||||
String prefix = "{{id table|";
|
||||
|
||||
int headerIndex = text.indexOf(header);
|
||||
if (headerIndex == -1) return map;
|
||||
String footer = "{{-}}";
|
||||
int endIndex = text.indexOf(footer, headerIndex);
|
||||
String part = text.substring(headerIndex, endIndex == -1 ? text.length() : endIndex);
|
||||
|
||||
int id = 255;
|
||||
String prefix = "{{id table|";
|
||||
for (String line : part.split("\n")) {
|
||||
String lower = line.toLowerCase();
|
||||
if (lower.startsWith(prefix)) {
|
||||
|
@ -0,0 +1,135 @@
|
||||
package com.boydti.fawe.object.collection;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Collections2;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import java.util.Spliterator;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Adapt a collection to a set
|
||||
* (It's assumed that the collection is set like, otherwise behavior will be weird)
|
||||
*
|
||||
* @param <T>
|
||||
*/
|
||||
public class AdaptedSetCollection<T, V> implements Set<V> {
|
||||
private final Function<T, V> adapter;
|
||||
private final Collection<V> adapted;
|
||||
private final Collection<T> original;
|
||||
|
||||
public AdaptedSetCollection(Collection<T> collection, Function<T, V> adapter) {
|
||||
this.original = collection;
|
||||
this.adapted = Collections2.transform(collection, adapter);
|
||||
this.adapter = adapter;
|
||||
}
|
||||
|
||||
public Collection<T> getOriginal() {
|
||||
return original;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return adapted.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return adapted.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Object o) {
|
||||
return adapted.contains(o);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Iterator<V> iterator() {
|
||||
return adapted.iterator();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Object[] toArray() {
|
||||
return adapted.toArray();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public <V> V[] toArray(@NotNull V[] a) {
|
||||
return adapted.toArray(a);
|
||||
}
|
||||
|
||||
public boolean add(V v) {
|
||||
return adapted.add(v);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(Object o) {
|
||||
return adapted.remove(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsAll(@NotNull Collection<?> c) {
|
||||
return adapted.containsAll(c);
|
||||
}
|
||||
|
||||
public boolean addAll(@NotNull Collection<? extends V> c) {
|
||||
return adapted.addAll(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeAll(@NotNull Collection<?> c) {
|
||||
return adapted.removeAll(c);
|
||||
}
|
||||
|
||||
public boolean removeIf(Predicate<? super V> filter) {
|
||||
return adapted.removeIf(filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean retainAll(@NotNull Collection<?> c) {
|
||||
return adapted.retainAll(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
adapted.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return adapted.equals(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return adapted.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Spliterator<V> spliterator() {
|
||||
return adapted.spliterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<V> stream() {
|
||||
return adapted.stream();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<V> parallelStream() {
|
||||
return adapted.parallelStream();
|
||||
}
|
||||
|
||||
public void forEach(Consumer<? super V> action) {
|
||||
adapted.forEach(action);
|
||||
}
|
||||
}
|
@ -0,0 +1,112 @@
|
||||
package com.boydti.fawe.object.collection;
|
||||
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.AbstractRegion;
|
||||
import com.sk89q.worldedit.regions.RegionOperationException;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
import java.util.AbstractSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class BlockSet extends AbstractRegion {
|
||||
private final int chunkOffsetX;
|
||||
private final int chunkOffsetZ;
|
||||
private final int blockOffsetX;
|
||||
private final int blockOffsetZ;
|
||||
|
||||
public BlockSet(int offsetX, int offsetZ) {
|
||||
super(null);
|
||||
this.chunkOffsetX = offsetX;
|
||||
this.chunkOffsetZ = offsetZ;
|
||||
this.blockOffsetX = offsetX << 4;
|
||||
this.blockOffsetZ = offsetZ << 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Object o) {
|
||||
try {
|
||||
return contains((BlockVector3) o);
|
||||
} catch (ClassCastException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean contains(BlockVector3 obj) {
|
||||
return contains(obj.getX(), obj.getY(), obj.getZ());
|
||||
}
|
||||
|
||||
protected final int lowestBit(long bitBuffer) {
|
||||
final long lowBit = Long.lowestOneBit(bitBuffer);
|
||||
return Long.bitCount(lowBit - 1);
|
||||
}
|
||||
|
||||
protected final int highestBit(long bitBuffer) {
|
||||
final long lowBit = Long.highestOneBit(bitBuffer);
|
||||
return Long.bitCount(lowBit - 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGlobal() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public final int getBlockOffsetX() {
|
||||
return blockOffsetX;
|
||||
}
|
||||
|
||||
public int getBlockOffsetZ() {
|
||||
return blockOffsetZ;
|
||||
}
|
||||
|
||||
public int getChunkOffsetX() {
|
||||
return chunkOffsetX;
|
||||
}
|
||||
|
||||
public int getChunkOffsetZ() {
|
||||
return chunkOffsetZ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(BlockVector3 p) {
|
||||
return add(p.getX(), p.getY(), p.getZ());
|
||||
}
|
||||
|
||||
public boolean remove(BlockVector3 p) {
|
||||
return remove(p.getX(), p.getY(), p.getZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(Object o) {
|
||||
try {
|
||||
return remove((BlockVector3) o);
|
||||
} catch (ClassCastException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract boolean contains(int x, int y, int z);
|
||||
public abstract boolean add(int x, int y, int z);
|
||||
public abstract void set(int x, int y, int z);
|
||||
public abstract void clear(int x, int y, int z);
|
||||
public abstract boolean remove(int x, int y, int z);
|
||||
public abstract Iterator<BlockVector3> iterator();
|
||||
public abstract Set<BlockVector2> getChunks();
|
||||
public abstract Set<BlockVector3> getChunkCubes();
|
||||
public abstract BlockVector3 getMaximumPoint();
|
||||
public abstract BlockVector3 getMinimumPoint();
|
||||
|
||||
@Override
|
||||
public void expand(BlockVector3... changes) throws RegionOperationException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contract(BlockVector3... changes) throws RegionOperationException {
|
||||
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user