[hud] HUD system

This commit is contained in:
c0repwn3r 2022-12-03 21:23:39 -05:00
parent e41a18a7bd
commit 67ef576d81
Signed by: core
GPG Key ID: FDBF740DADDCEECF
6 changed files with 108 additions and 10 deletions

View File

@ -1,5 +1,6 @@
package dev.coredoes.clientmod;
import dev.coredoes.clientmod.hud.HudManager;
import dev.coredoes.clientmod.modmenu.ModMenu;
import dev.coredoes.clientmod.modules.Jetpack;
import dev.coredoes.clientmod.modules.ModuleManager;
@ -21,6 +22,7 @@ public class ClientMod implements ClientModInitializer {
public static final Logger LOGGER = LoggerFactory.getLogger("coreclientmod");
public static ModuleManager moduleManager = new ModuleManager();
public static HudManager hudManager = new HudManager();
private static KeyBinding modMenuKeyBinding;

View File

@ -0,0 +1,25 @@
package dev.coredoes.clientmod.hud;
public enum HudColor {
DarkRed(0xaa0000),
Red(0xff5555),
Gold(0xffaa00),
Yellow(0xffff55),
DarkGreen(0x00aa00),
Green(0x55ff55),
Aqua(0x55fff),
DarkAqua(0xaaaa),
DarkBlue(0x0000aa),
Blue(0x5555ff),
LightPurple(0xff55ff),
DarkPurple(0xaa00aa),
White(0xffffff),
Gray(0xaaaaaa),
DarkGray(0x555555),
Black(0x000000);
public int value;
HudColor(int col) {
this.value = col;
}
}

View File

@ -0,0 +1,33 @@
package dev.coredoes.clientmod.hud;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import java.util.ArrayList;
import java.util.HashMap;
public class HudManager {
protected HashMap<String, HudMessage> messages;
public HudManager() {
messages = new HashMap<>();
HudRenderCallback.EVENT.register((ms, d) -> {
TextRenderer renderer = MinecraftClient.getInstance().textRenderer;
float currentY = 5;
for (HudMessage message : messages.values()) {
renderer.draw(ms, message.getText(), 5F, currentY, message.getColorAsInt());
currentY += renderer.fontHeight;
}
});
}
public void setMesssage(String key, HudMessage message) {
messages.put(key, message);
}
public void clearMessage(String key) {
messages.remove(key);
}
}

View File

@ -0,0 +1,22 @@
package dev.coredoes.clientmod.hud;
public class HudMessage {
private String text;
private HudColor color;
public HudMessage(String text, HudColor color) {
this.text = text;
this.color = color;
}
public String getText() {
return text;
}
public HudColor getColor() {
return color;
}
public int getColorAsInt() {
return color.value;
}
}

View File

@ -1,5 +1,8 @@
package dev.coredoes.clientmod.modules;
import dev.coredoes.clientmod.ClientMod;
import dev.coredoes.clientmod.hud.HudColor;
import dev.coredoes.clientmod.hud.HudMessage;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
@ -52,7 +55,6 @@ public class Jetpack implements Module {
while (toggleBinding.wasPressed()) {
this.isEnabled = !this.isEnabled;
client.player.sendMessage(Text.of(String.format("[%s] %s %s", this.getId(), (this.isEnabled) ? "Enabled" : "Disabled", this.getId())));
}
}
@ -63,9 +65,15 @@ public class Jetpack implements Module {
public void startTick(MinecraftClient client) {
Module.super.startTick(client);
if (client.player != null) {
if (this.isEnabled) {
ClientMod.hudManager.setMesssage("jetpack", new HudMessage(String.format("Jetpack: Enabled (UpVel %.2f, Max %.2f, VanillaBypass %s)", this.upwardsVel, this.max, (this.isVanillaBypassEnabled) ? "on" : "off"), HudColor.Green));
} else {
ClientMod.hudManager.clearMessage("jetpack");
}
if (!isEnabled) return;
if (client.player != null) {
boolean isJumping = client.options.jumpKey.isPressed();
boolean isSneaking = client.options.sneakKey.isPressed();
@ -139,6 +147,7 @@ public class Jetpack implements Module {
private Jetpack parentModule;
private ButtonWidget upwardsVelBtn;
private ButtonWidget maxSpdBtn;
public ModuleUI(Screen parent, GameOptions gameOptions, Jetpack parentModule) {
super(Text.of("JetpackModule"));
@ -183,23 +192,23 @@ public class Jetpack implements Module {
this.addDrawableChild(new ButtonWidget(5, 80, 20, 20, Text.of("++"), (button) -> {
this.parentModule.max += 1;
this.upwardsVelBtn.setMessage(Text.of("MaxSpd: " + df.format((this.parentModule.max))));
this.maxSpdBtn.setMessage(Text.of("MaxSpd: " + df.format((this.parentModule.max))));
}));
this.addDrawableChild(new ButtonWidget(30, 80, 20, 20, Text.of("+"), (button) -> {
this.parentModule.max += 0.1;
this.upwardsVelBtn.setMessage(Text.of("MaxSpd: " + df.format((this.parentModule.max))));
this.maxSpdBtn.setMessage(Text.of("MaxSpd: " + df.format((this.parentModule.max))));
}));
this.upwardsVelBtn = new ButtonWidget(55, 80, 70, 20, Text.of("MaxSpd: " + df.format((this.parentModule.max))), (button) -> {});
this.addDrawableChild(this.upwardsVelBtn);
this.maxSpdBtn = new ButtonWidget(55, 80, 70, 20, Text.of("MaxSpd: " + df.format((this.parentModule.max))), (button) -> {});
this.addDrawableChild(this.maxSpdBtn);
this.addDrawableChild(new ButtonWidget(130, 80, 20, 20, Text.of("-"), (button) -> {
this.parentModule.max -= 0.1;
this.upwardsVelBtn.setMessage(Text.of("MaxSpd: " + df.format((this.parentModule.max))));
this.maxSpdBtn.setMessage(Text.of("MaxSpd: " + df.format((this.parentModule.max))));
}));
this.addDrawableChild(new ButtonWidget(155, 80, 20, 20, Text.of("--"), (button) -> {
this.parentModule.max -= 1;
this.upwardsVelBtn.setMessage(Text.of("MaxSpd: " + df.format((this.parentModule.max))));
this.maxSpdBtn.setMessage(Text.of("MaxSpd: " + df.format((this.parentModule.max))));
}));
this.addDrawableChild(new ButtonWidget(5, this.height - 25, 40, 20, ScreenTexts.BACK, (button) -> {

View File

@ -1,6 +1,8 @@
package dev.coredoes.clientmod.modules;
import dev.coredoes.clientmod.ClientMod;
import dev.coredoes.clientmod.hud.HudColor;
import dev.coredoes.clientmod.hud.HudMessage;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
@ -36,9 +38,14 @@ public class NoFall implements Module {
public void endTick(MinecraftClient client) {
Module.super.endTick(client);
if (this.isEnabled) {
ClientMod.hudManager.setMesssage("nofall", new HudMessage("NoFall: Enabled", HudColor.Aqua));
} else {
ClientMod.hudManager.clearMessage("nofall");
}
while (toggleBinding.wasPressed()) {
this.isEnabled = !this.isEnabled;
client.player.sendMessage(Text.of(String.format("[%s] %s %s", this.getId(), (this.isEnabled) ? "Enabled" : "Disabled", this.getId())));
}
}