diff --git a/src/main/java/cc/fros/features/modules/hud/DurabilityHudModule.java b/src/main/java/cc/fros/features/modules/hud/DurabilityHudModule.java new file mode 100644 index 0000000..a7ac712 --- /dev/null +++ b/src/main/java/cc/fros/features/modules/hud/DurabilityHudModule.java @@ -0,0 +1,48 @@ +package cc.fros.features.modules.hud; + +import cc.fros.event.impl.render.Render2DEvent; +import cc.fros.features.modules.client.HudModule; +import cc.fros.features.settings.Setting; +import cc.fros.util.render.FrosFont; +import net.minecraft.world.item.ItemStack; + +public class DurabilityHudModule extends HudModule { + private static final int LABEL = 0xAAAAAA; + + public final Setting label = bool("Label", true); + + public DurabilityHudModule() { + super("Durability", "Display the durability of your held item", 100, 10); + } + + @Override + protected void render(Render2DEvent e) { + super.render(e); + + if (nullCheck()) return; + + ItemStack stack = mc.player.getMainHandItem(); + int max = stack.getMaxDamage(); + boolean damageable = !stack.isEmpty() && max > 0 && stack.isDamageableItem(); + + String prefix = label.getValue() ? "Durability: " : ""; + String value = damageable ? String.valueOf(max - stack.getDamageValue()) : "--"; + int color = damageable ? durabilityColor(stack, max) : LABEL; + + int x = (int) getX(); + int y = (int) getY(); + FrosFont.draw(e.getContext(), prefix, x, y, LABEL); + FrosFont.draw(e.getContext(), value, x + FrosFont.width(prefix), y, color); + + setWidth(FrosFont.width(prefix) + FrosFont.width(value)); + setHeight(FrosFont.lineHeight()); + } + + /** green while fresh, red as the item wears out (sydney's formula) */ + private static int durabilityColor(ItemStack stack, int max) { + float remaining = (max - stack.getDamageValue()) / (float) max; + int r = (int) ((1.0f - remaining) * 255); + int g = (int) (remaining * 255); + return 0xFF000000 | (r << 16) | (g << 8); + } +} diff --git a/src/main/java/cc/fros/features/modules/hud/HealthHudModule.java b/src/main/java/cc/fros/features/modules/hud/HealthHudModule.java new file mode 100644 index 0000000..4201740 --- /dev/null +++ b/src/main/java/cc/fros/features/modules/hud/HealthHudModule.java @@ -0,0 +1,48 @@ +package cc.fros.features.modules.hud; + +import cc.fros.event.impl.render.Render2DEvent; +import cc.fros.features.modules.client.HudModule; +import cc.fros.util.render.FrosFont; + +import java.text.DecimalFormat; + +public class HealthHudModule extends HudModule { + private static final DecimalFormat FORMAT = new DecimalFormat("0"); + + public HealthHudModule() { + super("Health", "Display your health in the center of the screen", 40, 10); + } + + @Override + protected void render(Render2DEvent e) { + super.render(e); + + if (nullCheck()) return; + + float health = mc.player.getHealth() + mc.player.getAbsorptionAmount(); + String text = FORMAT.format(health); + int color = healthColor(health); + int x = (int) getX(); + int y = (int) getY(); + + // sydney's drawTextWithOutline: black glyphs in the four cardinal directions + FrosFont.draw(e.getContext(), text, x - 1, y, 0xFF000000, false); + FrosFont.draw(e.getContext(), text, x + 1, y, 0xFF000000, false); + FrosFont.draw(e.getContext(), text, x, y - 1, 0xFF000000, false); + FrosFont.draw(e.getContext(), text, x, y + 1, 0xFF000000, false); + FrosFont.draw(e.getContext(), text, x, y, color, false); + + setWidth(FrosFont.width(text)); + setHeight(FrosFont.lineHeight()); + } + + /** sydney's thresholds, as vanilla chat colors */ + private static int healthColor(double health) { + if (health > 18.0) return 0x55FF55; + if (health > 16.0) return 0x00AA00; + if (health > 12.0) return 0xFFFF55; + if (health > 8.0) return 0xFFAA00; + if (health > 5.0) return 0xFF5555; + return 0xAA0000; + } +} diff --git a/src/main/java/cc/fros/features/modules/hud/SpeedHudModule.java b/src/main/java/cc/fros/features/modules/hud/SpeedHudModule.java new file mode 100644 index 0000000..a0b3a5c --- /dev/null +++ b/src/main/java/cc/fros/features/modules/hud/SpeedHudModule.java @@ -0,0 +1,45 @@ +package cc.fros.features.modules.hud; + +import cc.fros.event.impl.render.Render2DEvent; +import cc.fros.features.modules.client.HudModule; +import cc.fros.features.settings.Setting; +import cc.fros.util.render.FrosFont; + +import java.text.DecimalFormat; + +public class SpeedHudModule extends HudModule { + private static final DecimalFormat FORMAT = new DecimalFormat("0.00"); + + public final Setting label = bool("Label", true); + public final Setting unit = mode("Unit", Unit.METERS); + + public SpeedHudModule() { + super("Speed", "Display your movement speed", 100, 10); + } + + @Override + protected void render(Render2DEvent e) { + super.render(e); + + if (nullCheck()) return; + + // blocks travelled during the last tick, converted to m/s (or km/h) + double dx = mc.player.getX() - mc.player.xo; + double dz = mc.player.getZ() - mc.player.zo; + double perTick = Math.sqrt(dx * dx + dz * dz); + boolean meters = unit.getValue() == Unit.METERS; + double value = meters ? perTick * 20 : perTick * 72; + String suffix = meters ? "m/s" : "km/h"; + String speedStr = (label.getValue() ? "Speed: " : "") + FORMAT.format(value) + suffix; + + FrosFont.draw(e.getContext(), speedStr, (int) getX(), (int) getY(), -1); + + setWidth(FrosFont.width(speedStr)); + setHeight(FrosFont.lineHeight()); + } + + public enum Unit { + METERS, + KILOMETERS + } +} diff --git a/src/main/java/cc/fros/features/modules/hud/UptimeHudModule.java b/src/main/java/cc/fros/features/modules/hud/UptimeHudModule.java new file mode 100644 index 0000000..ce039f3 --- /dev/null +++ b/src/main/java/cc/fros/features/modules/hud/UptimeHudModule.java @@ -0,0 +1,34 @@ +package cc.fros.features.modules.hud; + +import cc.fros.event.impl.render.Render2DEvent; +import cc.fros.features.modules.client.HudModule; +import cc.fros.features.settings.Setting; +import cc.fros.util.render.FrosFont; + +import java.util.Locale; + +public class UptimeHudModule extends HudModule { + /** set when this class is loaded, i.e. when the client registers its modules */ + private static final long STARTED = System.currentTimeMillis(); + + public final Setting label = bool("Label", true); + + public UptimeHudModule() { + super("Uptime", "Display how long the client has been running", 100, 10); + } + + @Override + protected void render(Render2DEvent e) { + super.render(e); + + long seconds = (System.currentTimeMillis() - STARTED) / 1000; + String hms = String.format(Locale.ROOT, "%02d:%02d:%02d", + seconds / 3600, (seconds % 3600) / 60, seconds % 60); + String uptimeStr = label.getValue() ? "Uptime " + hms : hms; + + FrosFont.draw(e.getContext(), uptimeStr, (int) getX(), (int) getY(), -1); + + setWidth(FrosFont.width(uptimeStr)); + setHeight(FrosFont.lineHeight()); + } +} diff --git a/src/main/java/cc/fros/manager/ModuleManager.java b/src/main/java/cc/fros/manager/ModuleManager.java index 54abe92..8610af3 100644 --- a/src/main/java/cc/fros/manager/ModuleManager.java +++ b/src/main/java/cc/fros/manager/ModuleManager.java @@ -22,9 +22,13 @@ import cc.fros.features.modules.combat.SurroundModule; import cc.fros.features.modules.hud.ArrayListHudModule; import cc.fros.features.modules.hud.ArmorHudModule; import cc.fros.features.modules.hud.CrystalHudModule; +import cc.fros.features.modules.hud.DurabilityHudModule; +import cc.fros.features.modules.hud.HealthHudModule; import cc.fros.features.modules.hud.ServerHudModule; +import cc.fros.features.modules.hud.SpeedHudModule; import cc.fros.features.modules.hud.TotemHudModule; import cc.fros.features.modules.hud.TpsHudModule; +import cc.fros.features.modules.hud.UptimeHudModule; import cc.fros.features.modules.hud.XpHudModule; import cc.fros.features.modules.hud.CoordinatesHudModule; import cc.fros.features.modules.hud.FpsHudModule; @@ -75,6 +79,10 @@ public class ModuleManager implements Jsonable, Util { register(new TotemHudModule()); register(new CrystalHudModule()); register(new XpHudModule()); + register(new HealthHudModule()); + register(new DurabilityHudModule()); + register(new SpeedHudModule()); + register(new UptimeHudModule()); register(new HudEditorModule()); register(new ClickGuiModule()); register(new NotificationsModule());