use of com.blamejared.crafttweaker.api.brackets.CommandStringDisplayable 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