@@ -14,7 +14,7 @@ public class AngleMask extends AbstractExtentMask implements ResettableMask {
1414 protected static double ADJACENT_MOD = 0.5 ;
1515 protected static double DIAGONAL_MOD = 1 / Math .sqrt (8 );
1616
17- protected final CachedMask mask ;
17+ private final SolidBlockMask mask ;
1818 protected final double max ;
1919 protected final double min ;
2020 protected final boolean overlay ;
@@ -32,7 +32,7 @@ public class AngleMask extends AbstractExtentMask implements ResettableMask {
3232
3333 public AngleMask (Extent extent , double min , double max , boolean overlay , int distance ) {
3434 super (extent );
35- this .mask = new CachedMask ( new SolidBlockMask (extent ) );
35+ this .mask = new SolidBlockMask (extent );
3636 this .min = min ;
3737 this .max = max ;
3838 this .checkFirst = max >= (Math .tan (90 * (Math .PI / 180 )));
@@ -126,26 +126,31 @@ protected boolean testSlope(Extent extent, int x, int y, int z) {
126126 }
127127 }
128128
129- private boolean adjacentAir (Extent extent , MutableBlockVector3 mutable ) {
130- int x = mutable .x ();
131- int y = mutable .y ();
132- int z = mutable .z ();
133- if (!mask .test (extent , mutable .setComponents (x + 1 , y , z ))) {
129+ // for optimal performance, this method should be called with base being a CharFilterBlock
130+ private boolean adjacentAir (Extent extent , BlockVector3 base ) {
131+ int y = base .y ();
132+ // we expect the data for blocks above and below to be loaded already
133+ // in which case caching/reading from cache has more overhead
134+ if (y != maxY && !SolidBlockMask .isSolid (base .getStateRelativeY (extent , 1 ))) {
134135 return true ;
135136 }
136- if (! mask . test ( extent , mutable . setComponents ( x - 1 , y , z ))) {
137+ if (y != minY && ! SolidBlockMask . isSolid ( base . getStateRelativeY ( extent , - 1 ))) {
137138 return true ;
138139 }
139- if (!mask .test (extent , mutable .setComponents (x , y , z + 1 ))) {
140+ // other positions might be in different chunks, go a slower, cached path there
141+ MutableBlockVector3 mutable = new MutableBlockVector3 ();
142+ int x = base .x ();
143+ int z = base .z ();
144+ if (!mask .test (extent , mutable .setComponents (x + 1 , y , z ))) {
140145 return true ;
141146 }
142- if (!mask .test (extent , mutable .setComponents (x , y , z - 1 ))) {
147+ if (!mask .test (extent , mutable .setComponents (x - 1 , y , z ))) {
143148 return true ;
144149 }
145- if (y != maxY && ! mask .test (extent , mutable .setComponents (x , y + 1 , z ))) {
150+ if (! mask .test (extent , mutable .setComponents (x , y , z + 1 ))) {
146151 return true ;
147152 }
148- return y != minY && ! mask .test (extent , mutable .setComponents (x , y - 1 , z ));
153+ return ! mask .test (extent , mutable .setComponents (x , y , z - 1 ));
149154 }
150155
151156 @ Override
@@ -156,8 +161,7 @@ public boolean test(BlockVector3 vector) {
156161 }
157162 int y = vector .y ();
158163 if (overlay ) {
159- MutableBlockVector3 mutable = new MutableBlockVector3 (vector );
160- if (y < maxY && !adjacentAir (null , mutable )) {
164+ if (y < maxY && !adjacentAir (getExtent (), vector )) {
161165 return false ;
162166 }
163167 }
@@ -179,13 +183,11 @@ public boolean test(final Extent extent, final BlockVector3 vector) {
179183 }
180184 }
181185
182- MutableBlockVector3 mutable = new MutableBlockVector3 (x , y , z );
183-
184- if (!mask .test (extent , mutable )) {
186+ if (!mask .test (extent , vector )) {
185187 return false ;
186188 }
187189 if (overlay ) {
188- if (y < maxY && !adjacentAir (extent , mutable )) {
190+ if (y < maxY && !adjacentAir (extent , vector )) {
189191 return lastValue = false ;
190192 }
191193 }
0 commit comments