TurnBasedMinecraftMod/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/BattleUpdater.java

35 lines
960 B
Java
Raw Normal View History

2019-11-25 06:29:25 +00:00
package com.burnedkirby.TurnBasedMinecraft.common;
2023-12-29 08:20:14 +00:00
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.neoforge.event.TickEvent;
import java.util.concurrent.atomic.AtomicBoolean;
2018-09-06 08:08:36 +00:00
public class BattleUpdater
{
private BattleManager manager;
private AtomicBoolean isRunning;
private int tick;
private final int tickLimit = 3;
public BattleUpdater(BattleManager manager)
{
this.manager = manager;
isRunning = new AtomicBoolean(true);
tick = 0;
}
public void setRunning(boolean isRunning) {
this.isRunning.set(isRunning);
}
@SubscribeEvent
public void update(TickEvent.ServerTickEvent tickEvent) {
if(tickEvent.phase != TickEvent.Phase.START && isRunning.get() && ++tick > tickLimit) {
tick = 0;
manager.battleMap.entrySet().removeIf(entry -> entry.getValue().update());
manager.updateRecentlyLeftBattle();
}
}
}