mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-06-11 20:13:55 +00:00
delete FaweQueue
This commit is contained in:
@ -1,13 +1,18 @@
|
||||
package com.boydti.fawe.beta;
|
||||
|
||||
public abstract class DelegateFilter implements IDelegateFilter {
|
||||
public class DelegateFilter<T extends Filter> implements IDelegateFilter {
|
||||
private final Filter parent;
|
||||
|
||||
public DelegateFilter(Filter parent) {
|
||||
public DelegateFilter(T parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
@Override
|
||||
public Filter getParent() {
|
||||
return parent;
|
||||
public T getParent() {
|
||||
return (T) parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Filter newInstance(Filter other) {
|
||||
return new DelegateFilter(other);
|
||||
}
|
||||
}
|
||||
|
@ -46,5 +46,7 @@ public interface IDelegateFilter extends Filter {
|
||||
return this;
|
||||
}
|
||||
|
||||
Filter newInstance(Filter other);
|
||||
default Filter newInstance(Filter other) {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,9 @@
|
||||
package com.boydti.fawe.beta.filters;
|
||||
|
||||
import com.boydti.fawe.beta.FilterBlock;
|
||||
import com.boydti.fawe.config.BBC;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.util.Countable;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class CountFilter extends ForkedFilter<CountFilter> {
|
||||
private final int[] counter = new int[BlockTypes.states.length];
|
||||
private int total;
|
||||
|
||||
public CountFilter() {
|
||||
super(null);
|
||||
@ -29,9 +20,7 @@ public class CountFilter extends ForkedFilter<CountFilter> {
|
||||
|
||||
@Override
|
||||
public void join(CountFilter filter) {
|
||||
for (int i = 0; i < filter.counter.length; i++) {
|
||||
this.counter[i] += filter.counter[i];
|
||||
}
|
||||
this.total += filter.getTotal();
|
||||
}
|
||||
|
||||
/*
|
||||
@ -40,29 +29,10 @@ public class CountFilter extends ForkedFilter<CountFilter> {
|
||||
|
||||
@Override
|
||||
public final void applyBlock(final FilterBlock block) {
|
||||
counter[block.getOrdinal()]++;
|
||||
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 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);
|
||||
}
|
||||
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,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,143 @@
|
||||
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.BlockMask;
|
||||
import com.sk89q.worldedit.function.mask.BlockMaskBuilder;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.mask.SingleBlockStateMask;
|
||||
import com.sk89q.worldedit.function.operation.Operations;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.function.visitor.RegionVisitor;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.util.Countable;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
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.world.block.BlockTypes;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@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 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int setBlocks(Region region, Pattern pattern) throws MaxChangedBlocksException {
|
||||
apply(region, pattern);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int replaceBlocks(Region region, Mask mask, Pattern pattern) throws MaxChangedBlocksException {
|
||||
apply(region, mask.toFilter(pattern));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
@ -70,6 +70,10 @@ public abstract class QueueHandler implements Trimable, Runnable {
|
||||
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);
|
||||
@ -143,61 +147,4 @@ public abstract class QueueHandler implements Trimable, Runnable {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void apply(final World world, final Region region, final Filter filter) {
|
||||
// The chunks positions to iterate over
|
||||
final Set<BlockVector2> chunks = region.getChunks();
|
||||
final Iterator<BlockVector2> chunksIter = chunks.iterator();
|
||||
|
||||
// Get a pool, to operate on the chunks in parallel
|
||||
final int size = Math.min(chunks.size(), Settings.IMP.QUEUE.PARALLEL_THREADS);
|
||||
final ForkJoinTask[] tasks = new ForkJoinTask[size];
|
||||
for (int i = 0; i < size; i++) {
|
||||
tasks[i] = forkJoinPoolPrimary.submit(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final Filter newFilter = filter.fork();
|
||||
// Create a chunk that we will reuse/reset for each operation
|
||||
final IQueueExtent queue = getQueue(world);
|
||||
synchronized (queue) {
|
||||
ChunkFilterBlock block = null;
|
||||
|
||||
while (true) {
|
||||
// Get the next chunk posWeakChunk
|
||||
final int X, Z;
|
||||
synchronized (chunksIter) {
|
||||
if (!chunksIter.hasNext()) break;
|
||||
final BlockVector2 pos = chunksIter.next();
|
||||
X = pos.getX();
|
||||
Z = pos.getZ();
|
||||
}
|
||||
if (!newFilter.appliesChunk(X, Z)) {
|
||||
continue;
|
||||
}
|
||||
IChunk chunk = queue.getCachedChunk(X, Z);
|
||||
// Initialize
|
||||
chunk.init(queue, X, Z);
|
||||
|
||||
IChunk newChunk = newFilter.applyChunk(chunk, region);
|
||||
if (newChunk != null) {
|
||||
chunk = newChunk;
|
||||
if (block == null) block = queue.initFilterBlock();
|
||||
chunk.filterBlocks(newFilter, block, region);
|
||||
}
|
||||
queue.submit(chunk);
|
||||
}
|
||||
queue.flush();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
// Join filters
|
||||
for (int i = 0; i < tasks.length; i++) {
|
||||
final ForkJoinTask task = tasks[i];
|
||||
if (task != null) {
|
||||
task.quietlyJoin();
|
||||
}
|
||||
}
|
||||
filter.join();
|
||||
}
|
||||
}
|
@ -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,789 +0,0 @@
|
||||
package com.boydti.fawe.example;
|
||||
|
||||
import com.boydti.fawe.Fawe;
|
||||
import com.boydti.fawe.FaweAPI;
|
||||
import com.boydti.fawe.config.Settings;
|
||||
import com.boydti.fawe.object.FaweChunk;
|
||||
import com.boydti.fawe.object.FaweQueue;
|
||||
import com.boydti.fawe.object.IntegerPair;
|
||||
import com.boydti.fawe.object.RunnableVal;
|
||||
import com.boydti.fawe.object.RunnableVal2;
|
||||
import com.boydti.fawe.object.exception.FaweException;
|
||||
import com.boydti.fawe.object.extent.LightingExtent;
|
||||
import com.boydti.fawe.util.MathMan;
|
||||
import com.boydti.fawe.util.SetQueue;
|
||||
import com.boydti.fawe.util.TaskManager;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentLinkedDeque;
|
||||
import java.util.concurrent.ForkJoinPool;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public abstract class MappedFaweQueue<WORLD, CHUNK, CHUNKSECTIONS, SECTION> implements LightingExtent, FaweQueue {
|
||||
|
||||
private WORLD impWorld;
|
||||
|
||||
private IFaweQueueMap map;
|
||||
|
||||
public int lastSectionX = Integer.MIN_VALUE;
|
||||
public int lastSectionZ = Integer.MIN_VALUE;
|
||||
public int lastSectionY = Integer.MIN_VALUE;
|
||||
public CHUNK lastChunk;
|
||||
public CHUNKSECTIONS lastChunkSections;
|
||||
public SECTION lastSection;
|
||||
|
||||
|
||||
private World weWorld;
|
||||
private String world;
|
||||
private ConcurrentLinkedDeque<EditSession> sessions;
|
||||
private long modified = System.currentTimeMillis();
|
||||
private RunnableVal2<FaweChunk, FaweChunk> changeTask;
|
||||
private RunnableVal2<ProgressType, Integer> progressTask;
|
||||
private SetQueue.QueueStage stage;
|
||||
private Settings settings = Settings.IMP;
|
||||
public ConcurrentLinkedDeque<Runnable> tasks = new ConcurrentLinkedDeque<>();
|
||||
|
||||
private CHUNK cachedLoadChunk;
|
||||
public final RunnableVal<IntegerPair> loadChunk = new RunnableVal<IntegerPair>() {
|
||||
|
||||
{
|
||||
this.value = new IntegerPair(0, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(IntegerPair coord) {
|
||||
cachedLoadChunk = loadChunk(getWorld(), coord.x, coord.z, true);
|
||||
}
|
||||
};
|
||||
|
||||
public MappedFaweQueue(final World world) {
|
||||
this(world, null);
|
||||
}
|
||||
|
||||
public MappedFaweQueue(final String world) {
|
||||
this.world = world;
|
||||
map = getSettings().PREVENT_CRASHES ? new WeakFaweQueueMap(this) : new DefaultFaweQueueMap(this);
|
||||
}
|
||||
|
||||
public MappedFaweQueue(final String world, IFaweQueueMap map) {
|
||||
this.world = world;
|
||||
if (map == null) {
|
||||
map = getSettings().PREVENT_CRASHES ? new WeakFaweQueueMap(this) : new DefaultFaweQueueMap(this);
|
||||
}
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
public MappedFaweQueue(final World world, IFaweQueueMap map) {
|
||||
this.weWorld = world;
|
||||
if (world != null) this.world = world.getName();
|
||||
if (map == null) {
|
||||
map = getSettings().PREVENT_CRASHES ? new WeakFaweQueueMap(this) : new DefaultFaweQueueMap(this);
|
||||
}
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxY() {
|
||||
return weWorld == null ? 255 : weWorld.getMaxY();
|
||||
}
|
||||
|
||||
public IFaweQueueMap getFaweQueueMap() {
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<FaweChunk> getFaweChunks() {
|
||||
return map.getFaweChunks();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void optimize() {
|
||||
final ForkJoinPool pool = TaskManager.IMP.getPublicForkJoinPool();
|
||||
map.forEachChunk(new RunnableVal<FaweChunk>() {
|
||||
@Override
|
||||
public void run(final FaweChunk chunk) {
|
||||
pool.submit(chunk::optimize);
|
||||
}
|
||||
});
|
||||
pool.awaitQuiescence(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
public abstract WORLD getImpWorld();
|
||||
|
||||
public abstract boolean regenerateChunk(WORLD world, int x, int z, BiomeType biome, Long seed);
|
||||
|
||||
@Override
|
||||
public abstract FaweChunk getFaweChunk(int x, int z);
|
||||
|
||||
public abstract CHUNK loadChunk(WORLD world, int x, int z, boolean generate);
|
||||
|
||||
public abstract CHUNKSECTIONS getSections(CHUNK chunk);
|
||||
|
||||
public abstract CHUNKSECTIONS getCachedSections(WORLD world, int cx, int cz);
|
||||
|
||||
public abstract CHUNK getCachedChunk(WORLD world, int cx, int cz);
|
||||
|
||||
public WORLD getWorld() {
|
||||
if (impWorld != null) {
|
||||
return impWorld;
|
||||
}
|
||||
return impWorld = getImpWorld();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean regenerateChunk(int x, int z, BiomeType biome, Long seed) {
|
||||
return regenerateChunk(getWorld(), x, z, biome, seed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBlock(int x, int y, int z, int id) {
|
||||
int cx = x >> 4;
|
||||
int cz = z >> 4;
|
||||
FaweChunk chunk = map.getFaweChunk(cx, cz);
|
||||
chunk.setBlock(x & 15, y, z & 15, id);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTile(int x, int y, int z, CompoundTag tag) {
|
||||
if ((y >= FaweChunk.HEIGHT) || (y < 0)) {
|
||||
return;
|
||||
}
|
||||
int cx = x >> 4;
|
||||
int cz = z >> 4;
|
||||
FaweChunk chunk = map.getFaweChunk(cx, cz);
|
||||
chunk.setTile(x & 15, y, z & 15, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEntity(int x, int y, int z, CompoundTag tag) {
|
||||
if ((y >= FaweChunk.HEIGHT) || (y < 0)) {
|
||||
return;
|
||||
}
|
||||
int cx = x >> 4;
|
||||
int cz = z >> 4;
|
||||
FaweChunk chunk = map.getFaweChunk(cx, cz);
|
||||
chunk.setEntity(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeEntity(int x, int y, int z, UUID uuid) {
|
||||
if ((y >= FaweChunk.HEIGHT) || (y < 0)) {
|
||||
return;
|
||||
}
|
||||
int cx = x >> 4;
|
||||
int cz = z >> 4;
|
||||
FaweChunk chunk = map.getFaweChunk(cx, cz);
|
||||
chunk.removeEntity(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBiome(int x, int z, BiomeType biome) {
|
||||
int cx = x >> 4;
|
||||
int cz = z >> 4;
|
||||
FaweChunk chunk = map.getFaweChunk(cx, cz);
|
||||
chunk.setBiome(x & 15, z & 15, biome);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean next(int amount, long time) {
|
||||
return map.next(amount, time);
|
||||
}
|
||||
|
||||
public void start(FaweChunk chunk) {
|
||||
chunk.start();
|
||||
}
|
||||
|
||||
public void end(FaweChunk chunk) {
|
||||
if (getProgressTask() != null) {
|
||||
getProgressTask().run(ProgressType.DISPATCH, size() + 1);
|
||||
}
|
||||
chunk.end();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runTasks() {
|
||||
synchronized (this) {
|
||||
this.notifyAll();
|
||||
}
|
||||
if (getProgressTask() != null) {
|
||||
try {
|
||||
getProgressTask().run(ProgressType.DONE, 1);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
while (!tasks.isEmpty()) {
|
||||
Runnable task = tasks.poll();
|
||||
if (task != null) {
|
||||
try {
|
||||
task.run();
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (getProgressTask() != null) {
|
||||
try {
|
||||
getProgressTask().run(ProgressType.DONE, 1);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
ArrayDeque<Runnable> tmp = new ArrayDeque<>(tasks);
|
||||
tasks.clear();
|
||||
for (Runnable run : tmp) {
|
||||
try {
|
||||
run.run();
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Settings getSettings() {
|
||||
return settings;
|
||||
}
|
||||
|
||||
public void setSettings(Settings settings) {
|
||||
this.settings = settings == null ? Settings.IMP : settings;
|
||||
}
|
||||
|
||||
public void setWorld(String world) {
|
||||
this.world = world;
|
||||
this.weWorld = null;
|
||||
}
|
||||
|
||||
public World getWEWorld() {
|
||||
return weWorld != null ? weWorld : (weWorld = FaweAPI.getWorld(world));
|
||||
}
|
||||
|
||||
public String getWorldName() {
|
||||
return world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<EditSession> getEditSessions() {
|
||||
Collection<EditSession> tmp = sessions;
|
||||
if (tmp == null) tmp = new HashSet<>();
|
||||
return tmp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addEditSession(EditSession session) {
|
||||
ConcurrentLinkedDeque<EditSession> tmp = sessions;
|
||||
if (tmp == null) tmp = new ConcurrentLinkedDeque<>();
|
||||
tmp.add(session);
|
||||
this.sessions = tmp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supports(Capability capability) {
|
||||
if (capability == Capability.CHANGE_TASKS) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setSessions(ConcurrentLinkedDeque<EditSession> sessions) {
|
||||
this.sessions = sessions;
|
||||
}
|
||||
|
||||
public long getModified() {
|
||||
return modified;
|
||||
}
|
||||
|
||||
public void setModified(long modified) {
|
||||
this.modified = modified;
|
||||
}
|
||||
|
||||
public RunnableVal2<ProgressType, Integer> getProgressTask() {
|
||||
return progressTask;
|
||||
}
|
||||
|
||||
public void setProgressTask(RunnableVal2<ProgressType, Integer> progressTask) {
|
||||
this.progressTask = progressTask;
|
||||
}
|
||||
|
||||
public void setChangeTask(RunnableVal2<FaweChunk, FaweChunk> changeTask) {
|
||||
this.changeTask = changeTask;
|
||||
}
|
||||
|
||||
public RunnableVal2<FaweChunk, FaweChunk> getChangeTask() {
|
||||
return changeTask;
|
||||
}
|
||||
|
||||
public SetQueue.QueueStage getStage() {
|
||||
return stage;
|
||||
}
|
||||
|
||||
public void setStage(SetQueue.QueueStage stage) {
|
||||
this.stage = stage;
|
||||
}
|
||||
|
||||
public void addNotifyTask(Runnable runnable) {
|
||||
this.tasks.add(runnable);
|
||||
}
|
||||
|
||||
public void addTask(Runnable whenFree) {
|
||||
tasks.add(whenFree);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
int size = map.size();
|
||||
if (size == 0 && getStage() == SetQueue.QueueStage.NONE) {
|
||||
runTasks();
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
lastSectionX = Integer.MIN_VALUE;
|
||||
lastSectionZ = Integer.MIN_VALUE;
|
||||
lastSectionY = -1;
|
||||
lastChunk = null;
|
||||
lastChunkSections = null;
|
||||
map.clear();
|
||||
runTasks();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChunk(FaweChunk chunk) {
|
||||
map.add(chunk);
|
||||
}
|
||||
|
||||
public SECTION getCachedSection(CHUNKSECTIONS chunk, int cy) {
|
||||
return (SECTION) lastChunkSections;
|
||||
}
|
||||
|
||||
public abstract int getCombinedId4Data(SECTION section, int x, int y, int z);
|
||||
|
||||
public int getLocalCombinedId4Data(CHUNK chunk, int x, int y, int z) {
|
||||
CHUNKSECTIONS sections = getSections(lastChunk);
|
||||
SECTION section = getCachedSection(sections, y >> 4);
|
||||
if (section == null) {
|
||||
return BlockTypes.AIR.getInternalId();
|
||||
}
|
||||
return getCombinedId4Data(lastSection, x, y, z);
|
||||
}
|
||||
|
||||
public abstract BiomeType getBiome(CHUNK chunk, int x, int z);
|
||||
|
||||
public abstract CompoundTag getTileEntity(CHUNK chunk, int x, int y, int z);
|
||||
|
||||
public CHUNK ensureChunkLoaded(int cx, int cz) throws FaweException.FaweChunkLoadException {
|
||||
CHUNK chunk = getCachedChunk(getWorld(), cx, cz);
|
||||
if (chunk != null) {
|
||||
return chunk;
|
||||
}
|
||||
boolean sync = Fawe.isMainThread();
|
||||
if (sync) {
|
||||
return loadChunk(getWorld(), cx, cz, true);
|
||||
} else if (getSettings().HISTORY.CHUNK_WAIT_MS > 0) {
|
||||
cachedLoadChunk = null;
|
||||
loadChunk.value.x = cx;
|
||||
loadChunk.value.z = cz;
|
||||
TaskManager.IMP.syncWhenFree(loadChunk, getSettings().HISTORY.CHUNK_WAIT_MS);
|
||||
return cachedLoadChunk;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean queueChunkLoad(final int cx, final int cz) {
|
||||
CHUNK chunk = getCachedChunk(getWorld(), cx, cz);
|
||||
if (chunk == null) {
|
||||
SetQueue.IMP.addTask(() -> loadChunk(getWorld(), cx, cz, true));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean queueChunkLoad(final int cx, final int cz, RunnableVal<CHUNK> operation) {
|
||||
operation.value = getCachedChunk(getWorld(), cx, cz);
|
||||
if (operation.value == null) {
|
||||
SetQueue.IMP.addTask(() -> {
|
||||
operation.value = loadChunk(getWorld(), cx, cz, true);
|
||||
if (operation.value != null) TaskManager.IMP.async(operation);
|
||||
});
|
||||
return true;
|
||||
} else {
|
||||
TaskManager.IMP.async(operation);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasBlock(int x, int y, int z) throws FaweException.FaweChunkLoadException {
|
||||
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 false;
|
||||
}
|
||||
} else if (cy != lastSectionY) {
|
||||
if (lastChunkSections != null) {
|
||||
lastSection = getCachedSection(lastChunkSections, cy);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (lastSection == null) {
|
||||
return false;
|
||||
}
|
||||
return hasBlock(lastSection, x, y, z);
|
||||
}
|
||||
|
||||
public boolean hasBlock(SECTION section, int x, int y, int z) {
|
||||
return getCombinedId4Data(lastSection, x, y, z) != 0;
|
||||
}
|
||||
|
||||
public int getOpacity(SECTION section, int x, int y, int z) {
|
||||
int combined = getCombinedId4Data(section, x, y, z);
|
||||
if (combined == 0) {
|
||||
return 0;
|
||||
}
|
||||
return Math.min(15, BlockTypes.getFromStateId(combined).getMaterial().getLightOpacity());
|
||||
}
|
||||
|
||||
public int getBrightness(SECTION section, int x, int y, int z) {
|
||||
int combined = getCombinedId4Data(section, x, y, z);
|
||||
if (combined == 0) {
|
||||
return 0;
|
||||
}
|
||||
return Math.min(15, BlockTypes.getFromStateId(combined).getMaterial().getLightValue());
|
||||
}
|
||||
|
||||
public int getOpacityBrightnessPair(SECTION section, int x, int y, int z) {
|
||||
return MathMan.pair16(Math.min(15, getOpacity(section, x, y, z)), getBrightness(section, x, y, z));
|
||||
}
|
||||
|
||||
public abstract int getSkyLight(SECTION sections, int x, int y, int z);
|
||||
|
||||
public abstract int getEmmittedLight(SECTION sections, int x, int y, int z);
|
||||
|
||||
public int getLight(SECTION sections, int x, int y, int z) {
|
||||
if (!hasSky()) {
|
||||
return getEmmittedLight(sections, x, y, z);
|
||||
}
|
||||
return Math.max(getSkyLight(sections, x, y, z), getEmmittedLight(sections, x, y, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLight(int x, int y, int z) {
|
||||
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 0;
|
||||
}
|
||||
} else if (cy != lastSectionY) {
|
||||
if (lastChunkSections != null) {
|
||||
lastSection = getCachedSection(lastChunkSections, cy);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (lastSection == null) {
|
||||
return 0;
|
||||
}
|
||||
return getLight(lastSection, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSkyLight(int x, int y, int z) {
|
||||
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 0;
|
||||
}
|
||||
} else if (cy != lastSectionY) {
|
||||
if (lastChunkSections != null) {
|
||||
lastSection = getCachedSection(lastChunkSections, cy);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (lastSection == null) {
|
||||
if (lastChunkSections == null) {
|
||||
return 0;
|
||||
}
|
||||
int max = FaweChunk.HEIGHT >> 4;
|
||||
do {
|
||||
if (++cy >= max) {
|
||||
return 15;
|
||||
}
|
||||
lastSection = getCachedSection(lastChunkSections, cy);
|
||||
} while (lastSection == null);
|
||||
}
|
||||
if (lastSection == null) {
|
||||
|
||||
return getSkyLight(x, y + 16, z);
|
||||
}
|
||||
return getSkyLight(lastSection, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockLight(int x, int y, int z) {
|
||||
return getEmmittedLight(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEmmittedLight(int x, int y, int z) {
|
||||
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 0;
|
||||
}
|
||||
} else if (cy != lastSectionY) {
|
||||
if (lastChunkSections != null) {
|
||||
lastSection = getCachedSection(lastChunkSections, cy);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (lastSection == null) {
|
||||
return 0;
|
||||
}
|
||||
return getEmmittedLight(lastSection, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOpacity(int x, int y, int z) {
|
||||
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 0;
|
||||
}
|
||||
} else if (cy != lastSectionY) {
|
||||
if (lastChunkSections != null) {
|
||||
lastSection = getCachedSection(lastChunkSections, cy);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (lastSection == null) {
|
||||
return 0;
|
||||
}
|
||||
return getOpacity(lastSection, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOpacityBrightnessPair(int x, int y, int z) {
|
||||
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 0;
|
||||
}
|
||||
} else if (cy != lastSectionY) {
|
||||
if (lastChunkSections != null) {
|
||||
lastSection = getCachedSection(lastChunkSections, cy);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (lastSection == null) {
|
||||
return 0;
|
||||
}
|
||||
return getOpacityBrightnessPair(lastSection, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBrightness(int x, int y, int z) {
|
||||
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 0;
|
||||
}
|
||||
} else if (cy != lastSectionY) {
|
||||
if (lastChunkSections != null) {
|
||||
lastSection = getCachedSection(lastChunkSections, cy);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (lastSection == null) {
|
||||
return 0;
|
||||
}
|
||||
return getBrightness(lastSection, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCachedCombinedId4Data(int x, int y, int z) throws FaweException.FaweChunkLoadException {
|
||||
int cx = x >> 4;
|
||||
int cz = z >> 4;
|
||||
FaweChunk fc = map.getCachedFaweChunk(cx, cz);
|
||||
if (fc != null) {
|
||||
int combined = fc.getBlockCombinedId(x & 15, y, z & 15);
|
||||
if (combined != 0) {
|
||||
return combined;
|
||||
}
|
||||
}
|
||||
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 BlockTypes.AIR.getInternalId();
|
||||
}
|
||||
} else if (cy != lastSectionY) {
|
||||
if (lastChunkSections != null) {
|
||||
lastSection = getCachedSection(lastChunkSections, cy);
|
||||
} else {
|
||||
return BlockTypes.AIR.getInternalId();
|
||||
}
|
||||
}
|
||||
if (lastSection == null) {
|
||||
return BlockTypes.AIR.getInternalId();
|
||||
}
|
||||
return getCombinedId4Data(lastSection, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCombinedId4Data(int x, int y, int z) throws FaweException.FaweChunkLoadException {
|
||||
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 BlockTypes.AIR.getInternalId();
|
||||
}
|
||||
} else if (cy != lastSectionY) {
|
||||
if (lastChunkSections != null) {
|
||||
lastSection = getCachedSection(lastChunkSections, cy);
|
||||
} else {
|
||||
return BlockTypes.AIR.getInternalId();
|
||||
}
|
||||
}
|
||||
if (lastSection == null) {
|
||||
return BlockTypes.AIR.getInternalId();
|
||||
}
|
||||
return getCombinedId4Data(lastSection, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeType getBiomeType(int x, int z) throws FaweException.FaweChunkLoadException {
|
||||
int cx = x >> 4;
|
||||
int cz = z >> 4;
|
||||
lastSectionY = -1;
|
||||
if (cx != lastSectionX || cz != lastSectionZ) {
|
||||
lastSectionX = cx;
|
||||
lastSectionZ = cz;
|
||||
lastChunk = ensureChunkLoaded(cx, cz);
|
||||
if (lastChunk != null) {
|
||||
lastChunkSections = getSections(lastChunk);
|
||||
} else {
|
||||
lastChunkSections = null;
|
||||
return null;
|
||||
}
|
||||
} else if (lastChunk == null) {
|
||||
return null;
|
||||
}
|
||||
return getBiome(lastChunk, x, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag getTileEntity(int x, int y, int z) throws FaweException.FaweChunkLoadException {
|
||||
int cx = x >> 4;
|
||||
int cz = z >> 4;
|
||||
lastSectionY = -1;
|
||||
if (cx != lastSectionX || cz != lastSectionZ) {
|
||||
lastSectionX = cx;
|
||||
lastSectionZ = cz;
|
||||
lastChunk = ensureChunkLoaded(cx, cz);
|
||||
if (lastChunk != null) {
|
||||
lastChunkSections = getSections(lastChunk);
|
||||
} else {
|
||||
lastChunkSections = null;
|
||||
return null;
|
||||
}
|
||||
} else if (lastChunk == null) {
|
||||
return null;
|
||||
}
|
||||
return getTileEntity(lastChunk, x, y, z);
|
||||
}
|
||||
}
|
@ -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[0]);
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
@ -1,526 +0,0 @@
|
||||
package com.boydti.fawe.object;
|
||||
|
||||
import com.boydti.fawe.Fawe;
|
||||
import com.boydti.fawe.config.BBC;
|
||||
import com.boydti.fawe.config.Settings;
|
||||
import com.boydti.fawe.example.NullRelighter;
|
||||
import com.boydti.fawe.example.Relighter;
|
||||
import com.boydti.fawe.object.exception.FaweException;
|
||||
import com.boydti.fawe.util.MainUtil;
|
||||
import com.boydti.fawe.util.MathMan;
|
||||
import com.boydti.fawe.util.MemUtil;
|
||||
import com.boydti.fawe.util.SetQueue;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.MutableBlockVector3;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.UUID;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* A queue based Extent capable of queing chunk and region changes
|
||||
*/
|
||||
public interface FaweQueue extends HasFaweQueue, Extent {
|
||||
|
||||
enum ProgressType {
|
||||
QUEUE,
|
||||
DISPATCH,
|
||||
DONE,
|
||||
}
|
||||
|
||||
enum RelightMode {
|
||||
NONE,
|
||||
OPTIMAL,
|
||||
ALL,
|
||||
}
|
||||
|
||||
enum Capability {
|
||||
// If history can be recorded in an async task by the dispatcher
|
||||
CHANGE_TASKS,
|
||||
// If custom chunk packets can be sent
|
||||
CHUNK_PACKETS
|
||||
//
|
||||
}
|
||||
|
||||
default Relighter getRelighter() {
|
||||
return NullRelighter.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
default BlockVector3 getMinimumPoint() {
|
||||
return BlockVector3.at(-30000000, 0, -30000000);
|
||||
}
|
||||
|
||||
@Override
|
||||
default BlockVector3 getMaximumPoint() {
|
||||
return BlockVector3.at(30000000, getMaxY(), 30000000);
|
||||
}
|
||||
|
||||
@Override
|
||||
default BlockState getBlock(int x, int y, int z) {
|
||||
int combinedId4Data = getCachedCombinedId4Data(x, y, z, BlockTypes.AIR.getInternalId());
|
||||
try {
|
||||
return BlockState.getFromInternalId(combinedId4Data);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
return BlockTypes.AIR.getDefaultState();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
default <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block) throws WorldEditException {
|
||||
return setBlock(x, y, z, block.getInternalId(), block instanceof BaseBlock ? block.getNbtData() : null);
|
||||
}
|
||||
|
||||
@Override
|
||||
default BaseBlock getFullBlock(BlockVector3 position) {
|
||||
int combinedId4Data = getCachedCombinedId4Data(position.getBlockX(), position.getBlockY(), position.getBlockZ(), BlockTypes.AIR.getInternalId());
|
||||
try {
|
||||
BaseBlock block = BaseBlock.getFromInternalId(combinedId4Data, null);
|
||||
if (block.getMaterial().hasContainer()) {
|
||||
CompoundTag tile = getTileEntity(position.getBlockX(), position.getBlockY(), position.getBlockZ());
|
||||
if (tile != null) {
|
||||
return BaseBlock.getFromInternalId(combinedId4Data, tile);
|
||||
}
|
||||
}
|
||||
return block;
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
return BlockTypes.AIR.getDefaultState().toBaseBlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
default BiomeType getBiome(BlockVector2 position) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
default <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block) throws WorldEditException {
|
||||
return setBlock(position.getBlockX(), position.getBlockY(), position.getBlockZ(), block);
|
||||
}
|
||||
|
||||
boolean setBlock(final int x, final int y, final int z, int combinedId);
|
||||
|
||||
default boolean setBlock(final int x, final int y, final int z, int combinedId, CompoundTag nbtData) {
|
||||
if (setBlock(x, y, z, combinedId)) {
|
||||
if (nbtData != null) setTile(x, y, z, nbtData);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
default boolean setBiome(BlockVector2 position, BiomeType biome) {
|
||||
return setBiome(position.getBlockX(), position.getBlockZ(), biome);
|
||||
}
|
||||
|
||||
@Override
|
||||
default FaweQueue getQueue() {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
default void addEditSession(EditSession session) {
|
||||
if (session == null) {
|
||||
return;
|
||||
}
|
||||
Collection<EditSession> sessions = getEditSessions();
|
||||
sessions.add(session);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a progress task<br>
|
||||
* - Progress type
|
||||
* - Amount of type
|
||||
*
|
||||
* @param progressTask
|
||||
*/
|
||||
default void setProgressTracker(RunnableVal2<ProgressType, Integer> progressTask) {
|
||||
this.setProgressTask(progressTask);
|
||||
}
|
||||
|
||||
default Collection<EditSession> getEditSessions() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
default boolean supports(Capability capability) {
|
||||
return false;
|
||||
}
|
||||
|
||||
default void optimize() {}
|
||||
|
||||
default int setBlocks(CuboidRegion cuboid, int combinedId) {
|
||||
RegionWrapper current = new RegionWrapper(cuboid.getMinimumPoint(), cuboid.getMaximumPoint());
|
||||
final int minY = cuboid.getMinimumY();
|
||||
final int maxY = cuboid.getMaximumY();
|
||||
|
||||
final FaweChunk<?> fc = getFaweChunk(0, 0);
|
||||
fc.fillCuboid(0, 15, minY, maxY, 0, 15, combinedId);
|
||||
fc.optimize();
|
||||
|
||||
int bcx = (current.minX) >> 4;
|
||||
int bcz = (current.minZ) >> 4;
|
||||
|
||||
int tcx = (current.maxX) >> 4;
|
||||
int tcz = (current.maxZ) >> 4;
|
||||
// [chunkx, chunkz, pos1x, pos1z, pos2x, pos2z, isedge]
|
||||
MainUtil.chunkTaskSync(current, new RunnableVal<int[]>() {
|
||||
@Override
|
||||
public void run(int[] value) {
|
||||
FaweChunk newChunk;
|
||||
if (value[6] == 0) {
|
||||
newChunk = fc.copy(true);
|
||||
newChunk.setLoc(FaweQueue.this, value[0], value[1]);
|
||||
} else {
|
||||
int bx = value[2] & 15;
|
||||
int tx = value[4] & 15;
|
||||
int bz = value[3] & 15;
|
||||
int tz = value[5] & 15;
|
||||
if (bx == 0 && tx == 15 && bz == 0 && tz == 15) {
|
||||
newChunk = fc.copy(true);
|
||||
newChunk.setLoc(FaweQueue.this, value[0], value[1]);
|
||||
} else {
|
||||
newChunk = FaweQueue.this.getFaweChunk(value[0], value[1]);
|
||||
newChunk.fillCuboid(value[2] & 15, value[4] & 15, minY, maxY, value[3] & 15, value[5] & 15, combinedId);
|
||||
}
|
||||
}
|
||||
newChunk.addToQueue();
|
||||
}
|
||||
});
|
||||
return cuboid.getArea();
|
||||
}
|
||||
|
||||
void setTile(int x, int y, int z, CompoundTag tag);
|
||||
|
||||
void setEntity(int x, int y, int z, CompoundTag tag);
|
||||
|
||||
void removeEntity(int x, int y, int z, UUID uuid);
|
||||
|
||||
boolean setBiome(final int x, final int z, final BiomeType biome);
|
||||
|
||||
FaweChunk getFaweChunk(int x, int z);
|
||||
|
||||
Collection<FaweChunk> getFaweChunks();
|
||||
|
||||
default boolean setMCA(int mcaX, int mcaZ, RegionWrapper region, Runnable whileLocked, boolean save, boolean load) {
|
||||
if (whileLocked != null) whileLocked.run();
|
||||
return true;
|
||||
}
|
||||
|
||||
void setChunk(final FaweChunk chunk);
|
||||
|
||||
File getSaveFolder();
|
||||
|
||||
default int getMaxY() {
|
||||
World weWorld = getWEWorld();
|
||||
return weWorld == null ? 255 : weWorld.getMaxY();
|
||||
}
|
||||
|
||||
default Settings getSettings() {
|
||||
return Settings.IMP;
|
||||
}
|
||||
|
||||
default void setSettings(Settings settings) {
|
||||
|
||||
}
|
||||
|
||||
void setWorld(String world);
|
||||
|
||||
World getWEWorld();
|
||||
|
||||
String getWorldName();
|
||||
|
||||
long getModified();
|
||||
|
||||
void setModified(long modified);
|
||||
|
||||
RunnableVal2<ProgressType, Integer> getProgressTask();
|
||||
|
||||
void setProgressTask(RunnableVal2<ProgressType, Integer> progressTask);
|
||||
|
||||
void setChangeTask(RunnableVal2<FaweChunk, FaweChunk> changeTask);
|
||||
|
||||
RunnableVal2<FaweChunk, FaweChunk> getChangeTask();
|
||||
|
||||
SetQueue.QueueStage getStage();
|
||||
|
||||
void setStage(SetQueue.QueueStage stage);
|
||||
|
||||
void addNotifyTask(Runnable runnable);
|
||||
|
||||
void runTasks();
|
||||
|
||||
void addTask(Runnable whenFree);
|
||||
|
||||
default void forEachBlockInChunk(int cx, int cz, RunnableVal2<BlockVector3, BaseBlock> onEach) {
|
||||
int bx = cx << 4;
|
||||
int bz = cz << 4;
|
||||
MutableBlockVector3 mutable = new MutableBlockVector3(0, 0, 0);
|
||||
for (int x = 0; x < 16; x++) {
|
||||
int xx = x + bx;
|
||||
mutable.mutX(xx);
|
||||
for (int z = 0; z < 16; z++) {
|
||||
int zz = z + bz;
|
||||
mutable.mutZ(zz);
|
||||
for (int y = 0; y <= getMaxY(); y++) {
|
||||
int combined = getCombinedId4Data(xx, y, zz);
|
||||
BaseBlock block = BlockState.getFromInternalId(combined).toBaseBlock();
|
||||
BlockType type = block.getBlockType();
|
||||
if (type.getMaterial().isAir()) {
|
||||
continue;
|
||||
}
|
||||
mutable.mutY(y);
|
||||
CompoundTag tile = getTileEntity(x, y, z);
|
||||
if (tile != null) {
|
||||
onEach.run(mutable, block.toBaseBlock(tile));
|
||||
} else {
|
||||
onEach.run(mutable, block);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
default void forEachTileInChunk(int cx, int cz, RunnableVal2<BlockVector3, BaseBlock> onEach) {
|
||||
int bx = cx << 4;
|
||||
int bz = cz << 4;
|
||||
MutableBlockVector3 mutable = new MutableBlockVector3(0, 0, 0);
|
||||
for (int x = 0; x < 16; x++) {
|
||||
int xx = x + bx;
|
||||
for (int z = 0; z < 16; z++) {
|
||||
int zz = z + bz;
|
||||
for (int y = 0; y < getMaxY(); y++) {
|
||||
int combined = getCombinedId4Data(xx, y, zz);
|
||||
if (combined == 0) {
|
||||
continue;
|
||||
}
|
||||
BlockType type = BlockTypes.getFromStateId(combined);
|
||||
if (type.getMaterial().hasContainer()) {
|
||||
CompoundTag tile = getTileEntity(x, y, z);
|
||||
if (tile != null) {
|
||||
mutable.mutX(xx);
|
||||
mutable.mutZ(zz);
|
||||
mutable.mutY(y);
|
||||
BaseBlock block = BaseBlock.getFromInternalId(combined, tile);
|
||||
onEach.run(mutable, block);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
default boolean regenerateChunk(int x, int z) {
|
||||
return regenerateChunk(x, z, null, null);
|
||||
}
|
||||
|
||||
boolean regenerateChunk(int x, int z, @Nullable BiomeType biome, @Nullable Long seed);
|
||||
|
||||
default void startSet(boolean parallel) {
|
||||
}
|
||||
|
||||
default void endSet(boolean parallel) {
|
||||
}
|
||||
|
||||
default int cancel() {
|
||||
clear();
|
||||
int count = 0;
|
||||
for (EditSession session : getEditSessions()) {
|
||||
if (session.cancel()) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
void sendBlockUpdate(FaweChunk chunk, FawePlayer... players);
|
||||
|
||||
default void sendChunkUpdate(FaweChunk chunk, FawePlayer... players) {
|
||||
sendBlockUpdate(chunk, players);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
default boolean next() {
|
||||
int amount = Settings.IMP.QUEUE.PARALLEL_THREADS;
|
||||
long time = 20; // 30ms
|
||||
return next(amount, time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the FaweChunk and sets the requested blocks
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
boolean next(int amount, long time);
|
||||
|
||||
default void saveMemory() {
|
||||
MainUtil.sendAdmin(BBC.OOM.s());
|
||||
// Set memory limited
|
||||
MemUtil.memoryLimitedTask();
|
||||
// Clear block placement
|
||||
clear();
|
||||
Fawe.get().getWorldEdit().getSessionManager().clear();
|
||||
// GC
|
||||
System.gc();
|
||||
System.gc();
|
||||
// Unload chunks
|
||||
}
|
||||
|
||||
void sendChunk(FaweChunk chunk);
|
||||
|
||||
void sendChunk(int x, int z, int bitMask);
|
||||
|
||||
/**
|
||||
* This method is called when the server is < 1% available memory
|
||||
*/
|
||||
void clear();
|
||||
|
||||
default boolean hasBlock(int x, int y, int z) throws FaweException.FaweChunkLoadException {
|
||||
return getCombinedId4Data(x, y, z) != 0;
|
||||
}
|
||||
|
||||
BiomeType getBiomeType(int x, int z) throws FaweException.FaweChunkLoadException;
|
||||
|
||||
int getCombinedId4Data(int x, int y, int z) throws FaweException.FaweChunkLoadException;
|
||||
|
||||
int getCachedCombinedId4Data(int x, int y, int z) throws FaweException.FaweChunkLoadException;
|
||||
|
||||
default int getAdjacentLight(int x, int y, int z) {
|
||||
int light = 0;
|
||||
if ((light = Math.max(light, getSkyLight(x - 1, y, z))) == 15) {
|
||||
return light;
|
||||
}
|
||||
if ((light = Math.max(light, getSkyLight(x + 1, y, z))) == 15) {
|
||||
return light;
|
||||
}
|
||||
if ((light = Math.max(light, getSkyLight(x, y, z - 1))) == 15) {
|
||||
return light;
|
||||
}
|
||||
return Math.max(light, getSkyLight(x, y, z + 1));
|
||||
}
|
||||
|
||||
boolean hasSky();
|
||||
|
||||
int getSkyLight(int x, int y, int z);
|
||||
|
||||
default int getLight(int x, int y, int z) {
|
||||
if (!hasSky()) {
|
||||
return getEmmittedLight(x, y, z);
|
||||
}
|
||||
return Math.max(getSkyLight(x, y, z), getEmmittedLight(x, y, z));
|
||||
}
|
||||
|
||||
int getEmmittedLight(int x, int y, int z);
|
||||
|
||||
CompoundTag getTileEntity(int x, int y, int z) throws FaweException.FaweChunkLoadException;
|
||||
|
||||
default int getCombinedId4Data(int x, int y, int z, int def) {
|
||||
try {
|
||||
return getCombinedId4Data(x, y, z);
|
||||
} catch (FaweException ignore) {
|
||||
return def;
|
||||
}
|
||||
}
|
||||
|
||||
default int getCachedCombinedId4Data(int x, int y, int z, int def) {
|
||||
try {
|
||||
return getCachedCombinedId4Data(x, y, z);
|
||||
} catch (FaweException ignore) {
|
||||
return def;
|
||||
}
|
||||
}
|
||||
|
||||
default int getCombinedId4DataDebug(int x, int y, int z, int def, EditSession session) {
|
||||
try {
|
||||
return getCombinedId4Data(x, y, z);
|
||||
} catch (FaweException ignore) {
|
||||
session.debug(BBC.WORLDEDIT_FAILED_LOAD_CHUNK, x >> 4, z >> 4);
|
||||
return def;
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
return BlockTypes.AIR.getInternalId();
|
||||
}
|
||||
}
|
||||
|
||||
default int getBrightness(int x, int y, int z) {
|
||||
int combined = getCombinedId4Data(x, y, z);
|
||||
if (combined == 0) {
|
||||
return 0;
|
||||
}
|
||||
return BlockTypes.getFromStateId(combined).getMaterial().getLightValue();
|
||||
}
|
||||
|
||||
default int getOpacityBrightnessPair(int x, int y, int z) {
|
||||
return MathMan.pair16(Math.min(15, getOpacity(x, y, z)), getBrightness(x, y, z));
|
||||
}
|
||||
|
||||
default int getOpacity(int x, int y, int z) {
|
||||
int combined = getCombinedId4Data(x, y, z);
|
||||
if (combined == 0) {
|
||||
return 0;
|
||||
}
|
||||
return BlockTypes.getFromStateId(combined).getMaterial().getLightOpacity();
|
||||
}
|
||||
|
||||
int size();
|
||||
|
||||
default boolean isEmpty() {
|
||||
return size() == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lock the thread until the queue is empty
|
||||
*/
|
||||
default void flush() {
|
||||
flush(10000);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lock the thread until the queue is empty
|
||||
*/
|
||||
default void flush(int time) {
|
||||
if (size() > 0) {
|
||||
if (Fawe.isMainThread()) {
|
||||
SetQueue.IMP.flush(this);
|
||||
} else {
|
||||
if (enqueue()) {
|
||||
while (!isEmpty() && getStage() == SetQueue.QueueStage.ACTIVE) {
|
||||
synchronized (this) {
|
||||
try {
|
||||
this.wait(time);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
default boolean enqueue() {
|
||||
return SetQueue.IMP.enqueue(this);
|
||||
}
|
||||
|
||||
default void dequeue() {
|
||||
SetQueue.IMP.dequeue(this);
|
||||
}
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
package com.boydti.fawe.object;
|
||||
|
||||
public interface HasFaweQueue {
|
||||
FaweQueue getQueue();
|
||||
}
|
@ -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);
|
||||
|
@ -122,7 +122,6 @@ public class Schematic {
|
||||
public EditSession paste(World world, BlockVector3 to, boolean allowUndo, boolean pasteAir, boolean copyEntities, @Nullable Transform transform) {
|
||||
checkNotNull(world);
|
||||
checkNotNull(to);
|
||||
Region region = clipboard.getRegion();
|
||||
EditSession editSession;
|
||||
if (world instanceof EditSession) {
|
||||
editSession = (EditSession) world;
|
||||
|
@ -45,7 +45,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||
public class EditSessionBuilder {
|
||||
private World world;
|
||||
private String worldName;
|
||||
private FaweQueue queue;
|
||||
private Extent extent;
|
||||
private FawePlayer player;
|
||||
private FaweLimit limit;
|
||||
private FaweChangeSet changeSet;
|
||||
@ -76,12 +76,14 @@ public class EditSessionBuilder {
|
||||
public EditSessionBuilder(@Nonnull World world) {
|
||||
checkNotNull(world);
|
||||
this.world = world;
|
||||
this.extent = world;
|
||||
this.worldName = Fawe.imp().getWorldName(world);
|
||||
}
|
||||
|
||||
public EditSessionBuilder(World world, String worldName) {
|
||||
if (world == null && worldName == null) throw new NullPointerException("Both world and worldname cannot be null");
|
||||
this.world = world;
|
||||
this.extent = world;
|
||||
this.worldName = worldName;
|
||||
}
|
||||
|
||||
@ -198,8 +200,8 @@ public class EditSessionBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public EditSessionBuilder queue(@Nullable FaweQueue queue) {
|
||||
this.queue = queue;
|
||||
public EditSessionBuilder extent(@Nullable Extent extent) {
|
||||
this.extent = extent;
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -260,7 +262,6 @@ public class EditSessionBuilder {
|
||||
}
|
||||
|
||||
private FaweChangeSet changeTask;
|
||||
private AbstractDelegateExtent extent;
|
||||
private int maxY;
|
||||
private HistoryExtent history;
|
||||
private AbstractDelegateExtent bypassHistory;
|
||||
@ -270,18 +271,6 @@ public class EditSessionBuilder {
|
||||
if (extent != null) return this;
|
||||
|
||||
wrapped = false;
|
||||
//
|
||||
if (worldName == null) {
|
||||
if (world == null) {
|
||||
if (queue == null) {
|
||||
worldName = "";
|
||||
} else {
|
||||
worldName = queue.getWorldName();
|
||||
}
|
||||
} else {
|
||||
worldName = Fawe.imp().getWorldName(world);
|
||||
}
|
||||
}
|
||||
if (world == null && !this.worldName.isEmpty()) {
|
||||
world = FaweAPI.getWorld(this.worldName);
|
||||
}
|
||||
@ -326,106 +315,107 @@ public class EditSessionBuilder {
|
||||
this.blockBag = limit.INVENTORY_MODE != 0 ? blockBag : null;
|
||||
// this.limit = limit.copy();
|
||||
|
||||
if (queue == null) {
|
||||
boolean placeChunks = this.fastmode || this.limit.FAST_PLACEMENT;
|
||||
World unwrapped = WorldWrapper.unwrap(world);
|
||||
if (unwrapped instanceof FaweQueue) {
|
||||
queue = (FaweQueue) unwrapped;
|
||||
} else if (unwrapped instanceof MCAWorld) {
|
||||
queue = ((MCAWorld) unwrapped).getQueue();
|
||||
} else if (player != null && world.equals(player.getWorld())) {
|
||||
queue = player.getFaweQueue(placeChunks, autoQueue);
|
||||
} else {
|
||||
queue = SetQueue.IMP.getNewQueue(world, placeChunks, autoQueue);
|
||||
}
|
||||
}
|
||||
if (combineStages == null) {
|
||||
combineStages =
|
||||
// If it's enabled in the settings
|
||||
Settings.IMP.HISTORY.COMBINE_STAGES
|
||||
// If fast placement is disabled, it's slower to perform a copy on each chunk
|
||||
&& this.limit.FAST_PLACEMENT
|
||||
// If the specific queue doesn't support it
|
||||
&& queue.supports(FaweQueue.Capability.CHANGE_TASKS)
|
||||
// If the edit uses items from the inventory we can't use a delayed task
|
||||
&& this.blockBag == null;
|
||||
}
|
||||
if (!Settings.IMP.QUEUE.PROGRESS.DISPLAY.equalsIgnoreCase("false") && player != null) {
|
||||
switch (Settings.IMP.QUEUE.PROGRESS.DISPLAY.toLowerCase()) {
|
||||
case "chat":
|
||||
this.queue.setProgressTask(new ChatProgressTracker(player));
|
||||
break;
|
||||
case "title":
|
||||
case "true":
|
||||
default:
|
||||
this.queue.setProgressTask(new DefaultProgressTracker(player));
|
||||
}
|
||||
}
|
||||
this.bypassAll = wrapExtent(new FastWorldEditExtent(world, queue), eventBus, event, EditSession.Stage.BEFORE_CHANGE);
|
||||
this.bypassHistory = (this.extent = wrapExtent(bypassAll, eventBus, event, EditSession.Stage.BEFORE_REORDER));
|
||||
if (!this.fastmode || changeSet != null) {
|
||||
if (changeSet == null) {
|
||||
if (Settings.IMP.HISTORY.USE_DISK) {
|
||||
UUID uuid = player == null ? EditSession.CONSOLE : player.getUUID();
|
||||
if (Settings.IMP.HISTORY.USE_DATABASE) {
|
||||
changeSet = new RollbackOptimizedHistory(world, uuid);
|
||||
} else {
|
||||
changeSet = new DiskStorageHistory(world, uuid);
|
||||
}
|
||||
} else if (combineStages && Settings.IMP.HISTORY.COMPRESSION_LEVEL == 0 && !(queue instanceof MCAQueue)) {
|
||||
changeSet = new CPUOptimizedChangeSet(world);
|
||||
} else {
|
||||
changeSet = new MemoryOptimizedHistory(world);
|
||||
}
|
||||
}
|
||||
if (this.limit.SPEED_REDUCTION > 0) {
|
||||
this.bypassHistory = new SlowExtent(this.bypassHistory, this.limit.SPEED_REDUCTION);
|
||||
}
|
||||
if (changeSet instanceof NullChangeSet && Fawe.imp().getBlocksHubApi() != null && player != null) {
|
||||
changeSet = LoggingChangeSet.wrap(player, changeSet);
|
||||
}
|
||||
if (!(changeSet instanceof NullChangeSet)) {
|
||||
if (!(changeSet instanceof LoggingChangeSet) && player != null && Fawe.imp().getBlocksHubApi() != null) {
|
||||
changeSet = LoggingChangeSet.wrap(player, changeSet);
|
||||
}
|
||||
if (this.blockBag != null) {
|
||||
changeSet = new BlockBagChangeSet(changeSet, blockBag, limit.INVENTORY_MODE == 1);
|
||||
}
|
||||
if (combineStages) {
|
||||
changeTask = changeSet;
|
||||
changeSet.addChangeTask(queue);
|
||||
} else {
|
||||
this.extent = (history = new HistoryExtent(bypassHistory, changeSet, queue));
|
||||
// if (this.blockBag != null) {
|
||||
// this.extent = new BlockBagExtent(this.extent, blockBag, limit.INVENTORY_MODE == 1);
|
||||
// if (queue == null) {
|
||||
// boolean placeChunks = this.fastmode || this.limit.FAST_PLACEMENT;
|
||||
// World unwrapped = WorldWrapper.unwrap(world);
|
||||
// if (unwrapped instanceof FaweQueue) {
|
||||
// queue = (FaweQueue) unwrapped;
|
||||
// } else if (unwrapped instanceof MCAWorld) {
|
||||
// queue = ((MCAWorld) unwrapped).getQueue();
|
||||
// } else if (player != null && world.equals(player.getWorld())) {
|
||||
// queue = player.getFaweQueue(placeChunks, autoQueue);
|
||||
// } else {
|
||||
// queue = SetQueue.IMP.getNewQueue(world, placeChunks, autoQueue);
|
||||
// }
|
||||
// }
|
||||
// if (combineStages == null) {
|
||||
// combineStages =
|
||||
// // If it's enabled in the settings
|
||||
// Settings.IMP.HISTORY.COMBINE_STAGES
|
||||
// // If fast placement is disabled, it's slower to perform a copy on each chunk
|
||||
// && this.limit.FAST_PLACEMENT
|
||||
// // If the specific queue doesn't support it
|
||||
// && queue.supports(FaweQueue.Capability.CHANGE_TASKS)
|
||||
// // If the edit uses items from the inventory we can't use a delayed task
|
||||
// && this.blockBag == null;
|
||||
// }
|
||||
// if (!Settings.IMP.QUEUE.PROGRESS.DISPLAY.equalsIgnoreCase("false") && player != null) {
|
||||
// switch (Settings.IMP.QUEUE.PROGRESS.DISPLAY.toLowerCase()) {
|
||||
// case "chat":
|
||||
// this.queue.setProgressTask(new ChatProgressTracker(player));
|
||||
// break;
|
||||
// case "title":
|
||||
// case "true":
|
||||
// default:
|
||||
// this.queue.setProgressTask(new DefaultProgressTracker(player));
|
||||
// }
|
||||
// }
|
||||
// this.bypassAll = wrapExtent(new FastWorldEditExtent(world, queue), eventBus, event, EditSession.Stage.BEFORE_CHANGE);
|
||||
// this.bypassHistory = (this.extent = wrapExtent(bypassAll, eventBus, event, EditSession.Stage.BEFORE_REORDER));
|
||||
// if (!this.fastmode || changeSet != null) {
|
||||
// if (changeSet == null) {
|
||||
// if (Settings.IMP.HISTORY.USE_DISK) {
|
||||
// UUID uuid = player == null ? EditSession.CONSOLE : player.getUUID();
|
||||
// if (Settings.IMP.HISTORY.USE_DATABASE) {
|
||||
// changeSet = new RollbackOptimizedHistory(world, uuid);
|
||||
// } else {
|
||||
// changeSet = new DiskStorageHistory(world, uuid);
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
if (allowedRegions == null) {
|
||||
if (player != null && !player.hasPermission("fawe.bypass") && !player.hasPermission("fawe.bypass.regions") && !(queue instanceof VirtualWorld)) {
|
||||
allowedRegions = player.getCurrentRegions();
|
||||
}
|
||||
}
|
||||
this.maxY = world == null ? 255 : world.getMaxY();
|
||||
if (allowedRegions != null) {
|
||||
if (allowedRegions.length == 0) {
|
||||
this.extent = new NullExtent(this.extent, FaweException.NO_REGION);
|
||||
} else {
|
||||
this.extent = new ProcessedWEExtent(this.extent, this.limit);
|
||||
if (allowedRegions.length == 1) {
|
||||
this.extent = new SingleRegionExtent(this.extent, this.limit, allowedRegions[0]);
|
||||
} else {
|
||||
this.extent = new MultiRegionExtent(this.extent, this.limit, allowedRegions);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.extent = new HeightBoundExtent(this.extent, this.limit, 0, maxY);
|
||||
}
|
||||
if (this.limit.STRIP_NBT != null && !this.limit.STRIP_NBT.isEmpty()) {
|
||||
this.extent = new StripNBTExtent(this.extent, this.limit.STRIP_NBT);
|
||||
}
|
||||
this.extent = wrapExtent(this.extent, eventBus, event, EditSession.Stage.BEFORE_HISTORY);
|
||||
// } else if (combineStages && Settings.IMP.HISTORY.COMPRESSION_LEVEL == 0 && !(queue instanceof MCAQueue)) {
|
||||
// changeSet = new CPUOptimizedChangeSet(world);
|
||||
// } else {
|
||||
// changeSet = new MemoryOptimizedHistory(world);
|
||||
// }
|
||||
// }
|
||||
// if (this.limit.SPEED_REDUCTION > 0) {
|
||||
// this.bypassHistory = new SlowExtent(this.bypassHistory, this.limit.SPEED_REDUCTION);
|
||||
// }
|
||||
// if (changeSet instanceof NullChangeSet && Fawe.imp().getBlocksHubApi() != null && player != null) {
|
||||
// changeSet = LoggingChangeSet.wrap(player, changeSet);
|
||||
// }
|
||||
// if (!(changeSet instanceof NullChangeSet)) {
|
||||
// if (!(changeSet instanceof LoggingChangeSet) && player != null && Fawe.imp().getBlocksHubApi() != null) {
|
||||
// changeSet = LoggingChangeSet.wrap(player, changeSet);
|
||||
// }
|
||||
// if (this.blockBag != null) {
|
||||
// changeSet = new BlockBagChangeSet(changeSet, blockBag, limit.INVENTORY_MODE == 1);
|
||||
// }
|
||||
// if (combineStages) {
|
||||
// changeTask = changeSet;
|
||||
// changeSet.addChangeTask(queue);
|
||||
// } else {
|
||||
// this.extent = (history = new HistoryExtent(bypassHistory, changeSet, queue));
|
||||
//// if (this.blockBag != null) {
|
||||
//// this.extent = new BlockBagExtent(this.extent, blockBag, limit.INVENTORY_MODE == 1);
|
||||
//// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if (allowedRegions == null) {
|
||||
// if (player != null && !player.hasPermission("fawe.bypass") && !player.hasPermission("fawe.bypass.regions") && !(queue instanceof VirtualWorld)) {
|
||||
// allowedRegions = player.getCurrentRegions();
|
||||
// }
|
||||
// }
|
||||
// this.maxY = world == null ? 255 : world.getMaxY();
|
||||
// if (allowedRegions != null) {
|
||||
// if (allowedRegions.length == 0) {
|
||||
// this.extent = new NullExtent(this.extent, FaweException.NO_REGION);
|
||||
// } else {
|
||||
// this.extent = new ProcessedWEExtent(this.extent, this.limit);
|
||||
// if (allowedRegions.length == 1) {
|
||||
// this.extent = new SingleRegionExtent(this.extent, this.limit, allowedRegions[0]);
|
||||
// } else {
|
||||
// this.extent = new MultiRegionExtent(this.extent, this.limit, allowedRegions);
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// this.extent = new HeightBoundExtent(this.extent, this.limit, 0, maxY);
|
||||
// }
|
||||
// if (this.limit.STRIP_NBT != null && !this.limit.STRIP_NBT.isEmpty()) {
|
||||
// this.extent = new StripNBTExtent(this.extent, this.limit.STRIP_NBT);
|
||||
// }
|
||||
// this.extent = wrapExtent(this.extent, eventBus, event, EditSession.Stage.BEFORE_HISTORY);
|
||||
// return this;
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -445,10 +435,6 @@ public class EditSessionBuilder {
|
||||
return worldName;
|
||||
}
|
||||
|
||||
public FaweQueue getQueue() {
|
||||
return queue;
|
||||
}
|
||||
|
||||
public boolean isWrapped() {
|
||||
return wrapped;
|
||||
}
|
||||
|
@ -20,48 +20,33 @@
|
||||
package com.sk89q.worldedit;
|
||||
|
||||
import com.boydti.fawe.Fawe;
|
||||
import com.boydti.fawe.FaweAPI;
|
||||
import com.boydti.fawe.config.BBC;
|
||||
import com.boydti.fawe.config.Settings;
|
||||
import com.boydti.fawe.example.MappedFaweQueue;
|
||||
import com.boydti.fawe.jnbt.anvil.MCAQueue;
|
||||
import com.boydti.fawe.jnbt.anvil.MCAWorld;
|
||||
import com.boydti.fawe.logging.LoggingChangeSet;
|
||||
import com.boydti.fawe.logging.rollback.RollbackOptimizedHistory;
|
||||
import com.boydti.fawe.object.FaweLimit;
|
||||
import com.boydti.fawe.object.FawePlayer;
|
||||
import com.boydti.fawe.object.FaweQueue;
|
||||
import com.boydti.fawe.object.HasFaweQueue;
|
||||
import com.boydti.fawe.object.HistoryExtent;
|
||||
import com.boydti.fawe.object.NullChangeSet;
|
||||
import com.boydti.fawe.object.RegionWrapper;
|
||||
import com.boydti.fawe.object.RunnableVal;
|
||||
import com.boydti.fawe.object.brush.visualization.VirtualWorld;
|
||||
import com.boydti.fawe.object.changeset.BlockBagChangeSet;
|
||||
import com.boydti.fawe.object.changeset.CPUOptimizedChangeSet;
|
||||
import com.boydti.fawe.object.changeset.DiskStorageHistory;
|
||||
import com.boydti.fawe.object.changeset.FaweChangeSet;
|
||||
import com.boydti.fawe.object.changeset.MemoryOptimizedHistory;
|
||||
import com.boydti.fawe.object.collection.LocalBlockVectorSet;
|
||||
import com.boydti.fawe.object.exception.FaweException;
|
||||
import com.boydti.fawe.object.extent.*;
|
||||
import com.boydti.fawe.object.extent.FaweRegionExtent;
|
||||
import com.boydti.fawe.object.extent.NullExtent;
|
||||
import com.boydti.fawe.object.extent.ProcessedWEExtent;
|
||||
import com.boydti.fawe.object.extent.ResettableExtent;
|
||||
import com.boydti.fawe.object.extent.SourceMaskExtent;
|
||||
import com.boydti.fawe.object.function.SurfaceRegionFunction;
|
||||
import com.boydti.fawe.object.mask.ResettableMask;
|
||||
import com.boydti.fawe.object.pattern.ExistingPattern;
|
||||
import com.boydti.fawe.object.progress.ChatProgressTracker;
|
||||
import com.boydti.fawe.object.progress.DefaultProgressTracker;
|
||||
import com.boydti.fawe.util.EditSessionBuilder;
|
||||
import com.boydti.fawe.util.ExtentTraverser;
|
||||
import com.boydti.fawe.util.MaskTraverser;
|
||||
import com.boydti.fawe.util.MathMan;
|
||||
import com.boydti.fawe.util.MemUtil;
|
||||
import com.boydti.fawe.util.Perm;
|
||||
import com.boydti.fawe.util.SetQueue;
|
||||
import com.boydti.fawe.util.TaskManager;
|
||||
import com.boydti.fawe.wrappers.WorldWrapper;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||
@ -77,17 +62,25 @@ import com.sk89q.worldedit.extent.inventory.BlockBagExtent;
|
||||
import com.sk89q.worldedit.extent.world.SurvivalModeExtent;
|
||||
import com.sk89q.worldedit.function.GroundFunction;
|
||||
import com.sk89q.worldedit.function.RegionFunction;
|
||||
import com.sk89q.worldedit.function.RegionMaskingFilter;
|
||||
import com.sk89q.worldedit.function.block.BlockReplace;
|
||||
import com.sk89q.worldedit.function.block.Naturalizer;
|
||||
import com.sk89q.worldedit.function.generator.ForestGenerator;
|
||||
import com.sk89q.worldedit.function.generator.GardenPatchGenerator;
|
||||
import com.sk89q.worldedit.function.mask.*;
|
||||
import com.sk89q.worldedit.function.mask.BlockTypeMask;
|
||||
import com.sk89q.worldedit.function.mask.BoundedHeightMask;
|
||||
import com.sk89q.worldedit.function.mask.ExistingBlockMask;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.mask.MaskIntersection;
|
||||
import com.sk89q.worldedit.function.mask.MaskUnion;
|
||||
import com.sk89q.worldedit.function.mask.Masks;
|
||||
import com.sk89q.worldedit.function.mask.NoiseFilter2D;
|
||||
import com.sk89q.worldedit.function.mask.RegionMask;
|
||||
import com.sk89q.worldedit.function.mask.SingleBlockTypeMask;
|
||||
import com.sk89q.worldedit.function.mask.SolidBlockMask;
|
||||
import com.sk89q.worldedit.function.operation.ChangeSetExecutor;
|
||||
import com.sk89q.worldedit.function.operation.ForwardExtentCopy;
|
||||
import com.sk89q.worldedit.function.operation.Operation;
|
||||
import com.sk89q.worldedit.function.operation.Operations;
|
||||
import com.sk89q.worldedit.function.pattern.BlockPattern;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.function.pattern.WaterloggedRemover;
|
||||
import com.sk89q.worldedit.function.util.RegionOffset;
|
||||
@ -108,7 +101,6 @@ import com.sk89q.worldedit.internal.expression.runtime.ExpressionTimeoutExceptio
|
||||
import com.sk89q.worldedit.internal.expression.runtime.RValue;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.MathUtils;
|
||||
import com.sk89q.worldedit.math.MutableBlockVector2;
|
||||
import com.sk89q.worldedit.math.MutableBlockVector3;
|
||||
import com.sk89q.worldedit.math.Vector2;
|
||||
@ -123,16 +115,12 @@ import com.sk89q.worldedit.regions.EllipsoidRegion;
|
||||
import com.sk89q.worldedit.regions.FlatRegion;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.regions.Regions;
|
||||
import static com.sk89q.worldedit.regions.Regions.asFlatRegion;
|
||||
import static com.sk89q.worldedit.regions.Regions.maximumBlockY;
|
||||
import static com.sk89q.worldedit.regions.Regions.minimumBlockY;
|
||||
import com.sk89q.worldedit.regions.shape.ArbitraryBiomeShape;
|
||||
import com.sk89q.worldedit.regions.shape.ArbitraryShape;
|
||||
import com.sk89q.worldedit.regions.shape.RegionShape;
|
||||
import com.sk89q.worldedit.regions.shape.WorldEditExpressionEnvironment;
|
||||
import com.sk89q.worldedit.util.Countable;
|
||||
import com.sk89q.worldedit.util.Direction;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldedit.util.TreeGenerator;
|
||||
import com.sk89q.worldedit.util.eventbus.EventBus;
|
||||
import com.sk89q.worldedit.world.SimpleWorld;
|
||||
@ -151,7 +139,6 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@ -163,6 +150,12 @@ import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.sk89q.worldedit.regions.Regions.asFlatRegion;
|
||||
import static com.sk89q.worldedit.regions.Regions.maximumBlockY;
|
||||
import static com.sk89q.worldedit.regions.Regions.minimumBlockY;
|
||||
|
||||
/**
|
||||
* An {@link Extent} that handles history, {@link BlockBag}s, change limits,
|
||||
* block re-ordering, and much more. Most operations in WorldEdit use this class.
|
||||
@ -211,7 +204,6 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
|
||||
}
|
||||
private final World world;
|
||||
private final String worldName;
|
||||
private final FaweQueue queue;
|
||||
private boolean wrapped;
|
||||
private boolean fastMode;
|
||||
private final HistoryExtent history;
|
||||
@ -232,19 +224,18 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
|
||||
public static final UUID CONSOLE = UUID.fromString("1-1-3-3-7");
|
||||
|
||||
@Deprecated
|
||||
public EditSession(@Nonnull World world, @Nullable FaweQueue queue, @Nullable FawePlayer player, @Nullable FaweLimit limit, @Nullable FaweChangeSet changeSet, @Nullable RegionWrapper[] allowedRegions, @Nullable Boolean autoQueue, @Nullable Boolean fastmode, @Nullable Boolean checkMemory, @Nullable Boolean combineStages, @Nullable BlockBag blockBag, @Nullable EventBus bus, @Nullable EditSessionEvent event) {
|
||||
this(null, world, queue, player, limit, changeSet, allowedRegions, autoQueue, fastmode, checkMemory, combineStages, blockBag, bus, event);
|
||||
public EditSession(@Nonnull World world, @Nullable FawePlayer player, @Nullable FaweLimit limit, @Nullable FaweChangeSet changeSet, @Nullable RegionWrapper[] allowedRegions, @Nullable Boolean autoQueue, @Nullable Boolean fastmode, @Nullable Boolean checkMemory, @Nullable Boolean combineStages, @Nullable BlockBag blockBag, @Nullable EventBus bus, @Nullable EditSessionEvent event) {
|
||||
this(null, world, player, limit, changeSet, allowedRegions, autoQueue, fastmode, checkMemory, combineStages, blockBag, bus, event);
|
||||
}
|
||||
|
||||
public EditSession(@Nullable String worldName, @Nullable World world, @Nullable FaweQueue queue, @Nullable FawePlayer player, @Nullable FaweLimit limit, @Nullable FaweChangeSet changeSet, @Nullable Region[] allowedRegions, @Nullable Boolean autoQueue, @Nullable Boolean fastmode, @Nullable Boolean checkMemory, @Nullable Boolean combineStages, @Nullable BlockBag blockBag, @Nullable EventBus bus, @Nullable EditSessionEvent event) {
|
||||
this(new EditSessionBuilder(world, worldName).queue(queue).player(player).limit(limit).changeSet(changeSet).allowedRegions(allowedRegions).autoQueue(autoQueue).fastmode(fastmode).checkMemory(checkMemory).combineStages(combineStages).blockBag(blockBag).eventBus(bus).event(event));
|
||||
public EditSession(@Nullable String worldName, @Nullable World world, @Nullable FawePlayer player, @Nullable FaweLimit limit, @Nullable FaweChangeSet changeSet, @Nullable Region[] allowedRegions, @Nullable Boolean autoQueue, @Nullable Boolean fastmode, @Nullable Boolean checkMemory, @Nullable Boolean combineStages, @Nullable BlockBag blockBag, @Nullable EventBus bus, @Nullable EditSessionEvent event) {
|
||||
this(new EditSessionBuilder(world, worldName).player(player).limit(limit).changeSet(changeSet).allowedRegions(allowedRegions).autoQueue(autoQueue).fastmode(fastmode).checkMemory(checkMemory).combineStages(combineStages).blockBag(blockBag).eventBus(bus).event(event));
|
||||
}
|
||||
|
||||
public EditSession(EditSessionBuilder builder) {
|
||||
super(builder.compile().getExtent());
|
||||
this.world = builder.getWorld();
|
||||
this.worldName = builder.getWorldName();
|
||||
this.queue = builder.getQueue();
|
||||
this.wrapped = builder.isWrapped();
|
||||
this.fastMode = builder.hasFastMode();
|
||||
this.history = builder.getHistory();
|
||||
@ -268,7 +259,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
|
||||
* @param event the event to call with the extent
|
||||
*/
|
||||
public EditSession(EventBus eventBus, World world, int maxBlocks, @Nullable BlockBag blockBag, EditSessionEvent event) {
|
||||
this(world, null, null, null, null, null, true, null, null, null, blockBag, eventBus, event);
|
||||
this(world, null, null, null, null, true, null, null, null, blockBag, eventBus, event);
|
||||
}
|
||||
|
||||
public void setExtent(AbstractDelegateExtent extent) {
|
||||
@ -360,36 +351,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
|
||||
}
|
||||
bypassHistory = nullExtent;
|
||||
bypassAll = nullExtent;
|
||||
dequeue();
|
||||
if (!queue.isEmpty()) {
|
||||
if (Fawe.isMainThread()) {
|
||||
queue.clear();
|
||||
} else {
|
||||
SetQueue.IMP.addTask(() -> queue.clear());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove this EditSession from the queue<br>
|
||||
* - This doesn't necessarily stop it from being queued again
|
||||
*/
|
||||
public void dequeue() {
|
||||
if (queue != null) {
|
||||
SetQueue.IMP.dequeue(queue);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a task to run when this EditSession is done dispatching
|
||||
*
|
||||
* @param whenDone
|
||||
*/
|
||||
public void addNotifyTask(Runnable whenDone) {
|
||||
if (queue != null) {
|
||||
queue.addNotifyTask(whenDone);
|
||||
}
|
||||
return super.cancel();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -402,16 +364,6 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
|
||||
message.send(player, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the FaweQueue this EditSession uses to queue the changes<br>
|
||||
* - Note: All implementation queues for FAWE are instances of NMSMappedFaweQueue
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public FaweQueue getQueue() {
|
||||
return queue;
|
||||
}
|
||||
|
||||
// pkg private for TracedEditSession only, may later become public API
|
||||
boolean commitRequired() {
|
||||
return false;
|
||||
@ -481,26 +433,6 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
|
||||
changes++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the ChangeSet being used for this EditSession
|
||||
* - If history is disabled, no changeset can be set
|
||||
*
|
||||
* @param set (null = remove the changeset)
|
||||
*/
|
||||
public void setChangeSet(@Nullable FaweChangeSet set) {
|
||||
if (set == null) {
|
||||
disableHistory(true);
|
||||
} else {
|
||||
if (history != null) {
|
||||
history.setChangeSet(set);
|
||||
} else {
|
||||
changeTask = set;
|
||||
set.addChangeTask(queue);
|
||||
}
|
||||
}
|
||||
changes++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the maximum number of blocks that can be changed. -1 will be returned
|
||||
* if it the limit disabled.
|
||||
@ -847,31 +779,6 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
|
||||
return this.getExtent().setBiome(x, y, z, biome);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLight(int x, int y, int z) {
|
||||
return queue.getLight(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockLight(int x, int y, int z) {
|
||||
return queue.getEmmittedLight(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSkyLight(int x, int y, int z) {
|
||||
return queue.getSkyLight(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBrightness(int x, int y, int z) {
|
||||
return queue.getBrightness(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOpacity(int x, int y, int z) {
|
||||
return queue.getOpacity(x, y, z);
|
||||
}
|
||||
|
||||
public BlockState getBlock(int x, int y, int z) {
|
||||
return getExtent().getBlock(x, y, z);
|
||||
}
|
||||
@ -907,6 +814,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
|
||||
* @param maxY maximal height
|
||||
* @return height of highest block found or 'minY'
|
||||
*/
|
||||
@Override
|
||||
public int getHighestTerrainBlock(int x, int z, int minY, int maxY) {
|
||||
for (int y = maxY; y >= minY; --y) {
|
||||
if (getBlock(x, y, z).getBlockType().getMaterial().isMovementBlocker()) {
|
||||
@ -926,22 +834,18 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
|
||||
* @param filter a mask of blocks to consider, or null to consider any solid (movement-blocking) block
|
||||
* @return height of highest block found or 'minY'
|
||||
*/
|
||||
@Override
|
||||
public int getHighestTerrainBlock(int x, int z, int minY, int maxY, Mask filter) {
|
||||
for (int y = maxY; y >= minY; --y) {
|
||||
if (filter.test(mutablebv.setComponents(x, y, z))) {
|
||||
return y;
|
||||
}
|
||||
}
|
||||
|
||||
return minY;
|
||||
}
|
||||
|
||||
public BlockType getBlockType(int x, int y, int z) {
|
||||
if (!limit.MAX_CHECKS()) {
|
||||
throw FaweException.MAX_CHECKS;
|
||||
}
|
||||
int combinedId4Data = queue.getCombinedId4DataDebug(x, y, z, BlockTypes.AIR.getInternalId(), this);
|
||||
return BlockTypes.getFromStateId(combinedId4Data);
|
||||
return getBlock(x, y, z).getBlockType();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1208,15 +1112,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
|
||||
// Reset limit
|
||||
limit.set(originalLimit);
|
||||
// Enqueue it
|
||||
if (queue == null || queue.isEmpty()) {
|
||||
queue.dequeue();
|
||||
return;
|
||||
}
|
||||
if (Fawe.isMainThread()) {
|
||||
SetQueue.IMP.flush(queue);
|
||||
} else {
|
||||
queue.flush();
|
||||
}
|
||||
super.commit();
|
||||
if (getChangeSet() != null) {
|
||||
if (Settings.IMP.HISTORY.COMBINE_STAGES) {
|
||||
((FaweChangeSet) getChangeSet()).closeAsync();
|
||||
@ -1226,56 +1122,6 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Count the number of blocks of a given list of types in a region.
|
||||
*
|
||||
* @param region the region
|
||||
* @param searchIDs a list of IDs to search
|
||||
* @return the number of found blocks
|
||||
*/
|
||||
public int countBlock(final Region region, final Set<BlockType> searchIDs) {
|
||||
if (searchIDs.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
if (searchIDs.size() == 1) {
|
||||
final BlockType id = searchIDs.iterator().next();
|
||||
RegionVisitor visitor = new RegionVisitor(region, position -> getBlockType(position) == id, this);
|
||||
Operations.completeBlindly(visitor);
|
||||
return visitor.getAffected();
|
||||
}
|
||||
final boolean[] ids = new boolean[BlockTypes.size()];
|
||||
for (final BlockType id : searchIDs) {
|
||||
ids[id.getInternalId()] = true;
|
||||
}
|
||||
return this.countBlock(region, ids);
|
||||
}
|
||||
|
||||
public int countBlock(final Region region, final boolean[] ids) {
|
||||
RegionVisitor visitor = new RegionVisitor(region, position -> ids[getBlockType(position).getInternalId()], this);
|
||||
Operations.completeBlindly(visitor);
|
||||
return visitor.getAffected();
|
||||
}
|
||||
|
||||
public int countBlock(final Region region, final Mask mask) {
|
||||
RegionVisitor visitor = new RegionVisitor(region, mask::test, this);
|
||||
Operations.completeBlindly(visitor);
|
||||
return visitor.getAffected();
|
||||
}
|
||||
|
||||
/**
|
||||
* Count the number of blocks of a list of types in a region.
|
||||
*
|
||||
* @param region the region
|
||||
* @param searchBlocks the list of blocks to search
|
||||
* @return the number of blocks that matched the pattern
|
||||
*/
|
||||
public int countBlocks(Region region, Set<BlockStateHolder> searchBlocks) {
|
||||
Mask mask = new BlockMaskBuilder().addBlocks(searchBlocks).build(getExtent());
|
||||
RegionVisitor visitor = new RegionVisitor(region, mask::test, this);
|
||||
Operations.completeBlindly(visitor);
|
||||
return visitor.getAffected();
|
||||
}
|
||||
|
||||
public int fall(final Region region, boolean fullHeight, final BlockStateHolder replace) {
|
||||
FlatRegion flat = asFlatRegion(region);
|
||||
final int startPerformY = region.getMinimumPoint().getBlockY();
|
||||
@ -1520,137 +1366,6 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
|
||||
return replaceBlocks(region, mask, pattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets all the blocks inside a region to a given block type.
|
||||
*
|
||||
* @param region the region
|
||||
* @param block the block
|
||||
* @return number of blocks affected
|
||||
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
||||
*/
|
||||
public <B extends BlockStateHolder<B>> int setBlocks(Region region, B block) throws MaxChangedBlocksException {
|
||||
checkNotNull(region);
|
||||
checkNotNull(block);
|
||||
boolean hasNbt = block instanceof BaseBlock && ((BaseBlock)block).hasNbtData();
|
||||
|
||||
if (canBypassAll(region, false, true) && !hasNbt) {
|
||||
return changes = queue.setBlocks((CuboidRegion) region, block.getInternalId());
|
||||
}
|
||||
try {
|
||||
if (hasExtraExtents()) {
|
||||
RegionVisitor visitor = new RegionVisitor(region, new BlockReplace(getExtent(), (block)), this);
|
||||
Operations.completeBlindly(visitor);
|
||||
this.changes += visitor.getAffected();
|
||||
} else {
|
||||
for (BlockVector3 blockVector3 : region) {
|
||||
if (getExtent().setBlock(blockVector3, block)) {
|
||||
changes++;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (final WorldEditException e) {
|
||||
throw new RuntimeException("Unexpected exception", e);
|
||||
}
|
||||
return changes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets all the blocks inside a region to a given pattern.
|
||||
*
|
||||
* @param region the region
|
||||
* @param pattern the pattern that provides the replacement block
|
||||
* @return number of blocks affected
|
||||
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
||||
*/
|
||||
public int setBlocks(Region region, Pattern pattern) throws MaxChangedBlocksException {
|
||||
checkNotNull(region);
|
||||
checkNotNull(pattern);
|
||||
if (pattern instanceof BlockPattern) {
|
||||
return setBlocks(region, ((BlockPattern) pattern).getBlock());
|
||||
}
|
||||
if (pattern instanceof BlockStateHolder) {
|
||||
return setBlocks(region, (BlockStateHolder) pattern);
|
||||
}
|
||||
BlockReplace replace = new BlockReplace(this, pattern);
|
||||
RegionVisitor visitor = new RegionVisitor(region, replace, queue instanceof MappedFaweQueue ? (MappedFaweQueue) queue : null);
|
||||
Operations.completeBlindly(visitor);
|
||||
return this.changes = visitor.getAffected();
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces all the blocks matching a given filter, within a given region, to a block
|
||||
* returned by a given pattern.
|
||||
*
|
||||
* @param region the region to replace the blocks within
|
||||
* @param filter a list of block types to match, or null to use {@link ExistingBlockMask}
|
||||
* @param replacement the replacement block
|
||||
* @return number of blocks affected
|
||||
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
||||
*/
|
||||
public <B extends BlockStateHolder<B>> int replaceBlocks(Region region, Set<BaseBlock> filter, B replacement) throws MaxChangedBlocksException {
|
||||
return replaceBlocks(region, filter, (replacement));
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces all the blocks matching a given filter, within a given region, to a block
|
||||
* returned by a given pattern.
|
||||
*
|
||||
* @param region the region to replace the blocks within
|
||||
* @param filter a list of block types to match, or null to use {@link ExistingBlockMask}
|
||||
* @param pattern the pattern that provides the new blocks
|
||||
* @return number of blocks affected
|
||||
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
||||
*/
|
||||
public int replaceBlocks(Region region, Set<BaseBlock> filter, Pattern pattern) throws MaxChangedBlocksException {
|
||||
Mask mask = filter == null ? new ExistingBlockMask(this) : new BlockMaskBuilder().addBlocks(filter).build(this);
|
||||
return replaceBlocks(region, mask, pattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces all the blocks matching a given mask, within a given region, to a block
|
||||
* returned by a given pattern.
|
||||
*
|
||||
* @param region the region to replace the blocks within
|
||||
* @param mask the mask that blocks must match
|
||||
* @param pattern the pattern that provides the new blocks
|
||||
* @return number of blocks affected
|
||||
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
||||
*/
|
||||
public int replaceBlocks(Region region, Mask mask, Pattern pattern) throws MaxChangedBlocksException {
|
||||
checkNotNull(region);
|
||||
checkNotNull(mask);
|
||||
checkNotNull(pattern);
|
||||
|
||||
BlockReplace replace = new BlockReplace(this, pattern);
|
||||
RegionMaskingFilter filter = new RegionMaskingFilter(mask, replace);
|
||||
RegionVisitor visitor = new RegionVisitor(region, filter, queue instanceof MappedFaweQueue ? (MappedFaweQueue) queue : null);
|
||||
Operations.completeBlindly(visitor);
|
||||
return this.changes = visitor.getAffected();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the blocks at the center of the given region to the given pattern.
|
||||
* If the center sits between two blocks on a certain axis, then two blocks
|
||||
* will be placed to mark the center.
|
||||
*
|
||||
* @param region the region to find the center of
|
||||
* @param pattern the replacement pattern
|
||||
* @return the number of blocks placed
|
||||
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
||||
*/
|
||||
public int center(Region region, Pattern pattern) throws MaxChangedBlocksException {
|
||||
checkNotNull(region);
|
||||
checkNotNull(pattern);
|
||||
|
||||
Vector3 center = region.getCenter();
|
||||
Region centerRegion = new CuboidRegion(
|
||||
getWorld(), // Causes clamping of Y range
|
||||
BlockVector3.at(((int) center.getX()), ((int) center.getY()), ((int) center.getZ())),
|
||||
BlockVector3.at(MathUtils.roundHalfUp(center.getX()),
|
||||
center.getY(), MathUtils.roundHalfUp(center.getZ())));
|
||||
return setBlocks(centerRegion, pattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make the faces of the given region as if it was a {@link CuboidRegion}.
|
||||
*
|
||||
@ -1750,14 +1465,18 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
|
||||
if (region instanceof CuboidRegion) {
|
||||
return makeCuboidWalls(region, pattern);
|
||||
} else {
|
||||
for (BlockVector3 position : region) {
|
||||
int x = position.getBlockX();
|
||||
int y = position.getBlockY();
|
||||
int z = position.getBlockZ();
|
||||
if (!region.contains(x, z + 1) || !region.contains(x, z - 1) || !region.contains(x + 1, z) || !region.contains(x - 1, z)) {
|
||||
setBlock(position, pattern);
|
||||
replaceBlocks(region, new Mask() {
|
||||
@Override
|
||||
public boolean test(BlockVector3 position) {
|
||||
int x = position.getBlockX();
|
||||
int y = position.getBlockY();
|
||||
int z = position.getBlockZ();
|
||||
if (!region.contains(x, z + 1) || !region.contains(x, z - 1) || !region.contains(x + 1, z) || !region.contains(x - 1, z)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}, pattern);
|
||||
}
|
||||
return changes;
|
||||
}
|
||||
@ -1773,7 +1492,6 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
|
||||
*/
|
||||
public <B extends BlockStateHolder<B>> int overlayCuboidBlocks(Region region, B block) throws MaxChangedBlocksException {
|
||||
checkNotNull(block);
|
||||
|
||||
return overlayCuboidBlocks(region, (block));
|
||||
}
|
||||
|
||||
@ -3207,25 +2925,11 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
|
||||
Direction.DOWN.toBlockVector(),
|
||||
};
|
||||
|
||||
private static double lengthSq(double x, double y, double z) {
|
||||
return (x * x) + (y * y) + (z * z);
|
||||
}
|
||||
|
||||
private static double lengthSq(double x, double z) {
|
||||
return (x * x) + (z * z);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return worldName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockLightLevel(BlockVector3 position) {
|
||||
return queue.getEmmittedLight(position.getBlockX(), position.getBlockY(), position.getBlockZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean clearContainerBlockContents(BlockVector3 pos) {
|
||||
BaseBlock block = getFullBlock(pos);
|
||||
@ -3251,14 +2955,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
|
||||
for (int x = pos1.getX(); x <= pos2.getX(); x++) {
|
||||
for (int z = pos1.getBlockZ(); z <= pos2.getBlockZ(); z++) {
|
||||
for (int y = pos1.getY(); y <= pos2.getY(); y++) {
|
||||
int from = queue.getCombinedId4Data(x, y, z);
|
||||
queue.setBlock(x, y, z, from);
|
||||
if (BlockTypes.getFromStateId(from).getMaterial().hasContainer()) {
|
||||
CompoundTag tile = queue.getTileEntity(x, y, z);
|
||||
if (tile != null) {
|
||||
queue.setTile(x, y, z, tile);
|
||||
}
|
||||
}
|
||||
setBlock(x, y, z, getFullBlock(x, y, z));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3363,8 +3060,6 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
|
||||
if (changes != 0) {
|
||||
flushQueue();
|
||||
return true;
|
||||
} else {
|
||||
this.queue.clear();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -21,10 +21,9 @@ package com.sk89q.worldedit.command;
|
||||
|
||||
import com.boydti.fawe.Fawe;
|
||||
import com.boydti.fawe.FaweAPI;
|
||||
import com.boydti.fawe.beta.IQueueExtent;
|
||||
import com.boydti.fawe.beta.filters.SetFilter;
|
||||
import com.boydti.fawe.beta.implementation.QueueHandler;
|
||||
import com.boydti.fawe.beta.filters.CountFilter;
|
||||
import com.boydti.fawe.beta.filters.DistrFilter;
|
||||
import com.boydti.fawe.config.BBC;
|
||||
import com.boydti.fawe.example.NMSMappedFaweQueue;
|
||||
import com.boydti.fawe.object.FaweLimit;
|
||||
@ -77,8 +76,6 @@ import com.sk89q.worldedit.world.biome.BiomeTypes;
|
||||
import com.sk89q.worldedit.world.biome.Biomes;
|
||||
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.world.block.BlockTypes;
|
||||
import com.sk89q.worldedit.world.registry.BiomeRegistry;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -125,7 +122,7 @@ public class RegionCommands extends MethodCommands {
|
||||
public void debugtest(Player player, @Selection Region region) throws WorldEditException {
|
||||
QueueHandler queueHandler = Fawe.get().getQueueHandler();
|
||||
World world = player.getWorld();
|
||||
CountFilter filter = new CountFilter();
|
||||
DistrFilter filter = new DistrFilter();
|
||||
long start = System.currentTimeMillis();
|
||||
queueHandler.apply(world, region, filter);
|
||||
long diff = System.currentTimeMillis() - start;
|
||||
|
@ -66,7 +66,7 @@ public class AbstractDelegateExtent implements Extent, LightingExtent {
|
||||
*
|
||||
* @return the extent
|
||||
*/
|
||||
public Extent getExtent() {
|
||||
public final Extent getExtent() {
|
||||
return extent;
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
package com.sk89q.worldedit.extent;
|
||||
|
||||
import com.boydti.fawe.example.MappedFaweQueue;
|
||||
import com.boydti.fawe.jnbt.anvil.generator.CavesGen;
|
||||
import com.boydti.fawe.jnbt.anvil.generator.GenBase;
|
||||
import com.boydti.fawe.jnbt.anvil.generator.OreGen;
|
||||
@ -26,22 +27,35 @@ import com.boydti.fawe.jnbt.anvil.generator.Resource;
|
||||
import com.boydti.fawe.jnbt.anvil.generator.SchemGen;
|
||||
|
||||
import com.boydti.fawe.object.clipboard.WorldCopyClipboard;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
|
||||
import com.sk89q.worldedit.function.RegionMaskingFilter;
|
||||
import com.sk89q.worldedit.function.block.BlockReplace;
|
||||
import com.sk89q.worldedit.function.mask.BlockMask;
|
||||
import com.sk89q.worldedit.function.mask.BlockMaskBuilder;
|
||||
import com.sk89q.worldedit.function.mask.ExistingBlockMask;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.operation.Operation;
|
||||
import com.sk89q.worldedit.function.operation.Operations;
|
||||
import com.sk89q.worldedit.function.pattern.BlockPattern;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.function.visitor.RegionVisitor;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.MathUtils;
|
||||
import com.sk89q.worldedit.math.MutableBlockVector3;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.registry.state.PropertyGroup;
|
||||
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;
|
||||
@ -51,8 +65,11 @@ import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* A world, portion of a world, clipboard, or other object that can have blocks
|
||||
* set or entities placed.
|
||||
@ -328,7 +345,7 @@ public interface Extent extends InputExtent, OutputExtent {
|
||||
int[] counter = new int[BlockTypes.size()];
|
||||
|
||||
for (final BlockVector3 pt : region) {
|
||||
BlockType type = getBlockType(pt);
|
||||
BlockType type = getBlock(pt).getBlockType();
|
||||
counter[type.getInternalId()]++;
|
||||
}
|
||||
List<Countable<BlockType>> distribution = new ArrayList<>();
|
||||
@ -385,6 +402,10 @@ public interface Extent extends InputExtent, OutputExtent {
|
||||
return null;
|
||||
}
|
||||
|
||||
default boolean cancel() {
|
||||
|
||||
}
|
||||
|
||||
default int getMaxY() {
|
||||
return 255;
|
||||
}
|
||||
@ -401,4 +422,163 @@ public interface Extent extends InputExtent, OutputExtent {
|
||||
weClipboard.setOrigin(region.getMinimumPoint());
|
||||
return weClipboard;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Count the number of blocks of a list of types in a region.
|
||||
*
|
||||
* @param region the region
|
||||
* @param searchBlocks the list of blocks to search
|
||||
* @return the number of blocks that matched the block
|
||||
*/
|
||||
default int countBlocks(Region region, Set<BaseBlock> searchBlocks) {
|
||||
BlockMask mask = new BlockMask(this, searchBlocks);
|
||||
return countBlocks(region, mask);
|
||||
}
|
||||
|
||||
/**
|
||||
* Count the number of blocks of a list of types in a region.
|
||||
*
|
||||
* @param region the region
|
||||
* @param searchMask mask to match
|
||||
* @return the number of blocks that matched the mask
|
||||
*/
|
||||
default int countBlocks(Region region, Mask searchMask) {
|
||||
RegionVisitor visitor = new RegionVisitor(region, searchMask::test);
|
||||
Operations.completeBlindly(visitor);
|
||||
return visitor.getAffected();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets all the blocks inside a region to a given block type.
|
||||
*
|
||||
* @param region the region
|
||||
* @param block the block
|
||||
* @return number of blocks affected
|
||||
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
||||
*/
|
||||
default <B extends BlockStateHolder<B>> int setBlocks(Region region, B block) throws MaxChangedBlocksException {
|
||||
checkNotNull(region);
|
||||
checkNotNull(block);
|
||||
boolean hasNbt = block instanceof BaseBlock && ((BaseBlock)block).hasNbtData();
|
||||
|
||||
if (canBypassAll(region, false, true) && !hasNbt) {
|
||||
return changes = queue.setBlocks((CuboidRegion) region, block.getInternalId());
|
||||
}
|
||||
try {
|
||||
if (hasExtraExtents()) {
|
||||
RegionVisitor visitor = new RegionVisitor(region, new BlockReplace(getExtent(), (block)), this);
|
||||
Operations.completeBlindly(visitor);
|
||||
this.changes += visitor.getAffected();
|
||||
} else {
|
||||
for (BlockVector3 blockVector3 : region) {
|
||||
if (getExtent().setBlock(blockVector3, block)) {
|
||||
changes++;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (final WorldEditException e) {
|
||||
throw new RuntimeException("Unexpected exception", e);
|
||||
}
|
||||
return changes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets all the blocks inside a region to a given pattern.
|
||||
*
|
||||
* @param region the region
|
||||
* @param pattern the pattern that provides the replacement block
|
||||
* @return number of blocks affected
|
||||
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
||||
*/
|
||||
default int setBlocks(Region region, Pattern pattern) throws MaxChangedBlocksException {
|
||||
checkNotNull(region);
|
||||
checkNotNull(pattern);
|
||||
if (pattern instanceof BlockPattern) {
|
||||
return setBlocks(region, ((BlockPattern) pattern).getBlock());
|
||||
}
|
||||
if (pattern instanceof BlockStateHolder) {
|
||||
return setBlocks(region, (BlockStateHolder) pattern);
|
||||
}
|
||||
BlockReplace replace = new BlockReplace(this, pattern);
|
||||
RegionVisitor visitor = new RegionVisitor(region, replace, queue instanceof MappedFaweQueue ? (MappedFaweQueue) queue : null);
|
||||
Operations.completeBlindly(visitor);
|
||||
return this.changes = visitor.getAffected();
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces all the blocks matching a given filter, within a given region, to a block
|
||||
* returned by a given pattern.
|
||||
*
|
||||
* @param region the region to replace the blocks within
|
||||
* @param filter a list of block types to match, or null to use {@link com.sk89q.worldedit.function.mask.ExistingBlockMask}
|
||||
* @param replacement the replacement block
|
||||
* @return number of blocks affected
|
||||
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
||||
*/
|
||||
default <B extends BlockStateHolder<B>> int replaceBlocks(Region region, Set<BaseBlock> filter, B replacement) throws MaxChangedBlocksException {
|
||||
return replaceBlocks(region, filter, new BlockPattern(replacement));
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces all the blocks matching a given filter, within a given region, to a block
|
||||
* returned by a given pattern.
|
||||
*
|
||||
* @param region the region to replace the blocks within
|
||||
* @param filter a list of block types to match, or null to use {@link com.sk89q.worldedit.function.mask.ExistingBlockMask}
|
||||
* @param pattern the pattern that provides the new blocks
|
||||
* @return number of blocks affected
|
||||
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
||||
*/
|
||||
default int replaceBlocks(Region region, Set<BaseBlock> filter, Pattern pattern) throws MaxChangedBlocksException {
|
||||
Mask mask = filter == null ? new ExistingBlockMask(this) : new BlockMask(this, filter);
|
||||
return replaceBlocks(region, mask, pattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces all the blocks matching a given mask, within a given region, to a block
|
||||
* returned by a given pattern.
|
||||
*
|
||||
* @param region the region to replace the blocks within
|
||||
* @param mask the mask that blocks must match
|
||||
* @param pattern the pattern that provides the new blocks
|
||||
* @return number of blocks affected
|
||||
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
||||
*/
|
||||
default int replaceBlocks(Region region, Mask mask, Pattern pattern) throws MaxChangedBlocksException {
|
||||
checkNotNull(region);
|
||||
checkNotNull(mask);
|
||||
checkNotNull(pattern);
|
||||
|
||||
BlockReplace replace = new BlockReplace(this, pattern);
|
||||
RegionMaskingFilter filter = new RegionMaskingFilter(mask, replace);
|
||||
RegionVisitor visitor = new RegionVisitor(region, filter);
|
||||
Operations.completeLegacy(visitor);
|
||||
return visitor.getAffected();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the blocks at the center of the given region to the given pattern.
|
||||
* If the center sits between two blocks on a certain axis, then two blocks
|
||||
* will be placed to mark the center.
|
||||
*
|
||||
* @param region the region to find the center of
|
||||
* @param pattern the replacement pattern
|
||||
* @return the number of blocks placed
|
||||
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
||||
*/
|
||||
default int center(Region region, Pattern pattern) throws MaxChangedBlocksException {
|
||||
checkNotNull(region);
|
||||
checkNotNull(pattern);
|
||||
|
||||
Vector3 center = region.getCenter();
|
||||
Region centerRegion = new CuboidRegion(
|
||||
getWorld(), // Causes clamping of Y range
|
||||
BlockVector3.at(((int) center.getX()), ((int) center.getY()), ((int) center.getZ())),
|
||||
BlockVector3.at(MathUtils.roundHalfUp(center.getX()),
|
||||
center.getY(), MathUtils.roundHalfUp(center.getZ())));
|
||||
return setBlocks(centerRegion, pattern);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -56,10 +56,6 @@ public interface InputExtent {
|
||||
return getBlock(MutableBlockVector3.get(x, y, z));
|
||||
}
|
||||
|
||||
default BlockType getBlockType(BlockVector3 position) {
|
||||
return getBlock(position).getBlockType();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a immutable snapshot of the block at the given location.
|
||||
*
|
||||
|
@ -20,6 +20,7 @@
|
||||
package com.sk89q.worldedit.function.mask;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.extent.NullExtent;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
@ -34,12 +35,16 @@ import java.util.function.Predicate;
|
||||
public class BlockMask extends ABlockMask {
|
||||
private final boolean[] ordinals;
|
||||
|
||||
public BlockMask() {
|
||||
this(new NullExtent());
|
||||
}
|
||||
|
||||
public BlockMask(Extent extent) {
|
||||
this(extent, new boolean[BlockTypes.states.length]);
|
||||
}
|
||||
|
||||
public BlockMask(Extent extent, boolean[] ordinals) {
|
||||
super(extent);
|
||||
super(extent == null ? new NullExtent() : extent);
|
||||
this.ordinals = ordinals;
|
||||
}
|
||||
|
||||
|
@ -19,9 +19,12 @@
|
||||
|
||||
package com.sk89q.worldedit.function.mask;
|
||||
|
||||
import com.boydti.fawe.beta.DelegateFilter;
|
||||
import com.boydti.fawe.beta.Filter;
|
||||
import com.boydti.fawe.beta.FilterBlock;
|
||||
import com.sk89q.minecraft.util.commands.Link;
|
||||
import com.sk89q.worldedit.command.UtilityCommands;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@ -40,6 +43,28 @@ public interface Mask {
|
||||
*/
|
||||
boolean test(BlockVector3 vector);
|
||||
|
||||
default Filter toFilter(Runnable run) {
|
||||
return new Filter() {
|
||||
@Override
|
||||
public void applyBlock(FilterBlock block) {
|
||||
if (test(block)) {
|
||||
run.run();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
default <T extends Filter> DelegateFilter<T> toFilter(T filter) {
|
||||
return new DelegateFilter<T>(filter) {
|
||||
@Override
|
||||
public void applyBlock(FilterBlock block) {
|
||||
if (test(block)) {
|
||||
filter.applyBlock(block);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the 2D version of this mask if one exists.
|
||||
*
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
package com.sk89q.worldedit.function.pattern;
|
||||
|
||||
import com.boydti.fawe.beta.Filter;
|
||||
import com.boydti.fawe.beta.FilterBlock;
|
||||
import com.sk89q.minecraft.util.commands.Link;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
@ -32,7 +33,7 @@ import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
* Returns a {@link BlockStateHolder} for a given position.
|
||||
*/
|
||||
@Link(clazz = UtilityCommands.class, value = "patterns")
|
||||
public interface Pattern {
|
||||
public interface Pattern extends Filter {
|
||||
|
||||
/**
|
||||
* Return a {@link BlockStateHolder} for the given position.
|
||||
@ -45,4 +46,9 @@ public interface Pattern {
|
||||
default boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException {
|
||||
return set.setFullBlock(extent, apply(get));
|
||||
}
|
||||
|
||||
@Override
|
||||
default void applyBlock(final FilterBlock block) {
|
||||
apply(block, block, block);
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ import com.sk89q.jnbt.StringTag;
|
||||
import com.sk89q.jnbt.Tag;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.function.mask.ABlockMask;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.registry.state.Property;
|
||||
import com.sk89q.worldedit.registry.state.PropertyKey;
|
||||
@ -300,5 +301,4 @@ public class BaseBlock implements BlockStateHolder<BaseBlock> {
|
||||
return getAsString();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.function.mask.ABlockMask;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.mask.SingleBlockTypeMask;
|
||||
import com.sk89q.worldedit.function.pattern.FawePattern;
|
||||
@ -306,7 +307,11 @@ public class BlockType implements FawePattern, Keyed {
|
||||
return this.getDefaultState().toBaseBlock();
|
||||
}
|
||||
|
||||
public Mask toMask(Extent extent) {
|
||||
public SingleBlockTypeMask toMask() {
|
||||
return toMask(null);
|
||||
}
|
||||
|
||||
public SingleBlockTypeMask toMask(Extent extent) {
|
||||
return new SingleBlockTypeMask(extent, this);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user