feat: hide HUD modules on debug, fix avg speed

This commit is contained in:
əlemi 2023-03-08 17:24:56 +01:00
parent 598c5c8ad3
commit 9c296d76dc
Signed by: alemi
GPG key ID: A4895B84D311642C
5 changed files with 51 additions and 29 deletions

View file

@ -16,7 +16,8 @@ import static ftbsc.bscv.tools.Text.TextBuilder;
public class ActiveModules extends HudModule implements ICommons { public class ActiveModules extends HudModule implements ICommons {
@SubscribeEvent @SubscribeEvent
public void onRenderOverlay(RenderGameOverlayEvent event) { public void onRenderOverlay(RenderGameOverlayEvent event) {
if (event.getType() == ElementType.TEXT) { if (event.getType() != ElementType.TEXT) return;
if (this.shouldHide()) return;
int offset = 0; int offset = 0;
for (IModule m : Boscovicino.modManager.mods) { for (IModule m : Boscovicino.modManager.mods) {
if (m.isEnabled() && !m.getGroup().equalsIgnoreCase("HUD")) { if (m.isEnabled() && !m.getGroup().equalsIgnoreCase("HUD")) {
@ -31,5 +32,4 @@ public class ActiveModules extends HudModule implements ICommons {
} }
} }
} }
}
} }

View file

@ -15,7 +15,10 @@ import static ftbsc.bscv.tools.Text.TextBuilder;
public class Coordinates extends HudModule implements ICommons { public class Coordinates extends HudModule implements ICommons {
@SubscribeEvent @SubscribeEvent
public void onRenderOverlay(RenderGameOverlayEvent event) { public void onRenderOverlay(RenderGameOverlayEvent event) {
if (event.getType() == ElementType.TEXT && MC.player != null) { if (event.getType() != ElementType.TEXT) return;
if (MC.player == null) return;
if (this.shouldHide()) return;
Vector3d position = MC.player.position(); Vector3d position = MC.player.position();
TextBuilder() TextBuilder()
.txt(String.format("[ X %.1f | %.1f Z ] %.1f Y", position.x(), position.z(), position.y())) .txt(String.format("[ X %.1f | %.1f Z ] %.1f Y", position.x(), position.z(), position.y()))
@ -25,5 +28,4 @@ public class Coordinates extends HudModule implements ICommons {
.scale(this.scale.get()) .scale(this.scale.get())
.render(event.getMatrixStack(), event.getWindow()); .render(event.getMatrixStack(), event.getWindow());
} }
}
} }

View file

@ -39,6 +39,7 @@ public class EntityList extends HudModule implements ICommons {
@SubscribeEvent @SubscribeEvent
public void onRenderOverlay(RenderGameOverlayEvent event) { public void onRenderOverlay(RenderGameOverlayEvent event) {
if (event.getType() != ElementType.TEXT) return; if (event.getType() != ElementType.TEXT) return;
if (this.shouldHide()) return;
List<String> entities = new ArrayList<>(); List<String> entities = new ArrayList<>();
for (Entity e : MC.level.entitiesForRendering()) { for (Entity e : MC.level.entitiesForRendering()) {

View file

@ -16,6 +16,8 @@ import net.minecraftforge.event.TickEvent.Phase;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
import java.util.ArrayDeque; import java.util.ArrayDeque;
import java.util.LinkedList;
import java.util.Queue;
import static ftbsc.bscv.tools.Text.TextBuilder; import static ftbsc.bscv.tools.Text.TextBuilder;
@ -25,12 +27,12 @@ public class InfoDisplay extends HudModule implements ICommons {
private Vector3d last_position = new Vector3d(0.0, 0.0, 0.0); private Vector3d last_position = new Vector3d(0.0, 0.0, 0.0);
private double instant_speed = 0.0; private double instant_speed = 0.0;
private double average_speed = 0.0; private double average_speed = 0.0;
private ArrayDeque<Double> history_speed = new ArrayDeque<>(); private Queue<Double> history_speed = new LinkedList<>();
public final ForgeConfigSpec.ConfigValue<Boolean> logo; public final ForgeConfigSpec.ConfigValue<Boolean> logo;
public final ForgeConfigSpec.ConfigValue<Boolean> speed; public final ForgeConfigSpec.ConfigValue<Boolean> speed;
public final ForgeConfigSpec.ConfigValue<Boolean> time; public final ForgeConfigSpec.ConfigValue<Boolean> time;
// public final ForgeConfigSpec.ConfigValue<Boolean> fps; public final ForgeConfigSpec.ConfigValue<Boolean> fps;
// public final ForgeConfigSpec.ConfigValue<Boolean> biome; // public final ForgeConfigSpec.ConfigValue<Boolean> biome;
// public final ForgeConfigSpec.ConfigValue<Boolean> latency; // public final ForgeConfigSpec.ConfigValue<Boolean> latency;
// public final ForgeConfigSpec.ConfigValue<Boolean> tps; // public final ForgeConfigSpec.ConfigValue<Boolean> tps;
@ -64,6 +66,12 @@ public class InfoDisplay extends HudModule implements ICommons {
.fallback(true) .fallback(true)
.build(this); .build(this);
this.fps = Setting.Bool.builder()
.name("fps")
.comment("show current framerate")
.fallback(true)
.build(this);
this.hide_effects = Setting.Bool.builder() this.hide_effects = Setting.Bool.builder()
.name("hide-effects") .name("hide-effects")
.comment("hide effect icons on top right corner") .comment("hide effect icons on top right corner")
@ -76,16 +84,15 @@ public class InfoDisplay extends HudModule implements ICommons {
if (!this.speed.get()) return; if (!this.speed.get()) return;
if (event.phase == Phase.END) return; if (event.phase == Phase.END) return;
if (MC.player != null) { if (MC.player != null) {
this.instant_speed = this.instant_speed = this.last_position.distanceTo(MC.player.position());
this.last_position.distanceTo(MC.player.position());
this.last_position = MC.player.position(); this.last_position = MC.player.position();
} else { } else {
this.instant_speed = 0.0; this.instant_speed = 0.0;
} }
this.history_speed.push(this.instant_speed); this.history_speed.add(this.instant_speed);
while (this.history_speed.size() >= 100) { // TODO customize this parameter while (this.history_speed.size() >= 100) { // TODO customize this parameter
this.history_speed.pop(); this.history_speed.remove();
} }
double buf = 0.0; double buf = 0.0;
@ -143,5 +150,16 @@ public class InfoDisplay extends HudModule implements ICommons {
.render(event.getMatrixStack(), event.getWindow()); .render(event.getMatrixStack(), event.getWindow());
offset += MC.font.lineHeight * scale; offset += MC.font.lineHeight * scale;
} }
if (this.fps.get()) {
TextBuilder()
.txt("> " + MC.fpsString)
.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;
}
} }
} }

View file

@ -18,6 +18,7 @@ public class PlayerList extends HudModule implements ICommons {
@SubscribeEvent @SubscribeEvent
public void onRenderOverlay(RenderGameOverlayEvent event) { public void onRenderOverlay(RenderGameOverlayEvent event) {
if (event.getType() != ElementType.TEXT) return; if (event.getType() != ElementType.TEXT) return;
if (this.shouldHide()) return;
int offset = 0; int offset = 0;
for (Entity e : MC.level.entitiesForRendering()) { for (Entity e : MC.level.entitiesForRendering()) {