From c559af443219ab74ad151fe837e62e0a31b364bf Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Fri, 19 Sep 2025 19:41:46 -0700 Subject: [PATCH 01/11] make bottom/center alignments to top before drawing --- .../common/mui/widget/ScrollableTextWidget.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/gregtech/common/mui/widget/ScrollableTextWidget.java b/src/main/java/gregtech/common/mui/widget/ScrollableTextWidget.java index a20bfc92a41..da54f25850c 100644 --- a/src/main/java/gregtech/common/mui/widget/ScrollableTextWidget.java +++ b/src/main/java/gregtech/common/mui/widget/ScrollableTextWidget.java @@ -18,6 +18,7 @@ import com.cleanroommc.modularui.screen.ModularScreen; import com.cleanroommc.modularui.screen.RichTooltip; import com.cleanroommc.modularui.screen.viewport.ModularGuiContext; +import com.cleanroommc.modularui.utils.Alignment; import com.cleanroommc.modularui.utils.HoveredWidgetList; import com.cleanroommc.modularui.widget.Widget; import com.cleanroommc.modularui.widget.scroll.ScrollArea; @@ -173,6 +174,17 @@ private void drawText(ModularGuiContext context) { } this.dirty = false; } + // center and bottom alignments cause issues with the text renderer + // when drawing in a scrolling context + // they draw the text higher than expected + if (this.text.getAlignment().y > 0f) { // not top + int type = (int) (this.text.getAlignment().x * 2); + switch (type) { + case 1 -> this.text.alignment(Alignment.TopCenter); + case 2 -> this.text.alignment(Alignment.TopRight); + default -> this.text.alignment(Alignment.TopLeft); + } + } this.text.setupRenderer(this.renderer, getArea().getPadding().left, getArea().getPadding().top - getScrollY(), getArea().paddedWidth(), getArea().paddedHeight(), getWidgetTheme(context.getTheme()).getTextColor(), From 2a54ef8e22ef25be5ec195a01011621f3cb0d252 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Fri, 19 Sep 2025 19:52:48 -0700 Subject: [PATCH 02/11] extend TextRenderer instead --- .../mui/widget/ScrollableTextWidget.java | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/main/java/gregtech/common/mui/widget/ScrollableTextWidget.java b/src/main/java/gregtech/common/mui/widget/ScrollableTextWidget.java index da54f25850c..ded17595f6f 100644 --- a/src/main/java/gregtech/common/mui/widget/ScrollableTextWidget.java +++ b/src/main/java/gregtech/common/mui/widget/ScrollableTextWidget.java @@ -40,7 +40,7 @@ public class ScrollableTextWidget extends Widget private Object lastIngredient; private final ScrollArea scroll = new ScrollArea(); - private final TextRenderer renderer = new TextRenderer(); + private final TextRenderer renderer = new ScrollingTextRenderer(); public ScrollableTextWidget() { listenGuiAction((IGuiAction.MouseReleased) mouseButton -> { @@ -174,17 +174,6 @@ private void drawText(ModularGuiContext context) { } this.dirty = false; } - // center and bottom alignments cause issues with the text renderer - // when drawing in a scrolling context - // they draw the text higher than expected - if (this.text.getAlignment().y > 0f) { // not top - int type = (int) (this.text.getAlignment().x * 2); - switch (type) { - case 1 -> this.text.alignment(Alignment.TopCenter); - case 2 -> this.text.alignment(Alignment.TopRight); - default -> this.text.alignment(Alignment.TopLeft); - } - } this.text.setupRenderer(this.renderer, getArea().getPadding().left, getArea().getPadding().top - getScrollY(), getArea().paddedWidth(), getArea().paddedHeight(), getWidgetTheme(context.getTheme()).getTextColor(), @@ -240,4 +229,20 @@ public ScrollableTextWidget textBuilder(Consumer builder) { public @Nullable Object getIngredient() { return this.lastIngredient; } + + public static class ScrollingTextRenderer extends TextRenderer { + + public int getLastY() { + return (int) lastY; + } + + public int getLastX() { + return (int) lastX; + } + + @Override + protected int getStartY(float height) { + return this.y; // always draw at the top + } + } } From a4ba4ab8f24167a28fabbef4e6d590a2eb5f6748 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Fri, 19 Sep 2025 20:07:00 -0700 Subject: [PATCH 03/11] sobls --- .../java/gregtech/common/mui/widget/ScrollableTextWidget.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/gregtech/common/mui/widget/ScrollableTextWidget.java b/src/main/java/gregtech/common/mui/widget/ScrollableTextWidget.java index ded17595f6f..42b18db42f5 100644 --- a/src/main/java/gregtech/common/mui/widget/ScrollableTextWidget.java +++ b/src/main/java/gregtech/common/mui/widget/ScrollableTextWidget.java @@ -18,7 +18,6 @@ import com.cleanroommc.modularui.screen.ModularScreen; import com.cleanroommc.modularui.screen.RichTooltip; import com.cleanroommc.modularui.screen.viewport.ModularGuiContext; -import com.cleanroommc.modularui.utils.Alignment; import com.cleanroommc.modularui.utils.HoveredWidgetList; import com.cleanroommc.modularui.widget.Widget; import com.cleanroommc.modularui.widget.scroll.ScrollArea; From fc83635e85fbb592ce8fcd84ca77125fe427993a Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Sun, 26 Oct 2025 22:16:23 -0700 Subject: [PATCH 04/11] add simulate to text draw "improve" fix to drawing scrolling text remove dirty field from ui builder --- .../multiblock/ui/MultiblockUIBuilder.java | 31 ++++---- .../multiblock/ui/MultiblockUIFactory.java | 4 +- .../mui/widget/ScrollableTextWidget.java | 71 ++++++++++++++----- 3 files changed, 73 insertions(+), 33 deletions(-) diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/ui/MultiblockUIBuilder.java b/src/main/java/gregtech/api/metatileentity/multiblock/ui/MultiblockUIBuilder.java index 2dd58a00df4..a46febccd1d 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/ui/MultiblockUIBuilder.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/ui/MultiblockUIBuilder.java @@ -20,6 +20,7 @@ import gregtech.api.util.function.FloatSupplier; import gregtech.common.ConfigHolder; import gregtech.common.items.ToolItems; +import gregtech.common.mui.widget.ScrollableTextWidget; import net.minecraft.item.ItemStack; import net.minecraft.network.PacketBuffer; @@ -77,8 +78,8 @@ public class MultiblockUIBuilder { private IKey idlingKey = IKey.lang("gregtech.multiblock.idling").style(TextFormatting.GRAY); private IKey pausedKey = IKey.lang("gregtech.multiblock.work_paused").style(TextFormatting.GOLD); private IKey runningKey = IKey.lang("gregtech.multiblock.running").style(TextFormatting.GREEN); - private boolean dirty; private Runnable onRebuild; + private Runnable postRebuild; @NotNull InternalSyncer getSyncer() { @@ -797,18 +798,11 @@ public void sync(String key, PanelSyncManager syncManager) { } /** - * Builds the passed in rich text with operations and drawables.
- * Will clear and rebuild if this builder is marked dirty + * Builds the passed in rich text with operations and drawables. * * @param richText the rich text to add drawables to */ public void build(IRichTextBuilder richText) { - if (dirty) { - clear(); - onRebuild(); - runAction(); - dirty = false; - } for (Operation op : operations) { op.accept(richText); } @@ -820,11 +814,10 @@ private void onRebuild() { } } - /** - * Mark this builder as dirty. Will be rebuilt during {@link #build(IRichTextBuilder) build()} - */ - public void markDirty() { - dirty = true; + private void postRebuild() { + if (this.postRebuild != null) { + this.postRebuild.run(); + } } /* @@ -855,6 +848,15 @@ public void onRebuild(Runnable onRebuild) { this.onRebuild = onRebuild; } + /** + * The runnable is called after rebuilding, usually used for {@link ScrollableTextWidget#postRebuild()} + * + * @param postRebuild the runnable to run after rebuilding + */ + public void postRebuild(Runnable postRebuild) { + this.postRebuild = postRebuild; + } + private void addHoverableKey(IKey key, IDrawable... hover) { if (isServer()) return; addKey(KeyUtil.setHover(key, hover)); @@ -1042,6 +1044,7 @@ public void readOnClient(int id, PacketBuffer buf) { getSyncer().readBuffer(buf); onRebuild(); runAction(); + postRebuild(); } } diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/ui/MultiblockUIFactory.java b/src/main/java/gregtech/api/metatileentity/multiblock/ui/MultiblockUIFactory.java index 495a80a8aa8..87166d910f1 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/ui/MultiblockUIFactory.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/ui/MultiblockUIFactory.java @@ -360,9 +360,9 @@ protected Widget createScreen(PanelSyncManager syncManager) { .debugName("display_text") .sizeRel(1f) .alignment(Alignment.TopLeft) - .margin(4, 4) + .margin(4) .autoUpdate(true) - .textBuilder(display::build)); + .textBuilder(display)); } if (this.screenFunction != null) { diff --git a/src/main/java/gregtech/common/mui/widget/ScrollableTextWidget.java b/src/main/java/gregtech/common/mui/widget/ScrollableTextWidget.java index 42b18db42f5..ce6c490d96e 100644 --- a/src/main/java/gregtech/common/mui/widget/ScrollableTextWidget.java +++ b/src/main/java/gregtech/common/mui/widget/ScrollableTextWidget.java @@ -1,5 +1,6 @@ package gregtech.common.mui.widget; +import gregtech.api.metatileentity.multiblock.ui.MultiblockUIBuilder; import gregtech.api.mui.IconAcessor; import net.minecraft.client.gui.FontRenderer; @@ -18,24 +19,26 @@ import com.cleanroommc.modularui.screen.ModularScreen; import com.cleanroommc.modularui.screen.RichTooltip; import com.cleanroommc.modularui.screen.viewport.ModularGuiContext; +import com.cleanroommc.modularui.theme.WidgetTheme; +import com.cleanroommc.modularui.utils.Alignment; import com.cleanroommc.modularui.utils.HoveredWidgetList; import com.cleanroommc.modularui.widget.Widget; import com.cleanroommc.modularui.widget.scroll.ScrollArea; import com.cleanroommc.modularui.widget.scroll.ScrollData; import com.cleanroommc.modularui.widget.sizer.Area; +import com.cleanroommc.modularui.widget.sizer.Box; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.function.Consumer; - public class ScrollableTextWidget extends Widget implements IRichTextBuilder, Interactable, IViewport, JeiIngredientProvider { private final RichText text = new RichText(); - private Consumer builder; + private MultiblockUIBuilder builder; private boolean dirty = false; private boolean autoUpdate = false; + private boolean initScroll; private Object lastIngredient; private final ScrollArea scroll = new ScrollArea(); @@ -161,26 +164,60 @@ public void preDraw(ModularGuiContext context, boolean transformed) { if (!transformed) { Stencil.applyAtZero(this.scroll, context); } else { - drawText(context); + drawText(context, false); } } - private void drawText(ModularGuiContext context) { + public void postRebuild() { + if (initScroll || !isValid()) return; + initScroll = true; + + // i really hate how this is done but it works + // this is responsible for scrolling to the right value on ui ope + // eg half-way for center, and at the bottom for bottom alignments + drawText(getContext(), true); + int size = this.scroll.getScrollY().getScrollSize(); + if (size <= getArea().h()) return; + size -= getArea().h(); + + Alignment alignment = this.text.getAlignment(); + int scroll = (int) (size * alignment.y); + this.scroll.getScrollY().scrollTo(this.scroll, scroll); + } + + private void drawText(ModularGuiContext context, boolean simulate) { if (this.autoUpdate || this.dirty) { if (this.builder != null) { this.text.clearText(); - this.builder.accept(this.text); + this.builder.build(this.text); } this.dirty = false; } - this.text.setupRenderer(this.renderer, getArea().getPadding().left, getArea().getPadding().top - getScrollY(), - getArea().paddedWidth(), getArea().paddedHeight(), - getWidgetTheme(context.getTheme()).getTextColor(), - getWidgetTheme(context.getTheme()).getTextShadow()); - this.text.compileAndDraw(this.renderer, context, false); + + Alignment alignment = this.text.getAlignment(); + Area area = getArea(); + Box padding = area.getPadding(); + WidgetTheme widgetTheme = getWidgetTheme(context.getTheme()); + + this.text.compileAndDraw(this.renderer, context, true); + // this isn't perfect, but i hope it's good enough - int diff = (int) Math.ceil((this.renderer.getLastHeight() - getArea().h()) / 2); - this.scroll.getScrollY().setScrollSize(getArea().h() + Math.max(0, diff)); + int diff = (int) Math.ceil((this.renderer.getLastHeight() - area.h()) / 2); + this.scroll.getScrollY().setScrollSize(area.h() + Math.max(0, diff)); + + if (!simulate) { + // this is responsible for centering the text if there's not enough to scroll + int x = padding.left; + int y = (int) (area.h() * alignment.y); + if (alignment.y == 0.5f) y -= (int) (this.renderer.getLastHeight() / 2); + y = Math.min(Math.max(padding.top, y), area.h() - padding.bottom); + if (alignment.y > 0.5f) y -= area.h(); // why? + this.text.setupRenderer(this.renderer, x, y - getScrollY(), + area.paddedWidth(), area.paddedHeight(), + widgetTheme.getTextColor(), widgetTheme.getTextShadow()); + + this.text.compileAndDraw(this.renderer, context, false); + } } @Override @@ -215,11 +252,11 @@ public ScrollableTextWidget autoUpdate(boolean autoUpdate) { /** * A builder which is called every time before drawing when {@link #dirty} is true. * - * @param builder text builder - * @return this + * @param uiBuilder@return this */ - public ScrollableTextWidget textBuilder(Consumer builder) { - this.builder = builder; + public ScrollableTextWidget textBuilder(MultiblockUIBuilder uiBuilder) { + this.builder = uiBuilder; + this.builder.postRebuild(this::postRebuild); markDirty(); return this; } From 3000bd7db59b5b0ed2d56a445f874d53f07b13a4 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Sun, 26 Oct 2025 22:25:31 -0700 Subject: [PATCH 05/11] simplify and improve fix --- .../multiblock/ui/MultiblockUIFactory.java | 2 +- .../mui/widget/ScrollableTextWidget.java | 59 ++++++------------- 2 files changed, 20 insertions(+), 41 deletions(-) diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/ui/MultiblockUIFactory.java b/src/main/java/gregtech/api/metatileentity/multiblock/ui/MultiblockUIFactory.java index 87166d910f1..44e5f797e28 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/ui/MultiblockUIFactory.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/ui/MultiblockUIFactory.java @@ -362,7 +362,7 @@ protected Widget createScreen(PanelSyncManager syncManager) { .alignment(Alignment.TopLeft) .margin(4) .autoUpdate(true) - .textBuilder(display)); + .textBuilder(display::build)); } if (this.screenFunction != null) { diff --git a/src/main/java/gregtech/common/mui/widget/ScrollableTextWidget.java b/src/main/java/gregtech/common/mui/widget/ScrollableTextWidget.java index ce6c490d96e..2306d8b96ec 100644 --- a/src/main/java/gregtech/common/mui/widget/ScrollableTextWidget.java +++ b/src/main/java/gregtech/common/mui/widget/ScrollableTextWidget.java @@ -1,6 +1,5 @@ package gregtech.common.mui.widget; -import gregtech.api.metatileentity.multiblock.ui.MultiblockUIBuilder; import gregtech.api.mui.IconAcessor; import net.minecraft.client.gui.FontRenderer; @@ -30,15 +29,16 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.function.Consumer; + public class ScrollableTextWidget extends Widget implements IRichTextBuilder, Interactable, IViewport, JeiIngredientProvider { private final RichText text = new RichText(); - private MultiblockUIBuilder builder; + private Consumer> builder; private boolean dirty = false; private boolean autoUpdate = false; - private boolean initScroll; private Object lastIngredient; private final ScrollArea scroll = new ScrollArea(); @@ -164,32 +164,15 @@ public void preDraw(ModularGuiContext context, boolean transformed) { if (!transformed) { Stencil.applyAtZero(this.scroll, context); } else { - drawText(context, false); + drawText(context); } } - public void postRebuild() { - if (initScroll || !isValid()) return; - initScroll = true; - - // i really hate how this is done but it works - // this is responsible for scrolling to the right value on ui ope - // eg half-way for center, and at the bottom for bottom alignments - drawText(getContext(), true); - int size = this.scroll.getScrollY().getScrollSize(); - if (size <= getArea().h()) return; - size -= getArea().h(); - - Alignment alignment = this.text.getAlignment(); - int scroll = (int) (size * alignment.y); - this.scroll.getScrollY().scrollTo(this.scroll, scroll); - } - - private void drawText(ModularGuiContext context, boolean simulate) { + private void drawText(ModularGuiContext context) { if (this.autoUpdate || this.dirty) { if (this.builder != null) { this.text.clearText(); - this.builder.build(this.text); + this.builder.accept(this.text); } this.dirty = false; } @@ -205,19 +188,16 @@ private void drawText(ModularGuiContext context, boolean simulate) { int diff = (int) Math.ceil((this.renderer.getLastHeight() - area.h()) / 2); this.scroll.getScrollY().setScrollSize(area.h() + Math.max(0, diff)); - if (!simulate) { - // this is responsible for centering the text if there's not enough to scroll - int x = padding.left; - int y = (int) (area.h() * alignment.y); - if (alignment.y == 0.5f) y -= (int) (this.renderer.getLastHeight() / 2); - y = Math.min(Math.max(padding.top, y), area.h() - padding.bottom); - if (alignment.y > 0.5f) y -= area.h(); // why? - this.text.setupRenderer(this.renderer, x, y - getScrollY(), - area.paddedWidth(), area.paddedHeight(), - widgetTheme.getTextColor(), widgetTheme.getTextShadow()); - - this.text.compileAndDraw(this.renderer, context, false); - } + // this is responsible for centering the text if there's not enough to scroll + int x = padding.left; + int y = (int) (area.h() * alignment.y); + y -= (int) (this.renderer.getLastHeight() * alignment.y); + y = Math.min(Math.max(padding.top, y), area.h() - padding.bottom); + this.text.setupRenderer(this.renderer, x, y - getScrollY(), + area.paddedWidth(), area.paddedHeight(), + widgetTheme.getTextColor(), widgetTheme.getTextShadow()); + + this.text.compileAndDraw(this.renderer, context, false); } @Override @@ -252,11 +232,10 @@ public ScrollableTextWidget autoUpdate(boolean autoUpdate) { /** * A builder which is called every time before drawing when {@link #dirty} is true. * - * @param uiBuilder@return this + * @param builder@return this */ - public ScrollableTextWidget textBuilder(MultiblockUIBuilder uiBuilder) { - this.builder = uiBuilder; - this.builder.postRebuild(this::postRebuild); + public ScrollableTextWidget textBuilder(Consumer> builder) { + this.builder = builder; markDirty(); return this; } From 57d104c50ec81914a485415df2cd2eb1709d3cee Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Sun, 26 Oct 2025 22:28:58 -0700 Subject: [PATCH 06/11] fix javadoc --- .../java/gregtech/common/mui/widget/ScrollableTextWidget.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/gregtech/common/mui/widget/ScrollableTextWidget.java b/src/main/java/gregtech/common/mui/widget/ScrollableTextWidget.java index 2306d8b96ec..5d57f8ec5bf 100644 --- a/src/main/java/gregtech/common/mui/widget/ScrollableTextWidget.java +++ b/src/main/java/gregtech/common/mui/widget/ScrollableTextWidget.java @@ -232,7 +232,8 @@ public ScrollableTextWidget autoUpdate(boolean autoUpdate) { /** * A builder which is called every time before drawing when {@link #dirty} is true. * - * @param builder@return this + * @param builder text builder + * @return this */ public ScrollableTextWidget textBuilder(Consumer> builder) { this.builder = builder; From 5b6fd361f11bfe465c14ce1b07af2926c6653b25 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Sat, 1 Nov 2025 16:03:09 -0700 Subject: [PATCH 07/11] remove unused postBuild --- .../multiblock/ui/MultiblockUIBuilder.java | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/ui/MultiblockUIBuilder.java b/src/main/java/gregtech/api/metatileentity/multiblock/ui/MultiblockUIBuilder.java index a46febccd1d..8b7a3a5c62d 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/ui/MultiblockUIBuilder.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/ui/MultiblockUIBuilder.java @@ -20,7 +20,6 @@ import gregtech.api.util.function.FloatSupplier; import gregtech.common.ConfigHolder; import gregtech.common.items.ToolItems; -import gregtech.common.mui.widget.ScrollableTextWidget; import net.minecraft.item.ItemStack; import net.minecraft.network.PacketBuffer; @@ -814,12 +813,6 @@ private void onRebuild() { } } - private void postRebuild() { - if (this.postRebuild != null) { - this.postRebuild.run(); - } - } - /* * this is run on the server side to write values to the internal syncer * those values are then synced to the client and read back in the same order @@ -848,17 +841,7 @@ public void onRebuild(Runnable onRebuild) { this.onRebuild = onRebuild; } - /** - * The runnable is called after rebuilding, usually used for {@link ScrollableTextWidget#postRebuild()} - * - * @param postRebuild the runnable to run after rebuilding - */ - public void postRebuild(Runnable postRebuild) { - this.postRebuild = postRebuild; - } - private void addHoverableKey(IKey key, IDrawable... hover) { - if (isServer()) return; addKey(KeyUtil.setHover(key, hover)); } @@ -1044,7 +1027,6 @@ public void readOnClient(int id, PacketBuffer buf) { getSyncer().readBuffer(buf); onRebuild(); runAction(); - postRebuild(); } } From f01afbeeb77facf9eb2d02f7b365cf7ba4e41f90 Mon Sep 17 00:00:00 2001 From: Zorbatron <46525467+Zorbatron@users.noreply.github.com> Date: Sun, 16 Nov 2025 20:58:49 -0500 Subject: [PATCH 08/11] Post merge fixes --- src/main/java/gregtech/api/capability/IMiner.java | 4 ++-- .../multiblock/ui/MultiblockUIFactory.java | 2 +- .../common/mui/widget/ScrollableTextWidget.java | 14 +++++++------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/gregtech/api/capability/IMiner.java b/src/main/java/gregtech/api/capability/IMiner.java index 837ee9fd161..5d1fd04553f 100644 --- a/src/main/java/gregtech/api/capability/IMiner.java +++ b/src/main/java/gregtech/api/capability/IMiner.java @@ -5,8 +5,8 @@ import net.minecraftforge.items.IItemHandlerModifiable; import codechicken.lib.vec.Cuboid6; +import com.cleanroommc.modularui.api.drawable.IRichTextBuilder; import com.cleanroommc.modularui.drawable.UITexture; -import com.cleanroommc.modularui.drawable.text.RichText; import com.cleanroommc.modularui.utils.Alignment; import com.cleanroommc.modularui.value.sync.PanelSyncManager; import com.cleanroommc.modularui.value.sync.SyncHandlers; @@ -39,7 +39,7 @@ default int getWorkingArea(int maximumRadius) { default Widget createMinerWidgets(@NotNull PanelSyncManager panelSyncManager, @NotNull IItemHandlerModifiable inventory, int inventorySize, @NotNull UITexture textDisplayBackground, - @NotNull Consumer textBuilder) { + @NotNull Consumer> textBuilder) { int rowSize = (int) Math.sqrt(inventorySize); panelSyncManager.registerSlotGroup("export_items", rowSize); diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/ui/MultiblockUIFactory.java b/src/main/java/gregtech/api/metatileentity/multiblock/ui/MultiblockUIFactory.java index bdd21a36b27..bf73d4557f1 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/ui/MultiblockUIFactory.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/ui/MultiblockUIFactory.java @@ -359,7 +359,7 @@ protected Widget createScreen(PanelSyncManager syncManager) { parent.child(new ScrollableTextWidget() .debugName("display_text") .sizeRel(1f) - .alignment(Alignment.TopLeft) + .alignment(Alignment.Center) .margin(4) .autoUpdate(true) .textBuilder(display::build)); diff --git a/src/main/java/gregtech/common/mui/widget/ScrollableTextWidget.java b/src/main/java/gregtech/common/mui/widget/ScrollableTextWidget.java index 3dbf5137ad2..4197b30c5a2 100644 --- a/src/main/java/gregtech/common/mui/widget/ScrollableTextWidget.java +++ b/src/main/java/gregtech/common/mui/widget/ScrollableTextWidget.java @@ -181,7 +181,8 @@ private void drawText(ModularGuiContext context) { Alignment alignment = this.text.getAlignment(); Area area = getArea(); Box padding = area.getPadding(); - WidgetTheme widgetTheme = getWidgetTheme(context.getTheme()); + WidgetThemeEntry textThemeEntry = context.getTheme().getTextFieldTheme(); + TextFieldTheme textTheme = textThemeEntry.getTheme(); this.text.compileAndDraw(this.renderer, context, true); @@ -190,13 +191,12 @@ private void drawText(ModularGuiContext context) { this.scroll.getScrollY().setScrollSize(area.h() + Math.max(0, diff)); // this is responsible for centering the text if there's not enough to scroll - int x = padding.left; + int x = padding.getLeft(); int y = (int) (area.h() * alignment.y); - y -= (int) (this.renderer.getLastHeight() * alignment.y); - y = Math.min(Math.max(padding.top, y), area.h() - padding.bottom); - this.text.setupRenderer(this.renderer, x, y - getScrollY(), - area.paddedWidth(), area.paddedHeight(), - widgetTheme.getTextColor(), widgetTheme.getTextShadow()); + y -= (int) (this.renderer.getLastTrimmedHeight() * alignment.y); + y = Math.min(Math.max(padding.getTop(), y), area.h() - padding.getBottom()); + this.text.setupRenderer(this.renderer, x, y - getScrollY(), area.paddedWidth(), area.paddedHeight(), + textTheme.getTextColor(), textTheme.getTextShadow()); this.text.compileAndDraw(this.renderer, context, false); } From c4ca8837cf23513dd368138a846c3a87cff60a64 Mon Sep 17 00:00:00 2001 From: Zorbatron <46525467+Zorbatron@users.noreply.github.com> Date: Sun, 16 Nov 2025 22:27:15 -0500 Subject: [PATCH 09/11] Fix the starting x position of center or right aligned text not using the max width of the entire rendering area. --- .../gregtech/common/mui/widget/ScrollableTextWidget.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/gregtech/common/mui/widget/ScrollableTextWidget.java b/src/main/java/gregtech/common/mui/widget/ScrollableTextWidget.java index 4197b30c5a2..5d21696125b 100644 --- a/src/main/java/gregtech/common/mui/widget/ScrollableTextWidget.java +++ b/src/main/java/gregtech/common/mui/widget/ScrollableTextWidget.java @@ -250,6 +250,11 @@ public ScrollableTextWidget textBuilder(Consumer> builder) { public static class ScrollingTextRenderer extends TextRenderer { + @Override + protected int getStartX(float maxWidth, float lineWidth) { + return super.getStartX(this.maxWidth, lineWidth); + } + public int getLastY() { return (int) lastY; } From 5b4efa37a69b87a81bb3e08e9ef8c0ff5a646e51 Mon Sep 17 00:00:00 2001 From: Zorbatron <46525467+Zorbatron@users.noreply.github.com> Date: Sun, 16 Nov 2025 22:28:57 -0500 Subject: [PATCH 10/11] Undo testing change to MultiblockUIFactory --- .../api/metatileentity/multiblock/ui/MultiblockUIFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/ui/MultiblockUIFactory.java b/src/main/java/gregtech/api/metatileentity/multiblock/ui/MultiblockUIFactory.java index bf73d4557f1..bdd21a36b27 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/ui/MultiblockUIFactory.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/ui/MultiblockUIFactory.java @@ -359,7 +359,7 @@ protected Widget createScreen(PanelSyncManager syncManager) { parent.child(new ScrollableTextWidget() .debugName("display_text") .sizeRel(1f) - .alignment(Alignment.Center) + .alignment(Alignment.TopLeft) .margin(4) .autoUpdate(true) .textBuilder(display::build)); From b3a5c89d48f93c8dd43e693db5a5fae01d833ecf Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Sun, 16 Nov 2025 20:46:03 -0700 Subject: [PATCH 11/11] remove unused field --- .../api/metatileentity/multiblock/ui/MultiblockUIBuilder.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/ui/MultiblockUIBuilder.java b/src/main/java/gregtech/api/metatileentity/multiblock/ui/MultiblockUIBuilder.java index 0f80687a45f..e4f0bc5acf8 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/ui/MultiblockUIBuilder.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/ui/MultiblockUIBuilder.java @@ -78,7 +78,6 @@ public class MultiblockUIBuilder { private IKey pausedKey = IKey.lang("gregtech.multiblock.work_paused").style(TextFormatting.GOLD); private IKey runningKey = IKey.lang("gregtech.multiblock.running").style(TextFormatting.GREEN); private Runnable onRebuild; - private Runnable postRebuild; @NotNull InternalSyncer getSyncer() {