Search in sources :

Example 16 with ItemStackIngredient

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

the class BiomesOPlentyRecipeProvider method dye.

private void dye(Consumer<IFinishedRecipe> consumer, String basePath, IItemProvider output, EnumColor color, IItemProvider... inputs) {
    ItemStackIngredient inputIngredient = ItemStackIngredient.from(Ingredient.of(inputs));
    ItemStackToItemStackRecipeBuilder.enriching(inputIngredient, new ItemStack(output, 2)).addCondition(modLoaded).build(consumer, Mekanism.rl(basePath + "dye/" + color.getRegistryPrefix()));
    // Flowers -> 4x dye output (See PigmentExtractingRecipeProvider#addFlowerExtractionRecipes for note)
    long flowerRate = 3 * PigmentExtractingRecipeProvider.DYE_RATE;
    ItemStackToChemicalRecipeBuilder.pigmentExtracting(inputIngredient, MekanismPigments.PIGMENT_COLOR_LOOKUP.get(color).getStack(flowerRate)).addCondition(modLoaded).build(consumer, Mekanism.rl(basePath + "pigment_extracting/" + color.getRegistryPrefix()));
}
Also used : ItemStackIngredient(mekanism.api.recipes.inputs.ItemStackIngredient) ItemStack(net.minecraft.item.ItemStack)

Example 17 with ItemStackIngredient

use of mekanism.api.recipes.inputs.ItemStackIngredient 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)

Example 18 with ItemStackIngredient

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

the class PressurizedReactionRecipeSerializer method fromNetwork.

@Override
public RECIPE fromNetwork(@Nonnull ResourceLocation recipeId, @Nonnull PacketBuffer buffer) {
    try {
        ItemStackIngredient inputSolid = ItemStackIngredient.read(buffer);
        FluidStackIngredient inputFluid = FluidStackIngredient.read(buffer);
        GasStackIngredient inputGas = GasStackIngredient.read(buffer);
        FloatingLong energyRequired = FloatingLong.readFromBuffer(buffer);
        int duration = buffer.readVarInt();
        ItemStack outputItem = buffer.readItem();
        GasStack outputGas = GasStack.readFromPacket(buffer);
        return this.factory.create(recipeId, inputSolid, inputFluid, inputGas, energyRequired, duration, outputItem, outputGas);
    } catch (Exception e) {
        Mekanism.logger.error("Error reading pressurized reaction recipe from packet.", e);
        throw e;
    }
}
Also used : ItemStackIngredient(mekanism.api.recipes.inputs.ItemStackIngredient) FloatingLong(mekanism.api.math.FloatingLong) FluidStackIngredient(mekanism.api.recipes.inputs.FluidStackIngredient) GasStack(mekanism.api.chemical.gas.GasStack) ItemStack(net.minecraft.item.ItemStack) JsonSyntaxException(com.google.gson.JsonSyntaxException) GasStackIngredient(mekanism.api.recipes.inputs.chemical.GasStackIngredient)

Example 19 with ItemStackIngredient

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

the class SawmillRecipeSerializer method fromJson.

@Nonnull
@Override
public RECIPE fromJson(@Nonnull ResourceLocation recipeId, @Nonnull JsonObject json) {
    JsonElement input = JSONUtils.isArrayNode(json, JsonConstants.INPUT) ? JSONUtils.getAsJsonArray(json, JsonConstants.INPUT) : JSONUtils.getAsJsonObject(json, JsonConstants.INPUT);
    ItemStackIngredient inputIngredient = ItemStackIngredient.deserialize(input);
    ItemStack mainOutput = ItemStack.EMPTY;
    ItemStack secondaryOutput = ItemStack.EMPTY;
    double secondaryChance = 0;
    if (json.has(JsonConstants.SECONDARY_OUTPUT) || json.has(JsonConstants.SECONDARY_CHANCE)) {
        if (json.has(JsonConstants.MAIN_OUTPUT)) {
            // Allow for the main output to be optional if we have a secondary output
            mainOutput = SerializerHelper.getItemStack(json, JsonConstants.MAIN_OUTPUT);
            if (mainOutput.isEmpty()) {
                throw new JsonSyntaxException("Sawmill main recipe output must not be empty, if it is defined.");
            }
        }
        // If we have either json element for secondary information, assume we have both and fail if we can't get one of them
        JsonElement chance = json.get(JsonConstants.SECONDARY_CHANCE);
        if (!JSONUtils.isNumberValue(chance)) {
            throw new JsonSyntaxException("Expected secondaryChance to be a number greater than zero.");
        }
        secondaryChance = chance.getAsJsonPrimitive().getAsDouble();
        if (secondaryChance <= 0 || secondaryChance > 1) {
            throw new JsonSyntaxException("Expected secondaryChance to be greater than zero, and less than or equal to one.");
        }
        secondaryOutput = SerializerHelper.getItemStack(json, JsonConstants.SECONDARY_OUTPUT);
        if (secondaryOutput.isEmpty()) {
            throw new JsonSyntaxException("Sawmill secondary recipe output must not be empty, if there is no main output.");
        }
    } else {
        // If we don't have a secondary output require a main output
        mainOutput = SerializerHelper.getItemStack(json, JsonConstants.MAIN_OUTPUT);
        if (mainOutput.isEmpty()) {
            throw new JsonSyntaxException("Sawmill main recipe output must not be empty, if there is no secondary output.");
        }
    }
    return this.factory.create(recipeId, inputIngredient, mainOutput, secondaryOutput, secondaryChance);
}
Also used : ItemStackIngredient(mekanism.api.recipes.inputs.ItemStackIngredient) JsonSyntaxException(com.google.gson.JsonSyntaxException) JsonElement(com.google.gson.JsonElement) ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Example 20 with ItemStackIngredient

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

the class ItemStackToChemicalRecipeSerializer method fromJson.

@Nonnull
@Override
public RECIPE fromJson(@Nonnull ResourceLocation recipeId, @Nonnull JsonObject json) {
    JsonElement input = JSONUtils.isArrayNode(json, JsonConstants.INPUT) ? JSONUtils.getAsJsonArray(json, JsonConstants.INPUT) : JSONUtils.getAsJsonObject(json, JsonConstants.INPUT);
    ItemStackIngredient inputIngredient = ItemStackIngredient.deserialize(input);
    STACK output = fromJson(json, JsonConstants.OUTPUT);
    if (output.isEmpty()) {
        throw new JsonSyntaxException("Recipe output must not be empty.");
    }
    return this.factory.create(recipeId, inputIngredient, output);
}
Also used : ItemStackIngredient(mekanism.api.recipes.inputs.ItemStackIngredient) JsonSyntaxException(com.google.gson.JsonSyntaxException) JsonElement(com.google.gson.JsonElement) Nonnull(javax.annotation.Nonnull)

Aggregations

ItemStackIngredient (mekanism.api.recipes.inputs.ItemStackIngredient)26 ItemStack (net.minecraft.item.ItemStack)19 JsonSyntaxException (com.google.gson.JsonSyntaxException)18 JsonElement (com.google.gson.JsonElement)10 Nonnull (javax.annotation.Nonnull)10 GasStackIngredient (mekanism.api.recipes.inputs.chemical.GasStackIngredient)8 FloatingLong (mekanism.api.math.FloatingLong)5 FluidStackIngredient (mekanism.api.recipes.inputs.FluidStackIngredient)4 Ingredient (net.minecraft.item.crafting.Ingredient)4 IIngredient (com.blamejared.crafttweaker.api.item.IIngredient)3 GasStack (mekanism.api.chemical.gas.GasStack)3 Item (net.minecraft.item.Item)3 JsonObject (com.google.gson.JsonObject)2 ChemicalType (mekanism.api.chemical.ChemicalType)2 ChemicalStackIngredient (mekanism.api.recipes.inputs.chemical.ChemicalStackIngredient)2 IChemicalStackIngredient (mekanism.api.recipes.inputs.chemical.IChemicalStackIngredient)2 InfusionStackIngredient (mekanism.api.recipes.inputs.chemical.InfusionStackIngredient)2 PigmentStackIngredient (mekanism.api.recipes.inputs.chemical.PigmentStackIngredient)2 SlurryStackIngredient (mekanism.api.recipes.inputs.chemical.SlurryStackIngredient)2 ResourceLocation (net.minecraft.util.ResourceLocation)2