feat: added HUD module to show coords and mods
This commit is contained in:
parent
40ef8c34ae
commit
8b81f50b33
1 changed files with 80 additions and 0 deletions
80
src/main/java/co/fantabos/bscv/modules/Hud.java
Normal file
80
src/main/java/co/fantabos/bscv/modules/Hud.java
Normal file
|
@ -0,0 +1,80 @@
|
|||
package co.fantabos.bscv.modules;
|
||||
|
||||
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 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.CORE, 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) {
|
||||
Vector3d position = mc.player.getPosition(0.0f);
|
||||
TextComponent text = new StringTextComponent(String.format("[ X %.1f | %.1f Z ] %.1f Y", position.x(), position.z(), position.y()));
|
||||
text.setStyle(Style.EMPTY.withColor(Color.fromLegacyFormat(TextFormatting.WHITE)));
|
||||
float height = 1.0f;
|
||||
if (mc.screen != null && mc.screen instanceof ChatScreen) {
|
||||
height = 16.0f;
|
||||
}
|
||||
mc.font.drawShadow(event.getMatrixStack(), text, 1.0f, (event.getWindow().getHeight() / 2) - (mc.font.lineHeight + height), this.size.get());
|
||||
}
|
||||
|
||||
if (this.activemods.get()) {
|
||||
float offset = 27.0f;
|
||||
for (Module m : BoSCoVicino.mods) {
|
||||
if (m.enabled.get()) {
|
||||
TextComponent text = new StringTextComponent(String.format("%s <", m.name));
|
||||
text.setStyle(Style.EMPTY.withColor(Color.fromLegacyFormat(TextFormatting.WHITE)));
|
||||
int textWidth = BoSCoVicino.minecraft.font.width(String.format("%s <", m.name));
|
||||
mc.font.drawShadow(event.getMatrixStack(), text, (event.getWindow().getWidth() / 2) - (textWidth + 1), offset, this.size.get());
|
||||
offset += mc.font.lineHeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue