Skip to content

Commit ee33b5d

Browse files
committed
Fix JEI overlay when the recipe book is open
1 parent 96da829 commit ee33b5d

File tree

7 files changed

+27
-25
lines changed

7 files changed

+27
-25
lines changed

Common/src/main/java/mezz/jei/common/platform/IPlatformScreenHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ public interface IPlatformScreenHelper {
2323

2424
int getYSize(AbstractContainerScreen<?> containerScreen);
2525

26-
ImmutableRect2i getBookArea(AbstractRecipeBookScreen<?> screen);
27-
2826
ImmutableRect2i getToastsArea();
2927

3028
List<RecipeBookTabButton> getTabButtons(RecipeBookComponent<?> recipeBookComponent);
3129

3230
<T extends RecipeBookMenu> RecipeBookComponent<?> getRecipeBookComponent(AbstractRecipeBookScreen<T> screen);
3331

32+
ImmutableRect2i getBookArea(RecipeBookComponent<?> guiRecipeBook);
33+
3434
boolean canLoseFocus(EditBox editBox);
3535
}

Fabric/src/main/java/mezz/jei/fabric/platform/ScreenHelper.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,14 @@ public int getYSize(AbstractContainerScreen<?> containerScreen) {
4545
}
4646

4747
@Override
48-
public ImmutableRect2i getBookArea(AbstractRecipeBookScreen<?> screen) {
49-
RecipeBookComponent<?> guiRecipeBook = getRecipeBookComponent(screen);
48+
public ImmutableRect2i getBookArea(RecipeBookComponent<?> guiRecipeBook) {
5049
if (guiRecipeBook.isVisible()) {
51-
int i = (guiRecipeBook.width - 147) / 2 - guiRecipeBook.xOffset;
52-
int j = (guiRecipeBook.height - 166) / 2;
53-
return new ImmutableRect2i(i, j, 147, 166);
50+
return new ImmutableRect2i(
51+
guiRecipeBook.getXOrigin(),
52+
guiRecipeBook.getYOrigin(),
53+
RecipeBookComponent.IMAGE_WIDTH,
54+
RecipeBookComponent.IMAGE_HEIGHT
55+
);
5456
}
5557
return ImmutableRect2i.EMPTY;
5658
}

Fabric/src/main/resources/jei.accesswidener

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ accessible field net/minecraft/client/gui/screens/recipebook/RecipeBookComponent
1212
accessible field net/minecraft/client/gui/screens/recipebook/RecipeBookComponent height I
1313
accessible field net/minecraft/client/gui/screens/recipebook/RecipeBookComponent xOffset I
1414
accessible field net/minecraft/client/gui/screens/recipebook/RecipeBookComponent tabButtons Ljava/util/List;
15+
accessible method net/minecraft/client/gui/screens/recipebook/RecipeBookComponent getXOrigin ()I
16+
accessible method net/minecraft/client/gui/screens/recipebook/RecipeBookComponent getYOrigin ()I
1517

1618
accessible field net/minecraft/client/gui/screens/inventory/AbstractRecipeBookScreen recipeBookComponent Lnet/minecraft/client/gui/screens/recipebook/RecipeBookComponent;
1719

Gui/src/main/java/mezz/jei/gui/plugins/AbstractContainerScreenHandler.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
import mezz.jei.api.gui.handlers.IScreenHandler;
55
import mezz.jei.common.platform.IPlatformScreenHelper;
66
import mezz.jei.common.platform.Services;
7-
import mezz.jei.common.util.ImmutableRect2i;
87
import mezz.jei.gui.GuiProperties;
98
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
10-
import net.minecraft.client.gui.screens.inventory.AbstractRecipeBookScreen;
119
import net.minecraft.world.inventory.AbstractContainerMenu;
1210
import org.jetbrains.annotations.Nullable;
1311

@@ -22,14 +20,6 @@ public class AbstractContainerScreenHandler<T extends AbstractContainerMenu> imp
2220
int y = screenHelper.getGuiTop(containerScreen);
2321
int width = screenHelper.getXSize(containerScreen);
2422
int height = screenHelper.getYSize(containerScreen);
25-
if (containerScreen instanceof AbstractRecipeBookScreen<?> r) {
26-
ImmutableRect2i bookArea = screenHelper.getBookArea(r);
27-
if (!bookArea.isEmpty()) {
28-
width += (x - bookArea.getX());
29-
x = bookArea.getX();
30-
}
31-
}
32-
3323
if (x < 0) {
3424
width -= x;
3525
x = 0;

Library/src/main/java/mezz/jei/library/plugins/vanilla/gui/RecipeBookGuiHandler.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import mezz.jei.api.gui.handlers.IGuiContainerHandler;
44
import mezz.jei.common.platform.IPlatformScreenHelper;
55
import mezz.jei.common.platform.Services;
6+
import mezz.jei.common.util.ImmutableRect2i;
67
import net.minecraft.client.gui.GuiGraphics;
78
import net.minecraft.client.gui.screens.inventory.AbstractRecipeBookScreen;
89
import net.minecraft.client.gui.screens.recipebook.RecipeBookComponent;
@@ -24,13 +25,15 @@ public List<Rect2i> getGuiExtraAreas(T containerScreen) {
2425

2526
RecipeBookComponent<?> guiRecipeBook = screenHelper.getRecipeBookComponent(containerScreen);
2627
if (guiRecipeBook.isVisible()) {
27-
List<Rect2i> tabAreas = new ArrayList<>();
28+
List<Rect2i> extraAreas = new ArrayList<>();
29+
ImmutableRect2i bookArea = screenHelper.getBookArea(guiRecipeBook);
30+
extraAreas.add(bookArea.toMutable());
2831
for (RecipeBookTabButton tab : screenHelper.getTabButtons(guiRecipeBook)) {
2932
if (tab.visible) {
30-
tabAreas.add(new Rect2i(tab.getX(), tab.getY(), tab.getWidth(), tab.getHeight()));
33+
extraAreas.add(new Rect2i(tab.getX(), tab.getY(), tab.getWidth(), tab.getHeight()));
3134
}
3235
}
33-
return tabAreas;
36+
return extraAreas;
3437
}
3538
return Collections.emptyList();
3639
}

NeoForge/src/main/java/mezz/jei/neoforge/platform/ScreenHelper.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,14 @@ public int getYSize(AbstractContainerScreen<?> containerScreen) {
4545
}
4646

4747
@Override
48-
public ImmutableRect2i getBookArea(AbstractRecipeBookScreen<?> screen) {
49-
RecipeBookComponent<?> guiRecipeBook = getRecipeBookComponent(screen);
48+
public ImmutableRect2i getBookArea(RecipeBookComponent<?> guiRecipeBook) {
5049
if (guiRecipeBook.isVisible()) {
51-
int i = (guiRecipeBook.width - 147) / 2 - guiRecipeBook.xOffset;
52-
int j = (guiRecipeBook.height - 166) / 2;
53-
return new ImmutableRect2i(i, j, 147, 166);
50+
return new ImmutableRect2i(
51+
guiRecipeBook.getXOrigin(),
52+
guiRecipeBook.getYOrigin(),
53+
RecipeBookComponent.IMAGE_WIDTH,
54+
RecipeBookComponent.IMAGE_HEIGHT
55+
);
5456
}
5557
return ImmutableRect2i.EMPTY;
5658
}

NeoForge/src/main/resources/META-INF/accesstransformer.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,6 @@ public net.minecraft.client.gui.components.toasts.ToastManager visibleToasts
4343
public net.minecraft.client.gui.GuiGraphics blitSprite(Lcom/mojang/blaze3d/pipeline/RenderPipeline;Lnet/minecraft/client/renderer/texture/TextureAtlasSprite;IIIIIIIII)V
4444
public net.minecraft.client.gui.GuiGraphics blitNineSlicedSprite(Lcom/mojang/blaze3d/pipeline/RenderPipeline;Lnet/minecraft/client/renderer/texture/TextureAtlasSprite;Lnet/minecraft/client/resources/metadata/gui/GuiSpriteScaling$NineSlice;IIIII)V
4545
public net.minecraft.client.gui.GuiGraphics blitTiledSprite(Lcom/mojang/blaze3d/pipeline/RenderPipeline;Lnet/minecraft/client/renderer/texture/TextureAtlasSprite;IIIIIIIIIII)V
46+
47+
public net.minecraft.client.gui.screens.recipebook.RecipeBookComponent getXOrigin()I
48+
public net.minecraft.client.gui.screens.recipebook.RecipeBookComponent getYOrigin()I

0 commit comments

Comments
 (0)