From d4c12a8786597a38fe1a8e31b5be3835dffbb0c6 Mon Sep 17 00:00:00 2001 From: DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> Date: Wed, 29 Jun 2022 10:45:00 +0200 Subject: update hud --- .../cc/polyfrost/oneconfig/hud/SingleTextHud.java | 24 ++++++++------- .../java/cc/polyfrost/oneconfig/hud/TextHud.java | 34 +++++++++++----------- .../oneconfig/test/TestMultilineHud_Test.java | 7 +++-- 3 files changed, 35 insertions(+), 30 deletions(-) (limited to 'src/main/java/cc/polyfrost') diff --git a/src/main/java/cc/polyfrost/oneconfig/hud/SingleTextHud.java b/src/main/java/cc/polyfrost/oneconfig/hud/SingleTextHud.java index 7506c30..4d11b1e 100644 --- a/src/main/java/cc/polyfrost/oneconfig/hud/SingleTextHud.java +++ b/src/main/java/cc/polyfrost/oneconfig/hud/SingleTextHud.java @@ -52,27 +52,31 @@ public abstract class SingleTextHud extends TextHud { } @Override - protected List getLines() { - return Collections.singletonList(getCompleteText(getText())); + protected void getLines(List lines) { + lines.clear(); + lines.add(getCompleteText(getText())); } @Override - protected List getLinesFrequent() { + protected void getLinesFrequent(List lines) { String text = getTextFrequent(); - if (text == null) return null; - return Collections.singletonList(getCompleteText(text)); + if (text == null) return; + lines.clear(); + lines.add(getCompleteText(text)); } @Override - protected List getExampleLines() { - return Collections.singletonList(getCompleteText(getExampleText())); + protected void getExampleLines(List lines) { + lines.clear(); + lines.add(getCompleteText(getExampleText())); } @Override - protected List getExampleLinesFrequent() { + protected void getExampleLinesFrequent(List lines) { String text = getExampleTextFrequent(); - if (text == null) return null; - return Collections.singletonList(getCompleteText(text)); + if (text == null) return; + lines.clear(); + lines.add(getCompleteText(text)); } protected final String getCompleteText(String text) { diff --git a/src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java b/src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java index efe2556..4a1a765 100644 --- a/src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java +++ b/src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java @@ -11,10 +11,11 @@ import cc.polyfrost.oneconfig.libs.eventbus.Subscribe; import cc.polyfrost.oneconfig.libs.universal.UMinecraft; import cc.polyfrost.oneconfig.renderer.RenderManager; +import java.util.ArrayList; import java.util.List; public abstract class TextHud extends Hud { - protected transient List lines = null; + protected transient List lines = new ArrayList<>(); private transient int width; private transient int height; @@ -41,41 +42,41 @@ public abstract class TextHud extends Hud { /** * This function is called every tick * - * @return The new lines + * @param lines The current lines of the hud */ - protected abstract List getLines(); + protected abstract void getLines(List lines); /** * This function is called every frame * - * @return The new lines, null if you want to use the cached lines + * @param lines The current lines of the hud */ - protected List getLinesFrequent() { - return null; + protected void getLinesFrequent(List lines) { + } /** * This function is called every tick in the move GUI * - * @return The new lines + * @param lines The current lines of the hud */ - protected List getExampleLines() { - return getLines(); + protected void getExampleLines(List lines) { + getLines(lines); } /** * This function is called every frame in the move GUI * - * @return The new lines, null if you want to use the cached lines + * @param lines The current lines of the hud */ - protected List getExampleLinesFrequent() { - return getLinesFrequent(); + protected void getExampleLinesFrequent(List lines) { + getLinesFrequent(lines); } @Override public void draw(int x, int y, float scale) { - List frequentLines = HudCore.editing ? getExampleLinesFrequent() : getLinesFrequent(); - if (frequentLines != null) lines = frequentLines; + if (!HudCore.editing) getLinesFrequent(lines); + else getExampleLinesFrequent(lines); if (lines == null) return; int textY = y; @@ -98,13 +99,12 @@ public abstract class TextHud extends Hud { return (int) (height * scale); } - private class TickHandler { @Subscribe private void onTick(TickEvent event) { if (event.stage != Stage.START) return; - if (!HudCore.editing) lines = getLines(); - else lines = getExampleLines(); + if (!HudCore.editing) getLines(lines); + else getExampleLines(lines); } } } \ No newline at end of file diff --git a/src/main/java/cc/polyfrost/oneconfig/test/TestMultilineHud_Test.java b/src/main/java/cc/polyfrost/oneconfig/test/TestMultilineHud_Test.java index e7ba8af..9055862 100644 --- a/src/main/java/cc/polyfrost/oneconfig/test/TestMultilineHud_Test.java +++ b/src/main/java/cc/polyfrost/oneconfig/test/TestMultilineHud_Test.java @@ -1,7 +1,6 @@ package cc.polyfrost.oneconfig.test; import cc.polyfrost.oneconfig.hud.TextHud; -import com.google.common.collect.Lists; import net.minecraft.client.Minecraft; import java.util.List; @@ -12,7 +11,9 @@ public class TestMultilineHud_Test extends TextHud { } @Override - protected List getLines() { - return Lists.newArrayList(String.valueOf(System.currentTimeMillis()), String.valueOf(Minecraft.getSystemTime())); + protected void getLines(List lines) { + lines.clear(); + lines.add(String.valueOf(System.currentTimeMillis())); + lines.add(String.valueOf(Minecraft.getSystemTime())); } } -- cgit