diff --git a/src/main/java/appeng/client/gui/AEBaseScreen.java b/src/main/java/appeng/client/gui/AEBaseScreen.java index 917d727e9cd..cdd2298c0b8 100644 --- a/src/main/java/appeng/client/gui/AEBaseScreen.java +++ b/src/main/java/appeng/client/gui/AEBaseScreen.java @@ -393,7 +393,13 @@ public void drawTooltipWithHeader(GuiGraphics guiGraphics, int x, int y, List s.withColor(ChatFormatting.WHITE))); } else { - formattedLines.add(lines.get(i)); + formattedLines.add(lines.get(i).copy().withStyle(s -> { + if (s.getColor() != null) { + return s; + } else { + return s.withColor(ChatFormatting.GRAY); + } + })); } } drawTooltip(guiGraphics, x, y, formattedLines); diff --git a/src/main/java/appeng/client/gui/me/networktool/NetworkStatusScreen.java b/src/main/java/appeng/client/gui/me/networktool/NetworkStatusScreen.java index b7be5c76d73..ad1da142aec 100644 --- a/src/main/java/appeng/client/gui/me/networktool/NetworkStatusScreen.java +++ b/src/main/java/appeng/client/gui/me/networktool/NetworkStatusScreen.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.List; +import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.network.chat.Component; @@ -87,7 +88,10 @@ public void drawFG(GuiGraphics guiGraphics, int offsetX, int offsetY, int mouseX final int viewEnd = viewStart + COLUMNS * ROWS; List tooltip = null; - List machines = status.getGroupedMachines(); + List machines = new ArrayList<>(status.getGroupedMachines()); + // Sort anything with a classifier to the front + machines.sort(MachineGroup.COMPARATOR); + for (int i = viewStart; i < Math.min(viewEnd, machines.size()); i++) { MachineGroup entry = machines.get(i); @@ -98,6 +102,10 @@ public void drawFG(GuiGraphics guiGraphics, int offsetX, int offsetY, int mouseX int itemX = cellX + CELL_WIDTH - 17; int itemY = cellY + 1; + if (entry.isMissingChannel()) { + guiGraphics.fill(cellX, cellY, cellX + CELL_WIDTH, cellY + CELL_HEIGHT, 0xffff5555); + } + drawMachineCount(guiGraphics, itemX, cellY, entry.getCount()); AEKeyRendering.drawInGui(Minecraft.getInstance(), guiGraphics, itemX, itemY, entry.getDisplay()); @@ -106,6 +114,9 @@ public void drawFG(GuiGraphics guiGraphics, int offsetX, int offsetY, int mouseX if (isHovering(cellX, cellY, CELL_WIDTH, CELL_HEIGHT, mouseX, mouseY)) { tooltip = new ArrayList<>(); tooltip.add(entry.getDisplay().getDisplayName()); + if (entry.isMissingChannel()) { + tooltip.add(GuiText.NoChannel.text().withStyle(ChatFormatting.RED)); + } tooltip.add(GuiText.Installed.text(entry.getCount())); if (entry.getIdlePowerUsage() > 0) { diff --git a/src/main/java/appeng/menu/me/networktool/MachineGroup.java b/src/main/java/appeng/menu/me/networktool/MachineGroup.java index 06d5c9beb26..df28f8f69f8 100644 --- a/src/main/java/appeng/menu/me/networktool/MachineGroup.java +++ b/src/main/java/appeng/menu/me/networktool/MachineGroup.java @@ -18,20 +18,28 @@ package appeng.menu.me.networktool; +import java.util.Comparator; + import net.minecraft.network.FriendlyByteBuf; +import appeng.api.networking.IGridNode; import appeng.api.stacks.AEItemKey; /** - * Represents the status of machines grouped by their {@link IGridBlock#getMachineRepresentation() item representation}. + * Represents the status of machines grouped by their {@linkplain IGridNode#getVisualRepresentation() item + * representation}. */ public class MachineGroup { + public static final Comparator COMPARATOR = Comparator.comparing(MachineGroup::isMissingChannel) + .thenComparingInt(MachineGroup::getCount) + .reversed(); + /** - * The item stack used for grouping machines together, which is also used for showing the group in the UI. + * The key used for grouping machines together, which is also used for showing the group in the UI. * - * @see IGridBlock#getMachineRepresentation() + * @see IGridNode#getVisualRepresentation() */ - private final AEItemKey display; + private final MachineGroupKey key; /** * Summed up idle power usage of this machine group in AE/t. @@ -43,28 +51,32 @@ public class MachineGroup { */ private int count; - MachineGroup(AEItemKey display) { - this.display = display; + MachineGroup(MachineGroupKey key) { + this.key = key; } /** * Reads back a machine group previously {@link #write(FriendlyByteBuf) written}. */ static MachineGroup read(FriendlyByteBuf data) { - MachineGroup entry = new MachineGroup(AEItemKey.fromPacket(data)); + MachineGroup entry = new MachineGroup(MachineGroupKey.fromPacket(data)); entry.idlePowerUsage = data.readDouble(); entry.count = data.readVarInt(); return entry; } void write(FriendlyByteBuf data) { - display.writeToPacket(data); + key.write(data); data.writeDouble(idlePowerUsage); data.writeVarInt(count); } public AEItemKey getDisplay() { - return display; + return key.display(); + } + + public boolean isMissingChannel() { + return key.missingChannel(); } public double getIdlePowerUsage() { diff --git a/src/main/java/appeng/menu/me/networktool/MachineGroupKey.java b/src/main/java/appeng/menu/me/networktool/MachineGroupKey.java new file mode 100644 index 00000000000..a01071ab8fe --- /dev/null +++ b/src/main/java/appeng/menu/me/networktool/MachineGroupKey.java @@ -0,0 +1,24 @@ +package appeng.menu.me.networktool; + +import net.minecraft.network.FriendlyByteBuf; + +import appeng.api.stacks.AEItemKey; + +/** + * The information by which machines are grouped together. + */ +record MachineGroupKey(AEItemKey display, boolean missingChannel) { + + public static MachineGroupKey fromPacket(FriendlyByteBuf data) { + var display = AEItemKey.fromPacket(data); + var missingChannel = data.readBoolean(); + return new MachineGroupKey(display, missingChannel); + + } + + public void write(FriendlyByteBuf data) { + display.writeToPacket(data); + data.writeBoolean(missingChannel); + } + +} diff --git a/src/main/java/appeng/menu/me/networktool/NetworkStatus.java b/src/main/java/appeng/menu/me/networktool/NetworkStatus.java index 00d2b3e5c8e..ad7e4b1dfc4 100644 --- a/src/main/java/appeng/menu/me/networktool/NetworkStatus.java +++ b/src/main/java/appeng/menu/me/networktool/NetworkStatus.java @@ -25,12 +25,13 @@ import com.google.common.collect.ImmutableList; +import org.jetbrains.annotations.Nullable; + import net.minecraft.network.FriendlyByteBuf; import appeng.api.networking.IGrid; import appeng.api.networking.IGridNode; import appeng.api.networking.energy.IEnergyService; -import appeng.api.stacks.AEItemKey; import appeng.client.gui.me.networktool.NetworkStatusScreen; /** @@ -62,15 +63,12 @@ public static NetworkStatus fromGrid(IGrid grid) { status.channelsUsed = grid.getPathingService().getUsedChannels(); // This is essentially a groupBy machineRepresentation + count, sum(idlePowerUsage) - Map groupedMachines = new HashMap<>(); + Map groupedMachines = new HashMap<>(); for (var machineClass : grid.getMachineClasses()) { for (IGridNode machine : grid.getMachineNodes(machineClass)) { - var ais = machine.getVisualRepresentation(); - if (ais != null) { - MachineGroup group = groupedMachines.get(ais); - if (group == null) { - groupedMachines.put(ais, group = new MachineGroup(ais)); - } + var key = getKey(machine); + if (key != null) { + var group = groupedMachines.computeIfAbsent(key, MachineGroup::new); group.setCount(group.getCount() + 1); group.setIdlePowerUsage(group.getIdlePowerUsage() + machine.getIdlePowerUsage()); @@ -82,6 +80,16 @@ public static NetworkStatus fromGrid(IGrid grid) { return status; } + @Nullable + private static MachineGroupKey getKey(IGridNode machine) { + var visualRepresentation = machine.getVisualRepresentation(); + if (visualRepresentation == null) { + return null; + } + + return new MachineGroupKey(visualRepresentation, !machine.meetsChannelRequirements()); + } + public double getAveragePowerInjection() { return averagePowerInjection; }