From 07a266d9285a4724404ade18fe0e7f9e80d38623 Mon Sep 17 00:00:00 2001 From: expvintl Date: Tue, 20 Aug 2024 17:04:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=8E=A9=E5=AE=B6=E5=BB=B6?= =?UTF-8?q?=E8=BF=9F=E9=A2=9C=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci_build_1.21.yml | 4 +++- .../mctools/modules/PlayerListTextLatency.java | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci_build_1.21.yml b/.github/workflows/ci_build_1.21.yml index bd8a4a1..5068440 100644 --- a/.github/workflows/ci_build_1.21.yml +++ b/.github/workflows/ci_build_1.21.yml @@ -16,7 +16,9 @@ jobs: - name: 初始化Gradle uses: gradle/actions/setup-gradle@v4 - name: 构建项目 - run: ./gradlew build + run: | + chmod 755 ./gradlew + ./gradlew build - name: 上传构建 uses: actions/upload-artifact@v3 with: diff --git a/src/main/java/com/expvintl/mctools/modules/PlayerListTextLatency.java b/src/main/java/com/expvintl/mctools/modules/PlayerListTextLatency.java index a49359e..d7ee39d 100644 --- a/src/main/java/com/expvintl/mctools/modules/PlayerListTextLatency.java +++ b/src/main/java/com/expvintl/mctools/modules/PlayerListTextLatency.java @@ -11,12 +11,24 @@ public class PlayerListTextLatency { public void init(){ MCEventBus.INSTANCE.register(INSTANCE); } + private int calcLatencyColor(int latency){ + if(latency>=0&&latency<=60){ //0-60 + return 0x00FF00; //绿色 + }else if(latency>60&&latency<=120){ //60-120 + return 0xFFFF00; //黄色 + }else if(latency>120&&latency<=200){//120-200 + return 0xFFA500; //橙色 + }else if(latency>200){ //>200 + return 0xFF0000; //红色 + } + return 0xFFFFFF; //默认白色 + } @Subscribe public void onRenderLatencyIcon(RenderLatencyIconEvent event){ TextRenderer renderer=MinecraftClient.getInstance().textRenderer; - int latency=Math.clamp(event.entry.getLatency(),0,9999); + int latency=Math.clamp(event.entry.getLatency(),0,999); String text=latency+" ms"; - event.draw.drawTextWithShadow(renderer,text, event.x+event.width-renderer.getWidth(text),event.y,0x00E970); + event.draw.drawTextWithShadow(renderer,text, event.x+event.width-renderer.getWidth(text),event.y,calcLatencyColor(latency)); event.callback.cancel(); } }