Skip to content

Commit

Permalink
Fixed shaped recipe tooltip badges not showing correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
apace100 committed Jul 2, 2022
1 parent 3c03ae4 commit 607ff76
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.minecraft.item.ItemStack;
import net.minecraft.recipe.Ingredient;
import net.minecraft.recipe.Recipe;
import net.minecraft.recipe.ShapedRecipe;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
Expand Down Expand Up @@ -52,17 +53,18 @@ public DefaultedList<ItemStack> peekInputs(float time) {
@Override
public List<TooltipComponent> getTooltipComponents(PowerType<?> powerType, int widthLimit, float time, TextRenderer textRenderer) {
List<TooltipComponent> tooltips = new LinkedList<>();
int recipeWidth = this.recipe instanceof ShapedRecipe shapedRecipe ? shapedRecipe.getWidth() : 3;
if(MinecraftClient.getInstance().options.advancedItemTooltips) {
Text recipeIdText = ((MutableText)Text.of(recipe.getId().toString())).formatted(Formatting.DARK_GRAY);
widthLimit = Math.max(130, textRenderer.getWidth(recipeIdText));
if(prefix != null) TooltipBadge.addLines(tooltips, prefix, textRenderer, widthLimit);
tooltips.add(new CraftingRecipeTooltipComponent(this.peekInputs(time), this.recipe.getOutput()));
tooltips.add(new CraftingRecipeTooltipComponent(recipeWidth, this.peekInputs(time), this.recipe.getOutput()));
if(suffix != null) TooltipBadge.addLines(tooltips, suffix, textRenderer, widthLimit);
TooltipBadge.addLines(tooltips, recipeIdText, textRenderer, widthLimit);
} else {
widthLimit = 130;
if(prefix != null) TooltipBadge.addLines(tooltips, prefix, textRenderer, widthLimit);
tooltips.add(new CraftingRecipeTooltipComponent(this.peekInputs(time), this.recipe.getOutput()));
tooltips.add(new CraftingRecipeTooltipComponent(recipeWidth, this.peekInputs(time), this.recipe.getOutput()));
if(suffix != null) TooltipBadge.addLines(tooltips, suffix, textRenderer, widthLimit);
}
return tooltips;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@
import net.minecraft.util.Identifier;
import net.minecraft.util.collection.DefaultedList;

/**A {@link TooltipComponent} used for {@link io.github.apace100.origins.screen.badge.CraftingRecipeBadge}
/**A {@link TooltipComponent} used for {@link io.github.apace100.origins.badge.CraftingRecipeBadge}
* Draws a snapshot of a 3x3 crafting recipe in the tooltip*/
public class CraftingRecipeTooltipComponent implements TooltipComponent {
private final int recipeWidth;
private final DefaultedList<ItemStack> inputs;
private final ItemStack output;
private static final Identifier TEXTURE = Origins.identifier("textures/gui/tooltip/recipe_tooltip.png");

public CraftingRecipeTooltipComponent(DefaultedList<ItemStack> inputs, ItemStack output) {
public CraftingRecipeTooltipComponent(int recipeWidth, DefaultedList<ItemStack> inputs, ItemStack output) {
this.recipeWidth = recipeWidth;
this.inputs = inputs;
this.output = output;
}
Expand All @@ -38,10 +40,10 @@ public void drawItems(TextRenderer textRenderer, int x, int y, MatrixStack matri
this.drawBackGround(matrices, x, y, z);
for(int column = 0; column < 3; ++column) {
for(int row = 0; row < 3; ++row) {
int index = column + row * 3;
int index = column + row * recipeWidth;
int slotX = x + 8 + column * 18;
int slotY = y + 8 + row * 18;
ItemStack stack = inputs.get(index);
ItemStack stack = column >= recipeWidth ? ItemStack.EMPTY : inputs.get(index);
itemRenderer.renderInGuiWithOverrides(stack, slotX, slotY, index);
itemRenderer.renderGuiItemOverlay(textRenderer, stack, slotX, slotY);
}
Expand Down

0 comments on commit 607ff76

Please sign in to comment.