Skip to content

Commit

Permalink
Fix #3795 Prevent retaining the player client when crossing dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
mezz committed Oct 4, 2024
1 parent 124b785 commit b8a0253
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 17 deletions.
3 changes: 1 addition & 2 deletions Common/src/main/java/mezz/jei/common/util/TagUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ public class TagUtil {
public static <VALUE, STACK> Optional<TagKey<?>> getTagEquivalent(
Collection<STACK> stacks,
Function<STACK, VALUE> stackToValue,
Supplier<Stream<Pair<TagKey<VALUE>,
HolderSet.Named<VALUE>>>> tagSupplier
Supplier<Stream<Pair<TagKey<VALUE>, HolderSet.Named<VALUE>>>> tagSupplier
) {
List<VALUE> values = stacks.stream()
.map(stackToValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public interface IRecipeGuiLogic {

void nextPage();

void tick();
void tick(@Nullable AbstractContainerMenu container);

boolean showFocus(IFocusGroup focuses);

Expand Down
11 changes: 8 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 @@ -40,6 +40,7 @@ public class RecipeGuiLogic implements IRecipeGuiLogic {
private final IFocusFactory focusFactory;
private @Nullable IRecipeCategory<?> cachedRecipeCategory;
private @Nullable IRecipeLayoutList cachedRecipeLayoutsWithButtons;
private int cachedContainerId = -1;
private Set<RecipeSorterStage> cachedSorterStages = Set.of();

public RecipeGuiLogic(
Expand All @@ -64,9 +65,9 @@ public RecipeGuiLogic(
}

@Override
public void tick() {
public void tick(@Nullable AbstractContainerMenu container) {
if (cachedRecipeLayoutsWithButtons != null) {
cachedRecipeLayoutsWithButtons.tick();
cachedRecipeLayoutsWithButtons.tick(container);
}
}

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

int containerId = container == null ? -1 : container.containerId;
if (!recipeSorterStages.equals(cachedSorterStages) ||
this.cachedRecipeLayoutsWithButtons == null ||
this.cachedRecipeCategory != recipeCategory
this.cachedRecipeCategory != recipeCategory ||
this.cachedContainerId != containerId
) {
IFocusedRecipes<?> focusedRecipes = this.state.getFocusedRecipes();

Expand All @@ -221,6 +225,7 @@ public List<RecipeLayoutWithButtons<?>> getVisibleRecipeLayoutsWithButtons(
);
this.cachedRecipeCategory = recipeCategory;
this.cachedSorterStages = Set.copyOf(recipeSorterStages);
this.cachedContainerId = containerId;
}

final int recipeHeight =
Expand Down
4 changes: 2 additions & 2 deletions Gui/src/main/java/mezz/jei/gui/recipes/RecipesGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ public void tick() {

this.optionButtons.tick();

this.logic.tick();
this.logic.tick(container);
}

@Override
Expand Down Expand Up @@ -554,7 +554,7 @@ private ImmutableRect2i getRecipeLayoutsArea() {
}

@Nullable
private AbstractContainerMenu getParentContainerMenu() {
public AbstractContainerMenu getParentContainerMenu() {
Screen screen;
if (parentScreen == null) {
screen = Minecraft.getInstance().screen;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ static IRecipeLayoutList create(

Optional<RecipeLayoutWithButtons<?>> findFirst();

void tick();
void tick(@Nullable AbstractContainerMenu container);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import java.util.Set;

public class LazyRecipeLayoutList<T> implements IRecipeLayoutList {
private final @Nullable AbstractContainerMenu container;
private final IRecipeManager recipeManager;
private final IRecipeCategory<T> recipeCategory;
private final RecipesGui recipesGui;
Expand All @@ -55,7 +54,6 @@ public LazyRecipeLayoutList(
this.bookmarkList = bookmarkList;
boolean matchingBookmarks = recipeSorterStages.contains(RecipeSorterStage.BOOKMARKED);
boolean matchingCraftable = recipeSorterStages.contains(RecipeSorterStage.CRAFTABLE);
this.container = container;
this.recipeManager = recipeManager;
this.recipesGui = recipesGui;
this.focusGroup = focusGroup;
Expand Down Expand Up @@ -112,7 +110,11 @@ private IRecipeLayoutDrawable<T> createRecipeLayout(T recipe) {
return recipeManager.createRecipeLayoutDrawableOrShowError(recipeCategory, recipe, focusGroup);
}

private RecipeLayoutWithButtons<T> createRecipeLayoutWithButtons(IRecipeLayoutDrawable<T> recipeLayoutDrawable, IIngredientManager ingredientManager) {
private RecipeLayoutWithButtons<T> createRecipeLayoutWithButtons(
IRecipeLayoutDrawable<T> recipeLayoutDrawable,
IIngredientManager ingredientManager,
@Nullable AbstractContainerMenu container
) {
RecipeBookmark<T, ?> recipeBookmark = RecipeBookmark.create(recipeLayoutDrawable, ingredientManager);
return createRecipeLayoutWithButtons(recipeLayoutDrawable, recipeBookmark, bookmarkList, recipesGui, container);
}
Expand All @@ -129,8 +131,9 @@ public List<RecipeLayoutWithButtons<?>> subList(int from, int to) {
}

private void ensureResults(int index) {
AbstractContainerMenu container = recipesGui.getParentContainerMenu();
while (index >= results.size()) {
if (!calculateNextResult()) {
if (!calculateNextResult(container)) {
return;
}
}
Expand All @@ -146,18 +149,18 @@ public Optional<RecipeLayoutWithButtons<?>> findFirst() {
}

@Override
public void tick() {
calculateNextResult();
public void tick(@Nullable AbstractContainerMenu container) {
calculateNextResult(container);
}

private boolean calculateNextResult() {
private boolean calculateNextResult(@Nullable AbstractContainerMenu container) {
IJeiRuntime jeiRuntime = Internal.getJeiRuntime();
IIngredientManager ingredientManager = jeiRuntime.getIngredientManager();

while (unsortedIterator.hasNext()) {
T recipe = unsortedIterator.next();
IRecipeLayoutDrawable<T> recipeLayout = createRecipeLayout(recipe);
RecipeLayoutWithButtons<T> recipeLayoutWithButtons = createRecipeLayoutWithButtons(recipeLayout, ingredientManager);
RecipeLayoutWithButtons<T> recipeLayoutWithButtons = createRecipeLayoutWithButtons(recipeLayout, ingredientManager, container);
RecipeTransferButton transferButton = recipeLayoutWithButtons.transferButton();

if (matchingCraftable) {
Expand Down

0 comments on commit b8a0253

Please sign in to comment.