diff --git a/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/FluidProperty.java b/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/FluidProperty.java index 29ac6184f8..3e2c91a538 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/FluidProperty.java +++ b/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/FluidProperty.java @@ -5,9 +5,11 @@ import com.gregtechceu.gtceu.api.fluids.store.FluidStorage; import com.gregtechceu.gtceu.api.fluids.store.FluidStorageImpl; import com.gregtechceu.gtceu.api.fluids.store.FluidStorageKey; +import com.gregtechceu.gtceu.api.fluids.store.FluidStorageKeys; import com.gregtechceu.gtceu.api.registry.registrate.GTRegistrate; import net.minecraft.world.level.material.Fluid; +import net.minecraftforge.fluids.FluidStack; import lombok.Getter; import lombok.NoArgsConstructor; @@ -25,6 +27,8 @@ public class FluidProperty implements IMaterialProperty, FluidStorage { @Getter @Setter private FluidStorageKey primaryKey = null; + @Setter + private @Nullable Fluid solidifyingFluid = null; public FluidProperty(@NotNull FluidStorageKey key, @NotNull FluidBuilder builder) { enqueueRegistration(key, builder); @@ -71,6 +75,28 @@ public void store(@NotNull FluidStorageKey key, @NotNull Supplier materials) { + this.oreByProducts.clear(); + this.oreByProducts.addAll(materials); + } + + /** + * Add ore byproducts to this property + * + * @param materials the materials to add as byproducts + */ + public void addOreByProducts(@NotNull Material @NotNull... materials) { this.oreByProducts.addAll(Arrays.asList(materials)); } diff --git a/src/main/java/com/gregtechceu/gtceu/api/data/tag/TagPrefix.java b/src/main/java/com/gregtechceu/gtceu/api/data/tag/TagPrefix.java index 9a2174fa51..29af444e94 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/data/tag/TagPrefix.java +++ b/src/main/java/com/gregtechceu/gtceu/api/data/tag/TagPrefix.java @@ -1,7 +1,6 @@ package com.gregtechceu.gtceu.api.data.tag; import com.gregtechceu.gtceu.GTCEu; -import com.gregtechceu.gtceu.api.GTCEuAPI; import com.gregtechceu.gtceu.api.GTValues; import com.gregtechceu.gtceu.api.addon.AddonFinder; import com.gregtechceu.gtceu.api.addon.IGTAddon; @@ -9,7 +8,6 @@ import com.gregtechceu.gtceu.api.data.chemical.material.Material; import com.gregtechceu.gtceu.api.data.chemical.material.info.MaterialFlags; import com.gregtechceu.gtceu.api.data.chemical.material.info.MaterialIconType; -import com.gregtechceu.gtceu.api.data.chemical.material.properties.IMaterialProperty; import com.gregtechceu.gtceu.api.data.chemical.material.properties.PropertyKey; import com.gregtechceu.gtceu.api.data.chemical.material.stack.MaterialStack; import com.gregtechceu.gtceu.api.item.tool.GTToolType; @@ -24,7 +22,6 @@ import net.minecraft.client.renderer.RenderType; import net.minecraft.core.registries.Registries; -import net.minecraft.data.recipes.FinishedRecipe; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; import net.minecraft.resources.ResourceLocation; @@ -1085,21 +1082,12 @@ public boolean doGenerateBlock(Material material) { hasItemTable() && this.itemTable.get() != null && getItemFromTable(material) != null; } - @FunctionalInterface - public interface MaterialRecipeHandler { - - void accept(TagPrefix prefix, Material material, T property, Consumer provider); - } - - public void executeHandler(Consumer provider, - PropertyKey propertyKey, - MaterialRecipeHandler handler) { - for (Material material : GTCEuAPI.materialManager.getRegisteredMaterials()) { - if (material.hasProperty(propertyKey) && !material.hasFlag(MaterialFlags.NO_UNIFICATION) && - !ChemicalHelper.get(this, material).isEmpty()) { - handler.accept(this, material, material.getProperty(propertyKey), provider); - } - } + /** + * @param material the material to check + * @return if the material should have recipes autogenerated + */ + public boolean shouldGenerateRecipes(@NotNull Material material) { + return !material.hasFlag(MaterialFlags.NO_UNIFICATION) && !ChemicalHelper.get(this, material).isEmpty(); } public String getUnlocalizedName() { diff --git a/src/main/java/com/gregtechceu/gtceu/common/data/GTRecipes.java b/src/main/java/com/gregtechceu/gtceu/common/data/GTRecipes.java index f914450666..7f55227bb8 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/data/GTRecipes.java +++ b/src/main/java/com/gregtechceu/gtceu/common/data/GTRecipes.java @@ -1,6 +1,9 @@ package com.gregtechceu.gtceu.common.data; +import com.gregtechceu.gtceu.api.GTCEuAPI; import com.gregtechceu.gtceu.api.addon.AddonFinder; +import com.gregtechceu.gtceu.api.data.chemical.material.Material; +import com.gregtechceu.gtceu.api.data.chemical.material.info.MaterialFlags; import com.gregtechceu.gtceu.data.recipe.MaterialInfoLoader; import com.gregtechceu.gtceu.data.recipe.configurable.RecipeAddition; import com.gregtechceu.gtceu.data.recipe.configurable.RecipeRemoval; @@ -42,18 +45,27 @@ public static void recipeAddition(Consumer originalConsumer) { // Decomposition info loading MaterialInfoLoader.init(); + ToolRecipeHandler.setup(); + // com.gregtechceu.gtceu.data.recipe.generated.* - DecompositionRecipeHandler.init(consumer); - MaterialRecipeHandler.init(consumer); - OreRecipeHandler.init(consumer); - PartsRecipeHandler.init(consumer); - PipeRecipeHandler.init(consumer); - PolarizingRecipeHandler.init(consumer); - RecyclingRecipeHandler.init(consumer); - ToolRecipeHandler.init(consumer); - WireCombiningHandler.init(consumer); - WireRecipeHandler.init(consumer); + for (Material material : GTCEuAPI.materialManager.getRegisteredMaterials()) { + if (material.hasFlag(MaterialFlags.NO_UNIFICATION)) { + continue; + } + DecompositionRecipeHandler.run(consumer, material); + MaterialRecipeHandler.run(consumer, material); + OreRecipeHandler.run(consumer, material); + PartsRecipeHandler.run(consumer, material); + PipeRecipeHandler.run(consumer, material); + PolarizingRecipeHandler.run(consumer, material); + RecyclingRecipeHandler.run(consumer, material); + ToolRecipeHandler.run(consumer, material); + WireCombiningHandler.run(consumer, material); + WireRecipeHandler.run(consumer, material); + } + + CustomToolRecipes.init(consumer); AirScrubberRecipes.init(consumer); ChemistryRecipes.init(consumer); MetaTileEntityMachineRecipeLoader.init(consumer); diff --git a/src/main/java/com/gregtechceu/gtceu/common/item/TurbineRotorBehaviour.java b/src/main/java/com/gregtechceu/gtceu/common/item/TurbineRotorBehaviour.java index 9f30cc4540..c346b07d51 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/item/TurbineRotorBehaviour.java +++ b/src/main/java/com/gregtechceu/gtceu/common/item/TurbineRotorBehaviour.java @@ -1,5 +1,7 @@ package com.gregtechceu.gtceu.common.item; +import com.gregtechceu.gtceu.api.GTCEuAPI; +import com.gregtechceu.gtceu.api.data.chemical.material.Material; import com.gregtechceu.gtceu.api.data.chemical.material.properties.PropertyKey; import com.gregtechceu.gtceu.api.item.IComponentItem; import com.gregtechceu.gtceu.api.item.component.IMaterialPartItem; @@ -29,14 +31,21 @@ public class TurbineRotorBehaviour implements IMaterialPartItem, ISubItemHandler @Override public void fillItemCategory(Item item, CreativeModeTab category, NonNullList items) { - turbineBlade.executeHandler(null, PropertyKey.INGOT, (tagPrefix, material, property, provider) -> { + for (Material material : GTCEuAPI.materialManager.getRegisteredMaterials()) { + if (!turbineBlade.shouldGenerateRecipes(material)) { + return; + } + if (!material.hasProperty(PropertyKey.INGOT)) { + return; + } + var rotorStack = new ItemStack(item); var behavior = TurbineRotorBehaviour.getBehaviour(rotorStack); if (behavior != null) { behavior.setPartMaterial(rotorStack, material); items.add(rotorStack); } - }); + } } public int getRotorPower(ItemStack stack) { diff --git a/src/main/java/com/gregtechceu/gtceu/data/recipe/generated/DecompositionRecipeHandler.java b/src/main/java/com/gregtechceu/gtceu/data/recipe/generated/DecompositionRecipeHandler.java index 1380013de7..ec716a3c5a 100644 --- a/src/main/java/com/gregtechceu/gtceu/data/recipe/generated/DecompositionRecipeHandler.java +++ b/src/main/java/com/gregtechceu/gtceu/data/recipe/generated/DecompositionRecipeHandler.java @@ -1,17 +1,17 @@ package com.gregtechceu.gtceu.data.recipe.generated; -import com.gregtechceu.gtceu.api.GTCEuAPI; import com.gregtechceu.gtceu.api.data.chemical.ChemicalHelper; import com.gregtechceu.gtceu.api.data.chemical.material.Material; import com.gregtechceu.gtceu.api.data.chemical.material.properties.PropertyKey; import com.gregtechceu.gtceu.api.data.chemical.material.stack.MaterialStack; -import com.gregtechceu.gtceu.api.data.tag.TagPrefix; import com.gregtechceu.gtceu.data.recipe.builder.GTRecipeBuilder; import net.minecraft.data.recipes.FinishedRecipe; import net.minecraft.world.item.ItemStack; import net.minecraftforge.fluids.FluidStack; +import org.jetbrains.annotations.NotNull; + import java.util.ArrayList; import java.util.List; import java.util.function.Consumer; @@ -22,17 +22,15 @@ import static com.gregtechceu.gtceu.common.data.GTRecipeTypes.CENTRIFUGE_RECIPES; import static com.gregtechceu.gtceu.common.data.GTRecipeTypes.ELECTROLYZER_RECIPES; -public class DecompositionRecipeHandler { +public final class DecompositionRecipeHandler { - public static void init(Consumer provider) { - for (var material : GTCEuAPI.materialManager.getRegisteredMaterials()) { - var prefix = material.hasProperty(PropertyKey.DUST) ? dust : null; - processDecomposition(prefix, material, provider); - } + private DecompositionRecipeHandler() {} + + public static void run(@NotNull Consumer provider, @NotNull Material material) { + processDecomposition(provider, material); } - private static void processDecomposition(TagPrefix decomposePrefix, Material material, - Consumer provider) { + private static void processDecomposition(@NotNull Consumer provider, @NotNull Material material) { if (material.getMaterialComponents().isEmpty() || (!material.hasFlag(DECOMPOSITION_BY_ELECTROLYZING) && !material.hasFlag(DECOMPOSITION_BY_CENTRIFUGING)) || @@ -56,7 +54,8 @@ private static void processDecomposition(TagPrefix decomposePrefix, Material mat } // only reduce items - if (decomposePrefix != null) { + boolean hasDust = material.hasProperty(PropertyKey.DUST); + if (hasDust) { // calculate lowest common denominator List materialAmounts = new ArrayList<>(); materialAmounts.add(totalInputAmount); @@ -110,8 +109,8 @@ private static void processDecomposition(TagPrefix decomposePrefix, Material mat builder.outputFluids(fluidOutputs.toArray(FluidStack[]::new)); // finish builder - if (decomposePrefix != null) { - builder.inputItems(decomposePrefix, material, totalInputAmount); + if (hasDust) { + builder.inputItems(dust, material, totalInputAmount); } else { builder.inputFluids(material.getFluid(1000)); } diff --git a/src/main/java/com/gregtechceu/gtceu/data/recipe/generated/MaterialRecipeHandler.java b/src/main/java/com/gregtechceu/gtceu/data/recipe/generated/MaterialRecipeHandler.java index 156c68fdc0..02e93a2934 100644 --- a/src/main/java/com/gregtechceu/gtceu/data/recipe/generated/MaterialRecipeHandler.java +++ b/src/main/java/com/gregtechceu/gtceu/data/recipe/generated/MaterialRecipeHandler.java @@ -1,12 +1,10 @@ package com.gregtechceu.gtceu.data.recipe.generated; -import com.gregtechceu.gtceu.api.GTCEuAPI; import com.gregtechceu.gtceu.api.data.chemical.ChemicalHelper; import com.gregtechceu.gtceu.api.data.chemical.material.MarkerMaterials; import com.gregtechceu.gtceu.api.data.chemical.material.Material; import com.gregtechceu.gtceu.api.data.chemical.material.properties.*; import com.gregtechceu.gtceu.api.data.chemical.material.properties.PropertyKey; -import com.gregtechceu.gtceu.api.data.chemical.material.registry.MaterialRegistry; import com.gregtechceu.gtceu.api.data.chemical.material.stack.UnificationEntry; import com.gregtechceu.gtceu.api.data.tag.TagPrefix; import com.gregtechceu.gtceu.api.fluids.store.FluidStorageKeys; @@ -23,9 +21,12 @@ import net.minecraft.util.Mth; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; +import net.minecraftforge.fluids.FluidStack; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.Arrays; -import java.util.List; import java.util.Locale; import java.util.function.Consumer; @@ -35,41 +36,46 @@ import static com.gregtechceu.gtceu.common.data.GTMaterials.*; import static com.gregtechceu.gtceu.common.data.GTRecipeTypes.*; -public class MaterialRecipeHandler { - - private static final List GEM_ORDER = ConfigHolder.INSTANCE.recipes.generateLowQualityGems ? - Arrays.asList( - gemChipped, gemFlawed, gem, gemFlawless, gemExquisite) : - Arrays.asList(gem, gemFlawless, gemExquisite); - - public static void init(Consumer provider) { - ingot.executeHandler(provider, PropertyKey.INGOT, MaterialRecipeHandler::processIngot); - nugget.executeHandler(provider, PropertyKey.DUST, MaterialRecipeHandler::processNugget); - - block.executeHandler(provider, PropertyKey.DUST, MaterialRecipeHandler::processBlock); - frameGt.executeHandler(provider, PropertyKey.DUST, MaterialRecipeHandler::processFrame); - - dust.executeHandler(provider, PropertyKey.DUST, MaterialRecipeHandler::processDust); - dustSmall.executeHandler(provider, PropertyKey.DUST, MaterialRecipeHandler::processSmallDust); - dustTiny.executeHandler(provider, PropertyKey.DUST, MaterialRecipeHandler::processTinyDust); - - for (TagPrefix orePrefix : GEM_ORDER) { - orePrefix.executeHandler(provider, PropertyKey.GEM, MaterialRecipeHandler::processGemConversion); +public final class MaterialRecipeHandler { + + private MaterialRecipeHandler() {} + + public static void run(@NotNull Consumer provider, @NotNull Material material) { + processIngot(provider, material); + processNugget(provider, material); + processBlock(provider, material); + processFrame(provider, material); + processDust(provider, material); + processSmallDust(provider, material); + processTinyDust(provider, material); + if (ConfigHolder.INSTANCE.recipes.generateLowQualityGems) { + processGemConversion(provider, gemChipped, null, material); + processGemConversion(provider, gemFlawed, gemChipped, material); + processGemConversion(provider, gem, gemFlawed, material); + } else { + processGemConversion(provider, gem, null, material); } + processGemConversion(provider, gemFlawless, gem, material); + processGemConversion(provider, gemExquisite, gemFlawless, material); - generateSurfaceRockRecipe(provider); + generateSurfaceRockRecipe(provider, material); } - public static void processDust(TagPrefix dustPrefix, Material mat, DustProperty property, - Consumer provider) { - String id = "%s_%s".formatted(FormattingUtil.toLowerCaseUnder(dustPrefix.name), - mat.getName().toLowerCase(Locale.ROOT)); - ItemStack dustStack = ChemicalHelper.get(dustPrefix, mat); - OreProperty oreProperty = mat.hasProperty(PropertyKey.ORE) ? mat.getProperty(PropertyKey.ORE) : null; - if (mat.hasProperty(PropertyKey.GEM)) { - ItemStack gemStack = ChemicalHelper.get(gem, mat); + private static void processDust(@NotNull Consumer provider, @NotNull Material material) { + if (!dust.shouldGenerateRecipes(material)) { + return; + } + if (!material.hasProperty(PropertyKey.DUST)) { + return; + } - if (mat.hasFlag(CRYSTALLIZABLE)) { + String id = "dust_%s".formatted(material.getName().toLowerCase(Locale.ROOT)); + ItemStack dustStack = ChemicalHelper.get(dust, material); + OreProperty oreProperty = material.hasProperty(PropertyKey.ORE) ? material.getProperty(PropertyKey.ORE) : null; + if (material.hasProperty(PropertyKey.GEM)) { + ItemStack gemStack = ChemicalHelper.get(gem, material); + + if (material.hasFlag(CRYSTALLIZABLE)) { AUTOCLAVE_RECIPES.recipeBuilder("autoclave_" + id + "_water") .inputItems(dustStack) .inputFluids(Water.getFluid(250)) @@ -85,31 +91,31 @@ public static void processDust(TagPrefix dustPrefix, Material mat, DustProperty .save(provider); } - if (!mat.hasFlag(EXPLOSIVE) && !mat.hasFlag(FLAMMABLE)) { + if (!material.hasFlag(EXPLOSIVE) && !material.hasFlag(FLAMMABLE)) { IMPLOSION_RECIPES.recipeBuilder("implode_" + id + "_powderbarrel") - .inputItems(GTUtil.copyAmount(4, dustStack)) - .outputItems(GTUtil.copyAmount(3, gemStack)) + .inputItems(GTUtil.copy(4, dustStack)) + .outputItems(GTUtil.copy(3, gemStack)) .chancedOutput(dust, GTMaterials.DarkAsh, 2500, 0) .explosivesType(new ItemStack(GTBlocks.POWDERBARREL, 8)) .save(provider); IMPLOSION_RECIPES.recipeBuilder("implode_" + id + "_tnt") - .inputItems(GTUtil.copyAmount(4, dustStack)) - .outputItems(GTUtil.copyAmount(3, gemStack)) + .inputItems(GTUtil.copy(4, dustStack)) + .outputItems(GTUtil.copy(3, gemStack)) .chancedOutput(dust, GTMaterials.DarkAsh, 2500, 0) .explosivesAmount(4) .save(provider); IMPLOSION_RECIPES.recipeBuilder("implode_" + id + "_dynamite") - .inputItems(GTUtil.copyAmount(4, dustStack)) - .outputItems(GTUtil.copyAmount(3, gemStack)) + .inputItems(GTUtil.copy(4, dustStack)) + .outputItems(GTUtil.copy(3, gemStack)) .chancedOutput(dust, GTMaterials.DarkAsh, 2500, 0) .explosivesType(GTItems.DYNAMITE.asStack(2)) .save(provider); IMPLOSION_RECIPES.recipeBuilder("implode_" + id + "_itnt") - .inputItems(GTUtil.copyAmount(4, dustStack)) - .outputItems(GTUtil.copyAmount(3, gemStack)) + .inputItems(GTUtil.copy(4, dustStack)) + .outputItems(GTUtil.copy(3, gemStack)) .chancedOutput(dust, GTMaterials.DarkAsh, 2500, 0) .explosivesType(new ItemStack(GTBlocks.INDUSTRIAL_TNT)) .save(provider); @@ -119,35 +125,35 @@ public static void processDust(TagPrefix dustPrefix, Material mat, DustProperty Material smeltingResult = oreProperty.getDirectSmeltResult(); if (smeltingResult != null) { VanillaRecipeHelper.addSmeltingRecipe(provider, id + "_ingot", - ChemicalHelper.getTag(dustPrefix, mat), ChemicalHelper.get(ingot, smeltingResult)); + ChemicalHelper.getTag(dust, material), ChemicalHelper.get(ingot, smeltingResult)); } } - } else if (mat.hasProperty(PropertyKey.INGOT)) { - if (!mat.hasAnyOfFlags(FLAMMABLE, NO_SMELTING)) { + } else if (material.hasProperty(PropertyKey.INGOT)) { + if (!material.hasAnyOfFlags(FLAMMABLE, NO_SMELTING)) { - boolean hasHotIngot = ingotHot.doGenerateItem(mat); - ItemStack ingotStack = ChemicalHelper.get(hasHotIngot ? ingotHot : ingot, mat); + boolean hasHotIngot = ingotHot.doGenerateItem(material); + ItemStack ingotStack = ChemicalHelper.get(hasHotIngot ? ingotHot : ingot, material); if (ingotStack.isEmpty() && oreProperty != null) { Material smeltingResult = oreProperty.getDirectSmeltResult(); if (smeltingResult != null) { ingotStack = ChemicalHelper.get(ingot, smeltingResult); } } - int blastTemp = mat.getBlastTemperature(); + int blastTemp = material.getBlastTemperature(); if (blastTemp <= 0) { // smelting magnetic dusts is handled elsewhere - if (!mat.hasFlag(IS_MAGNETIC)) { + if (!material.hasFlag(IS_MAGNETIC)) { // do not register inputs by tag prefix here. Let other mods register their own dust -> ingots VanillaRecipeHelper.addSmeltingRecipe(provider, "smelt_" + id + "_to_ingot", - ChemicalHelper.getTag(dustPrefix, mat), ingotStack); + ChemicalHelper.getTag(dust, material), ingotStack); } } else { - IngotProperty ingotProperty = mat.getProperty(PropertyKey.INGOT); - BlastProperty blastProperty = mat.getProperty(PropertyKey.BLAST); + IngotProperty ingotProperty = material.getProperty(PropertyKey.INGOT); + BlastProperty blastProperty = material.getProperty(PropertyKey.BLAST); - processEBFRecipe(mat, blastProperty, ingotStack, provider); + processEBFRecipe(material, blastProperty, ingotStack, provider); if (ingotProperty.getMagneticMaterial() != null) { processEBFRecipe(ingotProperty.getMagneticMaterial(), blastProperty, ingotStack, provider); @@ -155,10 +161,10 @@ public static void processDust(TagPrefix dustPrefix, Material mat, DustProperty } } } else { - if (mat.hasFlag(GENERATE_PLATE) && !mat.hasFlag(EXCLUDE_PLATE_COMPRESSOR_RECIPE)) { + if (material.hasFlag(GENERATE_PLATE) && !material.hasFlag(EXCLUDE_PLATE_COMPRESSOR_RECIPE)) { COMPRESSOR_RECIPES.recipeBuilder("compress_plate_" + id) .inputItems(dustStack) - .outputItems(plate, mat) + .outputItems(plate, material) .save(provider); } @@ -169,7 +175,7 @@ public static void processDust(TagPrefix dustPrefix, Material mat, DustProperty ItemStack ingotStack = ChemicalHelper.get(ingot, smeltingResult); if (!ingotStack.isEmpty()) { VanillaRecipeHelper.addSmeltingRecipe(provider, "smelt_" + id + "_to_ingot", - ChemicalHelper.getTag(dustPrefix, mat), ingotStack); + ChemicalHelper.getTag(dust, material), ingotStack); } } } @@ -237,22 +243,33 @@ private static void processEBFRecipe(Material material, BlastProperty property, .save(provider); } } + + AlloyBlastProperty alloyBlastProperty = material.getProperty(PropertyKey.ALLOY_BLAST); + if (alloyBlastProperty != null) { + alloyBlastProperty.getRecipeProducer().produce(material, property, provider); + } } - public static void processSmallDust(TagPrefix orePrefix, Material material, DustProperty property, - Consumer provider) { + private static void processSmallDust(@NotNull Consumer provider, @NotNull Material material) { + if (!dustSmall.shouldGenerateRecipes(material)) { + return; + } + if (!material.hasProperty(PropertyKey.DUST)) { + return; + } + // small dust retains magnetism - ItemStack smallDustStack = ChemicalHelper.get(orePrefix, material); + ItemStack smallDustStack = ChemicalHelper.get(dustSmall, material); ItemStack dustStack = ChemicalHelper.get(dust, material); VanillaRecipeHelper.addStrictShapedRecipe(provider, String.format("small_dust_disassembling_%s", material.getName()), - GTUtil.copyAmount(4, smallDustStack), " X ", " ", " ", 'X', new UnificationEntry(dust, material)); + GTUtil.copy(4, smallDustStack), " X ", " ", " ", 'X', new UnificationEntry(dust, material)); VanillaRecipeHelper.addShapedRecipe(provider, String.format("small_dust_assembling_%s", material.getName()), - dustStack, "XX", "XX", 'X', new UnificationEntry(orePrefix, material)); + dustStack, "XX", "XX", 'X', new UnificationEntry(dustSmall, material)); PACKER_RECIPES.recipeBuilder("package_" + material.getName() + "_small_dust") - .inputItems(orePrefix, material, 4) + .inputItems(dustSmall, material, 4) .circuitMeta(1) .outputItems(dustStack) .save(provider); @@ -260,24 +277,30 @@ public static void processSmallDust(TagPrefix orePrefix, Material material, Dust PACKER_RECIPES.recipeBuilder("unpackage_" + material.getName() + "_small_dust") .inputItems(dust, material) .circuitMeta(2) - .outputItems(GTUtil.copyAmount(4, smallDustStack)) + .outputItems(GTUtil.copy(4, smallDustStack)) .save(provider); } - public static void processTinyDust(TagPrefix orePrefix, Material material, DustProperty property, - Consumer provider) { + private static void processTinyDust(@NotNull Consumer provider, @NotNull Material material) { + if (!dustTiny.shouldGenerateRecipes(material)) { + return; + } + if (!material.hasProperty(PropertyKey.DUST)) { + return; + } + // tiny dust retains magnetism - ItemStack tinyDustStack = ChemicalHelper.get(orePrefix, material); + ItemStack tinyDustStack = ChemicalHelper.get(dustTiny, material); ItemStack dustStack = ChemicalHelper.get(dust, material); VanillaRecipeHelper.addStrictShapedRecipe(provider, String.format("tiny_dust_disassembling_%s", material.getName()), - GTUtil.copyAmount(9, tinyDustStack), "X ", " ", " ", 'X', new UnificationEntry(dust, material)); + GTUtil.copy(9, tinyDustStack), "X ", " ", " ", 'X', new UnificationEntry(dust, material)); VanillaRecipeHelper.addShapedRecipe(provider, String.format("tiny_dust_assembling_%s", material.getName()), - dustStack, "XXX", "XXX", "XXX", 'X', new UnificationEntry(orePrefix, material)); + dustStack, "XXX", "XXX", "XXX", 'X', new UnificationEntry(dustTiny, material)); PACKER_RECIPES.recipeBuilder("package_" + material.getName() + "_tiny_dust") - .inputItems(orePrefix, material, 9) + .inputItems(dustTiny, material, 9) .circuitMeta(1) .outputItems(dustStack) .save(provider); @@ -285,15 +308,21 @@ public static void processTinyDust(TagPrefix orePrefix, Material material, DustP PACKER_RECIPES.recipeBuilder("unpackage_" + material.getName() + "_tiny_dust") .inputItems(dust, material) .circuitMeta(1) - .outputItems(GTUtil.copyAmount(9, tinyDustStack)) + .outputItems(GTUtil.copy(9, tinyDustStack)) .save(provider); } - public static void processIngot(TagPrefix ingotPrefix, Material material, IngotProperty property, - Consumer provider) { + private static void processIngot(@NotNull Consumer provider, @NotNull Material material) { + if (!ingot.shouldGenerateRecipes(material)) { + return; + } + if (!material.hasProperty(PropertyKey.INGOT)) { + return; + } + if (material.hasFlag(MORTAR_GRINDABLE)) { VanillaRecipeHelper.addShapedRecipe(provider, String.format("mortar_grind_%s", material.getName()), - ChemicalHelper.get(dust, material), "X", "m", 'X', new UnificationEntry(ingotPrefix, material)); + ChemicalHelper.get(dust, material), "X", "m", 'X', new UnificationEntry(ingot, material)); } var magMaterial = material.hasFlag(IS_MAGNETIC) ? @@ -303,10 +332,10 @@ public static void processIngot(TagPrefix ingotPrefix, Material material, IngotP VanillaRecipeHelper.addShapedRecipe(provider, String.format("stick_%s", material.getName()), ChemicalHelper.get(rod, magMaterial), "f ", " X", - 'X', new UnificationEntry(ingotPrefix, material)); + 'X', new UnificationEntry(ingot, material)); if (!material.hasFlag(NO_WORKING)) { EXTRUDER_RECIPES.recipeBuilder("extrude_" + material.getName() + "_to_rod") - .inputItems(ingotPrefix, material) + .inputItems(ingot, material) .notConsumable(GTItems.SHAPE_EXTRUDER_ROD) .outputItems(rod, magMaterial, 2) .duration((int) material.getMass() * 2) @@ -316,12 +345,15 @@ public static void processIngot(TagPrefix ingotPrefix, Material material, IngotP } if (material.hasFluid()) { - FLUID_SOLIDFICATION_RECIPES.recipeBuilder("solidify_" + material.getName() + "_to_ingot") - .notConsumable(GTItems.SHAPE_MOLD_INGOT) - .inputFluids(material.getFluid(L)) - .outputItems(ingotPrefix, material) - .duration(20).EUt(VA[ULV]) - .save(provider); + FluidStack stack = material.getProperty(PropertyKey.FLUID).solidifiesFrom(L); + if (!stack.isEmpty()) { + FLUID_SOLIDFICATION_RECIPES.recipeBuilder("solidify_" + material.getName() + "_to_ingot") + .notConsumable(GTItems.SHAPE_MOLD_INGOT) + .inputFluids(stack) + .outputItems(ingot, material) + .duration(20).EUt(VA[ULV]) + .save(provider); + } } if (material.hasFlag(NO_SMASHING)) { @@ -359,33 +391,32 @@ public static void processIngot(TagPrefix ingotPrefix, Material material, IngotP } if (material.hasFlag(GENERATE_PLATE) && !material.hasFlag(NO_WORKING)) { - if (!material.hasFlag(NO_SMASHING)) { ItemStack plateStack = ChemicalHelper.get(plate, material.hasFlag(IS_MAGNETIC) ? material.getProperty(PropertyKey.INGOT).getMacerateInto() : material); if (!plateStack.isEmpty()) { BENDER_RECIPES.recipeBuilder("bend_" + material.getName() + "_to_plate") .circuitMeta(1) - .inputItems(ingotPrefix, material) + .inputItems(ingot, material) .outputItems(plateStack) .EUt(24).duration((int) (material.getMass())) .save(provider); FORGE_HAMMER_RECIPES.recipeBuilder("hammer_" + material.getName() + "_to_plate") - .inputItems(ingotPrefix, material, 3) - .outputItems(GTUtil.copyAmount(2, plateStack)) + .inputItems(ingot, material, 3) + .outputItems(GTUtil.copy(2, plateStack)) .EUt(16).duration((int) material.getMass()) .save(provider); VanillaRecipeHelper.addShapedRecipe(provider, String.format("plate_%s", material.getName()), - plateStack, "h", "I", "I", 'I', new UnificationEntry(ingotPrefix, material)); + plateStack, "h", "I", "I", 'I', new UnificationEntry(ingot, material)); } } int voltageMultiplier = getVoltageMultiplier(material); if (!ChemicalHelper.get(plate, material).isEmpty()) { EXTRUDER_RECIPES.recipeBuilder("extrude_" + material.getName() + "_to_plate") - .inputItems(ingotPrefix, material) + .inputItems(ingot, material) .notConsumable(GTItems.SHAPE_EXTRUDER_PLATE) .outputItems(plate, magMaterial) .duration((int) material.getMass()) @@ -405,53 +436,71 @@ public static void processIngot(TagPrefix ingotPrefix, Material material, IngotP } } - public static void processGemConversion(TagPrefix gemPrefix, Material material, GemProperty property, - Consumer provider) { - long materialAmount = gemPrefix.getMaterialAmount(material); + private static void processGemConversion(@NotNull Consumer provider, @NotNull TagPrefix prefix, + @Nullable TagPrefix lowerPrefix, @NotNull Material material) { + if (!prefix.shouldGenerateRecipes(material)) { + return; + } + if (!material.hasProperty(PropertyKey.GEM)) { + return; + } + + long materialAmount = prefix.getMaterialAmount(material); ItemStack crushedStack = ChemicalHelper.getDust(material, materialAmount); if (material.hasFlag(MORTAR_GRINDABLE)) { VanillaRecipeHelper.addShapedRecipe(provider, String.format("gem_to_dust_%s_%s", material.getName(), - FormattingUtil.toLowerCaseUnder(gemPrefix.name)), + FormattingUtil.toLowerCaseUnder(prefix.name)), crushedStack, - "X", "m", 'X', new UnificationEntry(gemPrefix, material)); - } - - TagPrefix prevPrefix = GTUtil.getItem(GEM_ORDER, GEM_ORDER.indexOf(gemPrefix) - 1, null); - ItemStack prevStack = prevPrefix == null ? ItemStack.EMPTY : ChemicalHelper.get(prevPrefix, material, 2); - if (!prevStack.isEmpty() && prevPrefix != null) { - VanillaRecipeHelper.addShapelessRecipe(provider, - String.format("gem_to_gem_%s_%s", FormattingUtil.toLowerCaseUnder(prevPrefix.name), - material.getName()), - prevStack, - 'h', new UnificationEntry(gemPrefix, material)); - - CUTTER_RECIPES - .recipeBuilder("cut_" + material.getName() + "_" + FormattingUtil.toLowerCaseUnder(gemPrefix.name) + - "_to_" + FormattingUtil.toLowerCaseUnder(prevPrefix.name)) - .inputItems(gemPrefix, material) - .outputItems(prevStack) - .duration(20) - .EUt(16) - .save(provider); + "X", "m", 'X', new UnificationEntry(prefix, material)); + } - LASER_ENGRAVER_RECIPES - .recipeBuilder( - "engrave_" + material.getName() + "_" + FormattingUtil.toLowerCaseUnder(gemPrefix.name) + - "_to_" + FormattingUtil.toLowerCaseUnder(prevPrefix.name)) - .inputItems(prevStack) - .notConsumable(lens, MarkerMaterials.Color.White) - .outputItems(gemPrefix, material) - .duration(300) - .EUt(240) - .save(provider); + if (lowerPrefix == null) { + return; } + + ItemStack prevStack = ChemicalHelper.get(lowerPrefix, material, 2); + if (prevStack.isEmpty()) { + return; + } + + VanillaRecipeHelper.addShapelessRecipe(provider, + String.format("gem_to_gem_%s_%s", FormattingUtil.toLowerCaseUnder(lowerPrefix.name), + material.getName()), + prevStack, + 'h', new UnificationEntry(prefix, material)); + + CUTTER_RECIPES + .recipeBuilder("cut_" + material.getName() + "_" + FormattingUtil.toLowerCaseUnder(prefix.name) + + "_to_" + FormattingUtil.toLowerCaseUnder(lowerPrefix.name)) + .inputItems(prefix, material) + .outputItems(prevStack) + .duration(20) + .EUt(16) + .save(provider); + + LASER_ENGRAVER_RECIPES + .recipeBuilder( + "engrave_" + material.getName() + "_" + FormattingUtil.toLowerCaseUnder(prefix.name) + + "_to_" + FormattingUtil.toLowerCaseUnder(lowerPrefix.name)) + .inputItems(prevStack) + .notConsumable(lens, MarkerMaterials.Color.White) + .outputItems(prefix, material) + .duration(300) + .EUt(240) + .save(provider); } - public static void processNugget(TagPrefix orePrefix, Material material, DustProperty property, - Consumer provider) { - ItemStack nuggetStack = ChemicalHelper.get(orePrefix, material); + private static void processNugget(@NotNull Consumer provider, @NotNull Material material) { + if (!nugget.shouldGenerateRecipes(material)) { + return; + } + if (!material.hasProperty(PropertyKey.DUST)) { + return; + } + + ItemStack nuggetStack = ChemicalHelper.get(nugget, material); if (material.hasProperty(PropertyKey.INGOT)) { ItemStack ingotStack = ChemicalHelper.get(ingot, material.hasFlag(IS_MAGNETIC) ? material.getProperty(PropertyKey.INGOT).getMacerateInto() : material); @@ -460,12 +509,12 @@ public static void processNugget(TagPrefix orePrefix, Material material, DustPro if (!ingot.isIgnored(material)) { VanillaRecipeHelper.addShapelessRecipe(provider, String.format("nugget_disassembling_%s", material.getName()), - GTUtil.copyAmount(9, nuggetStack), new UnificationEntry(ingot, material)); + GTUtil.copy(9, nuggetStack), new UnificationEntry(ingot, material)); } - if (!orePrefix.isIgnored(material)) { + if (!nugget.isIgnored(material)) { VanillaRecipeHelper.addShapedRecipe(provider, String.format("nugget_assembling_%s", material.getName()), - ingotStack, "XXX", "XXX", "XXX", 'X', new UnificationEntry(orePrefix, material)); + ingotStack, "XXX", "XXX", "XXX", 'X', new UnificationEntry(nugget, material)); } } @@ -483,13 +532,16 @@ public static void processNugget(TagPrefix orePrefix, Material material, DustPro .save(provider); if (material.hasFluid()) { - FLUID_SOLIDFICATION_RECIPES.recipeBuilder("solidify_" + material.getName() + "_to_nugget") - .notConsumable(GTItems.SHAPE_MOLD_NUGGET) - .inputFluids(material.getFluid(L)) - .outputItems(orePrefix, material, 9) - .duration((int) material.getMass()) - .EUt(VA[ULV]) - .save(provider); + FluidStack stack = material.getProperty(PropertyKey.FLUID).solidifiesFrom(L); + if (!stack.isEmpty()) { + FLUID_SOLIDFICATION_RECIPES.recipeBuilder("solidify_" + material.getName() + "_to_nugget") + .notConsumable(GTItems.SHAPE_MOLD_NUGGET) + .inputFluids(stack) + .outputItems(nugget, material, 9) + .duration((int) material.getMass()) + .EUt(VA[ULV]) + .save(provider); + } } } else if (material.hasProperty(PropertyKey.GEM)) { ItemStack gemStack = ChemicalHelper.get(gem, material); @@ -498,47 +550,62 @@ public static void processNugget(TagPrefix orePrefix, Material material, DustPro if (!gem.isIgnored(material)) { VanillaRecipeHelper.addShapelessRecipe(provider, String.format("nugget_disassembling_%s", material.getName()), - GTUtil.copyAmount(9, nuggetStack), new UnificationEntry(gem, material)); + GTUtil.copy(9, nuggetStack), new UnificationEntry(gem, material)); } - if (!orePrefix.isIgnored(material)) { + if (!nugget.isIgnored(material)) { VanillaRecipeHelper.addShapedRecipe(provider, String.format("nugget_assembling_%s", material.getName()), - gemStack, "XXX", "XXX", "XXX", 'X', new UnificationEntry(orePrefix, material)); + gemStack, "XXX", "XXX", "XXX", 'X', new UnificationEntry(nugget, material)); } } } } - public static void processFrame(TagPrefix framePrefix, Material material, DustProperty property, - Consumer provider) { + private static void processFrame(@NotNull Consumer provider, @NotNull Material material) { + if (!frameGt.shouldGenerateRecipes(material)) { + return; + } + if (!material.hasProperty(PropertyKey.DUST)) { + return; + } + if (material.hasFlag(GENERATE_FRAME)) { boolean isWoodenFrame = material.hasProperty(PropertyKey.WOOD); VanillaRecipeHelper.addShapedRecipe(provider, String.format("frame_%s", material.getName()), - ChemicalHelper.get(framePrefix, material, 2), + ChemicalHelper.get(frameGt, material, 2), "SSS", isWoodenFrame ? "SsS" : "SwS", "SSS", 'S', new UnificationEntry(rod, material)); ASSEMBLER_RECIPES.recipeBuilder("assemble_" + material.getName() + "_frame") .inputItems(rod, material, 4) .circuitMeta(4) - .outputItems(framePrefix, material) + .outputItems(frameGt, material) .EUt(VA[ULV]).duration(64) .save(provider); } } - public static void processBlock(TagPrefix blockPrefix, Material material, DustProperty property, - Consumer provider) { - ItemStack blockStack = ChemicalHelper.get(blockPrefix, material.hasFlag(IS_MAGNETIC) ? + private static void processBlock(@NotNull Consumer provider, @NotNull Material material) { + if (!block.shouldGenerateRecipes(material)) { + return; + } + if (!material.hasProperty(PropertyKey.DUST)) { + return; + } + + ItemStack blockStack = ChemicalHelper.get(block, material.hasFlag(IS_MAGNETIC) ? material.getProperty(PropertyKey.INGOT).getMacerateInto() : material); - long materialAmount = blockPrefix.getMaterialAmount(material); + long materialAmount = block.getMaterialAmount(material); if (material.hasFluid()) { - FLUID_SOLIDFICATION_RECIPES.recipeBuilder("solidify_" + material.getName() + "_block") - .notConsumable(GTItems.SHAPE_MOLD_BLOCK) - .inputFluids(material.getFluid((int) (materialAmount * L / M))) - .outputItems(blockStack) - .duration((int) material.getMass()).EUt(VA[ULV]) - .save(provider); + FluidStack stack = material.getProperty(PropertyKey.FLUID).solidifiesFrom((int) (materialAmount * L / M)); + if (!stack.isEmpty()) { + FLUID_SOLIDFICATION_RECIPES.recipeBuilder("solidify_" + material.getName() + "_block") + .notConsumable(GTItems.SHAPE_MOLD_BLOCK) + .inputFluids(stack) + .outputItems(blockStack) + .duration((int) material.getMass()).EUt(VA[ULV]) + .save(provider); + } } if (material.hasFlag(GENERATE_PLATE)) { @@ -546,8 +613,8 @@ public static void processBlock(TagPrefix blockPrefix, Material material, DustPr material.getProperty(PropertyKey.INGOT).getMacerateInto() : material); if (!plateStack.isEmpty()) { CUTTER_RECIPES.recipeBuilder("cut_" + material.getName() + "_block_to_plate") - .inputItems(blockPrefix, material) - .outputItems(GTUtil.copyAmount((int) (materialAmount / M), plateStack)) + .inputItems(block, material) + .outputItems(GTUtil.copy((int) (materialAmount / M), plateStack)) .duration((int) (material.getMass() * 8L)).EUt(VA[LV]) .save(provider); } @@ -580,8 +647,8 @@ public static void processBlock(TagPrefix blockPrefix, Material material, DustPr VanillaRecipeHelper.addShapelessRecipe(provider, String.format("block_decompress_%s", material.getName()), - GTUtil.copyAmount(size, ChemicalHelper.get(blockEntry.tagPrefix, blockEntry.material)), - new UnificationEntry(blockPrefix, material)); + GTUtil.copy(size, ChemicalHelper.get(blockEntry.tagPrefix, blockEntry.material)), + new UnificationEntry(block, material)); } if (material.hasProperty(PropertyKey.INGOT)) { @@ -624,17 +691,14 @@ public static void processBlock(TagPrefix blockPrefix, Material material, DustPr } } - private static void generateSurfaceRockRecipe(Consumer provider) { - for (MaterialRegistry registry : GTCEuAPI.materialManager.getRegistries()) { - for (Material material : registry.getAllMaterials()) { - if (material.hasProperty(PropertyKey.ORE)) { - VanillaRecipeHelper.addShapedRecipe(provider, "%s_surface_indicator".formatted(material.getName()), - GTMaterialBlocks.SURFACE_ROCK_BLOCKS.get(material).asStack(2), - "DDD", "DGD", "DDD", - 'D', ChemicalHelper.get(dustSmall, material), - 'G', Items.GRAVEL); - } - } + private static void generateSurfaceRockRecipe(@NotNull Consumer provider, + @NotNull Material material) { + if (material.hasProperty(PropertyKey.ORE)) { + VanillaRecipeHelper.addShapedRecipe(provider, "%s_surface_indicator".formatted(material.getName()), + GTMaterialBlocks.SURFACE_ROCK_BLOCKS.get(material).asStack(2), + "DDD", "DGD", "DDD", + 'D', ChemicalHelper.get(dustSmall, material), + 'G', Items.GRAVEL); } } diff --git a/src/main/java/com/gregtechceu/gtceu/data/recipe/generated/OreRecipeHandler.java b/src/main/java/com/gregtechceu/gtceu/data/recipe/generated/OreRecipeHandler.java index ab640bd160..7763846708 100644 --- a/src/main/java/com/gregtechceu/gtceu/data/recipe/generated/OreRecipeHandler.java +++ b/src/main/java/com/gregtechceu/gtceu/data/recipe/generated/OreRecipeHandler.java @@ -21,6 +21,7 @@ import net.minecraftforge.common.crafting.IntersectionIngredient; import com.mojang.datafixers.util.Pair; +import org.jetbrains.annotations.NotNull; import java.util.List; import java.util.function.Consumer; @@ -31,74 +32,60 @@ import static com.gregtechceu.gtceu.common.data.GTMaterials.*; import static com.gregtechceu.gtceu.common.data.GTRecipeTypes.*; -public class OreRecipeHandler { +public final class OreRecipeHandler { // Make sure to update OreByProduct jei page with any byproduct changes made here! - public static void init(Consumer provider) { + private OreRecipeHandler() {} + + public static void run(@NotNull Consumer provider, @NotNull Material material) { + OreProperty property = material.getProperty(PropertyKey.ORE); + if (property == null) { + return; + } + for (TagPrefix ore : ORES.keySet()) { if (ConfigHolder.INSTANCE.worldgen.allUniqueStoneTypes || ORES.get(ore).shouldDropAsItem()) { - ore.executeHandler(provider, PropertyKey.ORE, OreRecipeHandler::processOre); + processOre(provider, ore, property, material); } } - ore.executeHandler(provider, PropertyKey.ORE, OreRecipeHandler::processOreForgeHammer); - rawOre.executeHandler(provider, PropertyKey.ORE, OreRecipeHandler::processRawOre); - - crushed.executeHandler(provider, PropertyKey.ORE, OreRecipeHandler::processCrushedOre); - crushedPurified.executeHandler(provider, PropertyKey.ORE, OreRecipeHandler::processCrushedPurified); - crushedRefined.executeHandler(provider, PropertyKey.ORE, OreRecipeHandler::processCrushedCentrifuged); - dustImpure.executeHandler(provider, PropertyKey.ORE, OreRecipeHandler::processDirtyDust); - dustPure.executeHandler(provider, PropertyKey.ORE, OreRecipeHandler::processPureDust); + processRawOre(provider, property, material); + processCrushedOre(provider, property, material); + processCrushedPurified(provider, property, material); + processCrushedCentrifuged(provider, property, material); + processDirtyDust(provider, property, material); + processPureDust(provider, property, material); } - private static void processMetalSmelting(TagPrefix crushedPrefix, Material material, OreProperty property, - Consumer provider) { - Material smeltingResult = property.getDirectSmeltResult() != null ? property.getDirectSmeltResult() : material; - + private static void processMetalSmelting(@NotNull Consumer provider, @NotNull OreProperty property, + @NotNull TagPrefix prefix, @NotNull Material material) { + Material smeltingResult = property.getDirectSmeltResult() == null ? material : property.getDirectSmeltResult(); if (smeltingResult.hasProperty(PropertyKey.INGOT)) { ItemStack ingotStack = ChemicalHelper.get(ingot, smeltingResult); - if (!ingotStack.isEmpty() && doesMaterialUseNormalFurnace(smeltingResult) && - !crushedPrefix.isIgnored(material)) { + if (!ingotStack.isEmpty() && doesMaterialUseNormalFurnace(smeltingResult) && !prefix.isIgnored(material)) { VanillaRecipeHelper.addSmeltingRecipe(provider, - "smelt_" + crushedPrefix.name + "_" + material.getName() + "_to_ingot", - ChemicalHelper.getTag(crushedPrefix, material), ingotStack, 0.5f); + "smelt_" + prefix.name + "_" + material.getName() + "_to_ingot", + ChemicalHelper.getTag(prefix, material), ingotStack, 0.5f); } } } - public static void processOreForgeHammer(TagPrefix orePrefix, Material material, OreProperty property, - Consumer provider) { - ItemStack crushedStack = ChemicalHelper.get(crushed, material); - int amountOfCrushedOre = property.getOreMultiplier(); - int oreTypeMultiplier = TagPrefix.ORES.get(orePrefix).isDoubleDrops() ? 2 : 1; - crushedStack.setCount(crushedStack.getCount() * property.getOreMultiplier()); - - String prefixString = orePrefix == ore ? "" : orePrefix.name + "_"; - GTRecipeBuilder builder = FORGE_HAMMER_RECIPES - .recipeBuilder("hammer_" + prefixString + material.getName() + "_ore_to_raw_ore") - .inputItems(orePrefix, material) - .category(GTRecipeCategories.ORE_FORGING) - .duration(10).EUt(16); - if (material.hasProperty(PropertyKey.GEM) && !gem.isIgnored(material)) { - builder.outputItems(GTUtil.copyAmount(amountOfCrushedOre * oreTypeMultiplier, - ChemicalHelper.get(gem, material, crushedStack.getCount()))); - } else { - builder.outputItems(GTUtil.copyAmount(amountOfCrushedOre * oreTypeMultiplier, crushedStack)); + private static void processOre(@NotNull Consumer provider, @NotNull TagPrefix orePrefix, + @NotNull OreProperty property, @NotNull Material material) { + if (!orePrefix.shouldGenerateRecipes(material)) { + return; } - builder.save(provider); - } - public static void processOre(TagPrefix orePrefix, Material material, OreProperty property, - Consumer provider) { - Material byproductMaterial = GTUtil.selectItemInList(0, material, property.getOreByProducts(), Material.class); - ItemStack ingotStack; + Material byproductMaterial = property.getOreByProduct(0, material); ItemStack byproductStack = ChemicalHelper.get(gem, byproductMaterial); - if (byproductStack.isEmpty()) byproductStack = ChemicalHelper.get(dust, byproductMaterial); + if (byproductStack.isEmpty()) { + byproductStack = ChemicalHelper.get(dust, byproductMaterial); + } + Material smeltingMaterial = property.getDirectSmeltResult() == null ? material : property.getDirectSmeltResult(); - ItemStack crushedStack = ChemicalHelper.get(crushed, material); - int amountOfCrushedOre = property.getOreMultiplier(); + ItemStack ingotStack; if (smeltingMaterial.hasProperty(PropertyKey.INGOT)) { ingotStack = ChemicalHelper.get(ingot, smeltingMaterial); } else if (smeltingMaterial.hasProperty(PropertyKey.GEM)) { @@ -106,17 +93,34 @@ public static void processOre(TagPrefix orePrefix, Material material, OrePropert } else { ingotStack = ChemicalHelper.get(dust, smeltingMaterial); } + int oreTypeMultiplier = TagPrefix.ORES.get(orePrefix).isDoubleDrops() ? 2 : 1; ingotStack.setCount(ingotStack.getCount() * property.getOreMultiplier() * oreTypeMultiplier); + + ItemStack crushedStack = ChemicalHelper.get(crushed, material); crushedStack.setCount(crushedStack.getCount() * property.getOreMultiplier()); String prefixString = orePrefix == ore ? "" : orePrefix.name + "_"; if (!crushedStack.isEmpty()) { - GTRecipeBuilder builder = MACERATOR_RECIPES + GTRecipeBuilder builder = FORGE_HAMMER_RECIPES + .recipeBuilder("hammer_" + prefixString + material.getName() + "_ore_to_crushed_ore") + .inputItems(IntersectionIngredient.of(Ingredient.of(orePrefix.getItemTags(material)[0]), + Ingredient.of(orePrefix.getItemParentTags()[0]))) + .category(GTRecipeCategories.ORE_FORGING) + .duration(10).EUt(16); + if (material.hasProperty(PropertyKey.GEM) && !ChemicalHelper.get(gem, material).isEmpty()) { + builder.outputItems(GTUtil.copy(property.getOreMultiplier() * oreTypeMultiplier, + ChemicalHelper.get(gem, material, crushedStack.getCount()))); + } else { + builder.outputItems(GTUtil.copy(property.getOreMultiplier() * oreTypeMultiplier, crushedStack)); + } + builder.save(provider); + + builder = MACERATOR_RECIPES .recipeBuilder("macerate_" + prefixString + material.getName() + "_ore_to_crushed_ore") .inputItems(IntersectionIngredient.of(Ingredient.of(orePrefix.getItemTags(material)[0]), Ingredient.of(orePrefix.getItemParentTags()[0]))) - .outputItems(GTUtil.copyAmount(amountOfCrushedOre * 2 * oreTypeMultiplier, crushedStack)) + .outputItems(GTUtil.copy(property.getOreMultiplier() * 2 * oreTypeMultiplier, crushedStack)) .chancedOutput(byproductStack, 1400, 850) .EUt(2) .category(GTRecipeCategories.ORE_CRUSHING) @@ -148,75 +152,78 @@ public static void processOre(TagPrefix orePrefix, Material material, OrePropert } } - public static void processRawOre(TagPrefix orePrefix, Material material, OreProperty property, - Consumer provider) { - ItemStack crushedStack = ChemicalHelper.get(crushed, material, - material.getProperty(PropertyKey.ORE).getOreMultiplier()); - ItemStack ingotStack; + private static void processRawOre(@NotNull Consumer provider, @NotNull OreProperty property, + @NotNull Material material) { + if (!rawOre.shouldGenerateRecipes(material)) { + return; + } + + Material byproductMaterial = property.getOreByProduct(0, material); + ItemStack byproductStack = ChemicalHelper.get(gem, byproductMaterial); + if (byproductStack.isEmpty()) { + byproductStack = ChemicalHelper.get(dust, byproductMaterial); + } + Material smeltingMaterial = property.getDirectSmeltResult() == null ? material : property.getDirectSmeltResult(); + ItemStack ingotStack; if (smeltingMaterial.hasProperty(PropertyKey.INGOT)) { - ingotStack = ChemicalHelper.get(ingot, smeltingMaterial, - material.getProperty(PropertyKey.ORE).getOreMultiplier()); + ingotStack = ChemicalHelper.get(ingot, smeltingMaterial); } else if (smeltingMaterial.hasProperty(PropertyKey.GEM)) { - ingotStack = ChemicalHelper.get(gem, smeltingMaterial, - material.getProperty(PropertyKey.ORE).getOreMultiplier()); + ingotStack = ChemicalHelper.get(gem, smeltingMaterial); } else { - ingotStack = ChemicalHelper.get(dust, smeltingMaterial, - material.getProperty(PropertyKey.ORE).getOreMultiplier()); + ingotStack = ChemicalHelper.get(dust, smeltingMaterial); } + ingotStack.setCount(ingotStack.getCount() * property.getOreMultiplier()); + + ItemStack crushedStack = ChemicalHelper.get(crushed, material); + crushedStack.setCount(crushedStack.getCount() * property.getOreMultiplier()); + if (!crushedStack.isEmpty()) { GTRecipeBuilder builder = FORGE_HAMMER_RECIPES - .recipeBuilder("hammer_" + orePrefix.name + "_" + material.getName() + "_to_crushed_ore") - .inputItems(orePrefix, material) + .recipeBuilder("hammer_raw_" + material.getName() + "_ore_to_crushed_ore") + .inputItems(rawOre, material) .category(GTRecipeCategories.ORE_FORGING) .duration(10).EUt(16); - if (material.hasProperty(PropertyKey.GEM) && !gem.isIgnored(material)) { - builder.outputItems(ChemicalHelper.get(gem, material, crushedStack.getCount())); + if (material.hasProperty(PropertyKey.GEM) && !ChemicalHelper.get(gem, material).isEmpty()) { + builder.outputItems(GTUtil.copy(property.getOreMultiplier(), + ChemicalHelper.get(gem, material, crushedStack.getCount()))); } else { - builder.outputItems(crushedStack.copy()); + builder.outputItems(GTUtil.copy(property.getOreMultiplier(), crushedStack)); } builder.save(provider); - GTRecipeBuilder builder2 = MACERATOR_RECIPES - .recipeBuilder("macerate_" + orePrefix.name + "_" + material.getName() + "_ore_to_crushed_ore") - .inputItems(orePrefix, material) - .outputItems(GTUtil.copyAmount(crushedStack.getCount() * 2, crushedStack)) - .category(GTRecipeCategories.ORE_CRUSHING) + builder = MACERATOR_RECIPES + .recipeBuilder("macerate_raw_" + material.getName() + "_ore_to_crushed_ore") + .inputItems(rawOre, material) + .outputItems(GTUtil.copy(property.getOreMultiplier() * 2, crushedStack)) + .chancedOutput(byproductStack, 1400, 850) .EUt(2) + .category(GTRecipeCategories.ORE_CRUSHING) .duration(400); - Material byproductMaterial = GTUtil.selectItemInList(0, material, property.getOreByProducts(), - Material.class); - ItemStack byproductStack = ChemicalHelper.get(gem, byproductMaterial); - if (byproductStack.isEmpty()) { - byproductStack = ChemicalHelper.get(dust, byproductMaterial); - } - builder2.chancedOutput(byproductStack, 1000, 300); - for (MaterialStack secondaryMaterial : ore.secondaryMaterials()) { if (secondaryMaterial.material().hasProperty(PropertyKey.DUST)) { ItemStack dustStack = ChemicalHelper.getGem(secondaryMaterial); - builder2.chancedOutput(dustStack, 500, 100); - break; + builder.chancedOutput(dustStack, 6700, 800); } } - builder2.save(provider); + + builder.save(provider); } - // do not try to add smelting recipes for materials which require blast furnace, or don't have smelting recipes - // at all. - if (!ingotStack.isEmpty() && doesMaterialUseNormalFurnace(smeltingMaterial) && !orePrefix.isIgnored(material)) { - float xp = Math.round(((1 + property.getOreMultiplier() * 0.33f) / 3) * 10f) / 10f; + // do not try to add smelting recipes for materials which require blast furnace + if (!ingotStack.isEmpty() && doesMaterialUseNormalFurnace(smeltingMaterial) && !rawOre.isIgnored(material)) { + float xp = Math.round(((1 + 0.5f) * 0.5f - 0.05f) * 10f) / 10f; VanillaRecipeHelper.addSmeltingRecipe(provider, - "smelt_" + orePrefix.name + "_" + material.getName() + "_ore_to_ingot", - ChemicalHelper.getTag(orePrefix, material), GTUtil.copyAmount(ingotStack.getCount(), ingotStack), - xp); + "smelt_raw_" + material.getName() + "_ore_to_ingot", + ChemicalHelper.getTag(rawOre, material), + ingotStack, xp); VanillaRecipeHelper.addBlastingRecipe(provider, - "smelt_" + orePrefix.name + "_" + material.getName() + "_ore_to_ingot", - ChemicalHelper.getTag(orePrefix, material), GTUtil.copyAmount(ingotStack.getCount(), ingotStack), - xp); + "smelt_raw_" + material.getName() + "_ore_to_ingot", + ChemicalHelper.getTag(rawOre, material), + ingotStack, xp); } if (!ConfigHolder.INSTANCE.recipes.disableManualCompression) { @@ -228,6 +235,7 @@ public static void processRawOre(TagPrefix orePrefix, Material material, OreProp ChemicalHelper.get(rawOre, material, 9), ChemicalHelper.getTag(rawOreBlock, material)); } + COMPRESSOR_RECIPES.recipeBuilder("compress_" + material.getName() + "_to_raw_ore_block") .inputItems(rawOre, material, 9) .outputItems(rawOreBlock, material) @@ -240,20 +248,24 @@ public static void processRawOre(TagPrefix orePrefix, Material material, OreProp .duration(300).EUt(2).save(provider); } - public static void processCrushedOre(TagPrefix crushedPrefix, Material material, OreProperty property, - Consumer provider) { + private static void processCrushedOre(@NotNull Consumer provider, @NotNull OreProperty property, + @NotNull Material material) { + if (!crushed.shouldGenerateRecipes(material)) { + return; + } + ItemStack impureDustStack = ChemicalHelper.get(dustImpure, material); - Material byproductMaterial = GTUtil.selectItemInList(0, material, property.getOreByProducts(), Material.class); + Material byproductMaterial = property.getOreByProduct(0, material); FORGE_HAMMER_RECIPES.recipeBuilder("hammer_" + material.getName() + "_crushed_ore_to_impure_dust") - .inputItems(crushedPrefix, material) + .inputItems(crushed, material) .outputItems(impureDustStack) .duration(10).EUt(16) .category(GTRecipeCategories.ORE_FORGING) .save(provider); MACERATOR_RECIPES.recipeBuilder("macerate_" + material.getName() + "_crushed_ore_to_impure_dust") - .inputItems(crushedPrefix, material) + .inputItems(crushed, material) .outputItems(impureDustStack) .duration(400).EUt(2) .chancedOutput(ChemicalHelper.get(dust, byproductMaterial, property.getByProductMultiplier()), 1400, @@ -261,22 +273,22 @@ public static void processCrushedOre(TagPrefix crushedPrefix, Material material, .category(GTRecipeCategories.ORE_CRUSHING) .save(provider); - ItemStack crushedPurifiedOre = GTUtil.copy( + ItemStack crushedPurifiedOre = GTUtil.copyFirst( ChemicalHelper.get(crushedPurified, material), ChemicalHelper.get(dust, material)); - ItemStack crushedCentrifugedOre = GTUtil.copy( + ItemStack crushedCentrifugedOre = GTUtil.copyFirst( ChemicalHelper.get(crushedRefined, material), ChemicalHelper.get(dust, material)); ORE_WASHER_RECIPES.recipeBuilder("wash_" + material.getName() + "_crushed_ore_to_purified_ore_fast") - .inputItems(crushedPrefix, material) + .inputItems(crushed, material) .circuitMeta(2) .inputFluids(Water.getFluid(100)) .outputItems(crushedPurifiedOre) .duration(8).EUt(4).save(provider); ORE_WASHER_RECIPES.recipeBuilder("wash_" + material.getName() + "_crushed_ore_to_purified_ore") - .inputItems(crushedPrefix, material) + .inputItems(crushed, material) .inputFluids(Water.getFluid(1000)) .circuitMeta(1) .outputItems(crushedPurifiedOre) @@ -285,7 +297,7 @@ public static void processCrushedOre(TagPrefix crushedPrefix, Material material, .save(provider); ORE_WASHER_RECIPES.recipeBuilder("wash_" + material.getName() + "_crushed_ore_to_purified_ore_distilled") - .inputItems(crushedPrefix, material) + .inputItems(crushed, material) .inputFluids(DistilledWater.getFluid(100)) .outputItems(crushedPurifiedOre) .chancedOutput(TagPrefix.dust, byproductMaterial, "1/3", 0) @@ -294,7 +306,7 @@ public static void processCrushedOre(TagPrefix crushedPrefix, Material material, .save(provider); THERMAL_CENTRIFUGE_RECIPES.recipeBuilder("centrifuge_" + material.getName() + "_crushed_ore_to_refined_ore") - .inputItems(crushedPrefix, material) + .inputItems(crushed, material) .outputItems(crushedCentrifugedOre) .chancedOutput(TagPrefix.dust, property.getOreByProduct(1, material), property.getByProductMultiplier(), "1/3", 0) @@ -302,11 +314,10 @@ public static void processCrushedOre(TagPrefix crushedPrefix, Material material, .save(provider); if (property.getWashedIn().getFirst() != null) { - Material washingByproduct = GTUtil.selectItemInList(3, material, property.getOreByProducts(), - Material.class); + Material washingByproduct = property.getOreByProduct(3, material); Pair washedInTuple = property.getWashedIn(); CHEMICAL_BATH_RECIPES.recipeBuilder("bathe_" + material.getName() + "_crushed_ore_to_purified_ore") - .inputItems(crushedPrefix, material) + .inputItems(crushed, material) .inputFluids(washedInTuple.getFirst().getFluid(washedInTuple.getSecond())) .outputItems(crushedPurifiedOre) .chancedOutput(ChemicalHelper.get(dust, washingByproduct, property.getByProductMultiplier()), 7000, @@ -318,26 +329,29 @@ public static void processCrushedOre(TagPrefix crushedPrefix, Material material, } VanillaRecipeHelper.addShapelessRecipe(provider, String.format("crushed_ore_to_dust_%s", material.getName()), - impureDustStack, 'h', new UnificationEntry(crushedPrefix, material)); + impureDustStack, 'h', new UnificationEntry(crushed, material)); - processMetalSmelting(crushedPrefix, material, property, provider); + processMetalSmelting(provider, property, crushed, material); } - public static void processCrushedCentrifuged(TagPrefix centrifugedPrefix, Material material, OreProperty property, - Consumer provider) { + private static void processCrushedCentrifuged(@NotNull Consumer provider, + @NotNull OreProperty property, @NotNull Material material) { + if (!crushedRefined.shouldGenerateRecipes(material)) { + return; + } + ItemStack dustStack = ChemicalHelper.get(dust, material); - ItemStack byproductStack = ChemicalHelper.get(dust, GTUtil.selectItemInList(2, - material, property.getOreByProducts(), Material.class), 1); + ItemStack byproductStack = ChemicalHelper.get(dust, property.getOreByProduct(2, material), 1); FORGE_HAMMER_RECIPES.recipeBuilder("hammer_" + material.getName() + "_refined_ore_to_dust") - .inputItems(centrifugedPrefix, material) + .inputItems(crushedRefined, material) .outputItems(dustStack) .duration(10).EUt(16) .category(GTRecipeCategories.ORE_FORGING) .save(provider); MACERATOR_RECIPES.recipeBuilder("macerate_" + material.getName() + "_refined_ore_to_dust") - .inputItems(centrifugedPrefix, material) + .inputItems(crushedRefined, material) .outputItems(dustStack) .chancedOutput(byproductStack, 1400, 850) .duration(400).EUt(2) @@ -346,21 +360,25 @@ public static void processCrushedCentrifuged(TagPrefix centrifugedPrefix, Materi VanillaRecipeHelper.addShapelessRecipe(provider, String.format("centrifuged_ore_to_dust_%s", material.getName()), dustStack, - 'h', new UnificationEntry(centrifugedPrefix, material)); + 'h', new UnificationEntry(crushedRefined, material)); - processMetalSmelting(centrifugedPrefix, material, property, provider); + processMetalSmelting(provider, property, crushedRefined, material); } - public static void processCrushedPurified(TagPrefix purifiedPrefix, Material material, OreProperty property, - Consumer provider) { + private static void processCrushedPurified(@NotNull Consumer provider, + @NotNull OreProperty property, + @NotNull Material material) { + if (!crushedPurified.shouldGenerateRecipes(material)) { + return; + } + ItemStack crushedCentrifugedStack = ChemicalHelper.get(crushedRefined, material); ItemStack dustStack = ChemicalHelper.get(dustPure, material); - Material byproductMaterial = GTUtil.selectItemInList( - 1, material, property.getOreByProducts(), Material.class); + Material byproductMaterial = property.getOreByProduct(1, material); ItemStack byproductStack = ChemicalHelper.get(dust, byproductMaterial); FORGE_HAMMER_RECIPES.recipeBuilder("hammer_" + material.getName() + "_crushed_ore_to_dust") - .inputItems(purifiedPrefix, material) + .inputItems(crushedPurified, material) .outputItems(dustStack) .duration(10) .EUt(16) @@ -368,7 +386,7 @@ public static void processCrushedPurified(TagPrefix purifiedPrefix, Material mat .save(provider); MACERATOR_RECIPES.recipeBuilder("macerate_" + material.getName() + "_crushed_ore_to_dust") - .inputItems(purifiedPrefix, material) + .inputItems(crushedPurified, material) .outputItems(dustStack) .chancedOutput(byproductStack, 1400, 850) .duration(400).EUt(2) @@ -377,12 +395,12 @@ public static void processCrushedPurified(TagPrefix purifiedPrefix, Material mat VanillaRecipeHelper.addShapelessRecipe(provider, String.format("purified_ore_to_dust_%s", material.getName()), dustStack, - 'h', new UnificationEntry(purifiedPrefix, material)); + 'h', new UnificationEntry(crushedPurified, material)); if (!crushedCentrifugedStack.isEmpty()) { THERMAL_CENTRIFUGE_RECIPES .recipeBuilder("centrifuge_" + material.getName() + "_purified_ore_to_refined_ore") - .inputItems(purifiedPrefix, material) + .inputItems(crushedPurified, material) .outputItems(crushedCentrifugedStack) .chancedOutput(TagPrefix.dust, byproductMaterial, "1/3", 0) .save(provider); @@ -398,7 +416,7 @@ public static void processCrushedPurified(TagPrefix purifiedPrefix, Material mat if (material.hasFlag(HIGH_SIFTER_OUTPUT)) { GTRecipeBuilder builder = SIFTER_RECIPES .recipeBuilder("sift_" + material.getName() + "_purified_ore_to_gems") - .inputItems(purifiedPrefix, material) + .inputItems(crushedPurified, material) .chancedOutput(exquisiteStack, 500, 150) .chancedOutput(flawlessStack, 1500, 200) .chancedOutput(gemStack, 5000, 1000) @@ -414,7 +432,7 @@ public static void processCrushedPurified(TagPrefix purifiedPrefix, Material mat } else { GTRecipeBuilder builder = SIFTER_RECIPES .recipeBuilder("sift_" + material.getName() + "_purified_ore_to_gems") - .inputItems(purifiedPrefix, material) + .inputItems(crushedPurified, material) .chancedOutput(exquisiteStack, 300, 100) .chancedOutput(flawlessStack, 1000, 150) .chancedOutput(gemStack, 3500, 500) @@ -429,19 +447,21 @@ public static void processCrushedPurified(TagPrefix purifiedPrefix, Material mat builder.save(provider); } } - processMetalSmelting(purifiedPrefix, material, property, provider); + processMetalSmelting(provider, property, crushedPurified, material); } - public static void processDirtyDust(TagPrefix dustPrefix, Material material, OreProperty property, - Consumer provider) { - ItemStack dustStack = ChemicalHelper.get(dust, material); + private static void processDirtyDust(@NotNull Consumer provider, @NotNull OreProperty property, + @NotNull Material material) { + if (!dustImpure.shouldGenerateRecipes(material)) { + return; + } - Material byproduct = GTUtil.selectItemInList( - 0, material, property.getOreByProducts(), Material.class); + ItemStack dustStack = ChemicalHelper.get(dust, material); + Material byproduct = property.getOreByProduct(0, material); GTRecipeBuilder builder = CENTRIFUGE_RECIPES .recipeBuilder("centrifuge_" + material.getName() + "_dirty_dust_to_dust") - .inputItems(dustPrefix, material) + .inputItems(dustImpure, material) .outputItems(dustStack) .duration((int) (material.getMass() * 4)).EUt(24); @@ -454,20 +474,23 @@ public static void processDirtyDust(TagPrefix dustPrefix, Material material, Ore builder.save(provider); ORE_WASHER_RECIPES.recipeBuilder("wash_" + material.getName() + "_dirty_dust_to_dust") - .inputItems(dustPrefix, material) + .inputItems(dustImpure, material) .circuitMeta(2) .inputFluids(Water.getFluid(100)) .outputItems(dustStack) .duration(8).EUt(4).save(provider); // dust gains same amount of material as normal dust - processMetalSmelting(dustPrefix, material, property, provider); + processMetalSmelting(provider, property, dustImpure, material); } - public static void processPureDust(TagPrefix purePrefix, Material material, OreProperty property, - Consumer provider) { - Material byproductMaterial = GTUtil.selectItemInList( - 1, material, property.getOreByProducts(), Material.class); + private static void processPureDust(@NotNull Consumer provider, @NotNull OreProperty property, + @NotNull Material material) { + if (!dustPure.shouldGenerateRecipes(material)) { + return; + } + + Material byproductMaterial = property.getOreByProduct(1, material); ItemStack dustStack = ChemicalHelper.get(dust, material); if (property.getSeparatedInto() != null && !property.getSeparatedInto().isEmpty()) { @@ -479,7 +502,7 @@ public static void processPureDust(TagPrefix purePrefix, Material material, OreP prefix == nugget ? 2 : 1); ELECTROMAGNETIC_SEPARATOR_RECIPES.recipeBuilder("separate_" + material.getName() + "_pure_dust_to_dust") - .inputItems(purePrefix, material) + .inputItems(dustPure, material) .outputItems(dustStack) .chancedOutput(TagPrefix.dust, separatedMaterial.get(0), 1000, 250) .chancedOutput(separatedStack2, prefix == TagPrefix.dust ? 500 : 2000, @@ -489,7 +512,7 @@ public static void processPureDust(TagPrefix purePrefix, Material material, OreP } CENTRIFUGE_RECIPES.recipeBuilder("centrifuge_" + material.getName() + "_pure_dust_to_dust") - .inputItems(purePrefix, material) + .inputItems(dustPure, material) .outputItems(dustStack) .chancedOutput(TagPrefix.dust, byproductMaterial, "1/9", 0) .duration(100) @@ -497,16 +520,16 @@ public static void processPureDust(TagPrefix purePrefix, Material material, OreP .save(provider); ORE_WASHER_RECIPES.recipeBuilder("wash_" + material.getName() + "_pure_dust_to_dust") - .inputItems(purePrefix, material) + .inputItems(dustPure, material) .circuitMeta(2) .inputFluids(Water.getFluid(100)) .outputItems(dustStack) .duration(8).EUt(4).save(provider); - processMetalSmelting(purePrefix, material, property, provider); + processMetalSmelting(provider, property, dustPure, material); } - private static boolean doesMaterialUseNormalFurnace(Material material) { + private static boolean doesMaterialUseNormalFurnace(@NotNull Material material) { return !material.hasProperty(PropertyKey.BLAST) && !material.hasFlag(MaterialFlags.NO_ORE_SMELTING); } } diff --git a/src/main/java/com/gregtechceu/gtceu/data/recipe/generated/PartsRecipeHandler.java b/src/main/java/com/gregtechceu/gtceu/data/recipe/generated/PartsRecipeHandler.java index 6594ea680f..bb027e073e 100644 --- a/src/main/java/com/gregtechceu/gtceu/data/recipe/generated/PartsRecipeHandler.java +++ b/src/main/java/com/gregtechceu/gtceu/data/recipe/generated/PartsRecipeHandler.java @@ -16,6 +16,9 @@ import net.minecraft.data.recipes.FinishedRecipe; import net.minecraft.world.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; + +import org.jetbrains.annotations.NotNull; import java.util.function.Consumer; @@ -24,37 +27,42 @@ import static com.gregtechceu.gtceu.api.data.tag.TagPrefix.*; import static com.gregtechceu.gtceu.common.data.GTRecipeTypes.*; -public class PartsRecipeHandler { +public final class PartsRecipeHandler { private PartsRecipeHandler() {} - public static void init(Consumer provider) { - rod.executeHandler(provider, PropertyKey.DUST, PartsRecipeHandler::processStick); - rodLong.executeHandler(provider, PropertyKey.DUST, PartsRecipeHandler::processLongStick); - plate.executeHandler(provider, PropertyKey.DUST, PartsRecipeHandler::processPlate); - plateDouble.executeHandler(provider, PropertyKey.INGOT, PartsRecipeHandler::processPlateDouble); - plateDense.executeHandler(provider, PropertyKey.DUST, PartsRecipeHandler::processPlateDense); - - turbineBlade.executeHandler(provider, PropertyKey.INGOT, PartsRecipeHandler::processTurbine); - rotor.executeHandler(provider, PropertyKey.INGOT, PartsRecipeHandler::processRotor); - bolt.executeHandler(provider, PropertyKey.DUST, PartsRecipeHandler::processBolt); - screw.executeHandler(provider, PropertyKey.DUST, PartsRecipeHandler::processScrew); - wireFine.executeHandler(provider, PropertyKey.INGOT, PartsRecipeHandler::processFineWire); - foil.executeHandler(provider, PropertyKey.INGOT, PartsRecipeHandler::processFoil); - lens.executeHandler(provider, PropertyKey.GEM, PartsRecipeHandler::processLens); - - gear.executeHandler(provider, PropertyKey.DUST, PartsRecipeHandler::processGear); - gearSmall.executeHandler(provider, PropertyKey.DUST, PartsRecipeHandler::processGear); - ring.executeHandler(provider, PropertyKey.INGOT, PartsRecipeHandler::processRing); - springSmall.executeHandler(provider, PropertyKey.INGOT, PartsRecipeHandler::processSpringSmall); - spring.executeHandler(provider, PropertyKey.INGOT, PartsRecipeHandler::processSpring); - round.executeHandler(provider, PropertyKey.INGOT, PartsRecipeHandler::processRound); + public static void run(@NotNull Consumer provider, @NotNull Material material) { + processStick(provider, material); + processLongStick(provider, material); + processPlate(provider, material); + processPlateDouble(provider, material); + processPlateDense(provider, material); + processTurbine(provider, material); + processRotor(provider, material); + processBolt(provider, material); + processScrew(provider, material); + processFineWire(provider, material); + processFoil(provider, material); + processLens(provider, material); + processGear(provider, gear, material); + processGear(provider, gearSmall, material); + processRing(provider, material); + processSpringSmall(provider, material); + processSpring(provider, material); + processRound(provider, material); } - public static void processBolt(TagPrefix boltPrefix, Material material, DustProperty property, - Consumer provider) { - ItemStack boltStack = ChemicalHelper.get(boltPrefix, material.hasFlag(IS_MAGNETIC) ? - material.getProperty(PropertyKey.INGOT).getMacerateInto() : material); + private static void processBolt(@NotNull Consumer provider, @NotNull Material material) { + if (!bolt.shouldGenerateRecipes(material)) { + return; + } + if (!material.hasProperty(PropertyKey.DUST)) { + return; + } + + ItemStack boltStack = ChemicalHelper.get(bolt, + material.hasFlag(IS_MAGNETIC) && material.hasProperty(PropertyKey.INGOT) ? + material.getProperty(PropertyKey.INGOT).getMacerateInto() : material); ItemStack ingotStack = ChemicalHelper.get(ingot, material); CUTTER_RECIPES.recipeBuilder("cut_" + material.getName() + "_screw_to_bolt") @@ -68,7 +76,7 @@ public static void processBolt(TagPrefix boltPrefix, Material material, DustProp EXTRUDER_RECIPES.recipeBuilder("extrude_" + material.getName() + "_ingot_to_bolt") .inputItems(ingot, material) .notConsumable(GTItems.SHAPE_EXTRUDER_BOLT) - .outputItems(GTUtil.copyAmount(8, boltStack)) + .outputItems(GTUtil.copy(8, boltStack)) .duration(15) .EUt(VA[MV]) .save(provider); @@ -77,7 +85,7 @@ public static void processBolt(TagPrefix boltPrefix, Material material, DustProp EXTRUDER_RECIPES.recipeBuilder("extrude_" + material.getName() + "_dust_to_bolt") .inputItems(dust, material) .notConsumable(GTItems.SHAPE_EXTRUDER_BOLT) - .outputItems(GTUtil.copyAmount(8, boltStack)) + .outputItems(GTUtil.copy(8, boltStack)) .duration(15) .EUt(VA[MV]) .save(provider); @@ -85,10 +93,17 @@ public static void processBolt(TagPrefix boltPrefix, Material material, DustProp } } - public static void processScrew(TagPrefix screwPrefix, Material material, DustProperty property, - Consumer provider) { - ItemStack screwStack = ChemicalHelper.get(screwPrefix, material.hasFlag(IS_MAGNETIC) ? - material.getProperty(PropertyKey.INGOT).getMacerateInto() : material); + private static void processScrew(@NotNull Consumer provider, @NotNull Material material) { + if (!screw.shouldGenerateRecipes(material)) { + return; + } + if (!material.hasProperty(PropertyKey.DUST)) { + return; + } + + ItemStack screwStack = ChemicalHelper.get(screw, + material.hasFlag(IS_MAGNETIC) && material.hasProperty(PropertyKey.INGOT) ? + material.getProperty(PropertyKey.INGOT).getMacerateInto() : material); LATHE_RECIPES.recipeBuilder("lathe_" + material.getName() + "_bolt_to_screw") .inputItems(bolt, material) @@ -102,18 +117,24 @@ public static void processScrew(TagPrefix screwPrefix, Material material, DustPr 'X', new UnificationEntry(bolt, material)); } - public static void processFoil(TagPrefix foilPrefix, Material material, IngotProperty property, - Consumer provider) { + private static void processFoil(@NotNull Consumer provider, @NotNull Material material) { + if (!foil.shouldGenerateRecipes(material)) { + return; + } + if (!material.hasProperty(PropertyKey.INGOT)) { + return; + } + var magMaterial = material.hasFlag(IS_MAGNETIC) ? material.getProperty(PropertyKey.INGOT).getMacerateInto() : material; if (!material.hasFlag(NO_SMASHING)) VanillaRecipeHelper.addShapedRecipe(provider, String.format("foil_%s", material.getName()), - ChemicalHelper.get(foilPrefix, material, 2), + ChemicalHelper.get(foil, material, 2), "hP ", 'P', new UnificationEntry(plate, magMaterial)); BENDER_RECIPES.recipeBuilder("bend_" + material.getName() + "_plate_to_foil") .inputItems(plate, material) - .outputItems(foilPrefix, magMaterial, 4) + .outputItems(foil, magMaterial, 4) .duration((int) material.getMass()) .EUt(24) .circuitMeta(1) @@ -121,7 +142,7 @@ public static void processFoil(TagPrefix foilPrefix, Material material, IngotPro BENDER_RECIPES.recipeBuilder("bend_" + material.getName() + "_ingot_to_foil") .inputItems(ingot, material) - .outputItems(foilPrefix, magMaterial, 4) + .outputItems(foil, magMaterial, 4) .duration((int) material.getMass()) .EUt(24) .circuitMeta(10) @@ -131,7 +152,7 @@ public static void processFoil(TagPrefix foilPrefix, Material material, IngotPro EXTRUDER_RECIPES.recipeBuilder("extrude_" + material.getName() + "_ingot_to_foil") .inputItems(ingot, material) .notConsumable(GTItems.SHAPE_EXTRUDER_FOIL) - .outputItems(foilPrefix, magMaterial, 4) + .outputItems(foil, magMaterial, 4) .duration((int) material.getMass()) .EUt(24) .save(provider); @@ -139,16 +160,22 @@ public static void processFoil(TagPrefix foilPrefix, Material material, IngotPro EXTRUDER_RECIPES.recipeBuilder("extrude_" + material.getName() + "_dust_to_foil") .inputItems(dust, material) .notConsumable(GTItems.SHAPE_EXTRUDER_FOIL) - .outputItems(foilPrefix, magMaterial, 4) + .outputItems(foil, magMaterial, 4) .duration((int) material.getMass()) .EUt(24) .save(provider); } } - public static void processFineWire(TagPrefix fineWirePrefix, Material material, IngotProperty property, - Consumer provider) { - ItemStack fineWireStack = ChemicalHelper.get(fineWirePrefix, material.hasFlag(IS_MAGNETIC) ? + private static void processFineWire(@NotNull Consumer provider, @NotNull Material material) { + if (!wireFine.shouldGenerateRecipes(material)) { + return; + } + if (!material.hasProperty(PropertyKey.INGOT)) { + return; + } + + ItemStack fineWireStack = ChemicalHelper.get(wireFine, material.hasFlag(IS_MAGNETIC) ? material.getProperty(PropertyKey.INGOT).getMacerateInto() : material); if (!ChemicalHelper.get(foil, material).isEmpty()) @@ -158,25 +185,34 @@ public static void processFineWire(TagPrefix fineWirePrefix, Material material, if (material.hasProperty(PropertyKey.WIRE)) { WIREMILL_RECIPES.recipeBuilder("mill_" + material.getName() + "_wire_to_fine_wire") .inputItems(wireGtSingle, material) - .outputItems(GTUtil.copyAmount(4, fineWireStack)) + .outputItems(GTUtil.copy(4, fineWireStack)) .duration((int) material.getMass() * 3 / 2) .EUt(VA[ULV]) .save(provider); } else { WIREMILL_RECIPES.recipeBuilder("mill_" + material.getName() + "ingot_to_fine_wire") .inputItems(ingot, material) - .outputItems(GTUtil.copyAmount(8, fineWireStack)) + .outputItems(GTUtil.copy(8, fineWireStack)) .duration((int) material.getMass() * 3) .EUt(VA[ULV]) .save(provider); } } - public static void processGear(TagPrefix gearPrefix, Material material, DustProperty property, - Consumer provider) { - ItemStack stack = ChemicalHelper.get(gearPrefix, material.hasFlag(IS_MAGNETIC) ? - material.getProperty(PropertyKey.INGOT).getMacerateInto() : material); - if (gearPrefix == gear && material.hasProperty(PropertyKey.INGOT)) { + private static void processGear(@NotNull Consumer provider, @NotNull TagPrefix prefix, + @NotNull Material material) { + if (!prefix.shouldGenerateRecipes(material)) { + return; + } + if (!material.hasProperty(PropertyKey.DUST)) { + return; + } + + boolean isSmall = prefix == gearSmall; + ItemStack stack = ChemicalHelper.get(prefix, + material.hasFlag(IS_MAGNETIC) && material.hasProperty(PropertyKey.INGOT) ? + material.getProperty(PropertyKey.INGOT).getMacerateInto() : material); + if (!isSmall && material.hasProperty(PropertyKey.INGOT)) { int voltageMultiplier = getVoltageMultiplier(material); EXTRUDER_RECIPES.recipeBuilder("extrude_" + material.getName() + "_ingot_to_gear") .inputItems(ingot, material, 4) @@ -207,18 +243,20 @@ public static void processGear(TagPrefix gearPrefix, Material material, DustProp } if (material.hasFluid()) { - boolean isSmall = gearPrefix == gearSmall; - FLUID_SOLIDFICATION_RECIPES.recipeBuilder("solidify_" + material.getName() + "_" + gearPrefix.name) - .notConsumable(isSmall ? GTItems.SHAPE_MOLD_GEAR_SMALL : GTItems.SHAPE_MOLD_GEAR) - .inputFluids(material.getFluid(L * (isSmall ? 1 : 4))) - .outputItems(stack) - .duration(isSmall ? 20 : 100) - .EUt(VA[ULV]) - .save(provider); + FluidStack fluidStack = material.getProperty(PropertyKey.FLUID).solidifiesFrom(L * (isSmall ? 1 : 4)); + if (!fluidStack.isEmpty()) { + FLUID_SOLIDFICATION_RECIPES.recipeBuilder("solidify_" + material.getName() + "_" + prefix.name) + .notConsumable(isSmall ? GTItems.SHAPE_MOLD_GEAR_SMALL : GTItems.SHAPE_MOLD_GEAR) + .inputFluids(fluidStack) + .outputItems(stack) + .duration(isSmall ? 20 : 100) + .EUt(VA[ULV]) + .save(provider); + } } if (material.hasFlag(GENERATE_PLATE) && material.hasFlag(GENERATE_ROD)) { - if (gearPrefix == gearSmall) { + if (isSmall) { VanillaRecipeHelper.addShapedRecipe(provider, String.format("small_gear_%s", material.getName()), stack, " R ", "hPx", " R ", 'R', new UnificationEntry(rod, material), 'P', @@ -258,9 +296,13 @@ public static void processGear(TagPrefix gearPrefix, Material material, DustProp } } - public static void processLens(TagPrefix lensPrefix, Material material, GemProperty property, - Consumer provider) { - ItemStack stack = ChemicalHelper.get(lensPrefix, material); + private static void processLens(@NotNull Consumer provider, @NotNull Material material) { + if (!lens.shouldGenerateRecipes(material)) { + return; + } + if (!material.hasProperty(PropertyKey.GEM)) { + return; + } LATHE_RECIPES.recipeBuilder("lathe_" + material.getName() + "_plate_to_lens") .inputItems(plate, material) @@ -277,55 +319,76 @@ public static void processLens(TagPrefix lensPrefix, Material material, GemPrope } } - public static void processPlate(TagPrefix platePrefix, Material material, DustProperty property, - Consumer provider) { + private static void processPlate(@NotNull Consumer provider, @NotNull Material material) { + if (!plate.shouldGenerateRecipes(material)) { + return; + } + if (!material.hasProperty(PropertyKey.DUST)) { + return; + } + if (material.hasFluid()) { - FLUID_SOLIDFICATION_RECIPES.recipeBuilder("solidify_" + material.getName() + "_to_plate") - .notConsumable(GTItems.SHAPE_MOLD_PLATE) - .inputFluids(material.getFluid(L)) - .outputItems(platePrefix, material) - .duration(40) - .EUt(VA[ULV]) - .save(provider); + FluidStack stack = material.getProperty(PropertyKey.FLUID).solidifiesFrom(L); + if (!stack.isEmpty()) { + FLUID_SOLIDFICATION_RECIPES.recipeBuilder("solidify_" + material.getName() + "_to_plate") + .notConsumable(GTItems.SHAPE_MOLD_PLATE) + .inputFluids(stack) + .outputItems(plate, material) + .duration(40) + .EUt(VA[ULV]) + .save(provider); + } } } - public static void processPlateDouble(TagPrefix doublePrefix, Material material, IngotProperty property, - Consumer provider) { + private static void processPlateDouble(@NotNull Consumer provider, @NotNull Material material) { + if (!plateDouble.shouldGenerateRecipes(material)) { + return; + } + if (!material.hasProperty(PropertyKey.INGOT)) { + return; + } + var magMaterial = material.hasFlag(IS_MAGNETIC) ? material.getProperty(PropertyKey.INGOT).getMacerateInto() : material; if (material.hasFlag(GENERATE_PLATE)) { if (!material.hasFlag(NO_SMASHING)) { VanillaRecipeHelper.addShapedRecipe(provider, String.format("plate_double_%s", material.getName()), - ChemicalHelper.get(doublePrefix, magMaterial), + ChemicalHelper.get(plateDouble, magMaterial), "h", "P", "P", 'P', new UnificationEntry(plate, material)); } BENDER_RECIPES.recipeBuilder("bend_" + material.getName() + "_plate_to_double_plate") .EUt(96).duration((int) material.getMass() * 2) .inputItems(plate, material, 2) - .outputItems(doublePrefix, magMaterial) + .outputItems(plateDouble, magMaterial) .circuitMeta(2) .save(provider); BENDER_RECIPES.recipeBuilder("bend_" + material.getName() + "_ingot_to_double_plate") .inputItems(ingot, material, 2) .circuitMeta(2) - .outputItems(doublePrefix, magMaterial) + .outputItems(plateDouble, magMaterial) .duration((int) material.getMass() * 2) .EUt(96) .save(provider); } } - public static void processPlateDense(TagPrefix tagPrefix, Material material, DustProperty property, - Consumer provider) { - var magMaterial = material.hasFlag(IS_MAGNETIC) ? + private static void processPlateDense(@NotNull Consumer provider, @NotNull Material material) { + if (!plateDense.shouldGenerateRecipes(material)) { + return; + } + if (!material.hasProperty(PropertyKey.DUST)) { + return; + } + + var magMaterial = material.hasFlag(IS_MAGNETIC) && material.hasProperty(PropertyKey.INGOT) ? material.getProperty(PropertyKey.INGOT).getMacerateInto() : material; BENDER_RECIPES.recipeBuilder("bend_" + material.getName() + "_plate_to_dense_plate") .inputItems(plate, material, 9) .circuitMeta(9) - .outputItems(tagPrefix, magMaterial) + .outputItems(plateDense, magMaterial) .duration((int) Math.max(material.getMass() * 9L, 1L)) .EUt(96) .save(provider); @@ -334,41 +397,53 @@ public static void processPlateDense(TagPrefix tagPrefix, Material material, Dus BENDER_RECIPES.recipeBuilder("bend_" + material.getName() + "_ingot_to_dense_plate") .inputItems(ingot, material, 9) .circuitMeta(9) - .outputItems(tagPrefix, magMaterial) + .outputItems(plateDense, magMaterial) .duration((int) Math.max(material.getMass() * 9L, 1L)) .EUt(96) .save(provider); } } - public static void processRing(TagPrefix ringPrefix, Material material, IngotProperty property, - Consumer provider) { + private static void processRing(@NotNull Consumer provider, @NotNull Material material) { + if (!ring.shouldGenerateRecipes(material)) { + return; + } + if (!material.hasProperty(PropertyKey.INGOT)) { + return; + } + EXTRUDER_RECIPES.recipeBuilder("extrude_" + material.getName() + "_ingot_to_ring") .inputItems(ingot, material) .notConsumable(GTItems.SHAPE_EXTRUDER_RING) - .outputItems(ringPrefix, material, 4) + .outputItems(ring, material, 4) .duration((int) material.getMass() * 2) .EUt(6L * getVoltageMultiplier(material)) .save(provider); if (!material.hasFlag(NO_SMASHING)) { VanillaRecipeHelper.addShapedRecipe(provider, String.format("ring_%s", material.getName()), - ChemicalHelper.get(ringPrefix, material), + ChemicalHelper.get(ring, material), "h ", " X", 'X', new UnificationEntry(rod, material)); } else { EXTRUDER_RECIPES.recipeBuilder("extrude_" + material.getName() + "_dust_to_ring") .inputItems(dust, material) .notConsumable(GTItems.SHAPE_EXTRUDER_RING) - .outputItems(ringPrefix, material, 4) + .outputItems(ring, material, 4) .duration((int) material.getMass() * 2) .EUt(6L * getVoltageMultiplier(material)) .save(provider); } } - public static void processSpringSmall(TagPrefix springPrefix, Material material, IngotProperty property, - Consumer provider) { + private static void processSpringSmall(@NotNull Consumer provider, @NotNull Material material) { + if (!springSmall.shouldGenerateRecipes(material)) { + return; + } + if (!material.hasProperty(PropertyKey.INGOT)) { + return; + } + VanillaRecipeHelper.addShapedRecipe(provider, String.format("spring_small_%s", material.getName()), ChemicalHelper.get(springSmall, material), " s ", "fRx", 'R', new UnificationEntry(rod, material)); @@ -381,8 +456,14 @@ public static void processSpringSmall(TagPrefix springPrefix, Material material, .save(provider); } - public static void processSpring(TagPrefix springPrefix, Material material, IngotProperty property, - Consumer provider) { + private static void processSpring(@NotNull Consumer provider, @NotNull Material material) { + if (!spring.shouldGenerateRecipes(material)) { + return; + } + if (!material.hasProperty(PropertyKey.INGOT)) { + return; + } + BENDER_RECIPES.recipeBuilder("bend_" + material.getName() + "_long_rod_to_spring") .inputItems(rodLong, material) .outputItems(spring, material) @@ -396,9 +477,15 @@ public static void processSpring(TagPrefix springPrefix, Material material, Ingo " s ", "fRx", " R ", 'R', new UnificationEntry(rodLong, material)); } - public static void processRotor(TagPrefix rotorPrefix, Material material, IngotProperty property, - Consumer provider) { - ItemStack stack = ChemicalHelper.get(rotorPrefix, material); + private static void processRotor(@NotNull Consumer provider, @NotNull Material material) { + if (!rotor.shouldGenerateRecipes(material)) { + return; + } + if (!material.hasProperty(PropertyKey.INGOT)) { + return; + } + + ItemStack stack = ChemicalHelper.get(rotor, material); VanillaRecipeHelper.addShapedRecipe(provider, String.format("rotor_%s", material.getName()), stack, "ChC", "SRf", "CdC", 'C', new UnificationEntry(plate, material), @@ -406,19 +493,22 @@ public static void processRotor(TagPrefix rotorPrefix, Material material, IngotP 'R', new UnificationEntry(ring, material)); if (material.hasFluid()) { - FLUID_SOLIDFICATION_RECIPES.recipeBuilder("solidify_" + material.getName() + "_to_rotor") - .notConsumable(GTItems.SHAPE_MOLD_ROTOR) - .inputFluids(material.getFluid(L * 4)) - .outputItems(GTUtil.copy(stack)) - .duration(120) - .EUt(20) - .save(provider); + FluidStack fluidStack = material.getProperty(PropertyKey.FLUID).solidifiesFrom(L * 4); + if (!fluidStack.isEmpty()) { + FLUID_SOLIDFICATION_RECIPES.recipeBuilder("solidify_" + material.getName() + "_to_rotor") + .notConsumable(GTItems.SHAPE_MOLD_ROTOR) + .inputFluids(fluidStack) + .outputItems(stack.copy()) + .duration(120) + .EUt(20) + .save(provider); + } } EXTRUDER_RECIPES.recipeBuilder("extrude_" + material.getName() + "_ingot_to_rotor") .inputItems(ingot, material, 4) .notConsumable(GTItems.SHAPE_EXTRUDER_ROTOR) - .outputItems(GTUtil.copy(stack)) + .outputItems(stack.copy()) .duration((int) material.getMass() * 4) .EUt(material.getBlastTemperature() >= 2800 ? 256 : 64) .save(provider); @@ -427,22 +517,28 @@ public static void processRotor(TagPrefix rotorPrefix, Material material, IngotP EXTRUDER_RECIPES.recipeBuilder("extrude_" + material.getName() + "_dust_to_rotor") .inputItems(dust, material, 4) .notConsumable(GTItems.SHAPE_EXTRUDER_ROTOR) - .outputItems(GTUtil.copy(stack)) + .outputItems(stack.copy()) .duration((int) material.getMass() * 4) .EUt(material.getBlastTemperature() >= 2800 ? 256 : 64) .save(provider); } } - public static void processStick(TagPrefix stickPrefix, Material material, DustProperty property, - Consumer provider) { + private static void processStick(@NotNull Consumer provider, @NotNull Material material) { + if (!rod.shouldGenerateRecipes(material)) { + return; + } + if (!material.hasProperty(PropertyKey.DUST)) { + return; + } + if (material.hasProperty(PropertyKey.GEM) || material.hasProperty(PropertyKey.INGOT)) { GTRecipeBuilder builder = LATHE_RECIPES.recipeBuilder("lathe_" + material.getName() + "_to_rod") .inputItems(material.hasProperty(PropertyKey.GEM) ? gem : ingot, material) .duration((int) Math.max(material.getMass() * 2, 1)) .EUt(16); - var materialOutput = material.hasFlag(IS_MAGNETIC) ? + var materialOutput = material.hasFlag(IS_MAGNETIC) && material.hasProperty(PropertyKey.INGOT) ? material.getProperty(PropertyKey.INGOT).getMacerateInto() : material; if (ConfigHolder.INSTANCE.recipes.harderRods) { builder.outputItems(rod, materialOutput); @@ -457,34 +553,42 @@ public static void processStick(TagPrefix stickPrefix, Material material, DustPr ItemStack boltStack = ChemicalHelper.get(bolt, material.hasFlag(IS_MAGNETIC) ? material.getProperty(PropertyKey.INGOT).getMacerateInto() : material); CUTTER_RECIPES.recipeBuilder("cut_" + material.getName() + "_rod_to_bolt") - .inputItems(stickPrefix, material) - .outputItems(GTUtil.copyAmount(4, boltStack)) + .inputItems(rod, material) + .outputItems(GTUtil.copy(4, boltStack)) .duration((int) Math.max(material.getMass() * 2L, 1L)) .EUt(4) .save(provider); VanillaRecipeHelper.addShapedRecipe(provider, String.format("bolt_saw_%s", material.getName()), - GTUtil.copyAmount(2, boltStack), + GTUtil.copy(2, boltStack), "s ", " X", 'X', new UnificationEntry(rod, material)); } } - public static void processLongStick(TagPrefix longStickPrefix, Material material, DustProperty property, - Consumer provider) { - ItemStack stack = ChemicalHelper.get(longStickPrefix, material.hasFlag(IS_MAGNETIC) ? - material.getProperty(PropertyKey.INGOT).getMacerateInto() : material); - ItemStack stickStack = ChemicalHelper.get(rod, material.hasFlag(IS_MAGNETIC) ? - material.getProperty(PropertyKey.INGOT).getMacerateInto() : material); + private static void processLongStick(@NotNull Consumer provider, @NotNull Material material) { + if (!rodLong.shouldGenerateRecipes(material)) { + return; + } + if (!material.hasProperty(PropertyKey.DUST)) { + return; + } + + ItemStack stack = ChemicalHelper.get(rodLong, + material.hasFlag(IS_MAGNETIC) && material.hasProperty(PropertyKey.INGOT) ? + material.getProperty(PropertyKey.INGOT).getMacerateInto() : material); + ItemStack stickStack = ChemicalHelper.get(rod, + material.hasFlag(IS_MAGNETIC) && material.hasProperty(PropertyKey.INGOT) ? + material.getProperty(PropertyKey.INGOT).getMacerateInto() : material); CUTTER_RECIPES.recipeBuilder("cut_" + material.getName() + "_long_rod_to_rod") - .inputItems(longStickPrefix, material) - .outputItems(GTUtil.copyAmount(2, stickStack)) + .inputItems(rodLong, material) + .outputItems(GTUtil.copy(2, stickStack)) .duration((int) Math.max(material.getMass(), 1L)).EUt(4) .save(provider); VanillaRecipeHelper.addShapedRecipe(provider, String.format("stick_long_%s", material.getName()), - GTUtil.copyAmount(2, stickStack), + GTUtil.copy(2, stickStack), "s", "X", 'X', new UnificationEntry(rodLong, material)); if (material.hasProperty(PropertyKey.GEM)) { @@ -497,7 +601,7 @@ public static void processLongStick(TagPrefix longStickPrefix, Material material VanillaRecipeHelper.addShapedRecipe(provider, String.format("stick_long_gem_exquisite_%s", material.getName()), - GTUtil.copyAmount(2, stickStack), + GTUtil.copy(2, stickStack), "sf", "G ", 'G', new UnificationEntry(gemExquisite, material)); @@ -535,8 +639,14 @@ public static void processLongStick(TagPrefix longStickPrefix, Material material } } - public static void processTurbine(TagPrefix toolPrefix, Material material, IngotProperty property, - Consumer provider) { + private static void processTurbine(@NotNull Consumer provider, @NotNull Material material) { + if (!turbineBlade.shouldGenerateRecipes(material)) { + return; + } + if (!material.hasProperty(PropertyKey.INGOT)) { + return; + } + ItemStack rotorStack = GTItems.TURBINE_ROTOR.asStack(); // noinspection ConstantConditions TurbineRotorBehaviour.getBehaviour(rotorStack).setPartMaterial(rotorStack, material); @@ -552,24 +662,29 @@ public static void processTurbine(TagPrefix toolPrefix, Material material, Ingot FORMING_PRESS_RECIPES.recipeBuilder("press_" + material.getName() + "_turbine_rotor") .inputItems(plateDouble, material, 5) .inputItems(screw, material, 2) - .outputItems(toolPrefix, material) + .outputItems(turbineBlade, material) .duration(20) .EUt(256) .save(provider); VanillaRecipeHelper.addShapedRecipe(provider, String.format("turbine_blade_%s", material.getName()), - ChemicalHelper.get(toolPrefix, material), + ChemicalHelper.get(turbineBlade, material), "PPP", "SPS", "fPd", 'P', new UnificationEntry(plateDouble, material), 'S', new UnificationEntry(screw, material)); } - public static void processRound(TagPrefix roundPrefix, Material material, IngotProperty property, - Consumer provider) { - var outputMaterial = material.hasFlag(IS_MAGNETIC) ? - material.getProperty(PropertyKey.INGOT).getMacerateInto() : material; - if (!material.hasFlag(NO_SMASHING)) { + private static void processRound(@NotNull Consumer provider, @NotNull Material material) { + if (!round.shouldGenerateRecipes(material)) { + return; + } + if (!material.hasProperty(PropertyKey.INGOT)) { + return; + } + var outputMaterial = material.hasFlag(IS_MAGNETIC) ? material.getProperty(PropertyKey.INGOT).getMacerateInto() : + material; + if (!material.hasFlag(NO_SMASHING)) { VanillaRecipeHelper.addShapedRecipe(provider, String.format("round_%s", material.getName()), ChemicalHelper.get(round, outputMaterial), "fN", "Nh", 'N', new UnificationEntry(nugget, material)); @@ -586,7 +701,7 @@ public static void processRound(TagPrefix roundPrefix, Material material, IngotP .save(provider); } - private static int getVoltageMultiplier(Material material) { + private static int getVoltageMultiplier(@NotNull Material material) { return material.getBlastTemperature() > 2800 ? VA[LV] : VA[ULV]; } } diff --git a/src/main/java/com/gregtechceu/gtceu/data/recipe/generated/PipeRecipeHandler.java b/src/main/java/com/gregtechceu/gtceu/data/recipe/generated/PipeRecipeHandler.java index d8a943a49a..8b95674d77 100644 --- a/src/main/java/com/gregtechceu/gtceu/data/recipe/generated/PipeRecipeHandler.java +++ b/src/main/java/com/gregtechceu/gtceu/data/recipe/generated/PipeRecipeHandler.java @@ -2,15 +2,10 @@ import com.gregtechceu.gtceu.api.data.chemical.ChemicalHelper; import com.gregtechceu.gtceu.api.data.chemical.material.Material; -import com.gregtechceu.gtceu.api.data.chemical.material.properties.FluidPipeProperties; -import com.gregtechceu.gtceu.api.data.chemical.material.properties.IMaterialProperty; -import com.gregtechceu.gtceu.api.data.chemical.material.properties.ItemPipeProperties; import com.gregtechceu.gtceu.api.data.chemical.material.properties.PropertyKey; import com.gregtechceu.gtceu.api.data.chemical.material.stack.UnificationEntry; import com.gregtechceu.gtceu.api.data.tag.TagPrefix; -import com.gregtechceu.gtceu.common.data.GTBlocks; import com.gregtechceu.gtceu.common.data.GTItems; -import com.gregtechceu.gtceu.common.pipelike.duct.DuctPipeType; import com.gregtechceu.gtceu.data.recipe.VanillaRecipeHelper; import com.gregtechceu.gtceu.utils.FormattingUtil; import com.gregtechceu.gtceu.utils.GTUtil; @@ -18,6 +13,8 @@ import net.minecraft.data.recipes.FinishedRecipe; import net.minecraft.world.item.ItemStack; +import org.jetbrains.annotations.NotNull; + import java.util.function.Consumer; import static com.gregtechceu.gtceu.api.GTValues.*; @@ -26,65 +23,69 @@ import static com.gregtechceu.gtceu.common.data.GTMaterials.*; import static com.gregtechceu.gtceu.common.data.GTRecipeTypes.*; -public class PipeRecipeHandler { - - public static void init(Consumer provider) { - pipeTinyFluid.executeHandler(provider, PropertyKey.FLUID_PIPE, PipeRecipeHandler::processPipeTiny); - pipeSmallFluid.executeHandler(provider, PropertyKey.FLUID_PIPE, PipeRecipeHandler::processPipeSmall); - pipeNormalFluid.executeHandler(provider, PropertyKey.FLUID_PIPE, PipeRecipeHandler::processPipeNormal); - pipeLargeFluid.executeHandler(provider, PropertyKey.FLUID_PIPE, PipeRecipeHandler::processPipeLarge); - pipeHugeFluid.executeHandler(provider, PropertyKey.FLUID_PIPE, PipeRecipeHandler::processPipeHuge); +public final class PipeRecipeHandler { - pipeQuadrupleFluid.executeHandler(provider, PropertyKey.FLUID_PIPE, PipeRecipeHandler::processPipeQuadruple); - pipeNonupleFluid.executeHandler(provider, PropertyKey.FLUID_PIPE, PipeRecipeHandler::processPipeNonuple); + private PipeRecipeHandler() {} - pipeSmallItem.executeHandler(provider, PropertyKey.ITEM_PIPE, PipeRecipeHandler::processPipeSmall); - pipeNormalItem.executeHandler(provider, PropertyKey.ITEM_PIPE, PipeRecipeHandler::processPipeNormal); - pipeLargeItem.executeHandler(provider, PropertyKey.ITEM_PIPE, PipeRecipeHandler::processPipeLarge); - pipeHugeItem.executeHandler(provider, PropertyKey.ITEM_PIPE, PipeRecipeHandler::processPipeHuge); + public static void run(@NotNull Consumer provider, @NotNull Material material) { + processPipeTiny(provider, PropertyKey.FLUID_PIPE, pipeTinyFluid, material); + processPipeSmall(provider, PropertyKey.FLUID_PIPE, pipeSmallFluid, material); + processPipeNormal(provider, PropertyKey.FLUID_PIPE, pipeNormalFluid, material); + processPipeLarge(provider, PropertyKey.FLUID_PIPE, pipeLargeFluid, material); + processPipeHuge(provider, PropertyKey.FLUID_PIPE, pipeHugeFluid, material); + processPipeQuadruple(provider, PropertyKey.FLUID_PIPE, pipeQuadrupleFluid, material); + processPipeNonuple(provider, PropertyKey.FLUID_PIPE, pipeNonupleFluid, material); - pipeSmallRestrictive.executeHandler(provider, PropertyKey.ITEM_PIPE, PipeRecipeHandler::processRestrictivePipe); - pipeNormalRestrictive.executeHandler(provider, PropertyKey.ITEM_PIPE, - PipeRecipeHandler::processRestrictivePipe); - pipeLargeRestrictive.executeHandler(provider, PropertyKey.ITEM_PIPE, PipeRecipeHandler::processRestrictivePipe); - pipeHugeRestrictive.executeHandler(provider, PropertyKey.ITEM_PIPE, PipeRecipeHandler::processRestrictivePipe); - - addDuctRecipes(provider, Steel, 2); - addDuctRecipes(provider, StainlessSteel, 4); - addDuctRecipes(provider, TungstenSteel, 8); + processPipeSmall(provider, PropertyKey.ITEM_PIPE, pipeSmallItem, material); + processPipeNormal(provider, PropertyKey.ITEM_PIPE, pipeNormalItem, material); + processPipeLarge(provider, PropertyKey.ITEM_PIPE, pipeLargeItem, material); + processPipeHuge(provider, PropertyKey.ITEM_PIPE, pipeHugeItem, material); + processRestrictivePipe(provider, PropertyKey.ITEM_PIPE, pipeSmallRestrictive, pipeSmallItem, material); + processRestrictivePipe(provider, PropertyKey.ITEM_PIPE, pipeNormalRestrictive, pipeNormalItem, material); + processRestrictivePipe(provider, PropertyKey.ITEM_PIPE, pipeLargeRestrictive, pipeLargeItem, material); + processRestrictivePipe(provider, PropertyKey.ITEM_PIPE, pipeHugeRestrictive, pipeHugeItem, material); } - private static void processRestrictivePipe(TagPrefix pipePrefix, Material material, ItemPipeProperties property, - Consumer provider) { - TagPrefix unrestrictive; - if (pipePrefix == pipeSmallRestrictive) unrestrictive = pipeSmallItem; - else if (pipePrefix == pipeNormalRestrictive) unrestrictive = pipeNormalItem; - else if (pipePrefix == pipeLargeRestrictive) unrestrictive = pipeLargeItem; - else if (pipePrefix == pipeHugeRestrictive) unrestrictive = pipeHugeItem; - else return; + private static void processRestrictivePipe(@NotNull Consumer provider, + @NotNull PropertyKey propertyKey, + @NotNull TagPrefix prefix, @NotNull TagPrefix unrestrictive, + @NotNull Material material) { + if (!prefix.shouldGenerateRecipes(material)) { + return; + } + if (!material.hasProperty(propertyKey)) { + return; + } - ASSEMBLER_RECIPES.recipeBuilder("assemble_" + material.getName() + "_" + pipePrefix.name) + ASSEMBLER_RECIPES.recipeBuilder("assemble_" + material.getName() + "_" + prefix.name) .inputItems(unrestrictive, material) .inputItems(ring, Iron, 2) - .outputItems(pipePrefix, material) + .outputItems(prefix, material) .duration(20) .EUt(VA[ULV]) .save(provider); VanillaRecipeHelper.addShapedRecipe(provider, - FormattingUtil.toLowerCaseUnder(pipePrefix.toString() + "_" + material.getName()), - ChemicalHelper.get(pipePrefix, material), "PR", "Rh", + FormattingUtil.toLowerCaseUnder(prefix + "_" + material.getName()), + ChemicalHelper.get(prefix, material), "PR", "Rh", 'P', new UnificationEntry(unrestrictive, material), 'R', ChemicalHelper.get(ring, Iron)); } - private static void processPipeTiny(TagPrefix pipePrefix, Material material, IMaterialProperty property, - Consumer provider) { + private static void processPipeTiny(@NotNull Consumer provider, @NotNull PropertyKey propertyKey, + @NotNull TagPrefix prefix, @NotNull Material material) { + if (!prefix.shouldGenerateRecipes(material)) { + return; + } + if (!material.hasProperty(propertyKey)) { + return; + } + if (material.hasProperty(PropertyKey.WOOD)) return; - ItemStack pipeStack = ChemicalHelper.get(pipePrefix, material); + ItemStack pipeStack = ChemicalHelper.get(prefix, material); EXTRUDER_RECIPES.recipeBuilder("extrude_" + material.getName() + "_tiny_pipe") .inputItems(ingot, material, 1) .notConsumable(GTItems.SHAPE_EXTRUDER_PIPE_TINY) - .outputItems(GTUtil.copyAmount(2, pipeStack)) + .outputItems(GTUtil.copy(2, pipeStack)) .duration((int) (material.getMass())) .EUt(6L * getVoltageMultiplier(material)) .save(provider); @@ -93,21 +94,29 @@ private static void processPipeTiny(TagPrefix pipePrefix, Material material, IMa EXTRUDER_RECIPES.recipeBuilder("extrude_" + material.getName() + "_tiny_pipe_dust") .inputItems(dust, material, 1) .notConsumable(GTItems.SHAPE_EXTRUDER_PIPE_TINY) - .outputItems(GTUtil.copyAmount(2, pipeStack)) + .outputItems(GTUtil.copy(2, pipeStack)) .duration((int) (material.getMass())) .EUt(6L * getVoltageMultiplier(material)) .save(provider); } else { VanillaRecipeHelper.addShapedRecipe(provider, String.format("tiny_%s_pipe", material.getName()), - GTUtil.copyAmount(2, pipeStack), " s ", "hXw", + GTUtil.copy(2, pipeStack), " s ", "hXw", 'X', new UnificationEntry(plate, material)); } } - private static void processPipeSmall(TagPrefix pipePrefix, Material material, IMaterialProperty property, - Consumer provider) { + private static void processPipeSmall(@NotNull Consumer provider, + @NotNull PropertyKey propertyKey, + @NotNull TagPrefix prefix, @NotNull Material material) { + if (!prefix.shouldGenerateRecipes(material)) { + return; + } + if (!material.hasProperty(propertyKey)) { + return; + } + if (material.hasProperty(PropertyKey.WOOD)) return; - ItemStack pipeStack = ChemicalHelper.get(pipePrefix, material); + ItemStack pipeStack = ChemicalHelper.get(prefix, material); EXTRUDER_RECIPES.recipeBuilder("extrude_" + material.getName() + "_small_pipe") .inputItems(ingot, material, 1) .notConsumable(GTItems.SHAPE_EXTRUDER_PIPE_SMALL) @@ -131,10 +140,18 @@ private static void processPipeSmall(TagPrefix pipePrefix, Material material, IM } } - private static void processPipeNormal(TagPrefix pipePrefix, Material material, IMaterialProperty property, - Consumer provider) { + private static void processPipeNormal(@NotNull Consumer provider, + @NotNull PropertyKey propertyKey, + @NotNull TagPrefix prefix, @NotNull Material material) { + if (!prefix.shouldGenerateRecipes(material)) { + return; + } + if (!material.hasProperty(propertyKey)) { + return; + } + if (material.hasProperty(PropertyKey.WOOD)) return; - ItemStack pipeStack = ChemicalHelper.get(pipePrefix, material); + ItemStack pipeStack = ChemicalHelper.get(prefix, material); EXTRUDER_RECIPES.recipeBuilder("extrude_" + material.getName() + "_pipe") .inputItems(ingot, material, 3) .notConsumable(GTItems.SHAPE_EXTRUDER_PIPE_NORMAL) @@ -158,10 +175,18 @@ private static void processPipeNormal(TagPrefix pipePrefix, Material material, I } } - private static void processPipeLarge(TagPrefix pipePrefix, Material material, IMaterialProperty property, - Consumer provider) { + private static void processPipeLarge(@NotNull Consumer provider, + @NotNull PropertyKey propertyKey, + @NotNull TagPrefix prefix, @NotNull Material material) { + if (!prefix.shouldGenerateRecipes(material)) { + return; + } + if (!material.hasProperty(propertyKey)) { + return; + } + if (material.hasProperty(PropertyKey.WOOD)) return; - ItemStack pipeStack = ChemicalHelper.get(pipePrefix, material); + ItemStack pipeStack = ChemicalHelper.get(prefix, material); EXTRUDER_RECIPES.recipeBuilder("extrude_" + material.getName() + "_large_pipe") .inputItems(ingot, material, 6) .notConsumable(GTItems.SHAPE_EXTRUDER_PIPE_LARGE) @@ -185,10 +210,17 @@ private static void processPipeLarge(TagPrefix pipePrefix, Material material, IM } } - private static void processPipeHuge(TagPrefix pipePrefix, Material material, IMaterialProperty property, - Consumer provider) { + private static void processPipeHuge(@NotNull Consumer provider, @NotNull PropertyKey propertyKey, + @NotNull TagPrefix prefix, @NotNull Material material) { + if (!prefix.shouldGenerateRecipes(material)) { + return; + } + if (!material.hasProperty(propertyKey)) { + return; + } + if (material.hasProperty(PropertyKey.WOOD)) return; - ItemStack pipeStack = ChemicalHelper.get(pipePrefix, material); + ItemStack pipeStack = ChemicalHelper.get(prefix, material); EXTRUDER_RECIPES.recipeBuilder("extrude_" + material.getName() + "_huge_pipe") .inputItems(ingot, material, 12) .notConsumable(GTItems.SHAPE_EXTRUDER_PIPE_HUGE) @@ -212,17 +244,25 @@ private static void processPipeHuge(TagPrefix pipePrefix, Material material, IMa } } - private static void processPipeQuadruple(TagPrefix pipePrefix, Material material, FluidPipeProperties property, - Consumer provider) { + private static void processPipeQuadruple(@NotNull Consumer provider, + @NotNull PropertyKey propertyKey, + @NotNull TagPrefix prefix, @NotNull Material material) { + if (!prefix.shouldGenerateRecipes(material)) { + return; + } + if (!material.hasProperty(propertyKey)) { + return; + } + if (material.hasProperty(PropertyKey.WOOD)) return; ItemStack smallPipe = ChemicalHelper.get(pipeSmallFluid, material); - ItemStack quadPipe = ChemicalHelper.get(pipePrefix, material); + ItemStack quadPipe = ChemicalHelper.get(prefix, material); VanillaRecipeHelper.addShapedRecipe(provider, String.format("quadruple_%s_pipe", material.getName()), quadPipe, "XX", "XX", 'X', smallPipe); PACKER_RECIPES.recipeBuilder("package_" + material.getName() + "_quadruple_pipe") - .inputItems(GTUtil.copyAmount(4, smallPipe)) + .inputItems(GTUtil.copy(4, smallPipe)) .circuitMeta(4) .outputItems(quadPipe) .duration(30) @@ -230,17 +270,25 @@ private static void processPipeQuadruple(TagPrefix pipePrefix, Material material .save(provider); } - private static void processPipeNonuple(TagPrefix pipePrefix, Material material, FluidPipeProperties property, - Consumer provider) { + private static void processPipeNonuple(@NotNull Consumer provider, + @NotNull PropertyKey propertyKey, + @NotNull TagPrefix prefix, @NotNull Material material) { + if (!prefix.shouldGenerateRecipes(material)) { + return; + } + if (!material.hasProperty(propertyKey)) { + return; + } + if (material.hasProperty(PropertyKey.WOOD)) return; ItemStack smallPipe = ChemicalHelper.get(pipeSmallFluid, material); - ItemStack nonuplePipe = ChemicalHelper.get(pipePrefix, material); + ItemStack nonuplePipe = ChemicalHelper.get(prefix, material); VanillaRecipeHelper.addShapedRecipe(provider, String.format("nonuple_%s_pipe", material.getName()), nonuplePipe, "XXX", "XXX", "XXX", 'X', smallPipe); PACKER_RECIPES.recipeBuilder("package_" + material.getName() + "_nonuple_pipe") - .inputItems(GTUtil.copyAmount(9, smallPipe)) + .inputItems(GTUtil.copy(9, smallPipe)) .circuitMeta(9) .outputItems(nonuplePipe) .duration(40) @@ -248,22 +296,7 @@ private static void processPipeNonuple(TagPrefix pipePrefix, Material material, .save(provider); } - private static void addDuctRecipes(Consumer provider, Material material, int outputAmount) { - VanillaRecipeHelper.addShapedRecipe(provider, "small_duct_%s".formatted(material.getName()), - GTBlocks.DUCT_PIPES[DuctPipeType.SMALL.ordinal()].asStack(outputAmount * 2), "w", "X", "h", - 'X', new UnificationEntry(plate, material)); - VanillaRecipeHelper.addShapedRecipe(provider, "medium_duct_%s".formatted(material.getName()), - GTBlocks.DUCT_PIPES[DuctPipeType.NORMAL.ordinal()].asStack(outputAmount), " X ", "wXh", " X ", - 'X', new UnificationEntry(plate, material)); - VanillaRecipeHelper.addShapedRecipe(provider, "large_duct_%s".formatted(material.getName()), - GTBlocks.DUCT_PIPES[DuctPipeType.LARGE.ordinal()].asStack(outputAmount), "XwX", "X X", "XhX", - 'X', new UnificationEntry(plate, material)); - VanillaRecipeHelper.addShapedRecipe(provider, "huge_duct_%s".formatted(material.getName()), - GTBlocks.DUCT_PIPES[DuctPipeType.HUGE.ordinal()].asStack(outputAmount), "XwX", "X X", "XhX", - 'X', new UnificationEntry(plateDouble, material)); - } - - private static int getVoltageMultiplier(Material material) { + private static int getVoltageMultiplier(@NotNull Material material) { return material.getBlastTemperature() >= 2800 ? VA[LV] : VA[ULV]; } } diff --git a/src/main/java/com/gregtechceu/gtceu/data/recipe/generated/PolarizingRecipeHandler.java b/src/main/java/com/gregtechceu/gtceu/data/recipe/generated/PolarizingRecipeHandler.java index 2a127f29af..5d2f31489b 100644 --- a/src/main/java/com/gregtechceu/gtceu/data/recipe/generated/PolarizingRecipeHandler.java +++ b/src/main/java/com/gregtechceu/gtceu/data/recipe/generated/PolarizingRecipeHandler.java @@ -11,47 +11,64 @@ import net.minecraft.data.recipes.FinishedRecipe; import net.minecraft.world.item.ItemStack; +import org.jetbrains.annotations.NotNull; + import java.util.function.Consumer; import static com.gregtechceu.gtceu.api.GTValues.*; import static com.gregtechceu.gtceu.api.data.tag.TagPrefix.*; import static com.gregtechceu.gtceu.common.data.GTRecipeTypes.POLARIZER_RECIPES; -public class PolarizingRecipeHandler { +public final class PolarizingRecipeHandler { private static final TagPrefix[] POLARIZING_PREFIXES = new TagPrefix[] { rod, rodLong, plate, ingot, plateDense, plateDouble, rotor, bolt, screw, wireFine, foil, ring, dust, nugget, block, - dustTiny, dustSmall }; + dustTiny, dustSmall + }; + + private PolarizingRecipeHandler() {} + + public static void run(@NotNull Consumer provider, @NotNull Material material) { + IngotProperty property = material.getProperty(PropertyKey.INGOT); + if (property == null) { + return; + } - public static void init(Consumer provider) { - for (TagPrefix orePrefix : POLARIZING_PREFIXES) { - orePrefix.executeHandler(provider, PropertyKey.INGOT, PolarizingRecipeHandler::processPolarizing); + for (TagPrefix prefix : POLARIZING_PREFIXES) { + processPolarizing(provider, property, prefix, material); } } - public static void processPolarizing(TagPrefix polarizingPrefix, Material material, IngotProperty property, - Consumer provider) { + private static void processPolarizing(@NotNull Consumer provider, @NotNull IngotProperty property, + @NotNull TagPrefix prefix, @NotNull Material material) { + if (!prefix.shouldGenerateRecipes(material)) { + return; + } + if (!material.hasProperty(PropertyKey.INGOT)) { + return; + } + Material magneticMaterial = property.getMagneticMaterial(); - if (magneticMaterial != null && (polarizingPrefix.doGenerateBlock(magneticMaterial) || - polarizingPrefix.doGenerateItem(magneticMaterial))) { - ItemStack magneticStack = ChemicalHelper.get(polarizingPrefix, magneticMaterial); - POLARIZER_RECIPES.recipeBuilder("polarize_" + material.getName() + "_" + polarizingPrefix.name) // polarizing - .inputItems(polarizingPrefix, material) + if (magneticMaterial != null && (prefix.doGenerateBlock(magneticMaterial) || + prefix.doGenerateItem(magneticMaterial))) { + ItemStack magneticStack = ChemicalHelper.get(prefix, magneticMaterial); + POLARIZER_RECIPES.recipeBuilder("polarize_" + material.getName() + "_" + prefix.name) // polarizing + .inputItems(prefix, material) .outputItems(magneticStack) - .duration((int) ((int) material.getMass() * polarizingPrefix.getMaterialAmount(material) / M)) + .duration((int) ((int) material.getMass() * prefix.getMaterialAmount(material) / M)) .EUt(getVoltageMultiplier(material)) .save(provider); VanillaRecipeHelper.addSmeltingRecipe(provider, - "demagnetize_" + magneticMaterial.getName() + "_" + polarizingPrefix, - ChemicalHelper.getTag(polarizingPrefix, magneticMaterial), - ChemicalHelper.get(polarizingPrefix, material)); // de-magnetizing + "demagnetize_" + magneticMaterial.getName() + "_" + prefix, + ChemicalHelper.getTag(prefix, magneticMaterial), + ChemicalHelper.get(prefix, material)); // de-magnetizing } } - private static int getVoltageMultiplier(Material material) { + private static int getVoltageMultiplier(@NotNull Material material) { if (material == GTMaterials.Steel || material == GTMaterials.Iron) return VH[LV]; if (material == GTMaterials.Neodymium) return VH[HV]; if (material == GTMaterials.Samarium) return VH[IV]; diff --git a/src/main/java/com/gregtechceu/gtceu/data/recipe/generated/RecyclingRecipeHandler.java b/src/main/java/com/gregtechceu/gtceu/data/recipe/generated/RecyclingRecipeHandler.java index 18dc17c18e..724e54c3e5 100644 --- a/src/main/java/com/gregtechceu/gtceu/data/recipe/generated/RecyclingRecipeHandler.java +++ b/src/main/java/com/gregtechceu/gtceu/data/recipe/generated/RecyclingRecipeHandler.java @@ -2,7 +2,6 @@ import com.gregtechceu.gtceu.api.data.chemical.ChemicalHelper; import com.gregtechceu.gtceu.api.data.chemical.material.Material; -import com.gregtechceu.gtceu.api.data.chemical.material.properties.DustProperty; import com.gregtechceu.gtceu.api.data.chemical.material.properties.PropertyKey; import com.gregtechceu.gtceu.api.data.chemical.material.stack.MaterialStack; import com.gregtechceu.gtceu.api.data.tag.TagPrefix; @@ -10,6 +9,8 @@ import net.minecraft.data.recipes.FinishedRecipe; +import org.jetbrains.annotations.NotNull; + import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -18,44 +19,57 @@ import static com.gregtechceu.gtceu.api.data.tag.TagPrefix.*; -public class RecyclingRecipeHandler { +public final class RecyclingRecipeHandler { private static final List CRUSHING_PREFIXES = Arrays.asList( ingot, gem, rod, plate, ring, rodLong, foil, bolt, screw, nugget, gearSmall, gear, frameGt, plateDense, spring, springSmall, block, wireFine, rotor, lens, turbineBlade, round, plateDouble, dust, - (Predicate) orePrefix -> orePrefix.name().startsWith("toolHead"), - (Predicate) orePrefix -> orePrefix.name().contains("Gem"), - (Predicate) orePrefix -> orePrefix.name().startsWith("cableGt"), - (Predicate) orePrefix -> orePrefix.name().startsWith("wireGt"), - (Predicate) orePrefix -> orePrefix.name().startsWith("pipe")); + (Predicate) prefix -> prefix.name().startsWith("toolHead"), + (Predicate) prefix -> prefix.name().contains("Gem"), + (Predicate) prefix -> prefix.name().startsWith("cableGt"), + (Predicate) prefix -> prefix.name().startsWith("wireGt"), + (Predicate) prefix -> prefix.name().startsWith("pipe")); private static final List IGNORE_ARC_SMELTING = Arrays.asList(ingot, gem, nugget); - public static void init(Consumer provider) { + private RecyclingRecipeHandler() {} + + public static void run(@NotNull Consumer provider, @NotNull Material material) { // registers universal maceration recipes for specified ore prefixes - for (TagPrefix orePrefix : TagPrefix.values()) { + for (TagPrefix prefix : TagPrefix.values()) { if (CRUSHING_PREFIXES.stream().anyMatch(object -> { - if (object instanceof TagPrefix) - return object == orePrefix; - else if (object instanceof Predicate) - return ((Predicate) object).test(orePrefix); - else return false; - })) orePrefix.executeHandler(provider, PropertyKey.DUST, RecyclingRecipeHandler::processCrushing); + if (object instanceof TagPrefix) { + return object == prefix; + } + if (object instanceof Predicate) { + return ((Predicate) object).test(prefix); + } + return false; + })) { + processCrushing(provider, prefix, material); + } } } - public static void processCrushing(TagPrefix thingPrefix, Material material, DustProperty property, - Consumer provider) { + private static void processCrushing(@NotNull Consumer provider, @NotNull TagPrefix prefix, + @NotNull Material material) { + if (!prefix.shouldGenerateRecipes(material)) { + return; + } + if (!material.hasProperty(PropertyKey.DUST)) { + return; + } + ArrayList materialStacks = new ArrayList<>(); - materialStacks.add(new MaterialStack(material, thingPrefix.getMaterialAmount(material))); - materialStacks.addAll(thingPrefix.secondaryMaterials()); + materialStacks.add(new MaterialStack(material, prefix.getMaterialAmount(material))); + materialStacks.addAll(prefix.secondaryMaterials()); // only ignore arc smelting for blacklisted prefixes if yielded material is the same as input material // if arc smelting gives different material, allow it - boolean ignoreArcSmelting = IGNORE_ARC_SMELTING.contains(thingPrefix) && + boolean ignoreArcSmelting = IGNORE_ARC_SMELTING.contains(prefix) && !(material.hasProperty(PropertyKey.INGOT) && material.getProperty(PropertyKey.INGOT).getArcSmeltingInto() != material); - RecyclingRecipes.registerRecyclingRecipes(provider, ChemicalHelper.get(thingPrefix, material), materialStacks, - ignoreArcSmelting, thingPrefix); + RecyclingRecipes.registerRecyclingRecipes(provider, ChemicalHelper.get(prefix, material), materialStacks, + ignoreArcSmelting, prefix); } } diff --git a/src/main/java/com/gregtechceu/gtceu/data/recipe/generated/ToolRecipeHandler.java b/src/main/java/com/gregtechceu/gtceu/data/recipe/generated/ToolRecipeHandler.java index a6ea9db984..da28c94563 100644 --- a/src/main/java/com/gregtechceu/gtceu/data/recipe/generated/ToolRecipeHandler.java +++ b/src/main/java/com/gregtechceu/gtceu/data/recipe/generated/ToolRecipeHandler.java @@ -13,144 +13,70 @@ import com.gregtechceu.gtceu.api.data.tag.TagPrefix; import com.gregtechceu.gtceu.api.item.tool.GTToolType; import com.gregtechceu.gtceu.api.item.tool.ToolHelper; -import com.gregtechceu.gtceu.api.recipe.ToolHeadReplaceRecipe; import com.gregtechceu.gtceu.common.data.GTItems; import com.gregtechceu.gtceu.common.data.GTMaterialItems; import com.gregtechceu.gtceu.common.data.GTMaterials; import com.gregtechceu.gtceu.common.data.GTRecipeTypes; -import com.gregtechceu.gtceu.data.recipe.CustomTags; import com.gregtechceu.gtceu.data.recipe.VanillaRecipeHelper; -import com.gregtechceu.gtceu.utils.ToolItemHelper; -import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.data.recipes.FinishedRecipe; -import net.minecraft.data.recipes.SpecialRecipeBuilder; -import net.minecraft.tags.ItemTags; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.item.crafting.Ingredient; -import net.minecraft.world.level.block.Blocks; -import com.google.common.collect.ImmutableList; import com.tterrag.registrate.util.entry.ItemEntry; +import it.unimi.dsi.fastutil.ints.Int2ReferenceArrayMap; +import it.unimi.dsi.fastutil.ints.Int2ReferenceMap; import org.apache.commons.lang3.ArrayUtils; import org.jetbrains.annotations.NotNull; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; import java.util.function.Consumer; -import static com.gregtechceu.gtceu.api.GTValues.*; import static com.gregtechceu.gtceu.api.data.chemical.material.info.MaterialFlags.*; import static com.gregtechceu.gtceu.api.data.tag.TagPrefix.*; -public class ToolRecipeHandler { +public final class ToolRecipeHandler { - public static Map> motorItems = new HashMap<>(); - public static Map baseMaterials = new HashMap<>(); - public static Map>> batteryItems = new HashMap<>(); - public static Map> powerUnitItems = new HashMap<>(); - private static final Material[] softMaterials = new Material[] { + public static final Int2ReferenceMap> powerUnitItems = new Int2ReferenceArrayMap<>(); + + public static final Material[] softMaterials = new Material[] { GTMaterials.Wood, GTMaterials.Rubber, GTMaterials.Polyethylene, GTMaterials.Polytetrafluoroethylene, GTMaterials.Polybenzimidazole, GTMaterials.SiliconeRubber, GTMaterials.StyreneButadieneRubber }; - public static void init(Consumer provider) { - initializeGTItems(); - TagPrefix.plate.executeHandler(provider, PropertyKey.TOOL, ToolRecipeHandler::processTool); - TagPrefix.plate.executeHandler(provider, PropertyKey.TOOL, ToolRecipeHandler::processElectricTool); - registerPowerUnitRecipes(provider); - registerCustomToolRecipes(provider); - } - - public static void initializeGTItems() { - motorItems.put(GTValues.LV, GTItems.ELECTRIC_MOTOR_LV); - motorItems.put(GTValues.MV, GTItems.ELECTRIC_MOTOR_MV); - motorItems.put(GTValues.HV, GTItems.ELECTRIC_MOTOR_HV); - motorItems.put(GTValues.EV, GTItems.ELECTRIC_MOTOR_EV); - motorItems.put(GTValues.IV, GTItems.ELECTRIC_MOTOR_IV); - - baseMaterials.put(GTValues.LV, GTMaterials.Steel); - baseMaterials.put(GTValues.MV, GTMaterials.Aluminium); - baseMaterials.put(GTValues.HV, GTMaterials.StainlessSteel); - baseMaterials.put(GTValues.EV, GTMaterials.Titanium); - baseMaterials.put(GTValues.IV, GTMaterials.TungstenSteel); + private ToolRecipeHandler() {} + public static void setup() { powerUnitItems.put(GTValues.LV, GTItems.POWER_UNIT_LV); powerUnitItems.put(GTValues.MV, GTItems.POWER_UNIT_MV); powerUnitItems.put(GTValues.HV, GTItems.POWER_UNIT_HV); powerUnitItems.put(GTValues.EV, GTItems.POWER_UNIT_EV); powerUnitItems.put(GTValues.IV, GTItems.POWER_UNIT_IV); - - batteryItems.put(GTValues.ULV, Collections.singletonList(GTItems.BATTERY_ULV_TANTALUM)); - batteryItems.put(GTValues.LV, - ImmutableList.of(GTItems.BATTERY_LV_LITHIUM, GTItems.BATTERY_LV_CADMIUM, GTItems.BATTERY_LV_SODIUM)); - batteryItems.put(GTValues.MV, - ImmutableList.of(GTItems.BATTERY_MV_LITHIUM, GTItems.BATTERY_MV_CADMIUM, GTItems.BATTERY_MV_SODIUM)); - batteryItems.put(GTValues.HV, ImmutableList.of(GTItems.BATTERY_HV_LITHIUM, GTItems.BATTERY_HV_CADMIUM, - GTItems.BATTERY_HV_SODIUM, GTItems.ENERGIUM_CRYSTAL)); - batteryItems.put(GTValues.EV, ImmutableList.of(GTItems.BATTERY_EV_VANADIUM, GTItems.LAPOTRON_CRYSTAL)); - batteryItems.put(GTValues.IV, ImmutableList.of(GTItems.BATTERY_IV_VANADIUM, GTItems.ENERGY_LAPOTRONIC_ORB)); - batteryItems.put(GTValues.LuV, - ImmutableList.of(GTItems.BATTERY_LuV_VANADIUM, GTItems.ENERGY_LAPOTRONIC_ORB_CLUSTER)); - batteryItems.put(GTValues.ZPM, ImmutableList.of(GTItems.BATTERY_ZPM_NAQUADRIA, GTItems.ENERGY_MODULE)); - batteryItems.put(GTValues.UV, ImmutableList.of(GTItems.BATTERY_UV_NAQUADRIA, GTItems.ENERGY_CLUSTER)); - - ToolHeadReplaceRecipe.setToolHeadForTool(toolHeadDrill, GTToolType.DRILL_LV); - ToolHeadReplaceRecipe.setToolHeadForTool(toolHeadDrill, GTToolType.DRILL_MV); - ToolHeadReplaceRecipe.setToolHeadForTool(toolHeadDrill, GTToolType.DRILL_HV); - ToolHeadReplaceRecipe.setToolHeadForTool(toolHeadDrill, GTToolType.DRILL_EV); - ToolHeadReplaceRecipe.setToolHeadForTool(toolHeadDrill, GTToolType.DRILL_IV); - ToolHeadReplaceRecipe.setToolHeadForTool(toolHeadChainsaw, GTToolType.CHAINSAW_LV); - ToolHeadReplaceRecipe.setToolHeadForTool(toolHeadWrench, GTToolType.WRENCH_LV); - ToolHeadReplaceRecipe.setToolHeadForTool(toolHeadWrench, GTToolType.WRENCH_HV); - ToolHeadReplaceRecipe.setToolHeadForTool(toolHeadWrench, GTToolType.WRENCH_IV); - ToolHeadReplaceRecipe.setToolHeadForTool(toolHeadBuzzSaw, GTToolType.BUZZSAW); - ToolHeadReplaceRecipe.setToolHeadForTool(toolHeadScrewdriver, GTToolType.SCREWDRIVER_LV); - ToolHeadReplaceRecipe.setToolHeadForTool(toolHeadWireCutter, GTToolType.WIRE_CUTTER_LV); - ToolHeadReplaceRecipe.setToolHeadForTool(toolHeadWireCutter, GTToolType.WIRE_CUTTER_HV); - ToolHeadReplaceRecipe.setToolHeadForTool(toolHeadWireCutter, GTToolType.WIRE_CUTTER_IV); } - public static void registerPowerUnitRecipes(Consumer provider) { - for (int tier : powerUnitItems.keySet()) { - List> tieredBatteryItems = batteryItems.get(tier); - for (ItemEntry batteryItem : tieredBatteryItems) { - if (powerUnitItems.get(tier) != null) { - ItemStack batteryStack = batteryItem.asStack(); - long maxCharge = GTCapabilityHelper.getElectricItem(batteryStack).getMaxCharge(); - ItemStack powerUnitStack = ToolItemHelper.getMaxChargeOverrideStack(powerUnitItems.get(tier).get(), - maxCharge); - String recipeName = String.format("%s_%s", - BuiltInRegistries.ITEM.getKey(powerUnitItems.get(tier).get()).getPath(), - BuiltInRegistries.ITEM.getKey(batteryItem.get()).getPath()); - - VanillaRecipeHelper.addShapedEnergyTransferRecipe(provider, true, false, true, recipeName, - Ingredient.of(batteryStack), powerUnitStack, - "S d", "GMG", "PBP", - 'M', motorItems.get(tier).asStack(), - 'S', new UnificationEntry(screw, baseMaterials.get(tier)), - 'P', new UnificationEntry(plate, baseMaterials.get(tier)), - 'G', new UnificationEntry(gearSmall, baseMaterials.get(tier)), - 'B', batteryStack); - } - } + public static void run(@NotNull Consumer provider, @NotNull Material material) { + ToolProperty property = material.getProperty(PropertyKey.TOOL); + if (property == null) { + return; } + + processTool(provider, material); + processElectricTool(provider, property, material); } - private static void processTool(TagPrefix prefix, Material material, ToolProperty property, - Consumer provider) { + private static void processTool(@NotNull Consumer provider, @NotNull Material material) { + if (!plate.shouldGenerateRecipes(material)) { + return; + } + ItemStack stick = new ItemStack(Items.STICK); UnificationEntry plate = new UnificationEntry(TagPrefix.plate, material); UnificationEntry ingot = new UnificationEntry( material.hasProperty(PropertyKey.GEM) ? TagPrefix.gem : TagPrefix.ingot, material); if (material.hasFlag(GENERATE_PLATE)) { - addToolRecipe(provider, material, GTToolType.MINING_HAMMER, true, "PPf", "PPS", "PPh", 'P', plate, @@ -261,8 +187,12 @@ private static void processTool(TagPrefix prefix, Material material, ToolPropert } } - private static void processElectricTool(TagPrefix prefix, Material material, ToolProperty property, - Consumer provider) { + private static void processElectricTool(@NotNull Consumer provider, @NotNull ToolProperty property, + @NotNull Material material) { + if (!plate.shouldGenerateRecipes(material)) { + return; + } + final int voltageMultiplier = material.getBlastTemperature() > 2800 ? GTValues.VA[GTValues.LV] : GTValues.VA[GTValues.ULV]; TagPrefix toolPrefix; @@ -281,8 +211,8 @@ private static void processElectricTool(TagPrefix prefix, Material material, Too 'X', plate, 'S', steelPlate); - addElectricToolRecipe(toolPrefix, material, new GTToolType[] { GTToolType.DRILL_LV, GTToolType.DRILL_MV, - GTToolType.DRILL_HV, GTToolType.DRILL_EV, GTToolType.DRILL_IV }, provider); + addElectricToolRecipe(provider, toolPrefix, new GTToolType[] { GTToolType.DRILL_LV, GTToolType.DRILL_MV, + GTToolType.DRILL_HV, GTToolType.DRILL_EV, GTToolType.DRILL_IV }, material); } // chainsaw @@ -295,15 +225,15 @@ private static void processElectricTool(TagPrefix prefix, Material material, Too 'S', steelPlate, 'R', steelRing); - addElectricToolRecipe(toolPrefix, material, new GTToolType[] { GTToolType.CHAINSAW_LV }, provider); + addElectricToolRecipe(provider, toolPrefix, new GTToolType[] { GTToolType.CHAINSAW_LV }, material); } // wrench if (property.hasType(GTToolType.WRENCH_LV)) { toolPrefix = TagPrefix.toolHeadWrench; - addElectricToolRecipe(toolPrefix, material, + addElectricToolRecipe(provider, toolPrefix, new GTToolType[] { GTToolType.WRENCH_LV, GTToolType.WRENCH_HV, GTToolType.WRENCH_IV }, - provider); + material); VanillaRecipeHelper.addShapedRecipe(provider, String.format("wrench_head_%s", material.getName()), ChemicalHelper.get(toolPrefix, material), @@ -316,10 +246,10 @@ private static void processElectricTool(TagPrefix prefix, Material material, Too // electric wire cutters if (property.hasType(GTToolType.WIRE_CUTTER_LV)) { toolPrefix = toolHeadWireCutter; - addElectricToolRecipe(toolPrefix, material, + addElectricToolRecipe(provider, toolPrefix, new GTToolType[] { GTToolType.WIRE_CUTTER_LV, GTToolType.WIRE_CUTTER_HV, GTToolType.WIRE_CUTTER_IV }, - provider); + material); VanillaRecipeHelper.addShapedRecipe(provider, String.format("wirecutter_head_%s", material.getName()), ChemicalHelper.get(toolPrefix, material), @@ -332,7 +262,7 @@ private static void processElectricTool(TagPrefix prefix, Material material, Too // buzzsaw if (property.hasType(GTToolType.BUZZSAW)) { toolPrefix = TagPrefix.toolHeadBuzzSaw; - addElectricToolRecipe(toolPrefix, material, new GTToolType[] { GTToolType.BUZZSAW }, provider); + addElectricToolRecipe(provider, toolPrefix, new GTToolType[] { GTToolType.BUZZSAW }, material); VanillaRecipeHelper.addShapedRecipe(provider, String.format("buzzsaw_blade_%s", material.getName()), ChemicalHelper.get(toolPrefix, material), @@ -360,7 +290,7 @@ private static void processElectricTool(TagPrefix prefix, Material material, Too if (property.hasType(GTToolType.SCREWDRIVER_LV)) { if (material.hasFlag(GENERATE_LONG_ROD)) { toolPrefix = TagPrefix.toolHeadScrewdriver; - addElectricToolRecipe(toolPrefix, material, new GTToolType[] { GTToolType.SCREWDRIVER_LV }, provider); + addElectricToolRecipe(provider, toolPrefix, new GTToolType[] { GTToolType.SCREWDRIVER_LV }, material); VanillaRecipeHelper.addShapedRecipe(provider, String.format("screwdriver_tip_%s", material.getName()), ChemicalHelper.get(toolPrefix, material), @@ -373,8 +303,9 @@ private static void processElectricTool(TagPrefix prefix, Material material, Too } } - public static void addElectricToolRecipe(TagPrefix toolHead, Material material, GTToolType[] toolItems, - Consumer provider) { + private static void addElectricToolRecipe(@NotNull Consumer provider, @NotNull TagPrefix toolHead, + @NotNull GTToolType @NotNull [] toolItems, + @NotNull Material material) { for (GTToolType toolType : toolItems) { if (!material.getProperty(PropertyKey.TOOL).hasType(toolType)) continue; @@ -393,7 +324,7 @@ public static void addElectricToolRecipe(TagPrefix toolHead, Material material, } } - public static void addToolRecipe(Consumer provider, @NotNull Material material, + public static void addToolRecipe(@NotNull Consumer provider, @NotNull Material material, @NotNull GTToolType tool, boolean mirrored, Object... recipe) { ItemStack toolStack = ToolHelper.get(tool, material); if (toolStack.isEmpty()) return; @@ -409,7 +340,7 @@ public static void addToolRecipe(Consumer provider, @NotNull Mat /** * {@code D} is inferred as the dye key */ - public static void addDyeableToolRecipe(Consumer provider, @NotNull Material material, + public static void addDyeableToolRecipe(@NotNull Consumer provider, @NotNull Material material, @NotNull GTToolType tool, boolean mirrored, Object... recipe) { ItemStack toolStack = ToolHelper.get(tool, material); if (toolStack.isEmpty()) return; @@ -429,169 +360,4 @@ public static void addDyeableToolRecipe(Consumer provider, @NotN } } } - - public static void registerCustomToolRecipes(Consumer provider) { - registerFlintToolRecipes(provider); - registerMortarRecipes(provider); - registerSoftToolRecipes(provider); - registerElectricRecipes(provider); - - SpecialRecipeBuilder.special(ToolHeadReplaceRecipe.SERIALIZER).save(provider, - "gtceu:crafting/replace_tool_head"); - } - - private static void registerFlintToolRecipes(Consumer provider) { - final UnificationEntry flint = new UnificationEntry(TagPrefix.gem, GTMaterials.Flint); - final ItemStack stick = new ItemStack(Items.STICK); - - addToolRecipe(provider, GTMaterials.Flint, GTToolType.MORTAR, false, - " I ", "SIS", "SSS", - 'I', flint, - 'S', new ItemStack(Blocks.STONE)); - - addToolRecipe(provider, GTMaterials.Flint, GTToolType.SWORD, false, - "I", "I", "S", - 'I', flint, - 'S', stick); - - addToolRecipe(provider, GTMaterials.Flint, GTToolType.PICKAXE, false, - "III", " S ", " S ", - 'I', flint, - 'S', stick); - - addToolRecipe(provider, GTMaterials.Flint, GTToolType.SHOVEL, false, - "I", "S", "S", - 'I', flint, - 'S', stick); - - addToolRecipe(provider, GTMaterials.Flint, GTToolType.AXE, true, - "II", "IS", " S", - 'I', flint, - 'S', stick); - - addToolRecipe(provider, GTMaterials.Flint, GTToolType.HOE, true, - "II", " S", " S", - 'I', flint, - 'S', stick); - - addToolRecipe(provider, GTMaterials.Flint, GTToolType.KNIFE, false, - "I", "S", - 'I', flint, - 'S', stick); - } - - private static void registerMortarRecipes(Consumer provider) { - for (Material material : new Material[] { - GTMaterials.Bronze, GTMaterials.Iron, GTMaterials.Invar, GTMaterials.Steel, - GTMaterials.DamascusSteel, GTMaterials.CobaltBrass, GTMaterials.WroughtIron }) { - - addToolRecipe(provider, material, GTToolType.MORTAR, false, - " I ", "SIS", "SSS", - 'I', - new UnificationEntry(material.hasProperty(PropertyKey.GEM) ? TagPrefix.gem : TagPrefix.ingot, - material), - 'S', new ItemStack(Blocks.STONE)); - } - } - - private static void registerSoftToolRecipes(Consumer provider) { - final ItemStack stick = new ItemStack(Items.STICK); - - for (int i = 0; i < softMaterials.length; i++) { - Material material = softMaterials[i]; - - if (material.hasProperty(PropertyKey.WOOD)) { - // todo allow these 3 to be mirrored - VanillaRecipeHelper.addShapedRecipe(provider, String.format("soft_mallet_%s", material.getName()), - ToolHelper.get(GTToolType.SOFT_MALLET, material), - "II ", "IIS", "II ", - 'I', ItemTags.PLANKS, - 'S', stick); - } else { - VanillaRecipeHelper.addShapedRecipe(provider, String.format("soft_mallet_%s", material.getName()), - ToolHelper.get(GTToolType.SOFT_MALLET, material), - "II ", "IIS", "II ", - 'I', new UnificationEntry(TagPrefix.ingot, material), - 'S', stick); - - VanillaRecipeHelper.addShapedRecipe(provider, String.format("plunger_%s", material.getName()), - ToolHelper.getAndSetToolData(GTToolType.PLUNGER, material, 128 * (i << 1), 1, 4F, 0F), - "xPP", " SP", "S f", - 'P', new UnificationEntry(TagPrefix.plate, material), - 'S', rod); - } - } - } - - private static void registerElectricRecipes(Consumer provider) { - for (ItemEntry batteryItem : batteryItems.get(LV)) { - VanillaRecipeHelper.addShapedEnergyTransferRecipe(provider, true, false, true, - "prospector_lv_" + batteryItem.getId().getPath(), - Ingredient.of(batteryItem), GTItems.PROSPECTOR_LV.asStack(), - "EPS", "CDC", "PBP", - 'E', GTItems.EMITTER_LV.asStack(), - 'P', new UnificationEntry(plate, GTMaterials.Steel), - 'S', GTItems.SENSOR_LV.asStack(), - 'D', new UnificationEntry(plate, GTMaterials.Glass), - 'C', CustomTags.LV_CIRCUITS, - 'B', batteryItem.asStack()); - - VanillaRecipeHelper.addShapedEnergyTransferRecipe(provider, true, false, true, - "lv_magnet_" + batteryItem.getId().getPath(), - Ingredient.of(batteryItem), GTItems.ITEM_MAGNET_LV.asStack(), - "MwM", "MBM", "CPC", - 'M', new UnificationEntry(rod, GTMaterials.SteelMagnetic), - 'P', new UnificationEntry(plate, GTMaterials.Steel), - 'C', new UnificationEntry(cableGtSingle, GTMaterials.Tin), - 'B', batteryItem.asStack()); - } - - for (ItemEntry batteryItem : batteryItems.get(MV)) { - VanillaRecipeHelper.addShapedEnergyTransferRecipe(provider, true, false, true, - "portable_scanner_" + batteryItem.getId().getPath(), - Ingredient.of(batteryItem), GTItems.PORTABLE_SCANNER.asStack(), - "EPS", "CDC", "PBP", - 'E', GTItems.EMITTER_MV.asStack(), - 'P', new UnificationEntry(plate, GTMaterials.Aluminium), - 'S', GTItems.SENSOR_MV.asStack(), - 'D', GTItems.COVER_SCREEN.asStack(), - 'C', CustomTags.MV_CIRCUITS, - 'B', batteryItem.asStack()); - } - - for (ItemEntry batteryItem : batteryItems.get(HV)) { - VanillaRecipeHelper.addShapedEnergyTransferRecipe(provider, true, false, true, - "prospector_hv_" + batteryItem.getId().getPath(), - Ingredient.of(batteryItem), GTItems.PROSPECTOR_HV.asStack(), - "EPS", "CDC", "PBP", - 'E', GTItems.EMITTER_HV.asStack(), - 'P', new UnificationEntry(plate, GTMaterials.StainlessSteel), - 'S', GTItems.SENSOR_HV.asStack(), - 'D', GTItems.COVER_SCREEN.asStack(), - 'C', CustomTags.HV_CIRCUITS, - 'B', batteryItem.asStack()); - - VanillaRecipeHelper.addShapedEnergyTransferRecipe(provider, true, false, true, - "hv_magnet_" + batteryItem.getId().getPath(), - Ingredient.of(batteryItem), GTItems.ITEM_MAGNET_HV.asStack(), - "MwM", "MBM", "CPC", - 'M', new UnificationEntry(rod, GTMaterials.NeodymiumMagnetic), - 'P', new UnificationEntry(plate, GTMaterials.StainlessSteel), - 'C', new UnificationEntry(cableGtSingle, GTMaterials.Gold), - 'B', batteryItem.asStack()); - } - - for (ItemEntry batteryItem : batteryItems.get(LuV)) { - VanillaRecipeHelper.addShapedEnergyTransferRecipe(provider, true, false, true, - "prospector_luv_" + batteryItem.getId().getPath(), - Ingredient.of(batteryItem), GTItems.PROSPECTOR_LuV.asStack(), - "EPS", "CDC", "PBP", - 'E', GTItems.EMITTER_LuV.asStack(), - 'P', new UnificationEntry(plate, GTMaterials.RhodiumPlatedPalladium), - 'S', GTItems.SENSOR_LuV.asStack(), - 'D', GTItems.COVER_SCREEN.asStack(), - 'C', CustomTags.LuV_CIRCUITS, - 'B', batteryItem.asStack()); - } - } } diff --git a/src/main/java/com/gregtechceu/gtceu/data/recipe/generated/WireCombiningHandler.java b/src/main/java/com/gregtechceu/gtceu/data/recipe/generated/WireCombiningHandler.java index 7e1ae80325..c0a307a12a 100644 --- a/src/main/java/com/gregtechceu/gtceu/data/recipe/generated/WireCombiningHandler.java +++ b/src/main/java/com/gregtechceu/gtceu/data/recipe/generated/WireCombiningHandler.java @@ -4,7 +4,6 @@ import com.gregtechceu.gtceu.api.data.chemical.ChemicalHelper; import com.gregtechceu.gtceu.api.data.chemical.material.Material; import com.gregtechceu.gtceu.api.data.chemical.material.properties.PropertyKey; -import com.gregtechceu.gtceu.api.data.chemical.material.properties.WireProperties; import com.gregtechceu.gtceu.api.data.chemical.material.stack.UnificationEntry; import com.gregtechceu.gtceu.api.data.tag.TagPrefix; import com.gregtechceu.gtceu.common.data.GTMaterials; @@ -12,8 +11,7 @@ import net.minecraft.data.recipes.FinishedRecipe; -import com.google.common.collect.ImmutableMap; -import org.apache.commons.lang3.ArrayUtils; +import org.jetbrains.annotations.NotNull; import java.util.Map; import java.util.function.Consumer; @@ -21,66 +19,80 @@ import static com.gregtechceu.gtceu.api.data.tag.TagPrefix.*; import static com.gregtechceu.gtceu.common.data.GTRecipeTypes.PACKER_RECIPES; -public class WireCombiningHandler { +public final class WireCombiningHandler { private static final TagPrefix[] WIRE_DOUBLING_ORDER = new TagPrefix[] { wireGtSingle, wireGtDouble, wireGtQuadruple, wireGtOctal, wireGtHex }; - private static final Map cableToWireMap = ImmutableMap.of( + private static final Map cableToWireMap = Map.of( cableGtSingle, wireGtSingle, cableGtDouble, wireGtDouble, cableGtQuadruple, wireGtQuadruple, cableGtOctal, wireGtOctal, cableGtHex, wireGtHex); - public static void init(Consumer provider) { + private WireCombiningHandler() {} + + public static void run(@NotNull Consumer provider, @NotNull Material material) { // Generate Wire Packer/Unpacker recipes - wireGtSingle.executeHandler(provider, PropertyKey.WIRE, WireCombiningHandler::processWireCompression); + processWireCompression(provider, material); // Generate manual recipes for combining Wires/Cables - for (TagPrefix wirePrefix : WIRE_DOUBLING_ORDER) { - wirePrefix.executeHandler(provider, PropertyKey.WIRE, WireCombiningHandler::generateWireCombiningRecipe); + for (int i = 0; i < WIRE_DOUBLING_ORDER.length; i++) { + generateWireCombiningRecipe(provider, i, material); } // Generate Cable -> Wire recipes in the unpacker - for (TagPrefix cablePrefix : cableToWireMap.keySet()) { - cablePrefix.executeHandler(provider, PropertyKey.WIRE, WireCombiningHandler::processCableStripping); + for (TagPrefix prefix : cableToWireMap.keySet()) { + processCableStripping(provider, prefix, material); } } - private static void generateWireCombiningRecipe(TagPrefix wirePrefix, Material material, WireProperties property, - Consumer provider) { - int wireIndex = ArrayUtils.indexOf(WIRE_DOUBLING_ORDER, wirePrefix); + private static void generateWireCombiningRecipe(@NotNull Consumer provider, int index, + @NotNull Material material) { + TagPrefix prefix = WIRE_DOUBLING_ORDER[index]; + if (!prefix.shouldGenerateRecipes(material)) { + return; + } + if (!material.hasProperty(PropertyKey.WIRE)) { + return; + } - if (wireIndex < WIRE_DOUBLING_ORDER.length - 1) { + if (index < WIRE_DOUBLING_ORDER.length - 1) { VanillaRecipeHelper.addShapelessRecipe(provider, - String.format("%s_wire_%s_doubling", material.getName(), wirePrefix), - ChemicalHelper.get(WIRE_DOUBLING_ORDER[wireIndex + 1], material), - new UnificationEntry(wirePrefix, material), - new UnificationEntry(wirePrefix, material)); + String.format("%s_wire_%s_doubling", material.getName(), prefix), + ChemicalHelper.get(WIRE_DOUBLING_ORDER[index + 1], material), + new UnificationEntry(prefix, material), + new UnificationEntry(prefix, material)); } - if (wireIndex > 0) { + if (index > 0) { VanillaRecipeHelper.addShapelessRecipe(provider, - String.format("%s_wire_%s_splitting", material.getName(), wirePrefix), - ChemicalHelper.get(WIRE_DOUBLING_ORDER[wireIndex - 1], material, 2), - new UnificationEntry(wirePrefix, material)); + String.format("%s_wire_%s_splitting", material.getName(), prefix), + ChemicalHelper.get(WIRE_DOUBLING_ORDER[index - 1], material, 2), + new UnificationEntry(prefix, material)); } - if (wireIndex < 3) { + if (index < WIRE_DOUBLING_ORDER.length - 2) { VanillaRecipeHelper.addShapelessRecipe(provider, - String.format("%s_wire_%s_quadrupling", material.getName(), wirePrefix), - ChemicalHelper.get(WIRE_DOUBLING_ORDER[wireIndex + 2], material), - new UnificationEntry(wirePrefix, material), - new UnificationEntry(wirePrefix, material), - new UnificationEntry(wirePrefix, material), - new UnificationEntry(wirePrefix, material)); + String.format("%s_wire_%s_quadrupling", material.getName(), prefix), + ChemicalHelper.get(WIRE_DOUBLING_ORDER[index + 2], material), + new UnificationEntry(prefix, material), + new UnificationEntry(prefix, material), + new UnificationEntry(prefix, material), + new UnificationEntry(prefix, material)); } } - private static void processWireCompression(TagPrefix prefix, Material material, WireProperties property, - Consumer provider) { + private static void processWireCompression(@NotNull Consumer provider, @NotNull Material material) { + if (!wireGtSingle.shouldGenerateRecipes(material)) { + return; + } + if (!material.hasProperty(PropertyKey.WIRE)) { + return; + } + for (int startTier = 0; startTier < 4; startTier++) { for (int i = 1; i < 5 - startTier; i++) { PACKER_RECIPES.recipeBuilder("pack_" + material.getName() + "_wires_" + i + "_" + startTier) @@ -100,8 +112,15 @@ private static void processWireCompression(TagPrefix prefix, Material material, } } - private static void processCableStripping(TagPrefix prefix, Material material, WireProperties property, - Consumer provider) { + private static void processCableStripping(@NotNull Consumer provider, @NotNull TagPrefix prefix, + @NotNull Material material) { + if (!prefix.shouldGenerateRecipes(material)) { + return; + } + if (!material.hasProperty(PropertyKey.WIRE)) { + return; + } + PACKER_RECIPES.recipeBuilder("strip_" + material.getName() + "_" + prefix.name) .inputItems(prefix, material) .outputItems(cableToWireMap.get(prefix), material) diff --git a/src/main/java/com/gregtechceu/gtceu/data/recipe/generated/WireRecipeHandler.java b/src/main/java/com/gregtechceu/gtceu/data/recipe/generated/WireRecipeHandler.java index ba6b4084bb..6922ea945a 100644 --- a/src/main/java/com/gregtechceu/gtceu/data/recipe/generated/WireRecipeHandler.java +++ b/src/main/java/com/gregtechceu/gtceu/data/recipe/generated/WireRecipeHandler.java @@ -14,9 +14,10 @@ import net.minecraft.data.recipes.FinishedRecipe; -import com.google.common.collect.ImmutableMap; +import it.unimi.dsi.fastutil.objects.Reference2IntMap; +import it.unimi.dsi.fastutil.objects.Reference2IntOpenHashMap; +import org.jetbrains.annotations.NotNull; -import java.util.Map; import java.util.function.Consumer; import static com.gregtechceu.gtceu.api.GTValues.*; @@ -44,35 +45,47 @@ *
* - Material Foil: At IV, an extra foil of the Material is needed to make the cable with SiR. */ -public class WireRecipeHandler { - - private static final Map INSULATION_AMOUNT = ImmutableMap.of( - cableGtSingle, 1, - cableGtDouble, 1, - cableGtQuadruple, 2, - cableGtOctal, 3, - cableGtHex, 5); +public final class WireRecipeHandler { + + private static final Reference2IntMap INSULATION_AMOUNT = new Reference2IntOpenHashMap<>(); + static { + INSULATION_AMOUNT.put(cableGtSingle, 1); + INSULATION_AMOUNT.put(cableGtDouble, 1); + INSULATION_AMOUNT.put(cableGtQuadruple, 2); + INSULATION_AMOUNT.put(cableGtOctal, 3); + INSULATION_AMOUNT.put(cableGtHex, 5); + } private static final TagPrefix[] wireSizes = { wireGtDouble, wireGtQuadruple, wireGtOctal, wireGtHex }; - public static void init(Consumer provider) { + private WireRecipeHandler() {} + + public static void run(@NotNull Consumer provider, @NotNull Material material) { + WireProperties property = material.getProperty(PropertyKey.WIRE); + if (property == null) { + return; + } + // Generate Wire creation recipes (Wiremill, Extruder, Wire Cutters) // Wiremill: Ingot -> 1x, 2x, 4x, 8x, 16x, Fine // Wiremill: 1x Wire -> Fine // Extruder: Ingot -> 1x Wire // Wire Cutter: Plate -> 1x Wire - wireGtSingle.executeHandler(provider, PropertyKey.WIRE, WireRecipeHandler::processWires); + processWires(provider, material); // Generate Cable Covering Recipes - wireGtSingle.executeHandler(provider, PropertyKey.WIRE, WireRecipeHandler::generateCableCovering); - wireGtDouble.executeHandler(provider, PropertyKey.WIRE, WireRecipeHandler::generateCableCovering); - wireGtQuadruple.executeHandler(provider, PropertyKey.WIRE, WireRecipeHandler::generateCableCovering); - wireGtOctal.executeHandler(provider, PropertyKey.WIRE, WireRecipeHandler::generateCableCovering); - wireGtHex.executeHandler(provider, PropertyKey.WIRE, WireRecipeHandler::generateCableCovering); + generateCableCovering(provider, property, wireGtSingle, material); + generateCableCovering(provider, property, wireGtDouble, material); + generateCableCovering(provider, property, wireGtQuadruple, material); + generateCableCovering(provider, property, wireGtOctal, material); + generateCableCovering(provider, property, wireGtHex, material); } - public static void processWires(TagPrefix wirePrefix, Material material, WireProperties property, - Consumer provider) { + private static void processWires(@NotNull Consumer provider, @NotNull Material material) { + if (!wireGtSingle.shouldGenerateRecipes(material)) { + return; + } + TagPrefix prefix = material.hasProperty(PropertyKey.INGOT) ? ingot : material.hasProperty(PropertyKey.GEM) ? gem : dust; @@ -120,27 +133,32 @@ public static void processWires(TagPrefix wirePrefix, Material material, WirePro } } - public static void generateCableCovering(TagPrefix wirePrefix, Material material, WireProperties property, - Consumer provider) { + private static void generateCableCovering(@NotNull Consumer provider, + @NotNull WireProperties property, + @NotNull TagPrefix prefix, @NotNull Material material) { + if (!prefix.shouldGenerateRecipes(material)) { + return; + } + // Superconductors have no Cables, so exit early if (property.isSuperconductor()) return; - int cableAmount = (int) (wirePrefix.getMaterialAmount(material) * 2 / M); - TagPrefix cablePrefix = TagPrefix.get("cable" + wirePrefix.name().substring(4)); + int cableAmount = (int) (prefix.getMaterialAmount(material) * 2 / M); + TagPrefix cablePrefix = TagPrefix.get("cable" + prefix.name().substring(4)); int voltageTier = GTUtil.getTierByVoltage(property.getVoltage()); - int insulationAmount = INSULATION_AMOUNT.get(cablePrefix); + int insulationAmount = INSULATION_AMOUNT.getInt(cablePrefix); // Generate hand-crafting recipes for ULV and LV cables if (voltageTier <= LV) { - generateManualRecipe(wirePrefix, material, cablePrefix, cableAmount, provider); + generateManualRecipe(provider, prefix, cablePrefix, cableAmount, material); } // Rubber Recipe (ULV-EV cables) if (voltageTier <= EV) { GTRecipeBuilder builder = ASSEMBLER_RECIPES - .recipeBuilder("cover_" + material.getName() + "_" + wirePrefix + "_rubber") + .recipeBuilder("cover_" + material.getName() + "_" + prefix + "_rubber") .EUt(VA[ULV]).duration(100) - .inputItems(wirePrefix, material) + .inputItems(prefix, material) .outputItems(cablePrefix, material) .inputFluids(Rubber.getFluid(L * insulationAmount)); @@ -152,9 +170,9 @@ public static void generateCableCovering(TagPrefix wirePrefix, Material material // Silicone Rubber Recipe (all cables) GTRecipeBuilder builder = ASSEMBLER_RECIPES - .recipeBuilder("cover_" + material.getName() + "_" + wirePrefix + "_silicone") + .recipeBuilder("cover_" + material.getName() + "_" + prefix + "_silicone") .EUt(VA[ULV]).duration(100) - .inputItems(wirePrefix, material) + .inputItems(prefix, material) .outputItems(cablePrefix, material); // Apply a Polyphenylene Sulfate Foil if LuV or above. @@ -172,9 +190,9 @@ public static void generateCableCovering(TagPrefix wirePrefix, Material material // Styrene Butadiene Rubber Recipe (all cables) builder = ASSEMBLER_RECIPES - .recipeBuilder("cover_" + material.getName() + "_" + wirePrefix + "_styrene_butadiene") + .recipeBuilder("cover_" + material.getName() + "_" + prefix + "_styrene_butadiene") .EUt(VA[ULV]).duration(100) - .inputItems(wirePrefix, material) + .inputItems(prefix, material) .outputItems(cablePrefix, material); // Apply a Polyphenylene Sulfate Foil if LuV or above. @@ -191,9 +209,10 @@ public static void generateCableCovering(TagPrefix wirePrefix, Material material .save(provider); } - private static void generateManualRecipe(TagPrefix wirePrefix, Material material, TagPrefix cablePrefix, - int cableAmount, Consumer provider) { - int insulationAmount = INSULATION_AMOUNT.get(cablePrefix); + private static void generateManualRecipe(@NotNull Consumer provider, @NotNull TagPrefix wirePrefix, + @NotNull TagPrefix cablePrefix, int cableAmount, + @NotNull Material material) { + int insulationAmount = INSULATION_AMOUNT.getInt(cablePrefix); Object[] ingredients = new Object[insulationAmount + 1]; ingredients[0] = new UnificationEntry(wirePrefix, material); for (int i = 1; i <= insulationAmount; i++) { @@ -211,7 +230,7 @@ private static void generateManualRecipe(TagPrefix wirePrefix, Material material .save(provider); } - private static int getVoltageMultiplier(Material material) { + private static int getVoltageMultiplier(@NotNull Material material) { return material.getBlastTemperature() >= 2800 ? VA[LV] : VA[ULV]; } } diff --git a/src/main/java/com/gregtechceu/gtceu/data/recipe/misc/CraftingRecipeLoader.java b/src/main/java/com/gregtechceu/gtceu/data/recipe/misc/CraftingRecipeLoader.java index 72fdb6ba40..458a1047f5 100644 --- a/src/main/java/com/gregtechceu/gtceu/data/recipe/misc/CraftingRecipeLoader.java +++ b/src/main/java/com/gregtechceu/gtceu/data/recipe/misc/CraftingRecipeLoader.java @@ -1,11 +1,13 @@ package com.gregtechceu.gtceu.data.recipe.misc; import com.gregtechceu.gtceu.api.data.chemical.ChemicalHelper; +import com.gregtechceu.gtceu.api.data.chemical.material.Material; import com.gregtechceu.gtceu.api.data.chemical.material.stack.UnificationEntry; import com.gregtechceu.gtceu.api.recipe.FacadeCoverRecipe; import com.gregtechceu.gtceu.api.recipe.ingredient.FluidContainerIngredient; import com.gregtechceu.gtceu.common.data.GTBlocks; import com.gregtechceu.gtceu.common.data.GTItems; +import com.gregtechceu.gtceu.common.pipelike.duct.DuctPipeType; import com.gregtechceu.gtceu.data.recipe.CustomTags; import com.gregtechceu.gtceu.data.recipe.VanillaRecipeHelper; @@ -17,6 +19,8 @@ import net.minecraft.world.level.block.Blocks; import net.minecraftforge.common.Tags; +import org.jetbrains.annotations.NotNull; + import java.util.function.Consumer; import static com.gregtechceu.gtceu.api.data.tag.TagPrefix.*; @@ -45,6 +49,10 @@ public static void init(Consumer provider) { ChemicalHelper.get(pipeLargeFluid, TreatedWood), "WWW", "s r", "WWW", 'W', GTBlocks.TREATED_WOOD_PLANK.asStack()); + addDuctRecipes(provider, Steel, 2); + addDuctRecipes(provider, StainlessSteel, 4); + addDuctRecipes(provider, TungstenSteel, 8); + VanillaRecipeHelper.addShapelessRecipe(provider, "programmed_circuit", PROGRAMMED_CIRCUIT.asStack(), CustomTags.LV_CIRCUITS); @@ -332,6 +340,22 @@ public static void init(Consumer provider) { SpecialRecipeBuilder.special(FacadeCoverRecipe.SERIALIZER).save(provider, "gtceu:crafting/facade_cover"); } + private static void addDuctRecipes(@NotNull Consumer provider, @NotNull Material material, + int outputAmount) { + VanillaRecipeHelper.addShapedRecipe(provider, "small_duct_%s".formatted(material.getName()), + GTBlocks.DUCT_PIPES[DuctPipeType.SMALL.ordinal()].asStack(outputAmount * 2), "w", "X", "h", + 'X', new UnificationEntry(plate, material)); + VanillaRecipeHelper.addShapedRecipe(provider, "medium_duct_%s".formatted(material.getName()), + GTBlocks.DUCT_PIPES[DuctPipeType.NORMAL.ordinal()].asStack(outputAmount), " X ", "wXh", " X ", + 'X', new UnificationEntry(plate, material)); + VanillaRecipeHelper.addShapedRecipe(provider, "large_duct_%s".formatted(material.getName()), + GTBlocks.DUCT_PIPES[DuctPipeType.LARGE.ordinal()].asStack(outputAmount), "XwX", "X X", "XhX", + 'X', new UnificationEntry(plate, material)); + VanillaRecipeHelper.addShapedRecipe(provider, "huge_duct_%s".formatted(material.getName()), + GTBlocks.DUCT_PIPES[DuctPipeType.HUGE.ordinal()].asStack(outputAmount), "XwX", "X X", "XhX", + 'X', new UnificationEntry(plateDouble, material)); + } + // private static void registerFacadeRecipe(Consumer provider, Material material, int facadeAmount) // { // OreIngredient ingredient = new OreIngredient(new UnificationEntry(plate, material).toString()); diff --git a/src/main/java/com/gregtechceu/gtceu/data/recipe/misc/CustomToolRecipes.java b/src/main/java/com/gregtechceu/gtceu/data/recipe/misc/CustomToolRecipes.java new file mode 100644 index 0000000000..50539814a5 --- /dev/null +++ b/src/main/java/com/gregtechceu/gtceu/data/recipe/misc/CustomToolRecipes.java @@ -0,0 +1,290 @@ +package com.gregtechceu.gtceu.data.recipe.misc; + +import com.gregtechceu.gtceu.api.GTValues; +import com.gregtechceu.gtceu.api.capability.GTCapabilityHelper; +import com.gregtechceu.gtceu.api.data.chemical.material.Material; +import com.gregtechceu.gtceu.api.data.chemical.material.properties.PropertyKey; +import com.gregtechceu.gtceu.api.data.chemical.material.stack.UnificationEntry; +import com.gregtechceu.gtceu.api.data.tag.TagPrefix; +import com.gregtechceu.gtceu.api.item.tool.GTToolType; +import com.gregtechceu.gtceu.api.item.tool.ToolHelper; +import com.gregtechceu.gtceu.api.recipe.ToolHeadReplaceRecipe; +import com.gregtechceu.gtceu.common.data.GTItems; +import com.gregtechceu.gtceu.common.data.GTMaterials; +import com.gregtechceu.gtceu.data.recipe.CustomTags; +import com.gregtechceu.gtceu.data.recipe.VanillaRecipeHelper; +import com.gregtechceu.gtceu.utils.ToolItemHelper; + +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.data.recipes.FinishedRecipe; +import net.minecraft.data.recipes.SpecialRecipeBuilder; +import net.minecraft.tags.ItemTags; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import net.minecraft.world.item.crafting.Ingredient; +import net.minecraft.world.level.block.Blocks; + +import com.google.common.collect.ImmutableList; +import com.tterrag.registrate.util.entry.ItemEntry; +import it.unimi.dsi.fastutil.ints.Int2ReferenceArrayMap; +import it.unimi.dsi.fastutil.ints.Int2ReferenceMap; +import org.jetbrains.annotations.NotNull; + +import java.util.Collections; +import java.util.List; +import java.util.function.Consumer; + +import static com.gregtechceu.gtceu.api.GTValues.*; +import static com.gregtechceu.gtceu.api.GTValues.LuV; +import static com.gregtechceu.gtceu.api.data.tag.TagPrefix.*; +import static com.gregtechceu.gtceu.data.recipe.generated.ToolRecipeHandler.*; + +public final class CustomToolRecipes { + + private static final Int2ReferenceMap> motorItems = new Int2ReferenceArrayMap<>(); + private static final Int2ReferenceMap baseMaterials = new Int2ReferenceArrayMap<>(); + private static final Int2ReferenceMap>> batteryItems = new Int2ReferenceArrayMap<>(); + + private CustomToolRecipes() {} + + public static void init(@NotNull Consumer provider) { + initializeGTItems(); + registerPowerUnitRecipes(provider); + registerCustomToolRecipes(provider); + } + + private static void initializeGTItems() { + motorItems.put(GTValues.LV, GTItems.ELECTRIC_MOTOR_LV); + motorItems.put(GTValues.MV, GTItems.ELECTRIC_MOTOR_MV); + motorItems.put(GTValues.HV, GTItems.ELECTRIC_MOTOR_HV); + motorItems.put(GTValues.EV, GTItems.ELECTRIC_MOTOR_EV); + motorItems.put(GTValues.IV, GTItems.ELECTRIC_MOTOR_IV); + + baseMaterials.put(GTValues.LV, GTMaterials.Steel); + baseMaterials.put(GTValues.MV, GTMaterials.Aluminium); + baseMaterials.put(GTValues.HV, GTMaterials.StainlessSteel); + baseMaterials.put(GTValues.EV, GTMaterials.Titanium); + baseMaterials.put(GTValues.IV, GTMaterials.TungstenSteel); + + batteryItems.put(GTValues.ULV, Collections.singletonList(GTItems.BATTERY_ULV_TANTALUM)); + batteryItems.put(GTValues.LV, + ImmutableList.of(GTItems.BATTERY_LV_LITHIUM, GTItems.BATTERY_LV_CADMIUM, GTItems.BATTERY_LV_SODIUM)); + batteryItems.put(GTValues.MV, + ImmutableList.of(GTItems.BATTERY_MV_LITHIUM, GTItems.BATTERY_MV_CADMIUM, GTItems.BATTERY_MV_SODIUM)); + batteryItems.put(GTValues.HV, ImmutableList.of(GTItems.BATTERY_HV_LITHIUM, GTItems.BATTERY_HV_CADMIUM, + GTItems.BATTERY_HV_SODIUM, GTItems.ENERGIUM_CRYSTAL)); + batteryItems.put(GTValues.EV, ImmutableList.of(GTItems.BATTERY_EV_VANADIUM, GTItems.LAPOTRON_CRYSTAL)); + batteryItems.put(GTValues.IV, ImmutableList.of(GTItems.BATTERY_IV_VANADIUM, GTItems.ENERGY_LAPOTRONIC_ORB)); + batteryItems.put(GTValues.LuV, + ImmutableList.of(GTItems.BATTERY_LuV_VANADIUM, GTItems.ENERGY_LAPOTRONIC_ORB_CLUSTER)); + batteryItems.put(GTValues.ZPM, ImmutableList.of(GTItems.BATTERY_ZPM_NAQUADRIA, GTItems.ENERGY_MODULE)); + batteryItems.put(GTValues.UV, ImmutableList.of(GTItems.BATTERY_UV_NAQUADRIA, GTItems.ENERGY_CLUSTER)); + + ToolHeadReplaceRecipe.setToolHeadForTool(toolHeadDrill, GTToolType.DRILL_LV); + ToolHeadReplaceRecipe.setToolHeadForTool(toolHeadDrill, GTToolType.DRILL_MV); + ToolHeadReplaceRecipe.setToolHeadForTool(toolHeadDrill, GTToolType.DRILL_HV); + ToolHeadReplaceRecipe.setToolHeadForTool(toolHeadDrill, GTToolType.DRILL_EV); + ToolHeadReplaceRecipe.setToolHeadForTool(toolHeadDrill, GTToolType.DRILL_IV); + ToolHeadReplaceRecipe.setToolHeadForTool(toolHeadChainsaw, GTToolType.CHAINSAW_LV); + ToolHeadReplaceRecipe.setToolHeadForTool(toolHeadWrench, GTToolType.WRENCH_LV); + ToolHeadReplaceRecipe.setToolHeadForTool(toolHeadWrench, GTToolType.WRENCH_HV); + ToolHeadReplaceRecipe.setToolHeadForTool(toolHeadWrench, GTToolType.WRENCH_IV); + ToolHeadReplaceRecipe.setToolHeadForTool(toolHeadBuzzSaw, GTToolType.BUZZSAW); + ToolHeadReplaceRecipe.setToolHeadForTool(toolHeadScrewdriver, GTToolType.SCREWDRIVER_LV); + ToolHeadReplaceRecipe.setToolHeadForTool(toolHeadWireCutter, GTToolType.WIRE_CUTTER_LV); + ToolHeadReplaceRecipe.setToolHeadForTool(toolHeadWireCutter, GTToolType.WIRE_CUTTER_HV); + ToolHeadReplaceRecipe.setToolHeadForTool(toolHeadWireCutter, GTToolType.WIRE_CUTTER_IV); + } + + private static void registerPowerUnitRecipes(@NotNull Consumer provider) { + for (int tier : powerUnitItems.keySet()) { + List> tieredBatteryItems = batteryItems.get(tier); + for (ItemEntry batteryItem : tieredBatteryItems) { + if (powerUnitItems.get(tier) != null) { + ItemStack batteryStack = batteryItem.asStack(); + long maxCharge = GTCapabilityHelper.getElectricItem(batteryStack).getMaxCharge(); + ItemStack powerUnitStack = ToolItemHelper.getMaxChargeOverrideStack(powerUnitItems.get(tier).get(), + maxCharge); + String recipeName = String.format("%s_%s", + BuiltInRegistries.ITEM.getKey(powerUnitItems.get(tier).get()).getPath(), + BuiltInRegistries.ITEM.getKey(batteryItem.get()).getPath()); + + VanillaRecipeHelper.addShapedEnergyTransferRecipe(provider, true, false, true, recipeName, + Ingredient.of(batteryStack), powerUnitStack, + "S d", "GMG", "PBP", + 'M', motorItems.get(tier).asStack(), + 'S', new UnificationEntry(screw, baseMaterials.get(tier)), + 'P', new UnificationEntry(plate, baseMaterials.get(tier)), + 'G', new UnificationEntry(gearSmall, baseMaterials.get(tier)), + 'B', batteryStack); + } + } + } + } + + private static void registerCustomToolRecipes(@NotNull Consumer provider) { + registerFlintToolRecipes(provider); + registerMortarRecipes(provider); + registerSoftToolRecipes(provider); + registerElectricRecipes(provider); + + SpecialRecipeBuilder.special(ToolHeadReplaceRecipe.SERIALIZER).save(provider, + "gtceu:crafting/replace_tool_head"); + } + + private static void registerFlintToolRecipes(@NotNull Consumer provider) { + final UnificationEntry flint = new UnificationEntry(TagPrefix.gem, GTMaterials.Flint); + final ItemStack stick = new ItemStack(Items.STICK); + + addToolRecipe(provider, GTMaterials.Flint, GTToolType.MORTAR, false, + " I ", "SIS", "SSS", + 'I', flint, + 'S', new ItemStack(Blocks.STONE)); + + addToolRecipe(provider, GTMaterials.Flint, GTToolType.SWORD, false, + "I", "I", "S", + 'I', flint, + 'S', stick); + + addToolRecipe(provider, GTMaterials.Flint, GTToolType.PICKAXE, false, + "III", " S ", " S ", + 'I', flint, + 'S', stick); + + addToolRecipe(provider, GTMaterials.Flint, GTToolType.SHOVEL, false, + "I", "S", "S", + 'I', flint, + 'S', stick); + + addToolRecipe(provider, GTMaterials.Flint, GTToolType.AXE, true, + "II", "IS", " S", + 'I', flint, + 'S', stick); + + addToolRecipe(provider, GTMaterials.Flint, GTToolType.HOE, true, + "II", " S", " S", + 'I', flint, + 'S', stick); + + addToolRecipe(provider, GTMaterials.Flint, GTToolType.KNIFE, false, + "I", "S", + 'I', flint, + 'S', stick); + } + + private static void registerMortarRecipes(@NotNull Consumer provider) { + for (Material material : new Material[] { + GTMaterials.Bronze, GTMaterials.Iron, GTMaterials.Invar, GTMaterials.Steel, + GTMaterials.DamascusSteel, GTMaterials.CobaltBrass, GTMaterials.WroughtIron }) { + + addToolRecipe(provider, material, GTToolType.MORTAR, false, + " I ", "SIS", "SSS", + 'I', + new UnificationEntry(material.hasProperty(PropertyKey.GEM) ? TagPrefix.gem : TagPrefix.ingot, + material), + 'S', new ItemStack(Blocks.STONE)); + } + } + + private static void registerSoftToolRecipes(@NotNull Consumer provider) { + final ItemStack stick = new ItemStack(Items.STICK); + + for (int i = 0; i < softMaterials.length; i++) { + Material material = softMaterials[i]; + + if (material.hasProperty(PropertyKey.WOOD)) { + // todo allow these 3 to be mirrored + VanillaRecipeHelper.addShapedRecipe(provider, String.format("soft_mallet_%s", material.getName()), + ToolHelper.get(GTToolType.SOFT_MALLET, material), + "II ", "IIS", "II ", + 'I', ItemTags.PLANKS, + 'S', stick); + } else { + VanillaRecipeHelper.addShapedRecipe(provider, String.format("soft_mallet_%s", material.getName()), + ToolHelper.get(GTToolType.SOFT_MALLET, material), + "II ", "IIS", "II ", + 'I', new UnificationEntry(TagPrefix.ingot, material), + 'S', stick); + + VanillaRecipeHelper.addShapedRecipe(provider, String.format("plunger_%s", material.getName()), + ToolHelper.getAndSetToolData(GTToolType.PLUNGER, material, 128 * (i << 1), 1, 4F, 0F), + "xPP", " SP", "S f", + 'P', new UnificationEntry(TagPrefix.plate, material), + 'S', rod); + } + } + } + + private static void registerElectricRecipes(@NotNull Consumer provider) { + for (ItemEntry batteryItem : batteryItems.get(LV)) { + VanillaRecipeHelper.addShapedEnergyTransferRecipe(provider, true, false, true, + "prospector_lv_" + batteryItem.getId().getPath(), + Ingredient.of(batteryItem), GTItems.PROSPECTOR_LV.asStack(), + "EPS", "CDC", "PBP", + 'E', GTItems.EMITTER_LV.asStack(), + 'P', new UnificationEntry(plate, GTMaterials.Steel), + 'S', GTItems.SENSOR_LV.asStack(), + 'D', new UnificationEntry(plate, GTMaterials.Glass), + 'C', CustomTags.LV_CIRCUITS, + 'B', batteryItem.asStack()); + + VanillaRecipeHelper.addShapedEnergyTransferRecipe(provider, true, false, true, + "lv_magnet_" + batteryItem.getId().getPath(), + Ingredient.of(batteryItem), GTItems.ITEM_MAGNET_LV.asStack(), + "MwM", "MBM", "CPC", + 'M', new UnificationEntry(rod, GTMaterials.SteelMagnetic), + 'P', new UnificationEntry(plate, GTMaterials.Steel), + 'C', new UnificationEntry(cableGtSingle, GTMaterials.Tin), + 'B', batteryItem.asStack()); + } + + for (ItemEntry batteryItem : batteryItems.get(MV)) { + VanillaRecipeHelper.addShapedEnergyTransferRecipe(provider, true, false, true, + "portable_scanner_" + batteryItem.getId().getPath(), + Ingredient.of(batteryItem), GTItems.PORTABLE_SCANNER.asStack(), + "EPS", "CDC", "PBP", + 'E', GTItems.EMITTER_MV.asStack(), + 'P', new UnificationEntry(plate, GTMaterials.Aluminium), + 'S', GTItems.SENSOR_MV.asStack(), + 'D', GTItems.COVER_SCREEN.asStack(), + 'C', CustomTags.MV_CIRCUITS, + 'B', batteryItem.asStack()); + } + + for (ItemEntry batteryItem : batteryItems.get(HV)) { + VanillaRecipeHelper.addShapedEnergyTransferRecipe(provider, true, false, true, + "prospector_hv_" + batteryItem.getId().getPath(), + Ingredient.of(batteryItem), GTItems.PROSPECTOR_HV.asStack(), + "EPS", "CDC", "PBP", + 'E', GTItems.EMITTER_HV.asStack(), + 'P', new UnificationEntry(plate, GTMaterials.StainlessSteel), + 'S', GTItems.SENSOR_HV.asStack(), + 'D', GTItems.COVER_SCREEN.asStack(), + 'C', CustomTags.HV_CIRCUITS, + 'B', batteryItem.asStack()); + + VanillaRecipeHelper.addShapedEnergyTransferRecipe(provider, true, false, true, + "hv_magnet_" + batteryItem.getId().getPath(), + Ingredient.of(batteryItem), GTItems.ITEM_MAGNET_HV.asStack(), + "MwM", "MBM", "CPC", + 'M', new UnificationEntry(rod, GTMaterials.NeodymiumMagnetic), + 'P', new UnificationEntry(plate, GTMaterials.StainlessSteel), + 'C', new UnificationEntry(cableGtSingle, GTMaterials.Gold), + 'B', batteryItem.asStack()); + } + + for (ItemEntry batteryItem : batteryItems.get(LuV)) { + VanillaRecipeHelper.addShapedEnergyTransferRecipe(provider, true, false, true, + "prospector_luv_" + batteryItem.getId().getPath(), + Ingredient.of(batteryItem), GTItems.PROSPECTOR_LuV.asStack(), + "EPS", "CDC", "PBP", + 'E', GTItems.EMITTER_LuV.asStack(), + 'P', new UnificationEntry(plate, GTMaterials.RhodiumPlatedPalladium), + 'S', GTItems.SENSOR_LuV.asStack(), + 'D', GTItems.COVER_SCREEN.asStack(), + 'C', CustomTags.LuV_CIRCUITS, + 'B', batteryItem.asStack()); + } + } +} diff --git a/src/main/java/com/gregtechceu/gtceu/data/recipe/misc/GCYMRecipes.java b/src/main/java/com/gregtechceu/gtceu/data/recipe/misc/GCYMRecipes.java index 3e945fb0fd..c00c63ce90 100644 --- a/src/main/java/com/gregtechceu/gtceu/data/recipe/misc/GCYMRecipes.java +++ b/src/main/java/com/gregtechceu/gtceu/data/recipe/misc/GCYMRecipes.java @@ -3,8 +3,6 @@ import com.gregtechceu.gtceu.api.GTValues; import com.gregtechceu.gtceu.api.data.chemical.ChemicalHelper; import com.gregtechceu.gtceu.api.data.chemical.material.Material; -import com.gregtechceu.gtceu.api.data.chemical.material.properties.AlloyBlastProperty; -import com.gregtechceu.gtceu.api.data.chemical.material.properties.PropertyKey; import com.gregtechceu.gtceu.api.data.chemical.material.stack.UnificationEntry; import com.gregtechceu.gtceu.api.data.tag.TagPrefix; import com.gregtechceu.gtceu.common.data.*; @@ -16,7 +14,6 @@ import net.minecraft.data.recipes.FinishedRecipe; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.util.function.Consumer; @@ -44,6 +41,8 @@ public static void init(Consumer provider) { private static void registerManualRecipes(Consumer provider) { registerPartsRecipes(provider); registerMultiblockControllerRecipes(provider); + registerFormulaic(provider); + registerManual(provider); // Recipes for graphene that don't get autogenerated GTRecipeTypes.EXTRUDER_RECIPES.recipeBuilder("graphene_to_foil") @@ -184,7 +183,6 @@ private static void registerPartsRecipes(Consumer provider) { private static void registerMachineRecipes(Consumer provider) { registerAssemblerRecipes(provider); registerMixerRecipes(provider); - registerBlastAlloyRecipes(provider); } private static void registerAssemblerRecipes(Consumer provider) { @@ -415,24 +413,4 @@ private static void registerTrinaryAlloy(@NotNull Material input1, int input1Amo .blastFurnaceTemp(output.getFluid().getFluidType().getTemperature()) .save(provider); } - - private static void registerBlastAlloyRecipes(Consumer provider) { - registerFormulaic(provider); - registerManual(provider); - ingot.executeHandler(provider, PropertyKey.ALLOY_BLAST, GCYMRecipes::generateAlloyBlastRecipes); - } - - /** - * Generates alloy blast recipes for a material - * - * @param material the material to generate for - * @param property the blast property of the material - */ - public static void generateAlloyBlastRecipes(@Nullable TagPrefix unused, @NotNull Material material, - @NotNull AlloyBlastProperty property, - @NotNull Consumer provider) { - if (material.hasProperty(PropertyKey.BLAST)) { - property.getRecipeProducer().produce(material, material.getProperty(PropertyKey.BLAST), provider); - } - } } diff --git a/src/main/java/com/gregtechceu/gtceu/data/recipe/misc/RecyclingRecipes.java b/src/main/java/com/gregtechceu/gtceu/data/recipe/misc/RecyclingRecipes.java index 8a3634bae6..3e2313dbd4 100644 --- a/src/main/java/com/gregtechceu/gtceu/data/recipe/misc/RecyclingRecipes.java +++ b/src/main/java/com/gregtechceu/gtceu/data/recipe/misc/RecyclingRecipes.java @@ -528,11 +528,11 @@ private static void splitStacks(List> list, Item UnificationEntry entry) { int amount = originalStack.getCount(); while (amount > 64) { - list.add(new Tuple<>(GTUtil.copyAmount(64, originalStack), + list.add(new Tuple<>(GTUtil.copy(64, originalStack), new MaterialStack(entry.material, entry.tagPrefix.getMaterialAmount(entry.material) * 64))); amount -= 64; } - list.add(new Tuple<>(GTUtil.copyAmount(amount, originalStack), + list.add(new Tuple<>(GTUtil.copy(amount, originalStack), new MaterialStack(entry.material, entry.tagPrefix.getMaterialAmount(entry.material) * amount))); } diff --git a/src/main/java/com/gregtechceu/gtceu/utils/GTUtil.java b/src/main/java/com/gregtechceu/gtceu/utils/GTUtil.java index 401acac5e0..6e5820f70d 100644 --- a/src/main/java/com/gregtechceu/gtceu/utils/GTUtil.java +++ b/src/main/java/com/gregtechceu/gtceu/utils/GTUtil.java @@ -227,42 +227,66 @@ public static byte getFloorTierByVoltage(long voltage) { return (byte) ((60 - Long.numberOfLeadingZeros(voltage)) >> 1); } + @Deprecated public static ItemStack copy(ItemStack... stacks) { for (ItemStack stack : stacks) if (!stack.isEmpty()) return stack.copy(); return ItemStack.EMPTY; } - public static ItemStack copyAmount(int amount, ItemStack... stacks) { - ItemStack stack = copy(stacks); - if (stack.isEmpty()) return ItemStack.EMPTY; - if (amount > 64) amount = 64; - else if (amount == -1) amount = 111; - else if (amount < 0) amount = 0; - stack.setCount(amount); - return stack; + /** + * Copies the ItemStack with new stack size. + * + * @param stack item stack for copying + * @return a copy of ItemStack, or {@link ItemStack#EMPTY} if the stack is empty + */ + public static @NotNull ItemStack copy(int newCount, @NotNull ItemStack stack) { + if (stack.isEmpty()) { + return ItemStack.EMPTY; + } + ItemStack copy = stack.copy(); + copy.setCount(newCount); + return copy; } - public static FluidStack copyAmount(int amount, FluidStack fluidStack) { - if (fluidStack == null) return null; - FluidStack stack = fluidStack.copy(); - stack.setAmount(amount); - return stack; + /** + * Copies first non-empty ItemStack from stacks. + * + * @param stacks list of candidates for copying + * @return a copy of ItemStack, or {@link ItemStack#EMPTY} if all the candidates are empty + * @throws IllegalArgumentException if {@code stacks} is empty + */ + public static @NotNull ItemStack copyFirst(@NotNull ItemStack @NotNull... stacks) { + if (stacks.length == 0) { + throw new IllegalArgumentException("Empty ItemStack candidates"); + } + for (ItemStack stack : stacks) { + if (!stack.isEmpty()) { + return stack.copy(); + } + } + return ItemStack.EMPTY; } - public static M selectItemInList(int index, M replacement, List list, Class minClass) { - if (list.isEmpty()) - return replacement; - - M maybeResult; - if (list.size() <= index) { - maybeResult = list.get(list.size() - 1); - } else if (index < 0) { - maybeResult = list.get(0); - } else maybeResult = list.get(index); - - if (maybeResult != null) return maybeResult; - return replacement; + /** + * Copies first non-empty ItemStack from stacks, with new stack size. + * + * @param stacks list of candidates for copying + * @return a copy of ItemStack, or {@link ItemStack#EMPTY} if all the candidates are empty + * @throws IllegalArgumentException if {@code stacks} is empty + */ + public static @NotNull ItemStack copyFirst(int newCount, @NotNull ItemStack @NotNull... stacks) { + if (stacks.length == 0) { + throw new IllegalArgumentException("Empty ItemStack candidates"); + } + for (ItemStack stack : stacks) { + if (!stack.isEmpty()) { + ItemStack copy = stack.copy(); + copy.setCount(newCount); + return copy; + } + } + return ItemStack.EMPTY; } public static M getItem(List list, int index, M replacement) {