More refactoring of check-if-in-battle code
This commit is contained in:
parent
80f37fc378
commit
c6b0cd9d26
2 changed files with 9 additions and 1 deletions
|
@ -1,5 +1,7 @@
|
||||||
# Upcoming changes
|
# Upcoming changes
|
||||||
|
|
||||||
|
More refactoring of check-if-in-battle lookup code.
|
||||||
|
|
||||||
# Version 1.21.3
|
# Version 1.21.3
|
||||||
|
|
||||||
Implemented "player-only" battles, which can be enabled in the server-side
|
Implemented "player-only" battles, which can be enabled in the server-side
|
||||||
|
|
|
@ -23,6 +23,7 @@ public class BattleManager
|
||||||
private Map<Integer, Combatant> recentlyLeftBattle;
|
private Map<Integer, Combatant> recentlyLeftBattle;
|
||||||
private BattleUpdater battleUpdater;
|
private BattleUpdater battleUpdater;
|
||||||
private Map<EntityIDDimPair, Integer> entityToBattleMap;
|
private Map<EntityIDDimPair, Integer> entityToBattleMap;
|
||||||
|
private EntityIDDimPair tempIDPair;
|
||||||
|
|
||||||
public BattleManager(Logger logger)
|
public BattleManager(Logger logger)
|
||||||
{
|
{
|
||||||
|
@ -32,6 +33,7 @@ public class BattleManager
|
||||||
battleUpdater = new BattleUpdater(this);
|
battleUpdater = new BattleUpdater(this);
|
||||||
entityToBattleMap = new HashMap<EntityIDDimPair, Integer>();
|
entityToBattleMap = new HashMap<EntityIDDimPair, Integer>();
|
||||||
MinecraftForge.EVENT_BUS.register(battleUpdater);
|
MinecraftForge.EVENT_BUS.register(battleUpdater);
|
||||||
|
tempIDPair = new EntityIDDimPair();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -361,6 +363,10 @@ public class BattleManager
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isInBattle(Entity entity) {
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue