hud: port Potions and Direction from Sydney

- Potions: one row per active effect (icon + name + amplifier + duration),
  Icons toggle, Sorting mode None/Width/Alphabetical, Color mode
  Vanilla (effect color) or Client (theme color). Duration comes from
  MobEffectUtil.formatDuration at the world tick rate, infinite shown as
  **:** like Sydney. Keeps its last bounds while no effects are active so
  it stays draggable in the editor. Sydney's Enhanced palette and its
  VanillaPotions Keep/Move/Hide handling are not ported (the latter would
  need a new Gui mixin hook)
- Direction: "North [-Z]" — facing name capitalized, axis label from
  Sydney's mapping (north -Z, east +X, south +Z, west -X)
This commit is contained in:
froslanz
2026-10-30 11:56:03 -04:00
parent 3f729f7894
commit 4adb232811
3 changed files with 148 additions and 0 deletions
@@ -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.util.render.FrosFont;
import net.minecraft.core.Direction;
public class DirectionHudModule extends HudModule {
private static final int BRACKET = 0xAAAAAA;
public DirectionHudModule() {
super("Direction", "Display the direction you are facing", 100, 10);
}
@Override
protected void render(Render2DEvent e) {
super.render(e);
if (nullCheck()) return;
Direction direction = mc.player.getDirection();
String raw = direction.getName();
String name = Character.toUpperCase(raw.charAt(0)) + raw.substring(1);
String bracket = " [" + axis(direction) + "]";
int x = (int) getX();
int y = (int) getY();
FrosFont.draw(e.getContext(), name, x, y, -1);
FrosFont.draw(e.getContext(), bracket, x + FrosFont.width(name), y, BRACKET);
setWidth(FrosFont.width(name) + FrosFont.width(bracket));
setHeight(FrosFont.lineHeight());
}
/** sydney's axis labels: north is -Z, east is +X */
private static String axis(Direction direction) {
return switch (direction) {
case NORTH -> "-Z";
case EAST -> "+X";
case SOUTH -> "+Z";
case WEST -> "-X";
default -> "N/A";
};
}
}
@@ -0,0 +1,99 @@
package cc.fros.features.modules.hud;
import cc.fros.Fros;
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.client.gui.Gui;
import net.minecraft.client.renderer.RenderPipelines;
import net.minecraft.resources.Identifier;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffectUtil;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
public class PotionsHudModule extends HudModule {
public final Setting<Boolean> icons = bool("Icons", true);
public final Setting<ColorMode> colorMode = mode("Color", ColorMode.VANILLA);
public final Setting<Sorting> sorting = mode("Sorting", Sorting.ALPHABETICAL);
public PotionsHudModule() {
super("Potions", "Display your active status effects", 120, 40);
}
@Override
protected void render(Render2DEvent e) {
super.render(e);
if (nullCheck()) return;
List<MobEffectInstance> effects = new ArrayList<>(mc.player.getActiveEffects());
switch (sorting.getValue()) {
case WIDTH -> effects.sort(Comparator.comparingInt((MobEffectInstance ie) -> -FrosFont.width(text(ie))));
case ALPHABETICAL -> effects.sort(Comparator.comparing((MobEffectInstance ie) -> name(ie)));
case NONE -> { }
}
boolean showIcons = icons.getValue();
int x = (int) getX();
int y = (int) getY();
int rowHeight = FrosFont.lineHeight();
int iconSpan = showIcons ? rowHeight + 2 : 0;
int width = 0;
int row = 0;
for (MobEffectInstance effect : effects) {
String text = text(effect);
int rowY = y + row * rowHeight;
if (showIcons) {
Identifier sprite = Gui.getMobEffectSprite(effect.getEffect());
if (sprite != null) {
e.getContext().blitSprite(RenderPipelines.GUI_TEXTURED, sprite, x, rowY, rowHeight, rowHeight);
}
}
FrosFont.draw(e.getContext(), text, x + iconSpan, rowY, color(effect));
width = Math.max(width, iconSpan + FrosFont.width(text));
row++;
}
// keep the last size while empty so the element stays draggable in the editor
if (row > 0) {
setWidth(width);
setHeight(row * rowHeight);
}
}
private static String name(MobEffectInstance effect) {
return effect.getEffect().value().getDisplayName().getString();
}
/** sydney's format: "Effect amplifier duration", infinite shown as **:** */
private static String text(MobEffectInstance effect) {
String duration = effect.isInfiniteDuration()
? "**:**"
: MobEffectUtil.formatDuration(effect, 1.0F, mc.level.tickRateManager().tickrate()).getString();
return name(effect) + " " + (effect.getAmplifier() + 1) + " " + duration;
}
private int color(MobEffectInstance effect) {
return switch (colorMode.getValue()) {
case VANILLA -> effect.getEffect().value().getColor();
case CLIENT -> Fros.colorManager.getColor().getRGB();
};
}
public enum ColorMode {
VANILLA,
CLIENT
}
public enum Sorting {
NONE,
WIDTH,
ALPHABETICAL
}
}
@@ -22,6 +22,7 @@ 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.DirectionHudModule;
import cc.fros.features.modules.hud.DurabilityHudModule;
import cc.fros.features.modules.hud.HealthHudModule;
import cc.fros.features.modules.hud.ServerHudModule;
@@ -33,6 +34,7 @@ import cc.fros.features.modules.hud.XpHudModule;
import cc.fros.features.modules.hud.CoordinatesHudModule;
import cc.fros.features.modules.hud.FpsHudModule;
import cc.fros.features.modules.hud.PingHudModule;
import cc.fros.features.modules.hud.PotionsHudModule;
import cc.fros.features.modules.hud.RadarHudModule;
import cc.fros.features.modules.hud.TimeHudModule;
import cc.fros.features.modules.hud.WelcomerHudModule;
@@ -83,6 +85,8 @@ public class ModuleManager implements Jsonable, Util {
register(new DurabilityHudModule());
register(new SpeedHudModule());
register(new UptimeHudModule());
register(new PotionsHudModule());
register(new DirectionHudModule());
register(new HudEditorModule());
register(new ClickGuiModule());
register(new NotificationsModule());