Search in sources :

Example 1 with FluidStackIngredient

use of mekanism.api.recipes.inputs.FluidStackIngredient 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 2 with FluidStackIngredient

use of mekanism.api.recipes.inputs.FluidStackIngredient 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 3 with FluidStackIngredient

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

the class FluidSlurryToSlurryRecipeSerializer method fromJson.

@Nonnull
@Override
public RECIPE fromJson(@Nonnull ResourceLocation recipeId, @Nonnull JsonObject json) {
    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 slurryInput = JSONUtils.isArrayNode(json, JsonConstants.SLURRY_INPUT) ? JSONUtils.getAsJsonArray(json, JsonConstants.SLURRY_INPUT) : JSONUtils.getAsJsonObject(json, JsonConstants.SLURRY_INPUT);
    SlurryStackIngredient slurryIngredient = SlurryStackIngredient.deserialize(slurryInput);
    SlurryStack output = SerializerHelper.getSlurryStack(json, JsonConstants.OUTPUT);
    if (output.isEmpty()) {
        throw new JsonSyntaxException("Recipe output must not be empty.");
    }
    return this.factory.create(recipeId, fluidIngredient, slurryIngredient, output);
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) FluidStackIngredient(mekanism.api.recipes.inputs.FluidStackIngredient) JsonElement(com.google.gson.JsonElement) SlurryStackIngredient(mekanism.api.recipes.inputs.chemical.SlurryStackIngredient) SlurryStack(mekanism.api.chemical.slurry.SlurryStack) Nonnull(javax.annotation.Nonnull)

Example 4 with FluidStackIngredient

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

the class FluidToFluidRecipeSerializer method fromNetwork.

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

Example 5 with FluidStackIngredient

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

FluidStackIngredient (mekanism.api.recipes.inputs.FluidStackIngredient)14 JsonSyntaxException (com.google.gson.JsonSyntaxException)10 GasStack (mekanism.api.chemical.gas.GasStack)8 JsonElement (com.google.gson.JsonElement)6 Nonnull (javax.annotation.Nonnull)6 FluidStack (net.minecraftforge.fluids.FluidStack)6 FloatingLong (mekanism.api.math.FloatingLong)5 GasStackIngredient (mekanism.api.recipes.inputs.chemical.GasStackIngredient)5 SlurryStack (mekanism.api.chemical.slurry.SlurryStack)3 SlurryStackIngredient (mekanism.api.recipes.inputs.chemical.SlurryStackIngredient)3 MCFluidStack (com.blamejared.crafttweaker.impl.fluid.MCFluidStack)2 JsonObject (com.google.gson.JsonObject)2 ItemStackIngredient (mekanism.api.recipes.inputs.ItemStackIngredient)2 ItemStack (net.minecraft.item.ItemStack)2 CommandStringDisplayable (com.blamejared.crafttweaker.api.brackets.CommandStringDisplayable)1 IFluidStack (com.blamejared.crafttweaker.api.fluid.IFluidStack)1 IIngredient (com.blamejared.crafttweaker.api.item.IIngredient)1 IItemStack (com.blamejared.crafttweaker.api.item.IItemStack)1 ItemStackHelper (com.blamejared.crafttweaker.impl.helper.ItemStackHelper)1 MCItemStack (com.blamejared.crafttweaker.impl.item.MCItemStack)1