feat: better Coordinates module
This commit is contained in:
parent
c22580be32
commit
330f90f821
1 changed files with 51 additions and 5 deletions
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue