fixed config and added temp stat ui
This commit is contained in:
parent
d457dd82b4
commit
3ce1b6cc3a
@ -27,7 +27,7 @@ public class Main implements ModInitializer {
|
||||
@Getter private static final Config statisticsConfig;
|
||||
static {
|
||||
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.addon.Addon;
|
||||
import cc.fascinated.wildaddons.statistic.Statistic;
|
||||
import cc.fascinated.wildaddons.tpsmonitor.TpsMonitor;
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
@ -24,6 +25,13 @@ public class OverlayAddon extends Addon {
|
||||
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, "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.serialize.SerializationException;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.*;
|
||||
|
||||
@Getter @RequiredArgsConstructor
|
||||
public enum Statistic {
|
||||
@ -95,26 +92,14 @@ public enum Statistic {
|
||||
* @param node the configuration node to load from
|
||||
*/
|
||||
public static void loadStatistics(ConfigurationNode node) {
|
||||
try {
|
||||
List<String> keys = node.getList(String.class);
|
||||
if (keys == null) {
|
||||
return;
|
||||
}
|
||||
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);
|
||||
}
|
||||
for (Map.Entry<Object, ? extends ConfigurationNode> entry : node.childrenMap().entrySet()) {
|
||||
ConfigurationNode data = entry.getValue();
|
||||
String key = (String) data.key();
|
||||
int value = data.getInt();
|
||||
|
||||
} catch (SerializationException e) {
|
||||
throw new RuntimeException(e);
|
||||
statistics.put(Statistic.getStatisticFromKey(key), value);
|
||||
}
|
||||
Main.LOGGER.info("Loaded statistics.");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -123,7 +108,7 @@ public enum Statistic {
|
||||
* @param key the key to check against
|
||||
* @return the statistic if found, otherwise null
|
||||
*/
|
||||
public Statistic getStatisticFromKey(String key) {
|
||||
public static Statistic getStatisticFromKey(String key) {
|
||||
for (Statistic value : values()) {
|
||||
if (value.key.equalsIgnoreCase(key)) {
|
||||
return value;
|
||||
|
@ -37,8 +37,17 @@ public class Config {
|
||||
}
|
||||
}
|
||||
|
||||
configurationLoader = HoconConfigurationLoader.builder().file(file).prettyPrinting(true).build();
|
||||
node = configurationLoader.createNode(ConfigurationOptions.defaults());
|
||||
configurationLoader = HoconConfigurationLoader.builder()
|
||||
.file(file)
|
||||
.emitJsonCompatible(true)
|
||||
.emitComments(true)
|
||||
.prettyPrinting(true)
|
||||
.build();
|
||||
try {
|
||||
node = configurationLoader.load();
|
||||
} catch (ConfigurateException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user