More refactoring of check-if-in-battle code

This commit is contained in:
Stephen Seo 2022-08-24 14:03:45 +09:00
parent 80f37fc378
commit c6b0cd9d26
2 changed files with 9 additions and 1 deletions

View 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

View 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);
}
}
}