From 8b81f50b33be4613c87db0d29600bad31d02b301 Mon Sep 17 00:00:00 2001 From: alemidev Date: Sun, 29 Jan 2023 05:04:20 +0100 Subject: [PATCH] feat: added HUD module to show coords and mods --- .../java/co/fantabos/bscv/modules/Hud.java | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 src/main/java/co/fantabos/bscv/modules/Hud.java diff --git a/src/main/java/co/fantabos/bscv/modules/Hud.java b/src/main/java/co/fantabos/bscv/modules/Hud.java new file mode 100644 index 0000000..4b54adf --- /dev/null +++ b/src/main/java/co/fantabos/bscv/modules/Hud.java @@ -0,0 +1,80 @@ +package co.fantabos.bscv.modules; + +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.arguments.BoolArgumentType; +import com.mojang.brigadier.arguments.IntegerArgumentType; + +import co.fantabos.bscv.BoSCoVicino; +import co.fantabos.bscv.Module; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.screen.ChatScreen; +import net.minecraft.command.CommandSource; +import net.minecraft.util.math.vector.Vector3d; +import net.minecraft.util.text.Color; +import net.minecraft.util.text.StringTextComponent; +import net.minecraft.util.text.Style; +import net.minecraft.util.text.TextComponent; +import net.minecraft.util.text.TextFormatting; +import net.minecraftforge.client.event.RenderGameOverlayEvent; +import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType; +import net.minecraftforge.common.ForgeConfigSpec; +import net.minecraftforge.eventbus.api.SubscribeEvent; + +public class Hud extends Module { + + private final ForgeConfigSpec.ConfigValue coordinates; + private final ForgeConfigSpec.ConfigValue activemods; + private final ForgeConfigSpec.ConfigValue size; + + public Hud(ForgeConfigSpec.Builder builder, CommandDispatcher dispatcher) { + super("Hud", Group.CORE, builder, dispatcher); + + this.coordinates = this.option( + "coords", "show coordinates on screen", true, + BoolArgumentType.bool(), Boolean.class, + builder, dispatcher + ); + + this.activemods = this.option( + "modules", "show active modules on screen", true, + BoolArgumentType.bool(), Boolean.class, + builder, dispatcher + ); + + this.size = this.option( + "size", "font size for text", 12, + IntegerArgumentType.integer(), Integer.class, + builder, dispatcher + ); + } + + @SubscribeEvent + public void onRenderOverlay(RenderGameOverlayEvent event) { + Minecraft mc = BoSCoVicino.minecraft; + if (event.getType() == ElementType.TEXT) { + if (this.coordinates.get() && BoSCoVicino.minecraft.player != null) { + Vector3d position = mc.player.getPosition(0.0f); + TextComponent text = new StringTextComponent(String.format("[ X %.1f | %.1f Z ] %.1f Y", position.x(), position.z(), position.y())); + text.setStyle(Style.EMPTY.withColor(Color.fromLegacyFormat(TextFormatting.WHITE))); + float height = 1.0f; + if (mc.screen != null && mc.screen instanceof ChatScreen) { + height = 16.0f; + } + mc.font.drawShadow(event.getMatrixStack(), text, 1.0f, (event.getWindow().getHeight() / 2) - (mc.font.lineHeight + height), this.size.get()); + } + + if (this.activemods.get()) { + float offset = 27.0f; + for (Module m : BoSCoVicino.mods) { + if (m.enabled.get()) { + TextComponent text = new StringTextComponent(String.format("%s <", m.name)); + text.setStyle(Style.EMPTY.withColor(Color.fromLegacyFormat(TextFormatting.WHITE))); + int textWidth = BoSCoVicino.minecraft.font.width(String.format("%s <", m.name)); + mc.font.drawShadow(event.getMatrixStack(), text, (event.getWindow().getWidth() / 2) - (textWidth + 1), offset, this.size.get()); + offset += mc.font.lineHeight; + } + } + } + } + } +}