添加玩家延迟颜色
All checks were successful
Build1.21 / build (push) Successful in 8m44s

This commit is contained in:
expvintl 2024-08-20 17:04:00 +08:00
parent 20131e4879
commit 07a266d928
2 changed files with 17 additions and 3 deletions

View File

@ -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:

View File

@ -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();
}
}