use of mekanism.api.chemical.Chemical in project Mekanism by mekanism.
the class ChemicalCrystallizerInputRecipeCache method findFirstRecipe.
@Nullable
private <CHEMICAL extends Chemical<CHEMICAL>, STACK extends ChemicalStack<CHEMICAL>> ChemicalCrystallizerRecipe findFirstRecipe(ChemicalType type, STACK stack) {
Predicate<ChemicalCrystallizerRecipe> matchPredicate = recipe -> ((IChemicalStackIngredient<CHEMICAL, STACK>) recipe.getInput()).test(stack);
ChemicalInputCache<CHEMICAL, STACK, ChemicalCrystallizerRecipe> cache = (ChemicalInputCache<CHEMICAL, STACK, ChemicalCrystallizerRecipe>) typeBasedCache.get(type);
ChemicalCrystallizerRecipe recipe = cache.findFirstRecipe(stack, matchPredicate);
return recipe == null ? findFirstRecipe(typeBasedComplexRecipes.get(type), matchPredicate) : recipe;
}
use of mekanism.api.chemical.Chemical in project Mekanism by mekanism.
the class ChemicalCrystallizerInputRecipeCache method containsInput.
/**
* Checks if there is a matching recipe that has the given input.
*
* @param world World.
* @param input Recipe input.
*
* @return {@code true} if there is a match, {@code false} if there isn't.
*/
public <CHEMICAL extends Chemical<CHEMICAL>, STACK extends ChemicalStack<CHEMICAL>> boolean containsInput(@Nullable World world, CHEMICAL input) {
if (input.isEmptyType()) {
// Don't allow empty inputs
return false;
}
initCacheIfNeeded(world);
ChemicalType type = ChemicalType.getTypeFor(input);
STACK stack = (STACK) input.getStack(1);
return containsInput(type, stack) || typeBasedComplexRecipes.get(type).stream().anyMatch(recipe -> recipe.testType(stack));
}
use of mekanism.api.chemical.Chemical in project Mekanism by mekanism.
the class BaseCrTExampleProvider method getIngredientRepresentation.
private <CHEMICAL extends Chemical<CHEMICAL>, STACK extends ChemicalStack<CHEMICAL>> String getIngredientRepresentation(IChemicalStackIngredient<CHEMICAL, STACK> ingredient, String ingredientType, ChemicalIngredientDeserializer<CHEMICAL, STACK, ?> deserializer, Function<STACK, CommandStringDisplayable> singleDescription, CrTChemicalTagManager<CHEMICAL> tagManager) {
if (ingredient instanceof ChemicalStackIngredient.SingleIngredient) {
JsonObject serialized = ingredient.serialize().getAsJsonObject();
String stackRepresentation = singleDescription.apply(deserializer.deserializeStack(serialized)).getCommandString();
return ingredientType + ".from(" + stackRepresentation + ")";
} else if (ingredient instanceof ChemicalStackIngredient.TaggedIngredient) {
JsonObject serialized = ingredient.serialize().getAsJsonObject();
String tagRepresentation = tagManager.getTag(serialized.get(JsonConstants.TAG).getAsString()).getCommandString();
return ingredientType + ".from(" + tagRepresentation + ", " + serialized.getAsJsonPrimitive(JsonConstants.AMOUNT) + ")";
} else if (ingredient instanceof ChemicalStackIngredient.MultiIngredient) {
ChemicalStackIngredient.MultiIngredient<CHEMICAL, STACK, ?> multiIngredient = (ChemicalStackIngredient.MultiIngredient<CHEMICAL, STACK, ?>) ingredient;
StringBuilder builder = new StringBuilder(ingredientType + ".createMulti(");
if (!multiIngredient.forEachIngredient(i -> {
String rep = getIngredientRepresentation(i, ingredientType, deserializer, singleDescription, tagManager);
if (rep == null) {
return true;
}
builder.append(rep).append(", ");
return false;
})) {
// Remove trailing comma and space
builder.setLength(builder.length() - 2);
builder.append(")");
return builder.toString();
}
}
return null;
}
Aggregations