Search in sources :

Example 1 with GasStackIngredient

use of mekanism.api.recipes.inputs.chemical.GasStackIngredient 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 GasStackIngredient

use of mekanism.api.recipes.inputs.chemical.GasStackIngredient 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 GasStackIngredient

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

the class GasToGasRecipeSerializer 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);
    GasStackIngredient inputIngredient = GasStackIngredient.deserialize(input);
    GasStack output = SerializerHelper.getGasStack(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) JsonElement(com.google.gson.JsonElement) GasStack(mekanism.api.chemical.gas.GasStack) GasStackIngredient(mekanism.api.recipes.inputs.chemical.GasStackIngredient) Nonnull(javax.annotation.Nonnull)

Example 4 with GasStackIngredient

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

the class GasToGasRecipeSerializer method fromNetwork.

@Override
public RECIPE fromNetwork(@Nonnull ResourceLocation recipeId, @Nonnull PacketBuffer buffer) {
    try {
        GasStackIngredient inputIngredient = GasStackIngredient.read(buffer);
        GasStack output = GasStack.readFromPacket(buffer);
        return this.factory.create(recipeId, inputIngredient, output);
    } catch (Exception e) {
        Mekanism.logger.error("Error reading gas to gas recipe from packet.", e);
        throw e;
    }
}
Also used : GasStack(mekanism.api.chemical.gas.GasStack) JsonSyntaxException(com.google.gson.JsonSyntaxException) GasStackIngredient(mekanism.api.recipes.inputs.chemical.GasStackIngredient)

Example 5 with GasStackIngredient

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

the class NucleosynthesizingRecipeSerializer 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);
    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 = SerializerHelper.getItemStack(json, JsonConstants.OUTPUT);
    if (itemOutput.isEmpty()) {
        throw new JsonSyntaxException("Nucleosynthesizing item output must not be empty.");
    }
    return this.factory.create(recipeId, itemIngredient, gasIngredient, itemOutput, duration);
}
Also used : ItemStackIngredient(mekanism.api.recipes.inputs.ItemStackIngredient) JsonSyntaxException(com.google.gson.JsonSyntaxException) JsonElement(com.google.gson.JsonElement) ItemStack(net.minecraft.item.ItemStack) GasStackIngredient(mekanism.api.recipes.inputs.chemical.GasStackIngredient) Nonnull(javax.annotation.Nonnull)

Aggregations

GasStackIngredient (mekanism.api.recipes.inputs.chemical.GasStackIngredient)11 JsonSyntaxException (com.google.gson.JsonSyntaxException)10 Nonnull (javax.annotation.Nonnull)6 GasStack (mekanism.api.chemical.gas.GasStack)6 ItemStackIngredient (mekanism.api.recipes.inputs.ItemStackIngredient)6 JsonElement (com.google.gson.JsonElement)5 ItemStack (net.minecraft.item.ItemStack)5 FluidStackIngredient (mekanism.api.recipes.inputs.FluidStackIngredient)4 FloatingLong (mekanism.api.math.FloatingLong)2 MatrixStack (com.mojang.blaze3d.matrix.MatrixStack)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 WeakHashMap (java.util.WeakHashMap)1 Collectors (java.util.stream.Collectors)1 Nullable (javax.annotation.Nullable)1 ChemicalStack (mekanism.api.chemical.ChemicalStack)1 ChemicalType (mekanism.api.chemical.ChemicalType)1 BoxedChemicalStack (mekanism.api.chemical.merged.BoxedChemicalStack)1