From cd6fb8e5eb13ad1d571f7bce7b1d51aa437d9c5c Mon Sep 17 00:00:00 2001 From: 17146 <1714673995@qq.com> Date: Sun, 23 Feb 2025 02:51:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0shells=E7=9A=84jei=E9=85=8D?= =?UTF-8?q?=E6=96=B9=E6=9F=A5=E7=9C=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jei/PotionMortarShellRecipeMaker.java | 40 +++++++++++++++++++ .../compat/jei/SbwJEIPlugin.java | 33 ++++++++++++++- 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/atsuishio/superbwarfare/compat/jei/PotionMortarShellRecipeMaker.java diff --git a/src/main/java/com/atsuishio/superbwarfare/compat/jei/PotionMortarShellRecipeMaker.java b/src/main/java/com/atsuishio/superbwarfare/compat/jei/PotionMortarShellRecipeMaker.java new file mode 100644 index 000000000..b6fa876fb --- /dev/null +++ b/src/main/java/com/atsuishio/superbwarfare/compat/jei/PotionMortarShellRecipeMaker.java @@ -0,0 +1,40 @@ +package com.atsuishio.superbwarfare.compat.jei; + +import com.atsuishio.superbwarfare.init.ModItems; +import mezz.jei.api.constants.ModIds; +import net.minecraft.core.NonNullList; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import net.minecraft.world.item.alchemy.PotionUtils; +import net.minecraft.world.item.crafting.CraftingBookCategory; +import net.minecraft.world.item.crafting.CraftingRecipe; +import net.minecraft.world.item.crafting.Ingredient; +import net.minecraft.world.item.crafting.ShapedRecipe; +import net.minecraftforge.registries.ForgeRegistries; + +import java.util.List; + +public class PotionMortarShellRecipeMaker { + + public static List createRecipes() { + String group = "jei.potion_mortar_shell"; + Ingredient ingredient = Ingredient.of(new ItemStack(ModItems.MORTAR_SHELL.get())); + + return ForgeRegistries.POTIONS.getValues().stream() + .map(potion -> { + ItemStack input = PotionUtils.setPotion(new ItemStack(Items.LINGERING_POTION), potion); + ItemStack output = PotionUtils.setPotion(new ItemStack(ModItems.POTION_MORTAR_SHELL.get(), 4), potion); + + Ingredient potionIngredient = Ingredient.of(input); + NonNullList inputs = NonNullList.of(Ingredient.EMPTY, + Ingredient.EMPTY, ingredient, Ingredient.EMPTY, + ingredient, potionIngredient, ingredient, + Ingredient.EMPTY, ingredient, Ingredient.EMPTY + ); + ResourceLocation id = new ResourceLocation(ModIds.MINECRAFT_ID, group + "." + output.getDescriptionId()); + return new ShapedRecipe(id, group, CraftingBookCategory.MISC, 3, 3, inputs, output); + }) + .toList(); + } +} diff --git a/src/main/java/com/atsuishio/superbwarfare/compat/jei/SbwJEIPlugin.java b/src/main/java/com/atsuishio/superbwarfare/compat/jei/SbwJEIPlugin.java index 42a026c95..1b0317573 100644 --- a/src/main/java/com/atsuishio/superbwarfare/compat/jei/SbwJEIPlugin.java +++ b/src/main/java/com/atsuishio/superbwarfare/compat/jei/SbwJEIPlugin.java @@ -4,22 +4,53 @@ import com.atsuishio.superbwarfare.ModUtils; import com.atsuishio.superbwarfare.init.ModItems; import mezz.jei.api.IModPlugin; import mezz.jei.api.JeiPlugin; +import mezz.jei.api.constants.RecipeTypes; +import mezz.jei.api.ingredients.subtypes.IIngredientSubtypeInterpreter; import mezz.jei.api.registration.IRecipeRegistration; +import mezz.jei.api.registration.ISubtypeRegistration; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.alchemy.Potion; +import net.minecraft.world.item.alchemy.PotionUtils; +import net.minecraft.world.item.crafting.CraftingRecipe; import org.jetbrains.annotations.NotNull; +import java.util.List; + @JeiPlugin public class SbwJEIPlugin implements IModPlugin { + @Override public @NotNull ResourceLocation getPluginUid() { - return new ResourceLocation(ModUtils.MODID, "jei_plugin"); + return ModUtils.loc("jei_plugin"); } @Override public void registerRecipes(@NotNull IRecipeRegistration registration) { registration.addItemStackInfo(new ItemStack(ModItems.ANCIENT_CPU.get()), Component.translatable("jei.superbwarfare.ancient_cpu")); registration.addItemStackInfo(new ItemStack(ModItems.CHARGING_STATION.get()), Component.translatable("jei.superbwarfare.charging_station")); + + List specialCraftingRecipes = PotionMortarShellRecipeMaker.createRecipes(); + registration.addRecipes(RecipeTypes.CRAFTING, specialCraftingRecipes); + } + + @Override + public void registerItemSubtypes(ISubtypeRegistration registration) { + registration.registerSubtypeInterpreter(ModItems.POTION_MORTAR_SHELL.get(), (stack, context) -> { + if (!stack.hasTag()) { + return IIngredientSubtypeInterpreter.NONE; + } + Potion potionType = PotionUtils.getPotion(stack); + String potionTypeString = potionType.getName(""); + StringBuilder stringBuilder = new StringBuilder(potionTypeString); + List effects = PotionUtils.getMobEffects(stack); + for (MobEffectInstance effect : effects) { + stringBuilder.append(";").append(effect); + } + + return stringBuilder.toString(); + }); } }