WIP: implement mod #1

Draft
Stachelbeere1248 wants to merge 9 commits from LovelyBunny/zombies-utils_fabric:master into master
10 changed files with 114 additions and 37 deletions
Showing only changes of commit fdb9acb04a - Show all commits

View file

@ -8,10 +8,8 @@ import net.minecraft.client.util.InputUtil;
import net.minecraft.text.MutableText;
import net.minecraft.text.Style;
import net.minecraft.text.Text;
import net.minecraft.text.TextColor;
import net.minecraft.util.Formatting;
import org.lwjgl.glfw.GLFW;
import xyz.stachel.zombiesutils.config.Configs;
public class ZombiesUtilsClient implements ClientModInitializer {
public static boolean PLAYER_VISIBILITY_SWITCH;

View file

@ -1,7 +1,9 @@
package xyz.stachel.zombiesutils.game;
import net.minecraft.client.MinecraftClient;
import net.minecraft.text.Style;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.jetbrains.annotations.NotNull;
import xyz.stachel.zombiesutils.ZombiesUtils;
@ -49,7 +51,7 @@ class Game extends Timer {
this.record();
} catch (Exception 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.round = round + 1;
@ -64,7 +66,7 @@ class Game extends Timer {
public void helicopter() {
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());
return;
}

View file

@ -1,7 +1,9 @@
package xyz.stachel.zombiesutils.game;
import net.minecraft.client.MinecraftClient;
import net.minecraft.text.Style;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.jetbrains.annotations.NotNull;
import xyz.stachel.zombiesutils.ZombiesUtils;
@ -20,9 +22,9 @@ class GameFile extends File {
private FileWriter writer;
GameFile(@NotNull final String serverNumber) {
super(new File("zombies", "runs"), formattedTime() + "_" + serverNumber + ".seg2");
this.data = new GameData(ZombiesUtils.getGameManager().getGame(serverNumber).mode.getMap());
GameFile(@NotNull final String serverNumber, @NotNull final GameMode mode) {
super(new File("zombies", "runs"), formattedTime() + "_" + serverNumber + ".seg2");
this.data = new GameData(mode.getMap());
FileManager.createDataFile(this, this.data);
}
@ -57,7 +59,7 @@ class GameFile extends File {
FileManager.writeDataToFile(this, this.data);
} catch (Exception 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);
}
}
}

View file

@ -19,7 +19,7 @@ public class GameManager {
this.queuedDifficulty.ifPresent(mode::changeDifficulty);
}
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) {
@ -27,18 +27,13 @@ public class GameManager {
final String mode = Location.getMode();
if (sn == null || mode == null || !Utils.isZombies()) return;
if (!this.games.containsKey(sn)) {
addGame(sn, new GameMode(Map.DEAD_END), round);
if (this.getGame(sn) == null) {
this.addGame(sn, new GameMode(Utils.getMap(mode)), round);
} 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) {
return this.games.get(sn);
}

View file

@ -36,10 +36,10 @@ public class Category {
this.name = Category.selectedCategory;
}
// public static void setSelectedCategory(String selectedCategory) {
// Category.selectedCategory = selectedCategory;
// ZombiesUtils.getGameManager().getGame().ifPresent(game -> game.setCategory(new Category()));
// }
public static void setSelectedCategory(String selectedCategory) {
Category.selectedCategory = selectedCategory;
// ZombiesUtils.getGameManager().getGame().ifPresent(game -> game.setCategory(new Category()));
}
public static String[] getCategories() {
File dir;
@ -67,7 +67,6 @@ public class Category {
case HARD -> categoryFiles[8];
case RIP -> categoryFiles[9];
};
default -> throw new IllegalStateException("Unexpected value: " + gameMode);
};
}

View file

@ -1,7 +1,9 @@
package xyz.stachel.zombiesutils.game.recorder.files;
import net.minecraft.client.MinecraftClient;
import net.minecraft.text.Style;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.jetbrains.annotations.NotNull;
import xyz.stachel.zombiesutils.ZombiesUtils;
@ -36,7 +38,7 @@ public class CategoryFile extends File {
FileManager.writeDataToFile(this, this.data);
} catch (Exception 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);
} catch (Exception 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);
}
}

View file

@ -10,9 +10,9 @@ public class Location {
private static String mode;
public static void onLocation(ClientboundLocationPacket p) {
Location.serverNumber = p.getServerName();
serverNumber = p.getServerName();
Optional<String> m = p.getMode();
if (m.isPresent()) Location.mode = m.get();
m.ifPresent(s -> mode = s);
}
public static String getServerNumber() {

View file

@ -3,6 +3,7 @@ package xyz.stachel.zombiesutils.mixin;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.network.packet.s2c.play.TitleS2CPacket;
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.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@ -14,17 +15,18 @@ import java.util.regex.Pattern;
@Mixin(ClientPlayNetworkHandler.class)
public abstract class ClientPlayNetworkHandlerMixin {
@Unique
private static final Pattern pattern = Pattern.compile("Round (\\d{1,3})");
@Inject(at = @At("HEAD"), method = "onTitle")
private void zombiesUtils_onTitle(TitleS2CPacket p, CallbackInfo info) {
final String msg = p.text().getString();
final Matcher matcher = pattern.matcher(msg);
if (matcher.find()) {
int number = Integer.parseInt(matcher.group(1));
if (number >= 1 && number <= 105) {
ZombiesUtils.getGameManager().onRound(number);
private void zombiesUtils_onTitle(TitleS2CPacket p, CallbackInfo info) {
final String msg = p.text().getString();
final Matcher matcher = pattern.matcher(msg);
if (matcher.find()) {
int number = Integer.parseInt(matcher.group(1));
if (number >= 1 && number <= 105) {
ZombiesUtils.getGameManager().onRound(number);
}
}
}
}
}

View file

@ -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;
}
}

View file

@ -1,6 +1,5 @@
package xyz.stachel.zombiesutils.util;
import net.minecraft.client.MinecraftClient;
import org.jetbrains.annotations.Nullable;
import xyz.stachel.zombiesutils.game.GameMode;
import xyz.stachel.zombiesutils.handlers.Location;
@ -10,8 +9,8 @@ import static xyz.stachel.zombiesutils.game.GameMode.Map.*;
public class Utils {
@Nullable
public static GameMode.Map getMap() {
return switch (Location.getMode()) {
public static GameMode.Map getMap(String mode) {
return switch (mode) {
case "ZOMBIES_DEAD_END" -> DEAD_END;
case "ZOMBIES_BAD_BLOOD" -> BAD_BLOOD;
case "ZOMBIES_ALIEN_ARCADIUM" -> ALIEN_ARCADIUM;