|
2 | 2 |
|
3 | 3 | import gregtech.api.GTValues; |
4 | 4 | import gregtech.api.capability.IEnergyContainer; |
| 5 | +import gregtech.api.recipes.Recipe; |
5 | 6 | import gregtech.api.util.GTUtility; |
6 | 7 | import gregtech.api.util.TextComponentUtil; |
7 | 8 | import gregtech.api.util.TextFormattingUtil; |
8 | 9 | import gregtech.common.ConfigHolder; |
9 | 10 |
|
| 11 | +import net.minecraft.item.ItemStack; |
10 | 12 | import net.minecraft.util.text.*; |
| 13 | +import net.minecraftforge.fluids.FluidStack; |
| 14 | + |
| 15 | +import org.jetbrains.annotations.Nullable; |
11 | 16 |
|
12 | 17 | import java.util.List; |
13 | 18 | import java.util.function.Consumer; |
@@ -478,5 +483,42 @@ public Builder addCustom(Consumer<List<ITextComponent>> customConsumer) { |
478 | 483 | customConsumer.accept(textList); |
479 | 484 | return this; |
480 | 485 | } |
| 486 | + |
| 487 | + /** While the Multiblock is active, add lines which display the outputs of the currently run recipe. */ |
| 488 | + public Builder addRecipeOutputsLine(@Nullable Recipe recipe) { |
| 489 | + if (!isStructureFormed || !isActive) { |
| 490 | + return this; |
| 491 | + } |
| 492 | + if (recipe == null) { |
| 493 | + return this; |
| 494 | + } |
| 495 | + if (!recipe.getAllItemOutputs().isEmpty()) { |
| 496 | + textList.add(TextComponentUtil.translationWithColor(TextFormatting.GRAY, |
| 497 | + "gregtech.multiblock.recipe_outputs", itemOutputsToString(recipe.getAllItemOutputs()))); |
| 498 | + } |
| 499 | + if (!recipe.getAllFluidOutputs().isEmpty()) { |
| 500 | + textList.add(TextComponentUtil.translationWithColor(TextFormatting.GRAY, |
| 501 | + "gregtech.multiblock.recipe_outputs", fluidOutputsToString(recipe.getAllFluidOutputs()))); |
| 502 | + } |
| 503 | + return this; |
| 504 | + } |
| 505 | + |
| 506 | + private String fluidOutputsToString(List<FluidStack> stacks) { |
| 507 | + StringBuilder output = new StringBuilder(); |
| 508 | + for (FluidStack stack : stacks) { |
| 509 | + output.append(stack.amount).append("L of ").append(stack.getLocalizedName()).append(", "); |
| 510 | + } |
| 511 | + String str = output.toString(); |
| 512 | + return str.substring(0, str.length() - 2); |
| 513 | + } |
| 514 | + |
| 515 | + private String itemOutputsToString(List<ItemStack> stacks) { |
| 516 | + StringBuilder output = new StringBuilder(); |
| 517 | + for (ItemStack stack : stacks) { |
| 518 | + output.append(stack.getCount()).append("x ").append(stack.getDisplayName()).append(", "); |
| 519 | + } |
| 520 | + String str = output.toString(); |
| 521 | + return str.substring(0, str.length() - 2); |
| 522 | + } |
481 | 523 | } |
482 | 524 | } |
0 commit comments