use of mekanism.api.recipes.inputs.ItemStackIngredient in project Mekanism by mekanism.
the class ItemStackChemicalToItemStackRecipeSerializer 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);
String chemicalInputKey = getChemicalInputJsonKey();
JsonElement chemicalInput = JSONUtils.isArrayNode(json, chemicalInputKey) ? JSONUtils.getAsJsonArray(json, chemicalInputKey) : JSONUtils.getAsJsonObject(json, chemicalInputKey);
INGREDIENT chemicalIngredient = getDeserializer().deserialize(chemicalInput);
ItemStack output = SerializerHelper.getItemStack(json, JsonConstants.OUTPUT);
if (output.isEmpty()) {
throw new JsonSyntaxException("Recipe output must not be empty.");
}
return this.factory.create(recipeId, itemIngredient, chemicalIngredient, output);
}
use of mekanism.api.recipes.inputs.ItemStackIngredient in project Mekanism by mekanism.
the class ItemStackToChemicalRecipeSerializer method fromNetwork.
@Override
public RECIPE fromNetwork(@Nonnull ResourceLocation recipeId, @Nonnull PacketBuffer buffer) {
try {
ItemStackIngredient inputIngredient = ItemStackIngredient.read(buffer);
STACK output = fromBuffer(buffer);
return this.factory.create(recipeId, inputIngredient, output);
} catch (Exception e) {
Mekanism.logger.error("Error reading itemstack to chemical recipe from packet.", e);
throw e;
}
}
use of mekanism.api.recipes.inputs.ItemStackIngredient in project Mekanism by mekanism.
the class ItemStackToEnergyRecipeSerializer method fromNetwork.
@Override
public RECIPE fromNetwork(@Nonnull ResourceLocation recipeId, @Nonnull PacketBuffer buffer) {
try {
ItemStackIngredient inputIngredient = ItemStackIngredient.read(buffer);
FloatingLong output = FloatingLong.readFromBuffer(buffer);
return this.factory.create(recipeId, inputIngredient, output);
} catch (Exception e) {
Mekanism.logger.error("Error reading itemstack to energy recipe from packet.", e);
throw e;
}
}
use of mekanism.api.recipes.inputs.ItemStackIngredient 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);
}
use of mekanism.api.recipes.inputs.ItemStackIngredient 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;
}
}
Aggregations