use of mekanism.common.integration.crafttweaker.example.component.CrTImportsComponent in project Mekanism by mekanism.
the class BaseCrTExampleProvider method getIngredientRepresentation.
private String getIngredientRepresentation(CrTImportsComponent imports, FluidStackIngredient ingredient) {
if (ingredient instanceof FluidStackIngredient.Single) {
JsonObject serialized = ingredient.serialize().getAsJsonObject();
String stackRepresentation = new MCFluidStack(SerializerHelper.deserializeFluid(serialized)).getCommandString();
return imports.addImport(CrTConstants.CLASS_FLUID_STACK_INGREDIENT) + ".from(" + stackRepresentation + ")";
} else if (ingredient instanceof FluidStackIngredient.Tagged) {
JsonObject serialized = ingredient.serialize().getAsJsonObject();
String tagRepresentation = TagManagerFluid.INSTANCE.getTag(serialized.get(JsonConstants.TAG).getAsString()).getCommandString();
return imports.addImport(CrTConstants.CLASS_FLUID_STACK_INGREDIENT) + ".from(" + tagRepresentation + ", " + serialized.getAsJsonPrimitive(JsonConstants.AMOUNT) + ")";
} else if (ingredient instanceof FluidStackIngredient.Multi) {
FluidStackIngredient.Multi multiIngredient = (FluidStackIngredient.Multi) ingredient;
StringBuilder builder = new StringBuilder(imports.addImport(CrTConstants.CLASS_FLUID_STACK_INGREDIENT) + ".createMulti(");
if (!multiIngredient.forEachIngredient(i -> {
String rep = getIngredientRepresentation(imports, i);
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;
}
use of mekanism.common.integration.crafttweaker.example.component.CrTImportsComponent in project Mekanism by mekanism.
the class CrTExampleBuilder method build.
public String build() {
int contentLength = contents.size();
if (contentLength == 0) {
invalidContents();
}
// TODO: Trim trailing and starting blank lines and check if empty again (may be best to do this *after* the string is built??)
// Though do we want it to just silently trim or do we want it to hard fail
StringBuilder preImports = new StringBuilder();
StringBuilder postImports = new StringBuilder();
for (int i = 0; i < contentLength; i++) {
ICrTExampleComponent component = contents.get(i);
if (component instanceof CrTImportsComponent) {
// Set imports being declared to false so that we move onto post imports
importsDeclared = false;
continue;
}
StringBuilder stringBuilder = importsDeclared ? preImports : postImports;
if (component != null) {
// Null components are blank lines and can be ignored here as the new line afterwards will be added when appropriate
stringBuilder.append(component.asString());
}
if (i < contentLength - 1) {
// If we are not on the last line add a new line after this
stringBuilder.append('\n');
}
}
return preImports.append(importsComponent.asString()).append(postImports).toString();
}
Aggregations