Search in sources :

Example 1 with TagDifferencePresentCondition

use of slimeknights.tconstruct.library.json.TagDifferencePresentCondition in project TinkersConstruct by SlimeKnights.

the class ISmelteryRecipeHelper method oreMelting.

/**
 * Base logic for {@link  #metalMelting(Consumer, Fluid, String, boolean, String, boolean, IByproduct...)}
 * @param consumer    Recipe consumer
 * @param fluid       Fluid to melt into
 * @param amount      Amount to melt into
 * @param tagName     Input tag
 * @param factor      Melting factor
 * @param recipePath  Recipe output name
 * @param oreRate     Ore rate for boosting
 * @param isOptional  If true, recipe is optional
 * @param byproducts  List of byproduct options for this metal, first one that is present will be used
 */
default void oreMelting(Consumer<FinishedRecipe> consumer, Fluid fluid, int amount, String tagName, @Nullable Tag.Named<Item> size, float factor, String recipePath, boolean isOptional, OreRateType oreRate, float byproductScale, IByproduct... byproducts) {
    Consumer<FinishedRecipe> wrapped;
    Ingredient baseIngredient = Ingredient.of(getTag("forge", tagName));
    Ingredient ingredient;
    // not everyone sets size, so treat singular as the fallback, means we want anything in the tag that is not sparse or dense
    if (size == Tags.Items.ORE_RATES_SINGULAR) {
        ingredient = IngredientDifference.difference(baseIngredient, CompoundIngredient.from(Ingredient.of(Tags.Items.ORE_RATES_SPARSE), Ingredient.of(Tags.Items.ORE_RATES_DENSE)));
        wrapped = withCondition(consumer, new TagDifferencePresentCondition(new ResourceLocation("forge", tagName), Tags.Items.ORE_RATES_SPARSE.getName(), Tags.Items.ORE_RATES_DENSE.getName()));
    // size tag means we want an intersection between the tag and that size
    } else if (size != null) {
        ingredient = IngredientIntersection.intersection(baseIngredient, Ingredient.of(size));
        wrapped = withCondition(consumer, new TagIntersectionPresentCondition(new ResourceLocation("forge", tagName), size.getName()));
    // default only need it to be in the tag
    } else {
        ingredient = baseIngredient;
        wrapped = isOptional ? withCondition(consumer, tagCondition(tagName)) : consumer;
    }
    Supplier<MeltingRecipeBuilder> supplier = () -> MeltingRecipeBuilder.melting(ingredient, fluid, amount, factor).setOre(oreRate);
    ResourceLocation location = modResource(recipePath);
    // if no byproducts, just build directly
    if (byproducts.length == 0) {
        supplier.get().save(wrapped, location);
    // if first option is always present, only need that one
    } else if (byproducts[0].isAlwaysPresent()) {
        supplier.get().addByproduct(new FluidStack(byproducts[0].getFluid(), (int) (byproducts[0].getAmount() * byproductScale))).save(wrapped, location);
    } else {
        // multiple options, will need a conditonal recipe
        ConditionalRecipe.Builder builder = ConditionalRecipe.builder();
        boolean alwaysPresent = false;
        for (IByproduct byproduct : byproducts) {
            // found an always present byproduct? no need to tag and we are done
            alwaysPresent = byproduct.isAlwaysPresent();
            if (alwaysPresent) {
                builder.addCondition(TrueCondition.INSTANCE);
            } else {
                builder.addCondition(tagCondition("ingots/" + byproduct.getName()));
            }
            builder.addRecipe(supplier.get().addByproduct(new FluidStack(byproduct.getFluid(), (int) (byproduct.getAmount() * byproductScale)))::save);
            if (alwaysPresent) {
                break;
            }
        }
        // not always present? add a recipe with no byproducts as a final fallback
        if (!alwaysPresent) {
            builder.addCondition(TrueCondition.INSTANCE);
            builder.addRecipe(supplier.get()::save);
        }
        builder.build(wrapped, location);
    }
}
Also used : TagDifferencePresentCondition(slimeknights.tconstruct.library.json.TagDifferencePresentCondition) FinishedRecipe(net.minecraft.data.recipes.FinishedRecipe) Ingredient(net.minecraft.world.item.crafting.Ingredient) CompoundIngredient(slimeknights.mantle.recipe.data.CompoundIngredient) FluidStack(net.minecraftforge.fluids.FluidStack) ResourceLocation(net.minecraft.resources.ResourceLocation) MeltingRecipeBuilder(slimeknights.tconstruct.library.recipe.melting.MeltingRecipeBuilder) ItemCastingRecipeBuilder(slimeknights.tconstruct.library.recipe.casting.ItemCastingRecipeBuilder) TagIntersectionPresentCondition(slimeknights.tconstruct.library.json.TagIntersectionPresentCondition) MeltingRecipeBuilder(slimeknights.tconstruct.library.recipe.melting.MeltingRecipeBuilder)

Aggregations

FinishedRecipe (net.minecraft.data.recipes.FinishedRecipe)1 ResourceLocation (net.minecraft.resources.ResourceLocation)1 Ingredient (net.minecraft.world.item.crafting.Ingredient)1 FluidStack (net.minecraftforge.fluids.FluidStack)1 CompoundIngredient (slimeknights.mantle.recipe.data.CompoundIngredient)1 TagDifferencePresentCondition (slimeknights.tconstruct.library.json.TagDifferencePresentCondition)1 TagIntersectionPresentCondition (slimeknights.tconstruct.library.json.TagIntersectionPresentCondition)1 ItemCastingRecipeBuilder (slimeknights.tconstruct.library.recipe.casting.ItemCastingRecipeBuilder)1 MeltingRecipeBuilder (slimeknights.tconstruct.library.recipe.melting.MeltingRecipeBuilder)1