fixed config and added temp stat ui

This commit is contained in:
Lee 2023-03-07 01:46:29 +00:00
parent d457dd82b4
commit 3ce1b6cc3a
4 changed files with 28 additions and 26 deletions

@ -27,7 +27,7 @@ public class Main implements ModInitializer {
@Getter private static final Config statisticsConfig; @Getter private static final Config statisticsConfig;
static { static {
String dirName = minecraftClient.runDirectory.getAbsolutePath() + File.separator + "wildaddons"; String dirName = minecraftClient.runDirectory.getAbsolutePath() + File.separator + "wildaddons";
statisticsConfig = new Config(dirName, "statistics.conf"); statisticsConfig = new Config(dirName, "statistics.json");
} }
/** /**

@ -2,6 +2,7 @@ package cc.fascinated.wildaddons.addon.impl.ui;
import cc.fascinated.wildaddons.Main; import cc.fascinated.wildaddons.Main;
import cc.fascinated.wildaddons.addon.Addon; import cc.fascinated.wildaddons.addon.Addon;
import cc.fascinated.wildaddons.statistic.Statistic;
import cc.fascinated.wildaddons.tpsmonitor.TpsMonitor; import cc.fascinated.wildaddons.tpsmonitor.TpsMonitor;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback; import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
@ -24,6 +25,13 @@ public class OverlayAddon extends Addon {
TextRenderer renderer = minecraftClient.textRenderer; TextRenderer renderer = minecraftClient.textRenderer;
renderer.drawWithShadow(matrixStack, "FPS: " + minecraftClient.getCurrentFps(), 5, 5, 0xffffff); renderer.drawWithShadow(matrixStack, "FPS: " + minecraftClient.getCurrentFps(), 5, 5, 0xffffff);
renderer.drawWithShadow(matrixStack, "TPS: " + TpsMonitor.getFormattedTPS(), 5, 16, 0xffffff); renderer.drawWithShadow(matrixStack, "TPS: " + TpsMonitor.getFormattedTPS(), 5, 16, 0xffffff);
renderer.drawWithShadow(matrixStack, "Statistics:", 5, 30, 0xffffff);
int lastY = 41;
for (Statistic statistic : Statistic.values()) {
renderer.drawWithShadow(matrixStack, statistic.name() + " - " + statistic.get(), 5, lastY, 0xffffff);
lastY += 11;
}
}); });
} }
} }

@ -8,10 +8,7 @@ import org.spongepowered.configurate.ConfigurateException;
import org.spongepowered.configurate.ConfigurationNode; import org.spongepowered.configurate.ConfigurationNode;
import org.spongepowered.configurate.serialize.SerializationException; import org.spongepowered.configurate.serialize.SerializationException;
import java.util.HashMap; import java.util.*;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
@Getter @RequiredArgsConstructor @Getter @RequiredArgsConstructor
public enum Statistic { public enum Statistic {
@ -95,26 +92,14 @@ public enum Statistic {
* @param node the configuration node to load from * @param node the configuration node to load from
*/ */
public static void loadStatistics(ConfigurationNode node) { public static void loadStatistics(ConfigurationNode node) {
try { for (Map.Entry<Object, ? extends ConfigurationNode> entry : node.childrenMap().entrySet()) {
List<String> keys = node.getList(String.class); ConfigurationNode data = entry.getValue();
if (keys == null) { String key = (String) data.key();
return; int value = data.getInt();
}
for (String key : keys) {
ConfigurationNode keyNode = node.node(key);
if (keyNode == null) {
continue;
}
Integer value = keyNode.get(Integer.class, 0);
if (value == null) {
continue;
}
statistics.put(Statistic.FILTERED_MESSAGES.getStatisticFromKey(key), value);
}
} catch (SerializationException e) { statistics.put(Statistic.getStatisticFromKey(key), value);
throw new RuntimeException(e);
} }
Main.LOGGER.info("Loaded statistics.");
} }
/** /**
@ -123,7 +108,7 @@ public enum Statistic {
* @param key the key to check against * @param key the key to check against
* @return the statistic if found, otherwise null * @return the statistic if found, otherwise null
*/ */
public Statistic getStatisticFromKey(String key) { public static Statistic getStatisticFromKey(String key) {
for (Statistic value : values()) { for (Statistic value : values()) {
if (value.key.equalsIgnoreCase(key)) { if (value.key.equalsIgnoreCase(key)) {
return value; return value;

@ -37,8 +37,17 @@ public class Config {
} }
} }
configurationLoader = HoconConfigurationLoader.builder().file(file).prettyPrinting(true).build(); configurationLoader = HoconConfigurationLoader.builder()
node = configurationLoader.createNode(ConfigurationOptions.defaults()); .file(file)
.emitJsonCompatible(true)
.emitComments(true)
.prettyPrinting(true)
.build();
try {
node = configurationLoader.load();
} catch (ConfigurateException e) {
throw new RuntimeException(e);
}
} }
/** /**