use of mekanism.api.recipes.PressurizedReactionRecipe in project Mekanism by mekanism.
the class PressurizedReactionRecipeMapper method handleRecipe.
@Override
public boolean handleRecipe(IMappingCollector<NormalizedSimpleStack, Long> mapper, IRecipe<?> iRecipe, INSSFakeGroupManager groupManager) {
if (!(iRecipe instanceof PressurizedReactionRecipe)) {
// Double check that we have a type of recipe we know how to handle
return false;
}
boolean handled = false;
PressurizedReactionRecipe recipe = (PressurizedReactionRecipe) iRecipe;
List<@NonNull ItemStack> itemRepresentations = recipe.getInputSolid().getRepresentations();
List<@NonNull FluidStack> fluidRepresentations = recipe.getInputFluid().getRepresentations();
List<@NonNull GasStack> gasRepresentations = recipe.getInputGas().getRepresentations();
for (ItemStack itemRepresentation : itemRepresentations) {
NormalizedSimpleStack nssItem = NSSItem.createItem(itemRepresentation);
for (FluidStack fluidRepresentation : fluidRepresentations) {
NormalizedSimpleStack nssFluid = NSSFluid.createFluid(fluidRepresentation);
for (GasStack gasRepresentation : gasRepresentations) {
NormalizedSimpleStack nssGas = NSSGas.createGas(gasRepresentation);
Pair<@NonNull ItemStack, @NonNull GasStack> output = recipe.getOutput(itemRepresentation, fluidRepresentation, gasRepresentation);
ItemStack itemOutput = output.getLeft();
GasStack gasOutput = output.getRight();
IngredientHelper ingredientHelper = new IngredientHelper(mapper);
ingredientHelper.put(nssItem, itemRepresentation.getCount());
ingredientHelper.put(nssFluid, fluidRepresentation.getAmount());
ingredientHelper.put(nssGas, gasRepresentation.getAmount());
if (itemOutput.isEmpty()) {
// We only have a gas output
if (!gasOutput.isEmpty() && ingredientHelper.addAsConversion(gasOutput)) {
handled = true;
}
} else if (gasOutput.isEmpty()) {
// We only have an item output
if (ingredientHelper.addAsConversion(itemOutput)) {
handled = true;
}
} else {
NormalizedSimpleStack nssItemOutput = NSSItem.createItem(itemOutput);
NormalizedSimpleStack nssGasOutput = NSSGas.createGas(gasOutput);
// We have both so do our best guess
// Add trying to calculate the item output (using it as if we needed negative of gas output)
ingredientHelper.put(nssGasOutput, -gasOutput.getAmount());
if (ingredientHelper.addAsConversion(nssItemOutput, itemOutput.getCount())) {
handled = true;
}
// Add trying to calculate gas output (using it as if we needed negative of item output)
ingredientHelper.resetHelper();
ingredientHelper.put(nssItem, itemRepresentation.getCount());
ingredientHelper.put(nssFluid, fluidRepresentation.getAmount());
ingredientHelper.put(nssGas, gasRepresentation.getAmount());
ingredientHelper.put(nssItemOutput, -itemOutput.getCount());
if (ingredientHelper.addAsConversion(nssGasOutput, gasOutput.getAmount())) {
handled = true;
}
}
}
}
}
return handled;
}
use of mekanism.api.recipes.PressurizedReactionRecipe in project Mekanism by mekanism.
the class TileEntityPressurizedReactionChamber method onCachedRecipeChanged.
@Override
public void onCachedRecipeChanged(@Nullable CachedRecipe<PressurizedReactionRecipe> cachedRecipe, int cacheIndex) {
int recipeDuration;
if (cachedRecipe == null) {
recipeDuration = BASE_DURATION;
recipeEnergyRequired = FloatingLong.ZERO;
} else {
PressurizedReactionRecipe recipe = cachedRecipe.getRecipe();
recipeDuration = recipe.getDuration();
recipeEnergyRequired = recipe.getEnergyRequired();
}
boolean update = baseTicksRequired != recipeDuration;
baseTicksRequired = recipeDuration;
if (update) {
recalculateUpgrades(Upgrade.SPEED);
}
// Ensure we take our recipe's energy per tick into account
energyContainer.updateEnergyPerTick();
}
Aggregations