This commit is contained in:
Stachelbeere1248 2023-11-26 17:21:53 +01:00
parent 289aba550c
commit 656af97389
9 changed files with 93 additions and 51 deletions

View file

@ -35,7 +35,7 @@ public class ZombiesUtils {
logger = event.getModLog(); logger = event.getModLog();
ZombiesUtilsConfig.config = new Configuration( ZombiesUtilsConfig.config = new Configuration(
event.getSuggestedConfigurationFile(), event.getSuggestedConfigurationFile(),
"1.1.1" "1.2.1"
); );
ZombiesUtilsConfig.load(); ZombiesUtilsConfig.load();
} }

View file

@ -1,7 +1,6 @@
package com.github.stachelbeere1248.zombiesutils.commands; package com.github.stachelbeere1248.zombiesutils.commands;
import com.github.stachelbeere1248.zombiesutils.timer.Timer; import com.github.stachelbeere1248.zombiesutils.timer.Timer;
import com.github.stachelbeere1248.zombiesutils.utils.Scoreboard;
import net.minecraft.command.*; import net.minecraft.command.*;
import net.minecraft.util.BlockPos; import net.minecraft.util.BlockPos;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -36,13 +35,9 @@ public class ZombiesUtilsCommand extends CommandBase {
} catch (NumberFormatException | NullPointerException ignored) { } catch (NumberFormatException | NullPointerException ignored) {
throw new NumberInvalidException("t",args[2]); throw new NumberInvalidException("t",args[2]);
} break; } 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: default:
throw new WrongUsageException( throw new WrongUsageException(
"[Invalid option] options: kill, split, start", args[0]); "[Invalid option] options: kill, split", args[0]);
} break; } break;
default: default:
throw new WrongUsageException( throw new WrongUsageException(
@ -54,7 +49,7 @@ public class ZombiesUtilsCommand extends CommandBase {
if (args.length == 1) return new ArrayList<>(Collections.singleton("timer")); if (args.length == 1) return new ArrayList<>(Collections.singleton("timer"));
switch (args[0]) { switch (args[0]) {
case "timer": case "timer":
return new ArrayList<>(Arrays.asList("kill","split","start")); return new ArrayList<>(Arrays.asList("kill","split"));
default: return Collections.emptyList(); default: return Collections.emptyList();
} }
} }

View file

@ -6,6 +6,7 @@ import org.lwjgl.input.Keyboard;
public class Hotkeys { public class Hotkeys {
private final KeyBinding chatMacro; private final KeyBinding chatMacro;
private final KeyBinding rlSpawn;
public Hotkeys() { public Hotkeys() {
chatMacro = new KeyBinding( chatMacro = new KeyBinding(
@ -13,11 +14,22 @@ public class Hotkeys {
Keyboard.KEY_Q, Keyboard.KEY_Q,
"Zombies Utils" "Zombies Utils"
); );
rlSpawn = new KeyBinding(
"Rocket Launcher Mode",
Keyboard.KEY_NONE,
"Zombies Utils"
);
} }
public void registerAll() { public void registerAll() {
ClientRegistry.registerKeyBinding(this.chatMacro); ClientRegistry.registerKeyBinding(this.chatMacro);
ClientRegistry.registerKeyBinding(this.rlSpawn);
} }
public KeyBinding getChatMacro() { public KeyBinding getChatMacro() {
return chatMacro; return chatMacro;
} }
public KeyBinding getRlSpawn() {
return rlSpawn;
}
} }

View file

@ -43,9 +43,9 @@ public class ZombiesUtilsConfig {
"name of the category to be selected unless specified using /runCategory" "name of the category to be selected unless specified using /runCategory"
); );
waveOffset = (short) config.getInt( waveOffset = (short) config.getInt(
"spawn-time offset ticks", "RL-mode offset",
Configuration.CATEGORY_GENERAL, Configuration.CATEGORY_GENERAL,
0, -28,
-200, -200,
200, 200,
"max: 200 ticks" "max: 200 ticks"

View file

@ -3,6 +3,7 @@ package com.github.stachelbeere1248.zombiesutils.handlers;
import com.github.stachelbeere1248.zombiesutils.ZombiesUtils; import com.github.stachelbeere1248.zombiesutils.ZombiesUtils;
import com.github.stachelbeere1248.zombiesutils.config.Hotkeys; import com.github.stachelbeere1248.zombiesutils.config.Hotkeys;
import com.github.stachelbeere1248.zombiesutils.config.ZombiesUtilsConfig; import com.github.stachelbeere1248.zombiesutils.config.ZombiesUtilsConfig;
import com.github.stachelbeere1248.zombiesutils.render.RenderGameOverlayHandler;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.InputEvent; import net.minecraftforge.fml.common.gameevent.InputEvent;
@ -18,6 +19,8 @@ public class KeyInputHandler {
Minecraft.getMinecraft().thePlayer.sendChatMessage( Minecraft.getMinecraft().thePlayer.sendChatMessage(
ZombiesUtilsConfig.getChatMacro() ZombiesUtilsConfig.getChatMacro()
); );
} else if (Keyboard.getEventKey() == hotkeys.getRlSpawn().getKeyCode()) {
RenderGameOverlayHandler.toggleRL();
} }
} }
} }

View file

@ -1,10 +1,13 @@
package com.github.stachelbeere1248.zombiesutils.mixin; package com.github.stachelbeere1248.zombiesutils.mixin;
import com.github.stachelbeere1248.zombiesutils.ZombiesUtils;
import com.github.stachelbeere1248.zombiesutils.timer.Timer; import com.github.stachelbeere1248.zombiesutils.timer.Timer;
import com.github.stachelbeere1248.zombiesutils.utils.Scoreboard; import com.github.stachelbeere1248.zombiesutils.utils.Scoreboard;
import net.minecraft.client.Minecraft;
import net.minecraft.client.network.NetHandlerPlayClient; import net.minecraft.client.network.NetHandlerPlayClient;
import net.minecraft.network.play.server.S29PacketSoundEffect; import net.minecraft.network.play.server.S29PacketSoundEffect;
import net.minecraft.network.play.server.S45PacketTitle; import net.minecraft.network.play.server.S45PacketTitle;
import net.minecraft.util.ChatComponentText;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.Unique;
@ -33,8 +36,7 @@ public class MixinNetHandlerPlayClient {
|| (soundEffect.equals("mob.guardian.curse") && !zombies_utils$alienUfoOpened) || (soundEffect.equals("mob.guardian.curse") && !zombies_utils$alienUfoOpened)
)) return; )) return;
zombies_utils$alienUfoOpened = soundEffect.equals("mob.guardian.curse"); zombies_utils$alienUfoOpened = soundEffect.equals("mob.guardian.curse");
/*if (!Timer.getInstance().isPresent()) {
if (!Timer.getInstance().isPresent()) {
new Timer( new Timer(
Scoreboard.getServerNumber().orElseThrow(() -> new RuntimeException("cannot figure out servernumber")), Scoreboard.getServerNumber().orElseThrow(() -> new RuntimeException("cannot figure out servernumber")),
Scoreboard.getMap().orElseThrow(() -> new RuntimeException("cannot figure out map")).map Scoreboard.getMap().orElseThrow(() -> new RuntimeException("cannot figure out map")).map
@ -58,15 +60,48 @@ public class MixinNetHandlerPlayClient {
map.map 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 @Unique
private void zombies_utils$handleTitle(@NotNull S45PacketTitle packet) { private void zombies_utils$handleTitle(@NotNull S45PacketTitle packet) {
if (packet.getType() != S45PacketTitle.Type.TITLE) return; if (packet.getType() != S45PacketTitle.Type.TITLE) return;
final String message = packet.getMessage().getUnformattedText().trim();
Timer.getInstance().ifPresent(timer -> { Timer.getInstance().ifPresent(timer -> {
if (Scoreboard.isZombies()) return; if (Scoreboard.isZombies()) return;
final String message = packet.getMessage().getUnformattedText().trim();
if (message.equals("§aYou Win!")) { if (message.equals("§aYou Win!")) {
switch (timer.getGameMode().getMap()) { switch (timer.getGameMode().getMap()) {
@ -82,4 +117,5 @@ public class MixinNetHandlerPlayClient {
} else if (message.equals("§cGame Over!")) Timer.dropInstances(); } else if (message.equals("§cGame Over!")) Timer.dropInstances();
}); });
} }
} }

View file

@ -17,6 +17,8 @@ import java.util.Objects;
public class RenderGameOverlayHandler { public class RenderGameOverlayHandler {
private final FontRenderer fontRenderer; private final FontRenderer fontRenderer;
private static int rl = 0;
public RenderGameOverlayHandler() { public RenderGameOverlayHandler() {
this.fontRenderer = Objects.requireNonNull(Minecraft.getMinecraft().fontRendererObj, "FontRenderer must not be null!"); this.fontRenderer = Objects.requireNonNull(Minecraft.getMinecraft().fontRendererObj, "FontRenderer must not be null!");
} }
@ -78,7 +80,7 @@ public class RenderGameOverlayHandler {
int color = 0xFFFF55; int color = 0xFFFF55;
for (byte waveTime: waveTimes) { for (byte waveTime: waveTimes) {
final short waveTicks = (short) ((waveTime * 20)-ZombiesUtilsConfig.getWaveOffset()); final short waveTicks = (short) ((waveTime * 20)-rl);
if (roundTicks>waveTicks) { if (roundTicks>waveTicks) {
heightIndex++; heightIndex++;
@ -110,7 +112,12 @@ public class RenderGameOverlayHandler {
private static String getWaveString(long waveTicks, int wave) { private static String getWaveString(long waveTicks, int wave) {
final long minutesPart = (waveTicks *50) / 60000; final long minutesPart = (waveTicks *50) / 60000;
final long secondsPart = ((waveTicks *50) % 60000) / 1000; 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;
}
} }

View file

@ -21,31 +21,14 @@ public class Timer {
private final String serverNumber; private final String serverNumber;
public Category category; public Category category;
private boolean pbTracking = false; 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}. * Constructs a timer and saves it to {@link #instance}.
* @param serverNumber The game's server the timer should be bound to. * @param serverNumber The game's server the timer should be bound to.
* @param map The map the timer should be started for. * @param map The map the timer should be started for.
* @param round If available, round to begin splitting. * @param round If available, round to begin splitting.
*/ */
//TODO: brooooooooo
public Timer (@NotNull String serverNumber, @NotNull Map map, byte round) { public Timer (@NotNull String serverNumber, @NotNull Map map, byte round) {
savedTotalWorldTime = getCurrentTotalWorldTime(); savedTotalWorldTime = getCurrentTotalWorldTime();
if (!serverNumber.trim().isEmpty()) this.serverNumber = serverNumber.trim(); if (!serverNumber.trim().isEmpty()) this.serverNumber = serverNumber.trim();
@ -56,7 +39,6 @@ public class Timer {
this.round = round; this.round = round;
if (ZombiesUtilsConfig.isSlaToggled()) SLA.instance = new SLA(map); if (ZombiesUtilsConfig.isSlaToggled()) SLA.instance = new SLA(map);
instance = this;
} }
@ -105,6 +87,11 @@ public class Timer {
public short roundTime() { public short roundTime() {
return (short) (gameTime() - passedRoundsTickSum); 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) { public boolean equalsServerOrNull(String serverNumber) {
return (serverNumber == null || serverNumber.equals(this.serverNumber) || serverNumber.isEmpty()); return (serverNumber == null || serverNumber.equals(this.serverNumber) || serverNumber.isEmpty());
} }
@ -128,4 +115,16 @@ public class Timer {
public GameMode getGameMode() { public GameMode getGameMode() {
return gameMode; 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 {
}
}
} }

View file

@ -91,40 +91,30 @@ public class Scoreboard {
ZombiesUtils.getInstance().getLogger().debug("Servernumber: " + string); ZombiesUtils.getInstance().getLogger().debug("Servernumber: " + string);
return Optional.ofNullable(string); return Optional.ofNullable(string);
} }
public static Optional<MapContainer> getMap() { public static Optional<Map> getMap() {
String line; String line;
boolean pregame;
try { try {
line = lines.get(12); line = lines.get(12);
pregame = false;
} catch (Exception couldBePregame) { } catch (Exception couldBePregame) {
try { try {
line = lines.get(2); line = lines.get(2);
pregame = true;
} catch (IndexOutOfBoundsException | NullPointerException ignored) { } catch (IndexOutOfBoundsException | NullPointerException ignored) {
return Optional.empty(); return Optional.empty();
} }
} }
String mapString = MAP_PATTERN.matcher(line).replaceAll("$1"); String mapString = MAP_PATTERN.matcher(line).replaceAll("$1");
switch (mapString) { switch (mapString) {
case "Dead End": return Optional.of(new MapContainer(Map.DEAD_END,pregame)); case "Dead End": return Optional.of(Map.DEAD_END);
case "Bad Blood": return Optional.of(new MapContainer(Map.BAD_BLOOD,pregame)); case "Bad Blood": return Optional.of(Map.BAD_BLOOD);
case "Alien Arcadium": return Optional.of(new MapContainer(Map.ALIEN_ARCADIUM,pregame)); case "Alien Arcadium": return Optional.of(Map.ALIEN_ARCADIUM);
default: return Optional.empty(); default: return Optional.empty();
} }
} }
public static int getLineCount() {
return lines.size();
}
public static boolean isZombies() { public static boolean isZombies() {
return (!"ZOMBIES".equals(title)); 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;
}
}
} }