diff --git a/src/main/java/com/atsuishio/superbwarfare/Mod.java b/src/main/java/com/atsuishio/superbwarfare/Mod.java index 7e129a3f6..271acaefe 100644 --- a/src/main/java/com/atsuishio/superbwarfare/Mod.java +++ b/src/main/java/com/atsuishio/superbwarfare/Mod.java @@ -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); diff --git a/src/main/java/com/atsuishio/superbwarfare/init/ModPotion.java b/src/main/java/com/atsuishio/superbwarfare/init/ModPotions.java similarity index 97% rename from src/main/java/com/atsuishio/superbwarfare/init/ModPotion.java rename to src/main/java/com/atsuishio/superbwarfare/init/ModPotions.java index 503654f59..a5ac1c0d7 100644 --- a/src/main/java/com/atsuishio/superbwarfare/init/ModPotion.java +++ b/src/main/java/com/atsuishio/superbwarfare/init/ModPotions.java @@ -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 POTIONS = DeferredRegister.create(BuiltInRegistries.POTION, Mod.MODID); public static final DeferredHolder SHOCK = POTIONS.register("superbwarfare_shock", diff --git a/src/main/java/com/atsuishio/superbwarfare/recipe/ModPotionRecipes.java b/src/main/java/com/atsuishio/superbwarfare/recipe/ModPotionRecipes.java new file mode 100644 index 000000000..43b11e6af --- /dev/null +++ b/src/main/java/com/atsuishio/superbwarfare/recipe/ModPotionRecipes.java @@ -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) { + 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)); + } + }; + } + +}