Skip to content

Commit

Permalink
Show the energy generation capacity of machines in the network status (
Browse files Browse the repository at this point in the history
  • Loading branch information
shartte authored Mar 12, 2024
1 parent 1de72ef commit 8d80b6a
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 1 deletion.
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 @@ -123,6 +123,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
16 changes: 16 additions & 0 deletions src/main/java/appeng/menu/me/networktool/MachineGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,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 @@ -61,13 +66,15 @@ public class MachineGroup {
static MachineGroup read(FriendlyByteBuf data) {
MachineGroup entry = new MachineGroup(MachineGroupKey.fromPacket(data));
entry.idlePowerUsage = data.readDouble();
entry.powerGenerationCapacity = data.readDouble();
entry.count = data.readVarInt();
return entry;
}

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

Expand All @@ -87,11 +94,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;
}

}
14 changes: 13 additions & 1 deletion src/main/java/appeng/menu/me/networktool/NetworkStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridNode;
import appeng.api.networking.energy.IEnergyService;
import appeng.api.networking.energy.IPassiveEnergyGenerator;
import appeng.blockentity.misc.VibrationChamberBlockEntity;
import appeng.client.gui.me.networktool.NetworkStatusScreen;

/**
Expand Down Expand Up @@ -72,6 +74,17 @@ 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 @@ -158,5 +171,4 @@ public void write(FriendlyByteBuf data) {
machine.write(data);
}
}

}

0 comments on commit 8d80b6a

Please sign in to comment.