v1.2.1
This commit is contained in:
parent
398034392f
commit
3321001b22
2 changed files with 36 additions and 3 deletions
|
@ -0,0 +1,21 @@
|
|||
package com.github.stachelbeere1248.zombiesutils.handlers;
|
||||
|
||||
import com.github.stachelbeere1248.zombiesutils.timer.Timer;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.monster.EntityZombie;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Round1Correction {
|
||||
|
||||
@SubscribeEvent
|
||||
public void onWaveSpawn(@NotNull EntityJoinWorldEvent event) {
|
||||
final Entity entity = event.entity;
|
||||
if (entity instanceof EntityZombie) {
|
||||
Timer.getInstance().ifPresent(Timer::correctRn);
|
||||
MinecraftForge.EVENT_BUS.unregister(this);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,10 +5,12 @@ import com.github.stachelbeere1248.zombiesutils.config.ZombiesUtilsConfig;
|
|||
import com.github.stachelbeere1248.zombiesutils.game.GameMode;
|
||||
import com.github.stachelbeere1248.zombiesutils.game.Map;
|
||||
import com.github.stachelbeere1248.zombiesutils.game.sla.SLA;
|
||||
import com.github.stachelbeere1248.zombiesutils.handlers.Round1Correction;
|
||||
import com.github.stachelbeere1248.zombiesutils.timer.recorder.Category;
|
||||
import com.github.stachelbeere1248.zombiesutils.timer.recorder.files.GameFile;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Optional;
|
||||
|
@ -17,22 +19,24 @@ public class Timer {
|
|||
|
||||
private static Timer instance;
|
||||
private final GameMode gameMode;
|
||||
private final long savedTotalWorldTime;
|
||||
private long savedTotalWorldTime;
|
||||
private int passedRoundsTickSum = 0;
|
||||
private final String serverNumber;
|
||||
public Category category;
|
||||
private final GameFile gameFile;
|
||||
private boolean pbTracking = false;
|
||||
private int round;
|
||||
private final Round1Correction correction;
|
||||
|
||||
/**
|
||||
* Constructs a timer and saves it to {@link #instance}.
|
||||
* @param serverNumber The game's server the timer should be bound to.
|
||||
* @param map The map the timer should be started for.
|
||||
* @param round If available, round to begin splitting.
|
||||
*/
|
||||
public Timer (@NotNull String serverNumber, @NotNull Map map, byte round) {
|
||||
savedTotalWorldTime = getCurrentTotalWorldTime();
|
||||
dropInstances();
|
||||
|
||||
this.savedTotalWorldTime = getCurrentTotalWorldTime();
|
||||
if (!serverNumber.trim().isEmpty()) this.serverNumber = serverNumber.trim();
|
||||
else throw new RuntimeException("invalid servernumber");
|
||||
|
||||
|
@ -43,6 +47,9 @@ public class Timer {
|
|||
this.round = round;
|
||||
if (ZombiesUtilsConfig.isSlaToggled()) SLA.instance = new SLA(map);
|
||||
|
||||
correction = new Round1Correction();
|
||||
MinecraftForge.EVENT_BUS.register(correction);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -65,6 +72,9 @@ public class Timer {
|
|||
passedRoundsTickSum = gameTime;
|
||||
round = passedRound;
|
||||
}
|
||||
public void correctRn() {
|
||||
savedTotalWorldTime = getCurrentTotalWorldTime()-200L;
|
||||
}
|
||||
|
||||
private void record(byte passedRound, short roundTime, int gameTime) {
|
||||
if (passedRound == (byte) 1) pbTracking = true;
|
||||
|
@ -111,6 +121,8 @@ public class Timer {
|
|||
* Call to invalidate {@link #instance} to trigger the garbage collector
|
||||
*/
|
||||
public static void dropInstances() {
|
||||
if (instance == null) return;
|
||||
if (instance.correction != null) MinecraftForge.EVENT_BUS.unregister(instance.correction);
|
||||
instance = null;
|
||||
}
|
||||
public byte getRound() {
|
||||
|
|
Loading…
Add table
Reference in a new issue