@@ -23,6 +23,7 @@ class ApplyTask<F extends Filter> extends RecursiveAction implements Runnable {
2323 private static final int SHIFT_REDUCTION = 1 ;
2424
2525 private final CommonState <F > commonState ;
26+ private final Region region ;
2627 private final ApplyTask <F > before ;
2728 private final int minChunkX ;
2829 private final int minChunkZ ;
@@ -39,7 +40,6 @@ public void run() {
3940
4041 private record CommonState <F extends Filter >(
4142 F originalFilter ,
42- Region region ,
4343 ParallelQueueExtent parallelQueueExtent ,
4444 ConcurrentMap <Thread , ThreadState <F >> stateCache ,
4545 boolean full ,
@@ -69,12 +69,12 @@ private ThreadState(SingleThreadQueueExtent queue, F filter) {
6969 ) {
7070 this .commonState = new CommonState <>(
7171 filter ,
72- region .clone (), // clone only once, assuming the filter doesn't modify that clone
7372 parallelQueueExtent ,
7473 new ConcurrentHashMap <>(),
7574 full ,
7675 faweExceptionReasonsUsed
7776 );
77+ this .region = region .clone ();
7878 this .before = null ;
7979 final BlockVector3 minimumPoint = region .getMinimumPoint ();
8080 this .minChunkX = minimumPoint .x () >> 4 ;
@@ -88,6 +88,7 @@ private ThreadState(SingleThreadQueueExtent queue, F filter) {
8888
8989 private ApplyTask (
9090 final CommonState <F > commonState ,
91+ final Region region ,
9192 final ApplyTask <F > before ,
9293 final int minChunkX ,
9394 final int maxChunkX ,
@@ -96,6 +97,7 @@ private ApplyTask(
9697 final int higherShift
9798 ) {
9899 this .commonState = commonState ;
100+ this .region = region .clone ();
99101 this .minChunkX = minChunkX ;
100102 this .maxChunkX = maxChunkX ;
101103 this .minChunkZ = minChunkZ ;
@@ -120,14 +122,15 @@ protected void compute() {
120122 processRegion (regionX , regionZ , this .shift );
121123 continue ;
122124 }
123- if (this .shift == 0 && !this .commonState . region .containsChunk (regionX , regionZ )) {
125+ if (this .shift == 0 && !this .region .containsChunk (regionX , regionZ )) {
124126 // if shift == 0, region coords are chunk coords
125127 continue ; // chunks not intersecting with the region don't need a task
126128 }
127129
128130 // creating more tasks will likely help parallelism as other threads aren't *that* busy
129131 subtask = new ApplyTask <>(
130132 this .commonState ,
133+ this .region ,
131134 subtask ,
132135 regionX << this .shift ,
133136 ((regionX + 1 ) << this .shift ) - 1 ,
@@ -166,7 +169,7 @@ private void processRegion(int regionX, int regionZ, int shift) {
166169 try {
167170 for (int chunkX = regionX << shift ; chunkX <= ((regionX + 1 ) << shift ) - 1 ; chunkX ++) {
168171 for (int chunkZ = regionZ << shift ; chunkZ <= ((regionZ + 1 ) << shift ) - 1 ; chunkZ ++) {
169- if (!this .commonState . region .containsChunk (chunkX , chunkZ )) {
172+ if (!this .region .containsChunk (chunkX , chunkZ )) {
170173 continue ; // chunks not intersecting with the region must not be processed
171174 }
172175 applyChunk (chunkX , chunkZ , state );
@@ -204,7 +207,7 @@ private void applyChunk(int chunkX, int chunkZ, ThreadState<F> state) {
204207 state .block = state .queue .apply (
205208 state .block ,
206209 state .filter ,
207- this .commonState . region ,
210+ this .region ,
208211 chunkX ,
209212 chunkZ ,
210213 this .commonState .full
0 commit comments