feat: added initial infodisplay hud mod
This commit is contained in:
parent
80b08eb4d4
commit
1b628a647d
2 changed files with 136 additions and 0 deletions
|
@ -72,6 +72,8 @@ public class BoSCoVicino {
|
|||
builder.pop();
|
||||
BoSCoVicino.mods.add(new FastInteract(builder, this.dispatcher));
|
||||
builder.pop();
|
||||
BoSCoVicino.mods.add(new InfoDisplay(builder, this.dispatcher));
|
||||
builder.pop();
|
||||
BoSCoVicino.mods.add(new Coordinates(builder, this.dispatcher));
|
||||
builder.pop();
|
||||
BoSCoVicino.mods.add(new EntityList(builder, this.dispatcher));
|
||||
|
|
134
src/main/java/co/fantabos/bscv/module/hud/InfoDisplay.java
Normal file
134
src/main/java/co/fantabos/bscv/module/hud/InfoDisplay.java
Normal file
|
@ -0,0 +1,134 @@
|
|||
package co.fantabos.bscv.module.hud;
|
||||
|
||||
import static co.fantabos.bscv.tools.Text.TextBuilder;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.BoolArgumentType;
|
||||
|
||||
import co.fantabos.bscv.BoSCoVicino;
|
||||
import co.fantabos.bscv.module.HudModule;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
import net.minecraft.util.text.Color;
|
||||
import net.minecraft.util.text.Style;
|
||||
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
||||
import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
|
||||
import net.minecraftforge.common.ForgeConfigSpec;
|
||||
import net.minecraftforge.event.TickEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
|
||||
public class InfoDisplay extends HudModule {
|
||||
|
||||
|
||||
private Vector3d last_position = new Vector3d(0.0, 0.0, 0.0);
|
||||
private double instant_speed = 0.0;
|
||||
private double average_speed = 0.0;
|
||||
private ArrayDeque<Double> history_speed = new ArrayDeque<>();
|
||||
|
||||
public final ForgeConfigSpec.ConfigValue<Boolean> logo;
|
||||
public final ForgeConfigSpec.ConfigValue<Boolean> speed;
|
||||
public final ForgeConfigSpec.ConfigValue<Boolean> time;
|
||||
// public final ForgeConfigSpec.ConfigValue<Boolean> fps;
|
||||
// public final ForgeConfigSpec.ConfigValue<Boolean> biome;
|
||||
// public final ForgeConfigSpec.ConfigValue<Boolean> latency;
|
||||
// public final ForgeConfigSpec.ConfigValue<Boolean> tps;
|
||||
// public final ForgeConfigSpec.ConfigValue<Boolean> light;
|
||||
// public final ForgeConfigSpec.ConfigValue<Boolean> saturation;
|
||||
// public final ForgeConfigSpec.ConfigValue<Boolean> system_time;
|
||||
// public final ForgeConfigSpec.ConfigValue<Boolean> damage_value;
|
||||
// public final ForgeConfigSpec.ConfigValue<Boolean> effects_list;
|
||||
// public final ForgeConfigSpec.ConfigValue<Boolean> item_quantity;
|
||||
// public final ForgeConfigSpec.ConfigValue<Boolean> client_chunk_size;
|
||||
|
||||
public InfoDisplay(ForgeConfigSpec.Builder builder, CommandDispatcher<CommandSource> dispatcher) {
|
||||
super("InfoDisplay", builder, dispatcher);
|
||||
|
||||
this.logo = this.option(
|
||||
"logo", "show logo at top of list", true,
|
||||
BoolArgumentType.bool(), Boolean.class,
|
||||
builder, dispatcher
|
||||
);
|
||||
|
||||
this.speed = this.option(
|
||||
"speed", "show speed meter", true,
|
||||
BoolArgumentType.bool(), Boolean.class,
|
||||
builder, dispatcher
|
||||
);
|
||||
|
||||
this.time = this.option(
|
||||
"time", "show world time", true,
|
||||
BoolArgumentType.bool(), Boolean.class,
|
||||
builder, dispatcher
|
||||
);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onTick(TickEvent.ClientTickEvent event) {
|
||||
if (!this.speed.get()) return;
|
||||
if (BoSCoVicino.minecraft.player != null) {
|
||||
this.instant_speed =
|
||||
this.last_position.distanceTo(BoSCoVicino.minecraft.player.position());
|
||||
this.last_position = BoSCoVicino.minecraft.player.position();
|
||||
} else {
|
||||
this.instant_speed = 0.0;
|
||||
}
|
||||
|
||||
this.history_speed.push(this.instant_speed);
|
||||
while (this.history_speed.size() >= 100) { // TODO customize this parameter
|
||||
this.history_speed.pop();
|
||||
}
|
||||
|
||||
double buf = 0.0;
|
||||
for (double v : this.history_speed) { buf += v; }
|
||||
this.average_speed = buf / this.history_speed.size();
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onRenderOverlay(RenderGameOverlayEvent event) {
|
||||
if (event.getType() != ElementType.TEXT) return;
|
||||
|
||||
Minecraft mc = BoSCoVicino.minecraft;
|
||||
int offset = 0;
|
||||
double scale = this.scale.get();
|
||||
if (this.logo.get()) {
|
||||
TextBuilder()
|
||||
.txt("BSCV")
|
||||
.anchor(this.anchor.get())
|
||||
.x(this.x.get() / 4)
|
||||
.y(this.y.get() / 4)
|
||||
.style(Style.EMPTY.withColor(Color.fromRgb(12542314)).withBold(true))
|
||||
.scale(scale * 4.0)
|
||||
.render(event.getMatrixStack(), event.getWindow());
|
||||
offset += mc.font.lineHeight * scale * 4.0;
|
||||
}
|
||||
|
||||
if (this.time.get()) {
|
||||
long daytime = 0;
|
||||
if (mc.level != null) {
|
||||
daytime = mc.level.dayTime();
|
||||
}
|
||||
TextBuilder()
|
||||
.txt(String.format("> time: %d/1200 (%d day)", (daytime / 20) % 1200, daytime / (20 * 1200) ))
|
||||
.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;
|
||||
}
|
||||
|
||||
if (this.speed.get()) {
|
||||
TextBuilder()
|
||||
.txt(String.format("> speed: %.1f [%.1f] m/s", this.instant_speed * 20.0, this.average_speed * 20.0))
|
||||
.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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue