WIP: implement mod #1
10 changed files with 114 additions and 37 deletions
|
@ -8,10 +8,8 @@ import net.minecraft.client.util.InputUtil;
|
||||||
import net.minecraft.text.MutableText;
|
import net.minecraft.text.MutableText;
|
||||||
import net.minecraft.text.Style;
|
import net.minecraft.text.Style;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
import net.minecraft.text.TextColor;
|
|
||||||
import net.minecraft.util.Formatting;
|
import net.minecraft.util.Formatting;
|
||||||
import org.lwjgl.glfw.GLFW;
|
import org.lwjgl.glfw.GLFW;
|
||||||
import xyz.stachel.zombiesutils.config.Configs;
|
|
||||||
|
|
||||||
public class ZombiesUtilsClient implements ClientModInitializer {
|
public class ZombiesUtilsClient implements ClientModInitializer {
|
||||||
public static boolean PLAYER_VISIBILITY_SWITCH;
|
public static boolean PLAYER_VISIBILITY_SWITCH;
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package xyz.stachel.zombiesutils.game;
|
package xyz.stachel.zombiesutils.game;
|
||||||
|
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
|
import net.minecraft.text.Style;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
|
import net.minecraft.util.Formatting;
|
||||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import xyz.stachel.zombiesutils.ZombiesUtils;
|
import xyz.stachel.zombiesutils.ZombiesUtils;
|
||||||
|
@ -49,7 +51,7 @@ class Game extends Timer {
|
||||||
this.record();
|
this.record();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
ZombiesUtils.LOGGER.error(ExceptionUtils.getStackTrace(e));
|
ZombiesUtils.LOGGER.error(ExceptionUtils.getStackTrace(e));
|
||||||
MinecraftClient.getInstance().player.sendMessage(Text.of("Error recording splits"), false);
|
MinecraftClient.getInstance().player.sendMessage(Text.literal("Error recording splits").setStyle(Style.EMPTY.withColor(Formatting.RED)), false);
|
||||||
}
|
}
|
||||||
this.split();
|
this.split();
|
||||||
this.round = round + 1;
|
this.round = round + 1;
|
||||||
|
@ -64,7 +66,7 @@ class Game extends Timer {
|
||||||
|
|
||||||
public void helicopter() {
|
public void helicopter() {
|
||||||
if (!this.mode.isMap(GameMode.Map.PRISON)) {
|
if (!this.mode.isMap(GameMode.Map.PRISON)) {
|
||||||
MinecraftClient.getInstance().player.sendMessage(Text.of("You are not imprisoned. Yet."), false);
|
MinecraftClient.getInstance().player.sendMessage(Text.literal("You are not imprisoned. Yet.").setStyle(Style.EMPTY.withColor(Formatting.RED)), false);
|
||||||
ZombiesUtils.LOGGER.error(Thread.currentThread().getStackTrace().toString());
|
ZombiesUtils.LOGGER.error(Thread.currentThread().getStackTrace().toString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package xyz.stachel.zombiesutils.game;
|
package xyz.stachel.zombiesutils.game;
|
||||||
|
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
|
import net.minecraft.text.Style;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
|
import net.minecraft.util.Formatting;
|
||||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import xyz.stachel.zombiesutils.ZombiesUtils;
|
import xyz.stachel.zombiesutils.ZombiesUtils;
|
||||||
|
@ -20,9 +22,9 @@ class GameFile extends File {
|
||||||
|
|
||||||
private FileWriter writer;
|
private FileWriter writer;
|
||||||
|
|
||||||
GameFile(@NotNull final String serverNumber) {
|
GameFile(@NotNull final String serverNumber, @NotNull final GameMode mode) {
|
||||||
super(new File("zombies", "runs"), formattedTime() + "_" + serverNumber + ".seg2");
|
super(new File("zombies", "runs"), formattedTime() + "_" + serverNumber + ".seg2");
|
||||||
this.data = new GameData(ZombiesUtils.getGameManager().getGame(serverNumber).mode.getMap());
|
this.data = new GameData(mode.getMap());
|
||||||
FileManager.createDataFile(this, this.data);
|
FileManager.createDataFile(this, this.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +59,7 @@ class GameFile extends File {
|
||||||
FileManager.writeDataToFile(this, this.data);
|
FileManager.writeDataToFile(this, this.data);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
ZombiesUtils.LOGGER.error(ExceptionUtils.getStackTrace(e));
|
ZombiesUtils.LOGGER.error(ExceptionUtils.getStackTrace(e));
|
||||||
MinecraftClient.getInstance().player.sendMessage(Text.of("Error saving segment to run-file. Please Contact Stachelbeere1248."), false);
|
MinecraftClient.getInstance().player.sendMessage(Text.literal("Error saving segment to run-file. Please Contact Stachelbeere1248.").setStyle(Style.EMPTY.withColor(Formatting.RED)), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ public class GameManager {
|
||||||
this.queuedDifficulty.ifPresent(mode::changeDifficulty);
|
this.queuedDifficulty.ifPresent(mode::changeDifficulty);
|
||||||
}
|
}
|
||||||
this.queuedDifficulty = Optional.empty();
|
this.queuedDifficulty = Optional.empty();
|
||||||
this.games.put(serverNumber, new Game(new GameFile(serverNumber), mode));
|
this.games.put(serverNumber, new Game(new GameFile(serverNumber, mode), mode, round));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onRound(final int round) {
|
public void onRound(final int round) {
|
||||||
|
@ -27,18 +27,13 @@ public class GameManager {
|
||||||
final String mode = Location.getMode();
|
final String mode = Location.getMode();
|
||||||
if (sn == null || mode == null || !Utils.isZombies()) return;
|
if (sn == null || mode == null || !Utils.isZombies()) return;
|
||||||
|
|
||||||
if (!this.games.containsKey(sn)) {
|
if (this.getGame(sn) == null) {
|
||||||
addGame(sn, new GameMode(Map.DEAD_END), round);
|
this.addGame(sn, new GameMode(Utils.getMap(mode)), round);
|
||||||
} else {
|
} else {
|
||||||
this.games.get(sn).split(round);
|
this.getGame(sn).split(round);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<Game> getGame() {
|
|
||||||
final String sn = Location.getServerNumber();
|
|
||||||
return Optional.of(this.games.get(sn));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Game getGame(String sn) {
|
public Game getGame(String sn) {
|
||||||
return this.games.get(sn);
|
return this.games.get(sn);
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,10 +36,10 @@ public class Category {
|
||||||
this.name = Category.selectedCategory;
|
this.name = Category.selectedCategory;
|
||||||
}
|
}
|
||||||
|
|
||||||
// public static void setSelectedCategory(String selectedCategory) {
|
public static void setSelectedCategory(String selectedCategory) {
|
||||||
// Category.selectedCategory = selectedCategory;
|
Category.selectedCategory = selectedCategory;
|
||||||
// ZombiesUtils.getGameManager().getGame().ifPresent(game -> game.setCategory(new Category()));
|
// ZombiesUtils.getGameManager().getGame().ifPresent(game -> game.setCategory(new Category()));
|
||||||
// }
|
}
|
||||||
|
|
||||||
public static String[] getCategories() {
|
public static String[] getCategories() {
|
||||||
File dir;
|
File dir;
|
||||||
|
@ -67,7 +67,6 @@ public class Category {
|
||||||
case HARD -> categoryFiles[8];
|
case HARD -> categoryFiles[8];
|
||||||
case RIP -> categoryFiles[9];
|
case RIP -> categoryFiles[9];
|
||||||
};
|
};
|
||||||
default -> throw new IllegalStateException("Unexpected value: " + gameMode);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package xyz.stachel.zombiesutils.game.recorder.files;
|
package xyz.stachel.zombiesutils.game.recorder.files;
|
||||||
|
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
|
import net.minecraft.text.Style;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
|
import net.minecraft.util.Formatting;
|
||||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import xyz.stachel.zombiesutils.ZombiesUtils;
|
import xyz.stachel.zombiesutils.ZombiesUtils;
|
||||||
|
@ -36,7 +38,7 @@ public class CategoryFile extends File {
|
||||||
FileManager.writeDataToFile(this, this.data);
|
FileManager.writeDataToFile(this, this.data);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
ZombiesUtils.LOGGER.error(ExceptionUtils.getStackTrace(e));
|
ZombiesUtils.LOGGER.error(ExceptionUtils.getStackTrace(e));
|
||||||
MinecraftClient.getInstance().player.sendMessage(Text.of("Error saving segment to splits-file. Please Contact Stachelbeere1248."), false);
|
MinecraftClient.getInstance().player.sendMessage(Text.literal("Error saving segment to splits-file. Please Contact Stachelbeere1248.").setStyle(Style.EMPTY.withColor(Formatting.RED)), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +53,7 @@ public class CategoryFile extends File {
|
||||||
FileManager.writeDataToFile(this, this.data);
|
FileManager.writeDataToFile(this, this.data);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
ZombiesUtils.LOGGER.error(ExceptionUtils.getStackTrace(e));
|
ZombiesUtils.LOGGER.error(ExceptionUtils.getStackTrace(e));
|
||||||
MinecraftClient.getInstance().player.sendMessage(Text.of("Error saving pb to splits-file. Please Contact Stachelbeere1248."), false);
|
MinecraftClient.getInstance().player.sendMessage(Text.literal("Error saving pb to splits-file. Please Contact Stachelbeere1248.").setStyle(Style.EMPTY.withColor(Formatting.RED)), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,9 +10,9 @@ public class Location {
|
||||||
private static String mode;
|
private static String mode;
|
||||||
|
|
||||||
public static void onLocation(ClientboundLocationPacket p) {
|
public static void onLocation(ClientboundLocationPacket p) {
|
||||||
Location.serverNumber = p.getServerName();
|
serverNumber = p.getServerName();
|
||||||
Optional<String> m = p.getMode();
|
Optional<String> m = p.getMode();
|
||||||
if (m.isPresent()) Location.mode = m.get();
|
m.ifPresent(s -> mode = s);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getServerNumber() {
|
public static String getServerNumber() {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package xyz.stachel.zombiesutils.mixin;
|
||||||
import net.minecraft.client.network.ClientPlayNetworkHandler;
|
import net.minecraft.client.network.ClientPlayNetworkHandler;
|
||||||
import net.minecraft.network.packet.s2c.play.TitleS2CPacket;
|
import net.minecraft.network.packet.s2c.play.TitleS2CPacket;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Unique;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
@ -14,17 +15,18 @@ import java.util.regex.Pattern;
|
||||||
|
|
||||||
@Mixin(ClientPlayNetworkHandler.class)
|
@Mixin(ClientPlayNetworkHandler.class)
|
||||||
public abstract class ClientPlayNetworkHandlerMixin {
|
public abstract class ClientPlayNetworkHandlerMixin {
|
||||||
|
@Unique
|
||||||
private static final Pattern pattern = Pattern.compile("Round (\\d{1,3})");
|
private static final Pattern pattern = Pattern.compile("Round (\\d{1,3})");
|
||||||
|
|
||||||
@Inject(at = @At("HEAD"), method = "onTitle")
|
@Inject(at = @At("HEAD"), method = "onTitle")
|
||||||
private void zombiesUtils_onTitle(TitleS2CPacket p, CallbackInfo info) {
|
private void zombiesUtils_onTitle(TitleS2CPacket p, CallbackInfo info) {
|
||||||
final String msg = p.text().getString();
|
final String msg = p.text().getString();
|
||||||
final Matcher matcher = pattern.matcher(msg);
|
final Matcher matcher = pattern.matcher(msg);
|
||||||
if (matcher.find()) {
|
if (matcher.find()) {
|
||||||
int number = Integer.parseInt(matcher.group(1));
|
int number = Integer.parseInt(matcher.group(1));
|
||||||
if (number >= 1 && number <= 105) {
|
if (number >= 1 && number <= 105) {
|
||||||
ZombiesUtils.getGameManager().onRound(number);
|
ZombiesUtils.getGameManager().onRound(number);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,78 @@
|
||||||
|
package xyz.stachel.zombiesutils.util;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
@SuppressWarnings("SpellCheckingInspection")
|
||||||
|
public class LanguageSupport {
|
||||||
|
private static final String[] LANGUAGES = {
|
||||||
|
"EN",
|
||||||
|
"FR",
|
||||||
|
"DE"
|
||||||
|
};
|
||||||
|
|
||||||
|
public static boolean isLoss(@NotNull String input) {
|
||||||
|
final String[] words = {
|
||||||
|
"§cGame Over!",
|
||||||
|
"§cPartie terminée!",
|
||||||
|
"§cDas Spiel ist vorbei!"
|
||||||
|
};
|
||||||
|
return Arrays.asList(words).contains(input);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isWin(@NotNull String input) {
|
||||||
|
final String[] words = {
|
||||||
|
"§aYou Win!",
|
||||||
|
"§aVous avez gagné!",
|
||||||
|
"§aDu gewinnst!"
|
||||||
|
};
|
||||||
|
return Arrays.asList(words).contains(input);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean containsHard(@NotNull String input) {
|
||||||
|
final String[] words = {
|
||||||
|
"Hard Difficulty",
|
||||||
|
"Difficulté Hard",
|
||||||
|
"Hard Schwierigkeitsgrad",
|
||||||
|
"困难",
|
||||||
|
"困難"
|
||||||
|
};
|
||||||
|
return Arrays.stream(words).anyMatch(input::contains);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean containsRIP(@NotNull String input) {
|
||||||
|
final String[] words = {
|
||||||
|
"RIP Difficulty",
|
||||||
|
"Difficulté RIP",
|
||||||
|
"RIP Schwierigkeitsgrad",
|
||||||
|
"安息"
|
||||||
|
};
|
||||||
|
return Arrays.stream(words).anyMatch(input::contains);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isHelicopterIncoming(@NotNull String input) {
|
||||||
|
final String[] words = {
|
||||||
|
"The Helicopter is on its way! Hold out for 120 more seconds!"
|
||||||
|
};
|
||||||
|
return Arrays.stream(words).anyMatch(input::contains);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NotNull Pattern roundPattern(@NotNull String language) {
|
||||||
|
switch (language) {
|
||||||
|
case "EN":
|
||||||
|
return Pattern.compile("Round ([0-9]{1,3})");
|
||||||
|
case "FR":
|
||||||
|
return Pattern.compile("Manche ([0-9]{1,3})");
|
||||||
|
case "DE":
|
||||||
|
return Pattern.compile("Runde ([0-9]{1,3})");
|
||||||
|
default:
|
||||||
|
throw new IllegalStateException("Unexpected value: " + language);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String[] getLanguages() {
|
||||||
|
return LANGUAGES;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,5 @@
|
||||||
package xyz.stachel.zombiesutils.util;
|
package xyz.stachel.zombiesutils.util;
|
||||||
|
|
||||||
import net.minecraft.client.MinecraftClient;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import xyz.stachel.zombiesutils.game.GameMode;
|
import xyz.stachel.zombiesutils.game.GameMode;
|
||||||
import xyz.stachel.zombiesutils.handlers.Location;
|
import xyz.stachel.zombiesutils.handlers.Location;
|
||||||
|
@ -10,8 +9,8 @@ import static xyz.stachel.zombiesutils.game.GameMode.Map.*;
|
||||||
public class Utils {
|
public class Utils {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static GameMode.Map getMap() {
|
public static GameMode.Map getMap(String mode) {
|
||||||
return switch (Location.getMode()) {
|
return switch (mode) {
|
||||||
case "ZOMBIES_DEAD_END" -> DEAD_END;
|
case "ZOMBIES_DEAD_END" -> DEAD_END;
|
||||||
case "ZOMBIES_BAD_BLOOD" -> BAD_BLOOD;
|
case "ZOMBIES_BAD_BLOOD" -> BAD_BLOOD;
|
||||||
case "ZOMBIES_ALIEN_ARCADIUM" -> ALIEN_ARCADIUM;
|
case "ZOMBIES_ALIEN_ARCADIUM" -> ALIEN_ARCADIUM;
|
||||||
|
|
Loading…
Add table
Reference in a new issue