2222 * THE SOFTWARE.
2323 */
2424
25- package com .ishland .raknetify .fabric .mixin .client . hud ;
25+ package com .ishland .raknetify .fabric .common .client ;
2626
2727import com .ishland .raknetify .common .connection .MetricsSynchronizationHandler ;
2828import com .ishland .raknetify .common .connection .MultiChannelingStreamingCompression ;
2929import com .ishland .raknetify .common .connection .SimpleMetricsLogger ;
3030import com .ishland .raknetify .fabric .common .util .MultiVersionUtil ;
3131import com .ishland .raknetify .fabric .mixin .access .IClientConnection ;
32- import com .ishland .raknetify .fabric .mixin .access .IClientPlayNetworkHandler ;
3332import io .netty .channel .Channel ;
3433import net .minecraft .client .MinecraftClient ;
35- import net .minecraft .client .gui .hud .DebugHud ;
3634import net .minecraft .client .network .ClientPlayNetworkHandler ;
3735import net .minecraft .network .ClientConnection ;
3836import network .ycc .raknet .RakNet ;
39- import org .spongepowered .asm .mixin .Mixin ;
40- import org .spongepowered .asm .mixin .injection .At ;
41- import org .spongepowered .asm .mixin .injection .Inject ;
42- import org .spongepowered .asm .mixin .injection .callback .CallbackInfoReturnable ;
4337
44- import java .util .List ;
38+ import java .util .function . Consumer ;
4539
46- @ Mixin (DebugHud .class )
47- public class MixinDebugHud {
40+ public class DebugHudUtil {
4841
49- @ Inject (method = "getLeftText" , at = @ At ("RETURN" ))
50- private void getLeftText (CallbackInfoReturnable <List <String >> cir ) {
42+ public static void getDebugString (Consumer <String > consumer ) {
5143 final ClientPlayNetworkHandler networkHandler = MinecraftClient .getInstance ().getNetworkHandler ();
5244 if (networkHandler != null ) {
5345 final ClientConnection connection = (ClientConnection ) MultiVersionUtil .ClientPlayNetworkHandler$connection .get (networkHandler );
5446 final Channel channel = ((IClientConnection ) connection ).getChannel ();
5547 if (channel != null ) {
5648 if (channel .config () instanceof RakNet .Config config ) {
5749 if (config .getMetrics () instanceof SimpleMetricsLogger logger ) {
58- cir . getReturnValue (). add (
50+ consumer . accept (
5951 "[Raknetify] A: true, MTU: %d, RTT: %.2f/%.2fms"
6052 .formatted (config .getMTU (),
6153 logger .getMeasureRTTns () / 1_000_000.0 ,
6254 logger .getMeasureRTTnsStdDev () / 1_000_000.0
6355 ));
6456 final MetricsSynchronizationHandler serverSync = logger .getMetricsSynchronizationHandler ();
6557 if (serverSync != null && serverSync .isRemoteSupported ()) {
66- cir . getReturnValue (). add (
58+ consumer . accept (
6759 "[Raknetify] C: BUF: %.2fMB; S: BUF: %.2fMB"
6860 .formatted (
6961 logger .getCurrentQueuedBytes () / 1024.0 / 1024.0 ,
7062 serverSync .getQueuedBytes () / 1024.0 / 1024.0
7163 ));
7264 } else {
73- cir . getReturnValue (). add (
65+ consumer . accept (
7466 "[Raknetify] C: BUF: %.2fMB"
7567 .formatted (
7668 logger .getCurrentQueuedBytes () / 1024.0 / 1024.0
7769 ));
7870 }
7971
80- cir . getReturnValue (). add (
72+ consumer . accept (
8173 "[Raknetify] C: I: %s, O: %s"
8274 .formatted (
8375 logger .getMeasureTrafficInFormatted (),
8476 logger .getMeasureTrafficOutFormatted ()
8577 ));
8678
87- cir . getReturnValue (). add (
79+ consumer . accept (
8880 "[Raknetify] C: ERR: %.4f%%, %d tx, %d rx, BST: %d"
8981 .formatted (
9082 logger .getMeasureErrorRate () * 100.0 ,
9183 logger .getMeasureTX (), logger .getMeasureRX (),
9284 logger .getMeasureBurstTokens () + config .getDefaultPendingFrameSets ()
9385 ));
9486 if (serverSync != null && serverSync .isRemoteSupported ()) {
95- cir . getReturnValue (). add (
87+ consumer . accept (
9688 "[Raknetify] S: ERR: %.4f%%, %d tx, %d rx, BST: %d"
9789 .formatted (
9890 serverSync .getErrorRate () * 100.0 ,
@@ -101,15 +93,15 @@ private void getLeftText(CallbackInfoReturnable<List<String>> cir) {
10193 ));
10294 }
10395 } else {
104- cir . getReturnValue (). add (
96+ consumer . accept (
10597 "[Raknetify] A: true, MTU: %d"
10698 .formatted (config .getMTU ())
10799 );
108100 }
109101
110102 final MultiChannelingStreamingCompression compression = channel .pipeline ().get (MultiChannelingStreamingCompression .class );
111103 if (compression != null && compression .isActive ()) {
112- cir . getReturnValue (). add (
104+ consumer . accept (
113105 "[Raknetify] CRatio: I: %.2f%%, O: %.2f%%"
114106 .formatted (compression .getInCompressionRatio () * 100 , compression .getOutCompressionRatio () * 100 )
115107 );
@@ -119,7 +111,7 @@ private void getLeftText(CallbackInfoReturnable<List<String>> cir) {
119111 }
120112 }
121113 }
122- cir . getReturnValue (). add ("[Raknetify] A: false" );
114+ consumer . accept ("[Raknetify] A: false" );
123115 }
124116
125117}
0 commit comments