Search in sources :

Example 1 with ChemicalStackIngredient

use of mekanism.api.recipes.inputs.chemical.ChemicalStackIngredient in project Mekanism by mekanism.

the class ChemicalCrystallizerRecipeSerializer method fromJson.

@Nonnull
@Override
public RECIPE fromJson(@Nonnull ResourceLocation recipeId, @Nonnull JsonObject json) {
    ChemicalType chemicalType = SerializerHelper.getChemicalType(json);
    JsonElement input = JSONUtils.isArrayNode(json, JsonConstants.INPUT) ? JSONUtils.getAsJsonArray(json, JsonConstants.INPUT) : JSONUtils.getAsJsonObject(json, JsonConstants.INPUT);
    ChemicalStackIngredient<?, ?> inputIngredient = (ChemicalStackIngredient<?, ?>) SerializerHelper.getDeserializerForType(chemicalType).deserialize(input);
    ItemStack output = SerializerHelper.getItemStack(json, JsonConstants.OUTPUT);
    if (output.isEmpty()) {
        throw new JsonSyntaxException("Recipe output must not be empty.");
    }
    return this.factory.create(recipeId, inputIngredient, output);
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) ChemicalType(mekanism.api.chemical.ChemicalType) JsonElement(com.google.gson.JsonElement) ItemStack(net.minecraft.item.ItemStack) ChemicalStackIngredient(mekanism.api.recipes.inputs.chemical.ChemicalStackIngredient) Nonnull(javax.annotation.Nonnull)

Example 2 with ChemicalStackIngredient

use of mekanism.api.recipes.inputs.chemical.ChemicalStackIngredient in project Mekanism by mekanism.

the class ChemicalCrystallizerRecipeSerializer method fromNetwork.

@Override
public RECIPE fromNetwork(@Nonnull ResourceLocation recipeId, @Nonnull PacketBuffer buffer) {
    try {
        ChemicalType chemicalType = buffer.readEnum(ChemicalType.class);
        ChemicalStackIngredient<?, ?> inputIngredient = (ChemicalStackIngredient<?, ?>) SerializerHelper.getDeserializerForType(chemicalType).read(buffer);
        ItemStack output = buffer.readItem();
        return this.factory.create(recipeId, inputIngredient, output);
    } catch (Exception e) {
        Mekanism.logger.error("Error reading boxed chemical to itemstack recipe from packet.", e);
        throw e;
    }
}
Also used : ChemicalType(mekanism.api.chemical.ChemicalType) ItemStack(net.minecraft.item.ItemStack) ChemicalStackIngredient(mekanism.api.recipes.inputs.chemical.ChemicalStackIngredient) JsonSyntaxException(com.google.gson.JsonSyntaxException)

Aggregations

JsonSyntaxException (com.google.gson.JsonSyntaxException)2 ChemicalType (mekanism.api.chemical.ChemicalType)2 ChemicalStackIngredient (mekanism.api.recipes.inputs.chemical.ChemicalStackIngredient)2 ItemStack (net.minecraft.item.ItemStack)2 JsonElement (com.google.gson.JsonElement)1 Nonnull (javax.annotation.Nonnull)1