Search in sources :

Example 6 with FluidStackIngredient

use of mekanism.api.recipes.inputs.FluidStackIngredient in project Mekanism by mekanism.

the class FluidInputCache method mapInputs.

@Override
public boolean mapInputs(RECIPE recipe, FluidStackIngredient inputIngredient) {
    if (inputIngredient instanceof FluidStackIngredient.Single) {
        HashedFluid input = HashedFluid.create(((FluidStackIngredient.Single) inputIngredient).getInputRaw());
        addNbtInputCache(input, recipe);
    } else if (inputIngredient instanceof FluidStackIngredient.Tagged) {
        for (Fluid input : ((FluidStackIngredient.Tagged) inputIngredient).getRawInput()) {
            addInputCache(input, recipe);
        }
    } else if (inputIngredient instanceof FluidStackIngredient.Multi) {
        return ((FluidStackIngredient.Multi) inputIngredient).forEachIngredient(ingredient -> mapInputs(recipe, ingredient));
    } else {
        // but if it does add it as a fallback
        return true;
    }
    return false;
}
Also used : FluidStackIngredient(mekanism.api.recipes.inputs.FluidStackIngredient) HashedFluid(mekanism.common.lib.HashedFluid) Fluid(net.minecraft.fluid.Fluid) HashedFluid(mekanism.common.lib.HashedFluid)

Example 7 with FluidStackIngredient

use of mekanism.api.recipes.inputs.FluidStackIngredient in project Mekanism by mekanism.

the class MekanismRecipeHandler method convertIngredient.

private String convertIngredient(FluidStackIngredient ingredient) {
    if (ingredient instanceof FluidStackIngredient.Single) {
        JsonObject serialized = ingredient.serialize().getAsJsonObject();
        // Note: Handled via implicit casts
        return new MCFluidStack(SerializerHelper.deserializeFluid(serialized)).getCommandString();
    } else if (ingredient instanceof FluidStackIngredient.Tagged) {
        JsonObject serialized = ingredient.serialize().getAsJsonObject();
        // Note: Handled via implicit casts
        return getTagWithExplicitAmount(TagManagerFluid.INSTANCE.getTag(serialized.get(JsonConstants.TAG).getAsString()), serialized.getAsJsonPrimitive(JsonConstants.AMOUNT).getAsInt());
    } else if (ingredient instanceof FluidStackIngredient.Multi) {
        FluidStackIngredient.Multi multiIngredient = (FluidStackIngredient.Multi) ingredient;
        StringBuilder builder = new StringBuilder(CrTConstants.CLASS_FLUID_STACK_INGREDIENT + ".createMulti(");
        multiIngredient.forEachIngredient(i -> {
            builder.append(convertIngredient(i)).append(", ");
            return false;
        });
        // Remove trailing comma and space
        builder.setLength(builder.length() - 2);
        builder.append(")");
        return builder.toString();
    }
    return "Unimplemented fluidstack ingredient: " + ingredient;
}
Also used : FluidStackIngredient(mekanism.api.recipes.inputs.FluidStackIngredient) MCFluidStack(com.blamejared.crafttweaker.impl.fluid.MCFluidStack) JsonObject(com.google.gson.JsonObject)

Example 8 with FluidStackIngredient

use of mekanism.api.recipes.inputs.FluidStackIngredient in project Mekanism by mekanism.

the class ElectrolysisRecipeMapper method handleRecipe.

@Override
public boolean handleRecipe(IMappingCollector<NormalizedSimpleStack, Long> mapper, IRecipe<?> iRecipe, INSSFakeGroupManager groupManager) {
    if (!(iRecipe instanceof ElectrolysisRecipe)) {
        // Double check that we have a type of recipe we know how to handle
        return false;
    }
    boolean handled = false;
    ElectrolysisRecipe recipe = (ElectrolysisRecipe) iRecipe;
    FluidStackIngredient input = recipe.getInput();
    for (FluidStack representation : input.getRepresentations()) {
        Pair<@NonNull GasStack, @NonNull GasStack> output = recipe.getOutput(representation);
        GasStack leftOutput = output.getLeft();
        GasStack rightOutput = output.getRight();
        if (!leftOutput.isEmpty() && !rightOutput.isEmpty()) {
            NormalizedSimpleStack nssInput = NSSFluid.createFluid(representation);
            NormalizedSimpleStack nssLeftOutput = NSSGas.createGas(leftOutput);
            NormalizedSimpleStack nssRightOutput = NSSGas.createGas(rightOutput);
            // Add trying to calculate left output (using it as if we needed negative of right output)
            IngredientHelper ingredientHelper = new IngredientHelper(mapper);
            ingredientHelper.put(nssInput, representation.getAmount());
            ingredientHelper.put(nssRightOutput, -rightOutput.getAmount());
            if (ingredientHelper.addAsConversion(nssLeftOutput, leftOutput.getAmount())) {
                handled = true;
            }
            // Add trying to calculate right output (using it as if we needed negative of left output)
            ingredientHelper.resetHelper();
            ingredientHelper.put(nssInput, representation.getAmount());
            ingredientHelper.put(nssLeftOutput, -leftOutput.getAmount());
            if (ingredientHelper.addAsConversion(nssRightOutput, rightOutput.getAmount())) {
                handled = true;
            }
        }
    }
    return handled;
}
Also used : NormalizedSimpleStack(moze_intel.projecte.api.nss.NormalizedSimpleStack) FluidStackIngredient(mekanism.api.recipes.inputs.FluidStackIngredient) ElectrolysisRecipe(mekanism.api.recipes.ElectrolysisRecipe) FluidStack(net.minecraftforge.fluids.FluidStack) GasStack(mekanism.api.chemical.gas.GasStack) IngredientHelper(mekanism.common.integration.projecte.IngredientHelper)

Example 9 with FluidStackIngredient

use of mekanism.api.recipes.inputs.FluidStackIngredient in project Mekanism by mekanism.

the class BaseCrTExampleProvider method getIngredientRepresentation.

private String getIngredientRepresentation(CrTImportsComponent imports, FluidStackIngredient ingredient) {
    if (ingredient instanceof FluidStackIngredient.Single) {
        JsonObject serialized = ingredient.serialize().getAsJsonObject();
        String stackRepresentation = new MCFluidStack(SerializerHelper.deserializeFluid(serialized)).getCommandString();
        return imports.addImport(CrTConstants.CLASS_FLUID_STACK_INGREDIENT) + ".from(" + stackRepresentation + ")";
    } else if (ingredient instanceof FluidStackIngredient.Tagged) {
        JsonObject serialized = ingredient.serialize().getAsJsonObject();
        String tagRepresentation = TagManagerFluid.INSTANCE.getTag(serialized.get(JsonConstants.TAG).getAsString()).getCommandString();
        return imports.addImport(CrTConstants.CLASS_FLUID_STACK_INGREDIENT) + ".from(" + tagRepresentation + ", " + serialized.getAsJsonPrimitive(JsonConstants.AMOUNT) + ")";
    } else if (ingredient instanceof FluidStackIngredient.Multi) {
        FluidStackIngredient.Multi multiIngredient = (FluidStackIngredient.Multi) ingredient;
        StringBuilder builder = new StringBuilder(imports.addImport(CrTConstants.CLASS_FLUID_STACK_INGREDIENT) + ".createMulti(");
        if (!multiIngredient.forEachIngredient(i -> {
            String rep = getIngredientRepresentation(imports, i);
            if (rep == null) {
                return true;
            }
            builder.append(rep).append(", ");
            return false;
        })) {
            // Remove trailing comma and space
            builder.setLength(builder.length() - 2);
            builder.append(")");
            return builder.toString();
        }
    }
    return null;
}
Also used : JSONUtils(net.minecraft.util.JSONUtils) JsonObject(com.google.gson.JsonObject) IDataProvider(net.minecraft.data.IDataProvider) Arrays(java.util.Arrays) ChemicalStack(mekanism.api.chemical.ChemicalStack) ICrTPigmentStack(mekanism.common.integration.crafttweaker.chemical.ICrTChemicalStack.ICrTPigmentStack) Item(net.minecraft.item.Item) BiFunction(java.util.function.BiFunction) ItemStackIngredient(mekanism.api.recipes.inputs.ItemStackIngredient) IItemStack(com.blamejared.crafttweaker.api.item.IItemStack) JsonConstants(mekanism.api.JsonConstants) CrTGasStack(mekanism.common.integration.crafttweaker.chemical.CrTChemicalStack.CrTGasStack) CrTImportsComponent(mekanism.common.integration.crafttweaker.example.component.CrTImportsComponent) ICrTGasStack(mekanism.common.integration.crafttweaker.chemical.ICrTChemicalStack.ICrTGasStack) Gson(com.google.gson.Gson) Chemical(mekanism.api.chemical.Chemical) Map(java.util.Map) GasStack(mekanism.api.chemical.gas.GasStack) IIngredient(com.blamejared.crafttweaker.api.item.IIngredient) Path(java.nio.file.Path) CrTChemicalTagManager(mekanism.common.integration.crafttweaker.tag.CrTChemicalTagManager) NBTIngredient(net.minecraftforge.common.crafting.NBTIngredient) PigmentStackIngredient(mekanism.api.recipes.inputs.chemical.PigmentStackIngredient) CrTInfusionStack(mekanism.common.integration.crafttweaker.chemical.CrTChemicalStack.CrTInfusionStack) CommandStringDisplayable(com.blamejared.crafttweaker.api.brackets.CommandStringDisplayable) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) MekanismRecipeHandler(mekanism.common.integration.crafttweaker.recipe.handler.MekanismRecipeHandler) List(java.util.List) SlurryStackIngredient(mekanism.api.recipes.inputs.chemical.SlurryStackIngredient) GasStackIngredient(mekanism.api.recipes.inputs.chemical.GasStackIngredient) PigmentStack(mekanism.api.chemical.pigment.PigmentStack) FluidStack(net.minecraftforge.fluids.FluidStack) MCTag(com.blamejared.crafttweaker.impl.tag.MCTag) IFluidStack(com.blamejared.crafttweaker.api.fluid.IFluidStack) IChemicalStackIngredient(mekanism.api.recipes.inputs.chemical.IChemicalStackIngredient) ForgeRegistries(net.minecraftforge.registries.ForgeRegistries) InfusionStackIngredient(mekanism.api.recipes.inputs.chemical.InfusionStackIngredient) MCItemStack(com.blamejared.crafttweaker.impl.item.MCItemStack) ICrTChemicalStack(mekanism.common.integration.crafttweaker.chemical.ICrTChemicalStack) CrTPigmentTagManager(mekanism.common.integration.crafttweaker.tag.CrTPigmentTagManager) Ingredient(net.minecraft.item.crafting.Ingredient) ICrTInfusionStack(mekanism.common.integration.crafttweaker.chemical.ICrTChemicalStack.ICrTInfusionStack) TagManagerFluid(com.blamejared.crafttweaker.impl.tag.manager.TagManagerFluid) MCWeightedItemStack(com.blamejared.crafttweaker.impl.item.MCWeightedItemStack) HashMap(java.util.HashMap) Function(java.util.function.Function) FluidStackIngredient(mekanism.api.recipes.inputs.FluidStackIngredient) SlurryStack(mekanism.api.chemical.slurry.SlurryStack) ArrayList(java.util.ArrayList) JsonElement(com.google.gson.JsonElement) LinkedHashMap(java.util.LinkedHashMap) ItemStack(net.minecraft.item.ItemStack) FloatingLong(mekanism.api.math.FloatingLong) ICrTSlurryStack(mekanism.common.integration.crafttweaker.chemical.ICrTChemicalStack.ICrTSlurryStack) ResourcePackType(net.minecraft.resources.ResourcePackType) CrTGasTagManager(mekanism.common.integration.crafttweaker.tag.CrTGasTagManager) ChemicalIngredientDeserializer(mekanism.api.recipes.inputs.chemical.ChemicalIngredientDeserializer) CrTInfuseTypeTagManager(mekanism.common.integration.crafttweaker.tag.CrTInfuseTypeTagManager) MCFluidStack(com.blamejared.crafttweaker.impl.fluid.MCFluidStack) Nonnull(javax.annotation.Nonnull) DataGenerator(net.minecraft.data.DataGenerator) Files(java.nio.file.Files) BufferedWriter(java.io.BufferedWriter) CrTSlurryStack(mekanism.common.integration.crafttweaker.chemical.CrTChemicalStack.CrTSlurryStack) DirectoryCache(net.minecraft.data.DirectoryCache) IOException(java.io.IOException) InputStreamReader(java.io.InputStreamReader) ExistingFileHelper(net.minecraftforge.common.data.ExistingFileHelper) CrTSlurryTagManager(mekanism.common.integration.crafttweaker.tag.CrTSlurryTagManager) InfusionStack(mekanism.api.chemical.infuse.InfusionStack) ChemicalStackIngredient(mekanism.api.recipes.inputs.chemical.ChemicalStackIngredient) CrTConstants(mekanism.common.integration.crafttweaker.CrTConstants) IItemProvider(net.minecraft.util.IItemProvider) CrTPigmentStack(mekanism.common.integration.crafttweaker.chemical.CrTChemicalStack.CrTPigmentStack) ItemStackHelper(com.blamejared.crafttweaker.impl.helper.ItemStackHelper) SerializerHelper(mekanism.api.SerializerHelper) ResourceLocation(net.minecraft.util.ResourceLocation) BufferedReader(java.io.BufferedReader) Collections(java.util.Collections) CraftingHelper(net.minecraftforge.common.crafting.CraftingHelper) FluidStackIngredient(mekanism.api.recipes.inputs.FluidStackIngredient) MCFluidStack(com.blamejared.crafttweaker.impl.fluid.MCFluidStack) JsonObject(com.google.gson.JsonObject)

Example 10 with FluidStackIngredient

use of mekanism.api.recipes.inputs.FluidStackIngredient in project Mekanism by mekanism.

the class PressurizedReactionRecipeSerializer method fromJson.

@Nonnull
@Override
public RECIPE fromJson(@Nonnull ResourceLocation recipeId, @Nonnull JsonObject json) {
    JsonElement itemInput = JSONUtils.isArrayNode(json, JsonConstants.ITEM_INPUT) ? JSONUtils.getAsJsonArray(json, JsonConstants.ITEM_INPUT) : JSONUtils.getAsJsonObject(json, JsonConstants.ITEM_INPUT);
    ItemStackIngredient solidIngredient = ItemStackIngredient.deserialize(itemInput);
    JsonElement fluidInput = JSONUtils.isArrayNode(json, JsonConstants.FLUID_INPUT) ? JSONUtils.getAsJsonArray(json, JsonConstants.FLUID_INPUT) : JSONUtils.getAsJsonObject(json, JsonConstants.FLUID_INPUT);
    FluidStackIngredient fluidIngredient = FluidStackIngredient.deserialize(fluidInput);
    JsonElement gasInput = JSONUtils.isArrayNode(json, JsonConstants.GAS_INPUT) ? JSONUtils.getAsJsonArray(json, JsonConstants.GAS_INPUT) : JSONUtils.getAsJsonObject(json, JsonConstants.GAS_INPUT);
    GasStackIngredient gasIngredient = GasStackIngredient.deserialize(gasInput);
    FloatingLong energyRequired = FloatingLong.ZERO;
    if (json.has(JsonConstants.ENERGY_REQUIRED)) {
        energyRequired = SerializerHelper.getFloatingLong(json, JsonConstants.ENERGY_REQUIRED);
    }
    int duration;
    JsonElement ticks = json.get(JsonConstants.DURATION);
    if (!JSONUtils.isNumberValue(ticks)) {
        throw new JsonSyntaxException("Expected duration to be a number greater than zero.");
    }
    duration = ticks.getAsJsonPrimitive().getAsInt();
    if (duration <= 0) {
        throw new JsonSyntaxException("Expected duration to be a number greater than zero.");
    }
    ItemStack itemOutput = ItemStack.EMPTY;
    GasStack gasOutput = GasStack.EMPTY;
    if (json.has(JsonConstants.ITEM_OUTPUT)) {
        itemOutput = SerializerHelper.getItemStack(json, JsonConstants.ITEM_OUTPUT);
        if (itemOutput.isEmpty()) {
            throw new JsonSyntaxException("Reaction chamber item output must not be empty, if it is defined.");
        }
        if (json.has(JsonConstants.GAS_OUTPUT)) {
            // The gas is optional given we have an output item
            gasOutput = SerializerHelper.getGasStack(json, JsonConstants.GAS_OUTPUT);
            if (gasOutput.isEmpty()) {
                throw new JsonSyntaxException("Reaction chamber gas output must not be empty, if it is defined.");
            }
        }
    } else {
        // If we don't have an output item, we are required to have an output gas
        gasOutput = SerializerHelper.getGasStack(json, JsonConstants.GAS_OUTPUT);
        if (gasOutput.isEmpty()) {
            throw new JsonSyntaxException("Reaction chamber gas output must not be empty, if there is no item output.");
        }
    }
    return this.factory.create(recipeId, solidIngredient, fluidIngredient, gasIngredient, energyRequired, duration, itemOutput, gasOutput);
}
Also used : ItemStackIngredient(mekanism.api.recipes.inputs.ItemStackIngredient) FloatingLong(mekanism.api.math.FloatingLong) JsonSyntaxException(com.google.gson.JsonSyntaxException) FluidStackIngredient(mekanism.api.recipes.inputs.FluidStackIngredient) JsonElement(com.google.gson.JsonElement) GasStack(mekanism.api.chemical.gas.GasStack) ItemStack(net.minecraft.item.ItemStack) GasStackIngredient(mekanism.api.recipes.inputs.chemical.GasStackIngredient) Nonnull(javax.annotation.Nonnull)

Aggregations

FluidStackIngredient (mekanism.api.recipes.inputs.FluidStackIngredient)14 JsonSyntaxException (com.google.gson.JsonSyntaxException)10 GasStack (mekanism.api.chemical.gas.GasStack)8 JsonElement (com.google.gson.JsonElement)6 Nonnull (javax.annotation.Nonnull)6 FluidStack (net.minecraftforge.fluids.FluidStack)6 FloatingLong (mekanism.api.math.FloatingLong)5 GasStackIngredient (mekanism.api.recipes.inputs.chemical.GasStackIngredient)5 SlurryStack (mekanism.api.chemical.slurry.SlurryStack)3 SlurryStackIngredient (mekanism.api.recipes.inputs.chemical.SlurryStackIngredient)3 MCFluidStack (com.blamejared.crafttweaker.impl.fluid.MCFluidStack)2 JsonObject (com.google.gson.JsonObject)2 ItemStackIngredient (mekanism.api.recipes.inputs.ItemStackIngredient)2 ItemStack (net.minecraft.item.ItemStack)2 CommandStringDisplayable (com.blamejared.crafttweaker.api.brackets.CommandStringDisplayable)1 IFluidStack (com.blamejared.crafttweaker.api.fluid.IFluidStack)1 IIngredient (com.blamejared.crafttweaker.api.item.IIngredient)1 IItemStack (com.blamejared.crafttweaker.api.item.IItemStack)1 ItemStackHelper (com.blamejared.crafttweaker.impl.helper.ItemStackHelper)1 MCItemStack (com.blamejared.crafttweaker.impl.item.MCItemStack)1