From 2a48c3cdf223645bcb8659b61e5bce8d04024793 Mon Sep 17 00:00:00 2001 From: Stachelbeere1248 Date: Mon, 11 Dec 2023 22:00:45 +0100 Subject: [PATCH] code cleanup --- .../zombiesutils/ZombiesUtils.java | 4 + .../commands/CategoryCommand.java | 7 +- .../commands/QuickZombiesCommand.java | 3 +- .../zombiesutils/commands/SlaCommand.java | 5 +- .../commands/ZombiesUtilsCommand.java | 22 ++- .../zombiesutils/config/Hotkeys.java | 2 + .../config/ZombiesUtilsConfig.java | 36 ++-- .../zombiesutils/game/GameMode.java | 8 +- .../zombiesutils/game/Map.java | 1 + .../zombiesutils/game/sla/QuickSLA.java | 4 +- .../zombiesutils/game/sla/SLA.java | 53 +++--- .../zombiesutils/game/waves/Waves.java | 19 +- .../zombiesutils/game/windows/Room.java | 170 +++++++++--------- .../zombiesutils/game/windows/Window.java | 30 +++- .../zombiesutils/handlers/ChatHandler.java | 6 +- .../handlers/HandlerRegistry.java | 1 - .../handlers/KeyInputHandler.java | 1 - .../RenderGameOverlayHandler.java | 56 +++--- .../mixin/MixinNetHandlerPlayClient.java | 14 +- .../zombiesutils/timer/RecordManager.java | 24 +-- .../zombiesutils/timer/Timer.java | 61 ++++--- .../zombiesutils/timer/recorder/Category.java | 20 +-- .../timer/recorder/FileManager.java | 3 + .../timer/recorder/SplitsFile.java | 2 + .../timer/recorder/data/CategoryData.java | 8 +- .../timer/recorder/data/GameData.java | 4 +- .../timer/recorder/files/CategoryFile.java | 30 ++-- .../timer/recorder/files/GameFile.java | 11 +- .../zombiesutils/utils/Scoreboard.java | 23 ++- 29 files changed, 369 insertions(+), 259 deletions(-) rename src/main/java/com/github/stachelbeere1248/zombiesutils/{render => handlers}/RenderGameOverlayHandler.java (84%) diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/ZombiesUtils.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/ZombiesUtils.java index 8129b8f..297d6e5 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/ZombiesUtils.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/ZombiesUtils.java @@ -16,10 +16,12 @@ public class ZombiesUtils { private static ZombiesUtils instance; private final Hotkeys hotkeys; private Logger logger; + public ZombiesUtils() { hotkeys = new Hotkeys(); instance = this; } + public static ZombiesUtils getInstance() { return instance; } @@ -33,12 +35,14 @@ public class ZombiesUtils { ); ZombiesUtilsConfig.load(); } + @Mod.EventHandler public void init(FMLInitializationEvent event) { HandlerRegistry.registerAll(); CommandRegistry.registerAll(); hotkeys.registerAll(); } + public Logger getLogger() { return logger; } diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/CategoryCommand.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/CategoryCommand.java index 514cdf6..d88d5d9 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/CategoryCommand.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/CategoryCommand.java @@ -14,9 +14,10 @@ import java.util.Arrays; import java.util.List; public class CategoryCommand extends CommandBase { - public CategoryCommand () { + public CategoryCommand() { } + @Override public String getCommandName() { return "category"; @@ -32,11 +33,13 @@ public class CategoryCommand extends CommandBase { if (args.length == 0) throw new WrongUsageException("Please enter a name for the category"); else { String cat = args[0]; - if (cat.contains(File.separator)) throw new WrongUsageException("Your name must not contain '" + File.separator + "' as this is the systems separator character for folder" + File.separator + "subfolder"); + if (cat.contains(File.separator)) + throw new WrongUsageException("Your name must not contain '" + File.separator + "' as this is the systems separator character for folder" + File.separator + "subfolder"); Category.setSelectedCategory(cat); Timer.getInstance().ifPresent(timer -> timer.setCategory(new Category())); } } + @Override public List addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos blockPos) { return Arrays.asList(Category.getCategories()); diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/QuickZombiesCommand.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/QuickZombiesCommand.java index 728a0ea..2cf1ec3 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/QuickZombiesCommand.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/QuickZombiesCommand.java @@ -24,7 +24,7 @@ public class QuickZombiesCommand extends CommandBase { } @Override - public void processCommand(ICommandSender sender, String[] args) throws CommandException { + public void processCommand(ICommandSender sender, String @NotNull [] args) throws CommandException { if (args.length == 0) throw new WrongUsageException( "[Missing option] options: de, bb, aa"); else switch (args[0]) { @@ -43,6 +43,7 @@ public class QuickZombiesCommand extends CommandBase { } } + @Override public List addTabCompletionOptions(ICommandSender sender, String @NotNull [] args, BlockPos blockPos) { if (args.length == 1) return Arrays.asList("de", "bb", "aa"); diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/SlaCommand.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/SlaCommand.java index 3b8040a..bfa17d1 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/SlaCommand.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/SlaCommand.java @@ -121,7 +121,7 @@ public class SlaCommand extends CommandBase { else { if (args.length > 1) switch (args[0]) { case "offset": - if (args.length<5) options.add("0"); + if (args.length < 5) options.add("0"); break; case "map": options.addAll(Arrays.asList("de", "bb", "aa")); @@ -135,7 +135,8 @@ public class SlaCommand extends CommandBase { case "quick": //noinspection SpellCheckingInspection options.addAll(Arrays.asList("mogi_a", "ghxula", "ghxula-garden")); - default: break; + default: + break; } } return options; 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 eb20945..394a8f9 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/ZombiesUtilsCommand.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/ZombiesUtilsCommand.java @@ -10,7 +10,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; -public class ZombiesUtilsCommand extends CommandBase { +public class ZombiesUtilsCommand extends CommandBase { @Override public String getCommandName() { return "zombiesutils"; @@ -28,29 +28,35 @@ public class ZombiesUtilsCommand extends CommandBase { else switch (args[0]) { case "timer": switch (args[1]) { - case "kill": Timer.dropInstances(); break; + case "kill": + Timer.dropInstances(); + break; case "split": try { - Timer.getInstance().ifPresent(timer -> timer.split(Byte.parseByte(args[2]))); + Timer.getInstance().ifPresent(timer -> timer.split(Byte.parseByte(args[2]))); } catch (NumberFormatException | NullPointerException ignored) { - throw new NumberInvalidException("t",args[2]); - } break; + throw new NumberInvalidException("t", args[2]); + } + break; default: throw new WrongUsageException( "[Invalid option] options: kill, split", args[0]); - } break; + } + break; default: throw new WrongUsageException( "[Invalid option] options: timer", args[0]); } } + @Override public List addTabCompletionOptions(ICommandSender sender, String @NotNull [] args, BlockPos blockPos) { if (args.length == 1) return new ArrayList<>(Collections.singleton("timer")); switch (args[0]) { case "timer": - return new ArrayList<>(Arrays.asList("kill","split")); - default: return Collections.emptyList(); + 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 cbe947c..a0a7b38 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/config/Hotkeys.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/config/Hotkeys.java @@ -21,10 +21,12 @@ public class Hotkeys { ); } + public void registerAll() { ClientRegistry.registerKeyBinding(this.chatMacro); ClientRegistry.registerKeyBinding(this.rlSpawn); } + public KeyBinding getChatMacro() { return chatMacro; } 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 a566dde..bde9b3b 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/config/ZombiesUtilsConfig.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/config/ZombiesUtilsConfig.java @@ -15,6 +15,7 @@ public class ZombiesUtilsConfig { private static String chatMacro; private static String defaultCategory; private static short waveOffset; + public static void load() { ZombiesUtils.getInstance().getLogger().debug("Loading config..."); config.load(); @@ -64,6 +65,26 @@ public class ZombiesUtilsConfig { return waveOffset; } + public static boolean isSlaToggled() { + return slaToggle; + } + + public static boolean isSlaShortened() { + return slaShortener; + } + + public static boolean isSpawntimeNotShortened() { + return shortSpawntime; + } + + public static String getChatMacro() { + return chatMacro; + } + + public static String getDefaultCategory() { + return defaultCategory; + } + @SubscribeEvent public void onConfigChange(ConfigChangedEvent.@NotNull OnConfigChangedEvent event) { if (event.modID.equals("zombiesutils") && event.configID == null) { @@ -71,19 +92,4 @@ public class ZombiesUtilsConfig { ZombiesUtilsConfig.load(); } } - public static boolean isSlaToggled() { - return slaToggle; - } - public static boolean isSlaShortened() { - return slaShortener; - } - public static boolean isSpawntimeNotShortened() { - return shortSpawntime; - } - public static String getChatMacro() { - return chatMacro; - } - public static String getDefaultCategory() { - return defaultCategory; - } } diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/game/GameMode.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/game/GameMode.java index 34aecb9..1fc76de 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/game/GameMode.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/game/GameMode.java @@ -10,25 +10,31 @@ public class GameMode { this.map = map; this.difficulty = Difficulty.NORMAL; } + public GameMode(@NotNull Map map, @NotNull Difficulty difficulty) { this.map = map; this.difficulty = difficulty; } + public Map getMap() { return map; } + public Difficulty getDifficulty() { return difficulty; } + public void changeDifficulty(@NotNull Difficulty difficulty) { switch (map) { - case DEAD_END: case BAD_BLOOD: + case DEAD_END: + case BAD_BLOOD: this.difficulty = difficulty; break; case ALIEN_ARCADIUM: throw new RuntimeException("Achievement Get: Alien Arcadium Hard/RIP" + Map.ALIEN_ARCADIUM); } } + public boolean is(Map map, Difficulty difficulty) { return this.getDifficulty() == difficulty && this.getMap() == map; } diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/game/Map.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/game/Map.java index 61db831..7b38a1c 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/game/Map.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/game/Map.java @@ -1,4 +1,5 @@ package com.github.stachelbeere1248.zombiesutils.game; + public enum Map { DEAD_END, BAD_BLOOD, ALIEN_ARCADIUM } diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/game/sla/QuickSLA.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/game/sla/QuickSLA.java index 59ad434..13cb49c 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/game/sla/QuickSLA.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/game/sla/QuickSLA.java @@ -7,13 +7,15 @@ public class QuickSLA { public static void mogi_a() { SLA.instance = new SLA(Map.BAD_BLOOD); SLA.instance.rotate(3); - SLA.instance.setOffset(new int[]{-3,35,-9}); + SLA.instance.setOffset(new int[]{-3, 35, -9}); } + public static void ghxula() { SLA.instance = new SLA(Map.DEAD_END); SLA.instance.rotate(1); SLA.instance.setOffset(new int[]{27, 35, 5}); } + public static void ghxulaGarden() { SLA.instance = new SLA(Map.DEAD_END); SLA.instance.rotate(1); diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/game/sla/SLA.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/game/sla/SLA.java index 919498a..7dffbc1 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/game/sla/SLA.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/game/sla/SLA.java @@ -19,37 +19,55 @@ public class SLA { public SLA(@NotNull Map map) { switch (map) { - case DEAD_END: this.rooms = Room.getDE(); break; - case BAD_BLOOD: this.rooms = Room.getBB(); break; - case ALIEN_ARCADIUM: this.rooms = Room.getAA(); break; - default: throw new IllegalStateException("Unexpected value: " + map); + case DEAD_END: + this.rooms = Room.getDE(); + break; + case BAD_BLOOD: + this.rooms = Room.getBB(); + break; + case ALIEN_ARCADIUM: + this.rooms = Room.getAA(); + break; + default: + throw new IllegalStateException("Unexpected value: " + map); } } + public static Optional getInstance() { + return Optional.ofNullable(instance); + } + + public static void drop() { + instance = null; + } + public void rotate(int rotations) { for (Room room : rooms) { - for (Window window: room.getWindows()) { + for (Window window : room.getWindows()) { window.rotate(rotations); } } } + public void mirrorX() { for (Room room : rooms) { - for (Window window: room.getWindows()) { + for (Window window : room.getWindows()) { window.mirrorX(); } } System.out.println("Co3 now at " + Arrays.toString(rooms[0].getWindows()[0].getXYZ())); } + public void mirrorZ() { for (Room room : rooms) { - for (Window window: room.getWindows()) { + for (Window window : room.getWindows()) { window.mirrorZ(); } } short[] win0 = rooms[0].getWindows()[0].getXYZ(); - ZombiesUtils.getInstance().getLogger().info("Window \"0\" is now at %s %s %s" + (double) win0[0]/2 + (double) win0[1]/2 + (double) win0[2]/2); + ZombiesUtils.getInstance().getLogger().info("Window \"0\" is now at %s %s %s" + (double) win0[0] / 2 + (double) win0[1] / 2 + (double) win0[2] / 2); } + public void refreshActives() { final EntityPlayerSP player = Minecraft.getMinecraft().thePlayer; final double[] playerCoords = { @@ -57,14 +75,14 @@ public class SLA { player.posY - offset[1], player.posZ - offset[2] }; - for (Room room: rooms - ) { + for (Room room : rooms + ) { room.resetActiveWindowCount(); - for (Window window: room.getWindows() - ) { + for (Window window : room.getWindows() + ) { double distanceDoubledThenSquared = 0; for (int i = 0; i < 3; i++) { - distanceDoubledThenSquared += ((playerCoords[i]*2 - window.getXYZ()[i]) * (playerCoords[i]*2 - window.getXYZ()[i])); + distanceDoubledThenSquared += ((playerCoords[i] * 2 - window.getXYZ()[i]) * (playerCoords[i] * 2 - window.getXYZ()[i])); } // (2x)²+(2y)²+(2z)² = 4(x²+y²+z²) = 4d² @@ -76,19 +94,14 @@ public class SLA { } } - - public static Optional getInstance() { - return Optional.ofNullable(instance); - } - public static void drop() { - instance = null; - } public Room[] getRooms() { return rooms; } + public void resetOffset() { Arrays.fill(this.offset, 0); } + public void setOffset(int[] offset) { System.arraycopy(offset, 0, this.offset, 0, 3); } diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/game/waves/Waves.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/game/waves/Waves.java index 745528c..01e0183 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/game/waves/Waves.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/game/waves/Waves.java @@ -6,15 +6,12 @@ import org.jetbrains.annotations.NotNull; @SuppressWarnings("DuplicatedCode") public class Waves { - private static final byte[][] deadEndWaveTimes = {{10,20},{10,20},{10,20,35},{10,20,35},{10,22,37},{10,22,44},{10,25,47},{10,25,50},{10,22,38},{10,24,45},{10,25,48},{10,25,50},{10,25,50},{10,25,45},{10,25,46},{10,24,47},{10,24,47},{10,24,47},{10,24,47},{10,24,49},{10,23,44},{10,23,45},{10,23,42},{10,23,43},{10,23,43},{10,23,36},{10,24,44},{10,24,42},{10,24,42},{10,24,45}}, - badBloodWaveTimes = {{10,22},{10,22},{10,22},{10,22,34},{10,22,34},{10,22,34},{10,22,34},{10,22,34},{10,22,34},{10,22,34},{10,22,34},{10,22,34},{10,22,34},{10,22,34},{10,22,34},{10,22,34},{10,22,34},{10,22,34},{10,22,34},{10,22,34},{10,22,34},{10,22,34},{10,22,34},{10,22,34},{10,22,34},{10,24,38},{10,24,38},{10,22,34},{10,24,38},{10,22,34}}, - alienArcadiumWaveTimes = {{10,13,16,19},{10,14,18,22},{10,13,16,19},{10,14,17,21,25,28},{10,14,18,22,26,30},{10,14,19,23,28,32},{10,15,19,23,27,31},{10,15,20,25,30,35},{10,14,19,23,28,32},{10,16,22,27,33,38},{10,16,21,27,32,38},{10,16,22,28,34,40},{10,16,22,28,34,40},{10,16,21,26,31,36},{10,17,24,31,38,46},{10,16,22,27,33,38},{10,14,19,23,28,32},{10,14,19,23,28,32},{10,14,18,22,26,30},{10,15,21,26,31,36},{10,14,19,23,28,32},{10,14,19,23,28,34},{10,14,18,22,26,30},{10,14,19,23,28,32},{10},{10,23,36},{10,22,34},{10,20,30},{10,24,38},{10,22,34},{10,22,34},{10,21,32},{10,22,34},{10,22,34},{10},{10,22,34},{10,20,31},{10,22,34},{10,22,34},{10,22,34,37,45},{10,21,32},{10,22,34},{10,13,22,25,34,37},{10,22,34},{10,22,34,35},{10,21,32,35},{10,20,30},{10,20,30,33},{10,21,32},{10,22,34,37},{10,20,30,33},{10,22,34,37},{10,22,34,37},{10,20,32,35,39},{10,16,22,28,34,40},{10,14,18},{10,14,18},{10,22,34,37,38},{10,14,18,22,26,30},{10,20,30,33},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,27,32},{10,14,18,22,27,32},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{5},{5},{5},{5},{5}} - ; - private static final short[] deadEndRoundTimesSum = {0,20,40,75,110,147,191,238,288,326,371,419,469,519,564,610,657,704,751,798,847,891,936,978,1021,1064,1100,1144,1186,1228,1273}, - badBloodRoundTimesSum = {0,22,44,66,100,134,168,202,236,270,304,338,372,406,440,474,508,542,576,610,644,678,712,746,780,814,852,890,924,962,996}, - alienArcadiumRoundTimesSum = {0,19,41,60,88,118,150,181,216,248,286,324,364,404,440,486,524,556,588,618,654,686,720,750,782,792,828,862,892,930,964,998,1030,1064,1098,1108,1142,1173,1207,1241,1286,1318,1352,1389,1423,1458,1493,1523,1556,1588,1625,1658,1695,1732,1771,1811,1829,1847,1885,1915,1948,1978,2008,2038,2068,2098,2128,2158,2188,2218,2248,2278,2308,2338,2368,2400,2432,2462,2492,2522,2552,2582,2612,2642,2672,2702,2732,2762,2792,2822,2852,2882,2912,2942,2972,3002,3032,3062,3092,3122,3152,3157,3162,3167,3172,3177} - ; - + private static final byte[][] deadEndWaveTimes = {{10, 20}, {10, 20}, {10, 20, 35}, {10, 20, 35}, {10, 22, 37}, {10, 22, 44}, {10, 25, 47}, {10, 25, 50}, {10, 22, 38}, {10, 24, 45}, {10, 25, 48}, {10, 25, 50}, {10, 25, 50}, {10, 25, 45}, {10, 25, 46}, {10, 24, 47}, {10, 24, 47}, {10, 24, 47}, {10, 24, 47}, {10, 24, 49}, {10, 23, 44}, {10, 23, 45}, {10, 23, 42}, {10, 23, 43}, {10, 23, 43}, {10, 23, 36}, {10, 24, 44}, {10, 24, 42}, {10, 24, 42}, {10, 24, 45}}, + badBloodWaveTimes = {{10, 22}, {10, 22}, {10, 22}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 24, 38}, {10, 24, 38}, {10, 22, 34}, {10, 24, 38}, {10, 22, 34}}, + alienArcadiumWaveTimes = {{10, 13, 16, 19}, {10, 14, 18, 22}, {10, 13, 16, 19}, {10, 14, 17, 21, 25, 28}, {10, 14, 18, 22, 26, 30}, {10, 14, 19, 23, 28, 32}, {10, 15, 19, 23, 27, 31}, {10, 15, 20, 25, 30, 35}, {10, 14, 19, 23, 28, 32}, {10, 16, 22, 27, 33, 38}, {10, 16, 21, 27, 32, 38}, {10, 16, 22, 28, 34, 40}, {10, 16, 22, 28, 34, 40}, {10, 16, 21, 26, 31, 36}, {10, 17, 24, 31, 38, 46}, {10, 16, 22, 27, 33, 38}, {10, 14, 19, 23, 28, 32}, {10, 14, 19, 23, 28, 32}, {10, 14, 18, 22, 26, 30}, {10, 15, 21, 26, 31, 36}, {10, 14, 19, 23, 28, 32}, {10, 14, 19, 23, 28, 34}, {10, 14, 18, 22, 26, 30}, {10, 14, 19, 23, 28, 32}, {10}, {10, 23, 36}, {10, 22, 34}, {10, 20, 30}, {10, 24, 38}, {10, 22, 34}, {10, 22, 34}, {10, 21, 32}, {10, 22, 34}, {10, 22, 34}, {10}, {10, 22, 34}, {10, 20, 31}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34, 37, 45}, {10, 21, 32}, {10, 22, 34}, {10, 13, 22, 25, 34, 37}, {10, 22, 34}, {10, 22, 34, 35}, {10, 21, 32, 35}, {10, 20, 30}, {10, 20, 30, 33}, {10, 21, 32}, {10, 22, 34, 37}, {10, 20, 30, 33}, {10, 22, 34, 37}, {10, 22, 34, 37}, {10, 20, 32, 35, 39}, {10, 16, 22, 28, 34, 40}, {10, 14, 18}, {10, 14, 18}, {10, 22, 34, 37, 38}, {10, 14, 18, 22, 26, 30}, {10, 20, 30, 33}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 27, 32}, {10, 14, 18, 22, 27, 32}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {5}, {5}, {5}, {5}, {5}}; + private static final short[] deadEndRoundTimesSum = {0, 20, 40, 75, 110, 147, 191, 238, 288, 326, 371, 419, 469, 519, 564, 610, 657, 704, 751, 798, 847, 891, 936, 978, 1021, 1064, 1100, 1144, 1186, 1228, 1273}, + badBloodRoundTimesSum = {0, 22, 44, 66, 100, 134, 168, 202, 236, 270, 304, 338, 372, 406, 440, 474, 508, 542, 576, 610, 644, 678, 712, 746, 780, 814, 852, 890, 924, 962, 996}, + alienArcadiumRoundTimesSum = {0, 19, 41, 60, 88, 118, 150, 181, 216, 248, 286, 324, 364, 404, 440, 486, 524, 556, 588, 618, 654, 686, 720, 750, 782, 792, 828, 862, 892, 930, 964, 998, 1030, 1064, 1098, 1108, 1142, 1173, 1207, 1241, 1286, 1318, 1352, 1389, 1423, 1458, 1493, 1523, 1556, 1588, 1625, 1658, 1695, 1732, 1771, 1811, 1829, 1847, 1885, 1915, 1948, 1978, 2008, 2038, 2068, 2098, 2128, 2158, 2188, 2218, 2248, 2278, 2308, 2338, 2368, 2400, 2432, 2462, 2492, 2522, 2552, 2582, 2612, 2642, 2672, 2702, 2732, 2762, 2792, 2822, 2852, 2882, 2912, 2942, 2972, 3002, 3032, 3062, 3092, 3122, 3152, 3157, 3162, 3167, 3172, 3177}; @Contract(pure = true) @@ -30,6 +27,7 @@ public class Waves { throw new IllegalStateException("Unexpected value: " + map); } } + public static short getSum(@NotNull Map map, byte round) { short sum; switch (map) { @@ -47,9 +45,10 @@ public class Waves { } return sum; } + public static byte getLastWave(@NotNull Map map, byte round) { byte[] aByte = get(map, round); - return aByte[aByte.length-1]; + return aByte[aByte.length - 1]; } } \ No newline at end of file diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/game/windows/Room.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/game/windows/Room.java index d04b5a7..4eb7579 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/game/windows/Room.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/game/windows/Room.java @@ -10,69 +10,63 @@ public class Room { private final String name; private final String alias; private int activeWindowCount; - public Room(String name,String alias, Window[] windows) { + + public Room(String name, String alias, Window[] windows) { this.windows = windows; this.name = name; this.alias = alias; } - public String getName() { - return name; - } - public Window[] getWindows() { - return windows; - } - @Contract(" -> new") public static Room @NotNull [] getDE() { - Vec3 t = new Vec3(3,3,3); + Vec3 t = new Vec3(3, 3, 3); t.rotatePitch(3); return new Room[]{ new Room("Alley", "al", new Window[]{ - new Window(1,9,138,87), - new Window(2,13,138,63), - new Window(3,85,140,59), - new Window(4,79,140,17) + new Window(1, 9, 138, 87), + new Window(2, 13, 138, 63), + new Window(3, 85, 140, 59), + new Window(4, 79, 140, 17) }), new Room("Office", "o", new Window[]{ - new Window(1,85,152,53), - new Window(2,105,152,63), - new Window(3,115,152,129) + new Window(1, 85, 152, 53), + new Window(2, 105, 152, 63), + new Window(3, 115, 152, 129) }), new Room("Hotel", "h", new Window[]{ - new Window(1,1,136,93), - new Window(2,-19,136,29), - new Window(3,53,138,7), - new Window(4,51,138,-7), - new Window(5,-7,152,-43), - new Window(6,51,152,-11) + new Window(1, 1, 136, 93), + new Window(2, -19, 136, 29), + new Window(3, 53, 138, 7), + new Window(4, 51, 138, -7), + new Window(5, -7, 152, -43), + new Window(6, 51, 152, -11) }), new Room("Apartments", "a", new Window[]{ - new Window(1,39,152,19), - new Window(2,-31,152,31), - new Window(3,-27,152,103), - new Window(4,-9,152,125) + new Window(1, 39, 152, 19), + new Window(2, -31, 152, 31), + new Window(3, -27, 152, 103), + new Window(4, -9, 152, 125) }), new Room("Power Station", "ps", new Window[]{ - new Window(1,-5,166,65), - new Window(2,7,166,125), - new Window(3,-11,136,133) + new Window(1, -5, 166, 65), + new Window(2, 7, 166, 125), + new Window(3, -11, 136, 133) }), new Room("Rooftop", "rt", new Window[]{ - new Window(1,-31,166,129), - new Window(2,-27,166,61), - new Window(3,-75,166,51), - new Window(4,-99,166,77) + new Window(1, -31, 166, 129), + new Window(2, -27, 166, 61), + new Window(3, -75, 166, 51), + new Window(4, -99, 166, 77) }), new Room("Garden", "g", new Window[]{ - new Window(1,1,136,-33), - new Window(2,49,136,-67), - new Window(3,69,136,-33) + new Window(1, 1, 136, -33), + new Window(2, 49, 136, -67), + new Window(3, 69, 136, -33) }), new Room("Gallery", "gal", new Window[]{ - new Window(1,45,152,155), - new Window(2,61,152,109), - new Window(3,31,152,131) + new Window(1, 45, 152, 155), + new Window(2, 61, 152, 109), + new Window(3, 31, 152, 131) }) }; } @@ -81,92 +75,104 @@ public class Room { public static Room @NotNull [] getBB() { return new Room[]{ new Room("Courtyard", "co", new Window[]{ - new Window(1,39,138,41), - new Window(2,61,138,21), - new Window(3,49,138,-37), - new Window(4,25,138,-35) + new Window(1, 39, 138, 41), + new Window(2, 61, 138, 21), + new Window(3, 49, 138, -37), + new Window(4, 25, 138, -35) }), new Room("Mansion", "m", new Window[]{ - new Window(1,1,148,-35), - new Window(2,1,148,37), - new Window(3,-25,146,57) + new Window(1, 1, 148, -35), + new Window(2, 1, 148, 37), + new Window(3, -25, 146, 57) }), new Room("Library", "l", new Window[]{ - new Window(1,3,148,-89), - new Window(2,-41,148,-59), - new Window(3,-81,148,-61), - new Window(4,-79,148,-115), - new Window(5,-109,148,-93), - new Window(6,-107,148,-67) + new Window(1, 3, 148, -89), + new Window(2, -41, 148, -59), + new Window(3, -81, 148, -61), + new Window(4, -79, 148, -115), + new Window(5, -109, 148, -93), + new Window(6, -107, 148, -67) }), new Room("Dungeon", "d", new Window[]{ - new Window(1,-21,136,-99), - new Window(2,-57,136,-69), - new Window(3,-19,136,-45), - new Window(4,-19,136,-37), - new Window(5,-73,136,-23) + new Window(1, -21, 136, -99), + new Window(2, -57, 136, -69), + new Window(3, -19, 136, -45), + new Window(4, -19, 136, -37), + new Window(5, -73, 136, -23) }), new Room("Crypts", "cr", new Window[]{ - new Window(1,-7,136,-5), - new Window(2,-31,136,1), - new Window(3,-57,136,41) + new Window(1, -7, 136, -5), + new Window(2, -31, 136, 1), + new Window(3, -57, 136, 41) }), new Room("Graveyard", "gy", new Window[]{ - new Window(1,-71,136,63), - new Window(2,-33,136,101), - new Window(3,-13,136,67) + new Window(1, -71, 136, 63), + new Window(2, -33, 136, 101), + new Window(3, -13, 136, 67) }), new Room("Balcony", "b", new Window[]{ - new Window(1,-65,148,-37), - new Window(2,-113,148,5), - new Window(3,-107,144,25), - new Window(4,-83,136,55) + new Window(1, -65, 148, -37), + new Window(2, -113, 148, 5), + new Window(3, -107, 144, 25), + new Window(4, -83, 136, 55) }), new Room("Great Hall", "gh", new Window[]{ - new Window(1,-39,148,-27), - new Window(2,-55,148,31), - new Window(3,-63,152,31) + new Window(1, -39, 148, -27), + new Window(2, -55, 148, 31), + new Window(3, -63, 152, 31) }) }; } + @Contract(" -> new") public static Room @NotNull [] getAA() { return new Room[]{ new Room("Park Entrance", "ent", new Window[]{ - new Window(1,13,144,63), - new Window(2,-45,144,31), - new Window(3,-43,144,21), - new Window(4,-21,144,-11), - new Window(5,45,144,27) + new Window(1, 13, 144, 63), + new Window(2, -45, 144, 31), + new Window(3, -43, 144, 21), + new Window(4, -21, 144, -11), + new Window(5, 45, 144, 27) }), new Room("Roller Coaster", "rc", new Window[]{ - new Window(1,-25,144,79), - new Window(2,-57,144,55) + new Window(1, -25, 144, 79), + new Window(2, -57, 144, 55) }), new Room("Ferris Wheel", "fw", new Window[]{ - new Window(1,55,144,63), - new Window(2,35,144,89) + new Window(1, 55, 144, 63), + new Window(2, 35, 144, 89) }), new Room("Bumper Cars", "bp", new Window[]{ - new Window(1,45,146,-27), - new Window(2,67,146,-3) + new Window(1, 45, 146, -27), + new Window(2, 67, 146, -3) }) }; } + public String getName() { + return name; + } + + public Window[] getWindows() { + return windows; + } + public void increaseActiveWindowCount() { this.activeWindowCount++; } + public void resetActiveWindowCount() { this.activeWindowCount = 0; } + public int getActiveWindowCount() { return activeWindowCount; } + public String getSlaString() { StringBuilder slaString = new StringBuilder(String.format("§6%s§r§d %x§e:", this.getName(), activeWindowCount)); - for (Window window: this.windows) { + for (Window window : this.windows) { if (window.isActive()) slaString.append("§2 ").append(alias).append(window.getID()); else if (!ZombiesUtilsConfig.isSlaShortened()) slaString.append("§c ").append(alias).append(window.getID()); } diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/game/windows/Window.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/game/windows/Window.java index 07cd814..f52b871 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/game/windows/Window.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/game/windows/Window.java @@ -7,54 +7,68 @@ public class Window { public Window(int id, int x, int y, int z) { this.id = id; - xyz[0] = (short) x; xyz[1] = (short) y; xyz[2] = (short) z; + xyz[0] = (short) x; + xyz[1] = (short) y; + xyz[2] = (short) z; } public int getID() { return id; } + public short[] getXYZ() { return xyz; } + public boolean isActive() { + return isActive; + } + public void setActive(boolean active) { isActive = active; } - public boolean isActive() { - return isActive; - } + private void rotateCounterClockwise() { final short x = xyz[0], z = xyz[2]; xyz[0] = (short) -z; xyz[2] = x; } + private void mirrorBoth() { xyz[0] = (short) -xyz[0]; xyz[2] = (short) -xyz[2]; } + private void rotateClockwise() { final short x = xyz[0], z = xyz[2]; xyz[0] = z; xyz[2] = (short) -x; } + public void rotate(int rotations) { rotations %= 4; switch (rotations) { - case -3: case 1: + case -3: + case 1: rotateCounterClockwise(); break; - case -2: case 2: + case -2: + case 2: mirrorBoth(); break; - case -1: case 3: + case -1: + case 3: rotateClockwise(); break; - case 0: break; + case 0: + break; } } + public void mirrorX() { xyz[0] = (short) -xyz[0]; } + public void mirrorZ() { xyz[2] = (short) -xyz[2]; } diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/handlers/ChatHandler.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/handlers/ChatHandler.java index 5ad4262..2d28bb3 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/handlers/ChatHandler.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/handlers/ChatHandler.java @@ -10,11 +10,11 @@ import org.jetbrains.annotations.NotNull; import java.util.regex.Pattern; public class ChatHandler { - public ChatHandler () { - } - private static final Pattern STRIP_COLOR_PATTERN = Pattern.compile("§[0-9A-FK-ORZ]", Pattern.CASE_INSENSITIVE); + public ChatHandler() { + } + @SubscribeEvent public void difficultyChange(@NotNull ClientChatReceivedEvent event) { if (!Timer.getInstance().isPresent()) return; diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/handlers/HandlerRegistry.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/handlers/HandlerRegistry.java index 53a437b..8187795 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/handlers/HandlerRegistry.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/handlers/HandlerRegistry.java @@ -1,7 +1,6 @@ package com.github.stachelbeere1248.zombiesutils.handlers; import com.github.stachelbeere1248.zombiesutils.config.ZombiesUtilsConfig; -import com.github.stachelbeere1248.zombiesutils.render.RenderGameOverlayHandler; import net.minecraftforge.common.MinecraftForge; public class HandlerRegistry { 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 fd54a24..e63a5a4 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/handlers/KeyInputHandler.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/handlers/KeyInputHandler.java @@ -3,7 +3,6 @@ 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; diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/render/RenderGameOverlayHandler.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/handlers/RenderGameOverlayHandler.java similarity index 84% rename from src/main/java/com/github/stachelbeere1248/zombiesutils/render/RenderGameOverlayHandler.java rename to src/main/java/com/github/stachelbeere1248/zombiesutils/handlers/RenderGameOverlayHandler.java index f84a0c3..1a04f78 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/render/RenderGameOverlayHandler.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/handlers/RenderGameOverlayHandler.java @@ -1,4 +1,4 @@ -package com.github.stachelbeere1248.zombiesutils.render; +package com.github.stachelbeere1248.zombiesutils.handlers; import com.github.stachelbeere1248.zombiesutils.config.ZombiesUtilsConfig; import com.github.stachelbeere1248.zombiesutils.game.sla.SLA; @@ -16,13 +16,32 @@ import org.jetbrains.annotations.NotNull; import java.util.Objects; public class RenderGameOverlayHandler { - private final FontRenderer fontRenderer; private static int rl = 0; + private final FontRenderer fontRenderer; public RenderGameOverlayHandler() { this.fontRenderer = Objects.requireNonNull(Minecraft.getMinecraft().fontRendererObj, "FontRenderer must not be null!"); } + private static String getTimeString(long timerTicks) { + final long minutesPart = (timerTicks * 50) / 60000; + final long secondsPart = ((timerTicks * 50) % 60000) / 1000; + final long tenthSecondsPart = ((timerTicks * 50) % 1000) / 100; + return String.format("%d:%02d.%d", minutesPart, secondsPart, tenthSecondsPart); + } + + private static String getWaveString(long waveTicks, int wave) { + final long minutesPart = (waveTicks * 50) / 60000; + final long secondsPart = ((waveTicks * 50) % 60000) / 1000; + final long tenthSecondsPart = ((waveTicks * 50) % 1000) / 100; + return String.format("W%d %d:%02d.%d", wave, minutesPart, secondsPart, tenthSecondsPart); + } + + static void toggleRL() { + if (rl == 0) rl = ZombiesUtilsConfig.getWaveOffset(); + else rl = 0; + } + @SubscribeEvent public void onRenderGameOverlay(RenderGameOverlayEvent.@NotNull Post event) { if (event.type != RenderGameOverlayEvent.ElementType.TEXT) return; @@ -60,10 +79,9 @@ public class RenderGameOverlayHandler { ); } - private void renderSla(Room @NotNull [] rooms) { int y = 0; - for (Room room: rooms) { + for (Room room : rooms) { if (ZombiesUtilsConfig.isSlaShortened() && room.getActiveWindowCount() == 0) continue; fontRenderer.drawStringWithShadow( room.getSlaString(), @@ -74,18 +92,19 @@ public class RenderGameOverlayHandler { y++; } } + private void renderSpawnTime(byte @NotNull [] waveTimes, short roundTicks) { if (Scoreboard.isNotZombies()) return; - final int length = waveTimes.length + 1; + final int length = waveTimes.length + 1; int heightIndex = 0; int color = 0xFFFF55; - for (byte waveTime: waveTimes) { + for (byte waveTime : waveTimes) { int clonedColor = color; - final short waveTicks = (short) ((waveTime * 20)+rl); + final short waveTicks = (short) ((waveTime * 20) + rl); - if (roundTicks>waveTicks) { + if (roundTicks > waveTicks) { if (ZombiesUtilsConfig.isSpawntimeNotShortened()) clonedColor = 0x555555; else { heightIndex++; @@ -102,28 +121,11 @@ public class RenderGameOverlayHandler { fontRenderer.drawStringWithShadow( time, screenWidth - width, - screenHeight - fontRenderer.FONT_HEIGHT * (length-heightIndex), + screenHeight - fontRenderer.FONT_HEIGHT * (length - heightIndex), clonedColor ); - if (clonedColor!=0x555555) color = 0xAAAAAA; + if (clonedColor != 0x555555) color = 0xAAAAAA; heightIndex++; } } - private static String getTimeString(long timerTicks) { - final long minutesPart = (timerTicks *50) / 60000; - final long secondsPart = ((timerTicks *50) % 60000) / 1000; - final long tenthSecondsPart = ((timerTicks *50) % 1000) / 100; - return String.format("%d:%02d.%d", minutesPart, secondsPart, tenthSecondsPart); - } - private static String getWaveString(long waveTicks, int wave) { - final long minutesPart = (waveTicks *50) / 60000; - final long secondsPart = ((waveTicks *50) % 60000) / 1000; - 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/mixin/MixinNetHandlerPlayClient.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/mixin/MixinNetHandlerPlayClient.java index a9291c4..90f330b 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/mixin/MixinNetHandlerPlayClient.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/mixin/MixinNetHandlerPlayClient.java @@ -19,21 +19,24 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; public class MixinNetHandlerPlayClient { @Unique private boolean zombies_utils$alienUfoOpened; + @Inject(method = "handleSoundEffect", at = @At(value = "HEAD")) private void handleSound(S29PacketSoundEffect packetIn, CallbackInfo ci) { zombies_utils$handleSound(packetIn); } + @Inject(method = "handleTitle", at = @At(value = "HEAD")) private void handleTitle(S45PacketTitle packetIn, CallbackInfo ci) { zombies_utils$handleTitle(packetIn); } + @Unique private void zombies_utils$handleSound(@NotNull S29PacketSoundEffect packet) { if (Scoreboard.isNotZombies()) return; final String soundEffect = packet.getSoundName(); if (!( soundEffect.equals("mob.wither.spawn") - || (soundEffect.equals("mob.guardian.curse") && !zombies_utils$alienUfoOpened) + || (soundEffect.equals("mob.guardian.curse") && !zombies_utils$alienUfoOpened) )) return; zombies_utils$alienUfoOpened = soundEffect.equals("mob.guardian.curse"); try { @@ -42,13 +45,14 @@ public class MixinNetHandlerPlayClient { final byte round = Scoreboard.getRound(); if (round == 0) { - if (Scoreboard.getLineCount()<13) Timer.instance = new Timer( + if (Scoreboard.getLineCount() < 13) Timer.instance = 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.instance = new Timer( Scoreboard.getServerNumber().orElseThrow(Timer.TimerException.ServerNumberException::new), + Timer.instance = new Timer( + Scoreboard.getServerNumber().orElseThrow(Timer.TimerException.ServerNumberException::new), Scoreboard.getMap().orElseThrow(Timer.TimerException.MapException::new), round ); @@ -63,6 +67,7 @@ public class MixinNetHandlerPlayClient { ZombiesUtils.getInstance().getLogger().warn(e); } } + @Unique private void zombies_utils$handleTitle(@NotNull S45PacketTitle packet) { if (packet.getType() != S45PacketTitle.Type.TITLE) return; @@ -73,7 +78,8 @@ public class MixinNetHandlerPlayClient { if (message.equals("§aYou Win!")) { switch (timer.getGameMode().getMap()) { - case DEAD_END: case BAD_BLOOD: + case DEAD_END: + case BAD_BLOOD: timer.split((byte) 30); Timer.dropInstances(); break; diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/RecordManager.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/RecordManager.java index df36c67..3e3eff5 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/RecordManager.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/RecordManager.java @@ -9,14 +9,13 @@ import org.jetbrains.annotations.NotNull; public class RecordManager { private static final String bar = "§l§a▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬"; + public static void compareSegment(byte round, short roundTime, @NotNull Category category) throws IndexOutOfBoundsException { String segmentMessage = bar + - "\n§e Category: §d" + category.getName() - ; + "\n§e Category: §d" + category.getName(); - @SuppressWarnings("OptionalGetWithoutIsPresent") - final CategoryFile categoryFile = category.getByGameMode(Timer.getInstance().get().getGameMode()); + @SuppressWarnings("OptionalGetWithoutIsPresent") final CategoryFile categoryFile = category.getByGameMode(Timer.getInstance().get().getGameMode()); short bestSegment = categoryFile.getBestSegment(round); if (bestSegment == (short) 0) { categoryFile.setBestSegment(round, roundTime); @@ -25,23 +24,22 @@ public class RecordManager { final String timeString = formattedTime(roundTime); segmentMessage += "\n§cRound " + round + "§e took §a" + timeString + "§e!"; } else { - if (roundTime getInstance() { + return Optional.ofNullable(instance); + } + + /** + * Call to invalidate {@link #instance} to trigger the garbage collector + */ + public static void dropInstances() { + instance = null; + } /** * The main splitting function. * Cancels on the second occurring sound-effect, important for {@link RecordManager} to not override values incorrectly. + * * @param passedRound The round that has been passed. */ public void split(byte passedRound) { @@ -69,9 +79,10 @@ public class Timer { passedRoundsTickSum = gameTime; round = passedRound; } + public void correctRn() { if (r1Corrected) return; - savedTotalWorldTime = getCurrentTotalWorldTime()-200L; + savedTotalWorldTime = getCurrentTotalWorldTime() - 200L; r1Corrected = true; } @@ -79,7 +90,7 @@ public class Timer { if (passedRound == (byte) 1) pbTracking = true; try { - gameFile.setSegment(passedRound,roundTime); + gameFile.setSegment(passedRound, roundTime); RecordManager.compareSegment(passedRound, roundTime, category); if (pbTracking) RecordManager.compareBest(passedRound, gameTime, category); } catch (IndexOutOfBoundsException exception) { @@ -89,15 +100,16 @@ public class Timer { } } - private long getCurrentTotalWorldTime() { if (Minecraft.getMinecraft() == null) return 0; if (Minecraft.getMinecraft().theWorld == null) return 0; return Minecraft.getMinecraft().theWorld.getTotalWorldTime(); } + public int gameTime() { return (int) (getCurrentTotalWorldTime() - savedTotalWorldTime); } + public short roundTime() { return (short) (gameTime() - passedRoundsTickSum); } @@ -109,21 +121,13 @@ public class Timer { public boolean equalsServerOrNull(String serverNumber) { return (serverNumber == null || serverNumber.equals(this.serverNumber) || serverNumber.isEmpty()); } + public void setCategory(Category category) { this.category = category; } - public static Optional getInstance() { - return Optional.ofNullable(instance); - } - /** - * Call to invalidate {@link #instance} to trigger the garbage collector - */ - public static void dropInstances() { - instance = null; - } public byte getRound() { - return (byte) (round+1); + return (byte) (round + 1); } public GameMode getGameMode() { @@ -134,6 +138,7 @@ public class Timer { public static class MapException extends TimerException { } + public static class ServerNumberException extends TimerException { } } diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/Category.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/Category.java index 783b3fd..1eab8df 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/Category.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/Category.java @@ -14,6 +14,7 @@ public class Category { private static String selectedCategory = ZombiesUtilsConfig.getDefaultCategory(); public final CategoryFile[] categoryFiles = new CategoryFile[7]; private final String name; + public Category() { final File category = new File(new File("zombies", "splits"), selectedCategory); categoryFiles[0] = new CategoryFile(category, new GameMode(Map.DEAD_END)); @@ -28,7 +29,16 @@ public class Category { this.name = Category.selectedCategory; } + public static void setSelectedCategory(String selectedCategory) { + Category.selectedCategory = selectedCategory; + Timer.getInstance().ifPresent(timer -> timer.setCategory(new Category())); + } + public static String[] getCategories() { + File dir = new File("zombies" + File.separator + "splits"); + if (dir.isDirectory()) return dir.list(); + else return new String[0]; + } public CategoryFile getByGameMode(@NotNull GameMode gameMode) { if (gameMode.is(Map.DEAD_END, Difficulty.NORMAL)) return categoryFiles[0]; @@ -43,16 +53,6 @@ public class Category { else throw new IllegalStateException("Unexpected value: " + gameMode); } - public static void setSelectedCategory(String selectedCategory) { - Category.selectedCategory = selectedCategory; - Timer.getInstance().ifPresent(timer -> timer.setCategory(new Category())); - } - public static String[] getCategories() { - File dir = new File("zombies"+File.separator+"splits"); - if (dir.isDirectory()) return dir.list(); - else return new String[0]; - } - public String getName() { return name; } diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/FileManager.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/FileManager.java index 5175298..2402fa5 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/FileManager.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/FileManager.java @@ -26,6 +26,7 @@ public class FileManager { return gson.fromJson(dataJson, CategoryData.class); } + public static void createDataFile(@NotNull SplitsFile splitsFile) { try { //noinspection ResultOfMethodCallIgnored @@ -37,9 +38,11 @@ public class FileManager { throw new RuntimeException(e); } } + public static void writeDataToFile(SplitsFile splitsFile) throws IOException { FileUtils.writeStringToFile(splitsFile, splitsFile.getData().toJSON(), StandardCharsets.UTF_16); } + public static CategoryData categoryReadOrCreate(CategoryFile file) { CategoryData data; try { diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/SplitsFile.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/SplitsFile.java index 1de5cba..3723485 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/SplitsFile.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/SplitsFile.java @@ -8,8 +8,10 @@ public abstract class SplitsFile extends File { public SplitsFile(String parent, @NotNull String child) { super(parent, child); } + public SplitsFile(File category, String child) { super(category, child); } + abstract public ISplitsData getData(); } diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/data/CategoryData.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/data/CategoryData.java index c14f860..fbba84a 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/data/CategoryData.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/data/CategoryData.java @@ -10,13 +10,15 @@ import java.util.Arrays; public class CategoryData implements ISplitsData { private final short[] bestSegments; //in ticks, max ~27 min private final int[] personalBests; //in ticks, + public CategoryData(@NotNull Map map) { switch (map) { case ALIEN_ARCADIUM: bestSegments = new short[105]; personalBests = new int[105]; break; - case DEAD_END: case BAD_BLOOD: + case DEAD_END: + case BAD_BLOOD: bestSegments = new short[30]; personalBests = new int[30]; break; @@ -26,6 +28,7 @@ public class CategoryData implements ISplitsData { Arrays.fill(bestSegments, (short) 0); Arrays.fill(personalBests, 0); } + @Override public String toJSON() { Gson gson = new Gson(); @@ -35,12 +38,15 @@ public class CategoryData implements ISplitsData { public short getBestSegment(int index) { return bestSegments[index]; } + public int getPersonalBest(int index) { return personalBests[index]; } + public void setBestSegment(int index, short ticks) { bestSegments[index] = ticks; } + public void setPersonalBest(int index, int ticks) { personalBests[index] = ticks; } diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/data/GameData.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/data/GameData.java index 3148fd8..09db293 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/data/GameData.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/data/GameData.java @@ -15,7 +15,8 @@ public class GameData implements ISplitsData { case ALIEN_ARCADIUM: segments = new short[105]; break; - case DEAD_END: case BAD_BLOOD: + case DEAD_END: + case BAD_BLOOD: segments = new short[30]; break; default: @@ -29,6 +30,7 @@ public class GameData implements ISplitsData { Gson gson = new Gson(); return gson.toJson(this.segments); } + public void setSegment(int index, short ticks) { segments[index] = ticks; } diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/files/CategoryFile.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/files/CategoryFile.java index 7cd4eb5..96ed41b 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/files/CategoryFile.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/files/CategoryFile.java @@ -13,31 +13,41 @@ import java.io.IOException; public class CategoryFile extends SplitsFile { private final CategoryData data; private final GameMode gameMode; + public CategoryFile(File category, @NotNull GameMode gameMode) { // Game-directory -> custom category -> file named "MAP_DIFFICULTY.times" // Content encoded in StandardCharsets.UTF_16 - super(category,gameMode.getMap() + "_" + gameMode.getDifficulty() + ".times"); + super(category, gameMode.getMap() + "_" + gameMode.getDifficulty() + ".times"); this.gameMode = gameMode; data = FileManager.categoryReadOrCreate(this); } public short getBestSegment(int round) { - return data.getBestSegment(round-1); + return data.getBestSegment(round - 1); } + public void setBestSegment(int round, short ticks) { - data.setBestSegment(round-1, ticks); + data.setBestSegment(round - 1, ticks); - try { FileManager.writeDataToFile(this); } - catch (IOException e) { throw new RuntimeException(e); } + try { + FileManager.writeDataToFile(this); + } catch (IOException e) { + throw new RuntimeException(e); + } } + public int getPersonalBest(int round) { - return data.getPersonalBest(round-1); + return data.getPersonalBest(round - 1); } - public void setPersonalBest(int round, int ticks) { - data.setPersonalBest(round-1, ticks); - try { FileManager.writeDataToFile(this); } - catch (IOException e) { throw new RuntimeException(e); } + public void setPersonalBest(int round, int ticks) { + data.setPersonalBest(round - 1, ticks); + + try { + FileManager.writeDataToFile(this); + } catch (IOException e) { + throw new RuntimeException(e); + } } public GameMode getGameMode() { diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/files/GameFile.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/files/GameFile.java index 3279c3e..8a61c2d 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/files/GameFile.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/files/GameFile.java @@ -25,14 +25,17 @@ public class GameFile extends SplitsFile { private static @NotNull String formattedTime() { final LocalDateTime dateTime = LocalDateTime.now().truncatedTo(ChronoUnit.MINUTES); - return dateTime.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME).replace(':','-').replaceFirst("T","_"); + return dateTime.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME).replace(':', '-').replaceFirst("T", "_"); } public void setSegment(int round, short ticks) { - data.setSegment(round-1, ticks); + data.setSegment(round - 1, ticks); - try { FileManager.writeDataToFile(this); } - catch (IOException e) { throw new RuntimeException(e); } + try { + FileManager.writeDataToFile(this); + } catch (IOException e) { + throw new RuntimeException(e); + } } @Override 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 5ae6c93..f7dd77f 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/utils/Scoreboard.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/utils/Scoreboard.java @@ -47,13 +47,14 @@ public class Scoreboard { List filteredScores = scoreCollection.stream().filter(input -> input.getPlayerName() != null && !input.getPlayerName().startsWith("#")).collect(Collectors.toList()); List scores; - if (filteredScores.size() > 15) scores = Lists.newArrayList(Iterables.skip(filteredScores, scoreCollection.size() - 15)); + if (filteredScores.size() > 15) + scores = Lists.newArrayList(Iterables.skip(filteredScores, scoreCollection.size() - 15)); else scores = filteredScores; scores = Lists.reverse(scores); lines = new ArrayList<>(); - for (Score score: scores - ) { + for (Score score : scores + ) { ScorePlayerTeam team = scoreboard.getPlayersTeam(score.getPlayerName()); String scoreboardLine = ScorePlayerTeam.formatPlayerName(team, score.getPlayerName()).trim(); lines.add(STRIP_COLOR_PATTERN.matcher(SIDEBAR_EMOJI_PATTERN.matcher(scoreboardLine).replaceAll("")).replaceAll("")); @@ -79,6 +80,7 @@ public class Scoreboard { return 0; } } + public static Optional getServerNumber() { String line; try { @@ -91,6 +93,7 @@ public class Scoreboard { ZombiesUtils.getInstance().getLogger().debug("Servernumber: " + string); return Optional.ofNullable(string); } + public static Optional getMap() { String line; try { @@ -104,16 +107,22 @@ public class Scoreboard { } String mapString = MAP_PATTERN.matcher(line).replaceAll("$1"); switch (mapString) { - 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(); + 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 isNotZombies() { return (!"ZOMBIES".equals(title)); }