From db81bb22a627e510db9b734180d04b45463f2e07 Mon Sep 17 00:00:00 2001 From: 90 Date: Wed, 4 Oct 2023 21:41:56 +0300 Subject: [PATCH] Add modLoaded conditions to AppMek integration recipes --- .../datagen/ForgeRecipeProvider.java | 137 ++++++++++-------- 1 file changed, 79 insertions(+), 58 deletions(-) diff --git a/forge/src/data/java/gripe/_90/megacells/datagen/ForgeRecipeProvider.java b/forge/src/data/java/gripe/_90/megacells/datagen/ForgeRecipeProvider.java index c5dff828..b2d60a30 100644 --- a/forge/src/data/java/gripe/_90/megacells/datagen/ForgeRecipeProvider.java +++ b/forge/src/data/java/gripe/_90/megacells/datagen/ForgeRecipeProvider.java @@ -6,6 +6,7 @@ import net.minecraft.data.PackOutput; import net.minecraft.data.recipes.FinishedRecipe; +import net.minecraft.data.recipes.RecipeBuilder; import net.minecraft.data.recipes.RecipeCategory; import net.minecraft.data.recipes.RecipeProvider; import net.minecraft.data.recipes.ShapedRecipeBuilder; @@ -14,6 +15,8 @@ import net.minecraft.tags.ItemTags; import net.minecraft.tags.TagKey; import net.minecraft.world.item.Item; +import net.minecraftforge.common.crafting.ConditionalRecipe; +import net.minecraftforge.common.crafting.conditions.ModLoadedCondition; import appeng.core.definitions.AEBlocks; import appeng.core.definitions.AEItems; @@ -38,15 +41,17 @@ public ForgeRecipeProvider(PackOutput output) { @Override protected void buildRecipes(@NotNull Consumer consumer) { if (MEGACells.PLATFORM.isAddonLoaded(Addons.APPMEK)) { - ShapedRecipeBuilder.shaped(RecipeCategory.MISC, AppMekItems.MEGA_CHEMICAL_CELL_HOUSING) - .pattern("aba") - .pattern("b b") - .pattern("ddd") - .define('a', AEBlocks.QUARTZ_VIBRANT_GLASS) - .define('b', AEItems.SKY_DUST) - .define('d', OSMIUM) - .unlockedBy("has_dusts/sky_stone", has(AEItems.SKY_DUST)) - .save(consumer, MEGACells.makeId("cells/has_mega_chemical_cell_housing")); + appmekRecipe( + consumer, + MEGACells.makeId("cells/mega_chemical_cell_housing"), + ShapedRecipeBuilder.shaped(RecipeCategory.MISC, AppMekItems.MEGA_CHEMICAL_CELL_HOUSING) + .pattern("aba") + .pattern("b b") + .pattern("ddd") + .define('a', AEBlocks.QUARTZ_VIBRANT_GLASS) + .define('b', AEItems.SKY_DUST) + .define('d', OSMIUM) + .unlockedBy("has_dusts/sky_stone", has(AEItems.SKY_DUST))); chemCell(consumer, AppMekItems.CHEMICAL_CELL_1M, MEGAItems.CELL_COMPONENT_1M); chemCell(consumer, AppMekItems.CHEMICAL_CELL_4M, MEGAItems.CELL_COMPONENT_4M); @@ -60,61 +65,77 @@ protected void buildRecipes(@NotNull Consumer consumer) { chemPortable(consumer, AppMekItems.PORTABLE_CHEMICAL_CELL_64M, MEGAItems.CELL_COMPONENT_64M); chemPortable(consumer, AppMekItems.PORTABLE_CHEMICAL_CELL_256M, MEGAItems.CELL_COMPONENT_256M); - ShapedRecipeBuilder.shaped(RecipeCategory.MISC, AppMekItems.RADIOACTIVE_CELL_COMPONENT) - .pattern("aba") - .pattern("cdc") - .pattern("aea") - .define('a', AEItems.SKY_DUST) - .define('b', MEGAItems.ACCUMULATION_PROCESSOR) - .define('c', MekanismBlocks.RADIOACTIVE_WASTE_BARREL) - .define('d', AEBlocks.QUARTZ_VIBRANT_GLASS) - .define('e', AEItems.CELL_COMPONENT_256K) - .unlockedBy("has_cell_component_256k", has(AEItems.CELL_COMPONENT_256K)) - .unlockedBy("has_waste_barrel", has(MekanismBlocks.RADIOACTIVE_WASTE_BARREL)) - .save(consumer, MEGACells.makeId("crafting/radioactive_cell_component")); - ShapedRecipeBuilder.shaped(RecipeCategory.MISC, AppMekItems.RADIOACTIVE_CHEMICAL_CELL) - .pattern("aba") - .pattern("bcb") - .pattern("ded") - .define('a', GeneratorsBlocks.REACTOR_GLASS) - .define('b', AEItems.SKY_DUST) - .define('c', AppMekItems.RADIOACTIVE_CELL_COMPONENT) - .define('d', MekanismItems.HDPE_SHEET) - .define('e', MekanismItems.POLONIUM_PELLET) - .unlockedBy("has_radioactive_cell_component", has(AppMekItems.RADIOACTIVE_CELL_COMPONENT)) - .save(consumer, MEGACells.makeId("cells/standard/radioactive_chemical_cell")); + appmekRecipe( + consumer, + MEGACells.makeId("crafting/radioactive_cell_component"), + ShapedRecipeBuilder.shaped(RecipeCategory.MISC, AppMekItems.RADIOACTIVE_CELL_COMPONENT) + .pattern("aba") + .pattern("cdc") + .pattern("aea") + .define('a', AEItems.SKY_DUST) + .define('b', MEGAItems.ACCUMULATION_PROCESSOR) + .define('c', MekanismBlocks.RADIOACTIVE_WASTE_BARREL) + .define('d', AEBlocks.QUARTZ_VIBRANT_GLASS) + .define('e', AEItems.CELL_COMPONENT_256K) + .unlockedBy("has_cell_component_256k", has(AEItems.CELL_COMPONENT_256K)) + .unlockedBy("has_waste_barrel", has(MekanismBlocks.RADIOACTIVE_WASTE_BARREL))); + appmekRecipe( + consumer, + MEGACells.makeId("cells/standard/radioactive_chemical_cell"), + ShapedRecipeBuilder.shaped(RecipeCategory.MISC, AppMekItems.RADIOACTIVE_CHEMICAL_CELL) + .pattern("aba") + .pattern("bcb") + .pattern("ded") + .define('a', GeneratorsBlocks.REACTOR_GLASS) + .define('b', AEItems.SKY_DUST) + .define('c', AppMekItems.RADIOACTIVE_CELL_COMPONENT) + .define('d', MekanismItems.HDPE_SHEET) + .define('e', MekanismItems.POLONIUM_PELLET) + .unlockedBy("has_radioactive_cell_component", has(AppMekItems.RADIOACTIVE_CELL_COMPONENT))); } } private void chemCell(Consumer consumer, ItemDefinition cell, ItemDefinition component) { - ShapedRecipeBuilder.shaped(RecipeCategory.MISC, cell) - .pattern("aba") - .pattern("bcb") - .pattern("ddd") - .define('a', AEBlocks.QUARTZ_VIBRANT_GLASS) - .define('b', AEItems.SKY_DUST) - .define('c', component) - .define('d', OSMIUM) - .unlockedBy("has_" + component.id().getPath(), has(component)) - .save(consumer, MEGACells.makeId("cells/standard/" + cell.id().getPath())); - - ShapelessRecipeBuilder.shapeless(RecipeCategory.MISC, cell) - .requires(AppMekItems.MEGA_CHEMICAL_CELL_HOUSING) - .requires(component) - .unlockedBy("has_" + component.id().getPath(), has(component)) - .unlockedBy("has_mega_chemical_cell_housing", has(AppMekItems.MEGA_CHEMICAL_CELL_HOUSING)) - .save(consumer, MEGACells.makeId("cells/standard/" + cell.id().getPath() + "_with_housing")); + appmekRecipe( + consumer, + MEGACells.makeId("cells/standard/" + cell.id().getPath()), + ShapedRecipeBuilder.shaped(RecipeCategory.MISC, cell) + .pattern("aba") + .pattern("bcb") + .pattern("ddd") + .define('a', AEBlocks.QUARTZ_VIBRANT_GLASS) + .define('b', AEItems.SKY_DUST) + .define('c', component) + .define('d', OSMIUM) + .unlockedBy("has_" + component.id().getPath(), has(component))); + appmekRecipe( + consumer, + MEGACells.makeId("cells/standard/" + cell.id().getPath() + "_with_housing"), + ShapelessRecipeBuilder.shapeless(RecipeCategory.MISC, cell) + .requires(AppMekItems.MEGA_CHEMICAL_CELL_HOUSING) + .requires(component) + .unlockedBy("has_" + component.id().getPath(), has(component)) + .unlockedBy("has_mega_chemical_cell_housing", has(AppMekItems.MEGA_CHEMICAL_CELL_HOUSING))); } private void chemPortable(Consumer consumer, ItemDefinition cell, ItemDefinition component) { - ShapelessRecipeBuilder.shapeless(RecipeCategory.MISC, cell) - .requires(AEBlocks.CHEST) - .requires(component) - .requires(AEBlocks.DENSE_ENERGY_CELL) - .requires(AppMekItems.MEGA_CHEMICAL_CELL_HOUSING) - .unlockedBy("has_mega_chemical_cell_housing", has(AppMekItems.MEGA_CHEMICAL_CELL_HOUSING)) - .unlockedBy("has_" + component.id().getPath(), has(component)) - .unlockedBy("has_dense_energy_cell", has(AEBlocks.DENSE_ENERGY_CELL)) - .save(consumer, MEGACells.makeId("cells/portable/" + cell.id().getPath())); + appmekRecipe( + consumer, + MEGACells.makeId("cells/portable/" + cell.id().getPath()), + ShapelessRecipeBuilder.shapeless(RecipeCategory.MISC, cell) + .requires(AEBlocks.CHEST) + .requires(component) + .requires(AEBlocks.DENSE_ENERGY_CELL) + .requires(AppMekItems.MEGA_CHEMICAL_CELL_HOUSING) + .unlockedBy("has_mega_chemical_cell_housing", has(AppMekItems.MEGA_CHEMICAL_CELL_HOUSING)) + .unlockedBy("has_" + component.id().getPath(), has(component)) + .unlockedBy("has_dense_energy_cell", has(AEBlocks.DENSE_ENERGY_CELL))); + } + + private void appmekRecipe(Consumer consumer, ResourceLocation id, RecipeBuilder builder) { + ConditionalRecipe.builder() + .addCondition(new ModLoadedCondition(Addons.APPMEK.getModId())) + .addRecipe(builder::save) + .build(consumer, id); } }