修复药水配方问题

This commit is contained in:
17146 2025-07-07 22:51:35 +08:00 committed by Light_Quanta
parent f0642bb279
commit 6258da944c
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
3 changed files with 58 additions and 2 deletions

View file

@ -62,7 +62,7 @@ public class Mod {
ModEntities.REGISTRY.register(bus);
ModMobEffects.REGISTRY.register(bus);
ModParticleTypes.REGISTRY.register(bus);
ModPotion.POTIONS.register(bus);
ModPotions.POTIONS.register(bus);
ModMenuTypes.REGISTRY.register(bus);
ModVillagers.register(bus);
ModRecipes.RECIPE_SERIALIZERS.register(bus);

View file

@ -8,7 +8,7 @@ import net.neoforged.neoforge.registries.DeferredHolder;
import net.neoforged.neoforge.registries.DeferredRegister;
@SuppressWarnings("unused")
public class ModPotion {
public class ModPotions {
public static final DeferredRegister<Potion> POTIONS = DeferredRegister.create(BuiltInRegistries.POTION, Mod.MODID);
public static final DeferredHolder<Potion, Potion> SHOCK = POTIONS.register("superbwarfare_shock",

View file

@ -0,0 +1,56 @@
package com.atsuishio.superbwarfare.recipe;
import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.init.ModPotions;
import com.momosoftworks.coldsweat.util.item.PotionUtils;
import net.minecraft.core.Holder;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.alchemy.Potion;
import net.minecraft.world.item.alchemy.Potions;
import net.minecraft.world.item.crafting.Ingredient;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.neoforge.common.brewing.BrewingRecipe;
import net.neoforged.neoforge.common.brewing.IBrewingRecipe;
import net.neoforged.neoforge.event.brewing.RegisterBrewingRecipesEvent;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
@EventBusSubscriber(modid = Mod.MODID)
public class ModPotionRecipes {
@SubscribeEvent
public static void register(RegisterBrewingRecipesEvent event) {
ItemStack water = potion(Potions.WATER);
ItemStack shock = potion(ModPotions.SHOCK);
ItemStack strongShock = potion(ModPotions.STRONG_SHOCK);
ItemStack longShock = potion(ModPotions.LONG_SHOCK);
event.getBuilder().addRecipe(createRecipe(Ingredient.of(water), Ingredient.of(Items.LIGHTNING_ROD), shock));
event.getBuilder().addRecipe(createRecipe(Ingredient.of(shock), Ingredient.of(Items.GLOWSTONE_DUST), strongShock));
event.getBuilder().addRecipe(createRecipe(Ingredient.of(shock), Ingredient.of(Items.REDSTONE), longShock));
}
private static ItemStack potion(Holder<Potion> potion) {
return PotionUtils.setPotion(Items.POTION.getDefaultInstance(), potion);
}
private static IBrewingRecipe createRecipe(Ingredient input, Ingredient ingredient, ItemStack output) {
return new BrewingRecipe(input, ingredient, output) {
@Override
public boolean isInput(@NotNull ItemStack stack) {
ItemStack[] matchingStacks = input.getItems();
return matchingStacks.length == 0 ? stack.isEmpty() : Arrays.stream(matchingStacks).anyMatch((itemstack) -> ItemStack.isSameItemSameComponents(itemstack, stack));
}
@Override
public boolean isIngredient(@NotNull ItemStack stack) {
ItemStack[] matchingStacks = ingredient.getItems();
return matchingStacks.length == 0 ? stack.isEmpty() : Arrays.stream(matchingStacks).anyMatch((itemstack) -> ItemStack.isSameItemSameComponents(itemstack, stack));
}
};
}
}