-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from refinedmods/feat/NO-ISSUE/autocrafting-tr…
…ansfer Autocrafting transfer
- Loading branch information
Showing
33 changed files
with
414 additions
and
109 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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 |
---|---|---|
@@ -1,6 +1,10 @@ | ||
refinedarchitectVersion=0.17.1 | ||
refinedstorageVersion=2.0.0-milestone.4.7 | ||
jeiVersion=19.8.2.99 | ||
minecraftVersion=1.21 | ||
refinedarchitectVersion=0.19.1 | ||
refinedstorageVersion=2.0.0-milestone.4.8 | ||
jeiVersion=19.20.0.241 | ||
minecraftVersion=1.21.1 | ||
# Gradle | ||
org.gradle.jvmargs=-Xmx1G | ||
org.gradle.configureondemand=true | ||
org.gradle.caching=true | ||
org.gradle.configuration-cache=true | ||
org.gradle.configuration-cache.problems=warn |
This file contains 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
38 changes: 38 additions & 0 deletions
38
...a/com/refinedmods/refinedstorage/jei/common/AbstractPatternGridRecipeTransferHandler.java
This file contains 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,38 @@ | ||
package com.refinedmods.refinedstorage.jei.common; | ||
|
||
import com.refinedmods.refinedstorage.api.grid.view.GridView; | ||
import com.refinedmods.refinedstorage.api.resource.ResourceAmount; | ||
import com.refinedmods.refinedstorage.common.autocrafting.PatternGridContainerMenu; | ||
|
||
import java.util.List; | ||
import javax.annotation.Nullable; | ||
|
||
import mezz.jei.api.gui.ingredient.IRecipeSlotView; | ||
import mezz.jei.api.gui.ingredient.IRecipeSlotsView; | ||
import mezz.jei.api.recipe.RecipeIngredientRole; | ||
import mezz.jei.api.recipe.transfer.IRecipeTransferError; | ||
import mezz.jei.api.recipe.transfer.IRecipeTransferHandler; | ||
|
||
abstract class AbstractPatternGridRecipeTransferHandler<R> | ||
implements IRecipeTransferHandler<PatternGridContainerMenu, R> { | ||
|
||
@Nullable | ||
public static IRecipeTransferError autocraftableHint(final GridView view, final IRecipeSlotsView recipeSlots) { | ||
final List<IRecipeSlotView> inputs = recipeSlots.getSlotViews(RecipeIngredientRole.INPUT); | ||
final boolean allAreAutocraftable = inputs.stream() | ||
.filter(slotView -> !slotView.isEmpty()) | ||
.allMatch(slotView -> SlotUtil.getResources(slotView) | ||
.stream() | ||
.map(ResourceAmount::resource) | ||
.anyMatch(view::isAutocraftable)); | ||
final List<IRecipeSlotView> autocraftableSlots = inputs.stream() | ||
.filter(slotView -> SlotUtil.getResources(slotView) | ||
.stream() | ||
.map(ResourceAmount::resource) | ||
.anyMatch(view::isAutocraftable)) | ||
.toList(); | ||
return autocraftableSlots.isEmpty() | ||
? null | ||
: new PatternGridRecipeTransferError(autocraftableSlots, allAreAutocraftable); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
.../src/main/java/com/refinedmods/refinedstorage/jei/common/AbstractRecipeTransferError.java
This file contains 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,18 @@ | ||
package com.refinedmods.refinedstorage.jei.common; | ||
|
||
import com.refinedmods.refinedstorage.common.grid.AutocraftableResourceHint; | ||
|
||
import mezz.jei.api.recipe.transfer.IRecipeTransferError; | ||
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent; | ||
import net.minecraft.network.chat.Component; | ||
|
||
abstract class AbstractRecipeTransferError implements IRecipeTransferError { | ||
protected static final ClientTooltipComponent MOVE_ITEMS = ClientTooltipComponent.create( | ||
Component.translatable("jei.tooltip.transfer").getVisualOrderText() | ||
); | ||
protected static final int AUTOCRAFTABLE_COLOR = AutocraftableResourceHint.AUTOCRAFTABLE.getColor(); | ||
|
||
protected static ClientTooltipComponent createAutocraftableHint(final Component component) { | ||
return ClientTooltipComponent.create(component.copy().withColor(AUTOCRAFTABLE_COLOR).getVisualOrderText()); | ||
} | ||
} |
This file contains 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
94 changes: 94 additions & 0 deletions
94
.../main/java/com/refinedmods/refinedstorage/jei/common/CraftingGridRecipeTransferError.java
This file contains 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,94 @@ | ||
package com.refinedmods.refinedstorage.jei.common; | ||
|
||
import com.refinedmods.refinedstorage.common.Platform; | ||
import com.refinedmods.refinedstorage.common.support.tooltip.HelpClientTooltipComponent; | ||
|
||
import java.awt.Color; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import com.mojang.blaze3d.vertex.PoseStack; | ||
import mezz.jei.api.gui.ingredient.IRecipeSlotsView; | ||
import net.minecraft.ChatFormatting; | ||
import net.minecraft.client.gui.GuiGraphics; | ||
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent; | ||
import net.minecraft.network.chat.Component; | ||
|
||
import static com.refinedmods.refinedstorage.jei.common.Common.MOD_ID; | ||
|
||
class CraftingGridRecipeTransferError extends AbstractRecipeTransferError { | ||
private static final Color MISSING_COLOR = new Color(1.0f, 0.0f, 0.0f, 0.4f); | ||
private static final ClientTooltipComponent MISSING_ITEMS = ClientTooltipComponent.create( | ||
Component.translatable("jei.tooltip.error.recipe.transfer.missing") | ||
.withStyle(ChatFormatting.RED) | ||
.getVisualOrderText()); | ||
private static final List<ClientTooltipComponent> MISSING_TOOLTIP = List.of(MOVE_ITEMS, MISSING_ITEMS); | ||
private static final Component CTRL_CLICK_TO_AUTOCRAFT = Component.translatable( | ||
"gui.%s.transfer.ctrl_click_to_autocraft".formatted(MOD_ID) | ||
); | ||
|
||
private final List<TransferInput> transferInputs; | ||
private final TransferType type; | ||
|
||
CraftingGridRecipeTransferError(final List<TransferInput> transferInputs, final TransferType type) { | ||
this.transferInputs = transferInputs; | ||
this.type = type; | ||
} | ||
|
||
@Override | ||
public Type getType() { | ||
return Type.COSMETIC; | ||
} | ||
|
||
@Override | ||
public int getButtonHighlightColor() { | ||
return switch (type) { | ||
case MISSING -> MISSING_COLOR.getRGB(); | ||
case MISSING_BUT_ALL_AUTOCRAFTABLE, MISSING_BUT_SOME_AUTOCRAFTABLE -> AUTOCRAFTABLE_COLOR; | ||
default -> 0; | ||
}; | ||
} | ||
|
||
@Override | ||
public void showError(final GuiGraphics graphics, | ||
final int mouseX, | ||
final int mouseY, | ||
final IRecipeSlotsView recipeSlotsView, | ||
final int recipeX, | ||
final int recipeY) { | ||
final PoseStack poseStack = graphics.pose(); | ||
poseStack.pushPose(); | ||
poseStack.translate(recipeX, recipeY, 0); | ||
transferInputs.forEach(input -> drawInputHighlight(graphics, input)); | ||
poseStack.popPose(); | ||
Platform.INSTANCE.renderTooltip(graphics, calculateTooltip(), mouseX, mouseY); | ||
} | ||
|
||
private List<ClientTooltipComponent> calculateTooltip() { | ||
return switch (type) { | ||
case MISSING -> MISSING_TOOLTIP; | ||
case MISSING_BUT_ALL_AUTOCRAFTABLE -> List.of( | ||
MOVE_ITEMS, | ||
createAutocraftableHint( | ||
Component.translatable("gui.%s.transfer.missing_but_all_autocraftable".formatted(MOD_ID)) | ||
), | ||
HelpClientTooltipComponent.createAlwaysDisplayed(CTRL_CLICK_TO_AUTOCRAFT) | ||
); | ||
case MISSING_BUT_SOME_AUTOCRAFTABLE -> List.of( | ||
MOVE_ITEMS, | ||
createAutocraftableHint( | ||
Component.translatable("gui.%s.transfer.missing_but_some_autocraftable".formatted(MOD_ID)) | ||
), | ||
HelpClientTooltipComponent.createAlwaysDisplayed(CTRL_CLICK_TO_AUTOCRAFT) | ||
); | ||
default -> Collections.emptyList(); | ||
}; | ||
} | ||
|
||
private static void drawInputHighlight(final GuiGraphics graphics, final TransferInput input) { | ||
switch (input.type()) { | ||
case MISSING -> input.view().drawHighlight(graphics, MISSING_COLOR.getRGB()); | ||
case AUTOCRAFTABLE -> input.view().drawHighlight(graphics, AUTOCRAFTABLE_COLOR); | ||
} | ||
} | ||
} |
Oops, something went wrong.