Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-12-24 18:10:08 +01:00
Fix Linear pattern index incrementing above array length (#2626)
* Fix index incrementing above array length in async * Add fork method
Dieser Commit ist enthalten in:
Ursprung
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;
|
||||
}
|
||||
return patternsArray[index++].apply(extent, get, set);
|
||||
index = (index + 1) % patternsArray.length;
|
||||
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
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren