finished first features

This commit is contained in:
Moritz Roßbacher 2023-11-01 18:08:14 +01:00
parent b6ab51ddcd
commit 3864fb6b10
13 changed files with 94 additions and 48 deletions

View file

@ -3,4 +3,4 @@ org.gradle.jvmargs=-Xmx2g
baseGroup = com.github.stachelbeere1248.zombiesutils
mcVersion = 1.8.9
modid = zombiesutils
version = 1.0.0
version = 1.0.1

View file

@ -1,6 +1,7 @@
package com.github.stachelbeere1248.zombiesutils;
import com.github.stachelbeere1248.zombiesutils.commands.CategoryCommand;
import com.github.stachelbeere1248.zombiesutils.handlers.ChatHandler;
import com.github.stachelbeere1248.zombiesutils.handlers.TickHandler;
import com.github.stachelbeere1248.zombiesutils.render.TimeRenderer;
import net.minecraftforge.client.ClientCommandHandler;
@ -11,7 +12,7 @@ import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import org.apache.logging.log4j.Logger;
@Mod(modid = "zombiesutils", useMetadata=true, clientSideOnly = true)
@Mod(modid = "zombiesutils", useMetadata = true, clientSideOnly = true)
public class ZombiesUtils {
private static ZombiesUtils instance;
private Configuration config;
@ -34,6 +35,7 @@ public class ZombiesUtils {
public void init(FMLInitializationEvent event) {
MinecraftForge.EVENT_BUS.register(new TimeRenderer());
MinecraftForge.EVENT_BUS.register(new TickHandler());
MinecraftForge.EVENT_BUS.register(new ChatHandler());
ClientCommandHandler.instance.registerCommand(new CategoryCommand());
}
public Configuration getConfig() {

View file

@ -3,7 +3,6 @@ package com.github.stachelbeere1248.zombiesutils.commands;
import com.github.stachelbeere1248.zombiesutils.timer.Timer;
import com.github.stachelbeere1248.zombiesutils.timer.recorder.Category;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.util.BlockPos;
import net.minecraft.util.ChatComponentText;
@ -27,7 +26,7 @@ public class CategoryCommand extends CommandBase {
}
@Override
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
public void processCommand(ICommandSender sender, String[] args) {
if (args.length == 0) {
IChatComponent error = new ChatComponentText("Please input the name for the category");
sender.addChatMessage(error);

View file

@ -7,7 +7,6 @@ public class GameMode {
public static final GameMode DEAD_END_NORMAL = new GameMode(Map.DEAD_END), DEAD_END_HARD = new GameMode(Map.DEAD_END, Difficulty.HARD), DEAD_END_RIP = new GameMode(Map.DEAD_END, Difficulty.RIP);
public static final GameMode BAD_BLOOD_NORMAL = new GameMode(Map.BAD_BLOOD), BAD_BLOOD_HARD = new GameMode(Map.BAD_BLOOD, Difficulty.HARD), BAD_BLOOD_RIP = new GameMode(Map.BAD_BLOOD, Difficulty.RIP);
public static final GameMode ALIEN_ARCADIUM = new GameMode(Map.ALIEN_ARCADIUM);
private final Map map;
private final Difficulty difficulty;
@ -41,7 +40,8 @@ public class GameMode {
case NORMAL: currentGameMode = DEAD_END_NORMAL; break;
case HARD: currentGameMode = DEAD_END_HARD; break;
case RIP: currentGameMode = DEAD_END_RIP; break;
} break;
}
break;
case BAD_BLOOD:
switch (difficulty) {
case NORMAL: currentGameMode = BAD_BLOOD_NORMAL; break;
@ -60,4 +60,8 @@ public class GameMode {
public static void drop() {
currentGameMode = null;
}
public boolean equals(@NotNull GameMode gameMode) {
return (this.getDifficulty() == gameMode.getDifficulty() && this.getMap() == gameMode.getMap());
}
}

View file

@ -9,22 +9,25 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
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);
@SubscribeEvent
public void onChatReceived(ClientChatReceivedEvent event) {
public void difficultyChange(ClientChatReceivedEvent event) {
String message = STRIP_COLOR_PATTERN.matcher(event.message.getUnformattedText()).replaceAll("").trim();
GameMode gameMode = GameMode.getCurrentGameMode();
if (message.contains(":")) return;
if (gameMode == null) return;
ZombiesUtils.getInstance().getLogger().debug("Chat-event: " + message);
if (message.contains("Hard Difficulty") || message.contains("困难") || message.contains("困難")) {
gameMode.changeDifficulty(Difficulty.HARD);
ZombiesUtils.getInstance().getLogger().debug("Changed to Hard");
} else if (message.contains("RIP Difficulty") || message.contains("安息") || message.contains("RIP")) {
gameMode.changeDifficulty(Difficulty.RIP);
ZombiesUtils.getInstance().getLogger().debug("Changed to RIP");
}
}

View file

@ -7,6 +7,7 @@ import net.minecraftforge.fml.common.gameevent.TickEvent;
public class TickHandler {
@SubscribeEvent
public void onTick(TickEvent.ClientTickEvent event) {
if (event.phase == TickEvent.Phase.START) return;
Scoreboard.refresh();
}
}

View file

@ -1,10 +1,12 @@
package com.github.stachelbeere1248.zombiesutils.mixin;
import com.github.stachelbeere1248.zombiesutils.ZombiesUtils;
import com.github.stachelbeere1248.zombiesutils.game.GameMode;
import com.github.stachelbeere1248.zombiesutils.timer.Timer;
import com.github.stachelbeere1248.zombiesutils.utils.Scoreboard;
import net.minecraft.client.network.NetHandlerPlayClient;
import net.minecraft.network.play.server.S29PacketSoundEffect;
import net.minecraft.network.play.server.S45PacketTitle;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
@ -21,15 +23,18 @@ public class MixinNetHandlerPlayClient {
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.isZombies()) return;
String soundEffect = packet.getSoundName();
if (!(
soundEffect.equals("mob.wither.spawn")
|| soundEffect.equals("mob.enderdragon.end")
|| (soundEffect.equals("mob.guardian.curse") && !zombies_utils$alienUfoOpened)
)) return;
zombies_utils$alienUfoOpened = soundEffect.equals("mob.guardian.curse");
if (!Timer.getInstance().isPresent()) {
@ -40,7 +45,6 @@ public class MixinNetHandlerPlayClient {
);
} else {
Timer timer = Timer.getInstance().get();
//TODO: GAME END
if (timer.equalsServerOrNull(Scoreboard.getServerNumber().orElse(null))) timer.split(Scoreboard.getRound());
else {
@ -53,4 +57,31 @@ public class MixinNetHandlerPlayClient {
}
}
}
@Unique
private void zombies_utils$handleTitle(S45PacketTitle packet) {
if (packet.getType() != S45PacketTitle.Type.TITLE) return;
if (!Scoreboard.isZombies()) return;
final String message = packet.getMessage().getUnformattedText().trim();
if (message.equals("\u00a7aYou Win!")) {
switch (GameMode.getCurrentGameMode().getMap()) {
case DEAD_END: case BAD_BLOOD:
Timer.getInstance().ifPresent(timer -> {
timer.split((byte) 30);
Timer.dropInstance();
});
break;
case ALIEN_ARCADIUM:
Timer.getInstance().ifPresent(timer -> {
timer.split((byte) 105);
Timer.dropInstance();
});
break;
}
} else if (message.equals("\u00a7cGame Over!")) {
Timer.dropInstance();
} else {
ZombiesUtils.getInstance().getLogger().debug(message);
}
}
}

View file

@ -1,6 +1,7 @@
package com.github.stachelbeere1248.zombiesutils.render;
import com.github.stachelbeere1248.zombiesutils.timer.Timer;
import com.github.stachelbeere1248.zombiesutils.utils.Scoreboard;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.ScaledResolution;
@ -18,6 +19,7 @@ public class TimeRenderer {
@SubscribeEvent
public void onRenderGameOverlay(RenderGameOverlayEvent.Post event) {
if (!Scoreboard.isZombies()) return;
if (event.type != RenderGameOverlayEvent.ElementType.ALL) return;
if (!Timer.getInstance().isPresent()) return;

View file

@ -4,63 +4,65 @@ import com.github.stachelbeere1248.zombiesutils.game.GameMode;
import com.github.stachelbeere1248.zombiesutils.timer.recorder.Category;
import com.github.stachelbeere1248.zombiesutils.timer.recorder.TimesFile;
import net.minecraft.client.Minecraft;
import net.minecraft.util.*;
import net.minecraft.util.ChatComponentText;
public class RecordManager {
public static void compareSegment(byte round, short roundTime, Category category) {
sendBar();
TimesFile timesFile = category.getByGameMode(GameMode.getCurrentGameMode());
short bestSegment = timesFile.getBestSegment(round);
if (roundTime<bestSegment) {
if (bestSegment == (short) 0) {
timesFile.setBestSegment(round, roundTime);
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(
"\u00a7l\u00a7e" + category.getName() + ": ***" + "\u00a7l\u00a76 NEW BEST SEGMENT! " + "\u00a7l\u00a7e***"
"\u00a7l\u00a7e Category: " + category.getName() + " - ***" + "\u00a7l\u00a76 NEW BEST SEGMENT! " + "\u00a7l\u00a7e***"
));
final String timeString = getTimeString(roundTime);
final String message = "\u00a7cRound " + round + "\u00a7e took \u00a7a" + timeString + "\u00a7e!";
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(message));
} else {
if (roundTime<bestSegment) {
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(
"\u00a7l\u00a7e Category: " + category.getName() + " - ***" + "\u00a7l\u00a76 NEW BEST SEGMENT! " + "\u00a7l\u00a7e***"
));
timesFile.setBestSegment(round, roundTime);
}
final String timeString = getTimeString(roundTime);
final String message = "\u00a7cRound " + round + "\u00a7e took \u00a7a" + timeString + " \u00a79\u03B4" + (double) (roundTime-bestSegment)/20;
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(message));
} else if (bestSegment == (short) 0) {
timesFile.setBestSegment(round, roundTime);
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(
"\u00a7l\u00a7e" + category.getName() + ": ***" + "\u00a7l\u00a76 NEW BEST SEGMENT! " + "\u00a7l\u00a7e***"
));
final String timeString = getTimeString(roundTime);
final String message = "\u00a7cRound " + round + "\u00a7e took \u00a7a" + timeString + "\u00a7e!";
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(message));
}
sendBar();
}
public static void compareBest(byte round, int gameTime, Category category) {
sendBar();
TimesFile timesFile = category.getByGameMode(GameMode.getCurrentGameMode());
int personalBest = timesFile.getPersonalBest(round);
if (gameTime<personalBest) {
if (personalBest == 0) {
timesFile.setPersonalBest(round, gameTime);
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(
"\u00a7l\u00a7e" + category.getName() + ": ***" + "\u00a7l\u00a76 NEW PERSONAL BEST! " + "\u00a7l\u00a7e***"
"\u00a7l\u00a7e Category: " + category.getName() + " - ***" + "\u00a7l\u00a76 NEW PERSONAL BEST! " + "\u00a7l\u00a7e***"
));
final String timeString = getTimeString(gameTime);
final String message = "\u00a7cRound " + round + "\u00a7e took \u00a7a" + timeString + " \u00a79\u03B4" + (double) (gameTime-personalBest)/20;
final String message = "\u00a7cRound " + round + "\u00a7e finished at \u00a7a" + timeString + "\u00a7e!";
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(message));
} else if (personalBest == 0) {
timesFile.setPersonalBest(round, gameTime);
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(
"\u00a7l\u00a7e" + category.getName() + ": ***" + "\u00a7l\u00a76 NEW PERSONAL BEST! " + "\u00a7l\u00a7e***"
));
} else {
if (gameTime<personalBest) {
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(
"\u00a7l\u00a7e Category: " + category.getName() + " - ***" + "\u00a7l\u00a76 NEW PERSONAL BEST! " + "\u00a7l\u00a7e***"
));
timesFile.setPersonalBest(round, gameTime);
}
final String timeString = getTimeString(gameTime);
final String message = "\u00a7cRound " + round + "\u00a7e took \u00a7a" + timeString + "\u00a7e!";
final String message = "\u00a7cRound " + round + "\u00a7e finished at \u00a7a" + timeString + " \u00a79\u03B4" + (double) (gameTime-personalBest)/20;
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(message));
}
sendBar();
}
private static String getTimeString(int gameTime) {
return String.format("%d:%02d.%d",
@ -69,4 +71,9 @@ public class RecordManager {
((gameTime *50) % 1000) / 100
);
}
private static void sendBar() {
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(
"\u00a7l\u00a7a▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬"
));
}
}

View file

@ -3,7 +3,6 @@ package com.github.stachelbeere1248.zombiesutils.timer;
import com.github.stachelbeere1248.zombiesutils.ZombiesUtils;
import com.github.stachelbeere1248.zombiesutils.game.GameMode;
import com.github.stachelbeere1248.zombiesutils.game.Map;
//import com.github.stachelbeere1248.zombiesutils.game.Waves;
import com.github.stachelbeere1248.zombiesutils.timer.recorder.Category;
import net.minecraft.client.Minecraft;
import org.jetbrains.annotations.NotNull;
@ -88,7 +87,7 @@ public class Timer {
/**
* Call to invalidate {@link #instance} to trigger the garbage collector
*/
public static void drop() {
public static void dropInstance() {
instance = null;
GameMode.drop();
}

View file

@ -1,13 +1,10 @@
package com.github.stachelbeere1248.zombiesutils.timer.recorder;
import com.github.stachelbeere1248.zombiesutils.ZombiesUtils;
import com.github.stachelbeere1248.zombiesutils.game.GameMode;
import com.github.stachelbeere1248.zombiesutils.timer.Timer;
import org.jetbrains.annotations.NotNull;
import scala.reflect.io.Directory;
import java.io.File;
import java.util.List;
public class Category {
private static String selectedCategory = "default"; // read from config ?

View file

@ -1,8 +1,6 @@
package com.github.stachelbeere1248.zombiesutils.timer.recorder;
import com.github.stachelbeere1248.zombiesutils.game.GameMode;
import org.jetbrains.annotations.NotNull;
import scala.reflect.io.Directory;
import java.io.File;

View file

@ -9,7 +9,10 @@ import net.minecraft.scoreboard.Score;
import net.minecraft.scoreboard.ScoreObjective;
import net.minecraft.scoreboard.ScorePlayerTeam;
import java.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@ -38,7 +41,7 @@ public class Scoreboard {
if (sidebar == null) return;
// get
title = sidebar.getDisplayName().trim();
title = STRIP_COLOR_PATTERN.matcher(sidebar.getDisplayName().trim()).replaceAll("");
Collection<Score> scoreCollection = scoreboard.getSortedScores(sidebar);
List<Score> filteredScores = scoreCollection.stream().filter(input -> input.getPlayerName() != null && !input.getPlayerName().startsWith("#")).collect(Collectors.toList());
@ -106,7 +109,7 @@ public class Scoreboard {
default: return Optional.empty();
}
}
public static String getTitle() {
return title;
public static boolean isZombies() {
return ("ZOMBIES".equals(title));
}
}