Skip to content

Commit a5c8a95

Browse files
authored
Merge pull request #28 from refinedmods/feat/NO-ISSUE/autocrafting-transfer
Autocrafting transfer
2 parents bfc01cf + a38edbf commit a5c8a95

33 files changed

+414
-109
lines changed

.github/workflows/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
types: [ opened, synchronize, reopened ]
99
jobs:
1010
build:
11-
uses: refinedmods/refinedarchitect/.github/workflows/build.yml@v0.17.1
11+
uses: refinedmods/refinedarchitect/.github/workflows/build.yml@v0.19.1
1212
with:
1313
mutation-testing: false
1414
secrets: inherit

.github/workflows/draft-release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ on:
1717
type: string
1818
jobs:
1919
draft:
20-
uses: refinedmods/refinedarchitect/.github/workflows/draft-release.yml@v0.17.1
20+
uses: refinedmods/refinedarchitect/.github/workflows/draft-release.yml@v0.19.1
2121
with:
2222
release-type: ${{ inputs.release-type }}
2323
version-number-override: ${{ inputs.version-number-override }}

.github/workflows/issue-for-unsupported-version.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ on:
44
types: [ labeled, unlabeled, reopened ]
55
jobs:
66
unsupported-labeler:
7-
uses: refinedmods/refinedarchitect/.github/workflows/issue-for-unsupported-version.yml@v0.17.1
7+
uses: refinedmods/refinedarchitect/.github/workflows/issue-for-unsupported-version.yml@v0.19.1

.github/workflows/publish-release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
- closed
88
jobs:
99
publish-release:
10-
uses: refinedmods/refinedarchitect/.github/workflows/publish-release.yml@v0.17.1
10+
uses: refinedmods/refinedarchitect/.github/workflows/publish-release.yml@v0.19.1
1111
secrets: inherit
1212
with:
1313
project-name: 'Refined Storage - JEI Integration'

.github/workflows/resolved-issue-locking.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ on:
44
- cron: '0 0 * * *'
55
jobs:
66
lock:
7-
uses: refinedmods/refinedarchitect/.github/workflows/resolved-issue-locking.yml@v0.17.1
7+
uses: refinedmods/refinedarchitect/.github/workflows/resolved-issue-locking.yml@v0.19.1

.github/workflows/validate-branch-name.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ name: Validate branch name
22
on: [ pull_request ]
33
jobs:
44
validate-branch-name:
5-
uses: refinedmods/refinedarchitect/.github/workflows/validate-branch-name.yml@v0.17.1
5+
uses: refinedmods/refinedarchitect/.github/workflows/validate-branch-name.yml@v0.19.1

.github/workflows/validate-changelog.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ on:
44
types: [ opened, synchronize, reopened, ready_for_review, labeled, unlabeled ]
55
jobs:
66
validate-changelog:
7-
uses: refinedmods/refinedarchitect/.github/workflows/validate-changelog.yml@v0.17.1
7+
uses: refinedmods/refinedarchitect/.github/workflows/validate-changelog.yml@v0.19.1

.github/workflows/validate-commit-messages.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ name: Validate commit messages
22
on: [ pull_request ]
33
jobs:
44
validate-commit-messages:
5-
uses: refinedmods/refinedarchitect/.github/workflows/validate-commit-messages.yml@v0.17.1
5+
uses: refinedmods/refinedarchitect/.github/workflows/validate-commit-messages.yml@v0.19.1

CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- The recipe transfer support in the Pattern Grid and Crafting Grid now indicates whether all or some resources are autocraftable.
13+
- You can now start autocrafting for missing autocraftable items from the Crafting Grid via the recipe transfer.
14+
- Alias support for the Disk Interface (formerly known as "Disk Manipulator").
15+
16+
### Fixed
17+
18+
- Support for Refined Storage v2.0.0-milestone.4.8.
19+
1020
## [0.5.0] - 2024-08-11
1121

1222
### Fixed

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ Adds support for:
2323
- [Crowdin](https://crowdin.com/project/refined-storage-jei-integration)
2424
- [Discord](https://discordapp.com/invite/VYzsydb)
2525
- [Twitter](https://twitter.com/refinedmods)
26-
- [Mastodon](https://anvil.social/@refinedmods)
2726

2827
## Building
2928

gradle.properties

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
refinedarchitectVersion=0.17.1
2-
refinedstorageVersion=2.0.0-milestone.4.7
3-
jeiVersion=19.8.2.99
4-
minecraftVersion=1.21
1+
refinedarchitectVersion=0.19.1
2+
refinedstorageVersion=2.0.0-milestone.4.8
3+
jeiVersion=19.20.0.241
4+
minecraftVersion=1.21.1
55
# Gradle
66
org.gradle.jvmargs=-Xmx1G
7+
org.gradle.configureondemand=true
8+
org.gradle.caching=true
9+
org.gradle.configuration-cache=true
10+
org.gradle.configuration-cache.problems=warn

gradle/wrapper/gradle-wrapper.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.refinedmods.refinedstorage.jei.common;
2+
3+
import com.refinedmods.refinedstorage.api.grid.view.GridView;
4+
import com.refinedmods.refinedstorage.api.resource.ResourceAmount;
5+
import com.refinedmods.refinedstorage.common.autocrafting.PatternGridContainerMenu;
6+
7+
import java.util.List;
8+
import javax.annotation.Nullable;
9+
10+
import mezz.jei.api.gui.ingredient.IRecipeSlotView;
11+
import mezz.jei.api.gui.ingredient.IRecipeSlotsView;
12+
import mezz.jei.api.recipe.RecipeIngredientRole;
13+
import mezz.jei.api.recipe.transfer.IRecipeTransferError;
14+
import mezz.jei.api.recipe.transfer.IRecipeTransferHandler;
15+
16+
abstract class AbstractPatternGridRecipeTransferHandler<R>
17+
implements IRecipeTransferHandler<PatternGridContainerMenu, R> {
18+
19+
@Nullable
20+
public static IRecipeTransferError autocraftableHint(final GridView view, final IRecipeSlotsView recipeSlots) {
21+
final List<IRecipeSlotView> inputs = recipeSlots.getSlotViews(RecipeIngredientRole.INPUT);
22+
final boolean allAreAutocraftable = inputs.stream()
23+
.filter(slotView -> !slotView.isEmpty())
24+
.allMatch(slotView -> SlotUtil.getResources(slotView)
25+
.stream()
26+
.map(ResourceAmount::resource)
27+
.anyMatch(view::isAutocraftable));
28+
final List<IRecipeSlotView> autocraftableSlots = inputs.stream()
29+
.filter(slotView -> SlotUtil.getResources(slotView)
30+
.stream()
31+
.map(ResourceAmount::resource)
32+
.anyMatch(view::isAutocraftable))
33+
.toList();
34+
return autocraftableSlots.isEmpty()
35+
? null
36+
: new PatternGridRecipeTransferError(autocraftableSlots, allAreAutocraftable);
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.refinedmods.refinedstorage.jei.common;
2+
3+
import com.refinedmods.refinedstorage.common.grid.AutocraftableResourceHint;
4+
5+
import mezz.jei.api.recipe.transfer.IRecipeTransferError;
6+
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent;
7+
import net.minecraft.network.chat.Component;
8+
9+
abstract class AbstractRecipeTransferError implements IRecipeTransferError {
10+
protected static final ClientTooltipComponent MOVE_ITEMS = ClientTooltipComponent.create(
11+
Component.translatable("jei.tooltip.transfer").getVisualOrderText()
12+
);
13+
protected static final int AUTOCRAFTABLE_COLOR = AutocraftableResourceHint.AUTOCRAFTABLE.getColor();
14+
15+
protected static ClientTooltipComponent createAutocraftableHint(final Component component) {
16+
return ClientTooltipComponent.create(component.copy().withColor(AUTOCRAFTABLE_COLOR).getVisualOrderText());
17+
}
18+
}

refinedstorage-jei-integration-common/src/main/java/com/refinedmods/refinedstorage/jei/common/ClickableIngredient.java

+12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.refinedmods.refinedstorage.jei.common;
22

3+
import mezz.jei.api.ingredients.IIngredientType;
34
import mezz.jei.api.ingredients.ITypedIngredient;
45
import mezz.jei.api.runtime.IClickableIngredient;
56
import net.minecraft.client.renderer.Rect2i;
@@ -14,10 +15,21 @@ class ClickableIngredient<T> implements IClickableIngredient<T> {
1415
}
1516

1617
@Override
18+
@SuppressWarnings({"removal"})
1719
public ITypedIngredient<T> getTypedIngredient() {
1820
return ingredient;
1921
}
2022

23+
@Override
24+
public IIngredientType<T> getIngredientType() {
25+
return ingredient.getType();
26+
}
27+
28+
@Override
29+
public T getIngredient() {
30+
return ingredient.getIngredient();
31+
}
32+
2133
@Override
2234
public Rect2i getArea() {
2335
return area;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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

Comments
 (0)