From 0aa2de299c75cf9e27402e381f55c8ae1d103dc8 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Thu, 9 Jan 2025 19:08:28 -0700 Subject: [PATCH] fix crafting widgets --- .../widget/workbench/CraftingInputSlot.java | 29 ++++++++++------- .../widget/workbench/CraftingOutputSlot.java | 32 +++++++++++-------- .../widget/workbench/RecipeMemorySlot.java | 27 ++++++++-------- 3 files changed, 50 insertions(+), 38 deletions(-) diff --git a/src/main/java/gregtech/common/mui/widget/workbench/CraftingInputSlot.java b/src/main/java/gregtech/common/mui/widget/workbench/CraftingInputSlot.java index 391eba14d62..86cdbb5569b 100644 --- a/src/main/java/gregtech/common/mui/widget/workbench/CraftingInputSlot.java +++ b/src/main/java/gregtech/common/mui/widget/workbench/CraftingInputSlot.java @@ -11,9 +11,8 @@ import com.cleanroommc.modularui.api.widget.Interactable; import com.cleanroommc.modularui.integration.jei.JeiGhostIngredientSlot; import com.cleanroommc.modularui.integration.jei.JeiIngredientProvider; -import com.cleanroommc.modularui.screen.GuiScreenWrapper; -import com.cleanroommc.modularui.screen.Tooltip; -import com.cleanroommc.modularui.screen.viewport.GuiContext; +import com.cleanroommc.modularui.screen.RichTooltip; +import com.cleanroommc.modularui.screen.viewport.ModularGuiContext; import com.cleanroommc.modularui.theme.WidgetTheme; import com.cleanroommc.modularui.value.sync.PanelSyncManager; import com.cleanroommc.modularui.value.sync.SyncHandler; @@ -34,12 +33,14 @@ public class CraftingInputSlot extends Widget implements Int public CraftingInputSlot(IItemHandlerModifiable handler, int index) { this.syncHandler = new InputSyncHandler(handler, index); setSyncHandler(this.syncHandler); - tooltip().setAutoUpdate(true).setHasTitleMargin(true); + tooltip().setAutoUpdate(true); + // .setHasTitleMargin(true); tooltipBuilder(tooltip -> { if (!isSynced()) return; ItemStack stack = this.syncHandler.getStack(); if (stack.isEmpty()) return; - tooltip.addStringLines(getScreen().getScreenWrapper().getItemToolTip(stack)); + tooltip.addFromItem(stack); + // tooltip.addStringLines(getScreen().getScreenWrapper().getItemToolTip(stack)); }); } @@ -49,6 +50,11 @@ public static CraftingInputSlot create(CraftingRecipeLogic logic, IItemHandlerMo return slot; } + @Override + public boolean isValidSyncHandler(SyncHandler syncHandler) { + return syncHandler instanceof InputSyncHandler; + } + @Override public void onInit() { getContext().getJeiSettings().addJeiGhostIngredientSlot(this); @@ -70,13 +76,12 @@ public Result onMousePressed(int mouseButton) { } @Override - public void draw(GuiContext context, WidgetTheme widgetTheme) { - GuiScreenWrapper guiScreen = getScreen().getScreenWrapper(); + public void draw(ModularGuiContext context, WidgetTheme widgetTheme) { + // GuiScreen guiScreen = getScreen().getScreenWrapper().getGuiScreen(); ItemStack itemstack = this.syncHandler.getStack(); if (itemstack.isEmpty()) return; - - guiScreen.getItemRenderer().zLevel = 0.0F; - guiScreen.setZ(0f); + // guiScreen.getItemRenderer().zLevel = 0.0F; + // guiScreen.setZ(0f); RenderUtil.renderItemInGUI(itemstack, 1, 1); if (!this.hasIngredients) { @@ -85,8 +90,8 @@ public void draw(GuiContext context, WidgetTheme widgetTheme) { } @Override - public void drawForeground(GuiContext context) { - Tooltip tooltip = getTooltip(); + public void drawForeground(ModularGuiContext context) { + RichTooltip tooltip = getTooltip(); if (tooltip != null && isHoveringFor(tooltip.getShowUpTimer())) { tooltip.draw(getContext(), this.syncHandler.getStack()); } diff --git a/src/main/java/gregtech/common/mui/widget/workbench/CraftingOutputSlot.java b/src/main/java/gregtech/common/mui/widget/workbench/CraftingOutputSlot.java index 5993c72b6ad..89684e662ba 100644 --- a/src/main/java/gregtech/common/mui/widget/workbench/CraftingOutputSlot.java +++ b/src/main/java/gregtech/common/mui/widget/workbench/CraftingOutputSlot.java @@ -17,9 +17,8 @@ import com.cleanroommc.modularui.api.widget.Interactable; import com.cleanroommc.modularui.integration.jei.JeiIngredientProvider; -import com.cleanroommc.modularui.screen.GuiScreenWrapper; -import com.cleanroommc.modularui.screen.Tooltip; -import com.cleanroommc.modularui.screen.viewport.GuiContext; +import com.cleanroommc.modularui.screen.RichTooltip; +import com.cleanroommc.modularui.screen.viewport.ModularGuiContext; import com.cleanroommc.modularui.theme.WidgetTheme; import com.cleanroommc.modularui.utils.MouseData; import com.cleanroommc.modularui.value.sync.IntSyncValue; @@ -48,15 +47,22 @@ public CraftingOutputSlot(IntSyncValue syncValue, MetaTileEntityWorkbench workbe workbench.getCraftingRecipeLogic().getCraftingResultInventory(), syncValue, workbench)); setSyncHandler(this.syncHandler); - tooltip().setAutoUpdate(true).setHasTitleMargin(true); + tooltip().setAutoUpdate(true); + // .setHasTitleMargin(true); tooltipBuilder(tooltip -> { if (!isSynced()) return; ItemStack stack = this.syncHandler.getOutputStack(); if (stack.isEmpty()) return; - tooltip.addStringLines(getScreen().getScreenWrapper().getItemToolTip(stack)); + tooltip.addFromItem(stack); + // tooltip.addStringLines(getScreen().getScreenWrapper().getItemToolTip(stack)); }); } + @Override + public boolean isValidSyncHandler(SyncHandler syncHandler) { + return syncHandler instanceof CraftingSlotSH; + } + @Override public @NotNull Result onMousePressed(int mouseButton) { MouseData mouseData = MouseData.create(mouseButton); @@ -65,23 +71,23 @@ public CraftingOutputSlot(IntSyncValue syncValue, MetaTileEntityWorkbench workbe } @Override - public void draw(GuiContext context, WidgetTheme widgetTheme) { - GuiScreenWrapper guiScreen = getScreen().getScreenWrapper(); + public void draw(ModularGuiContext context, WidgetTheme widgetTheme) { + // GuiScreenWrapper guiScreen = getScreen().getScreenWrapper(); ItemStack itemstack = this.syncHandler.getOutputStack(); if (itemstack.isEmpty()) return; - guiScreen.setZ(100f); - guiScreen.getItemRenderer().zLevel = 100.0F; + // guiScreen.setZ(100f); + // guiScreen.getItemRenderer().zLevel = 100.0F; RenderUtil.renderItemInGUI(itemstack, 1, 1); - guiScreen.getItemRenderer().zLevel = 0.0F; - guiScreen.setZ(0f); + // guiScreen.getItemRenderer().zLevel = 0.0F; + // guiScreen.setZ(0f); } @Override - public void drawForeground(GuiContext context) { - Tooltip tooltip = getTooltip(); + public void drawForeground(ModularGuiContext context) { + RichTooltip tooltip = getTooltip(); if (tooltip != null && isHoveringFor(tooltip.getShowUpTimer())) { tooltip.draw(getContext(), this.syncHandler.getOutputStack()); } diff --git a/src/main/java/gregtech/common/mui/widget/workbench/RecipeMemorySlot.java b/src/main/java/gregtech/common/mui/widget/workbench/RecipeMemorySlot.java index df0b13ff585..2c7754a37ba 100644 --- a/src/main/java/gregtech/common/mui/widget/workbench/RecipeMemorySlot.java +++ b/src/main/java/gregtech/common/mui/widget/workbench/RecipeMemorySlot.java @@ -7,11 +7,11 @@ import net.minecraft.client.renderer.GlStateManager; import net.minecraft.item.ItemStack; +import com.cleanroommc.modularui.api.MCHelper; import com.cleanroommc.modularui.api.drawable.IKey; import com.cleanroommc.modularui.api.widget.Interactable; -import com.cleanroommc.modularui.screen.GuiScreenWrapper; -import com.cleanroommc.modularui.screen.Tooltip; -import com.cleanroommc.modularui.screen.viewport.GuiContext; +import com.cleanroommc.modularui.screen.RichTooltip; +import com.cleanroommc.modularui.screen.viewport.ModularGuiContext; import com.cleanroommc.modularui.theme.WidgetTheme; import com.cleanroommc.modularui.utils.MouseData; import com.cleanroommc.modularui.widget.Widget; @@ -25,24 +25,25 @@ public class RecipeMemorySlot extends Widget implements Intera public RecipeMemorySlot(CraftingRecipeMemory memory, int index) { this.memory = memory; this.index = index; - tooltip().setAutoUpdate(true).setHasTitleMargin(true); + tooltip().setAutoUpdate(true); + // .setHasTitleMargin(true); tooltipBuilder(tooltip -> { var recipe = memory.getRecipeAtIndex(this.index); if (recipe == null) return; - var list = getScreen().getScreenWrapper().getItemToolTip(recipe.getRecipeResult()); + var list = MCHelper.getItemToolTip(recipe.getRecipeResult()); list.add(1, IKey.lang("Times Used: " + recipe.timesUsed).get()); tooltip.addStringLines(list); }); } @Override - public void draw(GuiContext context, WidgetTheme widgetTheme) { - GuiScreenWrapper guiScreen = getScreen().getScreenWrapper(); + public void draw(ModularGuiContext context, WidgetTheme widgetTheme) { + // GuiScreenWrapper guiScreen = getScreen().getScreenWrapper(); ItemStack itemstack = this.memory.getRecipeOutputAtIndex(this.index); if (itemstack.isEmpty()) return; - guiScreen.setZ(100f); - guiScreen.getItemRenderer().zLevel = 100.0F; + // guiScreen.setZ(100f); + // guiScreen.getItemRenderer().zLevel = 100.0F; int cachedCount = itemstack.getCount(); itemstack.setCount(1); // required to not render the amount overlay @@ -55,13 +56,13 @@ public void draw(GuiContext context, WidgetTheme widgetTheme) { GlStateManager.enableDepth(); } - guiScreen.getItemRenderer().zLevel = 0.0F; - guiScreen.setZ(0f); + // guiScreen.getItemRenderer().zLevel = 0.0F; + // guiScreen.setZ(0f); } @Override - public void drawForeground(GuiContext context) { - Tooltip tooltip = getTooltip(); + public void drawForeground(ModularGuiContext context) { + RichTooltip tooltip = getTooltip(); if (tooltip != null && isHoveringFor(tooltip.getShowUpTimer())) { tooltip.draw(getContext(), this.memory.getRecipeOutputAtIndex(this.index)); }