-
-
Notifications
You must be signed in to change notification settings - Fork 10
Show icons for crafting requirements #210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rubensworks
merged 5 commits into
master-1.21-lts
from
claude/integrated-terminals-206-crafting-requirement-icons
Aug 29, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
cb10b02
Show icons for crafting requirements
claude 6f65d3a
Merge remote-tracking branch 'origin/master-1.21-lts' into claude/int…
claude cb9c715
Group equal crafting requirements
claude 80efd65
Address review comments on crafting requirement icons
claude 3cfc4e4
Register tooltip component factories from the ClientProxy constructor
claude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
...yclops/integratedterminals/client/gui/tooltip/ClientCraftingOptionIngredientsTooltip.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| package org.cyclops.integratedterminals.client.gui.tooltip; | ||
|
|
||
| import net.minecraft.client.Minecraft; | ||
| import net.minecraft.client.gui.Font; | ||
| import net.minecraft.client.gui.GuiGraphics; | ||
| import net.minecraft.client.gui.screens.Screen; | ||
| import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; | ||
| import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent; | ||
| import net.minecraft.resources.ResourceLocation; | ||
| import net.neoforged.api.distmarker.Dist; | ||
| import net.neoforged.api.distmarker.OnlyIn; | ||
| import org.cyclops.commoncapabilities.api.ingredient.IPrototypedIngredient; | ||
| import org.cyclops.commoncapabilities.api.ingredient.IngredientComponent; | ||
| import org.cyclops.integratedterminals.Capabilities; | ||
| import org.cyclops.integratedterminals.client.gui.container.ContainerScreenTerminalStorage; | ||
|
|
||
| import javax.annotation.Nullable; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Renders the ingredients of a {@link CraftingOptionIngredientsTooltip} as a grid of icons. | ||
| * | ||
| * The grid wraps after {@link #MAX_COLUMNS} icons, | ||
| * and inputs that accept multiple alternatives are cycled through within their own slot. | ||
| * | ||
| * @author rubensworks | ||
| */ | ||
| @OnlyIn(Dist.CLIENT) | ||
| public class ClientCraftingOptionIngredientsTooltip implements ClientTooltipComponent { | ||
|
|
||
| private static final ResourceLocation SLOT_SPRITE = ResourceLocation.withDefaultNamespace("container/bundle/slot"); | ||
| private static final int SLOT_WIDTH = 18; | ||
| private static final int SLOT_HEIGHT = 20; | ||
| private static final int MAX_COLUMNS = 9; | ||
| private static final int MARGIN_Y = 2; | ||
|
|
||
| /** | ||
| * The number of ticks an alternative is shown before cycling to the next one. | ||
| */ | ||
| private static final int TICK_DELAY = 30; | ||
|
|
||
| private final List<List<IPrototypedIngredient<?, ?>>> ingredients; | ||
| private final int columns; | ||
| private final int rows; | ||
|
|
||
| public ClientCraftingOptionIngredientsTooltip(CraftingOptionIngredientsTooltip tooltip) { | ||
| this.ingredients = tooltip.ingredients(); | ||
| // Spread the ingredients evenly over as few rows as possible | ||
| this.rows = Math.max(1, (int) Math.ceil((double) this.ingredients.size() / MAX_COLUMNS)); | ||
| this.columns = Math.max(1, (int) Math.ceil((double) this.ingredients.size() / this.rows)); | ||
| } | ||
|
|
||
| @Override | ||
| public int getHeight() { | ||
| return this.rows * SLOT_HEIGHT + MARGIN_Y; | ||
| } | ||
|
|
||
| @Override | ||
| public int getWidth(Font font) { | ||
| return this.columns * SLOT_WIDTH; | ||
| } | ||
|
|
||
| @Override | ||
| public void renderImage(Font font, int x, int y, GuiGraphics guiGraphics) { | ||
| int tick = getTick(); | ||
| for (int i = 0; i < this.ingredients.size(); i++) { | ||
| List<IPrototypedIngredient<?, ?>> alternatives = this.ingredients.get(i); | ||
| int slotX = x + (i % this.columns) * SLOT_WIDTH; | ||
| int slotY = y + (i / this.columns) * SLOT_HEIGHT; | ||
| guiGraphics.blitSprite(SLOT_SPRITE, slotX, slotY, SLOT_WIDTH, SLOT_HEIGHT); | ||
| // Cycle over the alternatives of this input | ||
| drawIngredient(guiGraphics, alternatives.get(tick % alternatives.size()), slotX + 1, slotY + 1); | ||
| } | ||
| } | ||
|
|
||
| protected static <T, M> void drawIngredient(GuiGraphics guiGraphics, IPrototypedIngredient<T, M> ingredient, int x, int y) { | ||
| IngredientComponent<T, M> ingredientComponent = ingredient.getComponent(); | ||
| long quantity = ingredientComponent.getMatcher().getQuantity(ingredient.getPrototype()); | ||
| ingredientComponent.getCapability(Capabilities.IngredientComponentTerminalStorageHandler.INGREDIENT) | ||
| .ifPresent(handler -> handler.drawInstance(guiGraphics, ingredient.getPrototype(), quantity, null, | ||
| getContainerScreen(), ContainerScreenTerminalStorage.DrawLayer.BACKGROUND, 0, | ||
| x, y, 0, 0, null)); | ||
| } | ||
|
|
||
| @Nullable | ||
| protected static AbstractContainerScreen<?> getContainerScreen() { | ||
| Screen screen = Minecraft.getInstance().screen; | ||
| return screen instanceof AbstractContainerScreen<?> containerScreen ? containerScreen : null; | ||
| } | ||
|
|
||
| protected static int getTick() { | ||
| Minecraft minecraft = Minecraft.getInstance(); | ||
| return minecraft.level == null ? 0 : (int) (minecraft.level.getGameTime() / TICK_DELAY); | ||
| } | ||
|
|
||
| } |
19 changes: 19 additions & 0 deletions
19
.../org/cyclops/integratedterminals/client/gui/tooltip/CraftingOptionIngredientsTooltip.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package org.cyclops.integratedterminals.client.gui.tooltip; | ||
|
|
||
| import net.minecraft.world.inventory.tooltip.TooltipComponent; | ||
| import org.cyclops.commoncapabilities.api.ingredient.IPrototypedIngredient; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| /** | ||
| * A tooltip component holding the ingredients that are required by a crafting option. | ||
| * | ||
| * Every entry in {@link #ingredients()} represents a single required input, | ||
| * which holds all ingredients that are valid alternatives for that input. | ||
| * | ||
| * @param ingredients The required inputs, with their alternatives. | ||
| * @author rubensworks | ||
| */ | ||
| public record CraftingOptionIngredientsTooltip( | ||
| List<List<IPrototypedIngredient<?, ?>>> ingredients) implements TooltipComponent { | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.