|
| 1 | +package com.refinedmods.refinedstorage.jei.common; |
| 2 | + |
| 3 | +import com.refinedmods.refinedstorage.common.Platform; |
| 4 | +import com.refinedmods.refinedstorage.common.support.tooltip.HelpClientTooltipComponent; |
| 5 | + |
| 6 | +import java.awt.Color; |
| 7 | +import java.util.Collections; |
| 8 | +import java.util.List; |
| 9 | + |
| 10 | +import com.mojang.blaze3d.vertex.PoseStack; |
| 11 | +import mezz.jei.api.gui.ingredient.IRecipeSlotsView; |
| 12 | +import net.minecraft.ChatFormatting; |
| 13 | +import net.minecraft.client.gui.GuiGraphics; |
| 14 | +import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent; |
| 15 | +import net.minecraft.network.chat.Component; |
| 16 | + |
| 17 | +import static com.refinedmods.refinedstorage.jei.common.Common.MOD_ID; |
| 18 | + |
| 19 | +class CraftingGridRecipeTransferError extends AbstractRecipeTransferError { |
| 20 | + private static final Color MISSING_COLOR = new Color(1.0f, 0.0f, 0.0f, 0.4f); |
| 21 | + private static final ClientTooltipComponent MISSING_ITEMS = ClientTooltipComponent.create( |
| 22 | + Component.translatable("jei.tooltip.error.recipe.transfer.missing") |
| 23 | + .withStyle(ChatFormatting.RED) |
| 24 | + .getVisualOrderText()); |
| 25 | + private static final List<ClientTooltipComponent> MISSING_TOOLTIP = List.of(MOVE_ITEMS, MISSING_ITEMS); |
| 26 | + private static final Component CTRL_CLICK_TO_AUTOCRAFT = Component.translatable( |
| 27 | + "gui.%s.transfer.ctrl_click_to_autocraft".formatted(MOD_ID) |
| 28 | + ); |
| 29 | + |
| 30 | + private final List<TransferInput> transferInputs; |
| 31 | + private final TransferType type; |
| 32 | + |
| 33 | + CraftingGridRecipeTransferError(final List<TransferInput> transferInputs, final TransferType type) { |
| 34 | + this.transferInputs = transferInputs; |
| 35 | + this.type = type; |
| 36 | + } |
| 37 | + |
| 38 | + @Override |
| 39 | + public Type getType() { |
| 40 | + return Type.COSMETIC; |
| 41 | + } |
| 42 | + |
| 43 | + @Override |
| 44 | + public int getButtonHighlightColor() { |
| 45 | + return switch (type) { |
| 46 | + case MISSING -> MISSING_COLOR.getRGB(); |
| 47 | + case MISSING_BUT_ALL_AUTOCRAFTABLE, MISSING_BUT_SOME_AUTOCRAFTABLE -> AUTOCRAFTABLE_COLOR; |
| 48 | + default -> 0; |
| 49 | + }; |
| 50 | + } |
| 51 | + |
| 52 | + @Override |
| 53 | + public void showError(final GuiGraphics graphics, |
| 54 | + final int mouseX, |
| 55 | + final int mouseY, |
| 56 | + final IRecipeSlotsView recipeSlotsView, |
| 57 | + final int recipeX, |
| 58 | + final int recipeY) { |
| 59 | + final PoseStack poseStack = graphics.pose(); |
| 60 | + poseStack.pushPose(); |
| 61 | + poseStack.translate(recipeX, recipeY, 0); |
| 62 | + transferInputs.forEach(input -> drawInputHighlight(graphics, input)); |
| 63 | + poseStack.popPose(); |
| 64 | + Platform.INSTANCE.renderTooltip(graphics, calculateTooltip(), mouseX, mouseY); |
| 65 | + } |
| 66 | + |
| 67 | + private List<ClientTooltipComponent> calculateTooltip() { |
| 68 | + return switch (type) { |
| 69 | + case MISSING -> MISSING_TOOLTIP; |
| 70 | + case MISSING_BUT_ALL_AUTOCRAFTABLE -> List.of( |
| 71 | + MOVE_ITEMS, |
| 72 | + createAutocraftableHint( |
| 73 | + Component.translatable("gui.%s.transfer.missing_but_all_autocraftable".formatted(MOD_ID)) |
| 74 | + ), |
| 75 | + HelpClientTooltipComponent.createAlwaysDisplayed(CTRL_CLICK_TO_AUTOCRAFT) |
| 76 | + ); |
| 77 | + case MISSING_BUT_SOME_AUTOCRAFTABLE -> List.of( |
| 78 | + MOVE_ITEMS, |
| 79 | + createAutocraftableHint( |
| 80 | + Component.translatable("gui.%s.transfer.missing_but_some_autocraftable".formatted(MOD_ID)) |
| 81 | + ), |
| 82 | + HelpClientTooltipComponent.createAlwaysDisplayed(CTRL_CLICK_TO_AUTOCRAFT) |
| 83 | + ); |
| 84 | + default -> Collections.emptyList(); |
| 85 | + }; |
| 86 | + } |
| 87 | + |
| 88 | + private static void drawInputHighlight(final GuiGraphics graphics, final TransferInput input) { |
| 89 | + switch (input.type()) { |
| 90 | + case MISSING -> input.view().drawHighlight(graphics, MISSING_COLOR.getRGB()); |
| 91 | + case AUTOCRAFTABLE -> input.view().drawHighlight(graphics, AUTOCRAFTABLE_COLOR); |
| 92 | + } |
| 93 | + } |
| 94 | +} |
0 commit comments