Skip to content

Commit

Permalink
Fixed JEI crash issue if recipe had less extra items
Browse files Browse the repository at this point in the history
  • Loading branch information
RoboXGamer committed Oct 28, 2024
1 parent e4861e9 commit 6488d79
Showing 1 changed file with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -62,12 +63,27 @@ public void setRecipe(IRecipeLayoutBuilder builder, DiskAssemblerRecipe recipe,
builder.addSlot(RecipeIngredientRole.INPUT, 17 - guiUOffset, 27 - guiVOffset).addIngredients(recipe.diskPort());
builder.addSlot(RecipeIngredientRole.INPUT, 17 - guiUOffset, 45 - guiVOffset).addIngredients(recipe.diskCasing());
builder.addSlot(RecipeIngredientRole.INPUT, 35 - guiUOffset, 36 - guiVOffset).addIngredients(recipe.screws());

builder.addSlot(RecipeIngredientRole.INPUT, 116 - guiUOffset, 27 - guiVOffset).addIngredients(recipe.extras().getFirst());
builder.addSlot(RecipeIngredientRole.INPUT, 134 - guiUOffset, 27 - guiVOffset).addIngredients(recipe.extras().get(1));
builder.addSlot(RecipeIngredientRole.INPUT, 116 - guiUOffset, 45 - guiVOffset).addIngredients(recipe.extras().get(2));
builder.addSlot(RecipeIngredientRole.INPUT, 134 - guiUOffset, 45 - guiVOffset).addIngredients(recipe.extras().get(3));

int l = recipe.extras().size();
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
int index = i * 2 + j;

// Ensure the index is within bounds to prevent crashes
if (index < l) {
int x = (116 + i * 18) - guiUOffset;
int y = (27 + j * 18) - guiVOffset;
var slot = builder.addSlot(RecipeIngredientRole.INPUT, x, y);

if (!recipe.extras().get(index).isEmpty()) {
slot.addIngredients(recipe.extras().get(index));
}
} else {
recipe.extras().set(index, Ingredient.EMPTY);
}
}
}


builder.addSlot(RecipeIngredientRole.OUTPUT, 80 - guiUOffset, 36 - guiVOffset).addIngredient(
VanillaTypes.ITEM_STACK,
recipe.result()
Expand Down

0 comments on commit 6488d79

Please sign in to comment.