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