From 8e57c46bbadbe132aeaa736b344af8e57651ddcc Mon Sep 17 00:00:00 2001 From: ramidzkh Date: Tue, 10 Dec 2024 10:41:04 +1100 Subject: [PATCH] Use AE2 capacity replace and disassembly recipes (#78) Closes #76 Closes #77 --- build.gradle | 2 +- gradle.properties | 16 ++-- src/main/java/me/ramidzkh/mekae2/AMItems.java | 11 ++- .../ramidzkh/mekae2/data/RecipeProvider.java | 74 +++++++++++++++++++ .../mekae2/item/ChemicalStorageCell.java | 6 +- 5 files changed, 90 insertions(+), 19 deletions(-) diff --git a/build.gradle b/build.gradle index 6a31728..7f994dc 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id("net.neoforged.moddev") version "1.0.17" + id("net.neoforged.moddev") version "1.0.23" id("com.matthewprenger.cursegradle") version "1.4.0" id("com.diffplug.spotless") version "6.25.0" id("com.modrinth.minotaur") version "2.8.7" diff --git a/gradle.properties b/gradle.properties index 7d05a80..64439b3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,11 +1,11 @@ minecraft_version=1.21.1 -neoforge_version=21.1.22 -ae2_version=19.0.22-beta -mekanism_version=10.7.0.55 -emi_version=1.1.12+1.21 -jade_id=5427817 -jei_version=19.9.1.124 -jei_ae2_integration_id=5663887 +neoforge_version=21.1.84 +ae2_version=19.0.24 +mekanism_version=10.7.7.64 +emi_version=1.1.18+1.21.1 +jade_id=5884231 +jei_version=19.21.0.247 +jei_ae2_integration_id=5748513 # Dev runtime options ## Set to "jei" or "emi" to pick which tooltip mod gets picked at runtime @@ -14,7 +14,7 @@ runtime_itemlist_mod=emi loader_version_range=[1,) neo_version_range=[21.0,) -ae2_version_range=[19.0.20-beta,20.0.0) +ae2_version_range=[19.0.24,20.0.0) mekanism_version_range=[10.7.0,11-) org.gradle.caching=true diff --git a/src/main/java/me/ramidzkh/mekae2/AMItems.java b/src/main/java/me/ramidzkh/mekae2/AMItems.java index 92ae92a..a23a3ce 100644 --- a/src/main/java/me/ramidzkh/mekae2/AMItems.java +++ b/src/main/java/me/ramidzkh/mekae2/AMItems.java @@ -67,16 +67,15 @@ private static Item.Properties properties() { AMItems::basic); public static final DeferredItem CHEMICAL_CELL_1K = ITEMS.register("chemical_storage_cell_1k", - () -> new ChemicalStorageCell(properties().stacksTo(1), StorageTier.SIZE_1K, CHEMICAL_CELL_HOUSING.get())); + () -> new ChemicalStorageCell(properties().stacksTo(1), StorageTier.SIZE_1K)); public static final DeferredItem CHEMICAL_CELL_4K = ITEMS.register("chemical_storage_cell_4k", - () -> new ChemicalStorageCell(properties().stacksTo(1), StorageTier.SIZE_4K, CHEMICAL_CELL_HOUSING.get())); + () -> new ChemicalStorageCell(properties().stacksTo(1), StorageTier.SIZE_4K)); public static final DeferredItem CHEMICAL_CELL_16K = ITEMS.register("chemical_storage_cell_16k", - () -> new ChemicalStorageCell(properties().stacksTo(1), StorageTier.SIZE_16K, CHEMICAL_CELL_HOUSING.get())); + () -> new ChemicalStorageCell(properties().stacksTo(1), StorageTier.SIZE_16K)); public static final DeferredItem CHEMICAL_CELL_64K = ITEMS.register("chemical_storage_cell_64k", - () -> new ChemicalStorageCell(properties().stacksTo(1), StorageTier.SIZE_64K, CHEMICAL_CELL_HOUSING.get())); + () -> new ChemicalStorageCell(properties().stacksTo(1), StorageTier.SIZE_64K)); public static final DeferredItem CHEMICAL_CELL_256K = ITEMS.register("chemical_storage_cell_256k", - () -> new ChemicalStorageCell(properties().stacksTo(1), StorageTier.SIZE_256K, - CHEMICAL_CELL_HOUSING.get())); + () -> new ChemicalStorageCell(properties().stacksTo(1), StorageTier.SIZE_256K)); public static final DeferredItem PORTABLE_CHEMICAL_CELL_1K = ITEMS.register( "portable_chemical_cell_1k", diff --git a/src/main/java/me/ramidzkh/mekae2/data/RecipeProvider.java b/src/main/java/me/ramidzkh/mekae2/data/RecipeProvider.java index 2dbec91..11866b3 100644 --- a/src/main/java/me/ramidzkh/mekae2/data/RecipeProvider.java +++ b/src/main/java/me/ramidzkh/mekae2/data/RecipeProvider.java @@ -1,5 +1,7 @@ package me.ramidzkh.mekae2.data; +import java.util.ArrayList; +import java.util.List; import java.util.Locale; import java.util.concurrent.CompletableFuture; @@ -12,13 +14,19 @@ import net.minecraft.data.recipes.ShapelessRecipeBuilder; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.ItemTags; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.ItemLike; import net.neoforged.neoforge.common.Tags; +import net.neoforged.neoforge.registries.DeferredItem; import me.ramidzkh.mekae2.AMItems; import me.ramidzkh.mekae2.AppliedMekanistics; import appeng.core.definitions.AEBlocks; import appeng.core.definitions.AEItems; +import appeng.recipes.game.StorageCellDisassemblyRecipe; +import appeng.recipes.game.StorageCellUpgradeRecipe; public class RecipeProvider extends net.minecraft.data.recipes.RecipeProvider { @@ -66,5 +74,71 @@ protected void buildRecipes(RecipeOutput output) { .unlockedBy("has_energy_cell", has(AEBlocks.ENERGY_CELL)) .save(output); } + + // Copied from ae2 UpgradeRecipes.java + storageCellUpgradeRecipes( + output, + List.of( + new CellUpgradeTier("1k", AMItems.CHEMICAL_CELL_1K, AEItems.CELL_COMPONENT_1K), + new CellUpgradeTier("4k", AMItems.CHEMICAL_CELL_4K, AEItems.CELL_COMPONENT_4K), + new CellUpgradeTier("16k", AMItems.CHEMICAL_CELL_16K, AEItems.CELL_COMPONENT_16K), + new CellUpgradeTier("64k", AMItems.CHEMICAL_CELL_64K, AEItems.CELL_COMPONENT_64K), + new CellUpgradeTier("256k", AMItems.CHEMICAL_CELL_256K, AEItems.CELL_COMPONENT_256K)), + List.of(AMItems.CHEMICAL_CELL_HOUSING)); + storageCellUpgradeRecipes( + output, + List.of( + new CellUpgradeTier("1k", AMItems.PORTABLE_CHEMICAL_CELL_1K, AEItems.CELL_COMPONENT_1K), + new CellUpgradeTier("4k", AMItems.PORTABLE_CHEMICAL_CELL_4K, AEItems.CELL_COMPONENT_4K), + new CellUpgradeTier("16k", AMItems.PORTABLE_CHEMICAL_CELL_16K, AEItems.CELL_COMPONENT_16K), + new CellUpgradeTier("64k", AMItems.PORTABLE_CHEMICAL_CELL_64K, AEItems.CELL_COMPONENT_64K), + new CellUpgradeTier("256k", AMItems.PORTABLE_CHEMICAL_CELL_256K, AEItems.CELL_COMPONENT_256K)), + List.of(AEBlocks.ME_CHEST, AEBlocks.ENERGY_CELL, AMItems.CHEMICAL_CELL_HOUSING)); + } + + private void storageCellUpgradeRecipes(RecipeOutput output, List tiers, + List additionalDisassemblyItems) { + for (int i = 0; i < tiers.size(); i++) { + var fromTier = tiers.get(i); + var inputCell = fromTier.cell().asItem(); + var inputId = fromTier.cell().getId(); + var resultComponent = fromTier.component().asItem(); + + cellDisassembly(output, additionalDisassemblyItems, fromTier); + + // Allow a direct upgrade to any higher tier + for (int j = i + 1; j < tiers.size(); j++) { + var toTier = tiers.get(j); + var resultCell = toTier.cell().asItem(); + var inputComponent = toTier.component().asItem(); + + var recipeId = inputId.withPath(path -> "upgrade/" + path + "_to_" + toTier.suffix); + + output.accept( + recipeId, + new StorageCellUpgradeRecipe( + inputCell, inputComponent, + resultCell, resultComponent), + null); + } + } + } + + private void cellDisassembly(RecipeOutput consumer, List additionalReturn, CellUpgradeTier tier) { + List results = new ArrayList<>(); + for (var itemLike : additionalReturn) { + results.add(itemLike.asItem().getDefaultInstance()); + } + results.add(tier.component.asItem().getDefaultInstance()); + + consumer.accept( + tier.cell.getId().withPrefix("cell_upgrade/"), + new StorageCellDisassemblyRecipe( + tier.cell.asItem(), + results), + null); + } + + record CellUpgradeTier(String suffix, DeferredItem cell, ItemLike component) { } } diff --git a/src/main/java/me/ramidzkh/mekae2/item/ChemicalStorageCell.java b/src/main/java/me/ramidzkh/mekae2/item/ChemicalStorageCell.java index 40f4e2d..3b66c69 100644 --- a/src/main/java/me/ramidzkh/mekae2/item/ChemicalStorageCell.java +++ b/src/main/java/me/ramidzkh/mekae2/item/ChemicalStorageCell.java @@ -1,7 +1,6 @@ package me.ramidzkh.mekae2.item; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.ItemLike; import me.ramidzkh.mekae2.ae2.MekanismKey; import me.ramidzkh.mekae2.ae2.MekanismKeyType; @@ -13,9 +12,8 @@ public class ChemicalStorageCell extends BasicStorageCell { - public ChemicalStorageCell(Properties properties, StorageTier tier, ItemLike housingItem) { - super(properties, tier.componentSupplier().get(), housingItem, tier.idleDrain(), tier.bytes() / 1024, - tier.bytes() / 128, 5, MekanismKeyType.TYPE); + public ChemicalStorageCell(Properties properties, StorageTier tier) { + super(properties, tier.idleDrain(), tier.bytes() / 1024, tier.bytes() / 128, 5, MekanismKeyType.TYPE); } @Override