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

Add network bytes information for network status gui #419

Merged
merged 40 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
ba686f9
Add network bytes infomation for network status gui
MCTBL Oct 31, 2023
2fdbe14
Add network bytes infomation for network status gui
MCTBL Oct 31, 2023
d31900e
Update src/main/java/appeng/me/cache/GridStorageCache.java
MCTBL Oct 31, 2023
93fc689
swap some of Class.forName to instanceof
MCTBL Oct 31, 2023
80f7e1e
Merge branch 'master' into dev
MCTBL Oct 31, 2023
c94206a
Merge pull request #1 from MCTBL/dev
MCTBL Oct 31, 2023
e4a10fd
make cache update delay
MCTBL Oct 31, 2023
1ed5568
make cache update delay
MCTBL Oct 31, 2023
0524da5
Change error conditions
MCTBL Oct 31, 2023
4869ca9
Change delay from 1000t(50s) to 100t(5s)
MCTBL Oct 31, 2023
13fe5b0
Let cache update data at the beginning
MCTBL Oct 31, 2023
d09184e
Add a cfg that can change the cache update rate
MCTBL Nov 1, 2023
01dde62
Merge branch 'GTNewHorizons:master' into master
MCTBL Nov 2, 2023
1bc8db3
Add fluid bytes information
MCTBL Nov 2, 2023
e3da6a9
Add essentia status and change gui form
MCTBL Nov 3, 2023
f13174d
Apply the spotlessApply
MCTBL Nov 3, 2023
9747e1f
Delete useless rows
MCTBL Nov 3, 2023
ff3b6ee
Delete useless rows
MCTBL Nov 3, 2023
864bbd4
Revert "Merge branch 'GTNewHorizons:master' into master"
MCTBL Nov 3, 2023
de4eaea
Revert "Revert "Merge branch 'GTNewHorizons:master' into master""
MCTBL Nov 3, 2023
597a078
back roll some commits
MCTBL Nov 3, 2023
229c3e7
Merge branch 'master' into dev
MCTBL Nov 3, 2023
fd3eda1
Merge pull request #2 from MCTBL/dev
MCTBL Nov 3, 2023
ce9efce
delete incorrect import and depends
MCTBL Nov 3, 2023
bb1f4ec
Change interface's name
MCTBL Nov 3, 2023
a8334ba
Remove wrong annotations
MCTBL Nov 4, 2023
df8b2b3
Add new AdvancedNetworkTool
MCTBL Nov 5, 2023
9a6fb39
Add the Advanced Network Tool gui
MCTBL Nov 6, 2023
4a8bb6f
Add the advanced toolbox for other Gui
MCTBL Nov 7, 2023
4697694
Update Build Script
MCTBL Nov 7, 2023
025d595
Add recipe into AE and fix some issue
MCTBL Nov 9, 2023
8369c39
Fix the wrong info when cell in ME chest
MCTBL Nov 10, 2023
781e19f
Add external buttons for advanced network status
MCTBL Nov 11, 2023
4323385
Merge branch 'master' into master
MCTBL Nov 11, 2023
8872428
merge with main branch
MCTBL Nov 11, 2023
2b999db
Apply spotless
MCTBL Nov 12, 2023
ddb9cc3
Add external Gui for advanced network tool
MCTBL Nov 12, 2023
39c01cb
Add more info to new Gui
MCTBL Nov 14, 2023
41b822b
Apply spotless
MCTBL Nov 14, 2023
f01f40c
Replace some class to interface
MCTBL Nov 15, 2023
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 @@ -53,4 +53,5 @@ public interface IStorageGrid extends IGridCache, IStorageMonitorable {
* remove a provider added with addCellContainer
*/
void unregisterCellProvider(ICellProvider cc);

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

package appeng.client.gui.implementations;

import java.text.DecimalFormat;
import java.util.List;

import net.minecraft.client.gui.GuiButton;
Expand Down Expand Up @@ -51,7 +52,7 @@ public GuiNetworkStatus(final InventoryPlayer inventoryPlayer, final INetworkToo

this.setScrollBar(scrollbar);
this.repo = new ItemRepo(scrollbar, this);
this.ySize = 153;
this.ySize = 183;
this.xSize = 195;
this.repo.setRowSize(5);
}
Expand Down Expand Up @@ -115,7 +116,7 @@ public void drawScreen(final int mouseX, final int mouseY, final float btn) {
@Override
public void drawFG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) {
final ContainerNetworkStatus ns = (ContainerNetworkStatus) this.inventorySlots;

final DecimalFormat df = new DecimalFormat("#.##");
MCTBL marked this conversation as resolved.
Show resolved Hide resolved
this.fontRendererObj
.drawString(GuiText.NetworkDetails.getLocal(), 8, 6, GuiColors.NetworkStatusDetails.getColor());

Expand All @@ -140,6 +141,29 @@ public void drawFG(final int offsetX, final int offsetY, final int mouseX, final
13,
143 - 20,
GuiColors.NetworkStatusPowerUsageRate.getColor());
this.fontRendererObj.drawString(
GuiText.ByteTotal.getLocal() + ": " + Platform.formatByteLong(ns.getItemBytesTotal()),
13,
143,
GuiColors.NetworkStatusPowerUsageRate.getColor());
this.fontRendererObj.drawString(
GuiText.ByteUsage.getLocal() + ": "
+ Platform.formatByteLong(ns.getItemBytesUsed())
+ " ("
+ df.format(ns.getItemBytesUsed() * 100d / ns.getItemBytesTotal())
+ "%)",
13,
143 + 10,
GuiColors.NetworkStatusPowerUsageRate.getColor());
this.fontRendererObj.drawString(
GuiText.ByteFree.getLocal() + ": "
+ Platform.formatByteLong(ns.getItemBytesFree())
+ " ("
+ df.format(ns.getItemBytesFree() * 100d / ns.getItemBytesTotal())
+ "%)",
13,
143 + 20,
GuiColors.NetworkStatusPowerUsageRate.getColor());

final int sectionLength = 30;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@
import appeng.api.networking.IGridHost;
import appeng.api.networking.IGridNode;
import appeng.api.networking.energy.IEnergyGrid;
import appeng.api.networking.storage.IStorageGrid;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.container.AEBaseContainer;
import appeng.container.guisync.GuiSync;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketMEInventoryUpdate;
import appeng.me.cache.GridStorageCache;
import appeng.util.Platform;
import appeng.util.item.AEItemStack;

Expand All @@ -49,6 +51,15 @@ public class ContainerNetworkStatus extends AEBaseContainer {
@GuiSync(3)
public long maxPower;

@GuiSync(4)
public long itemBytesTotal;

@GuiSync(5)
public long itemBytesUsed;

@GuiSync(6)
public long itemBytesFree;

private IGrid network;
private int delay = 40;

Expand Down Expand Up @@ -121,6 +132,12 @@ public void detectAndSendChanges() {
} catch (final IOException e) {
// :P
}
final GridStorageCache sg = this.network.getCache(IStorageGrid.class);
if (sg != null) {
this.setItemBytesTotal(sg.getItemBytesTotal());
this.setItemBytesUsed(sg.getItemBytesUsed());
this.setItemBytesFree(this.getItemBytesTotal() - this.getItemBytesUsed());
}
}
super.detectAndSendChanges();
}
Expand Down Expand Up @@ -156,4 +173,28 @@ public long getPowerUsage() {
private void setPowerUsage(final long powerUsage) {
this.powerUsage = powerUsage;
}

public long getItemBytesTotal() {
return this.itemBytesTotal;
}

public long getItemBytesUsed() {
return this.itemBytesUsed;
}

public long getItemBytesFree() {
return this.itemBytesFree;
}

public void setItemBytesTotal(final long itemBytesTotal) {
this.itemBytesTotal = itemBytesTotal;
}

public void setItemBytesUsed(final long itemBytesUsed) {
this.itemBytesUsed = itemBytesUsed;
}

public void setItemBytesFree(final long itemBytesFree) {
this.itemBytesFree = itemBytesFree;
}
}
7 changes: 6 additions & 1 deletion src/main/java/appeng/core/localization/GuiText.java
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,12 @@ public enum GuiText {
VoidCellTooltip,

// If a thing is deprecated
Deprecated;
Deprecated,

// mine
ByteTotal,
ByteUsage,
ByteFree;

private final String root;

Expand Down
42 changes: 42 additions & 0 deletions src/main/java/appeng/me/cache/GridStorageCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
import appeng.api.storage.data.IAEStack;
import appeng.api.storage.data.IItemList;
import appeng.me.helpers.GenericInterestManager;
import appeng.me.storage.CellInventoryHandler;
import appeng.me.storage.DriveWatcher;
import appeng.me.storage.ItemWatcher;
import appeng.me.storage.NetworkInventoryHandler;

Expand All @@ -58,6 +60,10 @@ public class GridStorageCache implements IStorageGrid {
private NetworkInventoryHandler<IAEItemStack> myItemNetwork;
private NetworkInventoryHandler<IAEFluidStack> myFluidNetwork;

// mine
private long itemBytesTotal;
private long itemBytesUsed;

public GridStorageCache(final IGrid g) {
this.myGrid = g;
}
Expand All @@ -66,6 +72,32 @@ public GridStorageCache(final IGrid g) {
public void onUpdateTick() {
this.itemMonitor.onTick();
this.fluidMonitor.onTick();

this.itemBytesTotal = 0;
this.itemBytesUsed = 0;
try {
MCTBL marked this conversation as resolved.
Show resolved Hide resolved
for (ICellProvider icp : this.activeCellProviders) {
if (icp.getClass() == Class.forName("appeng.tile.storage.TileDrive")) {
MCTBL marked this conversation as resolved.
Show resolved Hide resolved
MCTBL marked this conversation as resolved.
Show resolved Hide resolved
// All Item Cell
for (IMEInventoryHandler meih : icp.getCellArray(StorageChannel.ITEMS)) {
Laiff marked this conversation as resolved.
Show resolved Hide resolved
MCTBL marked this conversation as resolved.
Show resolved Hide resolved
if (((DriveWatcher<IAEItemStack>) meih).getInternal().getClass()
MCTBL marked this conversation as resolved.
Show resolved Hide resolved
== Class.forName("appeng.me.storage.VoidCellInventory")) { // exclude void cell and
// creative cell
continue;
}
if (((CellInventoryHandler) (((DriveWatcher<IAEItemStack>) meih).getInternal())).getCellInv()
!= null) {
itemBytesTotal += ((CellInventoryHandler) (((DriveWatcher<IAEItemStack>) meih)
.getInternal())).getCellInv().getTotalBytes();
itemBytesUsed += ((CellInventoryHandler) (((DriveWatcher<IAEItemStack>) meih)
.getInternal())).getCellInv().getUsedBytes();
}
}
}
}
} catch (ClassNotFoundException e) {
// XD
}
}

@Override
Expand Down Expand Up @@ -196,6 +228,7 @@ public void cellUpdate(final MENetworkCellArrayUpdate ev) {
this.fluidMonitor.forceUpdate();

tracker.applyChanges();

}

private void postChangesToNetwork(final StorageChannel chan, final int upOrDown, final IItemList availableItems,
Expand Down Expand Up @@ -329,4 +362,13 @@ public void applyChanges() {
}
}
}

public long getItemBytesTotal() {
return this.itemBytesTotal;
}

public long getItemBytesUsed() {
return this.itemBytesUsed;
}

}
29 changes: 29 additions & 0 deletions src/main/java/appeng/util/Platform.java
Original file line number Diff line number Diff line change
Expand Up @@ -1863,4 +1863,33 @@ public static IAEItemStack getAEStackInSlot(Slot slot) {
public static long ceilDiv(long a, long b) {
return Math.addExact(Math.addExact(a, b), -1) / b;
}

/**
* From bytes to K,M,G,T like
*
* @param n Bytes number
* @return String that like 1G or 1.4T
*/
public static String formatByteLong(final long n) {
int storageUnit = Long.toBinaryString(n).length() / 10;
final DecimalFormat df = new DecimalFormat("#.##");
switch (storageUnit) {
case 6:
return df.format((double) n / 1152921504606846976d) + " EB";
case 5:
return df.format((double) n / 1125899906842624d) + " PB";
case 4:
return df.format((double) n / 1099511627776d) + " TB";
case 3:
return df.format((double) n / 1073741824d) + " GB";
case 2:
return df.format((double) n / 1048576d) + " MB";
case 1:
return df.format((double) n / 1024d) + " kB";
case 0:
return df.format((double) n) + " B";
default:
return df.format((double) n) + " B";
}
}
}
4 changes: 4 additions & 0 deletions src/main/resources/assets/appliedenergistics2/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ gui.appliedenergistics2.Nothing=Nothing
gui.appliedenergistics2.VoidCellTooltip=Deletes §4everything§7 stored on it
gui.appliedenergistics2.Deprecated=Deprecated, will be removed soon!

gui.appliedenergistics2.ByteTotal=Bytes Total
gui.appliedenergistics2.ByteUsage=Bytes Used
gui.appliedenergistics2.ByteFree=Bytes Free

# GUI Colors - ARGB
gui.color.appliedenergistics2.SearchboxFocused=6E000000
gui.color.appliedenergistics2.SearchboxUnfocused=00000000
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/assets/appliedenergistics2/lang/zh_CN.lang
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,10 @@ gui.appliedenergistics2.HoldShiftClick_HIGHLIGHT_INTERFACE=shift点击,高亮ME
gui.appliedenergistics2.VoidCellTooltip=删除§任何§7存储在里面的物品
gui.appliedenergistics2.Nothing=无

gui.appliedenergistics2.ByteTotal=所有字节
gui.appliedenergistics2.ByteUsage=已用字节
gui.appliedenergistics2.ByteFree=剩余字节

# GUI Colors - ARGB
gui.color.appliedenergistics2.SearchboxFocused=6E000000
gui.color.appliedenergistics2.SearchboxUnfocused=00000000
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.