|
6 | 6 | import com.gregtechceu.gtceu.api.capability.recipe.EURecipeCapability; |
7 | 7 | import com.gregtechceu.gtceu.api.capability.recipe.FluidRecipeCapability; |
8 | 8 | import com.gregtechceu.gtceu.api.capability.recipe.IO; |
9 | | -import com.gregtechceu.gtceu.api.gui.GuiTextures; |
10 | 9 | import com.gregtechceu.gtceu.api.gui.util.TimedProgressSupplier; |
11 | 10 | import com.gregtechceu.gtceu.api.machine.MetaMachine; |
12 | 11 | import com.gregtechceu.gtceu.api.machine.TickableSubscription; |
|
18 | 17 | import com.gregtechceu.gtceu.api.machine.trait.hpca.HPCAComputationProviderTrait; |
19 | 18 | import com.gregtechceu.gtceu.api.machine.trait.hpca.HPCACoolantProviderTrait; |
20 | 19 | import com.gregtechceu.gtceu.api.misc.EnergyContainerList; |
| 20 | +import com.gregtechceu.gtceu.api.mui.base.drawable.IDrawable; |
| 21 | +import com.gregtechceu.gtceu.api.mui.base.drawable.IKey; |
| 22 | +import com.gregtechceu.gtceu.api.mui.base.widget.IWidget; |
| 23 | +import com.gregtechceu.gtceu.api.mui.value.sync.GenericSyncValue; |
| 24 | +import com.gregtechceu.gtceu.api.mui.value.sync.PanelSyncManager; |
| 25 | +import com.gregtechceu.gtceu.api.mui.widgets.TextWidget; |
| 26 | +import com.gregtechceu.gtceu.api.mui.widgets.layout.Grid; |
21 | 27 | import com.gregtechceu.gtceu.api.pattern.util.RelativeDirection; |
22 | 28 | import com.gregtechceu.gtceu.api.sync_system.ISyncManaged; |
23 | 29 | import com.gregtechceu.gtceu.api.sync_system.SyncDataHolder; |
24 | 30 | import com.gregtechceu.gtceu.api.sync_system.annotations.SaveField; |
25 | 31 | import com.gregtechceu.gtceu.api.sync_system.annotations.SyncToClient; |
26 | 32 | import com.gregtechceu.gtceu.api.transfer.fluid.FluidHandlerList; |
| 33 | +import com.gregtechceu.gtceu.client.mui.screen.RichTooltip; |
| 34 | +import com.gregtechceu.gtceu.common.data.mui.GTMultiblockTextUtil; |
27 | 35 | import com.gregtechceu.gtceu.common.machine.multiblock.part.hpca.HPCAComponentPartMachine; |
| 36 | +import com.gregtechceu.gtceu.common.mui.GTGuiTextures; |
28 | 37 | import com.gregtechceu.gtceu.config.ConfigHolder; |
| 38 | +import com.gregtechceu.gtceu.utils.GTStringUtils; |
29 | 39 | import com.gregtechceu.gtceu.utils.GTTransferUtils; |
30 | | - |
31 | | -import com.lowdragmc.lowdraglib.gui.texture.ResourceTexture; |
| 40 | +import com.gregtechceu.gtceu.utils.serialization.network.ByteBufAdapters; |
32 | 41 |
|
33 | 42 | import net.minecraft.ChatFormatting; |
34 | 43 | import net.minecraft.MethodsReturnNonnullByDefault; |
|
39 | 48 | import net.minecraft.network.chat.MutableComponent; |
40 | 49 | import net.minecraft.server.TickTask; |
41 | 50 | import net.minecraft.server.level.ServerLevel; |
| 51 | +import net.minecraft.world.item.ItemStack; |
| 52 | +import net.minecraft.world.item.TooltipFlag; |
42 | 53 | import net.minecraft.world.level.Level; |
43 | 54 | import net.minecraftforge.fluids.FluidStack; |
44 | 55 | import net.minecraftforge.fluids.capability.IFluidHandler; |
@@ -240,6 +251,37 @@ private void consumeEnergy() { |
240 | 251 | } |
241 | 252 | } |
242 | 253 |
|
| 254 | + @Override |
| 255 | + public List<IWidget> getWidgetsForDisplay(PanelSyncManager syncManager) { |
| 256 | + if (isRemote()) { |
| 257 | + hpcaHandler.clearClientComponents(); |
| 258 | + if (isFormed()) { |
| 259 | + hpcaHandler.tryGatherClientComponents(getLevel(), getBlockPos(), getFrontFacing(), getUpwardsFacing(), |
| 260 | + isFlipped()); |
| 261 | + } |
| 262 | + } |
| 263 | + GenericSyncValue<Component> text = GenericSyncValue.builder(Component.class) |
| 264 | + .adapter(ByteBufAdapters.COMPONENT) |
| 265 | + .getter(() -> { |
| 266 | + List<Component> list = new ArrayList<>(); |
| 267 | + hpcaHandler.addErrors(list); |
| 268 | + hpcaHandler.addWarnings(list); |
| 269 | + hpcaHandler.addInfo(list); |
| 270 | + return GTStringUtils.toComponent(list); |
| 271 | + }) |
| 272 | + .build(); |
| 273 | + syncManager.syncValue("text", text); |
| 274 | + List<IWidget> widgets = new ArrayList<>(); |
| 275 | + widgets.add(GTMultiblockTextUtil.addWorkingStatusLine(this, syncManager)); |
| 276 | + widgets.add(GTMultiblockTextUtil.addEnergyUsageExactLine(this, syncManager)); |
| 277 | + widgets.add(new TextWidget<>(IKey.dynamic(text::getValue))); |
| 278 | + widgets.add(new Grid() |
| 279 | + .mapTo(3, 9, i -> hpcaHandler.getComponentTexture(i).asWidget() |
| 280 | + .tooltip(hpcaHandler.getComponentTooltip(i))) |
| 281 | + .horizontalCenter()); |
| 282 | + return widgets; |
| 283 | + } |
| 284 | + |
243 | 285 | // @Override |
244 | 286 | // public Widget createUIWidget() { |
245 | 287 | // WidgetGroup builder = (WidgetGroup) super.createUIWidget(); |
@@ -635,21 +677,25 @@ public int getMaxCoolantDemand() { |
635 | 677 | } |
636 | 678 |
|
637 | 679 | public void addInfo(List<Component> textList) { |
638 | | - // Max Computation |
639 | | - MutableComponent data = Component.literal(Integer.toString(getMaxCWUt())).withStyle(ChatFormatting.AQUA); |
640 | | - textList.add(Component.translatable("gtceu.multiblock.hpca.info_max_computation", data) |
| 680 | + // CWU/t |
| 681 | + Component cwutInfo = Component.literal(cachedCWUt + " / " + getMaxCWUt() + " CWU/t") |
| 682 | + .withStyle(ChatFormatting.AQUA); |
| 683 | + textList.add(Component.translatable("gtceu.multiblock.hpca.computation", cwutInfo) |
| 684 | + .withStyle(ChatFormatting.GRAY)); |
| 685 | + |
| 686 | + // Temperature |
| 687 | + Component tempInfo = Component.literal(Math.round(controller.temperature / 10.0D) + " °C") |
| 688 | + .withStyle(controller.getDisplayTemperatureColor()); |
| 689 | + textList.add(Component.translatable("gtceu.multiblock.hpca.temperature", tempInfo) |
641 | 690 | .withStyle(ChatFormatting.GRAY)); |
642 | 691 |
|
643 | 692 | // Cooling |
644 | 693 | ChatFormatting coolingColor = getMaxCoolingAmount() < getMaxCoolingDemand() ? ChatFormatting.RED : |
645 | 694 | ChatFormatting.GREEN; |
646 | | - data = Component.literal(Integer.toString(getMaxCoolingDemand())).withStyle(coolingColor); |
647 | | - textList.add(Component.translatable("gtceu.multiblock.hpca.info_max_cooling_demand", data) |
648 | | - .withStyle(ChatFormatting.GRAY)); |
649 | | - |
650 | | - data = Component.literal(Integer.toString(getMaxCoolingAmount())).withStyle(coolingColor); |
651 | | - textList.add(Component.translatable("gtceu.multiblock.hpca.info_max_cooling_available", data) |
652 | | - .withStyle(ChatFormatting.GRAY)); |
| 695 | + MutableComponent data = Component.literal(Integer.toString(getMaxCoolingDemand())).withStyle(coolingColor); |
| 696 | + textList.add( |
| 697 | + Component.translatable("gtceu.multiblock.hpca.info_cooling_demand", data, getMaxCoolingAmount()) |
| 698 | + .withStyle(ChatFormatting.GRAY)); |
653 | 699 |
|
654 | 700 | // Coolant Required |
655 | 701 | if (getMaxCoolantDemand() > 0) { |
@@ -702,13 +748,26 @@ public void addErrors(List<Component> textList) { |
702 | 748 | } |
703 | 749 | } |
704 | 750 |
|
705 | | - public ResourceTexture getComponentTexture(int index) { |
| 751 | + public IDrawable getComponentTexture(int index) { |
706 | 752 | if (components.size() <= index) { |
707 | | - return GuiTextures.BLANK_TRANSPARENT; |
| 753 | + return GTGuiTextures.BLANK_TRANSPARENT; |
708 | 754 | } |
709 | 755 | if (components.get(index).getMachine() instanceof HPCAComponentPartMachine componentPartMachine) |
710 | 756 | return componentPartMachine.getComponentIcon(); |
711 | | - return GuiTextures.BLANK_TRANSPARENT; |
| 757 | + return GTGuiTextures.BLANK_TRANSPARENT; |
| 758 | + } |
| 759 | + |
| 760 | + public RichTooltip getComponentTooltip(int index) { |
| 761 | + if (components.size() <= index) { |
| 762 | + return new RichTooltip(); |
| 763 | + } |
| 764 | + if (components.get(index).getMachine() instanceof HPCAComponentPartMachine componentPartMachine) { |
| 765 | + ItemStack stack = componentPartMachine.getDefinition().asStack(); |
| 766 | + RichTooltip tooltip = new RichTooltip(); |
| 767 | + stack.getTooltipLines(null, TooltipFlag.NORMAL).forEach(tooltip::addLine); |
| 768 | + return tooltip; |
| 769 | + } |
| 770 | + return new RichTooltip(); |
712 | 771 | } |
713 | 772 |
|
714 | 773 | public void tryGatherClientComponents(Level world, BlockPos pos, Direction frontFacing, |
|
0 commit comments