]> git.seodisparate.com - TurnBasedMinecraftMod/commitdiff
More refactoring of check-if-in-battle code
authorStephen Seo <seo.disparate@gmail.com>
Wed, 24 Aug 2022 05:03:45 +0000 (14:03 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Fri, 2 Sep 2022 10:41:03 +0000 (19:41 +0900)
Changelog.md
src/main/java/com/burnedkirby/TurnBasedMinecraft/common/BattleManager.java

index 1ce708c7d71bcd1d4f0e5a3bc04c096543df78e8..e27d61bcc8db96768a3ead76fea29b06a71a33b8 100644 (file)
@@ -1,5 +1,7 @@
 # Upcoming changes
 
+More refactoring of check-if-in-battle lookup code.
+
 # Version 1.21.3
 
 Implemented "player-only" battles, which can be enabled in the server-side
index 28978def9b8198900060007b1123283f244c8760..0b5f3c050d377cdfc7f799d78150ef449df4b752 100644 (file)
@@ -23,6 +23,7 @@ public class BattleManager
     private Map<Integer, Combatant> recentlyLeftBattle;
     private BattleUpdater battleUpdater;
     private Map<EntityIDDimPair, Integer> entityToBattleMap;
+    private EntityIDDimPair tempIDPair;
 
     public BattleManager(Logger logger)
     {
@@ -32,6 +33,7 @@ public class BattleManager
         battleUpdater = new BattleUpdater(this);
         entityToBattleMap = new HashMap<EntityIDDimPair, Integer>();
         MinecraftForge.EVENT_BUS.register(battleUpdater);
+        tempIDPair = new EntityIDDimPair();
     }
     
     /**
@@ -361,6 +363,10 @@ public class BattleManager
     }
 
     public boolean isInBattle(Entity entity) {
-        return entityToBattleMap.keySet().contains(new EntityIDDimPair(entity));
+        synchronized(tempIDPair) {
+            tempIDPair.id = entity.getId();
+            tempIDPair.dim = entity.level.dimension();
+            return entityToBattleMap.keySet().contains(tempIDPair);
+        }
     }
 }
\ No newline at end of file