diff --git a/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e b/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e new file mode 100644 index 000000000..d19f735ba --- /dev/null +++ b/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e @@ -0,0 +1,2 @@ +// 1.20.1 2025-02-22T22:55:11.4694739 Recipes +2e1d1bbf32801f3d355c0d3f78ebbb1122cebd4c data/minecraft/recipes/potion_mortar_shell.json diff --git a/src/generated/resources/data/minecraft/recipes/potion_mortar_shell.json b/src/generated/resources/data/minecraft/recipes/potion_mortar_shell.json new file mode 100644 index 000000000..e5ee9b624 --- /dev/null +++ b/src/generated/resources/data/minecraft/recipes/potion_mortar_shell.json @@ -0,0 +1,4 @@ +{ + "type": "superbwarfare:potion_mortar_shell", + "category": "misc" +} \ No newline at end of file diff --git a/src/main/java/com/atsuishio/superbwarfare/ModUtils.java b/src/main/java/com/atsuishio/superbwarfare/ModUtils.java index e2ca06fc4..dd3edec50 100644 --- a/src/main/java/com/atsuishio/superbwarfare/ModUtils.java +++ b/src/main/java/com/atsuishio/superbwarfare/ModUtils.java @@ -65,6 +65,7 @@ public class ModUtils { ModPotion.POTIONS.register(bus); ModMenuTypes.REGISTRY.register(bus); ModVillagers.register(bus); + ModRecipes.RECIPE_SERIALIZERS.register(bus); bus.addListener(this::onCommonSetup); bus.addListener(this::onClientSetup); diff --git a/src/main/java/com/atsuishio/superbwarfare/datagen/DataGenerators.java b/src/main/java/com/atsuishio/superbwarfare/datagen/DataGenerators.java index 3b648fbeb..27e628d35 100644 --- a/src/main/java/com/atsuishio/superbwarfare/datagen/DataGenerators.java +++ b/src/main/java/com/atsuishio/superbwarfare/datagen/DataGenerators.java @@ -22,7 +22,7 @@ public class DataGenerators { ExistingFileHelper existingFileHelper = event.getExistingFileHelper(); generator.addProvider(event.includeServer(), ModLootTableProvider.create(packOutput)); -// generator.addProvider(event.includeServer(), new ModWorldGenProvider(packOutput, lookupProvider)); + generator.addProvider(event.includeServer(), new ModRecipeProvider(packOutput)); generator.addProvider(event.includeServer(), new ModBlockStateProvider(packOutput, existingFileHelper)); generator.addProvider(event.includeServer(), new ModItemModelProvider(packOutput, existingFileHelper)); ModBlockTagProvider tagProvider = generator.addProvider(event.includeServer(), new ModBlockTagProvider(packOutput, lookupProvider, existingFileHelper)); diff --git a/src/main/java/com/atsuishio/superbwarfare/datagen/ModRecipeProvider.java b/src/main/java/com/atsuishio/superbwarfare/datagen/ModRecipeProvider.java new file mode 100644 index 000000000..2deed6a56 --- /dev/null +++ b/src/main/java/com/atsuishio/superbwarfare/datagen/ModRecipeProvider.java @@ -0,0 +1,22 @@ +package com.atsuishio.superbwarfare.datagen; + +import com.atsuishio.superbwarfare.init.ModRecipes; +import net.minecraft.data.PackOutput; +import net.minecraft.data.recipes.FinishedRecipe; +import net.minecraft.data.recipes.RecipeProvider; +import net.minecraft.data.recipes.SpecialRecipeBuilder; +import net.minecraftforge.common.crafting.conditions.IConditionBuilder; + +import java.util.function.Consumer; + +public class ModRecipeProvider extends RecipeProvider implements IConditionBuilder { + + public ModRecipeProvider(PackOutput pOutput) { + super(pOutput); + } + + @Override + protected void buildRecipes(Consumer pWriter) { + SpecialRecipeBuilder.special(ModRecipes.POTION_MORTAR_SHELL_SERIALIZER.get()).save(pWriter, "potion_mortar_shell"); + } +} diff --git a/src/main/java/com/atsuishio/superbwarfare/init/ModRecipes.java b/src/main/java/com/atsuishio/superbwarfare/init/ModRecipes.java new file mode 100644 index 000000000..53db9d365 --- /dev/null +++ b/src/main/java/com/atsuishio/superbwarfare/init/ModRecipes.java @@ -0,0 +1,17 @@ +package com.atsuishio.superbwarfare.init; + +import com.atsuishio.superbwarfare.ModUtils; +import com.atsuishio.superbwarfare.recipe.PotionMortarShellRecipe; +import net.minecraft.world.item.crafting.RecipeSerializer; +import net.minecraft.world.item.crafting.SimpleCraftingRecipeSerializer; +import net.minecraftforge.registries.DeferredRegister; +import net.minecraftforge.registries.ForgeRegistries; +import net.minecraftforge.registries.RegistryObject; + +public class ModRecipes { + + public static final DeferredRegister> RECIPE_SERIALIZERS = DeferredRegister.create(ForgeRegistries.RECIPE_SERIALIZERS, ModUtils.MODID); + + public static final RegistryObject> POTION_MORTAR_SHELL_SERIALIZER = + RECIPE_SERIALIZERS.register("potion_mortar_shell", () -> new SimpleCraftingRecipeSerializer<>(PotionMortarShellRecipe::new)); +} diff --git a/src/main/java/com/atsuishio/superbwarfare/recipe/PotionMortarShellRecipe.java b/src/main/java/com/atsuishio/superbwarfare/recipe/PotionMortarShellRecipe.java new file mode 100644 index 000000000..dd1650b2f --- /dev/null +++ b/src/main/java/com/atsuishio/superbwarfare/recipe/PotionMortarShellRecipe.java @@ -0,0 +1,72 @@ +package com.atsuishio.superbwarfare.recipe; + +import com.atsuishio.superbwarfare.init.ModItems; +import com.atsuishio.superbwarfare.init.ModRecipes; +import net.minecraft.core.RegistryAccess; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.inventory.CraftingContainer; +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.CustomRecipe; +import net.minecraft.world.item.crafting.RecipeSerializer; +import net.minecraft.world.level.Level; + +public class PotionMortarShellRecipe extends CustomRecipe { + + public PotionMortarShellRecipe(ResourceLocation pId, CraftingBookCategory pCategory) { + super(pId, pCategory); + } + + @Override + public boolean matches(CraftingContainer pContainer, Level pLevel) { + if (pContainer.getWidth() == 3 && pContainer.getHeight() == 3) { + for (int i = 0; i < pContainer.getWidth(); ++i) { + for (int j = 0; j < pContainer.getHeight(); ++j) { + int index = i + j * pContainer.getWidth(); + + ItemStack itemstack = pContainer.getItem(index); + + if (index % 2 == 0) { + if (i == 1 && j == 1) { + if (!itemstack.is(Items.LINGERING_POTION)) { + return false; + } + } else if (!itemstack.isEmpty()) { + return false; + } + } else if (!itemstack.is(ModItems.MORTAR_SHELL.get())) { + return false; + } + } + } + return true; + } else { + return false; + } + } + + @Override + public ItemStack assemble(CraftingContainer pContainer, RegistryAccess pRegistryAccess) { + ItemStack itemstack = pContainer.getItem(1 + pContainer.getWidth()); + if (!itemstack.is(Items.LINGERING_POTION)) { + return ItemStack.EMPTY; + } else { + ItemStack res = new ItemStack(ModItems.POTION_MORTAR_SHELL.get(), 4); + PotionUtils.setPotion(res, PotionUtils.getPotion(itemstack)); + PotionUtils.setCustomEffects(res, PotionUtils.getCustomEffects(itemstack)); + return res; + } + } + + @Override + public boolean canCraftInDimensions(int pWidth, int pHeight) { + return pWidth >= 2 && pHeight >= 2; + } + + @Override + public RecipeSerializer getSerializer() { + return ModRecipes.POTION_MORTAR_SHELL_SERIALIZER.get(); + } +}