Skip to content

Commit 493fd1a

Browse files
committed
Fix #3794 Avoid storing the client player in a field, it can leak when traveling between dimensions
1 parent bc0098d commit 493fd1a

File tree

4 files changed

+13
-24
lines changed

4 files changed

+13
-24
lines changed

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,6 @@ public List<RecipeLayoutWithButtons<?>> getVisibleRecipeLayoutsWithButtons(
200200
BookmarkList bookmarkList,
201201
RecipesGui recipesGui
202202
) {
203-
Player player = Minecraft.getInstance().player;
204-
205203
IRecipeCategory<?> recipeCategory = getSelectedRecipeCategory();
206204

207205
IJeiClientConfigs jeiClientConfigs = Internal.getJeiClientConfigs();
@@ -217,7 +215,6 @@ public List<RecipeLayoutWithButtons<?>> getVisibleRecipeLayoutsWithButtons(
217215
this.cachedRecipeLayoutsWithButtons = IRecipeLayoutList.create(
218216
recipeSorterStages,
219217
container,
220-
player,
221218
focusedRecipes,
222219
state.getFocuses(),
223220
bookmarkList,

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
import mezz.jei.common.transfer.RecipeTransferUtil;
1313
import mezz.jei.gui.elements.GuiIconToggleButton;
1414
import mezz.jei.gui.input.UserInput;
15+
import net.minecraft.client.Minecraft;
1516
import net.minecraft.client.gui.GuiGraphics;
1617
import net.minecraft.client.gui.screens.Screen;
18+
import net.minecraft.client.player.LocalPlayer;
1719
import net.minecraft.client.renderer.Rect2i;
1820
import net.minecraft.client.renderer.RenderType;
1921
import net.minecraft.network.chat.Component;
@@ -45,7 +47,6 @@ public static RecipeTransferButton create(
4547
private final Runnable onClose;
4648
private @Nullable IRecipeTransferError recipeTransferError;
4749
private @Nullable AbstractContainerMenu parentContainer;
48-
private @Nullable Player player;
4950

5051
private RecipeTransferButton(IDrawable icon, IRecipeLayoutDrawable<?> recipeLayout, Runnable onClose) {
5152
super(icon, icon);
@@ -54,7 +55,6 @@ private RecipeTransferButton(IDrawable icon, IRecipeLayoutDrawable<?> recipeLayo
5455
}
5556

5657
public void update(@Nullable AbstractContainerMenu parentContainer, @Nullable Player player) {
57-
this.player = player;
5858
this.parentContainer = parentContainer;
5959

6060
if (parentContainer != null && player != null) {
@@ -81,6 +81,8 @@ protected boolean onMouseClicked(UserInput input) {
8181
if (!input.isSimulate()) {
8282
IRecipeTransferManager recipeTransferManager = Internal.getJeiRuntime().getRecipeTransferManager();
8383
boolean maxTransfer = Screen.hasShiftDown();
84+
Minecraft minecraft = Minecraft.getInstance();
85+
LocalPlayer player = minecraft.player;
8486
if (parentContainer != null && player != null && RecipeTransferUtil.transferRecipe(recipeTransferManager, parentContainer, recipeLayout, player, maxTransfer)) {
8587
onClose.run();
8688
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ public interface IRecipeLayoutList {
1919
static IRecipeLayoutList create(
2020
Set<RecipeSorterStage> recipeSorterStages,
2121
@Nullable AbstractContainerMenu container,
22-
@Nullable Player player,
2322
IFocusedRecipes<?> selectedRecipes,
2423
IFocusGroup focusGroup,
2524
BookmarkList bookmarkList,
@@ -29,7 +28,6 @@ static IRecipeLayoutList create(
2928
return new LazyRecipeLayoutList<>(
3029
recipeSorterStages,
3130
container,
32-
player,
3331
selectedRecipes,
3432
bookmarkList,
3533
recipeManager,

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

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import mezz.jei.gui.recipes.RecipeTransferButton;
1919
import mezz.jei.gui.recipes.RecipesGui;
2020
import mezz.jei.gui.recipes.lookups.IFocusedRecipes;
21+
import net.minecraft.client.Minecraft;
2122
import net.minecraft.world.entity.player.Player;
2223
import net.minecraft.world.inventory.AbstractContainerMenu;
2324
import org.jetbrains.annotations.Nullable;
@@ -30,7 +31,6 @@
3031

3132
public class LazyRecipeLayoutList<T> implements IRecipeLayoutList {
3233
private final @Nullable AbstractContainerMenu container;
33-
private final @Nullable Player player;
3434
private final IRecipeManager recipeManager;
3535
private final IRecipeCategory<T> recipeCategory;
3636
private final RecipesGui recipesGui;
@@ -46,7 +46,6 @@ public class LazyRecipeLayoutList<T> implements IRecipeLayoutList {
4646
public LazyRecipeLayoutList(
4747
Set<RecipeSorterStage> recipeSorterStages,
4848
@Nullable AbstractContainerMenu container,
49-
@Nullable Player player,
5049
IFocusedRecipes<T> selectedRecipes,
5150
BookmarkList bookmarkList,
5251
IRecipeManager recipeManager,
@@ -57,7 +56,6 @@ public LazyRecipeLayoutList(
5756
boolean matchingBookmarks = recipeSorterStages.contains(RecipeSorterStage.BOOKMARKED);
5857
boolean matchingCraftable = recipeSorterStages.contains(RecipeSorterStage.CRAFTABLE);
5958
this.container = container;
60-
this.player = player;
6159
this.recipeManager = recipeManager;
6260
this.recipesGui = recipesGui;
6361
this.focusGroup = focusGroup;
@@ -86,7 +84,7 @@ public LazyRecipeLayoutList(
8684
RecipeBookmark<T, ?> recipeBookmark = bookmarkList.getMatchingBookmark(recipeType, recipe);
8785
if (recipeBookmark != null) {
8886
IRecipeLayoutDrawable<T> recipeLayout = recipeManager.createRecipeLayoutDrawableOrShowError(recipeCategory, recipe, focusGroup);
89-
RecipeLayoutWithButtons<T> recipeLayoutWithButtons = createRecipeLayoutWithButtons(recipeLayout, recipeBookmark, bookmarkList, recipesGui, container, player);
87+
RecipeLayoutWithButtons<T> recipeLayoutWithButtons = createRecipeLayoutWithButtons(recipeLayout, recipeBookmark, bookmarkList, recipesGui, container);
9088
results.add(recipeLayoutWithButtons);
9189
iterator.remove();
9290
}
@@ -98,20 +96,15 @@ public LazyRecipeLayoutList(
9896

9997
private static <T> RecipeLayoutWithButtons<T> createRecipeLayoutWithButtons(
10098
IRecipeLayoutDrawable<T> recipeLayoutDrawable,
101-
RecipeBookmark<?, ?> recipeBookmark,
99+
@Nullable RecipeBookmark<?, ?> recipeBookmark,
102100
BookmarkList bookmarks,
103101
RecipesGui recipesGui,
104-
@Nullable AbstractContainerMenu container,
105-
@Nullable Player player
102+
@Nullable AbstractContainerMenu container
106103
) {
104+
Minecraft minecraft = Minecraft.getInstance();
105+
Player player = minecraft.player;
107106
RecipeTransferButton transferButton = RecipeTransferButton.create(recipeLayoutDrawable, recipesGui::onClose, container, player);
108-
109-
RecipeBookmarkButton bookmarkButton = RecipeBookmarkButton.create(
110-
recipeLayoutDrawable,
111-
bookmarks,
112-
recipeBookmark
113-
);
114-
107+
RecipeBookmarkButton bookmarkButton = RecipeBookmarkButton.create(recipeLayoutDrawable, bookmarks, recipeBookmark);
115108
return new RecipeLayoutWithButtons<>(recipeLayoutDrawable, transferButton, bookmarkButton);
116109
}
117110

@@ -120,9 +113,8 @@ private IRecipeLayoutDrawable<T> createRecipeLayout(T recipe) {
120113
}
121114

122115
private RecipeLayoutWithButtons<T> createRecipeLayoutWithButtons(IRecipeLayoutDrawable<T> recipeLayoutDrawable, IIngredientManager ingredientManager) {
123-
RecipeTransferButton transferButton = RecipeTransferButton.create(recipeLayoutDrawable, recipesGui::onClose, container, player);
124-
RecipeBookmarkButton bookmarkButton = RecipeBookmarkButton.create(recipeLayoutDrawable, ingredientManager, bookmarkList);
125-
return new RecipeLayoutWithButtons<>(recipeLayoutDrawable, transferButton, bookmarkButton);
116+
RecipeBookmark<T, ?> recipeBookmark = RecipeBookmark.create(recipeLayoutDrawable, ingredientManager);
117+
return createRecipeLayoutWithButtons(recipeLayoutDrawable, recipeBookmark, bookmarkList, recipesGui, container);
126118
}
127119

128120
@Override

0 commit comments

Comments
 (0)