Skip to content

Commit

Permalink
fix crafting widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
ghzdude committed Jan 10, 2025
1 parent f542e0b commit 0aa2de2
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,12 +33,14 @@ public class CraftingInputSlot extends Widget<CraftingOutputSlot> 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));
});
}

Expand All @@ -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);
Expand All @@ -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) {
Expand All @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,24 +25,25 @@ public class RecipeMemorySlot extends Widget<RecipeMemorySlot> 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
Expand All @@ -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));
}
Expand Down

0 comments on commit 0aa2de2

Please sign in to comment.