aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
author alemi <me@alemi.dev>2023-03-15 09:47:06 +0100
committer alemi <me@alemi.dev>2023-03-15 09:47:06 +0100
commit330f90f821bc6499e8139c372338988e7ad0cf89 (patch)
treed5fb358f5c7c778b298942ad4536e83127c45e61 /src/main/java
parentc22580be320fe9c72cbf7605ca7953330eab6502 (diff)
feat: better Coordinates module
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/ftbsc/bscv/modules/hud/Coordinates.java56
1 files changed, 51 insertions, 5 deletions
diff --git a/src/main/java/ftbsc/bscv/modules/hud/Coordinates.java b/src/main/java/ftbsc/bscv/modules/hud/Coordinates.java
index 258983c..1cd37db 100644
--- a/src/main/java/ftbsc/bscv/modules/hud/Coordinates.java
+++ b/src/main/java/ftbsc/bscv/modules/hud/Coordinates.java
@@ -1,31 +1,77 @@
package ftbsc.bscv.modules.hud;
import com.google.auto.service.AutoService;
-import ftbsc.bscv.ICommons;
import ftbsc.bscv.api.ILoadable;
import ftbsc.bscv.modules.HudModule;
-import net.minecraft.util.math.vector.Vector3d;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
+import net.minecraftforge.event.TickEvent;
+import net.minecraftforge.event.TickEvent.Phase;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import static ftbsc.bscv.tools.Text.TextBuilder;
@AutoService(ILoadable.class)
-public class Coordinates extends HudModule implements ICommons {
+public class Coordinates extends HudModule {
+
+ private double posX = 0.;
+ private double posY = 0.;
+ private double posZ = 0.;
+
+ private double otherX = 0.;
+ private double otherZ = 0.;
+
+ private String facing = "";
+
+ @SubscribeEvent
+ public void onTick(TickEvent.ClientTickEvent event) {
+ if (event.phase == Phase.START) return;
+ if (MC.player == null) return;
+
+ this.posX = MC.player.getX();
+ this.posY = MC.player.getY();
+ this.posZ = MC.player.getZ();
+
+ double factor = MC.level.dimensionType().coordinateScale();
+ double otherFactor = factor == 1. ? 8. : 1.;
+ this.otherX = this.posX * (factor / otherFactor);
+ this.otherZ = this.posZ * (factor / otherFactor);
+
+ switch (MC.player.getDirection()) {
+ case DOWN:
+ this.facing = "Down [-Y]"; break;
+ case EAST:
+ this.facing = "East [+X]"; break;
+ case NORTH:
+ this.facing = "North [-Z]"; break;
+ case SOUTH:
+ this.facing = "South [+Z]"; break;
+ case UP:
+ this.facing = "Up [+Y]"; break;
+ case WEST:
+ this.facing = "West [-X]"; break;
+ }
+ }
+
@SubscribeEvent
public void onRenderOverlay(RenderGameOverlayEvent event) {
if (event.getType() != ElementType.TEXT) return;
if (MC.player == null) return;
if (this.shouldHide()) return;
- Vector3d position = MC.player.position();
TextBuilder()
- .txt(String.format("[ X %.1f | %.1f Z ] %.1f Y", position.x(), position.z(), position.y()))
+ .txt("[ X %.1f | %.1f Z ] (%.1f) Y", this.posX, this.posZ, this.posY)
.anchor(this.anchor.get())
.x(this.x.get())
.y(this.y.get())
.scale(this.scale.get())
.render(event.getMatrixStack(), event.getWindow());
+ TextBuilder()
+ .txt("[ %.1f | %.1f ] - %s", this.otherX, this.otherZ, this.facing)
+ .anchor(this.anchor.get())
+ .x(this.x.get())
+ .y(this.y.get() + MC.font.lineHeight + 1)
+ .scale(this.scale.get())
+ .render(event.getMatrixStack(), event.getWindow());
}
}