use of mekanism.api.recipes.inputs.chemical.GasStackIngredient in project Mekanism by mekanism.
the class NucleosynthesizingRecipeSerializer method fromNetwork.
@Override
public RECIPE fromNetwork(@Nonnull ResourceLocation recipeId, @Nonnull PacketBuffer buffer) {
try {
ItemStackIngredient inputSolid = ItemStackIngredient.read(buffer);
GasStackIngredient inputGas = GasStackIngredient.read(buffer);
ItemStack outputItem = buffer.readItem();
int duration = buffer.readVarInt();
return this.factory.create(recipeId, inputSolid, inputGas, outputItem, duration);
} catch (Exception e) {
Mekanism.logger.error("Error reading nucleosynthesizing recipe from packet.", e);
throw e;
}
}
use of mekanism.api.recipes.inputs.chemical.GasStackIngredient 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.");
}
use of mekanism.api.recipes.inputs.chemical.GasStackIngredient in project Mekanism by mekanism.
the class PressurizedReactionRecipeSerializer 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 solidIngredient = ItemStackIngredient.deserialize(itemInput);
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 gasInput = JSONUtils.isArrayNode(json, JsonConstants.GAS_INPUT) ? JSONUtils.getAsJsonArray(json, JsonConstants.GAS_INPUT) : JSONUtils.getAsJsonObject(json, JsonConstants.GAS_INPUT);
GasStackIngredient gasIngredient = GasStackIngredient.deserialize(gasInput);
FloatingLong energyRequired = FloatingLong.ZERO;
if (json.has(JsonConstants.ENERGY_REQUIRED)) {
energyRequired = SerializerHelper.getFloatingLong(json, JsonConstants.ENERGY_REQUIRED);
}
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 = ItemStack.EMPTY;
GasStack gasOutput = GasStack.EMPTY;
if (json.has(JsonConstants.ITEM_OUTPUT)) {
itemOutput = SerializerHelper.getItemStack(json, JsonConstants.ITEM_OUTPUT);
if (itemOutput.isEmpty()) {
throw new JsonSyntaxException("Reaction chamber item output must not be empty, if it is defined.");
}
if (json.has(JsonConstants.GAS_OUTPUT)) {
// The gas is optional given we have an output item
gasOutput = SerializerHelper.getGasStack(json, JsonConstants.GAS_OUTPUT);
if (gasOutput.isEmpty()) {
throw new JsonSyntaxException("Reaction chamber gas output must not be empty, if it is defined.");
}
}
} else {
// If we don't have an output item, we are required to have an output gas
gasOutput = SerializerHelper.getGasStack(json, JsonConstants.GAS_OUTPUT);
if (gasOutput.isEmpty()) {
throw new JsonSyntaxException("Reaction chamber gas output must not be empty, if there is no item output.");
}
}
return this.factory.create(recipeId, solidIngredient, fluidIngredient, gasIngredient, energyRequired, duration, itemOutput, gasOutput);
}
use of mekanism.api.recipes.inputs.chemical.GasStackIngredient in project Mekanism by mekanism.
the class PressurizedReactionRecipeSerializer method fromNetwork.
@Override
public RECIPE fromNetwork(@Nonnull ResourceLocation recipeId, @Nonnull PacketBuffer buffer) {
try {
ItemStackIngredient inputSolid = ItemStackIngredient.read(buffer);
FluidStackIngredient inputFluid = FluidStackIngredient.read(buffer);
GasStackIngredient inputGas = GasStackIngredient.read(buffer);
FloatingLong energyRequired = FloatingLong.readFromBuffer(buffer);
int duration = buffer.readVarInt();
ItemStack outputItem = buffer.readItem();
GasStack outputGas = GasStack.readFromPacket(buffer);
return this.factory.create(recipeId, inputSolid, inputFluid, inputGas, energyRequired, duration, outputItem, outputGas);
} catch (Exception e) {
Mekanism.logger.error("Error reading pressurized reaction recipe from packet.", e);
throw e;
}
}
use of mekanism.api.recipes.inputs.chemical.GasStackIngredient in project Mekanism by mekanism.
the class RotaryRecipeSerializer method fromNetwork.
@Override
public RECIPE fromNetwork(@Nonnull ResourceLocation recipeId, @Nonnull PacketBuffer buffer) {
try {
FluidStackIngredient fluidInputIngredient = null;
GasStackIngredient gasInputIngredient = null;
GasStack gasOutput = null;
FluidStack fluidOutput = null;
boolean hasFluidToGas = buffer.readBoolean();
if (hasFluidToGas) {
fluidInputIngredient = FluidStackIngredient.read(buffer);
gasOutput = GasStack.readFromPacket(buffer);
}
boolean hasGasToFluid = buffer.readBoolean();
if (hasGasToFluid) {
gasInputIngredient = GasStackIngredient.read(buffer);
fluidOutput = FluidStack.readFromPacket(buffer);
}
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);
}
// Should never happen, but if we somehow get here log it
Mekanism.logger.error("Error reading rotary recipe from packet. A recipe got sent with no conversion in either direction.");
return null;
} catch (Exception e) {
Mekanism.logger.error("Error reading rotary recipe from packet.", e);
throw e;
}
}
Aggregations