Skip to content

Commit

Permalink
Fix #3794 Avoid storing the client player in a field, it can leak whe…
Browse files Browse the repository at this point in the history
…n traveling between dimensions
  • Loading branch information
mezz committed Oct 4, 2024
1 parent bc0098d commit 493fd1a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 24 deletions.
3 changes: 0 additions & 3 deletions Gui/src/main/java/mezz/jei/gui/recipes/RecipeGuiLogic.java
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,6 @@ public List<RecipeLayoutWithButtons<?>> getVisibleRecipeLayoutsWithButtons(
BookmarkList bookmarkList,
RecipesGui recipesGui
) {
Player player = Minecraft.getInstance().player;

IRecipeCategory<?> recipeCategory = getSelectedRecipeCategory();

IJeiClientConfigs jeiClientConfigs = Internal.getJeiClientConfigs();
Expand All @@ -217,7 +215,6 @@ public List<RecipeLayoutWithButtons<?>> getVisibleRecipeLayoutsWithButtons(
this.cachedRecipeLayoutsWithButtons = IRecipeLayoutList.create(
recipeSorterStages,
container,
player,
focusedRecipes,
state.getFocuses(),
bookmarkList,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
import mezz.jei.common.transfer.RecipeTransferUtil;
import mezz.jei.gui.elements.GuiIconToggleButton;
import mezz.jei.gui.input.UserInput;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.client.renderer.Rect2i;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.network.chat.Component;
Expand Down Expand Up @@ -45,7 +47,6 @@ public static RecipeTransferButton create(
private final Runnable onClose;
private @Nullable IRecipeTransferError recipeTransferError;
private @Nullable AbstractContainerMenu parentContainer;
private @Nullable Player player;

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

public void update(@Nullable AbstractContainerMenu parentContainer, @Nullable Player player) {
this.player = player;
this.parentContainer = parentContainer;

if (parentContainer != null && player != null) {
Expand All @@ -81,6 +81,8 @@ protected boolean onMouseClicked(UserInput input) {
if (!input.isSimulate()) {
IRecipeTransferManager recipeTransferManager = Internal.getJeiRuntime().getRecipeTransferManager();
boolean maxTransfer = Screen.hasShiftDown();
Minecraft minecraft = Minecraft.getInstance();
LocalPlayer player = minecraft.player;
if (parentContainer != null && player != null && RecipeTransferUtil.transferRecipe(recipeTransferManager, parentContainer, recipeLayout, player, maxTransfer)) {
onClose.run();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public interface IRecipeLayoutList {
static IRecipeLayoutList create(
Set<RecipeSorterStage> recipeSorterStages,
@Nullable AbstractContainerMenu container,
@Nullable Player player,
IFocusedRecipes<?> selectedRecipes,
IFocusGroup focusGroup,
BookmarkList bookmarkList,
Expand All @@ -29,7 +28,6 @@ static IRecipeLayoutList create(
return new LazyRecipeLayoutList<>(
recipeSorterStages,
container,
player,
selectedRecipes,
bookmarkList,
recipeManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import mezz.jei.gui.recipes.RecipeTransferButton;
import mezz.jei.gui.recipes.RecipesGui;
import mezz.jei.gui.recipes.lookups.IFocusedRecipes;
import net.minecraft.client.Minecraft;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import org.jetbrains.annotations.Nullable;
Expand All @@ -30,7 +31,6 @@

public class LazyRecipeLayoutList<T> implements IRecipeLayoutList {
private final @Nullable AbstractContainerMenu container;
private final @Nullable Player player;
private final IRecipeManager recipeManager;
private final IRecipeCategory<T> recipeCategory;
private final RecipesGui recipesGui;
Expand All @@ -46,7 +46,6 @@ public class LazyRecipeLayoutList<T> implements IRecipeLayoutList {
public LazyRecipeLayoutList(
Set<RecipeSorterStage> recipeSorterStages,
@Nullable AbstractContainerMenu container,
@Nullable Player player,
IFocusedRecipes<T> selectedRecipes,
BookmarkList bookmarkList,
IRecipeManager recipeManager,
Expand All @@ -57,7 +56,6 @@ public LazyRecipeLayoutList(
boolean matchingBookmarks = recipeSorterStages.contains(RecipeSorterStage.BOOKMARKED);
boolean matchingCraftable = recipeSorterStages.contains(RecipeSorterStage.CRAFTABLE);
this.container = container;
this.player = player;
this.recipeManager = recipeManager;
this.recipesGui = recipesGui;
this.focusGroup = focusGroup;
Expand Down Expand Up @@ -86,7 +84,7 @@ public LazyRecipeLayoutList(
RecipeBookmark<T, ?> recipeBookmark = bookmarkList.getMatchingBookmark(recipeType, recipe);
if (recipeBookmark != null) {
IRecipeLayoutDrawable<T> recipeLayout = recipeManager.createRecipeLayoutDrawableOrShowError(recipeCategory, recipe, focusGroup);
RecipeLayoutWithButtons<T> recipeLayoutWithButtons = createRecipeLayoutWithButtons(recipeLayout, recipeBookmark, bookmarkList, recipesGui, container, player);
RecipeLayoutWithButtons<T> recipeLayoutWithButtons = createRecipeLayoutWithButtons(recipeLayout, recipeBookmark, bookmarkList, recipesGui, container);
results.add(recipeLayoutWithButtons);
iterator.remove();
}
Expand All @@ -98,20 +96,15 @@ public LazyRecipeLayoutList(

private static <T> RecipeLayoutWithButtons<T> createRecipeLayoutWithButtons(
IRecipeLayoutDrawable<T> recipeLayoutDrawable,
RecipeBookmark<?, ?> recipeBookmark,
@Nullable RecipeBookmark<?, ?> recipeBookmark,
BookmarkList bookmarks,
RecipesGui recipesGui,
@Nullable AbstractContainerMenu container,
@Nullable Player player
@Nullable AbstractContainerMenu container
) {
Minecraft minecraft = Minecraft.getInstance();
Player player = minecraft.player;
RecipeTransferButton transferButton = RecipeTransferButton.create(recipeLayoutDrawable, recipesGui::onClose, container, player);

RecipeBookmarkButton bookmarkButton = RecipeBookmarkButton.create(
recipeLayoutDrawable,
bookmarks,
recipeBookmark
);

RecipeBookmarkButton bookmarkButton = RecipeBookmarkButton.create(recipeLayoutDrawable, bookmarks, recipeBookmark);
return new RecipeLayoutWithButtons<>(recipeLayoutDrawable, transferButton, bookmarkButton);
}

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

private RecipeLayoutWithButtons<T> createRecipeLayoutWithButtons(IRecipeLayoutDrawable<T> recipeLayoutDrawable, IIngredientManager ingredientManager) {
RecipeTransferButton transferButton = RecipeTransferButton.create(recipeLayoutDrawable, recipesGui::onClose, container, player);
RecipeBookmarkButton bookmarkButton = RecipeBookmarkButton.create(recipeLayoutDrawable, ingredientManager, bookmarkList);
return new RecipeLayoutWithButtons<>(recipeLayoutDrawable, transferButton, bookmarkButton);
RecipeBookmark<T, ?> recipeBookmark = RecipeBookmark.create(recipeLayoutDrawable, ingredientManager);
return createRecipeLayoutWithButtons(recipeLayoutDrawable, recipeBookmark, bookmarkList, recipesGui, container);
}

@Override
Expand Down

0 comments on commit 493fd1a

Please sign in to comment.