Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate PSS average IO into in and out #2353

Merged
merged 2 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ public class MetaTileEntityPowerSubstation extends MultiblockWithDisplayBase
private boolean isActive, isWorkingEnabled = true;

// Stats tracked for UI display
private long netIOLastSec;
private long averageIOLastSec;
private long netInLastSec;
private long averageInLastSec;
private long netOutLastSec;
private long averageOutLastSec;

public MetaTileEntityPowerSubstation(ResourceLocation metaTileEntityId) {
super(metaTileEntityId);
Expand Down Expand Up @@ -138,8 +140,10 @@ public void invalidateStructure() {
inputHatches = null;
outputHatches = null;
passiveDrain = 0;
netIOLastSec = 0;
averageIOLastSec = 0;
netInLastSec = 0;
averageInLastSec = 0;
netOutLastSec = 0;
averageOutLastSec = 0;
super.invalidateStructure();
}

Expand All @@ -149,25 +153,27 @@ protected void updateFormedValid() {
if (getOffsetTimer() % 20 == 0) {
// active here is just used for rendering
setActive(energyBank.hasEnergy());
averageIOLastSec = netIOLastSec / 20;
netIOLastSec = 0;
averageInLastSec = netInLastSec / 20;
averageOutLastSec = netOutLastSec / 20;
netInLastSec = 0;
netOutLastSec = 0;
}

if (isWorkingEnabled()) {
// Bank from Energy Input Hatches
long energyBanked = energyBank.fill(inputHatches.getEnergyStored());
inputHatches.changeEnergy(-energyBanked);
netIOLastSec += energyBanked;
netInLastSec += energyBanked;

// Passive drain
long energyPassiveDrained = energyBank.drain(getPassiveDrain());
netIOLastSec -= energyPassiveDrained;
netOutLastSec += energyPassiveDrained;

// Debank to Dynamo Hatches
long energyDebanked = energyBank
.drain(outputHatches.getEnergyCapacity() - outputHatches.getEnergyStored());
outputHatches.changeEnergy(energyDebanked);
netIOLastSec -= energyDebanked;
netOutLastSec += energyDebanked;
}
}
}
Expand Down Expand Up @@ -359,44 +365,44 @@ protected void addDisplayText(List<ITextComponent> textList) {
"gregtech.multiblock.power_substation.passive_drain",
passiveDrain));

// Average I/O line
TextFormatting averageIOColor = TextFormatting.GRAY;
if (isActive() && isWorkingEnabled() && averageIOLastSec == 0) {
// only set to yellow on zero if the machine is on, avoids a yellow "warning"
// color when the machine is first formed and not yet plugged in.
averageIOColor = TextFormatting.YELLOW;
} else if (averageIOLastSec > 0) {
averageIOColor = TextFormatting.GREEN;
} else if (averageIOLastSec < 0) {
averageIOColor = TextFormatting.RED;
}

ITextComponent averageIO = TextComponentUtil.stringWithColor(
averageIOColor,
TextFormattingUtil.formatNumbers(averageIOLastSec) + " EU/t");

// Average EU IN line
ITextComponent avgValue = TextComponentUtil.stringWithColor(
TextFormatting.GREEN,
TextFormattingUtil.formatNumbers(averageInLastSec) + " EU/t");
ITextComponent base = TextComponentUtil.translationWithColor(
TextFormatting.GRAY,
"gregtech.multiblock.power_substation.average_io",
averageIO);

"gregtech.multiblock.power_substation.average_in",
avgValue);
ITextComponent hover = TextComponentUtil.translationWithColor(
TextFormatting.GRAY,
"gregtech.multiblock.power_substation.average_io_hover");
"gregtech.multiblock.power_substation.average_in_hover");
tl.add(TextComponentUtil.setHover(base, hover));

// Average EU OUT line
avgValue = TextComponentUtil.stringWithColor(
TextFormatting.RED,
TextFormattingUtil.formatNumbers(averageOutLastSec) + " EU/t");
base = TextComponentUtil.translationWithColor(
TextFormatting.GRAY,
"gregtech.multiblock.power_substation.average_out",
avgValue);
hover = TextComponentUtil.translationWithColor(
TextFormatting.GRAY,
"gregtech.multiblock.power_substation.average_out_hover");
tl.add(TextComponentUtil.setHover(base, hover));

// Time to fill/drain line
if (averageIOLastSec > 0) {
if (averageInLastSec > averageOutLastSec) {
ITextComponent timeToFill = getTimeToFillDrainText(energyCapacity.subtract(energyStored)
.divide(BigInteger.valueOf(averageIOLastSec * 20)));
.divide(BigInteger.valueOf((averageInLastSec - averageOutLastSec) * 20)));
TextComponentUtil.setColor(timeToFill, TextFormatting.GREEN);
tl.add(TextComponentUtil.translationWithColor(
TextFormatting.GRAY,
"gregtech.multiblock.power_substation.time_to_fill",
timeToFill));
} else if (averageIOLastSec < 0) {
} else if (averageInLastSec < averageOutLastSec) {
ITextComponent timeToDrain = getTimeToFillDrainText(
energyStored.divide(BigInteger.valueOf(Math.abs(averageIOLastSec) * 20)));
energyStored.divide(BigInteger.valueOf((averageOutLastSec - averageInLastSec) * 20)));
TextComponentUtil.setColor(timeToDrain, TextFormatting.RED);
tl.add(TextComponentUtil.translationWithColor(
TextFormatting.GRAY,
Expand All @@ -412,9 +418,9 @@ protected void addDisplayText(List<ITextComponent> textList) {
protected void addWarningText(List<ITextComponent> textList) {
super.addWarningText(textList);
if (isStructureFormed()) {
if (averageIOLastSec < 0) { // decreasing
if (averageInLastSec < averageOutLastSec) { // decreasing
BigInteger timeToDrainSeconds = energyBank.getStored()
.divide(BigInteger.valueOf(Math.abs(averageIOLastSec) * 20));
.divide(BigInteger.valueOf((averageOutLastSec - averageInLastSec) * 20));
if (timeToDrainSeconds.compareTo(BigInteger.valueOf(60 * 60)) < 0) { // less than 1 hour left
textList.add(TextComponentUtil.translationWithColor(
TextFormatting.YELLOW,
Expand Down Expand Up @@ -550,8 +556,12 @@ public String getCapacity() {
return TextFormattingUtil.formatNumbers(energyBank.getCapacity());
}

public long getAverageIOLastSec() {
return averageIOLastSec;
public long getAverageInLastSec() {
return averageInLastSec;
}

public long getAverageOutLastSec() {
return averageOutLastSec;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,14 @@ public Object[] getPassiveDrain(final Context context, final Arguments args) {
return new Object[] { tileEntity.getPassiveDrain() };
}

@Callback(doc = "function():number -- Returns the average net EU/t in or out over the last second.")
public Object[] getAverageIOLastSec(final Context context, final Arguments args) {
return new Object[] { tileEntity.getAverageIOLastSec() };
@Callback(doc = "function():number -- Returns the average EU/t in over the last second.")
public Object[] getAverageInLastSec(final Context context, final Arguments args) {
return new Object[] { tileEntity.getAverageInLastSec() };
}

@Callback(doc = "function():number -- Returns the average EU/t out over the last second.")
public Object[] getAverageOutLastSec(final Context context, final Arguments args) {
return new Object[] { tileEntity.getAverageOutLastSec() };
}
}
}
6 changes: 4 additions & 2 deletions src/main/resources/assets/gregtech/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -5647,8 +5647,10 @@ gregtech.multiblock.computation.not_enough_computation=Machine needs more comput
gregtech.multiblock.power_substation.stored=Stored: %s
gregtech.multiblock.power_substation.capacity=Capacity: %s
gregtech.multiblock.power_substation.passive_drain=Passive Drain: %s
gregtech.multiblock.power_substation.average_io=Avg. I/O: %s
gregtech.multiblock.power_substation.average_io_hover=The average change in energy of the Power Substation's internal energy bank
gregtech.multiblock.power_substation.average_in=Avg. EU IN: %s
gregtech.multiblock.power_substation.average_out=Avg. EU OUT: %s
gregtech.multiblock.power_substation.average_in_hover=The average EU/t input into the Power Substation's internal energy bank
gregtech.multiblock.power_substation.average_out_hover=The average EU/t output from the Power Substation's internal energy bank, both passive loss and outputs
gregtech.multiblock.power_substation.time_to_fill=Time to fill: %s
gregtech.multiblock.power_substation.time_to_drain=Time to drain: %s
gregtech.multiblock.power_substation.time_seconds=%s Seconds
Expand Down
Loading