Package me.hackware.api.util
Class ScaleUtil
java.lang.Object
me.hackware.api.util.ScaleUtil
Shared helpers for client UI scale values.
Client surfaces (HUD, HUD editor, ClickGUI) render on top of Minecraft's
already gui-scaled coordinate space, so a scale of 1.0 matches the
player's Minecraft GUI scale exactly and any other value multiplies that base
(e.g. 2.0 = twice the Minecraft GUI scale, 0.5 = half).
When fractional scaling is enabled, raw slider values snap to fractions
n/d. The available denominators scale with the Minecraft GUI scale:
a GUI scale of 5 allows denominators 2..5, a GUI scale of
6 allows 2..6, and so on (denominator 1 = whole
numbers, always available). Higher GUI scales therefore unlock finer steps,
since each fractional step still lands on a whole physical pixel boundary.
-
Method Summary
Modifier and TypeMethodDescriptionstatic Stringformat(double v) Format a scale value for display, e.g.static Stringlabel(double v) Convenience:format(double)with a trailing"x".static intmaxDenominator(double guiScale) Largest fraction denominator available for the given Minecraft GUI scale.static doubleParse a value that may be a decimal ("1.25") or a fraction ("2/3").static doublesnap(double raw, boolean fractional, double min, double max, int maxDenom) Snap a raw scale value to the nearest valid stop within[min, max].static doublestep(double value, int dir, boolean fractional, double min, double max, int maxDenom) Move one stop up (dir > 0) or down (dir < 0) from the current value.
-
Method Details
-
maxDenominator
public static int maxDenominator(double guiScale) Largest fraction denominator available for the given Minecraft GUI scale. GUI scale 5 → 5 (denominators 2..5), GUI scale 6 → 6, etc. Always ≥ 1. -
snap
public static double snap(double raw, boolean fractional, double min, double max, int maxDenom) Snap a raw scale value to the nearest valid stop within[min, max].- Parameters:
raw- raw (continuous) value, typically straight off a sliderfractional- when true, snap to fractions; otherwise to whole numbersmin- lower clamp boundmax- upper clamp boundmaxDenom- largest fraction denominator (seemaxDenominator(double))
-
step
public static double step(double value, int dir, boolean fractional, double min, double max, int maxDenom) Move one stop up (dir > 0) or down (dir < 0) from the current value. Used by scroll-to-adjust handlers so each notch advances to the next valid stop. -
format
Format a scale value for display, e.g."1","1/2","3/2","1.25". -
label
Convenience:format(double)with a trailing"x". -
parse
Parse a value that may be a decimal ("1.25") or a fraction ("2/3"). Returnsfallbackif the text can't be parsed.
-