From 6b32a9207bb40f36abe90821d49c4cb349a76069 Mon Sep 17 00:00:00 2001 From: LatvianModder Date: Tue, 23 Jul 2024 12:30:27 +0300 Subject: [PATCH] Fixed custom stack size text offset. moved some configs to client --- .../java/dev/latvian/mods/kubejs/CommonProperties.java | 2 -- .../dev/latvian/mods/kubejs/client/ClientProperties.java | 4 ++++ .../java/dev/latvian/mods/kubejs/client/KubeJSClient.java | 8 ++++---- .../latvian/mods/kubejs/core/mixin/GuiGraphicsMixin.java | 3 ++- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main/java/dev/latvian/mods/kubejs/CommonProperties.java b/src/main/java/dev/latvian/mods/kubejs/CommonProperties.java index e6e7de864..cea520581 100644 --- a/src/main/java/dev/latvian/mods/kubejs/CommonProperties.java +++ b/src/main/java/dev/latvian/mods/kubejs/CommonProperties.java @@ -37,7 +37,6 @@ public static void reload() { public String startupErrorReportUrl; public boolean removeSlotLimit; public int defaultMaxStackSize; - public boolean customStackSizeText; public JsonElement creativeModeTabIcon; public JsonElement creativeModeTabName; @@ -59,7 +58,6 @@ protected void load() { startupErrorReportUrl = get("startup_error_report_url", ""); removeSlotLimit = get("remove_slot_limit", false); defaultMaxStackSize = Math.max(0, Math.min(1_000_000_000, get("default_max_stack_size", 0))); - customStackSizeText = get("custom_stack_size_text", true); creativeModeTabIcon = get("creative_mode_tab_icon", new JsonObject()); creativeModeTabName = get("creative_mode_tab_name", JsonNull.INSTANCE); diff --git a/src/main/java/dev/latvian/mods/kubejs/client/ClientProperties.java b/src/main/java/dev/latvian/mods/kubejs/client/ClientProperties.java index 21b777ef7..a8dfebf70 100644 --- a/src/main/java/dev/latvian/mods/kubejs/client/ClientProperties.java +++ b/src/main/java/dev/latvian/mods/kubejs/client/ClientProperties.java @@ -34,6 +34,8 @@ public static void reload() { // public int menuInnerBackgroundBrightness; // public float menuBackgroundScale; public boolean blurScaledPackIcon; + public boolean customStackSizeText; + public boolean shrinkStackSizeText; private ClientProperties() { super(KubeJSPaths.CLIENT_PROPERTIES, "KubeJS Client Properties"); @@ -54,6 +56,8 @@ protected void load() { // menuInnerBackgroundBrightness = Mth.clamp(get("menuInnerBackgroundBrightness", 32), 0, 255); // menuBackgroundScale = (float) Mth.clamp(get("menuBackgroundScale", 32D), 0.0625D, 1024D); blurScaledPackIcon = get("blur_scaled_pack_icon", true); + customStackSizeText = get("custom_stack_size_text", true); + shrinkStackSizeText = get("shrink_stack_size_text", true); } /* diff --git a/src/main/java/dev/latvian/mods/kubejs/client/KubeJSClient.java b/src/main/java/dev/latvian/mods/kubejs/client/KubeJSClient.java index 9798b7279..8ebc93d96 100644 --- a/src/main/java/dev/latvian/mods/kubejs/client/KubeJSClient.java +++ b/src/main/java/dev/latvian/mods/kubejs/client/KubeJSClient.java @@ -210,12 +210,12 @@ public static String formatNumber(int count) { public static int drawStackSize(GuiGraphics graphics, Font font, int size, int x, int y, int color, boolean dropShadow) { var str = formatNumber(size); - float scale = str.length() >= 4 ? 0.5F : str.length() == 3 ? 0.75F : 1F; + int w = font.width(str); + float scale = ClientProperties.get().shrinkStackSizeText ? (str.length() >= 4 ? 0.5F : str.length() == 3 ? 0.75F : 1F) : 1F; graphics.pose().pushPose(); - graphics.pose().translate(x + 16F, y + 16F, 0F); + graphics.pose().translate((int) (x + 16F - (w - 1F) * scale), (int) (y + 16F - 7F * scale), 0F); graphics.pose().scale(scale, scale, 1F); - int w = font.width(str); - int s = graphics.drawString(font, str, -w, -8F, color, dropShadow); + int s = graphics.drawString(font, str, 0F, 0F, color, dropShadow); graphics.pose().popPose(); return Mth.ceil(s * scale); } diff --git a/src/main/java/dev/latvian/mods/kubejs/core/mixin/GuiGraphicsMixin.java b/src/main/java/dev/latvian/mods/kubejs/core/mixin/GuiGraphicsMixin.java index 828d3c32c..8353279b6 100644 --- a/src/main/java/dev/latvian/mods/kubejs/core/mixin/GuiGraphicsMixin.java +++ b/src/main/java/dev/latvian/mods/kubejs/core/mixin/GuiGraphicsMixin.java @@ -1,6 +1,7 @@ package dev.latvian.mods.kubejs.core.mixin; import dev.latvian.mods.kubejs.CommonProperties; +import dev.latvian.mods.kubejs.client.ClientProperties; import dev.latvian.mods.kubejs.client.KubeJSClient; import net.minecraft.client.gui.Font; import net.minecraft.client.gui.GuiGraphics; @@ -19,7 +20,7 @@ public abstract class GuiGraphicsMixin { @Inject(method = "renderItemDecorations(Lnet/minecraft/client/gui/Font;Lnet/minecraft/world/item/ItemStack;IILjava/lang/String;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;drawString(Lnet/minecraft/client/gui/Font;Ljava/lang/String;IIIZ)I", shift = At.Shift.BEFORE)) private void kjs$beforeDrawSize(Font font, ItemStack stack, int x, int y, String text, CallbackInfo ci) { - if (text == null && CommonProperties.get().removeSlotLimit && CommonProperties.get().customStackSizeText && stack.getCount() > 1) { + if (text == null && CommonProperties.get().removeSlotLimit && ClientProperties.get().customStackSizeText && stack.getCount() > 1) { kjs$itemSize[0] = stack.getCount(); kjs$itemSize[1] = x; kjs$itemSize[2] = y;