Skip to content

Commit

Permalink
Highlight devices missing a channel on the network status screen
Browse files Browse the repository at this point in the history
  • Loading branch information
shartte committed Mar 12, 2024
1 parent 0f1a638 commit 2185264
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 22 deletions.
1 change: 1 addition & 0 deletions src/generated/resources/assets/ae2/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@
"gui.ae2.Empty": "Empty",
"gui.ae2.Encoded": "Encoded",
"gui.ae2.EnergyDrain": "Passive Drain: %s",
"gui.ae2.EnergyGenerationCapacity": "Generation Capacity: %s",
"gui.ae2.EnergyLevelEmitter": "ME Energy Level Emitter",
"gui.ae2.Excluded": "Excluded",
"gui.ae2.ExportBus": "ME Export Bus",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,10 @@ public interface IPassiveEnergyGenerator extends IGridNodeService {
*/
void setSuppressed(boolean suppressed);

/**
* @return Whether this generator is currently suppressed.
* @see #setSuppressed(boolean)
*/
boolean isSuppressed();

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ public double getRate() {
return AEConfig.instance().getCrystalResonanceGeneratorRate();
}

@Override
public boolean isSuppressed() {
return CrystalResonanceGeneratorBlockEntity.this.suppressed;
}

@Override
public void setSuppressed(boolean suppressed) {
if (suppressed != CrystalResonanceGeneratorBlockEntity.this.suppressed) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,6 @@

package appeng.client.gui.me.networktool;

import java.util.ArrayList;
import java.util.List;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.player.Inventory;

import appeng.api.client.AEKeyRendering;
import appeng.client.gui.AEBaseScreen;
import appeng.client.gui.style.PaletteColor;
Expand All @@ -37,6 +29,14 @@
import appeng.menu.me.networktool.NetworkStatus;
import appeng.menu.me.networktool.NetworkStatusMenu;
import appeng.util.Platform;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.player.Inventory;

import java.util.ArrayList;
import java.util.List;

public class NetworkStatusScreen extends AEBaseScreen<NetworkStatusMenu> {

Expand All @@ -56,7 +56,7 @@ public class NetworkStatusScreen extends AEBaseScreen<NetworkStatusMenu> {
private final Scrollbar scrollbar;

public NetworkStatusScreen(NetworkStatusMenu menu, Inventory playerInventory,
Component title, ScreenStyle style) {
Component title, ScreenStyle style) {
super(menu, playerInventory, title, style);
this.scrollbar = widgets.addScrollBar("scrollbar");

Expand All @@ -80,7 +80,7 @@ protected void updateBeforeRender() {

@Override
public void drawFG(GuiGraphics guiGraphics, int offsetX, int offsetY, int mouseX,
int mouseY) {
int mouseY) {
int x = 0;
int y = 0;
final int viewStart = scrollbar.getCurrentScroll() * COLUMNS;
Expand Down Expand Up @@ -112,6 +112,10 @@ public void drawFG(GuiGraphics guiGraphics, int offsetX, int offsetY, int mouseX
tooltip.add(GuiText.EnergyDrain
.text(Platform.formatPower(entry.getIdlePowerUsage(), true)));
}
if (entry.getPowerGenerationCapacity() > 0) {
tooltip.add(GuiText.EnergyGenerationCapacity
.text(Platform.formatPower(entry.getPowerGenerationCapacity(), true)));
}
}

if (++x >= COLUMNS) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/appeng/core/localization/GuiText.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public enum GuiText implements LocalizationEnum {
Empty("Empty"),
Encoded("Encoded"),
EnergyDrain("Passive Drain: %s"),
EnergyGenerationCapacity("Generation Capacity: %s"),
EnergyLevelEmitter("ME Energy Level Emitter"),
Excluded("Excluded"),
ExportBus("ME Export Bus"),
Expand Down
23 changes: 22 additions & 1 deletion src/main/java/appeng/menu/me/networktool/MachineGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@

package appeng.menu.me.networktool;

import appeng.api.networking.IGridNode;
import appeng.api.stacks.AEItemKey;
import net.minecraft.core.BlockPos;
import net.minecraft.network.FriendlyByteBuf;

import appeng.api.stacks.AEItemKey;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Set;

/**
* Represents the status of machines grouped by their {@link IGridBlock#getMachineRepresentation() item representation}.
Expand All @@ -38,6 +43,11 @@ public class MachineGroup {
*/
private double idlePowerUsage;

/**
* The sum of power this group of machines can generate in AE/t.
*/
private double powerGenerationCapacity;

/**
* The number of machines in this group.
*/
Expand All @@ -53,13 +63,15 @@ public class MachineGroup {
static MachineGroup read(FriendlyByteBuf data) {
MachineGroup entry = new MachineGroup(AEItemKey.fromPacket(data));
entry.idlePowerUsage = data.readDouble();
entry.powerGenerationCapacity = data.readDouble();
entry.count = data.readVarInt();
return entry;
}

void write(FriendlyByteBuf data) {
display.writeToPacket(data);
data.writeDouble(idlePowerUsage);
data.writeDouble(powerGenerationCapacity);
data.writeVarInt(count);
}

Expand All @@ -75,11 +87,20 @@ void setIdlePowerUsage(double idlePowerUsage) {
this.idlePowerUsage = idlePowerUsage;
}

public double getPowerGenerationCapacity() {
return powerGenerationCapacity;
}

public void setPowerGenerationCapacity(double powerGenerationCapacity) {
this.powerGenerationCapacity = powerGenerationCapacity;
}

public int getCount() {
return count;
}

void setCount(int count) {
this.count = count;
}

}
34 changes: 23 additions & 11 deletions src/main/java/appeng/menu/me/networktool/NetworkStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,24 @@

package appeng.menu.me.networktool;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.google.common.collect.ImmutableList;

import net.minecraft.network.FriendlyByteBuf;

import appeng.api.implementations.parts.ICablePart;
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridNode;
import appeng.api.networking.energy.IEnergyService;
import appeng.api.stacks.AEItemKey;
import appeng.api.networking.energy.IPassiveEnergyGenerator;
import appeng.blockentity.misc.VibrationChamberBlockEntity;
import appeng.client.gui.me.networktool.NetworkStatusScreen;
import appeng.parts.AEBasePart;
import com.google.common.collect.ImmutableList;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.block.entity.BlockEntity;
import org.jetbrains.annotations.Nullable;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* Contains statistics about an ME network and the machines that form it.
Expand Down Expand Up @@ -74,6 +78,15 @@ public static NetworkStatus fromGrid(IGrid grid) {

group.setCount(group.getCount() + 1);
group.setIdlePowerUsage(group.getIdlePowerUsage() + machine.getIdlePowerUsage());

var owner = machine.getOwner();
var passiveEnergyGenerator =machine.getService(IPassiveEnergyGenerator.class);
if (passiveEnergyGenerator != null && !passiveEnergyGenerator.isSuppressed()) {
group.setPowerGenerationCapacity(group.getPowerGenerationCapacity() + passiveEnergyGenerator.getRate());
}
if (owner instanceof VibrationChamberBlockEntity vibrationChamberBlockEntity) {
group.setPowerGenerationCapacity(group.getPowerGenerationCapacity() + vibrationChamberBlockEntity.getMaxEnergyRate());
}
}
}
}
Expand Down Expand Up @@ -150,5 +163,4 @@ public void write(FriendlyByteBuf data) {
machine.write(data);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package appeng.menu.me.networktool;

import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.MenuType;

Expand Down

0 comments on commit 2185264

Please sign in to comment.