diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock index 572ca08..1598481 100644 Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/.gradle/file-system.probe b/.gradle/file-system.probe index e45e494..4d3a3d5 100644 Binary files a/.gradle/file-system.probe and b/.gradle/file-system.probe differ diff --git a/build/classes/java/main/MCTools-refmap.json b/build/classes/java/main/MCTools-refmap.json index cdcd1cb..d383cde 100644 --- a/build/classes/java/main/MCTools-refmap.json +++ b/build/classes/java/main/MCTools-refmap.json @@ -7,6 +7,15 @@ "com/expvintl/mctools/mixin/SoundSystemMixin": { "play(Lnet/minecraft/client/sound/SoundInstance;)V": "Lnet/minecraft/class_1140;method_4854(Lnet/minecraft/class_1113;)V" }, + "com/expvintl/mctools/mixin/hud/ChatHudMixin": { + "Lnet/minecraft/client/gui/DrawContext;drawTextWithShadow(Lnet/minecraft/client/font/TextRenderer;Lnet/minecraft/text/OrderedText;III)I": "Lnet/minecraft/class_332;method_35720(Lnet/minecraft/class_327;Lnet/minecraft/class_5481;III)I", + "render": "Lnet/minecraft/class_338;method_1805(Lnet/minecraft/class_332;IIIZ)V" + }, + "com/expvintl/mctools/mixin/hud/PlayerListHudMixin": { + "getPlayerName": "Lnet/minecraft/class_355;method_1918(Lnet/minecraft/class_640;)Lnet/minecraft/class_2561;", + "render": "Lnet/minecraft/class_355;method_1919(Lnet/minecraft/class_332;ILnet/minecraft/class_269;Lnet/minecraft/class_266;)V", + "renderLatencyIcon": "Lnet/minecraft/class_355;method_1923(Lnet/minecraft/class_332;IIILnet/minecraft/class_640;)V" + }, "com/expvintl/mctools/mixin/interfaces/ClientPlayerInteractionManagerAccessor": { "syncSelectedSlot": "method_2911()V" }, @@ -20,6 +29,9 @@ "com/expvintl/mctools/mixin/interfaces/SimpleOptionAccessor": { "value": "field_37868:Ljava/lang/Object;" }, + "com/expvintl/mctools/mixin/item/ItemStackMixin": { + "getTooltip": "Lnet/minecraft/class_1799;method_7950(Lnet/minecraft/class_1792$class_9635;Lnet/minecraft/class_1657;Lnet/minecraft/class_1836;)Ljava/util/List;" + }, "com/expvintl/mctools/mixin/network/ClientConnectionMixin": { "handlePacket": "Lnet/minecraft/class_2535;method_10759(Lnet/minecraft/class_2596;Lnet/minecraft/class_2547;)V", "send(Lnet/minecraft/network/packet/Packet;)V": "Lnet/minecraft/class_2535;method_10743(Lnet/minecraft/class_2596;)V" @@ -42,6 +54,15 @@ "com/expvintl/mctools/mixin/SoundSystemMixin": { "play(Lnet/minecraft/client/sound/SoundInstance;)V": "Lnet/minecraft/class_1140;method_4854(Lnet/minecraft/class_1113;)V" }, + "com/expvintl/mctools/mixin/hud/ChatHudMixin": { + "Lnet/minecraft/client/gui/DrawContext;drawTextWithShadow(Lnet/minecraft/client/font/TextRenderer;Lnet/minecraft/text/OrderedText;III)I": "Lnet/minecraft/class_332;method_35720(Lnet/minecraft/class_327;Lnet/minecraft/class_5481;III)I", + "render": "Lnet/minecraft/class_338;method_1805(Lnet/minecraft/class_332;IIIZ)V" + }, + "com/expvintl/mctools/mixin/hud/PlayerListHudMixin": { + "getPlayerName": "Lnet/minecraft/class_355;method_1918(Lnet/minecraft/class_640;)Lnet/minecraft/class_2561;", + "render": "Lnet/minecraft/class_355;method_1919(Lnet/minecraft/class_332;ILnet/minecraft/class_269;Lnet/minecraft/class_266;)V", + "renderLatencyIcon": "Lnet/minecraft/class_355;method_1923(Lnet/minecraft/class_332;IIILnet/minecraft/class_640;)V" + }, "com/expvintl/mctools/mixin/interfaces/ClientPlayerInteractionManagerAccessor": { "syncSelectedSlot": "method_2911()V" }, @@ -55,6 +76,9 @@ "com/expvintl/mctools/mixin/interfaces/SimpleOptionAccessor": { "value": "field_37868:Ljava/lang/Object;" }, + "com/expvintl/mctools/mixin/item/ItemStackMixin": { + "getTooltip": "Lnet/minecraft/class_1799;method_7950(Lnet/minecraft/class_1792$class_9635;Lnet/minecraft/class_1657;Lnet/minecraft/class_1836;)Ljava/util/List;" + }, "com/expvintl/mctools/mixin/network/ClientConnectionMixin": { "handlePacket": "Lnet/minecraft/class_2535;method_10759(Lnet/minecraft/class_2596;Lnet/minecraft/class_2547;)V", "send(Lnet/minecraft/network/packet/Packet;)V": "Lnet/minecraft/class_2535;method_10743(Lnet/minecraft/class_2596;)V" diff --git a/build/classes/java/main/com/expvintl/mctools/MCToolsClient.class b/build/classes/java/main/com/expvintl/mctools/MCToolsClient.class index 8a21279..4fda857 100644 Binary files a/build/classes/java/main/com/expvintl/mctools/MCToolsClient.class and b/build/classes/java/main/com/expvintl/mctools/MCToolsClient.class differ diff --git a/build/classes/java/main/com/expvintl/mctools/commands/CAutoFishCommand.class b/build/classes/java/main/com/expvintl/mctools/commands/CAutoFishCommand.class index f388736..f6203c7 100644 Binary files a/build/classes/java/main/com/expvintl/mctools/commands/CAutoFishCommand.class and b/build/classes/java/main/com/expvintl/mctools/commands/CAutoFishCommand.class differ diff --git a/build/classes/java/main/com/expvintl/mctools/commands/CAutoRespawnCommand.class b/build/classes/java/main/com/expvintl/mctools/commands/CAutoRespawnCommand.class index ddaa934..bbeb062 100644 Binary files a/build/classes/java/main/com/expvintl/mctools/commands/CAutoRespawnCommand.class and b/build/classes/java/main/com/expvintl/mctools/commands/CAutoRespawnCommand.class differ diff --git a/build/classes/java/main/com/expvintl/mctools/commands/CAutoToolCommand.class b/build/classes/java/main/com/expvintl/mctools/commands/CAutoToolCommand.class index a0aa8b9..e1bdefe 100644 Binary files a/build/classes/java/main/com/expvintl/mctools/commands/CAutoToolCommand.class and b/build/classes/java/main/com/expvintl/mctools/commands/CAutoToolCommand.class differ diff --git a/build/classes/java/main/com/expvintl/mctools/commands/CNoFallPacketCommand.class b/build/classes/java/main/com/expvintl/mctools/commands/CNoFallPacketCommand.class index c0c7b0e..f1ee8e2 100644 Binary files a/build/classes/java/main/com/expvintl/mctools/commands/CNoFallPacketCommand.class and b/build/classes/java/main/com/expvintl/mctools/commands/CNoFallPacketCommand.class differ diff --git a/build/classes/java/main/com/expvintl/mctools/commands/CQServerPluginsCommand$1.class b/build/classes/java/main/com/expvintl/mctools/commands/CQServerPluginsCommand$1.class index ff3d097..c7b2ee3 100644 Binary files a/build/classes/java/main/com/expvintl/mctools/commands/CQServerPluginsCommand$1.class and b/build/classes/java/main/com/expvintl/mctools/commands/CQServerPluginsCommand$1.class differ diff --git a/build/classes/java/main/com/expvintl/mctools/commands/CQServerPluginsCommand.class b/build/classes/java/main/com/expvintl/mctools/commands/CQServerPluginsCommand.class index 237a657..1461802 100644 Binary files a/build/classes/java/main/com/expvintl/mctools/commands/CQServerPluginsCommand.class and b/build/classes/java/main/com/expvintl/mctools/commands/CQServerPluginsCommand.class differ diff --git a/build/classes/java/main/com/expvintl/mctools/commands/CSafeWalkCommand.class b/build/classes/java/main/com/expvintl/mctools/commands/CSafeWalkCommand.class index 38f6690..ae8eadd 100644 Binary files a/build/classes/java/main/com/expvintl/mctools/commands/CSafeWalkCommand.class and b/build/classes/java/main/com/expvintl/mctools/commands/CSafeWalkCommand.class differ diff --git a/build/classes/java/main/com/expvintl/mctools/mixin/player/PlayerEntityMixin.class b/build/classes/java/main/com/expvintl/mctools/mixin/player/PlayerEntityMixin.class index 7446f10..d625997 100644 Binary files a/build/classes/java/main/com/expvintl/mctools/mixin/player/PlayerEntityMixin.class and b/build/classes/java/main/com/expvintl/mctools/mixin/player/PlayerEntityMixin.class differ diff --git a/build/classes/java/main/com/expvintl/mctools/utils/Utils.class b/build/classes/java/main/com/expvintl/mctools/utils/Utils.class index 9e00d2c..26123a1 100644 Binary files a/build/classes/java/main/com/expvintl/mctools/utils/Utils.class and b/build/classes/java/main/com/expvintl/mctools/utils/Utils.class differ diff --git a/build/devlibs/MCTools-1.0-dev.jar b/build/devlibs/MCTools-1.0-dev.jar index 16eeea7..3f84121 100644 Binary files a/build/devlibs/MCTools-1.0-dev.jar and b/build/devlibs/MCTools-1.0-dev.jar differ diff --git a/build/devlibs/MCTools-1.0-sources.jar b/build/devlibs/MCTools-1.0-sources.jar index 5420623..592b382 100644 Binary files a/build/devlibs/MCTools-1.0-sources.jar and b/build/devlibs/MCTools-1.0-sources.jar differ diff --git a/build/libs/MCTools-1.0-sources.jar b/build/libs/MCTools-1.0-sources.jar index f29ecb0..187baa9 100644 Binary files a/build/libs/MCTools-1.0-sources.jar and b/build/libs/MCTools-1.0-sources.jar differ diff --git a/build/resources/main/mctools.mixins.json b/build/resources/main/mctools.mixins.json index 63dbd5f..e0a2256 100644 --- a/build/resources/main/mctools.mixins.json +++ b/build/resources/main/mctools.mixins.json @@ -4,7 +4,10 @@ "package": "com.expvintl.mctools.mixin", "compatibilityLevel": "JAVA_21", "mixins": [ + "hud.ChatHudMixin", + "hud.PlayerListHudMixin", "interfaces.PlayerMoveC2SPacketAccessor", + "item.ItemStackMixin", "network.ClientConnectionMixin", "player.PlayerEntityMixin" ], diff --git a/build/tmp/compileJava/previous-compilation-data.bin b/build/tmp/compileJava/previous-compilation-data.bin index f0c3a8d..8e882c7 100644 Binary files a/build/tmp/compileJava/previous-compilation-data.bin and b/build/tmp/compileJava/previous-compilation-data.bin differ diff --git a/src/main/java/com/expvintl/mctools/Globals.java b/src/main/java/com/expvintl/mctools/Globals.java index becdebf..37bc5db 100644 --- a/src/main/java/com/expvintl/mctools/Globals.java +++ b/src/main/java/com/expvintl/mctools/Globals.java @@ -1,13 +1,13 @@ package com.expvintl.mctools; -import com.expvintl.mctools.types.GBool; +import com.expvintl.mctools.types.Setting; public class Globals { - public static GBool autoRespawn=new GBool(); - public static GBool selfWalk=new GBool(); - public static GBool checkBukkitPlugins=new GBool(); - public static GBool autoTool=new GBool(); - public static GBool autoFish=new GBool(); - public static GBool noFallPacket=new GBool(); + public static Setting autoRespawn=new Setting(); + public static Setting selfWalk=new Setting(); + public static Setting checkBukkitPlugins=new Setting(); + public static Setting autoTool=new Setting(); + public static Setting autoFish=new Setting(); + public static Setting noFallPacket=new Setting(); public static int TPS=0; } diff --git a/src/main/java/com/expvintl/mctools/MCToolsClient.java b/src/main/java/com/expvintl/mctools/MCToolsClient.java index 2c98b07..a0cc78d 100644 --- a/src/main/java/com/expvintl/mctools/MCToolsClient.java +++ b/src/main/java/com/expvintl/mctools/MCToolsClient.java @@ -1,6 +1,8 @@ package com.expvintl.mctools; import com.expvintl.mctools.commands.*; +import com.expvintl.mctools.modules.BetterTooltip; +import com.expvintl.mctools.modules.PlayerListTextLatency; import com.expvintl.mctools.utils.Utils; import com.mojang.brigadier.CommandDispatcher; import net.fabricmc.api.ClientModInitializer; @@ -22,11 +24,14 @@ public class MCToolsClient implements ClientModInitializer { private static int infoY=1; @Override public void onInitializeClient() { - //初始化命令注册回调 ClientCommandRegistrationCallback.EVENT.register(MCToolsClient::registerCommands); HudRenderCallback.EVENT.register(MCToolsClient::drawHUD); - + InitModules(); + } + public void InitModules(){ + BetterTooltip.INSTANCE.init(); + PlayerListTextLatency.INSTANCE.init(); } private static String gameDayToRealTimeFormat(long gameDays) { // 游戏 1 小时等于 20 分钟 diff --git a/src/main/java/com/expvintl/mctools/commands/CAutoRespawnCommand.java b/src/main/java/com/expvintl/mctools/commands/CAutoRespawnCommand.java index e07d0fd..0254dff 100644 --- a/src/main/java/com/expvintl/mctools/commands/CAutoRespawnCommand.java +++ b/src/main/java/com/expvintl/mctools/commands/CAutoRespawnCommand.java @@ -3,7 +3,6 @@ package com.expvintl.mctools.commands; import com.expvintl.mctools.Globals; import com.expvintl.mctools.events.MCEventBus; import com.expvintl.mctools.events.client.OpenScreenEvent; -import com.expvintl.mctools.types.GBool; import com.expvintl.mctools.utils.CommandUtils; import com.google.common.eventbus.Subscribe; import com.mojang.brigadier.Command; diff --git a/src/main/java/com/expvintl/mctools/commands/CAutoToolCommand.java b/src/main/java/com/expvintl/mctools/commands/CAutoToolCommand.java index ad3c7af..97b4bfc 100644 --- a/src/main/java/com/expvintl/mctools/commands/CAutoToolCommand.java +++ b/src/main/java/com/expvintl/mctools/commands/CAutoToolCommand.java @@ -102,7 +102,7 @@ public class CAutoToolCommand { //遍历每一个物品槽 for(int i=0;i<9;i++){ ItemStack item = mc.player.getInventory().getStack(i); - float score=getScore(item,state); + float score= getToolsScore(item,state); if(score<0) continue; //选出最好分数的工具 if(score>bestScore){ @@ -123,9 +123,8 @@ public class CAutoToolCommand { } } } - public float getScore(ItemStack item, BlockState state){ + public float getToolsScore(ItemStack item, BlockState state){ float score=0; - //Is Tool!! if(item.getItem() instanceof ToolItem || item.getItem() instanceof ShearsItem){ //根据挖掘速度提升评分 score+=item.getMiningSpeedMultiplier(state)*30; @@ -134,7 +133,7 @@ public class CAutoToolCommand { score+= Utils.GetEnchantLevel(Enchantments.UNBREAKING, item); //效率 score+=Utils.GetEnchantLevel(Enchantments.EFFICIENCY,item); - //经验修补(此项最优先) + //经验修补 score+=Utils.GetEnchantLevel(Enchantments.MENDING,item); if (item.getItem() instanceof SwordItem item1 && (state.getBlock() instanceof BambooBlock|| state.getBlock() instanceof BambooShootBlock)) //根据挖掘等级加分 diff --git a/src/main/java/com/expvintl/mctools/events/hud/RenderLatencyIconEvent.java b/src/main/java/com/expvintl/mctools/events/hud/RenderLatencyIconEvent.java new file mode 100644 index 0000000..f41b4a9 --- /dev/null +++ b/src/main/java/com/expvintl/mctools/events/hud/RenderLatencyIconEvent.java @@ -0,0 +1,22 @@ +package com.expvintl.mctools.events.hud; + +import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.network.PlayerListEntry; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +public class RenderLatencyIconEvent { + public static RenderLatencyIconEvent INSTANCE=new RenderLatencyIconEvent(); + public DrawContext draw; + public PlayerListEntry entry; + public CallbackInfo callback; + public int x,y,width; + public static RenderLatencyIconEvent get(DrawContext draw,int width,int x,int y,PlayerListEntry entry,CallbackInfo callback){ + INSTANCE.draw=draw; + INSTANCE.callback=callback; + INSTANCE.entry=entry; + INSTANCE.y=y; + INSTANCE.x=x; + INSTANCE.width=width; + return INSTANCE; + } +} diff --git a/src/main/java/com/expvintl/mctools/events/item/ItemStackTooltipEvent.java b/src/main/java/com/expvintl/mctools/events/item/ItemStackTooltipEvent.java new file mode 100644 index 0000000..6682e71 --- /dev/null +++ b/src/main/java/com/expvintl/mctools/events/item/ItemStackTooltipEvent.java @@ -0,0 +1,18 @@ +package com.expvintl.mctools.events.item; + +import net.minecraft.item.ItemStack; +import net.minecraft.text.Text; + +import java.util.List; + +public class ItemStackTooltipEvent { + public static ItemStackTooltipEvent INSTANCE=new ItemStackTooltipEvent(); + public ItemStack item; + public List textList; + + public static ItemStackTooltipEvent get(ItemStack item,List list){ + INSTANCE.item=item; + INSTANCE.textList=list; + return INSTANCE; + } +} diff --git a/src/main/java/com/expvintl/mctools/mixin/hud/ChatHudMixin.java b/src/main/java/com/expvintl/mctools/mixin/hud/ChatHudMixin.java new file mode 100644 index 0000000..e823f8f --- /dev/null +++ b/src/main/java/com/expvintl/mctools/mixin/hud/ChatHudMixin.java @@ -0,0 +1,26 @@ +package com.expvintl.mctools.mixin.hud; + +import com.expvintl.mctools.utils.Utils; +import com.llamalad7.mixinextras.injector.ModifyReceiver; +import com.llamalad7.mixinextras.sugar.Local; +import com.mojang.blaze3d.systems.RenderSystem; +import net.minecraft.client.font.TextRenderer; +import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.gui.hud.ChatHud; +import net.minecraft.client.gui.hud.ChatHudLine; +import net.minecraft.text.OrderedText; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +@Mixin(ChatHud.class) +public class ChatHudMixin { + @ModifyReceiver(method = "render",at=@At(value = "INVOKE",target = "Lnet/minecraft/client/gui/DrawContext;drawTextWithShadow(Lnet/minecraft/client/font/TextRenderer;Lnet/minecraft/text/OrderedText;III)I")) + private DrawContext onRenderDrawTextWithShadow(DrawContext context, TextRenderer renderer, OrderedText text, int x, int y, int color, @Local ChatHudLine.Visible line){ + RenderSystem.enableBlend(); + RenderSystem.setShaderColor(1,1,1,((color >> 24) & 0x000000FF)/255f); + Utils.DrawHeadIcon(context,line,y); + RenderSystem.setShaderColor(1,1,1,1); + RenderSystem.disableBlend(); + return context; + } +} diff --git a/src/main/java/com/expvintl/mctools/mixin/hud/PlayerListHudMixin.java b/src/main/java/com/expvintl/mctools/mixin/hud/PlayerListHudMixin.java new file mode 100644 index 0000000..9ecc1ce --- /dev/null +++ b/src/main/java/com/expvintl/mctools/mixin/hud/PlayerListHudMixin.java @@ -0,0 +1,38 @@ +package com.expvintl.mctools.mixin.hud; + +import com.expvintl.mctools.events.MCEventBus; +import com.expvintl.mctools.events.hud.RenderLatencyIconEvent; +import com.expvintl.mctools.utils.Utils; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.gui.hud.PlayerListHud; +import net.minecraft.client.network.PlayerListEntry; +import net.minecraft.text.Text; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.ModifyArg; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(PlayerListHud.class) +public class PlayerListHudMixin { + @ModifyArg(method = "render",at=@At(value = "INVOKE",target = "Ljava/lang/Math;min(II)I"),index = 0) + private int fixWidth(int width){ + return width+25; + } + @Inject(method = "getPlayerName",at=@At("HEAD"),cancellable = true) + private void getPlayerName(PlayerListEntry entry, CallbackInfoReturnable info){ + if(Utils.isReady()){ + Text name=entry.getDisplayName(); + if(entry.getProfile().getId().toString().equals(MinecraftClient.getInstance().player.getGameProfile().getId().toString())){ + info.setReturnValue(Text.literal(name.getString()).setStyle(name.getStyle().withColor(0xff0000))); + } + } + } + + @Inject(method = "renderLatencyIcon",at=@At("HEAD"),cancellable = true) + private void onRenderLatencyIcon(DrawContext draw, int width, int x, int y, PlayerListEntry entry, CallbackInfo info){ + MCEventBus.INSTANCE.post(RenderLatencyIconEvent.get(draw,width,x,y,entry,info)); + } +} diff --git a/src/main/java/com/expvintl/mctools/mixin/item/ItemStackMixin.java b/src/main/java/com/expvintl/mctools/mixin/item/ItemStackMixin.java new file mode 100644 index 0000000..5813b10 --- /dev/null +++ b/src/main/java/com/expvintl/mctools/mixin/item/ItemStackMixin.java @@ -0,0 +1,27 @@ +package com.expvintl.mctools.mixin.item; + +import com.expvintl.mctools.events.MCEventBus; +import com.expvintl.mctools.events.item.ItemStackTooltipEvent; +import com.expvintl.mctools.utils.Utils; +import com.llamalad7.mixinextras.injector.ModifyReturnValue; +import net.minecraft.client.MinecraftClient; +import net.minecraft.item.ItemStack; +import net.minecraft.text.Text; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; + +import java.util.List; + +@Mixin(ItemStack.class) +public class ItemStackMixin { + @ModifyReturnValue(method = "getTooltip",at=@At("RETURN")) + private List onGetTooltip(List list) { + if(Utils.isReady()) { + ItemStackTooltipEvent event=ItemStackTooltipEvent.get((ItemStack) (Object) this, list); + MCEventBus.INSTANCE.post(event); + return event.textList; + } + return list; + } +} diff --git a/src/main/java/com/expvintl/mctools/modules/BetterTooltip.java b/src/main/java/com/expvintl/mctools/modules/BetterTooltip.java new file mode 100644 index 0000000..fd4a563 --- /dev/null +++ b/src/main/java/com/expvintl/mctools/modules/BetterTooltip.java @@ -0,0 +1,18 @@ +package com.expvintl.mctools.modules; + +import com.expvintl.mctools.events.MCEventBus; +import com.expvintl.mctools.events.item.ItemStackTooltipEvent; +import com.google.common.eventbus.Subscribe; +import net.minecraft.client.MinecraftClient; +import net.minecraft.text.Text; + +public class BetterTooltip { + public static BetterTooltip INSTANCE=new BetterTooltip(); + public void init(){ + MCEventBus.INSTANCE.register(INSTANCE); + } + @Subscribe + public void onGetTooltip(ItemStackTooltipEvent event){ + + } +} diff --git a/src/main/java/com/expvintl/mctools/modules/PlayerListTextLatency.java b/src/main/java/com/expvintl/mctools/modules/PlayerListTextLatency.java new file mode 100644 index 0000000..a49359e --- /dev/null +++ b/src/main/java/com/expvintl/mctools/modules/PlayerListTextLatency.java @@ -0,0 +1,22 @@ +package com.expvintl.mctools.modules; + +import com.expvintl.mctools.events.MCEventBus; +import com.expvintl.mctools.events.hud.RenderLatencyIconEvent; +import com.google.common.eventbus.Subscribe; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.font.TextRenderer; + +public class PlayerListTextLatency { + public static PlayerListTextLatency INSTANCE=new PlayerListTextLatency(); + public void init(){ + MCEventBus.INSTANCE.register(INSTANCE); + } + @Subscribe + public void onRenderLatencyIcon(RenderLatencyIconEvent event){ + TextRenderer renderer=MinecraftClient.getInstance().textRenderer; + int latency=Math.clamp(event.entry.getLatency(),0,9999); + String text=latency+" ms"; + event.draw.drawTextWithShadow(renderer,text, event.x+event.width-renderer.getWidth(text),event.y,0x00E970); + event.callback.cancel(); + } +} diff --git a/src/main/java/com/expvintl/mctools/types/GBool.java b/src/main/java/com/expvintl/mctools/types/Setting.java similarity index 89% rename from src/main/java/com/expvintl/mctools/types/GBool.java rename to src/main/java/com/expvintl/mctools/types/Setting.java index 615a44c..01f16b3 100644 --- a/src/main/java/com/expvintl/mctools/types/GBool.java +++ b/src/main/java/com/expvintl/mctools/types/Setting.java @@ -1,6 +1,6 @@ package com.expvintl.mctools.types; -public class GBool{ +public class Setting { public boolean value=false; public boolean get(){ return this.value; diff --git a/src/main/java/com/expvintl/mctools/utils/CommandUtils.java b/src/main/java/com/expvintl/mctools/utils/CommandUtils.java index 7146c4a..5586ead 100644 --- a/src/main/java/com/expvintl/mctools/utils/CommandUtils.java +++ b/src/main/java/com/expvintl/mctools/utils/CommandUtils.java @@ -1,13 +1,13 @@ package com.expvintl.mctools.utils; -import com.expvintl.mctools.types.GBool; +import com.expvintl.mctools.types.Setting; import com.mojang.brigadier.Command; import com.mojang.brigadier.CommandDispatcher; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; import net.minecraft.text.Text; import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; public class CommandUtils { - public static void CreateStatusCommand(String cmd, GBool toggle, CommandDispatcher dispatcher){ + public static void CreateStatusCommand(String cmd, Setting toggle, CommandDispatcher dispatcher){ dispatcher.register(literal(cmd).executes((context -> { context.getSource().getPlayer().sendMessage(Text.literal("当前启用状态: "+toggle.get())); return Command.SINGLE_SUCCESS; diff --git a/src/main/java/com/expvintl/mctools/utils/Utils.java b/src/main/java/com/expvintl/mctools/utils/Utils.java index 16f44b0..3895071 100644 --- a/src/main/java/com/expvintl/mctools/utils/Utils.java +++ b/src/main/java/com/expvintl/mctools/utils/Utils.java @@ -1,6 +1,7 @@ package com.expvintl.mctools.utils; import com.expvintl.mctools.mixin.interfaces.MinecraftClientAccessor; +import com.mojang.authlib.GameProfile; import com.mojang.blaze3d.systems.RenderSystem; import it.unimi.dsi.fastutil.objects.Object2IntMap; import net.minecraft.block.Block; @@ -17,6 +18,7 @@ import net.minecraft.item.Items; import net.minecraft.registry.RegistryKey; import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.text.MutableText; +import net.minecraft.text.OrderedText; import net.minecraft.text.Text; import net.minecraft.util.Identifier; import net.minecraft.util.math.BlockPos; @@ -29,10 +31,13 @@ import java.util.Optional; import java.util.Set; import java.util.Timer; import java.util.logging.Logger; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class Utils { private static final MinecraftClient mc = MinecraftClient.getInstance(); public static final Timer timer = new Timer(); + private static final Pattern usernameRegex = Pattern.compile("^(?:<[0-9]{2}:[0-9]{2}>\\s)?<(.*?)>.*"); public static String getCurrentDimensionName() { if (mc.world != null) { @@ -221,4 +226,36 @@ public class Utils { } } } + public static boolean isReady(){ + MinecraftClient cli=MinecraftClient.getInstance(); + return cli!=null&&cli.world!=null&&cli.player!=null; + } + + public static void DrawHeadIcon(DrawContext draw, ChatHudLine.Visible text,int y){ + StringBuffer buf=new StringBuffer(); + text.content().accept((idx,style,codePoint)->{ + buf.appendCodePoint(codePoint); + return true; + }); + String txt=buf.toString(); + GameProfile sender=getChatSender(txt); + if(sender==null) return; + PlayerListEntry entry = mc.getNetworkHandler().getPlayerListEntry(sender.getId()); + if (entry == null) return; + + Identifier skin = entry.getSkinTextures().texture(); + + draw.drawTexture(skin, 0, y, 8, 8, 8, 8, 8, 8, 64, 64); + draw.drawTexture(skin, 0, y, 8, 8, 40, 8, 8, 8, 64, 64); + draw.getMatrices().translate(10, 0, 0); + } + public static GameProfile getChatSender(String text){ + Matcher usernameMatcher=usernameRegex.matcher(text); + if(usernameMatcher.matches()){ + String username=usernameMatcher.group(1); + PlayerListEntry entry=mc.getNetworkHandler().getPlayerListEntry(username); + if(entry!=null) return entry.getProfile(); + } + return null; + } } diff --git a/src/main/resources/mctools.mixins.json b/src/main/resources/mctools.mixins.json index 63dbd5f..e0a2256 100644 --- a/src/main/resources/mctools.mixins.json +++ b/src/main/resources/mctools.mixins.json @@ -4,7 +4,10 @@ "package": "com.expvintl.mctools.mixin", "compatibilityLevel": "JAVA_21", "mixins": [ + "hud.ChatHudMixin", + "hud.PlayerListHudMixin", "interfaces.PlayerMoveC2SPacketAccessor", + "item.ItemStackMixin", "network.ClientConnectionMixin", "player.PlayerEntityMixin" ],