summaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
author alemidev <me@alemi.dev>2023-01-30 02:19:39 +0100
committer alemidev <me@alemi.dev>2023-01-30 02:19:39 +0100
commit2aa64795f5bf196429e9ca729b0717c40b77d432 (patch)
tree9c34aad4c0bfe162725bd10e5ac30db693818814 /src/main/java
parent52c5b2d205812f8c3033ce31d212f6ef4a9f4d9a (diff)
fix: improved and fixed Align and Text utils
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/co/fantabos/bscv/modules/Hud.java88
-rw-r--r--src/main/java/co/fantabos/bscv/tools/Align.java37
-rw-r--r--src/main/java/co/fantabos/bscv/tools/Anchor.java50
-rw-r--r--src/main/java/co/fantabos/bscv/tools/Text.java11
4 files changed, 58 insertions, 128 deletions
diff --git a/src/main/java/co/fantabos/bscv/modules/Hud.java b/src/main/java/co/fantabos/bscv/modules/Hud.java
deleted file mode 100644
index d82b5ec..0000000
--- a/src/main/java/co/fantabos/bscv/modules/Hud.java
+++ /dev/null
@@ -1,88 +0,0 @@
-package co.fantabos.bscv.modules;
-
-import static co.fantabos.bscv.tools.Text.TextBuilder;
-
-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 co.fantabos.bscv.tools.Align.Anchor;
-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<Boolean> coordinates;
- private final ForgeConfigSpec.ConfigValue<Boolean> activemods;
- private final ForgeConfigSpec.ConfigValue<Integer> size;
-
- public Hud(ForgeConfigSpec.Builder builder, CommandDispatcher<CommandSource> dispatcher) {
- super("Hud", Group.HUD, 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) {
- float height = 1.0f;
- if (mc.screen != null && mc.screen instanceof ChatScreen) {
- height = 16.0f;
- }
- Vector3d position = mc.player.position();
- TextBuilder()
- .txt(String.format("[ X %.1f | %.1f Z ] %.1f Y", position.x(), position.z(), position.y()))
- .anchor(Anchor.BOTTOMLEFT)
- .x(1.0f)
- .y(height)
- .render(event.getMatrixStack(), event.getWindow());
- }
-
- if (this.activemods.get()) {
- float offset = 27.0f;
- for (Module m : BoSCoVicino.mods) {
- if (m.enabled.get()) {
- TextBuilder()
- .txt(String.format("%s <", m.name))
- .anchor(Anchor.BOTTOMLEFT)
- .x(1.0f)
- .y(offset)
- .render(event.getMatrixStack(), event.getWindow());
- offset += mc.font.lineHeight;
- }
- }
- }
- }
- }
-}
diff --git a/src/main/java/co/fantabos/bscv/tools/Align.java b/src/main/java/co/fantabos/bscv/tools/Align.java
deleted file mode 100644
index 495f214..0000000
--- a/src/main/java/co/fantabos/bscv/tools/Align.java
+++ /dev/null
@@ -1,37 +0,0 @@
-package co.fantabos.bscv.tools;
-
-import net.minecraft.client.MainWindow;
-import net.minecraft.util.math.vector.Vector2f;
-
-public final class Align {
- public enum Anchor {
- TOPLEFT, TOPCENTER, TOPRIGHT,
- MIDDLELEFT, MIDDLECENTER, MIDDLERIGHT,
- BOTTOMLEFT, BOTTOMCENTER, BOTTOMRIGHT
- }
-
- public static Vector2f translate(Anchor anchor, MainWindow window, Vector2f in) {
- switch (anchor) {
- case TOPLEFT:
- return new Vector2f(in.x, in.y);
- case TOPCENTER:
- return new Vector2f((window.getWidth()/4.0f) + in.x, in.y);
- case TOPRIGHT:
- return new Vector2f((window.getWidth()/2.0f) - in.x, in.y);
- case MIDDLELEFT:
- return new Vector2f(in.x, (window.getHeight()/4.0f) + in.y);
- case MIDDLECENTER:
- return new Vector2f((window.getWidth()/4.0f) + in.x, (window.getHeight()/4.0f) + in.y);
- case MIDDLERIGHT:
- return new Vector2f((window.getWidth()/2.0f) - in.x, (window.getHeight()/4.0f) + in.y);
- case BOTTOMLEFT:
- return new Vector2f(in.x, (window.getHeight()/2.0f) - in.y);
- case BOTTOMCENTER:
- return new Vector2f((window.getWidth()/4.0f) + in.x, (window.getHeight()/2.0f) - in.y);
- case BOTTOMRIGHT:
- return new Vector2f((window.getWidth()/2.0f) - in.x, (window.getHeight()/2.0f) - in.y);
- default:
- return new Vector2f(0.0f, 0.0f);
- }
- }
-}
diff --git a/src/main/java/co/fantabos/bscv/tools/Anchor.java b/src/main/java/co/fantabos/bscv/tools/Anchor.java
new file mode 100644
index 0000000..2e5e8af
--- /dev/null
+++ b/src/main/java/co/fantabos/bscv/tools/Anchor.java
@@ -0,0 +1,50 @@
+package co.fantabos.bscv.tools;
+
+import co.fantabos.bscv.BoSCoVicino;
+import net.minecraft.client.MainWindow;
+import net.minecraft.client.gui.screen.ChatScreen;
+import net.minecraft.util.math.vector.Vector2f;
+
+public enum Anchor {
+
+ TOPLEFT("TOPLEFT"), TOPCENTER("TOPCENTER"), TOPRIGHT("TOPRIGHT"),
+ MIDDLELEFT("MIDDLELEFT"), MIDDLECENTER("MIDDLECENTER"), MIDDLERIGHT("MIDDLERIGHT"),
+ BOTTOMLEFT("BOTTOMLEFT"), BOTTOMCENTER("BOTTOMCENTER"), BOTTOMRIGHT("BOTTOMRIGHT");
+
+ private Anchor(String in) { }
+
+ public Vector2f translate(Vector2f in, int textWidth, int lineHeight, MainWindow window) {
+ int offset = 0;
+ switch (this) {
+ case BOTTOMLEFT:
+ case BOTTOMCENTER:
+ case BOTTOMRIGHT:
+ if (BoSCoVicino.minecraft.screen instanceof ChatScreen) {
+ offset = 15;
+ }
+ default:
+ }
+ switch (this) {
+ case TOPLEFT:
+ return new Vector2f(in.x, in.y);
+ case TOPCENTER:
+ return new Vector2f((window.getWidth()/4.0f) + in.x - (textWidth / 2), in.y);
+ case TOPRIGHT:
+ return new Vector2f((window.getWidth()/2.0f) - (in.x + textWidth), in.y);
+ case MIDDLELEFT:
+ return new Vector2f(in.x, (window.getHeight()/4.0f) + in.y - (lineHeight / 2));
+ case MIDDLECENTER:
+ return new Vector2f((window.getWidth()/4.0f) + in.x - (textWidth / 2), (window.getHeight()/4.0f) + in.y - (lineHeight / 2));
+ case MIDDLERIGHT:
+ return new Vector2f((window.getWidth()/2.0f) - (in.x + textWidth), (window.getHeight()/4.0f) + in.y - (lineHeight / 2));
+ case BOTTOMLEFT:
+ return new Vector2f(in.x, (window.getHeight()/2.0f) - (in.y + lineHeight + offset));
+ case BOTTOMCENTER:
+ return new Vector2f((window.getWidth()/4.0f) + in.x - (textWidth / 2), (window.getHeight()/2.0f) - (in.y + lineHeight + offset));
+ case BOTTOMRIGHT:
+ return new Vector2f((window.getWidth()/2.0f) - (in.x + textWidth), (window.getHeight()/2.0f) - (in.y + lineHeight + offset));
+ default:
+ return new Vector2f(0.0f, 0.0f);
+ }
+ }
+}
diff --git a/src/main/java/co/fantabos/bscv/tools/Text.java b/src/main/java/co/fantabos/bscv/tools/Text.java
index a861281..a0ee92e 100644
--- a/src/main/java/co/fantabos/bscv/tools/Text.java
+++ b/src/main/java/co/fantabos/bscv/tools/Text.java
@@ -3,7 +3,7 @@ package co.fantabos.bscv.tools;
import com.mojang.blaze3d.matrix.MatrixStack;
import co.fantabos.bscv.BoSCoVicino;
-import co.fantabos.bscv.tools.Align.Anchor;
+import co.fantabos.bscv.tools.Anchor;
import net.minecraft.client.MainWindow;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.util.math.vector.Vector2f;
@@ -23,7 +23,7 @@ public final class Text {
private Text() {
this.text = "";
this.anchor = Anchor.TOPLEFT;
- this.style = Style.EMPTY;
+ this.style = Style.EMPTY.withColor(Color.fromRgb(16777215));
this.x = 0.0f;
this.y = 0.0f;
}
@@ -60,7 +60,12 @@ public final class Text {
public void render(MatrixStack stack, MainWindow window) {
FontRenderer font = BoSCoVicino.minecraft.font;
ITextComponent text = new StringTextComponent(this.text).setStyle(this.style);
- Vector2f abs_coords = Align.translate(this.anchor, window, new Vector2f(this.x, this.y));
+ Vector2f abs_coords = this.anchor.translate(
+ new Vector2f(this.x, this.y),
+ font.width(text),
+ font.lineHeight,
+ window
+ );
font.drawShadow(
stack,
text,