Skip to content

Commit

Permalink
fix jei weapon table recipe
Browse files Browse the repository at this point in the history
close #1353
from f2e7d6d
  • Loading branch information
Cheaterpaul committed Apr 17, 2024
1 parent 5dbb736 commit 9f1b077
Showing 1 changed file with 56 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,16 @@ public Component getTitle() {
return localizedName;
}



@Override
public void setRecipe(IRecipeLayoutBuilder builder, IWeaponTableRecipe recipe, IFocusGroup focuses) {
if (recipe instanceof ShapelessWeaponTableRecipe) {
builder.setShapeless();
}
List<List<ItemStack>> inputs = recipe.getIngredients().stream()
.map(ingredient -> List.of(ingredient.getItems()))
.toList();
List<List<ItemStack>> list = recipe.getIngredients().stream().map(s -> List.of(s.getItems())).toList();
IRecipeSlotBuilder output = builder.addSlot(RecipeIngredientRole.OUTPUT, 112, 32);
output.addItemStack(RecipeUtil.getResultItem(recipe));
Expand All @@ -130,15 +135,60 @@ public void setRecipe(IRecipeLayoutBuilder builder, IWeaponTableRecipe recipe, I
int height = recipe instanceof IShapedRecipe<?> shaped ? shaped.getRecipeHeight() : 4;
int width = recipe instanceof IShapedRecipe<?> shaped ? shaped.getRecipeWidth() : 4;

for (int i = 0; i < height; i++) {
for (int i1 = 0; i1 < width; i1++) {
IRecipeSlotBuilder slot = inputSlots.get(i1 + i * 4);
for (int i = 0; i < inputs.size(); i++) {
int index = getCraftingIndex(i, width, height);
IRecipeSlotBuilder slot = inputSlots.get(index);
List<ItemStack> itemStacks = inputs.get(i);
if (itemStacks != null) {
slot.addIngredients(VanillaTypes.ITEM_STACK, itemStacks);
}
}
}

List<ItemStack> itemList = list.get(i1 + i * width);
if (itemList != null) {
slot.addIngredients(VanillaTypes.ITEM_STACK, itemList);
private static int getCraftingIndex(int i, int width, int height) {
int index;
if (width == 1) {
if (height == 4) {
index = (i * 4) + 1;
} else if (height == 3) {
index = (i * 4) + 1;
} else if (height == 2) {
index = (i * 4) + 1;
} else {
index = 5;
}
} else if (height == 1) {
index = i + 4;
} else if (width == 2) {
index = i;
if (i > 1) {
index+=2;
if (i > 3) {
index+=2;
if (i > 5){
index+=2;
}
}
}
} else if (height == 2) {
index = i;
if (width == 3 && i > 2) {
index++;
}
} else if (width == 3) {
index = i;
if (i > 2) {
index++;
if (i > 5) {
index++;
if (i > 8) {
index++;
}
}
}
} else {
index = i;
}
return index;
}
}

0 comments on commit 9f1b077

Please sign in to comment.