11package com .fastasyncworldedit .core .function .pattern ;
22
3+ import com .fastasyncworldedit .core .queue .Filter ;
34import com .sk89q .worldedit .WorldEditException ;
45import com .sk89q .worldedit .extent .Extent ;
56import com .sk89q .worldedit .function .pattern .AbstractPattern ;
67import com .sk89q .worldedit .function .pattern .Pattern ;
78import com .sk89q .worldedit .math .BlockVector3 ;
89import com .sk89q .worldedit .world .block .BaseBlock ;
910
11+ import java .util .Arrays ;
12+
1013public class LinearBlockPattern extends AbstractPattern implements ResettablePattern {
1114
1215 private final Pattern [] patternsArray ;
@@ -15,26 +18,28 @@ public class LinearBlockPattern extends AbstractPattern implements ResettablePat
1518 /**
1619 * Create a new {@link Pattern} instance
1720 *
18- * @param patterns array of patterns to linearly choose from based on x/z coordinates
21+ * @param patterns array of patterns to linearly choose from
1922 */
2023 public LinearBlockPattern (Pattern [] patterns ) {
2124 this .patternsArray = patterns ;
2225 }
2326
2427 @ Override
2528 public BaseBlock applyBlock (BlockVector3 position ) {
26- if (index == patternsArray .length ) {
27- index = 0 ;
28- }
29- return patternsArray [index ++].applyBlock (position );
29+ index = (index + 1 ) % patternsArray .length ;
30+ return patternsArray [index ].applyBlock (position );
3031 }
3132
3233 @ Override
3334 public boolean apply (Extent extent , BlockVector3 get , BlockVector3 set ) throws WorldEditException {
34- if (index == patternsArray .length ) {
35- index = 0 ;
36- }
37- return patternsArray [index ++].apply (extent , get , set );
35+ index = (index + 1 ) % patternsArray .length ;
36+ return patternsArray [index ].apply (extent , get , set );
37+ }
38+
39+ @ Override
40+ public Filter fork () {
41+ final Pattern [] forked = Arrays .stream (this .patternsArray ).map (Pattern ::fork ).toArray (Pattern []::new );
42+ return new LinearBlockPattern (forked );
3843 }
3944
4045 @ Override
0 commit comments