Skip to content

Commit

Permalink
v1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Stachelbeere1248 committed Nov 26, 2023
1 parent 289aba5 commit 656af97
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void preInit(@NotNull FMLPreInitializationEvent event) {
logger = event.getModLog();
ZombiesUtilsConfig.config = new Configuration(
event.getSuggestedConfigurationFile(),
"1.1.1"
"1.2.1"
);
ZombiesUtilsConfig.load();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -36,13 +35,9 @@ else switch (args[0]) {
} 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(
Expand All @@ -54,7 +49,7 @@ public List<String> addTabCompletionOptions(ICommandSender sender, String @NotNu
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();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,30 @@

public class Hotkeys {
private final KeyBinding chatMacro;
private final KeyBinding rlSpawn;

public Hotkeys() {
chatMacro = new KeyBinding(
"Chat Macro",
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public static void load() {
"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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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;
Expand All @@ -18,6 +19,8 @@ public void onKeyInput(InputEvent.KeyInputEvent event) {
Minecraft.getMinecraft().thePlayer.sendChatMessage(
ZombiesUtilsConfig.getChatMacro()
);
} else if (Keyboard.getEventKey() == hotkeys.getRlSpawn().getKeyCode()) {
RenderGameOverlayHandler.toggleRL();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -33,8 +36,7 @@ private void handleTitle(S45PacketTitle packetIn, CallbackInfo ci) {
|| (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
Expand All @@ -58,15 +60,48 @@ private void handleTitle(S45PacketTitle packetIn, CallbackInfo ci) {
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()) {
Expand All @@ -82,4 +117,5 @@ private void handleTitle(S45PacketTitle packetIn, CallbackInfo ci) {
} else if (message.equals("§cGame Over!")) Timer.dropInstances();
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

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!");
}
Expand Down Expand Up @@ -78,7 +80,7 @@ private void renderSpawnTime(byte @NotNull [] waveTimes, short roundTicks) {
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++;
Expand Down Expand Up @@ -110,7 +112,12 @@ private static String getTimeString(long timerTicks) {
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -56,7 +39,6 @@ public Timer (@NotNull String serverNumber, @NotNull Map map, byte round) {
this.round = round;
if (ZombiesUtilsConfig.isSlaToggled()) SLA.instance = new SLA(map);

instance = this;
}


Expand Down Expand Up @@ -105,6 +87,11 @@ public int gameTime() {
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());
}
Expand All @@ -128,4 +115,16 @@ public byte getRound() {
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 {
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,40 +91,30 @@ public static Optional<String> getServerNumber() {
ZombiesUtils.getInstance().getLogger().debug("Servernumber: " + string);
return Optional.ofNullable(string);
}
public static Optional<MapContainer> getMap() {
public static Optional<Map> 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;
}
}
}

0 comments on commit 656af97

Please sign in to comment.