use of mekanism.api.recipes.inputs.ItemStackIngredient in project Mekanism by mekanism.
the class BiomesOPlentyRecipeProvider method dye.
private void dye(Consumer<IFinishedRecipe> consumer, String basePath, IItemProvider output, EnumColor color, IItemProvider... inputs) {
ItemStackIngredient inputIngredient = ItemStackIngredient.from(Ingredient.of(inputs));
ItemStackToItemStackRecipeBuilder.enriching(inputIngredient, new ItemStack(output, 2)).addCondition(modLoaded).build(consumer, Mekanism.rl(basePath + "dye/" + color.getRegistryPrefix()));
// Flowers -> 4x dye output (See PigmentExtractingRecipeProvider#addFlowerExtractionRecipes for note)
long flowerRate = 3 * PigmentExtractingRecipeProvider.DYE_RATE;
ItemStackToChemicalRecipeBuilder.pigmentExtracting(inputIngredient, MekanismPigments.PIGMENT_COLOR_LOOKUP.get(color).getStack(flowerRate)).addCondition(modLoaded).build(consumer, Mekanism.rl(basePath + "pigment_extracting/" + color.getRegistryPrefix()));
}
use of mekanism.api.recipes.inputs.ItemStackIngredient 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.ItemStackIngredient 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.ItemStackIngredient in project Mekanism by mekanism.
the class SawmillRecipeSerializer 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);
ItemStackIngredient inputIngredient = ItemStackIngredient.deserialize(input);
ItemStack mainOutput = ItemStack.EMPTY;
ItemStack secondaryOutput = ItemStack.EMPTY;
double secondaryChance = 0;
if (json.has(JsonConstants.SECONDARY_OUTPUT) || json.has(JsonConstants.SECONDARY_CHANCE)) {
if (json.has(JsonConstants.MAIN_OUTPUT)) {
// Allow for the main output to be optional if we have a secondary output
mainOutput = SerializerHelper.getItemStack(json, JsonConstants.MAIN_OUTPUT);
if (mainOutput.isEmpty()) {
throw new JsonSyntaxException("Sawmill main recipe output must not be empty, if it is defined.");
}
}
// If we have either json element for secondary information, assume we have both and fail if we can't get one of them
JsonElement chance = json.get(JsonConstants.SECONDARY_CHANCE);
if (!JSONUtils.isNumberValue(chance)) {
throw new JsonSyntaxException("Expected secondaryChance to be a number greater than zero.");
}
secondaryChance = chance.getAsJsonPrimitive().getAsDouble();
if (secondaryChance <= 0 || secondaryChance > 1) {
throw new JsonSyntaxException("Expected secondaryChance to be greater than zero, and less than or equal to one.");
}
secondaryOutput = SerializerHelper.getItemStack(json, JsonConstants.SECONDARY_OUTPUT);
if (secondaryOutput.isEmpty()) {
throw new JsonSyntaxException("Sawmill secondary recipe output must not be empty, if there is no main output.");
}
} else {
// If we don't have a secondary output require a main output
mainOutput = SerializerHelper.getItemStack(json, JsonConstants.MAIN_OUTPUT);
if (mainOutput.isEmpty()) {
throw new JsonSyntaxException("Sawmill main recipe output must not be empty, if there is no secondary output.");
}
}
return this.factory.create(recipeId, inputIngredient, mainOutput, secondaryOutput, secondaryChance);
}
use of mekanism.api.recipes.inputs.ItemStackIngredient in project Mekanism by mekanism.
the class ItemStackToChemicalRecipeSerializer 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);
ItemStackIngredient inputIngredient = ItemStackIngredient.deserialize(input);
STACK output = fromJson(json, JsonConstants.OUTPUT);
if (output.isEmpty()) {
throw new JsonSyntaxException("Recipe output must not be empty.");
}
return this.factory.create(recipeId, inputIngredient, output);
}
Aggregations