Skip to content

Commit b8a0253

Browse files
committed
Fix #3795 Prevent retaining the player client when crossing dimensions
1 parent 124b785 commit b8a0253

File tree

6 files changed

+24
-17
lines changed

6 files changed

+24
-17
lines changed

Common/src/main/java/mezz/jei/common/util/TagUtil.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ public class TagUtil {
1515
public static <VALUE, STACK> Optional<TagKey<?>> getTagEquivalent(
1616
Collection<STACK> stacks,
1717
Function<STACK, VALUE> stackToValue,
18-
Supplier<Stream<Pair<TagKey<VALUE>,
19-
HolderSet.Named<VALUE>>>> tagSupplier
18+
Supplier<Stream<Pair<TagKey<VALUE>, HolderSet.Named<VALUE>>>> tagSupplier
2019
) {
2120
List<VALUE> values = stacks.stream()
2221
.map(stackToValue)

Gui/src/main/java/mezz/jei/gui/recipes/IRecipeGuiLogic.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public interface IRecipeGuiLogic {
3737

3838
void nextPage();
3939

40-
void tick();
40+
void tick(@Nullable AbstractContainerMenu container);
4141

4242
boolean showFocus(IFocusGroup focuses);
4343

Gui/src/main/java/mezz/jei/gui/recipes/RecipeGuiLogic.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public class RecipeGuiLogic implements IRecipeGuiLogic {
4040
private final IFocusFactory focusFactory;
4141
private @Nullable IRecipeCategory<?> cachedRecipeCategory;
4242
private @Nullable IRecipeLayoutList cachedRecipeLayoutsWithButtons;
43+
private int cachedContainerId = -1;
4344
private Set<RecipeSorterStage> cachedSorterStages = Set.of();
4445

4546
public RecipeGuiLogic(
@@ -64,9 +65,9 @@ public RecipeGuiLogic(
6465
}
6566

6667
@Override
67-
public void tick() {
68+
public void tick(@Nullable AbstractContainerMenu container) {
6869
if (cachedRecipeLayoutsWithButtons != null) {
69-
cachedRecipeLayoutsWithButtons.tick();
70+
cachedRecipeLayoutsWithButtons.tick(container);
7071
}
7172
}
7273

@@ -121,6 +122,7 @@ private boolean setState(ILookupState state, boolean saveHistory) {
121122
this.initialState = false;
122123
this.cachedRecipeCategory = null;
123124
this.cachedRecipeLayoutsWithButtons = null;
125+
this.cachedContainerId = -1;
124126
stateListener.onStateChange();
125127
return true;
126128
}
@@ -204,9 +206,11 @@ public List<RecipeLayoutWithButtons<?>> getVisibleRecipeLayoutsWithButtons(
204206
IClientConfig clientConfig = jeiClientConfigs.getClientConfig();
205207
Set<RecipeSorterStage> recipeSorterStages = clientConfig.getRecipeSorterStages();
206208

209+
int containerId = container == null ? -1 : container.containerId;
207210
if (!recipeSorterStages.equals(cachedSorterStages) ||
208211
this.cachedRecipeLayoutsWithButtons == null ||
209-
this.cachedRecipeCategory != recipeCategory
212+
this.cachedRecipeCategory != recipeCategory ||
213+
this.cachedContainerId != containerId
210214
) {
211215
IFocusedRecipes<?> focusedRecipes = this.state.getFocusedRecipes();
212216

@@ -221,6 +225,7 @@ public List<RecipeLayoutWithButtons<?>> getVisibleRecipeLayoutsWithButtons(
221225
);
222226
this.cachedRecipeCategory = recipeCategory;
223227
this.cachedSorterStages = Set.copyOf(recipeSorterStages);
228+
this.cachedContainerId = containerId;
224229
}
225230

226231
final int recipeHeight =

Gui/src/main/java/mezz/jei/gui/recipes/RecipesGui.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ public void tick() {
351351

352352
this.optionButtons.tick();
353353

354-
this.logic.tick();
354+
this.logic.tick(container);
355355
}
356356

357357
@Override
@@ -554,7 +554,7 @@ private ImmutableRect2i getRecipeLayoutsArea() {
554554
}
555555

556556
@Nullable
557-
private AbstractContainerMenu getParentContainerMenu() {
557+
public AbstractContainerMenu getParentContainerMenu() {
558558
Screen screen;
559559
if (parentScreen == null) {
560560
screen = Minecraft.getInstance().screen;

Gui/src/main/java/mezz/jei/gui/recipes/layouts/IRecipeLayoutList.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,5 @@ static IRecipeLayoutList create(
4141

4242
Optional<RecipeLayoutWithButtons<?>> findFirst();
4343

44-
void tick();
44+
void tick(@Nullable AbstractContainerMenu container);
4545
}

Gui/src/main/java/mezz/jei/gui/recipes/layouts/LazyRecipeLayoutList.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import java.util.Set;
3131

3232
public class LazyRecipeLayoutList<T> implements IRecipeLayoutList {
33-
private final @Nullable AbstractContainerMenu container;
3433
private final IRecipeManager recipeManager;
3534
private final IRecipeCategory<T> recipeCategory;
3635
private final RecipesGui recipesGui;
@@ -55,7 +54,6 @@ public LazyRecipeLayoutList(
5554
this.bookmarkList = bookmarkList;
5655
boolean matchingBookmarks = recipeSorterStages.contains(RecipeSorterStage.BOOKMARKED);
5756
boolean matchingCraftable = recipeSorterStages.contains(RecipeSorterStage.CRAFTABLE);
58-
this.container = container;
5957
this.recipeManager = recipeManager;
6058
this.recipesGui = recipesGui;
6159
this.focusGroup = focusGroup;
@@ -112,7 +110,11 @@ private IRecipeLayoutDrawable<T> createRecipeLayout(T recipe) {
112110
return recipeManager.createRecipeLayoutDrawableOrShowError(recipeCategory, recipe, focusGroup);
113111
}
114112

115-
private RecipeLayoutWithButtons<T> createRecipeLayoutWithButtons(IRecipeLayoutDrawable<T> recipeLayoutDrawable, IIngredientManager ingredientManager) {
113+
private RecipeLayoutWithButtons<T> createRecipeLayoutWithButtons(
114+
IRecipeLayoutDrawable<T> recipeLayoutDrawable,
115+
IIngredientManager ingredientManager,
116+
@Nullable AbstractContainerMenu container
117+
) {
116118
RecipeBookmark<T, ?> recipeBookmark = RecipeBookmark.create(recipeLayoutDrawable, ingredientManager);
117119
return createRecipeLayoutWithButtons(recipeLayoutDrawable, recipeBookmark, bookmarkList, recipesGui, container);
118120
}
@@ -129,8 +131,9 @@ public List<RecipeLayoutWithButtons<?>> subList(int from, int to) {
129131
}
130132

131133
private void ensureResults(int index) {
134+
AbstractContainerMenu container = recipesGui.getParentContainerMenu();
132135
while (index >= results.size()) {
133-
if (!calculateNextResult()) {
136+
if (!calculateNextResult(container)) {
134137
return;
135138
}
136139
}
@@ -146,18 +149,18 @@ public Optional<RecipeLayoutWithButtons<?>> findFirst() {
146149
}
147150

148151
@Override
149-
public void tick() {
150-
calculateNextResult();
152+
public void tick(@Nullable AbstractContainerMenu container) {
153+
calculateNextResult(container);
151154
}
152155

153-
private boolean calculateNextResult() {
156+
private boolean calculateNextResult(@Nullable AbstractContainerMenu container) {
154157
IJeiRuntime jeiRuntime = Internal.getJeiRuntime();
155158
IIngredientManager ingredientManager = jeiRuntime.getIngredientManager();
156159

157160
while (unsortedIterator.hasNext()) {
158161
T recipe = unsortedIterator.next();
159162
IRecipeLayoutDrawable<T> recipeLayout = createRecipeLayout(recipe);
160-
RecipeLayoutWithButtons<T> recipeLayoutWithButtons = createRecipeLayoutWithButtons(recipeLayout, ingredientManager);
163+
RecipeLayoutWithButtons<T> recipeLayoutWithButtons = createRecipeLayoutWithButtons(recipeLayout, ingredientManager, container);
161164
RecipeTransferButton transferButton = recipeLayoutWithButtons.transferButton();
162165

163166
if (matchingCraftable) {

0 commit comments

Comments
 (0)