From 576d86408ccbcf9c85f8b1829d1193c0484a4a18 Mon Sep 17 00:00:00 2001 From: liam Date: Tue, 7 Mar 2023 23:28:48 +0000 Subject: [PATCH] added more info to the overlay and changed many things --- .../java/cc/fascinated/wildaddons/Main.java | 10 +-- .../addon/impl/chat/AutoWelcomerAddon.java | 2 + .../addon/impl/ui/OverlayAddon.java | 62 ++++++++++++++-- .../wildaddons/client/WildAddonsClient.java | 16 ++-- .../wildaddons/event/EventListener.java | 16 +++- .../listener/ActivePotionsListener.java | 37 ++++++++++ .../wildaddons/listener/ArmorListener.java | 73 +++++++++++++++++++ .../wildaddons/listener/PlayerListener.java | 2 +- .../listener/ResearchTasksListener.java | 40 ++++++++++ .../mixin/MinecraftClientMixin.java | 8 +- .../wildaddons/mixin/PlayerListGuiMixin.java | 46 ++++++++++++ .../wildaddons/statistic/Statistic.java | 14 +++- .../wildaddons/tpsmonitor/TpsMonitor.java | 14 +++- .../fascinated/wildaddons/utils/Config.java | 2 - .../wildaddons/utils/GameUtils.java | 31 ++++++++ .../wildaddons/utils/NumberUtils.java | 14 +++- .../wildaddons/utils/PlayerUtils.java | 13 ++++ .../wildaddons/utils/TextUtils.java | 12 ++- src/main/resources/fabric.mod.json | 2 +- ...ons.mixins.json => wildaddons.mixins.json} | 6 +- 20 files changed, 382 insertions(+), 38 deletions(-) create mode 100644 src/main/java/cc/fascinated/wildaddons/listener/ActivePotionsListener.java create mode 100644 src/main/java/cc/fascinated/wildaddons/listener/ArmorListener.java create mode 100644 src/main/java/cc/fascinated/wildaddons/listener/ResearchTasksListener.java create mode 100644 src/main/java/cc/fascinated/wildaddons/mixin/PlayerListGuiMixin.java create mode 100644 src/main/java/cc/fascinated/wildaddons/utils/GameUtils.java rename src/main/resources/{WildAddons.mixins.json => wildaddons.mixins.json} (77%) diff --git a/src/main/java/cc/fascinated/wildaddons/Main.java b/src/main/java/cc/fascinated/wildaddons/Main.java index 1246054..a66851e 100644 --- a/src/main/java/cc/fascinated/wildaddons/Main.java +++ b/src/main/java/cc/fascinated/wildaddons/Main.java @@ -1,20 +1,15 @@ package cc.fascinated.wildaddons; import cc.fascinated.wildaddons.utils.Config; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; import lombok.Getter; import net.fabricmc.api.ModInitializer; import net.minecraft.client.MinecraftClient; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.spongepowered.configurate.CommentedConfigurationNode; -import org.spongepowered.configurate.ConfigurationNode; -import org.spongepowered.configurate.ConfigurationOptions; -import org.spongepowered.configurate.hocon.HoconConfigurationLoader; -import org.spongepowered.configurate.loader.ConfigurationLoader; -import org.spongepowered.configurate.serialize.SerializationException; import java.io.File; -import java.nio.file.Path; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -23,6 +18,7 @@ public class Main implements ModInitializer { public static final Logger LOGGER = LogManager.getLogger(Main.class); @Getter private static final ExecutorService executorService = Executors.newCachedThreadPool(); @Getter private static final MinecraftClient minecraftClient = MinecraftClient.getInstance(); + @Getter private static final Gson gson = new GsonBuilder().create(); @Getter private static final Config statisticsConfig; static { diff --git a/src/main/java/cc/fascinated/wildaddons/addon/impl/chat/AutoWelcomerAddon.java b/src/main/java/cc/fascinated/wildaddons/addon/impl/chat/AutoWelcomerAddon.java index 016d7f5..c073ae0 100644 --- a/src/main/java/cc/fascinated/wildaddons/addon/impl/chat/AutoWelcomerAddon.java +++ b/src/main/java/cc/fascinated/wildaddons/addon/impl/chat/AutoWelcomerAddon.java @@ -16,6 +16,8 @@ public class AutoWelcomerAddon extends Addon { "Automatically sends the welcome command when a new player joins.", Category.CHAT ); + + // TODO: actually check if we got the gem for welcoming } @Override diff --git a/src/main/java/cc/fascinated/wildaddons/addon/impl/ui/OverlayAddon.java b/src/main/java/cc/fascinated/wildaddons/addon/impl/ui/OverlayAddon.java index 973124d..9f5991f 100644 --- a/src/main/java/cc/fascinated/wildaddons/addon/impl/ui/OverlayAddon.java +++ b/src/main/java/cc/fascinated/wildaddons/addon/impl/ui/OverlayAddon.java @@ -2,12 +2,24 @@ package cc.fascinated.wildaddons.addon.impl.ui; import cc.fascinated.wildaddons.Main; import cc.fascinated.wildaddons.addon.Addon; +import cc.fascinated.wildaddons.listener.ActivePotionsListener; +import cc.fascinated.wildaddons.listener.ArmorListener; +import cc.fascinated.wildaddons.listener.PlayerListener; +import cc.fascinated.wildaddons.listener.ResearchTasksListener; import cc.fascinated.wildaddons.statistic.Statistic; import cc.fascinated.wildaddons.tpsmonitor.TpsMonitor; +import cc.fascinated.wildaddons.utils.GameUtils; +import cc.fascinated.wildaddons.utils.NumberUtils; +import cc.fascinated.wildaddons.utils.PlayerUtils; +import lombok.Getter; import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback; import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; +import java.util.LinkedHashSet; +import java.util.Map; +import java.util.Set; + public class OverlayAddon extends Addon { public OverlayAddon() { @@ -20,18 +32,58 @@ public class OverlayAddon extends Addon { if (!this.isEnabled()) { return; } + int lastY = 5; MinecraftClient minecraftClient = Main.getMinecraftClient(); TextRenderer renderer = minecraftClient.textRenderer; - renderer.drawWithShadow(matrixStack, "FPS: " + minecraftClient.getCurrentFps(), 5, 5, 0xffffff); - renderer.drawWithShadow(matrixStack, "TPS: " + TpsMonitor.getFormattedTPS(), 5, 16, 0xffffff); + renderer.drawWithShadow(matrixStack, "FPS: " + GameUtils.getFpsFormatted(), 5, lastY, 0xffffff); + lastY += 11; + renderer.drawWithShadow(matrixStack, "TPS: " + TpsMonitor.getFormattedTPS(), 5, lastY, 0xffffff); + if (!PlayerUtils.isOnWild()) { + return; + } + lastY += 11; + renderer.drawWithShadow(matrixStack, "IP: " + PlayerUtils.getCurrentServerIp(), 5, lastY, 0xffffff); + lastY += 11; + renderer.drawWithShadow(matrixStack, "Is Afk: " + !PlayerListener.isMoving(), 5, lastY, 0xffffff); + lastY += 13; - renderer.drawWithShadow(matrixStack, "Statistics:", 5, 30, 0xffffff); - int lastY = 41; + renderer.drawWithShadow(matrixStack, "§7§nStatistics:", 5, lastY, 0xffffff); + lastY += 11; for (Statistic statistic : Statistic.values()) { - renderer.drawWithShadow(matrixStack, statistic.name() + " - " + statistic.get(), 5, lastY, 0xffffff); + renderer.drawWithShadow(matrixStack, "§e" + statistic.getName() + " §f- §a" + NumberUtils.format(statistic.get(), true), 5, lastY, 0xffffff); lastY += 11; } + + if (ResearchTasksListener.getResearchTasks().size() > 0) { + lastY += 3; + renderer.drawWithShadow(matrixStack, "§7§nResearch Tasks:", 5, lastY, 0xffffff); + lastY += 11; + for (String task : ResearchTasksListener.getResearchTasks()) { + renderer.drawWithShadow(matrixStack, task, 5, lastY, 0xffffff); + lastY += 11; + } + } + + if (ActivePotionsListener.getActivePotions().size() > 0) { + lastY += 3; + renderer.drawWithShadow(matrixStack, "§7§nActive Potions:", 5, lastY, 0xffffff); + lastY += 11; + for (String task : ActivePotionsListener.getActivePotions()) { + renderer.drawWithShadow(matrixStack, task, 5, lastY, 0xffffff); + lastY += 11; + } + } + + if (ActivePotionsListener.getActivePotions().size() > 0) { + lastY += 3; + renderer.drawWithShadow(matrixStack, "§7§nArmor Multipliers:", 5, lastY, 0xffffff); + lastY += 11; + for (Map.Entry entry : ArmorListener.getArmorMultipliers().entrySet()) { + renderer.drawWithShadow(matrixStack, "§e" + entry.getKey() + " §f- §a" + entry.getValue() + "x", 5, lastY, 0xffffff); + lastY += 11; + } + } }); } } diff --git a/src/main/java/cc/fascinated/wildaddons/client/WildAddonsClient.java b/src/main/java/cc/fascinated/wildaddons/client/WildAddonsClient.java index d2404c4..cdaf1a0 100644 --- a/src/main/java/cc/fascinated/wildaddons/client/WildAddonsClient.java +++ b/src/main/java/cc/fascinated/wildaddons/client/WildAddonsClient.java @@ -3,20 +3,13 @@ package cc.fascinated.wildaddons.client; import cc.fascinated.wildaddons.Main; import cc.fascinated.wildaddons.addon.AddonManager; import cc.fascinated.wildaddons.event.EventManager; +import cc.fascinated.wildaddons.listener.ActivePotionsListener; +import cc.fascinated.wildaddons.listener.ArmorListener; import cc.fascinated.wildaddons.listener.PlayerListener; +import cc.fascinated.wildaddons.listener.ResearchTasksListener; import cc.fascinated.wildaddons.statistic.Statistic; import cc.fascinated.wildaddons.tpsmonitor.TpsMonitor; import net.fabricmc.api.ClientModInitializer; -import org.spongepowered.configurate.CommentedConfigurationNode; -import org.spongepowered.configurate.ConfigurateException; -import org.spongepowered.configurate.ConfigurationNode; -import org.spongepowered.configurate.ConfigurationOptions; -import org.spongepowered.configurate.hocon.HoconConfigurationLoader; -import org.spongepowered.configurate.loader.ConfigurationLoader; -import org.spongepowered.configurate.serialize.SerializationException; - -import java.io.File; -import java.io.IOException; public class WildAddonsClient implements ClientModInitializer { @@ -32,5 +25,8 @@ public class WildAddonsClient implements ClientModInitializer { EventManager.registerListener(new PlayerListener()); EventManager.registerListener(new TpsMonitor()); + EventManager.registerListener(new ArmorListener()); + EventManager.registerListener(new ResearchTasksListener()); + EventManager.registerListener(new ActivePotionsListener()); } } diff --git a/src/main/java/cc/fascinated/wildaddons/event/EventListener.java b/src/main/java/cc/fascinated/wildaddons/event/EventListener.java index 8ff227a..e19d45f 100644 --- a/src/main/java/cc/fascinated/wildaddons/event/EventListener.java +++ b/src/main/java/cc/fascinated/wildaddons/event/EventListener.java @@ -1,11 +1,17 @@ package cc.fascinated.wildaddons.event; import net.minecraft.network.Packet; +import net.minecraft.text.Text; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; public interface EventListener { - default void onTick() {} + /** + * Gets called every game tick + * + * @param ticksPassed the total amount of ticks passed + */ + default void onTick(int ticksPassed) {} /** * Gets called when a chat message is received @@ -28,4 +34,12 @@ public interface EventListener { * @param packet the packet */ default void onPacketSend(Packet packet) {} + + /** + * Gets called every time the tab-list updates. + * + * @param header the header + * @param footer the footer + */ + default void onTabListUpdate(Text header, Text footer) {} } diff --git a/src/main/java/cc/fascinated/wildaddons/listener/ActivePotionsListener.java b/src/main/java/cc/fascinated/wildaddons/listener/ActivePotionsListener.java new file mode 100644 index 0000000..aa27567 --- /dev/null +++ b/src/main/java/cc/fascinated/wildaddons/listener/ActivePotionsListener.java @@ -0,0 +1,37 @@ +package cc.fascinated.wildaddons.listener; + +import cc.fascinated.wildaddons.event.EventListener; +import cc.fascinated.wildaddons.utils.TextUtils; +import lombok.Getter; +import net.minecraft.text.Text; + +import java.util.LinkedHashSet; +import java.util.Set; + +public class ActivePotionsListener implements EventListener { + + @Getter private static final Set activePotions = new LinkedHashSet<>(); + + @Override + public void onTabListUpdate(Text header, Text footer) { + String footerString = footer.getString(); + String[] lines = footerString.split("\n"); + + activePotions.clear(); + boolean found = false; + for (String part : lines) { + String partStripped = TextUtils.stripColors(part); + if (partStripped.contains("POTION BUFFS")) { + found = true; + continue; + } + if (!found) { + continue; + } + if (partStripped.isEmpty()) { // Don't overflow into other data + break; + } + activePotions.add(TextUtils.removeColorCode(part, "§o")); + } + } +} diff --git a/src/main/java/cc/fascinated/wildaddons/listener/ArmorListener.java b/src/main/java/cc/fascinated/wildaddons/listener/ArmorListener.java new file mode 100644 index 0000000..31e87eb --- /dev/null +++ b/src/main/java/cc/fascinated/wildaddons/listener/ArmorListener.java @@ -0,0 +1,73 @@ +package cc.fascinated.wildaddons.listener; + +import cc.fascinated.wildaddons.Main; +import cc.fascinated.wildaddons.event.EventListener; +import lombok.Getter; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.item.TooltipContext; +import net.minecraft.client.network.ClientPlayerEntity; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.nbt.NbtElement; +import net.minecraft.text.Text; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class ArmorListener implements EventListener { + + /** + * The current multipliers from armor + */ + @Getter private static Map armorMultipliers = new HashMap<>(); + + @Override + public void onTick(int ticksPassed) { // TODO: move to its own thread + if (ticksPassed % 20 != 0) { + return; + } + + MinecraftClient client = Main.getMinecraftClient(); + ClientPlayerEntity player = client.player; + if (player == null) { + return; + } + armorMultipliers.clear(); + PlayerInventory inventory = player.getInventory(); + for (ItemStack stack : inventory.armor) { + if (stack == null) { + continue; + } + Text name = stack.getName(); + if (name == null) { + return; + } + NbtCompound nbt = stack.getNbt(); + if (nbt == null) { + continue; + } + NbtElement armourTypeNbt = nbt.get("armor-piece"); + if (armourTypeNbt == null) { + continue; + } + List tooltip = stack.getTooltip(player, TooltipContext.ADVANCED); + for (int i = 10; i < tooltip.size(); i++) { + Text text = tooltip.get(i); + + String string = text.getString(); + if (string.isEmpty()) { + break; + } + String[] parts = string.split(" "); + double amount = Double.parseDouble(parts[0].replace("x", "")); + String boostName = parts[3]; + double oldAmount = armorMultipliers.computeIfAbsent(boostName, (e) -> 0.0D); + oldAmount+=amount; + + armorMultipliers.put(boostName, oldAmount); + } + } + } +} diff --git a/src/main/java/cc/fascinated/wildaddons/listener/PlayerListener.java b/src/main/java/cc/fascinated/wildaddons/listener/PlayerListener.java index cc9bb89..897ec68 100644 --- a/src/main/java/cc/fascinated/wildaddons/listener/PlayerListener.java +++ b/src/main/java/cc/fascinated/wildaddons/listener/PlayerListener.java @@ -13,7 +13,7 @@ public class PlayerListener implements EventListener { private static long lastMovement; @Override - public void onTick() { + public void onTick(int ticksPassed) { if (!PlayerUtils.isOnWild()) { // Ignore if the player isn't on Wild return; } diff --git a/src/main/java/cc/fascinated/wildaddons/listener/ResearchTasksListener.java b/src/main/java/cc/fascinated/wildaddons/listener/ResearchTasksListener.java new file mode 100644 index 0000000..ed7d5ff --- /dev/null +++ b/src/main/java/cc/fascinated/wildaddons/listener/ResearchTasksListener.java @@ -0,0 +1,40 @@ +package cc.fascinated.wildaddons.listener; + +import cc.fascinated.wildaddons.Main; +import cc.fascinated.wildaddons.event.EventListener; +import cc.fascinated.wildaddons.utils.PlayerUtils; +import cc.fascinated.wildaddons.utils.TextUtils; +import lombok.Getter; +import net.minecraft.client.network.ClientPlayerEntity; +import net.minecraft.text.Text; + +import java.util.LinkedHashSet; +import java.util.Set; + +public class ResearchTasksListener implements EventListener { + + @Getter private static final Set researchTasks = new LinkedHashSet<>(); + + @Override + public void onTabListUpdate(Text header, Text footer) { + String footerString = footer.getString(); + String[] lines = footerString.split("\n"); + + researchTasks.clear(); + boolean found = false; + for (String part : lines) { + String partStripped = TextUtils.stripColors(part); + if (partStripped.contains("RESEARCH TASKS")) { + found = true; + continue; + } + if (!found) { + continue; + } + if (partStripped.isEmpty()) { // Don't overflow into other data + break; + } + researchTasks.add(TextUtils.removeColorCode(part, "§o")); + } + } +} diff --git a/src/main/java/cc/fascinated/wildaddons/mixin/MinecraftClientMixin.java b/src/main/java/cc/fascinated/wildaddons/mixin/MinecraftClientMixin.java index 679bc65..c25c04d 100644 --- a/src/main/java/cc/fascinated/wildaddons/mixin/MinecraftClientMixin.java +++ b/src/main/java/cc/fascinated/wildaddons/mixin/MinecraftClientMixin.java @@ -13,8 +13,14 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(MinecraftClient.class) public class MinecraftClientMixin { + /** + * The total amount of ticks since mod initialization + */ + private int ticksPassed = 0; + @Inject(method = "tick", at = @At("HEAD")) public void onTick(CallbackInfo ci) { + ticksPassed++; if (!PlayerUtils.isOnWild()) { // Ignore if the player isn't on Wild return; } @@ -22,7 +28,7 @@ public class MinecraftClientMixin { return; } for (EventListener listener : EventManager.getListeners()) { - listener.onTick(); + listener.onTick(ticksPassed); } } } diff --git a/src/main/java/cc/fascinated/wildaddons/mixin/PlayerListGuiMixin.java b/src/main/java/cc/fascinated/wildaddons/mixin/PlayerListGuiMixin.java new file mode 100644 index 0000000..3c60f11 --- /dev/null +++ b/src/main/java/cc/fascinated/wildaddons/mixin/PlayerListGuiMixin.java @@ -0,0 +1,46 @@ +package cc.fascinated.wildaddons.mixin; + +import cc.fascinated.wildaddons.addon.impl.ui.OverlayAddon; +import cc.fascinated.wildaddons.event.EventListener; +import cc.fascinated.wildaddons.event.EventManager; +import cc.fascinated.wildaddons.utils.TextUtils; +import net.minecraft.client.gui.hud.PlayerListHud; +import net.minecraft.text.Text; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + + +@Mixin(PlayerListHud.class) +public class PlayerListGuiMixin { + + private Text header; + private Text footer; + + @Inject(method = "setHeader", at = @At(value = "HEAD")) + public void setHeader(Text header, CallbackInfo ci) { + this.header = header; + + update(); + } + + @Inject(method = "setFooter", at = @At(value = "HEAD")) + public void setFooter(Text footer, CallbackInfo ci) { + this.footer = footer; + + update(); + } + + /** + * Send out to listeners that the tab-list has changed. + */ + private void update() { + if (header == null || footer == null) { + return; + } + for (EventListener listener : EventManager.getListeners()) { + listener.onTabListUpdate(header, footer); + } + } +} diff --git a/src/main/java/cc/fascinated/wildaddons/statistic/Statistic.java b/src/main/java/cc/fascinated/wildaddons/statistic/Statistic.java index 10776bf..e78b556 100644 --- a/src/main/java/cc/fascinated/wildaddons/statistic/Statistic.java +++ b/src/main/java/cc/fascinated/wildaddons/statistic/Statistic.java @@ -8,13 +8,16 @@ import org.spongepowered.configurate.ConfigurateException; import org.spongepowered.configurate.ConfigurationNode; import org.spongepowered.configurate.serialize.SerializationException; -import java.util.*; +import java.util.HashMap; +import java.util.Map; +import java.util.Timer; +import java.util.TimerTask; @Getter @RequiredArgsConstructor public enum Statistic { - PLAYERS_WELCOMED("players-welcomed"), - FILTERED_MESSAGES("filtered-messages"); + PLAYERS_WELCOMED("Players Welcomed", "players-welcomed"), + FILTERED_MESSAGES("Filtered Messages","filtered-messages"); /** * The in memory storage for all statistics @@ -26,6 +29,11 @@ public enum Statistic { */ private static boolean dirty; + /** + * The display name for the statistic + */ + private final String name; + /** * The key used in the storage */ diff --git a/src/main/java/cc/fascinated/wildaddons/tpsmonitor/TpsMonitor.java b/src/main/java/cc/fascinated/wildaddons/tpsmonitor/TpsMonitor.java index 91aceaa..8305bba 100644 --- a/src/main/java/cc/fascinated/wildaddons/tpsmonitor/TpsMonitor.java +++ b/src/main/java/cc/fascinated/wildaddons/tpsmonitor/TpsMonitor.java @@ -13,7 +13,7 @@ public class TpsMonitor implements EventListener { private static long worldTicks = 0; @Override - public void onPacketReceive(Packet packet) { + public void onPacketReceive(Packet packet) { // TODO: move to its own thread? if (!(packet instanceof WorldTimeUpdateS2CPacket)) { return; } @@ -51,6 +51,16 @@ public class TpsMonitor implements EventListener { public static String getFormattedTPS() { float tps = Math.max(calculateServerTPS(), 0); - return tps > 20.00 ? "20.00*" : NumberUtils.format(tps); + String tpsFormatted = tps > 20.00 ? "20.00*" : NumberUtils.format(tps); + if (tps > 18) { + tpsFormatted = "§a" + tpsFormatted; + } else if (tps > 15) { + tpsFormatted = "§e" + tpsFormatted; + } else if (tps > 10) { + tpsFormatted = "§c" + tpsFormatted; + } else { + tpsFormatted = "§4" + tpsFormatted; + } + return tpsFormatted; } } diff --git a/src/main/java/cc/fascinated/wildaddons/utils/Config.java b/src/main/java/cc/fascinated/wildaddons/utils/Config.java index b9d19e5..94a00f9 100644 --- a/src/main/java/cc/fascinated/wildaddons/utils/Config.java +++ b/src/main/java/cc/fascinated/wildaddons/utils/Config.java @@ -1,11 +1,9 @@ package cc.fascinated.wildaddons.utils; -import cc.fascinated.wildaddons.Main; import lombok.Getter; import org.spongepowered.configurate.CommentedConfigurationNode; import org.spongepowered.configurate.ConfigurateException; import org.spongepowered.configurate.ConfigurationNode; -import org.spongepowered.configurate.ConfigurationOptions; import org.spongepowered.configurate.hocon.HoconConfigurationLoader; import org.spongepowered.configurate.loader.ConfigurationLoader; diff --git a/src/main/java/cc/fascinated/wildaddons/utils/GameUtils.java b/src/main/java/cc/fascinated/wildaddons/utils/GameUtils.java new file mode 100644 index 0000000..735908b --- /dev/null +++ b/src/main/java/cc/fascinated/wildaddons/utils/GameUtils.java @@ -0,0 +1,31 @@ +package cc.fascinated.wildaddons.utils; + +import cc.fascinated.wildaddons.Main; + +public class GameUtils { + + /** + * Gets the current fps + * + * @return the fps + */ + public static int getFps() { + return Main.getMinecraftClient().getCurrentFps(); + } + + /** + * Gets the current fps formatted with colors + * + * @return the fps + */ + public static String getFpsFormatted() { + int fps = getFps(); + if (fps > 60) { + return "§a" + fps; + } + if (fps > 30) { + return "§e" + fps; + } + return "§c" + fps; + } +} diff --git a/src/main/java/cc/fascinated/wildaddons/utils/NumberUtils.java b/src/main/java/cc/fascinated/wildaddons/utils/NumberUtils.java index b79fd06..ad67507 100644 --- a/src/main/java/cc/fascinated/wildaddons/utils/NumberUtils.java +++ b/src/main/java/cc/fascinated/wildaddons/utils/NumberUtils.java @@ -5,11 +5,23 @@ import java.text.DecimalFormat; public class NumberUtils { private static final DecimalFormat formatter = new DecimalFormat("##.##"); + private static final DecimalFormat commaFormatter = new DecimalFormat("#,###"); static { formatter.setMinimumFractionDigits(2); formatter.setMaximumFractionDigits(2); } + /** + * Formats the given number. + * + * @param number the number to format + * @param withCommas use commas + * @return the formatted number + */ + public static String format(Object number, boolean withCommas) { + return withCommas ? commaFormatter.format(number) : formatter.format(number); + } + /** * Formats the given number. * @@ -17,6 +29,6 @@ public class NumberUtils { * @return the formatted number */ public static String format(Object number) { - return formatter.format(number); + return format(number, false); } } diff --git a/src/main/java/cc/fascinated/wildaddons/utils/PlayerUtils.java b/src/main/java/cc/fascinated/wildaddons/utils/PlayerUtils.java index bf31b60..2abd182 100644 --- a/src/main/java/cc/fascinated/wildaddons/utils/PlayerUtils.java +++ b/src/main/java/cc/fascinated/wildaddons/utils/PlayerUtils.java @@ -42,4 +42,17 @@ public class PlayerUtils { public static boolean isOnWild() { return onServer("wildprison.net", "wildnetwork.net"); } + + /** + * Gets the current servers ip + * + * @return the ip + */ + public static String getCurrentServerIp() { + ServerInfo currentServerEntry = Main.getMinecraftClient().getCurrentServerEntry(); + if (currentServerEntry == null) { + return null; + } + return currentServerEntry.address; + } } diff --git a/src/main/java/cc/fascinated/wildaddons/utils/TextUtils.java b/src/main/java/cc/fascinated/wildaddons/utils/TextUtils.java index 97f515f..bf2e019 100644 --- a/src/main/java/cc/fascinated/wildaddons/utils/TextUtils.java +++ b/src/main/java/cc/fascinated/wildaddons/utils/TextUtils.java @@ -9,6 +9,16 @@ public class TextUtils { * @return the stripped string */ public static String stripColors(String message) { - return message.replaceAll("(?i)§[0-9A-FK-OR]/g", ""); + return message.replaceAll("§.", ""); + } + + /** + * Removes the given color code from the message + * + * @param message the message to modify + * @return the changed message + */ + public static String removeColorCode(String message, String colorCode) { + return message.replaceAll(colorCode, ""); } } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 8cf58ef..791f980 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -19,7 +19,7 @@ ] }, "mixins": [ - "WildAddons.mixins.json" + "wildaddons.mixins.json" ], "depends": { "fabricloader": ">=0.14.17", diff --git a/src/main/resources/WildAddons.mixins.json b/src/main/resources/wildaddons.mixins.json similarity index 77% rename from src/main/resources/WildAddons.mixins.json rename to src/main/resources/wildaddons.mixins.json index de81d2b..57cbb30 100644 --- a/src/main/resources/WildAddons.mixins.json +++ b/src/main/resources/wildaddons.mixins.json @@ -6,10 +6,10 @@ "mixins": [ "ChatHudMixin", "ClientConnectionMixin", - "MinecraftClientMixin" - ], - "client": [ + "MinecraftClientMixin", + "PlayerListGuiMixin" ], + "client": [], "injectors": { "defaultRequire": 1 }