use of moze_intel.projecte.api.nss.NormalizedSimpleStack in project Mekanism by mekanism.
the class PaintingMachineRecipeMapper method handleRecipe.
@Override
public boolean handleRecipe(IMappingCollector<NormalizedSimpleStack, Long> mapper, IRecipe<?> iRecipe, INSSFakeGroupManager groupManager) {
if (!(iRecipe instanceof PaintingRecipe)) {
// Double check that we have a type of recipe we know how to handle
return false;
}
boolean handled = false;
PaintingRecipe recipe = (PaintingRecipe) iRecipe;
List<@NonNull PigmentStack> pigmentRepresentations = recipe.getChemicalInput().getRepresentations();
List<@NonNull ItemStack> itemRepresentations = recipe.getItemInput().getRepresentations();
for (PigmentStack pigmentRepresentation : pigmentRepresentations) {
NormalizedSimpleStack nssPigment = NSSPigment.createPigment(pigmentRepresentation);
for (ItemStack itemRepresentation : itemRepresentations) {
ItemStack output = recipe.getOutput(itemRepresentation, pigmentRepresentation);
if (!output.isEmpty()) {
IngredientHelper ingredientHelper = new IngredientHelper(mapper);
ingredientHelper.put(nssPigment, pigmentRepresentation.getAmount());
ingredientHelper.put(itemRepresentation);
if (ingredientHelper.addAsConversion(output)) {
handled = true;
}
}
}
}
return handled;
}
use of moze_intel.projecte.api.nss.NormalizedSimpleStack in project Mekanism by mekanism.
the class PigmentMixerRecipeMapper method handleRecipe.
@Override
public boolean handleRecipe(IMappingCollector<NormalizedSimpleStack, Long> mapper, IRecipe<?> iRecipe, INSSFakeGroupManager groupManager) {
if (!(iRecipe instanceof PigmentMixingRecipe)) {
// Double check that we have a type of recipe we know how to handle
return false;
}
boolean handled = false;
PigmentMixingRecipe recipe = (PigmentMixingRecipe) iRecipe;
List<@NonNull PigmentStack> leftInputRepresentations = recipe.getLeftInput().getRepresentations();
List<@NonNull PigmentStack> rightInputRepresentations = recipe.getRightInput().getRepresentations();
for (PigmentStack leftRepresentation : leftInputRepresentations) {
NormalizedSimpleStack nssLeft = NSSPigment.createPigment(leftRepresentation);
for (PigmentStack rightRepresentation : rightInputRepresentations) {
PigmentStack output = recipe.getOutput(leftRepresentation, rightRepresentation);
if (!output.isEmpty()) {
IngredientHelper ingredientHelper = new IngredientHelper(mapper);
ingredientHelper.put(nssLeft, leftRepresentation.getAmount());
ingredientHelper.put(rightRepresentation);
if (ingredientHelper.addAsConversion(output)) {
handled = true;
}
}
}
}
return handled;
}
use of moze_intel.projecte.api.nss.NormalizedSimpleStack 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 moze_intel.projecte.api.nss.NormalizedSimpleStack in project Mekanism by mekanism.
the class SawmillRecipeMapper method handleRecipe.
@Override
public boolean handleRecipe(IMappingCollector<NormalizedSimpleStack, Long> mapper, IRecipe<?> iRecipe, INSSFakeGroupManager groupManager) {
if (!(iRecipe instanceof SawmillRecipe)) {
// Double check that we have a type of recipe we know how to handle
return false;
}
SawmillRecipe recipe = (SawmillRecipe) iRecipe;
ItemStackIngredient input = recipe.getInput();
int primaryMultiplier = 1;
int secondaryMultiplier = 1;
if (recipe.getSecondaryChance() > 0 && recipe.getSecondaryChance() < 1) {
Fraction multiplier;
try {
multiplier = Fraction.getFraction(recipe.getSecondaryChance()).invert();
} catch (ArithmeticException e) {
// If we couldn't turn it into a fraction, then note we failed to convert the recipe
return false;
}
primaryMultiplier = multiplier.getNumerator();
secondaryMultiplier = multiplier.getDenominator();
}
boolean handled = false;
for (ItemStack representation : input.getRepresentations()) {
ChanceOutput output = recipe.getOutput(representation);
ItemStack mainOutput = output.getMainOutput();
ItemStack secondaryOutput = output.getMaxSecondaryOutput();
NormalizedSimpleStack nssInput = NSSItem.createItem(representation);
IngredientHelper ingredientHelper = new IngredientHelper(mapper);
if (secondaryOutput.isEmpty()) {
// We only have a main output
if (!mainOutput.isEmpty()) {
ingredientHelper.put(nssInput, representation.getCount());
if (ingredientHelper.addAsConversion(mainOutput)) {
handled = true;
}
}
} else if (mainOutput.isEmpty()) {
// We only have a secondary output
ingredientHelper.put(nssInput, representation.getCount() * primaryMultiplier);
if (ingredientHelper.addAsConversion(NSSItem.createItem(secondaryOutput), secondaryOutput.getCount() * secondaryMultiplier)) {
handled = true;
}
} else {
NormalizedSimpleStack nssMainOutput = NSSItem.createItem(mainOutput);
NormalizedSimpleStack nssSecondaryOutput = NSSItem.createItem(secondaryOutput);
// We have both so do our best guess by trying to subtract them from each other
// Add trying to calculate the main output (using it as if we needed negative of secondary output)
ingredientHelper.put(nssInput, representation.getCount() * primaryMultiplier);
ingredientHelper.put(nssSecondaryOutput, -secondaryOutput.getCount() * secondaryMultiplier);
if (ingredientHelper.addAsConversion(nssMainOutput, mainOutput.getCount() * primaryMultiplier)) {
handled = true;
}
// Add trying to calculate secondary output (using it as if we needed negative of main output)
ingredientHelper.resetHelper();
ingredientHelper.put(nssInput, representation.getCount() * primaryMultiplier);
ingredientHelper.put(nssMainOutput, -mainOutput.getCount() * primaryMultiplier);
if (ingredientHelper.addAsConversion(nssSecondaryOutput, secondaryOutput.getCount() * secondaryMultiplier)) {
handled = true;
}
}
}
return handled;
}
Aggregations