mirror of
https://github.com/Shiewk/Widgets.git
synced 2026-04-28 11:34:17 +02:00
Fix accuracy in bandwidth when the tick rate is lower than 20
This commit is contained in:
@@ -22,18 +22,15 @@ public class BandwidthWidget extends BasicTextWidget {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tickWidget() {
|
public void tickWidget() {
|
||||||
t++;
|
float tickRate = 20f;
|
||||||
if (t >= 20){
|
MinecraftClient client = MinecraftClient.getInstance();
|
||||||
t = 0;
|
if (client.world != null) {
|
||||||
final MultiValueDebugSampleLogImpl packetSizeLog = MinecraftClient.getInstance().getDebugHud().getPacketSizeLog();
|
tickRate = client.world.getTickManager().getTickRate();
|
||||||
final int logLength = packetSizeLog.getLength();
|
|
||||||
final int avgCompileLength = 60;
|
|
||||||
long size = 0;
|
|
||||||
for (int i = logLength-1; i > logLength-avgCompileLength; i--) {
|
|
||||||
if (i < 0) break;
|
|
||||||
size += packetSizeLog.get(i);
|
|
||||||
}
|
}
|
||||||
long avgBytesPerSecond = size / avgCompileLength * 20;
|
t++;
|
||||||
|
if (t >= tickRate){
|
||||||
|
t = 0;
|
||||||
|
long avgBytesPerSecond = getAvgBytesPerSecond(client, tickRate);
|
||||||
this.renderText = Text.of(formatByteSize(avgBytesPerSecond));
|
this.renderText = Text.of(formatByteSize(avgBytesPerSecond));
|
||||||
if (this.dynamicColor){
|
if (this.dynamicColor){
|
||||||
if (avgBytesPerSecond < 100000){
|
if (avgBytesPerSecond < 100000){
|
||||||
@@ -47,6 +44,18 @@ public class BandwidthWidget extends BasicTextWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static long getAvgBytesPerSecond(MinecraftClient client, float tickRate) {
|
||||||
|
final MultiValueDebugSampleLogImpl packetSizeLog = client.getDebugHud().getPacketSizeLog();
|
||||||
|
final int logLength = packetSizeLog.getLength();
|
||||||
|
final int avgCompileLength = (int) (3 * tickRate);
|
||||||
|
long size = 0;
|
||||||
|
for (int i = logLength-1; i > logLength-avgCompileLength; i--) {
|
||||||
|
if (i < 0) break;
|
||||||
|
size += packetSizeLog.get(i);
|
||||||
|
}
|
||||||
|
return (long) ((float) size / avgCompileLength * tickRate);
|
||||||
|
}
|
||||||
|
|
||||||
private String formatByteSize(long bytes) {
|
private String formatByteSize(long bytes) {
|
||||||
if (bytes > 1000) {
|
if (bytes > 1000) {
|
||||||
double mb = bytes / 100 / 10d;
|
double mb = bytes / 100 / 10d;
|
||||||
|
|||||||
Reference in New Issue
Block a user