From 656af973893901559cd7074509e21ddf108f84aa Mon Sep 17 00:00:00 2001 From: Stachelbeere1248 Date: Sun, 26 Nov 2023 17:21:53 +0100 Subject: [PATCH] v1.2.0 --- .../zombiesutils/ZombiesUtils.java | 2 +- .../commands/ZombiesUtilsCommand.java | 9 +--- .../zombiesutils/config/Hotkeys.java | 12 ++++++ .../config/ZombiesUtilsConfig.java | 4 +- .../handlers/KeyInputHandler.java | 3 ++ .../mixin/MixinNetHandlerPlayClient.java | 42 +++++++++++++++++-- .../render/RenderGameOverlayHandler.java | 11 ++++- .../zombiesutils/timer/Timer.java | 37 ++++++++-------- .../zombiesutils/utils/Scoreboard.java | 24 ++++------- 9 files changed, 93 insertions(+), 51 deletions(-) diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/ZombiesUtils.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/ZombiesUtils.java index 94a823a..df80f4c 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/ZombiesUtils.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/ZombiesUtils.java @@ -35,7 +35,7 @@ public class ZombiesUtils { logger = event.getModLog(); ZombiesUtilsConfig.config = new Configuration( event.getSuggestedConfigurationFile(), - "1.1.1" + "1.2.1" ); ZombiesUtilsConfig.load(); } diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/ZombiesUtilsCommand.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/ZombiesUtilsCommand.java index a07d865..eb20945 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/ZombiesUtilsCommand.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/ZombiesUtilsCommand.java @@ -1,7 +1,6 @@ package com.github.stachelbeere1248.zombiesutils.commands; import com.github.stachelbeere1248.zombiesutils.timer.Timer; -import com.github.stachelbeere1248.zombiesutils.utils.Scoreboard; import net.minecraft.command.*; import net.minecraft.util.BlockPos; import org.jetbrains.annotations.NotNull; @@ -36,13 +35,9 @@ public class ZombiesUtilsCommand extends CommandBase { } catch (NumberFormatException | NullPointerException ignored) { throw new NumberInvalidException("t",args[2]); } break; - case "start": new Timer( - Scoreboard.getServerNumber().orElseThrow(() -> new RuntimeException("cannot figure out servernumber")), - Scoreboard.getMap().orElseThrow(() -> new RuntimeException("cannot figure out map")).map - ); break; default: throw new WrongUsageException( - "[Invalid option] options: kill, split, start", args[0]); + "[Invalid option] options: kill, split", args[0]); } break; default: throw new WrongUsageException( @@ -54,7 +49,7 @@ public class ZombiesUtilsCommand extends CommandBase { if (args.length == 1) return new ArrayList<>(Collections.singleton("timer")); switch (args[0]) { case "timer": - return new ArrayList<>(Arrays.asList("kill","split","start")); + return new ArrayList<>(Arrays.asList("kill","split")); default: return Collections.emptyList(); } } diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/config/Hotkeys.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/config/Hotkeys.java index 4517ed3..cbe947c 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/config/Hotkeys.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/config/Hotkeys.java @@ -6,6 +6,7 @@ import org.lwjgl.input.Keyboard; public class Hotkeys { private final KeyBinding chatMacro; + private final KeyBinding rlSpawn; public Hotkeys() { chatMacro = new KeyBinding( @@ -13,11 +14,22 @@ public class Hotkeys { Keyboard.KEY_Q, "Zombies Utils" ); + rlSpawn = new KeyBinding( + "Rocket Launcher Mode", + Keyboard.KEY_NONE, + "Zombies Utils" + ); + } public void registerAll() { ClientRegistry.registerKeyBinding(this.chatMacro); + ClientRegistry.registerKeyBinding(this.rlSpawn); } public KeyBinding getChatMacro() { return chatMacro; } + + public KeyBinding getRlSpawn() { + return rlSpawn; + } } diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/config/ZombiesUtilsConfig.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/config/ZombiesUtilsConfig.java index 518f6dd..4e8ceea 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/config/ZombiesUtilsConfig.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/config/ZombiesUtilsConfig.java @@ -43,9 +43,9 @@ public class ZombiesUtilsConfig { "name of the category to be selected unless specified using /runCategory" ); waveOffset = (short) config.getInt( - "spawn-time offset ticks", + "RL-mode offset", Configuration.CATEGORY_GENERAL, - 0, + -28, -200, 200, "max: 200 ticks" diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/handlers/KeyInputHandler.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/handlers/KeyInputHandler.java index f152016..fd54a24 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/handlers/KeyInputHandler.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/handlers/KeyInputHandler.java @@ -3,6 +3,7 @@ package com.github.stachelbeere1248.zombiesutils.handlers; import com.github.stachelbeere1248.zombiesutils.ZombiesUtils; import com.github.stachelbeere1248.zombiesutils.config.Hotkeys; import com.github.stachelbeere1248.zombiesutils.config.ZombiesUtilsConfig; +import com.github.stachelbeere1248.zombiesutils.render.RenderGameOverlayHandler; import net.minecraft.client.Minecraft; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.InputEvent; @@ -18,6 +19,8 @@ public class KeyInputHandler { Minecraft.getMinecraft().thePlayer.sendChatMessage( ZombiesUtilsConfig.getChatMacro() ); + } else if (Keyboard.getEventKey() == hotkeys.getRlSpawn().getKeyCode()) { + RenderGameOverlayHandler.toggleRL(); } } } diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/mixin/MixinNetHandlerPlayClient.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/mixin/MixinNetHandlerPlayClient.java index 02d240f..72c27d5 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/mixin/MixinNetHandlerPlayClient.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/mixin/MixinNetHandlerPlayClient.java @@ -1,10 +1,13 @@ package com.github.stachelbeere1248.zombiesutils.mixin; +import com.github.stachelbeere1248.zombiesutils.ZombiesUtils; import com.github.stachelbeere1248.zombiesutils.timer.Timer; import com.github.stachelbeere1248.zombiesutils.utils.Scoreboard; +import net.minecraft.client.Minecraft; import net.minecraft.client.network.NetHandlerPlayClient; import net.minecraft.network.play.server.S29PacketSoundEffect; import net.minecraft.network.play.server.S45PacketTitle; +import net.minecraft.util.ChatComponentText; import org.jetbrains.annotations.NotNull; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; @@ -33,8 +36,7 @@ public class MixinNetHandlerPlayClient { || (soundEffect.equals("mob.guardian.curse") && !zombies_utils$alienUfoOpened) )) return; zombies_utils$alienUfoOpened = soundEffect.equals("mob.guardian.curse"); - - if (!Timer.getInstance().isPresent()) { + /*if (!Timer.getInstance().isPresent()) { new Timer( Scoreboard.getServerNumber().orElseThrow(() -> new RuntimeException("cannot figure out servernumber")), Scoreboard.getMap().orElseThrow(() -> new RuntimeException("cannot figure out map")).map @@ -58,15 +60,48 @@ public class MixinNetHandlerPlayClient { map.map ); } + }*/ + + + try { + + if (Timer.getInstance().isPresent()) { + final Timer running = Timer.getInstance().get(); + final byte round = Scoreboard.getRound(); + + if (round == 0) { + if (Scoreboard.getLineCount()<13) Timer.setInstance(new Timer( + Scoreboard.getServerNumber().orElseThrow(Timer.TimerException.ServerNumberException::new), + Scoreboard.getMap().orElseThrow(Timer.TimerException.MapException::new), + round + )); + } else if (!running.equalsServerOrNull(Scoreboard.getServerNumber().orElse(null))) { + Timer.setInstance(new Timer( + Scoreboard.getServerNumber().orElseThrow(Timer.TimerException.ServerNumberException::new), + Scoreboard.getMap().orElseThrow(Timer.TimerException.MapException::new), + round + )); + } else running.split(round); + + + + } else Timer.setInstance(new Timer( + Scoreboard.getServerNumber().orElseThrow(Timer.TimerException.ServerNumberException::new), + Scoreboard.getMap().orElseThrow(Timer.TimerException.MapException::new), + Scoreboard.getRound() + )); + } catch (Timer.TimerException e) { + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("§cFailed to start or split timer.\nData parsing error. Blame scoreboard.")); + ZombiesUtils.getInstance().getLogger().warn(e); } } @Unique private void zombies_utils$handleTitle(@NotNull S45PacketTitle packet) { if (packet.getType() != S45PacketTitle.Type.TITLE) return; + final String message = packet.getMessage().getUnformattedText().trim(); Timer.getInstance().ifPresent(timer -> { if (Scoreboard.isZombies()) return; - final String message = packet.getMessage().getUnformattedText().trim(); if (message.equals("§aYou Win!")) { switch (timer.getGameMode().getMap()) { @@ -82,4 +117,5 @@ public class MixinNetHandlerPlayClient { } else if (message.equals("§cGame Over!")) Timer.dropInstances(); }); } + } diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/render/RenderGameOverlayHandler.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/render/RenderGameOverlayHandler.java index 9aca347..9a6c6f6 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/render/RenderGameOverlayHandler.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/render/RenderGameOverlayHandler.java @@ -17,6 +17,8 @@ import java.util.Objects; public class RenderGameOverlayHandler { private final FontRenderer fontRenderer; + private static int rl = 0; + public RenderGameOverlayHandler() { this.fontRenderer = Objects.requireNonNull(Minecraft.getMinecraft().fontRendererObj, "FontRenderer must not be null!"); } @@ -78,7 +80,7 @@ public class RenderGameOverlayHandler { int color = 0xFFFF55; for (byte waveTime: waveTimes) { - final short waveTicks = (short) ((waveTime * 20)-ZombiesUtilsConfig.getWaveOffset()); + final short waveTicks = (short) ((waveTime * 20)-rl); if (roundTicks>waveTicks) { heightIndex++; @@ -110,7 +112,12 @@ public class RenderGameOverlayHandler { private static String getWaveString(long waveTicks, int wave) { final long minutesPart = (waveTicks *50) / 60000; final long secondsPart = ((waveTicks *50) % 60000) / 1000; - return String.format("W%d %d:%02d", wave, minutesPart, secondsPart); + final long tenthSecondsPart = ((waveTicks *50) % 1000) / 100; + return String.format("W%d %d:%02d.%d", wave, minutesPart, secondsPart, tenthSecondsPart); } + public static void toggleRL() { + if (rl == 0) rl = ZombiesUtilsConfig.getWaveOffset(); + else rl = 0; + } } diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/Timer.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/Timer.java index a7a7480..2cbfbb0 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/Timer.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/Timer.java @@ -21,31 +21,14 @@ public class Timer { private final String serverNumber; public Category category; private boolean pbTracking = false; - private int round = 0; + private int round; - /** - * 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. - */ - public Timer (@NotNull String serverNumber, @NotNull Map map) { - savedTotalWorldTime = getCurrentTotalWorldTime(); - if (!serverNumber.trim().isEmpty()) this.serverNumber = serverNumber.trim(); - else throw new RuntimeException("invalid servernumber"); - - this.category = new Category(); - this.gameMode = new GameMode(map); - if (ZombiesUtilsConfig.isSlaToggled()) SLA.instance = new SLA(map); - - instance = this; - } /** * 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. */ - //TODO: brooooooooo public Timer (@NotNull String serverNumber, @NotNull Map map, byte round) { savedTotalWorldTime = getCurrentTotalWorldTime(); if (!serverNumber.trim().isEmpty()) this.serverNumber = serverNumber.trim(); @@ -56,7 +39,6 @@ public class Timer { this.round = round; if (ZombiesUtilsConfig.isSlaToggled()) SLA.instance = new SLA(map); - instance = this; } @@ -105,6 +87,11 @@ public class Timer { public short roundTime() { return (short) (gameTime() - passedRoundsTickSum); } + + /** + * @param serverNumber Servernumber to be compared + * @return false, if and only if input exists and is unequal to {@link #serverNumber} + */ public boolean equalsServerOrNull(String serverNumber) { return (serverNumber == null || serverNumber.equals(this.serverNumber) || serverNumber.isEmpty()); } @@ -128,4 +115,16 @@ public class Timer { public GameMode getGameMode() { return gameMode; } + public static void setInstance(@NotNull Timer instance) { + Timer.instance = instance; + } + + + public static abstract class TimerException extends Exception { + + public static class MapException extends TimerException { + } + public static class ServerNumberException extends TimerException { + } + } } diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/utils/Scoreboard.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/utils/Scoreboard.java index 62cf7a1..54f142a 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/utils/Scoreboard.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/utils/Scoreboard.java @@ -91,40 +91,30 @@ public class Scoreboard { ZombiesUtils.getInstance().getLogger().debug("Servernumber: " + string); return Optional.ofNullable(string); } - public static Optional getMap() { + public static Optional getMap() { String line; - boolean pregame; try { line = lines.get(12); - pregame = false; } catch (Exception couldBePregame) { try { line = lines.get(2); - pregame = true; } catch (IndexOutOfBoundsException | NullPointerException ignored) { return Optional.empty(); } } String mapString = MAP_PATTERN.matcher(line).replaceAll("$1"); switch (mapString) { - case "Dead End": return Optional.of(new MapContainer(Map.DEAD_END,pregame)); - case "Bad Blood": return Optional.of(new MapContainer(Map.BAD_BLOOD,pregame)); - case "Alien Arcadium": return Optional.of(new MapContainer(Map.ALIEN_ARCADIUM,pregame)); + case "Dead End": return Optional.of(Map.DEAD_END); + case "Bad Blood": return Optional.of(Map.BAD_BLOOD); + case "Alien Arcadium": return Optional.of(Map.ALIEN_ARCADIUM); default: return Optional.empty(); } } + public static int getLineCount() { + return lines.size(); + } public static boolean isZombies() { return (!"ZOMBIES".equals(title)); } - - public static class MapContainer { - public final Map map; - public final boolean pregame; - - public MapContainer(Map map, boolean pregame) { - this.map = map; - this.pregame = pregame; - } - } } \ No newline at end of file