添加Tab显示优化,聊天HUD增加头像

This commit is contained in:
expvintl 2024-08-20 03:04:10 +08:00
parent 3e69fb7512
commit 694fa42ce7
33 changed files with 258 additions and 17 deletions

Binary file not shown.

View File

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

Binary file not shown.

Binary file not shown.

View File

@ -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"
],

View File

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

View File

@ -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 分钟

View File

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

View File

@ -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))
//根据挖掘等级加分

View File

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

View File

@ -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<Text> textList;
public static ItemStackTooltipEvent get(ItemStack item,List<Text> list){
INSTANCE.item=item;
INSTANCE.textList=list;
return INSTANCE;
}
}

View File

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

View File

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

View File

@ -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<Text> onGetTooltip(List<Text> list) {
if(Utils.isReady()) {
ItemStackTooltipEvent event=ItemStackTooltipEvent.get((ItemStack) (Object) this, list);
MCEventBus.INSTANCE.post(event);
return event.textList;
}
return list;
}
}

View File

@ -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){
}
}

View File

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

View File

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

View File

@ -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<FabricClientCommandSource> dispatcher){
public static void CreateStatusCommand(String cmd, Setting toggle, CommandDispatcher<FabricClientCommandSource> dispatcher){
dispatcher.register(literal(cmd).executes((context -> {
context.getSource().getPlayer().sendMessage(Text.literal("当前启用状态: "+toggle.get()));
return Command.SINGLE_SUCCESS;

View File

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

View File

@ -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"
],