summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author alemidev <me@alemi.dev>2023-02-01 00:33:13 +0100
committer alemidev <me@alemi.dev>2023-02-01 00:33:13 +0100
commit1b628a647d6ab52c1cd024665ad985c7b8eb0b56 (patch)
tree27f4a2164c01ad9084e1c538f8537bc44d30edb1
parent80b08eb4d4d076377222afcb856a5e76e26bf71c (diff)
feat: added initial infodisplay hud mod
-rw-r--r--src/main/java/co/fantabos/bscv/BoSCoVicino.java2
-rw-r--r--src/main/java/co/fantabos/bscv/module/hud/InfoDisplay.java134
2 files changed, 136 insertions, 0 deletions
diff --git a/src/main/java/co/fantabos/bscv/BoSCoVicino.java b/src/main/java/co/fantabos/bscv/BoSCoVicino.java
index a7dfb55..bd0864c 100644
--- a/src/main/java/co/fantabos/bscv/BoSCoVicino.java
+++ b/src/main/java/co/fantabos/bscv/BoSCoVicino.java
@@ -72,6 +72,8 @@ public class BoSCoVicino {
builder.pop();
BoSCoVicino.mods.add(new FastInteract(builder, this.dispatcher));
builder.pop();
+ BoSCoVicino.mods.add(new InfoDisplay(builder, this.dispatcher));
+ builder.pop();
BoSCoVicino.mods.add(new Coordinates(builder, this.dispatcher));
builder.pop();
BoSCoVicino.mods.add(new EntityList(builder, this.dispatcher));
diff --git a/src/main/java/co/fantabos/bscv/module/hud/InfoDisplay.java b/src/main/java/co/fantabos/bscv/module/hud/InfoDisplay.java
new file mode 100644
index 0000000..a715a1a
--- /dev/null
+++ b/src/main/java/co/fantabos/bscv/module/hud/InfoDisplay.java
@@ -0,0 +1,134 @@
+package co.fantabos.bscv.module.hud;
+
+import static co.fantabos.bscv.tools.Text.TextBuilder;
+
+import java.util.ArrayDeque;
+
+import com.mojang.brigadier.CommandDispatcher;
+import com.mojang.brigadier.arguments.BoolArgumentType;
+
+import co.fantabos.bscv.BoSCoVicino;
+import co.fantabos.bscv.module.HudModule;
+import net.minecraft.client.Minecraft;
+import net.minecraft.command.CommandSource;
+import net.minecraft.util.math.vector.Vector3d;
+import net.minecraft.util.text.Color;
+import net.minecraft.util.text.Style;
+import net.minecraftforge.client.event.RenderGameOverlayEvent;
+import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
+import net.minecraftforge.common.ForgeConfigSpec;
+import net.minecraftforge.event.TickEvent;
+import net.minecraftforge.eventbus.api.SubscribeEvent;
+
+public class InfoDisplay extends HudModule {
+
+
+ private Vector3d last_position = new Vector3d(0.0, 0.0, 0.0);
+ private double instant_speed = 0.0;
+ private double average_speed = 0.0;
+ private ArrayDeque<Double> history_speed = new ArrayDeque<>();
+
+ public final ForgeConfigSpec.ConfigValue<Boolean> logo;
+ public final ForgeConfigSpec.ConfigValue<Boolean> speed;
+ public final ForgeConfigSpec.ConfigValue<Boolean> time;
+ // public final ForgeConfigSpec.ConfigValue<Boolean> fps;
+ // public final ForgeConfigSpec.ConfigValue<Boolean> biome;
+ // public final ForgeConfigSpec.ConfigValue<Boolean> latency;
+ // public final ForgeConfigSpec.ConfigValue<Boolean> tps;
+ // public final ForgeConfigSpec.ConfigValue<Boolean> light;
+ // public final ForgeConfigSpec.ConfigValue<Boolean> saturation;
+ // public final ForgeConfigSpec.ConfigValue<Boolean> system_time;
+ // public final ForgeConfigSpec.ConfigValue<Boolean> damage_value;
+ // public final ForgeConfigSpec.ConfigValue<Boolean> effects_list;
+ // public final ForgeConfigSpec.ConfigValue<Boolean> item_quantity;
+ // public final ForgeConfigSpec.ConfigValue<Boolean> client_chunk_size;
+
+ public InfoDisplay(ForgeConfigSpec.Builder builder, CommandDispatcher<CommandSource> dispatcher) {
+ super("InfoDisplay", builder, dispatcher);
+
+ this.logo = this.option(
+ "logo", "show logo at top of list", true,
+ BoolArgumentType.bool(), Boolean.class,
+ builder, dispatcher
+ );
+
+ this.speed = this.option(
+ "speed", "show speed meter", true,
+ BoolArgumentType.bool(), Boolean.class,
+ builder, dispatcher
+ );
+
+ this.time = this.option(
+ "time", "show world time", true,
+ BoolArgumentType.bool(), Boolean.class,
+ builder, dispatcher
+ );
+ }
+
+ @SubscribeEvent
+ public void onTick(TickEvent.ClientTickEvent event) {
+ if (!this.speed.get()) return;
+ if (BoSCoVicino.minecraft.player != null) {
+ this.instant_speed =
+ this.last_position.distanceTo(BoSCoVicino.minecraft.player.position());
+ this.last_position = BoSCoVicino.minecraft.player.position();
+ } else {
+ this.instant_speed = 0.0;
+ }
+
+ this.history_speed.push(this.instant_speed);
+ while (this.history_speed.size() >= 100) { // TODO customize this parameter
+ this.history_speed.pop();
+ }
+
+ double buf = 0.0;
+ for (double v : this.history_speed) { buf += v; }
+ this.average_speed = buf / this.history_speed.size();
+ }
+
+ @SubscribeEvent
+ public void onRenderOverlay(RenderGameOverlayEvent event) {
+ if (event.getType() != ElementType.TEXT) return;
+
+ Minecraft mc = BoSCoVicino.minecraft;
+ int offset = 0;
+ double scale = this.scale.get();
+ if (this.logo.get()) {
+ TextBuilder()
+ .txt("BSCV")
+ .anchor(this.anchor.get())
+ .x(this.x.get() / 4)
+ .y(this.y.get() / 4)
+ .style(Style.EMPTY.withColor(Color.fromRgb(12542314)).withBold(true))
+ .scale(scale * 4.0)
+ .render(event.getMatrixStack(), event.getWindow());
+ offset += mc.font.lineHeight * scale * 4.0;
+ }
+
+ if (this.time.get()) {
+ long daytime = 0;
+ if (mc.level != null) {
+ daytime = mc.level.dayTime();
+ }
+ TextBuilder()
+ .txt(String.format("> time: %d/1200 (%d day)", (daytime / 20) % 1200, daytime / (20 * 1200) ))
+ .anchor(this.anchor.get())
+ .x(this.x.get())
+ .y(this.y.get() + offset)
+ .scale(scale)
+ .render(event.getMatrixStack(), event.getWindow());
+ offset += mc.font.lineHeight * scale;
+ }
+
+ if (this.speed.get()) {
+ TextBuilder()
+ .txt(String.format("> speed: %.1f [%.1f] m/s", this.instant_speed * 20.0, this.average_speed * 20.0))
+ .anchor(this.anchor.get())
+ .x(this.x.get())
+ .y(this.y.get() + offset)
+ .scale(scale)
+ .render(event.getMatrixStack(), event.getWindow());
+ offset += mc.font.lineHeight * scale;
+ }
+ }
+}