private Sequencer sequencer;
private Clip clip;
private boolean playingIsSilly;
+ private boolean isPlaying;
public BattleMusic(Logger logger)
{
this.logger = logger;
battleMusic = new ArrayList<File>();
sillyMusic = new ArrayList<File>();
+ isPlaying = false;
try {
sequencer = MidiSystem.getSequencer();
play(nextBattle, volume);
pickNextBattle();
playingIsSilly = false;
+ isPlaying = true;
}
public void playSilly(float volume)
play(nextSilly, volume);
pickNextSilly();
playingIsSilly = true;
+ isPlaying = true;
}
private void play(File next, float volume)
}
}
- public void stopMusic()
+ public void stopMusic(boolean resumeMCSounds)
{
if(sequencer.isRunning())
{
clip.stop();
clip.close();
}
+ if(resumeMCSounds)
+ {
+ Minecraft.getMinecraft().addScheduledTask(() -> {
+ Minecraft.getMinecraft().getSoundHandler().resumeSounds();
+ });
+ }
+ isPlaying = false;
}
public boolean isPlayingSilly()
public boolean isPlaying()
{
- return sequencer.isRunning() || clip.isActive();
+ return isPlaying || sequencer.isRunning() || clip.isActive();
}
}
private Map<Integer, Combatant> sideB;
private Map<Integer, Combatant> players;
private PriorityQueue<Combatant> turnOrderQueue;
+ private Queue<Combatant> sideAEntryQueue;
+ private Queue<Combatant> sideBEntryQueue;
private State state;
private AtomicInteger playerCount;
this.sideB = new Hashtable<Integer, Combatant>();
players = new Hashtable<Integer, Combatant>();
turnOrderQueue = new PriorityQueue<Combatant>(new Combatant.CombatantComparator());
+ sideAEntryQueue = new ArrayDeque<Combatant>();
+ sideBEntryQueue = new ArrayDeque<Combatant>();
playerCount = new AtomicInteger(0);
undecidedCount = new AtomicInteger(0);
if(sideA != null)
Combatant newCombatant = new Combatant(e, entityInfo);
newCombatant.isSideA = true;
newCombatant.battleID = getId();
- sideA.put(e.getEntityId(), newCombatant);
+ if(isServer)
+ {
+ synchronized(sideAEntryQueue)
+ {
+ sideAEntryQueue.add(newCombatant);
+ }
+ }
+ else
+ {
+ sideA.put(e.getEntityId(), newCombatant);
+ }
if(e instanceof EntityPlayer)
{
newCombatant.recalcSpeedOnCompare = true;
Combatant newCombatant = new Combatant(e, entityInfo);
newCombatant.isSideA = false;
newCombatant.battleID = getId();
- sideB.put(e.getEntityId(), newCombatant);
+ if(isServer)
+ {
+ synchronized(sideBEntryQueue)
+ {
+ sideBEntryQueue.add(newCombatant);
+ }
+ }
+ else
+ {
+ sideB.put(e.getEntityId(), newCombatant);
+ }
if(e instanceof EntityPlayer)
{
newCombatant.recalcSpeedOnCompare = true;
*/
public boolean update()
{
- if(battleEnded)
+ if(!isServer)
+ {
+ return false;
+ }
+ else if(battleEnded)
{
return true;
}
{
return true;
}
+ synchronized(sideAEntryQueue)
+ {
+ for(Combatant c = sideAEntryQueue.poll(); c != null; c = sideAEntryQueue.poll())
+ {
+ sideA.put(c.entity.getEntityId(), c);
+ }
+ }
+ synchronized(sideBEntryQueue)
+ {
+ for(Combatant c = sideBEntryQueue.poll(); c != null; c = sideBEntryQueue.poll())
+ {
+ sideB.put(c.entity.getEntityId(), c);
+ }
+ }
if(TurnBasedMinecraftMod.config.isFreezeCombatantsEnabled())
{
enforceFreezePositions();