44import java .util .LinkedHashMap ;
55import java .util .List ;
66import java .util .Map ;
7+ import java .util .Objects ;
78import java .util .Set ;
89import java .util .UUID ;
910import java .util .concurrent .atomic .AtomicBoolean ;
@@ -75,12 +76,12 @@ synchronized void replace(
7576 if (viewer == null || !viewer .isOnline ()) {
7677 continue ;
7778 }
78- List <InteractionGeometry > geometry = interactionGeometry (interactions );
7979 ActiveProxies current = previous .get (viewerId );
80- if (this .canReuse (viewerId , viewer , current , geometry )) {
80+ if (this .canReuse (viewerId , viewer , current , interactions )) {
8181 next .put (viewerId , current );
8282 continue ;
8383 }
84+ List <InteractionGeometry > geometry = interactionGeometry (interactions );
8485 List <ClientProxy > proxies = this .backend .create (viewer , interactions );
8586 if (!proxies .isEmpty ()) {
8687 ActiveProxies created = new ActiveProxies (
@@ -135,11 +136,11 @@ private boolean canReuse(
135136 UUID viewerId ,
136137 Player viewer ,
137138 ActiveProxies active ,
138- List <InteractionGeometry > geometry
139+ List <DisplayInteractionRayRegistry . RayInteraction > interactions
139140 ) {
140141 if (active == null
141142 || active .viewer () != viewer
142- || !active .geometry (). equals ( geometry )
143+ || !sameGeometry ( active .geometry (), interactions )
143144 || active .proxies ().isEmpty ()) {
144145 return false ;
145146 }
@@ -153,6 +154,21 @@ private boolean canReuse(
153154 return true ;
154155 }
155156
157+ private static boolean sameGeometry (
158+ List <InteractionGeometry > geometry ,
159+ List <DisplayInteractionRayRegistry .RayInteraction > interactions
160+ ) {
161+ if (geometry .size () != interactions .size ()) {
162+ return false ;
163+ }
164+ for (int index = 0 ; index < geometry .size (); index ++) {
165+ if (!geometry .get (index ).matches (interactions .get (index ))) {
166+ return false ;
167+ }
168+ }
169+ return true ;
170+ }
171+
156172 private static List <InteractionGeometry > interactionGeometry (
157173 List <DisplayInteractionRayRegistry .RayInteraction > interactions
158174 ) {
@@ -355,6 +371,17 @@ private record InteractionGeometry(
355371 float height ,
356372 float depth
357373 ) {
374+ private boolean matches (DisplayInteractionRayRegistry .RayInteraction interaction ) {
375+ return Objects .equals (this .worldId , interaction .worldId ())
376+ && Double .compare (this .centerX , interaction .centerX ()) == 0
377+ && Double .compare (this .centerY , interaction .centerY ()) == 0
378+ && Double .compare (this .centerZ , interaction .centerZ ()) == 0
379+ && Double .compare (this .acrossX , interaction .acrossX ()) == 0
380+ && Double .compare (this .acrossZ , interaction .acrossZ ()) == 0
381+ && Float .compare (this .width , interaction .width ()) == 0
382+ && Float .compare (this .height , interaction .height ()) == 0
383+ && Float .compare (this .depth , interaction .depth ()) == 0 ;
384+ }
358385 }
359386
360387 private static final class SparrowBackend implements Backend {
0 commit comments