Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add extended Y limit configuration option
- Loading branch information
1 parent
12abdec
commit f6c7a05
Showing
8 changed files
with
167 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
worldedit-core/src/main/java/com/sk89q/worldedit/util/collection/LongPositionList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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(); | |||
} | |||
} | |||
} |
28 changes: 28 additions & 0 deletions
28
worldedit-core/src/main/java/com/sk89q/worldedit/util/collection/PositionList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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(); | |||
|
|||
} |
52 changes: 52 additions & 0 deletions
52
worldedit-core/src/main/java/com/sk89q/worldedit/util/collection/VectorPositionList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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(); | |||
} | |||
}; | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters