From 2214ceb4bfec6c08d63d2c4ef277a2ca541b4aa7 Mon Sep 17 00:00:00 2001 From: jude <60681673+luvvlyjude@users.noreply.github.com> Date: Fri, 25 Oct 2024 17:31:37 -0500 Subject: [PATCH 1/5] start work with some custom text element stuff --- .../seedqueue/gui/wall/SeedQueueWallScreen.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/main/java/me/contaria/seedqueue/gui/wall/SeedQueueWallScreen.java b/src/main/java/me/contaria/seedqueue/gui/wall/SeedQueueWallScreen.java index fbce3596..6d824b6f 100644 --- a/src/main/java/me/contaria/seedqueue/gui/wall/SeedQueueWallScreen.java +++ b/src/main/java/me/contaria/seedqueue/gui/wall/SeedQueueWallScreen.java @@ -1,5 +1,6 @@ package me.contaria.seedqueue.gui.wall; +import com.google.common.io.Files; import com.mojang.blaze3d.systems.RenderSystem; import me.contaria.seedqueue.SeedQueue; import me.contaria.seedqueue.SeedQueueEntry; @@ -34,7 +35,11 @@ import org.jetbrains.annotations.Nullable; import org.lwjgl.glfw.GLFW; +import java.io.File; +import java.nio.charset.Charset; import java.util.*; +import java.nio.file.Path; +import java.util.stream.IntStream; public class SeedQueueWallScreen extends Screen { private static final Set WORLD_RENDERERS = new HashSet<>(); @@ -165,6 +170,14 @@ public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) { this.drawAnimatedTexture(this.overlay, matrices, 0, 0, this.width, this.height); } + if (true) { + try { + textRenderer.draw(matrices, new LiteralText(Files.readFirstLine(new File("C:\\Users\\Jude\\IdeaProjects\\seedqueue\\run\\config\\mcsr\\atum\\rsg-attempts.txt"), Charset.defaultCharset())), (float) 0, (float) 0, 0xffffff); + } catch (Exception e) { + SeedQueue.LOGGER.warn("yeah dat shit broke with some error {} idgaf", e); + } + } + if (this.debugHud != null) { SeedQueueProfiler.swap("fps_graph"); ((DebugHudAccessor) this.debugHud).seedQueue$drawMetricsData(matrices, this.client.getMetricsData(), 0, this.width / 2, true); @@ -248,6 +261,10 @@ private void drawAnimatedTexture(AnimatedTexture texture, MatrixStack matrices, RenderSystem.disableBlend(); } + private void renderText(Path path) { + + } + private boolean playSound(SoundEvent sound) { // spread out reset sounds over multiple ticks if (sound == SeedQueueSounds.RESET_INSTANCE) { From 31ddb057d8a78c0b6390f5e816c195b7bb73ea5b Mon Sep 17 00:00:00 2001 From: jude <60681673+luvvlyjude@users.noreply.github.com> Date: Sun, 27 Oct 2024 22:11:47 -0500 Subject: [PATCH 2/5] =?UTF-8?q?line=20wrapping=20for=20text=20cleaner=20fi?= =?UTF-8?q?le=20reading=20and=20text=20rendering=20structure=20start=20wor?= =?UTF-8?q?k=20on=20api=20calls=20for=20custom=20text=20(its=20laggy=20cau?= =?UTF-8?q?se=20its=20called=20from=20render=20rn=20cause=20im=20a=20silly?= =?UTF-8?q?=20goober=20>.<)=20=F0=9F=98=BB=F0=9F=98=BA=F0=9F=98=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gui/wall/SeedQueueWallScreen.java | 86 ++++++++++++++++--- 1 file changed, 75 insertions(+), 11 deletions(-) diff --git a/src/main/java/me/contaria/seedqueue/gui/wall/SeedQueueWallScreen.java b/src/main/java/me/contaria/seedqueue/gui/wall/SeedQueueWallScreen.java index 6d824b6f..86e3be02 100644 --- a/src/main/java/me/contaria/seedqueue/gui/wall/SeedQueueWallScreen.java +++ b/src/main/java/me/contaria/seedqueue/gui/wall/SeedQueueWallScreen.java @@ -1,6 +1,6 @@ package me.contaria.seedqueue.gui.wall; -import com.google.common.io.Files; +import com.google.gson.*; import com.mojang.blaze3d.systems.RenderSystem; import me.contaria.seedqueue.SeedQueue; import me.contaria.seedqueue.SeedQueueEntry; @@ -30,16 +30,21 @@ import net.minecraft.client.world.ClientWorld; import net.minecraft.sound.SoundEvent; import net.minecraft.text.LiteralText; +import net.minecraft.text.StringRenderable; import net.minecraft.util.Identifier; import org.apache.commons.lang3.ArrayUtils; import org.jetbrains.annotations.Nullable; import org.lwjgl.glfw.GLFW; -import java.io.File; -import java.nio.charset.Charset; -import java.util.*; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.URL; +import java.nio.file.Files; +import java.io.IOException; import java.nio.file.Path; -import java.util.stream.IntStream; +import java.util.*; +import java.nio.file.Paths; +import java.util.stream.Collectors; public class SeedQueueWallScreen extends Screen { private static final Set WORLD_RENDERERS = new HashSet<>(); @@ -171,11 +176,11 @@ public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) { } if (true) { - try { - textRenderer.draw(matrices, new LiteralText(Files.readFirstLine(new File("C:\\Users\\Jude\\IdeaProjects\\seedqueue\\run\\config\\mcsr\\atum\\rsg-attempts.txt"), Charset.defaultCharset())), (float) 0, (float) 0, 0xffffff); - } catch (Exception e) { - SeedQueue.LOGGER.warn("yeah dat shit broke with some error {} idgaf", e); - } + Path path = Paths.get("C:\\Users\\Jude\\IdeaProjects\\seedqueue\\run\\config\\mcsr\\atum\\rsg-attempts.txt"); + this.drawCustomTextFromFile(matrices, path, 0 , 0, 0xffffff); + path = Paths.get("C:\\Users\\Jude\\IdeaProjects\\seedqueue\\run\\options.txt"); + this.drawCustomTextFromFile(matrices, path, 40 , 70, 0x80117a); +// this.drawCustomTextFromURL(matrices, "https://paceman.gg/stats/api/getSessionStats/?name=meebie&hours=999999&hoursBetween=999999", 10 , 20, 0xfe37f); } if (this.debugHud != null) { @@ -261,8 +266,67 @@ private void drawAnimatedTexture(AnimatedTexture texture, MatrixStack matrices, RenderSystem.disableBlend(); } - private void renderText(Path path) { + private void drawCustomTextFromFile(MatrixStack matrices, Path path, float x, float y, int color) { + try { + List lines = Files.readAllLines(path).stream().map(StringRenderable::plain).collect(Collectors.toList()); + float height = this.textRenderer.fontHeight; + for (StringRenderable line : lines) { + this.textRenderer.draw(matrices, line, x, y, color); + y += height; + } + } catch (IOException e) { + SeedQueue.LOGGER.warn("File {} failed to be read", path); + } + } + + private void drawCustomTextFromURL(MatrixStack matrices, String urlString, float x, float y, int color) { + try { + URL url = new URL(urlString); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + connection.connect(); + int responseCode = connection.getResponseCode(); + if (responseCode != 200) { + SeedQueue.LOGGER.warn("Bad response: {} from {}", responseCode, urlString); + } else { + JsonObject jsonObject = getJsonObject(url); + + //Get the required object from the above created object + String netherCount = jsonObject.getAsJsonObject("nether").getAsJsonPrimitive("count").getAsString(); + String netherAverage = jsonObject.getAsJsonObject("nether").getAsJsonPrimitive("avg").getAsString(); + + this.textRenderer.draw(matrices, netherCount, x, y, color); + this.textRenderer.draw(matrices, netherAverage, x, y+30, color); + } + + /* List lines = string.stream().map(StringRenderable::plain).collect(Collectors.toList()); + float height = this.textRenderer.fontHeight; + for (StringRenderable line : lines) { + this.textRenderer.draw(matrices, line, x, y, color); + y += height; + } + this.textRenderer.draw(matrices, string, x, y, color); */ + } catch (MalformedURLException e) { + SeedQueue.LOGGER.warn("URL {} failed to be read", urlString); + } catch (IOException e) { + SeedQueue.LOGGER.warn("Browser content at {} failed to be read", urlString); + } + } + + private static JsonObject getJsonObject(URL url) throws IOException { + StringBuilder inline = new StringBuilder(); + Scanner scanner = new Scanner(url.openStream()); + + //Write all the JSON data into a string using a scanner + while (scanner.hasNext()) { + inline.append(scanner.nextLine()); + } + + //Close the scanner + scanner.close(); + //Using the JSON simple library parse the string into a json object + return new JsonParser().parse(inline.toString()).getAsJsonObject(); } private boolean playSound(SoundEvent sound) { From 29ae4ea4944c7a18e918d64aa1d2e21677c9cdce Mon Sep 17 00:00:00 2001 From: jude <60681673+luvvlyjude@users.noreply.github.com> Date: Tue, 29 Oct 2024 07:53:35 -0500 Subject: [PATCH 3/5] jojoe and woofdoggo said api calls in sq is probably stupid and gay so ill remove this --- .../gui/wall/SeedQueueWallScreen.java | 55 ------------------- 1 file changed, 55 deletions(-) diff --git a/src/main/java/me/contaria/seedqueue/gui/wall/SeedQueueWallScreen.java b/src/main/java/me/contaria/seedqueue/gui/wall/SeedQueueWallScreen.java index 86e3be02..66e92b45 100644 --- a/src/main/java/me/contaria/seedqueue/gui/wall/SeedQueueWallScreen.java +++ b/src/main/java/me/contaria/seedqueue/gui/wall/SeedQueueWallScreen.java @@ -1,6 +1,5 @@ package me.contaria.seedqueue.gui.wall; -import com.google.gson.*; import com.mojang.blaze3d.systems.RenderSystem; import me.contaria.seedqueue.SeedQueue; import me.contaria.seedqueue.SeedQueueEntry; @@ -36,9 +35,6 @@ import org.jetbrains.annotations.Nullable; import org.lwjgl.glfw.GLFW; -import java.net.HttpURLConnection; -import java.net.MalformedURLException; -import java.net.URL; import java.nio.file.Files; import java.io.IOException; import java.nio.file.Path; @@ -180,7 +176,6 @@ public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) { this.drawCustomTextFromFile(matrices, path, 0 , 0, 0xffffff); path = Paths.get("C:\\Users\\Jude\\IdeaProjects\\seedqueue\\run\\options.txt"); this.drawCustomTextFromFile(matrices, path, 40 , 70, 0x80117a); -// this.drawCustomTextFromURL(matrices, "https://paceman.gg/stats/api/getSessionStats/?name=meebie&hours=999999&hoursBetween=999999", 10 , 20, 0xfe37f); } if (this.debugHud != null) { @@ -279,56 +274,6 @@ private void drawCustomTextFromFile(MatrixStack matrices, Path path, float x, fl } } - private void drawCustomTextFromURL(MatrixStack matrices, String urlString, float x, float y, int color) { - try { - URL url = new URL(urlString); - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - connection.setRequestMethod("GET"); - connection.connect(); - int responseCode = connection.getResponseCode(); - if (responseCode != 200) { - SeedQueue.LOGGER.warn("Bad response: {} from {}", responseCode, urlString); - } else { - JsonObject jsonObject = getJsonObject(url); - - //Get the required object from the above created object - String netherCount = jsonObject.getAsJsonObject("nether").getAsJsonPrimitive("count").getAsString(); - String netherAverage = jsonObject.getAsJsonObject("nether").getAsJsonPrimitive("avg").getAsString(); - - this.textRenderer.draw(matrices, netherCount, x, y, color); - this.textRenderer.draw(matrices, netherAverage, x, y+30, color); - } - - /* List lines = string.stream().map(StringRenderable::plain).collect(Collectors.toList()); - float height = this.textRenderer.fontHeight; - for (StringRenderable line : lines) { - this.textRenderer.draw(matrices, line, x, y, color); - y += height; - } - this.textRenderer.draw(matrices, string, x, y, color); */ - } catch (MalformedURLException e) { - SeedQueue.LOGGER.warn("URL {} failed to be read", urlString); - } catch (IOException e) { - SeedQueue.LOGGER.warn("Browser content at {} failed to be read", urlString); - } - } - - private static JsonObject getJsonObject(URL url) throws IOException { - StringBuilder inline = new StringBuilder(); - Scanner scanner = new Scanner(url.openStream()); - - //Write all the JSON data into a string using a scanner - while (scanner.hasNext()) { - inline.append(scanner.nextLine()); - } - - //Close the scanner - scanner.close(); - - //Using the JSON simple library parse the string into a json object - return new JsonParser().parse(inline.toString()).getAsJsonObject(); - } - private boolean playSound(SoundEvent sound) { // spread out reset sounds over multiple ticks if (sound == SeedQueueSounds.RESET_INSTANCE) { From 0d0811ecb82c9cec78924f306cd9a6fdc60d1446 Mon Sep 17 00:00:00 2001 From: jude <60681673+luvvlyjude@users.noreply.github.com> Date: Tue, 29 Oct 2024 15:53:23 -0500 Subject: [PATCH 4/5] added the resource pack options for a text object display text in whatever size or location u want with pos --- .../seedqueue/customization/Layout.java | 47 +++++++++++++++++-- .../gui/wall/SeedQueueWallScreen.java | 31 ++++++------ 2 files changed, 59 insertions(+), 19 deletions(-) diff --git a/src/main/java/me/contaria/seedqueue/customization/Layout.java b/src/main/java/me/contaria/seedqueue/customization/Layout.java index ac680454..d14e8929 100644 --- a/src/main/java/me/contaria/seedqueue/customization/Layout.java +++ b/src/main/java/me/contaria/seedqueue/customization/Layout.java @@ -9,6 +9,8 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.nio.file.Path; +import java.nio.file.Paths; import java.io.InputStreamReader; import java.io.Reader; import java.math.BigDecimal; @@ -21,16 +23,19 @@ public class Layout { public final Group locked; public final Group[] preparing; public final boolean replaceLockedInstances; + @Nullable + public final CustomTextObject[] customTextObjects; private Layout(@NotNull Group main) { - this(main, null, new Group[0], true); + this(main, null, new Group[0], true, null); } - private Layout(@NotNull Group main, @Nullable Group locked, Group[] preparing, boolean replaceLockedInstances) { + private Layout(@NotNull Group main, @Nullable Group locked, Group[] preparing, boolean replaceLockedInstances, @Nullable CustomTextObject[] customTextObjects) { this.main = main; this.locked = locked; this.preparing = preparing; this.replaceLockedInstances = replaceLockedInstances; + this.customTextObjects = customTextObjects; if (this.main.cosmetic) { throw new IllegalArgumentException("Main Group may not be cosmetic!"); @@ -62,6 +67,10 @@ private static int getAsInt(JsonObject jsonObject, String name, int windowSize) return jsonPrimitive.getAsInt(); } + private static int getColor(JsonObject jsonObject) { + return Integer.parseInt(jsonObject.get("color").getAsString(), 16); + } + private static Layout grid(int rows, int columns, int width, int height) { return new Layout(Group.grid(rows, columns, 0, 0, width, height, 0, false, true)); } @@ -71,7 +80,8 @@ private static Layout fromJson(JsonObject jsonObject) throws JsonParseException Group.fromJson(jsonObject.getAsJsonObject("main"), SeedQueue.config.rows, SeedQueue.config.columns), jsonObject.has("locked") ? Group.fromJson(jsonObject.getAsJsonObject("locked")) : null, jsonObject.has("preparing") ? Group.fromJson(jsonObject.getAsJsonArray("preparing")) : new Group[0], - jsonObject.has("replaceLockedInstances") && jsonObject.get("replaceLockedInstances").getAsBoolean() + jsonObject.has("replaceLockedInstances") && jsonObject.get("replaceLockedInstances").getAsBoolean(), + jsonObject.has("customTextObjects") ? CustomTextObject.fromJson(jsonObject.getAsJsonArray("customTextObjects")) : null ); } @@ -192,4 +202,35 @@ private static Pos fromJson(JsonObject jsonObject) throws JsonParseException { ); } } + + public static class CustomTextObject { + public final Pos pos; + public final int color; + public final float lineSpacing; + public final Path path; + + CustomTextObject(Pos pos, int color, float lineSpacing, Path path) { + this.pos = pos; + this.color = color; + this.lineSpacing = lineSpacing; + this.path = path; + } + + private static CustomTextObject[] fromJson(JsonArray jsonArray) { + CustomTextObject[] textObjects = new CustomTextObject[jsonArray.size()]; + for (int i = 0; i < jsonArray.size(); i++) { + textObjects[i] = CustomTextObject.fromJson(jsonArray.get(i).getAsJsonObject()); + } + return textObjects; + } + + private static CustomTextObject fromJson(JsonObject jsonObject) throws JsonParseException { + return new CustomTextObject( + Pos.fromJson(jsonObject), + getColor(jsonObject), + jsonObject.has("lineSpacing") ? jsonObject.get("lineSpacing").getAsFloat() : 9.0f, + Paths.get(jsonObject.get("path").getAsString()) + ); + } + } } diff --git a/src/main/java/me/contaria/seedqueue/gui/wall/SeedQueueWallScreen.java b/src/main/java/me/contaria/seedqueue/gui/wall/SeedQueueWallScreen.java index 66e92b45..161297d2 100644 --- a/src/main/java/me/contaria/seedqueue/gui/wall/SeedQueueWallScreen.java +++ b/src/main/java/me/contaria/seedqueue/gui/wall/SeedQueueWallScreen.java @@ -37,9 +37,7 @@ import java.nio.file.Files; import java.io.IOException; -import java.nio.file.Path; import java.util.*; -import java.nio.file.Paths; import java.util.stream.Collectors; public class SeedQueueWallScreen extends Screen { @@ -162,6 +160,13 @@ public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) { SeedQueueProfiler.pop(); } + if (this.layout.customTextObjects != null) { + SeedQueueProfiler.swap("draw_text"); + for (Layout.CustomTextObject customTextObject : this.layout.customTextObjects) { + this.drawCustomTextObject(matrices, Objects.requireNonNull(customTextObject)); + } + } + SeedQueueProfiler.swap("reset"); this.resetViewport(); this.loadPreviewSettings(this.settingsCache, 0); @@ -171,13 +176,6 @@ public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) { this.drawAnimatedTexture(this.overlay, matrices, 0, 0, this.width, this.height); } - if (true) { - Path path = Paths.get("C:\\Users\\Jude\\IdeaProjects\\seedqueue\\run\\config\\mcsr\\atum\\rsg-attempts.txt"); - this.drawCustomTextFromFile(matrices, path, 0 , 0, 0xffffff); - path = Paths.get("C:\\Users\\Jude\\IdeaProjects\\seedqueue\\run\\options.txt"); - this.drawCustomTextFromFile(matrices, path, 40 , 70, 0x80117a); - } - if (this.debugHud != null) { SeedQueueProfiler.swap("fps_graph"); ((DebugHudAccessor) this.debugHud).seedQueue$drawMetricsData(matrices, this.client.getMetricsData(), 0, this.width / 2, true); @@ -261,16 +259,17 @@ private void drawAnimatedTexture(AnimatedTexture texture, MatrixStack matrices, RenderSystem.disableBlend(); } - private void drawCustomTextFromFile(MatrixStack matrices, Path path, float x, float y, int color) { + private void drawCustomTextObject(MatrixStack matrices, Layout.CustomTextObject customTextObject) { + assert this.client != null; try { - List lines = Files.readAllLines(path).stream().map(StringRenderable::plain).collect(Collectors.toList()); - float height = this.textRenderer.fontHeight; - for (StringRenderable line : lines) { - this.textRenderer.draw(matrices, line, x, y, color); - y += height; + List lines = Files.readAllLines(customTextObject.path).stream().map(StringRenderable::plain).collect(Collectors.toList()); + this.setViewport(customTextObject.pos); + for (int i = 0; i < lines.size(); i++) { + this.client.textRenderer.draw(matrices, lines.get(i), 0, customTextObject.lineSpacing * i, customTextObject.color); } + this.resetViewport(); } catch (IOException e) { - SeedQueue.LOGGER.warn("File {} failed to be read", path); + SeedQueue.LOGGER.warn("File {} failed to be read", customTextObject.path); } } From 67c499102497ad14d41cf6a7218de9570968ed84 Mon Sep 17 00:00:00 2001 From: jude <60681673+luvvlyjude@users.noreply.github.com> Date: Wed, 30 Oct 2024 02:33:02 -0500 Subject: [PATCH 5/5] boolean option to add shadow to text in resource pack --- .../java/me/contaria/seedqueue/customization/Layout.java | 5 ++++- .../contaria/seedqueue/gui/wall/SeedQueueWallScreen.java | 9 ++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/me/contaria/seedqueue/customization/Layout.java b/src/main/java/me/contaria/seedqueue/customization/Layout.java index d14e8929..65323b1f 100644 --- a/src/main/java/me/contaria/seedqueue/customization/Layout.java +++ b/src/main/java/me/contaria/seedqueue/customization/Layout.java @@ -207,12 +207,14 @@ public static class CustomTextObject { public final Pos pos; public final int color; public final float lineSpacing; + public final boolean shadow; public final Path path; - CustomTextObject(Pos pos, int color, float lineSpacing, Path path) { + CustomTextObject(Pos pos, int color, float lineSpacing, boolean shadow, Path path) { this.pos = pos; this.color = color; this.lineSpacing = lineSpacing; + this.shadow = shadow; this.path = path; } @@ -229,6 +231,7 @@ private static CustomTextObject fromJson(JsonObject jsonObject) throws JsonParse Pos.fromJson(jsonObject), getColor(jsonObject), jsonObject.has("lineSpacing") ? jsonObject.get("lineSpacing").getAsFloat() : 9.0f, + jsonObject.has("shadow") && jsonObject.get("shadow").getAsBoolean(), Paths.get(jsonObject.get("path").getAsString()) ); } diff --git a/src/main/java/me/contaria/seedqueue/gui/wall/SeedQueueWallScreen.java b/src/main/java/me/contaria/seedqueue/gui/wall/SeedQueueWallScreen.java index 161297d2..c00f68df 100644 --- a/src/main/java/me/contaria/seedqueue/gui/wall/SeedQueueWallScreen.java +++ b/src/main/java/me/contaria/seedqueue/gui/wall/SeedQueueWallScreen.java @@ -22,8 +22,7 @@ import net.minecraft.client.gui.hud.DebugHud; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.TitleScreen; -import net.minecraft.client.render.BufferBuilderStorage; -import net.minecraft.client.render.WorldRenderer; +import net.minecraft.client.render.*; import net.minecraft.client.util.Window; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.client.world.ClientWorld; @@ -265,7 +264,11 @@ private void drawCustomTextObject(MatrixStack matrices, Layout.CustomTextObject List lines = Files.readAllLines(customTextObject.path).stream().map(StringRenderable::plain).collect(Collectors.toList()); this.setViewport(customTextObject.pos); for (int i = 0; i < lines.size(); i++) { - this.client.textRenderer.draw(matrices, lines.get(i), 0, customTextObject.lineSpacing * i, customTextObject.color); + if (customTextObject.shadow) { + this.client.textRenderer.drawWithShadow(matrices, lines.get(i), 0, customTextObject.lineSpacing * i, customTextObject.color); + } else { + this.client.textRenderer.draw(matrices, lines.get(i), 0, customTextObject.lineSpacing * i, customTextObject.color); + } } this.resetViewport(); } catch (IOException e) {