Search in sources :

Example 6 with GasStack

use of mekanism.api.chemical.gas.GasStack in project Mekanism by mekanism.

the class ElectrolysisRecipeSerializer method fromNetwork.

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

Example 7 with GasStack

use of mekanism.api.chemical.gas.GasStack in project Mekanism by mekanism.

the class ElectrolysisRecipeSerializer 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);
    FluidStackIngredient inputIngredient = FluidStackIngredient.deserialize(input);
    GasStack leftGasOutput = SerializerHelper.getGasStack(json, JsonConstants.LEFT_GAS_OUTPUT);
    GasStack rightGasOutput = SerializerHelper.getGasStack(json, JsonConstants.RIGHT_GAS_OUTPUT);
    FloatingLong energyMultiplier = FloatingLong.ONE;
    if (json.has(JsonConstants.ENERGY_MULTIPLIER)) {
        energyMultiplier = SerializerHelper.getFloatingLong(json, JsonConstants.ENERGY_MULTIPLIER);
        if (energyMultiplier.smallerThan(FloatingLong.ONE)) {
            throw new JsonSyntaxException("Expected energyMultiplier to be at least one.");
        }
    }
    if (leftGasOutput.isEmpty() || rightGasOutput.isEmpty()) {
        throw new JsonSyntaxException("Electrolysis recipe outputs must not be empty.");
    }
    return this.factory.create(recipeId, inputIngredient, energyMultiplier, leftGasOutput, rightGasOutput);
}
Also used : 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) Nonnull(javax.annotation.Nonnull)

Example 8 with GasStack

use of mekanism.api.chemical.gas.GasStack 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 9 with GasStack

use of mekanism.api.chemical.gas.GasStack 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 10 with GasStack

use of mekanism.api.chemical.gas.GasStack in project Mekanism by mekanism.

the class RotaryRecipeSerializer method fromJson.

@Nonnull
@Override
public RECIPE fromJson(@Nonnull ResourceLocation recipeId, @Nonnull JsonObject json) {
    FluidStackIngredient fluidInputIngredient = null;
    GasStackIngredient gasInputIngredient = null;
    GasStack gasOutput = null;
    FluidStack fluidOutput = null;
    boolean hasFluidToGas = false;
    boolean hasGasToFluid = false;
    if (json.has(JsonConstants.FLUID_INPUT) || json.has(JsonConstants.GAS_OUTPUT)) {
        JsonElement fluidInput = JSONUtils.isArrayNode(json, JsonConstants.FLUID_INPUT) ? JSONUtils.getAsJsonArray(json, JsonConstants.FLUID_INPUT) : JSONUtils.getAsJsonObject(json, JsonConstants.FLUID_INPUT);
        fluidInputIngredient = FluidStackIngredient.deserialize(fluidInput);
        gasOutput = SerializerHelper.getGasStack(json, JsonConstants.GAS_OUTPUT);
        hasFluidToGas = true;
        if (gasOutput.isEmpty()) {
            throw new JsonSyntaxException("Rotary recipe gas output cannot be empty if it is defined.");
        }
    }
    if (json.has(JsonConstants.GAS_INPUT) || json.has(JsonConstants.FLUID_OUTPUT)) {
        JsonElement gasInput = JSONUtils.isArrayNode(json, JsonConstants.GAS_INPUT) ? JSONUtils.getAsJsonArray(json, JsonConstants.GAS_INPUT) : JSONUtils.getAsJsonObject(json, JsonConstants.GAS_INPUT);
        gasInputIngredient = GasStackIngredient.deserialize(gasInput);
        fluidOutput = SerializerHelper.getFluidStack(json, JsonConstants.FLUID_OUTPUT);
        hasGasToFluid = true;
        if (fluidOutput.isEmpty()) {
            throw new JsonSyntaxException("Rotary recipe fluid output cannot be empty if it is defined.");
        }
    }
    if (hasFluidToGas && hasGasToFluid) {
        return this.factory.create(recipeId, fluidInputIngredient, gasInputIngredient, gasOutput, fluidOutput);
    } else if (hasFluidToGas) {
        return this.factory.create(recipeId, fluidInputIngredient, gasOutput);
    } else if (hasGasToFluid) {
        return this.factory.create(recipeId, gasInputIngredient, fluidOutput);
    }
    throw new JsonSyntaxException("Rotary recipes require at least a gas to fluid or fluid to gas conversion.");
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) FluidStackIngredient(mekanism.api.recipes.inputs.FluidStackIngredient) FluidStack(net.minecraftforge.fluids.FluidStack) JsonElement(com.google.gson.JsonElement) GasStack(mekanism.api.chemical.gas.GasStack) GasStackIngredient(mekanism.api.recipes.inputs.chemical.GasStackIngredient) Nonnull(javax.annotation.Nonnull)

Aggregations

GasStack (mekanism.api.chemical.gas.GasStack)44 ItemStack (net.minecraft.item.ItemStack)17 JsonSyntaxException (com.google.gson.JsonSyntaxException)8 IngredientHelper (mekanism.common.integration.projecte.IngredientHelper)8 FluidStackIngredient (mekanism.api.recipes.inputs.FluidStackIngredient)7 FluidStack (net.minecraftforge.fluids.FluidStack)7 List (java.util.List)6 IGasHandler (mekanism.api.chemical.gas.IGasHandler)6 PigmentStack (mekanism.api.chemical.pigment.PigmentStack)6 FloatingLong (mekanism.api.math.FloatingLong)6 GasStackIngredient (mekanism.api.recipes.inputs.chemical.GasStackIngredient)6 NonNull (mekanism.api.annotations.NonNull)5 InfusionStack (mekanism.api.chemical.infuse.InfusionStack)5 SlurryStack (mekanism.api.chemical.slurry.SlurryStack)5 Nonnull (javax.annotation.Nonnull)4 JsonElement (com.google.gson.JsonElement)3 Collections (java.util.Collections)3 Nullable (javax.annotation.Nullable)3 ChemicalType (mekanism.api.chemical.ChemicalType)3 BoxedChemicalStack (mekanism.api.chemical.merged.BoxedChemicalStack)3