Add ore dictionary support for Inscriber recipes in JEI (#430)

This commit is contained in:
zeng-git
2024-05-24 18:51:37 +08:00
committed by GitHub
parent 08a7aff600
commit 59edb38208
10 changed files with 127 additions and 108 deletions
@@ -14,6 +14,7 @@ import net.minecraftforge.common.crafting.CraftingHelper;
import net.minecraftforge.common.crafting.JsonContext;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@@ -27,34 +28,25 @@ public class InscriberHandler implements IAERecipeFactory {
JsonObject ingredients = JsonUtils.getJsonObject(json, "ingredients");
List<ItemStack> middle = Arrays.asList(CraftingHelper.getIngredient(ingredients.get("middle"), ctx).getMatchingStacks());
ItemStack[] top = new ItemStack[]{null};
List<ItemStack> top = Collections.emptyList();
if (ingredients.has("top")) {
top = CraftingHelper.getIngredient(JsonUtils.getJsonObject(ingredients, "top"), ctx).getMatchingStacks();
top = Arrays.asList(CraftingHelper.getIngredient(JsonUtils.getJsonObject(ingredients, "top"), ctx).getMatchingStacks());
}
ItemStack[] bottom = new ItemStack[]{null};
List<ItemStack> bottom = Collections.emptyList();
if (ingredients.has("bottom")) {
bottom = CraftingHelper.getIngredient(JsonUtils.getJsonObject(ingredients, "bottom"), ctx).getMatchingStacks();
bottom = Arrays.asList(CraftingHelper.getIngredient(JsonUtils.getJsonObject(ingredients, "bottom"), ctx).getMatchingStacks());
}
final IInscriberRegistry reg = AEApi.instance().registries().inscriber();
for (int i = 0; i < top.length; ++i) {
for (int j = 0; j < bottom.length; ++j) {
final IInscriberRecipeBuilder builder = reg.builder();
builder.withOutput(result);
builder.withProcessType("press".equals(mode) ? InscriberProcessType.PRESS : InscriberProcessType.INSCRIBE);
builder.withInputs(middle);
if (top[i] != null) {
builder.withTopOptional(top[i]);
}
if (bottom[j] != null) {
builder.withBottomOptional(bottom[j]);
}
reg.addRecipe(builder.build());
}
if (!top.isEmpty() || !bottom.isEmpty()) {
final IInscriberRecipeBuilder builder = reg.builder();
builder.withOutput(result);
builder.withProcessType("press".equals(mode) ? InscriberProcessType.PRESS : InscriberProcessType.INSCRIBE);
builder.withTopOptional(top);
builder.withInputs(middle);
builder.withBottomOptional(bottom);
reg.addRecipe(builder.build());
}
}
}