修复信息在f3显示的问题以及快速丢弃命令,优化命令查看

This commit is contained in:
expvintl
2024-08-19 20:18:28 +08:00
parent 2d360b24f1
commit 3e69fb7512
31 changed files with 93 additions and 34 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,11 +1,13 @@
package com.expvintl.mctools;
import com.expvintl.mctools.types.GBool;
public class Globals {
public static boolean autoRespawn=false;
public static boolean selfWalk=false;
public static boolean checkBukkitPlugins=false;
public static boolean autoTool=false;
public static boolean autoFish=false;
public static boolean noFallPacket=false;
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 int TPS=0;
}

View File

@ -44,13 +44,13 @@ public class MCToolsClient implements ClientModInitializer {
timeString.append(days).append("");
}
if (hours > 0) {
if (timeString.length() > 0) {
if (!timeString.isEmpty()) {
timeString.append(" ");
}
timeString.append(hours).append(" 小时");
}
if (minutes > 0 || timeString.length() == 0) {
if (timeString.length() > 0) {
if (minutes > 0 || timeString.isEmpty()) {
if (!timeString.isEmpty()) {
timeString.append(" ");
}
timeString.append(minutes).append(" 分钟");
@ -61,7 +61,7 @@ public class MCToolsClient implements ClientModInitializer {
private static void drawHUD(DrawContext drawContext, RenderTickCounter v) {
MinecraftClient mc=MinecraftClient.getInstance();
//跳过调试
if(mc.options.hudHidden) return;
if(mc.getDebugHud().shouldShowDebugHud()||mc.options.hudHidden) return;
if(mc.world!=null&&mc.player!=null) {
infoY=1;
@ -86,8 +86,6 @@ public class MCToolsClient implements ClientModInitializer {
AddText(drawContext,String.format("世界时间: %d天 (%s)",mc.world.getTimeOfDay()/24000,gameDayToRealTimeFormat(mc.world.getTimeOfDay()/24000)));
AddText(drawContext,String.format("当前区块: [%d,%d]",mc.player.getChunkPos().x,mc.player.getChunkPos().z));
AddText(drawContext,String.format("本地难度:%.2f",mc.world.getLocalDifficulty(mc.player.getBlockPos()).getLocalDifficulty()));
AddText(drawContext,String.format("服务器视距:%d 区块",mc.options.getSyncedOptions().viewDistance()));
ItemStack currentItem=p.getInventory().getMainHandStack();
if(currentItem!=null&&currentItem.isDamageable()){
AddText(drawContext,String.format("耐久度:%d/%d",currentItem.getMaxDamage()-currentItem.getDamage(),currentItem.getMaxDamage()));

View File

@ -3,6 +3,7 @@ package com.expvintl.mctools.commands;
import com.expvintl.mctools.Globals;
import com.expvintl.mctools.events.MCEventBus;
import com.expvintl.mctools.events.client.sounds.PlaySoundEvent;
import com.expvintl.mctools.utils.CommandUtils;
import com.expvintl.mctools.utils.Utils;
import com.google.common.eventbus.Subscribe;
import com.mojang.brigadier.Command;
@ -21,12 +22,14 @@ public class CAutoFishCommand {
private static final CAutoFishCommand INSTANCE=new CAutoFishCommand();
public static void register(CommandDispatcher<FabricClientCommandSource> dispatcher){
MCEventBus.INSTANCE.register(INSTANCE);
CommandUtils.CreateStatusCommand("cautofish",Globals.autoFish,dispatcher);
dispatcher.register(literal("cautofish").then(argument("开关", BoolArgumentType.bool()).executes(CAutoFishCommand::execute)));
}
private static int execute(CommandContext<FabricClientCommandSource> context) {
Globals.autoFish=context.getArgument("开关", Boolean.class);
if(Globals.autoFish){
Globals.autoFish.set(context.getArgument("开关", Boolean.class));
if(Globals.autoFish.get()){
context.getSource().getPlayer().sendMessage(Text.literal("已启用自动钓鱼!"));
}else{
context.getSource().getPlayer().sendMessage(Text.literal("已禁用自动钓鱼!"));
@ -35,7 +38,7 @@ public class CAutoFishCommand {
}
@Subscribe
private void onPlaySound(PlaySoundEvent event){
if(Globals.autoFish) {
if(Globals.autoFish.get()) {
//自动钓鱼
if (event.soundInstance.getId().getPath().equals("entity.fishing_bobber.splash")) {
//收杆

View File

@ -3,6 +3,8 @@ 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;
import com.mojang.brigadier.CommandDispatcher;
@ -20,12 +22,13 @@ public class CAutoRespawnCommand {
private static final CAutoRespawnCommand INSTANCE=new CAutoRespawnCommand();
public static void register(CommandDispatcher<FabricClientCommandSource> dispatcher){
MCEventBus.INSTANCE.register(INSTANCE);
CommandUtils.CreateStatusCommand("cautorespawn",Globals.autoRespawn,dispatcher);
dispatcher.register(literal("cautorespawn").then(argument("开关", BoolArgumentType.bool()).executes(CAutoRespawnCommand::execute)));
}
private static int execute(CommandContext<FabricClientCommandSource> context) {
Globals.autoRespawn=context.getArgument("开关", Boolean.class);
if(Globals.autoRespawn){
Globals.autoRespawn.set(context.getArgument("开关", Boolean.class));
if(Globals.autoRespawn.get()){
context.getSource().getPlayer().sendMessage(Text.literal("已启用自动重生!"));
}else{
context.getSource().getPlayer().sendMessage(Text.literal("已禁用自动重生!"));
@ -34,7 +37,7 @@ public class CAutoRespawnCommand {
}
@Subscribe
private void onOpenScreen(OpenScreenEvent event){
if(Globals.autoRespawn) {
if(Globals.autoRespawn.get()) {
//自动重生
if (event.screen instanceof DeathScreen) {
if (MinecraftClient.getInstance().player != null) {

View File

@ -6,6 +6,7 @@ import com.expvintl.mctools.events.player.PlayerAttackBlockEvent;
import com.expvintl.mctools.events.player.PlayerAttackEntityEvent;
import com.expvintl.mctools.events.player.PlayerBreakBlockEvent;
import com.expvintl.mctools.mixin.interfaces.ClientPlayerInteractionManagerAccessor;
import com.expvintl.mctools.utils.CommandUtils;
import com.expvintl.mctools.utils.Utils;
import com.google.common.eventbus.Subscribe;
import com.mojang.brigadier.Command;
@ -32,12 +33,13 @@ public class CAutoToolCommand {
private int lastSlot=-1;
public static void register(CommandDispatcher<FabricClientCommandSource> dispatcher){
MCEventBus.INSTANCE.register(INSTANCE);
CommandUtils.CreateStatusCommand("cautotool",Globals.autoTool,dispatcher);
dispatcher.register(literal("cautotool").then(argument("开关", BoolArgumentType.bool()).executes(CAutoToolCommand::execute)));
}
private static int execute(CommandContext<FabricClientCommandSource> context) {
Globals.autoTool=context.getArgument("开关", Boolean.class);
if(Globals.autoTool){
Globals.autoTool.set(context.getArgument("开关", Boolean.class));
if(Globals.autoTool.get()){
context.getSource().getPlayer().sendMessage(Text.literal("已启用智能工具!"));
}else{
context.getSource().getPlayer().sendMessage(Text.literal("已禁用智能工具!"));
@ -46,7 +48,7 @@ public class CAutoToolCommand {
}
@Subscribe
private void onBreakBlock(PlayerBreakBlockEvent event){
if(!Globals.autoTool) return;
if(!Globals.autoTool.get()) return;
MinecraftClient mc=MinecraftClient.getInstance();
if (mc.world == null||mc.player==null) return;
if (lastSlot!=-1){
@ -57,7 +59,7 @@ public class CAutoToolCommand {
}
@Subscribe
private void onAttackEntity(PlayerAttackEntityEvent event){
if(!Globals.autoTool) return;
if(!Globals.autoTool.get()) return;
if(event.target.hasCustomName()) return;
//不对玩家使用
if(event.target.isPlayer()) return;
@ -86,7 +88,7 @@ public class CAutoToolCommand {
}
@Subscribe
private void onAttackBlock(PlayerAttackBlockEvent event){
if(!Globals.autoTool) return;
if(!Globals.autoTool.get()) return;
//自动工具
MinecraftClient mc=MinecraftClient.getInstance();
if (mc.world == null||mc.player==null) return;

View File

@ -1,6 +1,7 @@
package com.expvintl.mctools.commands;
import com.expvintl.mctools.mixin.interfaces.SimpleOptionAccessor;
import com.expvintl.mctools.utils.PlayerUtils;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext;
@ -31,6 +32,9 @@ public class CFastDropCommand {
trashItem.add(Items.BASALT); //玄武岩
trashItem.add(Items.DIRT);//泥土
trashItem.add(Items.PUFFERFISH);//河豚
trashItem.add(Items.DANDELION);
trashItem.add(Items.SUNFLOWER);
trashItem.add(Items.CORNFLOWER);
}
private static int execute(CommandContext<FabricClientCommandSource> context) {
@ -43,7 +47,7 @@ public class CFastDropCommand {
ItemStack item = inv.main.get(i);
for (Item trash : trashItem) {
if (item.getItem() == trash) {
player.dropStack(item);
PlayerUtils.DropItem(i);
}
}
}

View File

@ -4,6 +4,7 @@ import com.expvintl.mctools.Globals;
import com.expvintl.mctools.events.MCEventBus;
import com.expvintl.mctools.events.network.PacketSendEvent;
import com.expvintl.mctools.mixin.interfaces.PlayerMoveC2SPacketAccessor;
import com.expvintl.mctools.utils.CommandUtils;
import com.google.common.eventbus.Subscribe;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher;
@ -22,12 +23,14 @@ public class CNoFallPacketCommand {
private static final MinecraftClient mc=MinecraftClient.getInstance();
public static void register(CommandDispatcher<FabricClientCommandSource> dispatcher){
MCEventBus.INSTANCE.register(INSTANCE);
CommandUtils.CreateStatusCommand("cnofallpacket",Globals.noFallPacket,dispatcher);
dispatcher.register(literal("cnofallpacket").then(argument("开关", BoolArgumentType.bool()).executes(CNoFallPacketCommand::execute)));
}
private static int execute(CommandContext<FabricClientCommandSource> context) {
Globals.noFallPacket=context.getArgument("开关", Boolean.class);
if(Globals.noFallPacket){
Globals.noFallPacket.set(context.getArgument("开关", Boolean.class));
if(Globals.noFallPacket.get()){
context.getSource().getPlayer().sendMessage(Text.literal("已启用摔落伤害!"));
}else{
context.getSource().getPlayer().sendMessage(Text.literal("已禁用摔落伤害!"));
@ -39,7 +42,7 @@ public class CNoFallPacketCommand {
//跳过非移动的数据包
if(!(event.packet instanceof PlayerMoveC2SPacket)) return;
//跳过创造
if(Globals.noFallPacket&& !mc.player.getAbilities().creativeMode){
if(Globals.noFallPacket.get()&& !mc.player.getAbilities().creativeMode){
if(mc.player.isFallFlying()) return;
if(mc.player.getVelocity().y> -0.5) return;
//直接发送在地面的数据包来免伤

View File

@ -29,13 +29,13 @@ public class CQServerPluginsCommand {
private static int execute(CommandContext<FabricClientCommandSource> context) {
//注册数据包接受事件
MCEventBus.INSTANCE.register(INSTANCE);
Globals.checkBukkitPlugins=true;
Globals.checkBukkitPlugins.set(true);
context.getSource().getPlayer().networkHandler.sendPacket(new RequestCommandCompletionsC2SPacket(new Random().nextInt(200),"bukkit:ver "));
//1秒后关闭避免识别其他命令提示
Utils.timer.schedule(new TimerTask() {
@Override
public void run() {
Globals.checkBukkitPlugins=false;
Globals.checkBukkitPlugins.set(false);
MCEventBus.INSTANCE.unregister(INSTANCE);
}
},1000);
@ -44,7 +44,7 @@ public class CQServerPluginsCommand {
@Subscribe
public void onReceivePacket(PacketReceiveEvent p){
//探测bukkit服务器插件
if (!MinecraftClient.getInstance().isIntegratedServerRunning()&& Globals.checkBukkitPlugins) {
if (!MinecraftClient.getInstance().isIntegratedServerRunning()&& Globals.checkBukkitPlugins.get()) {
if (p.packet instanceof CommandSuggestionsS2CPacket sg) {
StringBuilder buf=new StringBuilder();
buf.append(String.format("找到%d个插件:",sg.getSuggestions().getList().size())).append('\n');
@ -54,7 +54,7 @@ public class CQServerPluginsCommand {
if(MinecraftClient.getInstance().player!=null){
MinecraftClient.getInstance().player.sendMessage(Text.literal(buf.toString()));
}
Globals.checkBukkitPlugins=false;
Globals.checkBukkitPlugins.set(false);
//取消事件注册
MCEventBus.INSTANCE.unregister(INSTANCE);
}

View File

@ -1,6 +1,7 @@
package com.expvintl.mctools.commands;
import com.expvintl.mctools.Globals;
import com.expvintl.mctools.utils.CommandUtils;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.BoolArgumentType;
@ -13,12 +14,14 @@ import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.lit
public class CSafeWalkCommand {
public static void register(CommandDispatcher<FabricClientCommandSource> dispatcher){
CommandUtils.CreateStatusCommand("cselfwalk",Globals.selfWalk,dispatcher);
dispatcher.register(literal("cselfwalk").then(argument("开关", BoolArgumentType.bool()).executes(CSafeWalkCommand::execute)));
}
private static int execute(CommandContext<FabricClientCommandSource> context) {
Globals.selfWalk=context.getArgument("开关", Boolean.class);
if(Globals.selfWalk){
Globals.selfWalk.set(context.getArgument("开关", Boolean.class));
if(Globals.selfWalk.get()){
context.getSource().getPlayer().sendMessage(Text.literal("已启用自动挂边!"));
}else{
context.getSource().getPlayer().sendMessage(Text.literal("已禁用自动挂边!"));

View File

@ -15,7 +15,7 @@ public class PlayerEntityMixin {
if(MinecraftClient.getInstance().world!=null&&MinecraftClient.getInstance().player!=null) {
if (!MinecraftClient.getInstance().world.isClient) return;
//挂住边缘
if (Globals.selfWalk && !MinecraftClient.getInstance().player.isSneaking()) cir.setReturnValue(true);
if (Globals.selfWalk.get() && !MinecraftClient.getInstance().player.isSneaking()) cir.setReturnValue(true);
}
}
}

View File

@ -0,0 +1,11 @@
package com.expvintl.mctools.types;
public class GBool{
public boolean value=false;
public boolean get(){
return this.value;
}
public void set(boolean value){
this.value=value;
}
}

View File

@ -0,0 +1,16 @@
package com.expvintl.mctools.utils;
import com.expvintl.mctools.types.GBool;
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){
dispatcher.register(literal(cmd).executes((context -> {
context.getSource().getPlayer().sendMessage(Text.literal("当前启用状态: "+toggle.get()));
return Command.SINGLE_SUCCESS;
})));
}
}

View File

@ -0,0 +1,14 @@
package com.expvintl.mctools.utils;
import net.minecraft.client.MinecraftClient;
import net.minecraft.screen.slot.SlotActionType;
import java.util.Objects;
public class PlayerUtils {
public static void DropItem(int slot){
MinecraftClient mc=MinecraftClient.getInstance();
if(mc.interactionManager==null||mc.player==null) return;
mc.interactionManager.clickSlot(mc.player.currentScreenHandler.syncId, slot,1, SlotActionType.THROW,mc.player);
}
}