From 1b628a647d6ab52c1cd024665ad985c7b8eb0b56 Mon Sep 17 00:00:00 2001 From: alemidev Date: Wed, 1 Feb 2023 00:33:13 +0100 Subject: feat: added initial infodisplay hud mod --- src/main/java/co/fantabos/bscv/BoSCoVicino.java | 2 + .../co/fantabos/bscv/module/hud/InfoDisplay.java | 134 +++++++++++++++++++++ 2 files changed, 136 insertions(+) create mode 100644 src/main/java/co/fantabos/bscv/module/hud/InfoDisplay.java (limited to 'src') 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 history_speed = new ArrayDeque<>(); + + public final ForgeConfigSpec.ConfigValue logo; + public final ForgeConfigSpec.ConfigValue speed; + public final ForgeConfigSpec.ConfigValue time; + // public final ForgeConfigSpec.ConfigValue fps; + // public final ForgeConfigSpec.ConfigValue biome; + // public final ForgeConfigSpec.ConfigValue latency; + // public final ForgeConfigSpec.ConfigValue tps; + // public final ForgeConfigSpec.ConfigValue light; + // public final ForgeConfigSpec.ConfigValue saturation; + // public final ForgeConfigSpec.ConfigValue system_time; + // public final ForgeConfigSpec.ConfigValue damage_value; + // public final ForgeConfigSpec.ConfigValue effects_list; + // public final ForgeConfigSpec.ConfigValue item_quantity; + // public final ForgeConfigSpec.ConfigValue client_chunk_size; + + public InfoDisplay(ForgeConfigSpec.Builder builder, CommandDispatcher 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; + } + } +} -- cgit v1.2.3-56-ga3b1