Skip to content

Commit 4cc4c5a

Browse files
committed
Fix broken JEI integration when multiple recipes are displayed
1 parent 63b2519 commit 4cc4c5a

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

src/client/java/dev/technici4n/moderndynamics/client/compat/jei/UpgradeCategory.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ public class UpgradeCategory implements IRecipeCategory<UpgradeDisplay> {
5252
private final IDrawable icon;
5353
private final IDrawable background;
5454
private final IDrawable slotDrawable;
55-
private final List<UpgradeEffect> effects = new ArrayList<>();
5655
private final IDrawable[] icons;
57-
private int effectsBaseX;
5856

5957
public UpgradeCategory(IGuiHelper guiHelper) {
6058
this.background = guiHelper.createBlankDrawable(150, 67);
@@ -96,10 +94,12 @@ public IDrawable getBackground() {
9694
public void setRecipe(IRecipeLayoutBuilder builder, UpgradeDisplay recipe, IFocusGroup focuses) {
9795
builder.addSlot(RecipeIngredientRole.INPUT, 7, 7)
9896
.addItemStack(new ItemStack(recipe.item()));
97+
}
9998

99+
private EffectsInfo computeEffects(UpgradeDisplay recipe) {
100100
var type = recipe.upgradeInfo();
101101

102-
effects.clear();
102+
var effects = new ArrayList<UpgradeEffect>();
103103
effects.add(new UpgradeEffect(0, type.isEnableAdvancedBehavior() ? -1 : 0, "enableAdvancedBehavior",
104104
I18n.get("gui.moderndynamics.tooltip.advanced_behavior_available")));
105105
effects.add(new UpgradeEffect(1, type.getAddFilterSlots(), "addFilterSlots", "+" + type.getAddFilterSlots()));
@@ -114,7 +114,9 @@ public void setRecipe(IRecipeLayoutBuilder builder, UpgradeDisplay recipe, IFocu
114114
effects.removeIf(e -> e.count() == 0);
115115

116116
int totalWidth = effects.size() * EFFECT_WIDTH + (effects.size() - 1) * EFFECT_SPACING;
117-
effectsBaseX = (background.getWidth() - totalWidth) / 2;
117+
int effectsBaseX = (background.getWidth() - totalWidth) / 2;
118+
119+
return new EffectsInfo(effects, effectsBaseX);
118120
}
119121

120122
@Override
@@ -137,9 +139,11 @@ public void draw(UpgradeDisplay recipe, IRecipeSlotsView recipeSlotsView, PoseSt
137139
var effectsTextX = (background.getWidth() - fontRenderer.width(effectsText)) / 2;
138140
fontRenderer.draw(stack, effectsText, effectsTextX, 5 + 22, 0xFF404040);
139141

140-
int baseX = effectsBaseX;
142+
var effects = computeEffects(recipe);
143+
144+
int baseX = effects.effectsBaseX();
141145

142-
for (var e : effects) {
146+
for (var e : effects.effects()) {
143147
icons[e.iconIndex].draw(stack, baseX, EFFECT_BASE_Y);
144148
if (e.count >= 0) {
145149
fontRenderer.draw(stack, String.valueOf(e.count), baseX + countXOffset, countY, 0xFF404040);
@@ -151,8 +155,10 @@ public void draw(UpgradeDisplay recipe, IRecipeSlotsView recipeSlotsView, PoseSt
151155

152156
@Override
153157
public List<Component> getTooltipStrings(UpgradeDisplay recipe, IRecipeSlotsView recipeSlotsView, double mouseX, double mouseY) {
154-
var x = effectsBaseX;
155-
for (var e : effects) {
158+
var effects = computeEffects(recipe);
159+
160+
var x = effects.effectsBaseX();
161+
for (var e : effects.effects()) {
156162
var tooltipRect = new Rect2i(x, EFFECT_BASE_Y, 20, 20);
157163

158164
if (tooltipRect.contains((int) mouseX, (int) mouseY)) {
@@ -170,4 +176,7 @@ public List<Component> getTooltipStrings(UpgradeDisplay recipe, IRecipeSlotsView
170176

171177
private record UpgradeEffect(int iconIndex, int count, String upgradeName, String greenText) {
172178
}
179+
180+
private record EffectsInfo(List<UpgradeEffect> effects, int effectsBaseX) {
181+
}
173182
}

0 commit comments

Comments
 (0)