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;
}
}
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);
}
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);
}
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;
}
}
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.");
}
Aggregations