diff options
author | DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> | 2022-06-29 10:45:00 +0200 |
---|---|---|
committer | DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> | 2022-06-29 10:45:00 +0200 |
commit | d4c12a8786597a38fe1a8e31b5be3835dffbb0c6 (patch) | |
tree | b6f631da2aa5b52c4aef6451d8512637242bdadd /src | |
parent | f33aaadbb09e0691479192ad0b5342e8c47f2a1e (diff) | |
download | OneConfig-d4c12a8786597a38fe1a8e31b5be3835dffbb0c6.tar.gz OneConfig-d4c12a8786597a38fe1a8e31b5be3835dffbb0c6.tar.bz2 OneConfig-d4c12a8786597a38fe1a8e31b5be3835dffbb0c6.zip |
update hud
Diffstat (limited to 'src')
3 files changed, 35 insertions, 30 deletions
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<String> getLines() { - return Collections.singletonList(getCompleteText(getText())); + protected void getLines(List<String> lines) { + lines.clear(); + lines.add(getCompleteText(getText())); } @Override - protected List<String> getLinesFrequent() { + protected void getLinesFrequent(List<String> 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<String> getExampleLines() { - return Collections.singletonList(getCompleteText(getExampleText())); + protected void getExampleLines(List<String> lines) { + lines.clear(); + lines.add(getCompleteText(getExampleText())); } @Override - protected List<String> getExampleLinesFrequent() { + protected void getExampleLinesFrequent(List<String> 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<String> lines = null; + protected transient List<String> 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<String> getLines(); + protected abstract void getLines(List<String> 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<String> getLinesFrequent() { - return null; + protected void getLinesFrequent(List<String> 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<String> getExampleLines() { - return getLines(); + protected void getExampleLines(List<String> 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<String> getExampleLinesFrequent() { - return getLinesFrequent(); + protected void getExampleLinesFrequent(List<String> lines) { + getLinesFrequent(lines); } @Override public void draw(int x, int y, float scale) { - List<String> 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<String> getLines() { - return Lists.newArrayList(String.valueOf(System.currentTimeMillis()), String.valueOf(Minecraft.getSystemTime())); + protected void getLines(List<String> lines) { + lines.clear(); + lines.add(String.valueOf(System.currentTimeMillis())); + lines.add(String.valueOf(Minecraft.getSystemTime())); } } |