mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-11-16 17:16:11 +00:00
Fix Linear pattern index incrementing above array length (#2626)
* Fix index incrementing above array length in async * Add fork method
This commit is contained in:
parent
5e234a7003
commit
c10f58ac95
@ -1,5 +1,6 @@
|
||||
package com.fastasyncworldedit.core.function.pattern;
|
||||
|
||||
import com.fastasyncworldedit.core.queue.Filter;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.function.pattern.AbstractPattern;
|
||||
@ -7,6 +8,8 @@ import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class LinearBlockPattern extends AbstractPattern implements ResettablePattern {
|
||||
|
||||
private final Pattern[] patternsArray;
|
||||
@ -15,7 +18,7 @@ public class LinearBlockPattern extends AbstractPattern implements ResettablePat
|
||||
/**
|
||||
* Create a new {@link Pattern} instance
|
||||
*
|
||||
* @param patterns array of patterns to linearly choose from based on x/z coordinates
|
||||
* @param patterns array of patterns to linearly choose from
|
||||
*/
|
||||
public LinearBlockPattern(Pattern[] patterns) {
|
||||
this.patternsArray = patterns;
|
||||
@ -23,18 +26,20 @@ public class LinearBlockPattern extends AbstractPattern implements ResettablePat
|
||||
|
||||
@Override
|
||||
public BaseBlock applyBlock(BlockVector3 position) {
|
||||
if (index == patternsArray.length) {
|
||||
index = 0;
|
||||
}
|
||||
return patternsArray[index++].applyBlock(position);
|
||||
index = (index + 1) % patternsArray.length;
|
||||
return patternsArray[index].applyBlock(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException {
|
||||
if (index == patternsArray.length) {
|
||||
index = 0;
|
||||
index = (index + 1) % patternsArray.length;
|
||||
return patternsArray[index].apply(extent, get, set);
|
||||
}
|
||||
return patternsArray[index++].apply(extent, get, set);
|
||||
|
||||
@Override
|
||||
public Filter fork() {
|
||||
final Pattern[] forked = Arrays.stream(this.patternsArray).map(Pattern::fork).toArray(Pattern[]::new);
|
||||
return new LinearBlockPattern(forked);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user