Skip to content

Commit be35470

Browse files
committed
Add convenience function for setting the standard slot background
1 parent b5ba8ce commit be35470

File tree

9 files changed

+37
-18
lines changed

9 files changed

+37
-18
lines changed

CommonApi/src/main/java/mezz/jei/api/gui/builder/IRecipeSlotBuilder.java

+11
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import mezz.jei.api.gui.drawable.IDrawable;
44
import mezz.jei.api.gui.ingredient.IRecipeSlotRichTooltipCallback;
55
import mezz.jei.api.gui.ingredient.IRecipeSlotsView;
6+
import mezz.jei.api.helpers.IGuiHelper;
67
import mezz.jei.api.ingredients.IIngredientRenderer;
78
import mezz.jei.api.ingredients.IIngredientType;
89
import mezz.jei.api.recipe.category.IRecipeCategory;
@@ -51,6 +52,16 @@ public interface IRecipeSlotBuilder extends IIngredientAcceptor<IRecipeSlotBuild
5152
*/
5253
IRecipeSlotBuilder setSlotName(String slotName);
5354

55+
/**
56+
* Set a normal slot background to draw behind the slot's ingredients.
57+
* This background is 18x18 pixels and offset by -1, -1 to match vanilla slots.
58+
*
59+
* @see IGuiHelper#getSlotDrawable() for the slot background drawable.
60+
*
61+
* @since 19.18.7
62+
*/
63+
IRecipeSlotBuilder setStandardSlotBackground();
64+
5465
/**
5566
* Set a custom background to draw behind the slot's ingredients.
5667
*

Library/src/main/java/mezz/jei/library/gui/recipes/layout/builder/RecipeSlotBuilder.java

+11
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,19 @@
44
import it.unimi.dsi.fastutil.ints.IntSet;
55
import mezz.jei.api.gui.builder.IRecipeSlotBuilder;
66
import mezz.jei.api.gui.drawable.IDrawable;
7+
import mezz.jei.api.gui.drawable.IDrawableStatic;
78
import mezz.jei.api.gui.ingredient.IRecipeSlotDrawable;
89
import mezz.jei.api.gui.ingredient.IRecipeSlotRichTooltipCallback;
910
import mezz.jei.api.gui.widgets.ISlottedWidgetFactory;
11+
import mezz.jei.api.helpers.IGuiHelper;
1012
import mezz.jei.api.ingredients.IIngredientRenderer;
1113
import mezz.jei.api.ingredients.IIngredientType;
1214
import mezz.jei.api.ingredients.IIngredientTypeWithSubtypes;
1315
import mezz.jei.api.ingredients.ITypedIngredient;
1416
import mezz.jei.api.recipe.IFocusGroup;
1517
import mezz.jei.api.recipe.RecipeIngredientRole;
1618
import mezz.jei.api.runtime.IIngredientManager;
19+
import mezz.jei.common.Internal;
1720
import mezz.jei.common.gui.elements.OffsetDrawable;
1821
import mezz.jei.common.platform.IPlatformFluidHelperInternal;
1922
import mezz.jei.common.platform.Services;
@@ -101,6 +104,14 @@ public IRecipeSlotBuilder addOptionalTypedIngredients(List<Optional<ITypedIngred
101104
return this;
102105
}
103106

107+
@Override
108+
public IRecipeSlotBuilder setStandardSlotBackground() {
109+
IGuiHelper guiHelper = Internal.getJeiRuntime().getJeiHelpers().getGuiHelper();
110+
IDrawableStatic background = guiHelper.getSlotDrawable();
111+
this.background = OffsetDrawable.create(background, -1, -1);
112+
return this;
113+
}
114+
104115
@Override
105116
public IRecipeSlotBuilder setBackground(IDrawable background, int xOffset, int yOffset) {
106117
ErrorUtil.checkNotNull(background, "background");

Library/src/main/java/mezz/jei/library/gui/recipes/supplier/builder/IngredientSlotBuilder.java

+5
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ public IRecipeSlotBuilder addOptionalTypedIngredients(List<Optional<ITypedIngred
7575
return this;
7676
}
7777

78+
@Override
79+
public IRecipeSlotBuilder setStandardSlotBackground() {
80+
return this;
81+
}
82+
7883
@Override
7984
public IRecipeSlotBuilder setBackground(IDrawable background, int xOffset, int yOffset) {
8085
return this;

Library/src/main/java/mezz/jei/library/plugins/debug/ObnoxiouslyLargeCategory.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ public void setRecipe(IRecipeLayoutBuilder builder, ObnoxiouslyLargeRecipe recip
7373
int yPos = yOffset + (y * slotHeight);
7474
ItemStack stack = iterator.next();
7575
builder.addSlot(RecipeIngredientRole.INPUT, xPos + 1, yPos + 1)
76-
.setBackground(slotBackground, -1, -1)
76+
.setStandardSlotBackground()
7777
.addItemStack(stack);
7878
}
7979
}
8080

8181
builder.addSlot(RecipeIngredientRole.OUTPUT, WIDTH + slotWidth, HEIGHT / 2)
82-
.setBackground(slotBackground, -1, -1)
82+
.setStandardSlotBackground()
8383
.addItemStack(iterator.next());
8484
}
8585

Library/src/main/java/mezz/jei/library/plugins/jei/info/IngredientInfoRecipeCategory.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public void setRecipe(IRecipeLayoutBuilder builder, IJeiIngredientInfoRecipe rec
8787
int xPos = (recipeWidth - 16) / 2;
8888

8989
IRecipeSlotBuilder inputSlotBuilder = builder.addSlot(RecipeIngredientRole.INPUT, xPos, 1)
90-
.setBackground(slotBackground, -1, -1);
90+
.setStandardSlotBackground();
9191

9292
IIngredientAcceptor<?> outputSlotBuilder = builder.addInvisibleIngredients(RecipeIngredientRole.OUTPUT);
9393

Library/src/main/java/mezz/jei/library/plugins/jei/tags/TagInfoRecipeCategory.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import mezz.jei.api.gui.builder.IRecipeLayoutBuilder;
44
import mezz.jei.api.gui.builder.ITooltipBuilder;
55
import mezz.jei.api.gui.drawable.IDrawable;
6-
import mezz.jei.api.gui.drawable.IDrawableStatic;
76
import mezz.jei.api.gui.ingredient.IRecipeSlotsView;
87
import mezz.jei.api.gui.widgets.IScrollGridWidgetFactory;
98
import mezz.jei.api.helpers.IGuiHelper;
@@ -41,12 +40,10 @@ public class TagInfoRecipeCategory<R extends ITagInfoRecipe, T extends RecipeTyp
4140
private final Component localizedName;
4241
private final ImmutableRect2i nameArea;
4342
private final IScrollGridWidgetFactory<?> scrollGridFactory;
44-
private final IDrawableStatic slotDrawable;
4543

4644
public TagInfoRecipeCategory(IGuiHelper guiHelper, T recipeType, ResourceLocation registryLocation) {
4745
this.background = guiHelper.createBlankDrawable(WIDTH, HEIGHT);
4846
this.icon = guiHelper.createDrawableItemLike(Items.NAME_TAG);
49-
this.slotDrawable = guiHelper.getSlotDrawable();
5047
this.recipeType = recipeType;
5148
Component registryName = Component.translatableWithFallback(
5249
"gui.jei.category.registry." + ResourceLocationUtil.sanitizePath(registryLocation.getPath()),
@@ -89,7 +86,7 @@ public void setRecipe(IRecipeLayoutBuilder builder, R recipe, IFocusGroup focuse
8986
ScreenRectangle gridArea = scrollGridFactory.getArea();
9087
builder.addSlot(RecipeIngredientRole.INPUT, gridArea.position().x() + 1, 1)
9188
.addTypedIngredients(recipe.getTypedIngredients())
92-
.setBackground(slotDrawable, -1, -1);
89+
.setStandardSlotBackground();
9390

9491
for (ITypedIngredient<?> stack : recipe.getTypedIngredients()) {
9592
builder.addSlotToWidget(RecipeIngredientRole.OUTPUT, scrollGridFactory)

Library/src/main/java/mezz/jei/library/plugins/vanilla/anvil/SmithingRecipeCategory.java

+4-6
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,11 @@
3434
public class SmithingRecipeCategory implements IRecipeCategory<RecipeHolder<SmithingRecipe>>, IExtendableSmithingRecipeCategory {
3535
private final IDrawable background;
3636
private final IDrawable icon;
37-
private final IDrawable slot;
3837
private final IDrawable recipeArrow;
3938
private final Map<Class<? extends SmithingRecipe>, ISmithingCategoryExtension<?>> extensions = new HashMap<>();
4039

4140
public SmithingRecipeCategory(IGuiHelper guiHelper) {
4241
background = guiHelper.createBlankDrawable(108, 28);
43-
slot = guiHelper.getSlotDrawable();
4442
icon = guiHelper.createDrawableItemLike(Blocks.SMITHING_TABLE);
4543
Textures textures = Internal.getTextures();
4644
recipeArrow = textures.getRecipeArrow();
@@ -76,16 +74,16 @@ public void setRecipe(IRecipeLayoutBuilder builder, RecipeHolder<SmithingRecipe>
7674
}
7775

7876
IRecipeSlotBuilder templateSlot = builder.addSlot(RecipeIngredientRole.INPUT, 1, 6)
79-
.setBackground(slot, -1, -1);
77+
.setStandardSlotBackground();
8078

8179
IRecipeSlotBuilder baseSlot = builder.addSlot(RecipeIngredientRole.INPUT, 19, 6)
82-
.setBackground(slot, -1, -1);
80+
.setStandardSlotBackground();
8381

8482
IRecipeSlotBuilder additionSlot = builder.addSlot(RecipeIngredientRole.INPUT, 37, 6)
85-
.setBackground(slot, -1, -1);
83+
.setStandardSlotBackground();
8684

8785
IRecipeSlotBuilder outputSlot = builder.addSlot(RecipeIngredientRole.OUTPUT, 91, 6)
88-
.setBackground(slot, -1, -1);
86+
.setStandardSlotBackground();
8987

9088
extension.setTemplate(recipe, templateSlot);
9189
extension.setBase(recipe, baseSlot);

Library/src/main/java/mezz/jei/library/plugins/vanilla/brewing/BrewingRecipeCategory.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
public class BrewingRecipeCategory implements IRecipeCategory<IJeiBrewingRecipe> {
2828
private final IDrawable background;
2929
private final IDrawable icon;
30-
private final IDrawable slotDrawable;
3130
private final Component localizedName;
3231
private final IDrawableAnimated arrow;
3332
private final IDrawableAnimated bubbles;
@@ -49,8 +48,6 @@ public BrewingRecipeCategory(IGuiHelper guiHelper) {
4948
.buildAnimated(bubblesTickTimer, IDrawableAnimated.StartDirection.BOTTOM);
5049

5150
blazeHeat = guiHelper.createDrawable(location, 64, 29, 18, 4);
52-
53-
slotDrawable = guiHelper.getSlotDrawable();
5451
}
5552

5653
@Override
@@ -104,7 +101,7 @@ public void setRecipe(IRecipeLayoutBuilder builder, IJeiBrewingRecipe recipe, IF
104101

105102
builder.addSlot(RecipeIngredientRole.OUTPUT, 81, 3)
106103
.addItemStack(recipe.getPotionOutput())
107-
.setBackground(slotDrawable, -1, -1);
104+
.setStandardSlotBackground();
108105
}
109106

110107
@Override

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,4 @@ modrinthId=u6dRKJwZ
7474
jUnitVersion=5.8.2
7575

7676
# Version
77-
specificationVersion=19.18.6
77+
specificationVersion=19.18.7

0 commit comments

Comments
 (0)