Skip to content

Commit

Permalink
Fixed custom stack size text offset. moved some configs to client
Browse files Browse the repository at this point in the history
  • Loading branch information
LatvianModder committed Jul 23, 2024
1 parent 2313238 commit 6b32a92
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
2 changes: 0 additions & 2 deletions src/main/java/dev/latvian/mods/kubejs/CommonProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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);
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 6b32a92

Please sign in to comment.