Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.tooltip.TooltipComponent;
import net.minecraft.world.item.ItemStack;
import net.minecraft.network.chat.Component;
import net.minecraft.ChatFormatting;
Expand Down Expand Up @@ -54,9 +55,33 @@ public interface IIngredientComponentTerminalStorageHandler<T, M> {
* @param mouseY The mouse Y position.
* @param additionalTooltipLines The additional tooltip lines to add.
*/
@Deprecated // TODO: remove in next major
@OnlyIn(Dist.CLIENT)
public default void drawInstance(GuiGraphics guiGraphics, T instance, long maxQuantity, @Nullable String label, AbstractContainerScreen gui, ContainerScreenTerminalStorage.DrawLayer layer, float partialTick, int x, int y,
Comment thread
rubensworks marked this conversation as resolved.
int mouseX, int mouseY, @Nullable List<Component> additionalTooltipLines) {
drawInstance(guiGraphics, instance, maxQuantity, label, gui, layer, partialTick, x, y, mouseX, mouseY, additionalTooltipLines, null);
}

/**
* Draw the given instance in the given gui.
* @param guiGraphics The matrix stack.
* @param instance An instance.
* @param maxQuantity The maximum allowed quantity of the given instance.
* @param label An optional label that should be rendered instead of the quantity.
* @param gui A gui to render in.
* @param layer The layer to render in.
* @param partialTick The partial tick.
* @param x The slot X position.
* @param y The slot Y position.
* @param mouseX The mouse X position.
* @param mouseY The mouse Y position.
* @param additionalTooltipLines The additional tooltip lines to add.
* @param additionalTooltipComponent An optional visual tooltip component to render below the tooltip lines.
*/
@OnlyIn(Dist.CLIENT)
public void drawInstance(GuiGraphics guiGraphics, T instance, long maxQuantity, @Nullable String label, AbstractContainerScreen gui, ContainerScreenTerminalStorage.DrawLayer layer, float partialTick, int x, int y,
int mouseX, int mouseY, @Nullable List<Component> additionalTooltipLines);
int mouseX, int mouseY, @Nullable List<Component> additionalTooltipLines,
@Nullable TooltipComponent additionalTooltipComponent);

/**
* Show the quantity of the given instance on the second tooltip line.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package org.cyclops.integratedterminals.api.terminalstorage.crafting;

import org.cyclops.commoncapabilities.api.ingredient.IIngredientMatcher;
import org.cyclops.commoncapabilities.api.ingredient.IPrototypedIngredient;
import org.cyclops.commoncapabilities.api.ingredient.IngredientComponent;
import org.cyclops.commoncapabilities.api.ingredient.PrototypedIngredient;

import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;

/**
* Identifies a crafting job possibility.
Expand Down Expand Up @@ -45,4 +51,24 @@ public interface ITerminalCraftingOption<T> extends Comparable<ITerminalCrafting
*/
public <T1, M> Collection<T1> getInputs(IngredientComponent<T1, M> ingredientComponent);

/**
* The inputs of this crafting job option for the given ingredient component,
* where each input can be fulfilled by any of its alternatives.
*
* By default, this only exposes the single input instances from {@link #getInputs(IngredientComponent)}.
*
* @param ingredientComponent An ingredient component,
* @param <T1> The instance type.
* @param <M> The matching condition parameter, may be Void.
* @return The inputs, where each entry holds at least one alternative.
*/
public default <T1, M> List<List<IPrototypedIngredient<T1, M>>> getInputAlternatives(IngredientComponent<T1, M> ingredientComponent) {
IIngredientMatcher<T1, M> matcher = ingredientComponent.getMatcher();
return getInputs(ingredientComponent)
.stream()
.<List<IPrototypedIngredient<T1, M>>>map(input -> Collections.singletonList(
new PrototypedIngredient<>(ingredientComponent, input, matcher.getExactMatchNoQuantityCondition())))
.collect(Collectors.toList());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.inventory.tooltip.TooltipComponent;
import net.minecraft.world.item.ItemStack;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.api.distmarker.OnlyIn;
Expand All @@ -28,6 +29,7 @@
import org.cyclops.integratedterminals.api.ingredient.IIngredientInstanceSorter;
import org.cyclops.integratedterminals.client.gui.container.ContainerScreenTerminalStorage;
import org.cyclops.integratedterminals.client.gui.image.Images;
import org.cyclops.integratedterminals.client.gui.tooltip.TooltipRenderHelpers;
import org.cyclops.integratedterminals.core.terminalstorage.query.SearchMode;

import javax.annotation.Nullable;
Expand Down Expand Up @@ -64,7 +66,8 @@ public ItemStack getIcon() {
@OnlyIn(Dist.CLIENT)
public void drawInstance(GuiGraphics guiGraphics, Long instance, long maxQuantity, @Nullable String label, AbstractContainerScreen gui,
ContainerScreenTerminalStorage.DrawLayer layer, float partialTick, int x, int y,
int mouseX, int mouseY, @Nullable List<Component> additionalTooltipLines) {
int mouseX, int mouseY, @Nullable List<Component> additionalTooltipLines,
@Nullable TooltipComponent additionalTooltipComponent) {
if (instance > 0) {
if (layer == ContainerScreenTerminalStorage.DrawLayer.BACKGROUND){

Expand All @@ -91,7 +94,7 @@ public void drawInstance(GuiGraphics guiGraphics, Long instance, long maxQuantit

Lighting.setupFor3DItems();
} else {
GuiHelpers.renderTooltip(gui, guiGraphics.pose(), x, y, GuiHelpers.SLOT_SIZE_INNER, GuiHelpers.SLOT_SIZE_INNER,
TooltipRenderHelpers.renderTooltip(gui, guiGraphics, x, y, GuiHelpers.SLOT_SIZE_INNER, GuiHelpers.SLOT_SIZE_INNER,
mouseX, mouseY, () -> {
List<Component> lines = Lists.newArrayList();
lines.add(Component.translatable("gui.integratedterminals.terminal_storage.tooltip.energy"));
Expand All @@ -100,7 +103,7 @@ public void drawInstance(GuiGraphics guiGraphics, Long instance, long maxQuantit
lines.addAll(additionalTooltipLines);
}
return lines;
});
}, additionalTooltipComponent);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.inventory.tooltip.TooltipComponent;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.neoforged.api.distmarker.Dist;
Expand All @@ -35,6 +36,7 @@
import org.cyclops.integratedterminals.capability.ingredient.sorter.FluidStackNameSorter;
import org.cyclops.integratedterminals.capability.ingredient.sorter.FluidStackQuantitySorter;
import org.cyclops.integratedterminals.client.gui.container.ContainerScreenTerminalStorage;
import org.cyclops.integratedterminals.client.gui.tooltip.TooltipRenderHelpers;
import org.cyclops.integratedterminals.core.terminalstorage.query.SearchMode;

import javax.annotation.Nullable;
Expand Down Expand Up @@ -71,7 +73,8 @@ public ItemStack getIcon() {
public void drawInstance(GuiGraphics guiGraphics, FluidStack instance, long maxQuantity, @Nullable String label, AbstractContainerScreen gui,
ContainerScreenTerminalStorage.DrawLayer layer, float partialTick,
int x, int y, int mouseX, int mouseY,
@Nullable List<Component> additionalTooltipLines) {
@Nullable List<Component> additionalTooltipLines,
@Nullable TooltipComponent additionalTooltipComponent) {
if (instance != null) {
if (layer == ContainerScreenTerminalStorage.DrawLayer.BACKGROUND) {
// Draw fluid
Expand All @@ -81,15 +84,15 @@ public void drawInstance(GuiGraphics guiGraphics, FluidStack instance, long maxQ
GuiGraphicsExtended renderItem = new GuiGraphicsExtended(guiGraphics);
renderItem.drawSlotText(Minecraft.getInstance().font, label != null ? label : GuiHelpers.quantityToScaledString(instance.getAmount()), x, y);
} else {
GuiHelpers.renderTooltip(gui, guiGraphics.pose(), x, y, GuiHelpers.SLOT_SIZE_INNER, GuiHelpers.SLOT_SIZE_INNER, mouseX, mouseY, () -> {
TooltipRenderHelpers.renderTooltip(gui, guiGraphics, x, y, GuiHelpers.SLOT_SIZE_INNER, GuiHelpers.SLOT_SIZE_INNER, mouseX, mouseY, () -> {
List<Component> lines = Lists.newArrayList();
lines.add(((MutableComponent) instance.getHoverName()).withStyle(instance.getFluid().getFluidType().getRarity().getStyleModifier().apply(Style.EMPTY)));
addQuantityTooltip(lines, instance);
if (additionalTooltipLines != null) {
lines.addAll(additionalTooltipLines);
}
return lines;
});
}, additionalTooltipComponent);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.inventory.tooltip.TooltipComponent;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
Expand All @@ -31,6 +32,7 @@
import org.cyclops.integratedterminals.capability.ingredient.sorter.ItemStackNameSorter;
import org.cyclops.integratedterminals.capability.ingredient.sorter.ItemStackQuantitySorter;
import org.cyclops.integratedterminals.client.gui.container.ContainerScreenTerminalStorage;
import org.cyclops.integratedterminals.client.gui.tooltip.TooltipRenderHelpers;
import org.cyclops.integratedterminals.core.terminalstorage.query.SearchMode;
import org.lwjgl.opengl.GL11;

Expand Down Expand Up @@ -67,7 +69,8 @@ public ItemStack getIcon() {
@OnlyIn(Dist.CLIENT)
public void drawInstance(GuiGraphics guiGraphics, ItemStack instance, long maxQuantity, @Nullable String label, AbstractContainerScreen gui,
ContainerScreenTerminalStorage.DrawLayer layer, float partialTick, int x, int y,
int mouseX, int mouseY, @Nullable List<Component> additionalTooltipLines) {
int mouseX, int mouseY, @Nullable List<Component> additionalTooltipLines,
@Nullable TooltipComponent additionalTooltipComponent) {
// Make a copy of the item to make sure that any changes in the NBT tag that the mod may make during rendering
// does not propagate into our client-side index. Otherwise, the client may think it has different items than
// the server, which will cause these items not to be extractable by the client from the terminal.
Expand All @@ -85,7 +88,7 @@ public void drawInstance(GuiGraphics guiGraphics, ItemStack instance, long maxQu
guiGraphics.renderItem(instanceCopy, x, y);
renderItem.renderItemDecorations(Minecraft.getInstance().font, instanceCopy, x, y, label);
} else {
GuiHelpers.renderTooltip(gui, guiGraphics.pose(), x, y, GuiHelpers.SLOT_SIZE_INNER, GuiHelpers.SLOT_SIZE_INNER, mouseX, mouseY, () -> {
TooltipRenderHelpers.renderTooltip(gui, guiGraphics, x, y, GuiHelpers.SLOT_SIZE_INNER, GuiHelpers.SLOT_SIZE_INNER, mouseX, mouseY, () -> {
List<Component> lines = instanceCopy.getTooltipLines(
Item.TooltipContext.of(Minecraft.getInstance().player.registryAccess()),
Minecraft.getInstance().player, Minecraft.getInstance().options.advancedItemTooltips
Expand All @@ -95,7 +98,7 @@ public void drawInstance(GuiGraphics guiGraphics, ItemStack instance, long maxQu
}
addQuantityTooltip(lines, instanceCopy);
return lines;
});
}, additionalTooltipComponent);
}
Lighting.setupForFlatItems();
}
Expand Down
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);
}

}
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 {
}
Loading
Loading