Skip to content
Permalink
Browse files

Add extended Y limit configuration option

  • Loading branch information...
kenzierocks committed Jul 19, 2019
1 parent 12abdec commit f6c7a05823dc2d8f9f3c9dfe3f75d3cb5e28bd51
@@ -75,6 +75,7 @@
public int butcherMaxRadius = -1;
public boolean allowSymlinks = false;
public boolean serverSideCUI = true;
public boolean extendedYLimit = false;

protected String[] getDefaultDisallowedBlocks() {
List<BlockType> blockTypes = Lists.newArrayList(
@@ -118,6 +118,7 @@ public void load() {
butcherMaxRadius = getInt("butcher-max-radius", butcherMaxRadius);
allowSymlinks = getBool("allow-symbolic-links", allowSymlinks);
serverSideCUI = getBool("server-side-cui", serverSideCUI);
extendedYLimit = getBool("extended-y-limit", extendedYLimit);

LocalSession.MAX_HISTORY_SIZE = Math.max(15, getInt("history-size", 15));

@@ -124,6 +124,7 @@ public void load() {
String type = config.getString("shell-save-type", "").trim();
shellSaveType = type.isEmpty() ? null : type;

extendedYLimit = config.getBoolean("compat.extended-y-limit", false);
}

public void unload() {
@@ -19,19 +19,16 @@

package com.sk89q.worldedit.util.collection;

import com.google.common.collect.AbstractIterator;
import com.google.common.collect.Iterators;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.util.LocatedBlock;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import it.unimi.dsi.fastutil.longs.LongArrayList;
import it.unimi.dsi.fastutil.longs.LongListIterator;

import javax.annotation.Nullable;
import java.util.Collection;
import java.util.Iterator;
import java.util.function.Predicate;
import java.util.function.ToLongFunction;

import static com.google.common.base.Preconditions.checkNotNull;

@@ -41,7 +38,9 @@
public class LocatedBlockList implements Iterable<LocatedBlock> {

private final BlockMap blocks = BlockMap.create();
private final LongArrayList order = new LongArrayList();
private final PositionList order = PositionList.create(
WorldEdit.getInstance().getConfiguration().extendedYLimit
);

public LocatedBlockList() {
}
@@ -59,7 +58,7 @@ public void add(LocatedBlock setBlockCall) {

public <B extends BlockStateHolder<B>> void add(BlockVector3 location, B block) {
blocks.put(location, block.toBaseBlock());
order.add(location.toLongPackedForm());
order.add(location);
}

public boolean containsLocation(BlockVector3 location) {
@@ -81,39 +80,13 @@ public void clear() {

@Override
public Iterator<LocatedBlock> iterator() {
return new LocatedBlockIterator(order.listIterator(),
LongListIterator::hasNext,
LongListIterator::nextLong);
return Iterators.transform(order.iterator(), position ->
new LocatedBlock(position, blocks.get(position)));
}

public Iterator<LocatedBlock> reverseIterator() {
return new LocatedBlockIterator(order.listIterator(order.size()),
LongListIterator::hasPrevious,
LongListIterator::previousLong);
}

private final class LocatedBlockIterator extends AbstractIterator<LocatedBlock> {

private final LongListIterator iterator;
private final Predicate<LongListIterator> hasNext;
private final ToLongFunction<LongListIterator> next;

private LocatedBlockIterator(LongListIterator iterator,
Predicate<LongListIterator> hasNext,
ToLongFunction<LongListIterator> next) {
this.iterator = iterator;
this.hasNext = hasNext;
this.next = next;
}

@Override
protected LocatedBlock computeNext() {
if (!hasNext.test(iterator)) {
return endOfData();
}
BlockVector3 position = BlockVector3.fromLongPackedForm(next.applyAsLong(iterator));
return new LocatedBlock(position, blocks.get(position));
}
return Iterators.transform(order.reverseIterator(), position ->
new LocatedBlock(position, blocks.get(position)));
}

}
@@ -0,0 +1,72 @@
package com.sk89q.worldedit.util.collection;

import com.google.common.collect.AbstractIterator;
import com.sk89q.worldedit.math.BlockVector3;
import it.unimi.dsi.fastutil.longs.LongArrayList;
import it.unimi.dsi.fastutil.longs.LongList;
import it.unimi.dsi.fastutil.longs.LongListIterator;

import java.util.Iterator;
import java.util.function.Predicate;
import java.util.function.ToLongFunction;

class LongPositionList implements PositionList {

private final LongList delegate = new LongArrayList();

@Override
public BlockVector3 get(int index) {
return BlockVector3.fromLongPackedForm(delegate.getLong(index));
}

@Override
public void add(BlockVector3 vector) {
delegate.add(vector.toLongPackedForm());
}

@Override
public int size() {
return delegate.size();
}

@Override
public void clear() {
delegate.clear();
}

@Override
public Iterator<BlockVector3> iterator() {
return new PositionIterator(delegate.iterator(),
LongListIterator::hasNext,
LongListIterator::nextLong);
}

@Override
public Iterator<BlockVector3> reverseIterator() {
return new PositionIterator(delegate.listIterator(size()),
LongListIterator::hasPrevious,
LongListIterator::previousLong);
}

private static final class PositionIterator extends AbstractIterator<BlockVector3> {

private final LongListIterator iterator;
private final Predicate<LongListIterator> hasNext;
private final ToLongFunction<LongListIterator> next;

private PositionIterator(LongListIterator iterator,
Predicate<LongListIterator> hasNext,
ToLongFunction<LongListIterator> next) {
this.iterator = iterator;
this.hasNext = hasNext;
this.next = next;
}

@Override
protected BlockVector3 computeNext() {
return hasNext.test(iterator)
? BlockVector3.fromLongPackedForm(next.applyAsLong(iterator))
: endOfData();
}
}
}
@@ -0,0 +1,28 @@
package com.sk89q.worldedit.util.collection;

import com.sk89q.worldedit.math.BlockVector3;

import java.util.Iterator;

interface PositionList {

static PositionList create(boolean extendedYLimit) {
if (extendedYLimit) {
return new VectorPositionList();
}
return new LongPositionList();
}

BlockVector3 get(int index);

void add(BlockVector3 vector);

int size();

void clear();

Iterator<BlockVector3> iterator();

Iterator<BlockVector3> reverseIterator();

}
@@ -0,0 +1,52 @@
package com.sk89q.worldedit.util.collection;

import com.google.common.collect.AbstractIterator;
import com.sk89q.worldedit.math.BlockVector3;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;

import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

class VectorPositionList implements PositionList {

private final List<BlockVector3> delegate = new ObjectArrayList<>();

@Override
public BlockVector3 get(int index) {
return delegate.get(index);
}

@Override
public void add(BlockVector3 vector) {
delegate.add(vector);
}

@Override
public int size() {
return delegate.size();
}

@Override
public void clear() {
delegate.clear();
}

@Override
public Iterator<BlockVector3> iterator() {
return delegate.iterator();
}

@Override
public Iterator<BlockVector3> reverseIterator() {
return new AbstractIterator<BlockVector3>() {

private final ListIterator<BlockVector3> iterator = delegate.listIterator(size());

@Override
protected BlockVector3 computeNext() {
return iterator.hasPrevious() ? iterator.previous() : endOfData();
}
};
}
}
@@ -129,5 +129,7 @@ public void load() {

String type = node.getNode("shell-save-type").getString("").trim();
shellSaveType = type.equals("") ? null : type;

extendedYLimit = node.getNode("compat", "extended-y-limit").getBoolean(false);
}
}

0 comments on commit f6c7a05

Please sign in to comment.
You can’t perform that action at this time.