Search in sources :

Example 1 with ItemStackIngredient

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

the class ChemicalDissolutionRecipeSerializer 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 itemIngredient = ItemStackIngredient.deserialize(itemInput);
    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);
    ChemicalStack<?> output = SerializerHelper.getBoxedChemicalStack(json, JsonConstants.OUTPUT);
    if (output.isEmpty()) {
        throw new JsonSyntaxException("Recipe output must not be empty.");
    }
    return this.factory.create(recipeId, itemIngredient, gasIngredient, output);
}
Also used : ItemStackIngredient(mekanism.api.recipes.inputs.ItemStackIngredient) JsonSyntaxException(com.google.gson.JsonSyntaxException) JsonElement(com.google.gson.JsonElement) GasStackIngredient(mekanism.api.recipes.inputs.chemical.GasStackIngredient) Nonnull(javax.annotation.Nonnull)

Example 2 with ItemStackIngredient

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

the class ChemicalDissolutionRecipeSerializer method fromNetwork.

@Override
public RECIPE fromNetwork(@Nonnull ResourceLocation recipeId, @Nonnull PacketBuffer buffer) {
    try {
        ItemStackIngredient itemInput = ItemStackIngredient.read(buffer);
        GasStackIngredient gasInput = GasStackIngredient.read(buffer);
        ChemicalType chemicalType = buffer.readEnum(ChemicalType.class);
        ChemicalStack<?> output;
        if (chemicalType == ChemicalType.GAS) {
            output = GasStack.readFromPacket(buffer);
        } else if (chemicalType == ChemicalType.INFUSION) {
            output = InfusionStack.readFromPacket(buffer);
        } else if (chemicalType == ChemicalType.PIGMENT) {
            output = PigmentStack.readFromPacket(buffer);
        } else if (chemicalType == ChemicalType.SLURRY) {
            output = SlurryStack.readFromPacket(buffer);
        } else {
            throw new IllegalStateException("Unknown chemical type");
        }
        return this.factory.create(recipeId, itemInput, gasInput, output);
    } catch (Exception e) {
        Mekanism.logger.error("Error reading itemstack gas to gas recipe from packet.", e);
        throw e;
    }
}
Also used : ItemStackIngredient(mekanism.api.recipes.inputs.ItemStackIngredient) ChemicalType(mekanism.api.chemical.ChemicalType) JsonSyntaxException(com.google.gson.JsonSyntaxException) GasStackIngredient(mekanism.api.recipes.inputs.chemical.GasStackIngredient)

Example 3 with ItemStackIngredient

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

the class CombinerRecipeSerializer method fromJson.

@Nonnull
@Override
public RECIPE fromJson(@Nonnull ResourceLocation recipeId, @Nonnull JsonObject json) {
    JsonElement mainInput = JSONUtils.isArrayNode(json, JsonConstants.MAIN_INPUT) ? JSONUtils.getAsJsonArray(json, JsonConstants.MAIN_INPUT) : JSONUtils.getAsJsonObject(json, JsonConstants.MAIN_INPUT);
    ItemStackIngredient mainIngredient = ItemStackIngredient.deserialize(mainInput);
    JsonElement extraInput = JSONUtils.isArrayNode(json, JsonConstants.EXTRA_INPUT) ? JSONUtils.getAsJsonArray(json, JsonConstants.EXTRA_INPUT) : JSONUtils.getAsJsonObject(json, JsonConstants.EXTRA_INPUT);
    ItemStackIngredient extraIngredient = ItemStackIngredient.deserialize(extraInput);
    ItemStack output = SerializerHelper.getItemStack(json, JsonConstants.OUTPUT);
    if (output.isEmpty()) {
        throw new JsonSyntaxException("Combiner recipe output must not be empty.");
    }
    return this.factory.create(recipeId, mainIngredient, extraIngredient, output);
}
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 4 with ItemStackIngredient

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

the class CombinerRecipeSerializer method fromNetwork.

@Override
public RECIPE fromNetwork(@Nonnull ResourceLocation recipeId, @Nonnull PacketBuffer buffer) {
    try {
        ItemStackIngredient mainInput = ItemStackIngredient.read(buffer);
        ItemStackIngredient extraInput = ItemStackIngredient.read(buffer);
        ItemStack output = buffer.readItem();
        return this.factory.create(recipeId, mainInput, extraInput, output);
    } catch (Exception e) {
        Mekanism.logger.error("Error reading combiner recipe from packet.", e);
        throw e;
    }
}
Also used : ItemStackIngredient(mekanism.api.recipes.inputs.ItemStackIngredient) ItemStack(net.minecraft.item.ItemStack) JsonSyntaxException(com.google.gson.JsonSyntaxException)

Example 5 with ItemStackIngredient

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

the class ItemStackChemicalToItemStackRecipeSerializer method fromNetwork.

@Override
public RECIPE fromNetwork(@Nonnull ResourceLocation recipeId, @Nonnull PacketBuffer buffer) {
    try {
        ItemStackIngredient itemInput = ItemStackIngredient.read(buffer);
        INGREDIENT chemicalInput = getDeserializer().read(buffer);
        ItemStack output = buffer.readItem();
        return this.factory.create(recipeId, itemInput, chemicalInput, output);
    } catch (Exception e) {
        Mekanism.logger.error("Error reading itemstack chemical to itemstack recipe from packet.", e);
        throw e;
    }
}
Also used : ItemStackIngredient(mekanism.api.recipes.inputs.ItemStackIngredient) ItemStack(net.minecraft.item.ItemStack) JsonSyntaxException(com.google.gson.JsonSyntaxException)

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