支持1.21,修复一些问题,为自动工具添加实体识别
This commit is contained in:
@ -1,10 +1,11 @@
|
||||
package com.expvintl.mctools;
|
||||
|
||||
public class FeaturesBool {
|
||||
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 int TPS=0;
|
||||
}
|
@ -11,6 +11,7 @@ import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
import net.minecraft.client.render.RenderTickCounter;
|
||||
import net.minecraft.command.CommandRegistryAccess;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Colors;
|
||||
@ -27,22 +28,40 @@ public class MCToolsClient implements ClientModInitializer {
|
||||
HudRenderCallback.EVENT.register(MCToolsClient::drawHUD);
|
||||
|
||||
}
|
||||
private static String gameDayToRealTimeFormat(long gameDays){
|
||||
long min=gameDays*20;
|
||||
if(min<60){
|
||||
return String.format("%d 分钟",min);
|
||||
}else if(min>60&&min<1440){
|
||||
return String.format("%d 小时",min/60);
|
||||
}else if(min>1440){
|
||||
return String.format("%d 天",(min/60)/24);
|
||||
}else {
|
||||
return String.format("%d 分钟",min);
|
||||
private static String gameDayToRealTimeFormat(long gameDays) {
|
||||
// 游戏 1 小时等于 20 分钟
|
||||
long totalMinutes = gameDays * 20;
|
||||
|
||||
long days = totalMinutes / (60 * 24); // 计算天数
|
||||
long remainingMinutesAfterDays = totalMinutes % (60 * 24);
|
||||
|
||||
long hours = remainingMinutesAfterDays / 60; // 计算小时数
|
||||
long minutes = remainingMinutesAfterDays % 60; // 计算剩余分钟数
|
||||
|
||||
StringBuilder timeString = new StringBuilder();
|
||||
|
||||
if (days > 0) {
|
||||
timeString.append(days).append(" 天");
|
||||
}
|
||||
if (hours > 0) {
|
||||
if (timeString.length() > 0) {
|
||||
timeString.append(" ");
|
||||
}
|
||||
timeString.append(hours).append(" 小时");
|
||||
}
|
||||
if (minutes > 0 || timeString.length() == 0) {
|
||||
if (timeString.length() > 0) {
|
||||
timeString.append(" ");
|
||||
}
|
||||
timeString.append(minutes).append(" 分钟");
|
||||
}
|
||||
|
||||
return timeString.toString();
|
||||
}
|
||||
private static void drawHUD(DrawContext drawContext, float v) {
|
||||
private static void drawHUD(DrawContext drawContext, RenderTickCounter v) {
|
||||
MinecraftClient mc=MinecraftClient.getInstance();
|
||||
//跳过调试
|
||||
if(mc.options.debugEnabled) return;
|
||||
if(mc.options.hudHidden) return;
|
||||
|
||||
if(mc.world!=null&&mc.player!=null) {
|
||||
infoY=1;
|
||||
@ -66,6 +85,9 @@ 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&¤tItem.isDamageable()){
|
||||
AddText(drawContext,String.format("耐久度:%d/%d",currentItem.getMaxDamage()-currentItem.getDamage(),currentItem.getMaxDamage()));
|
||||
@ -87,5 +109,6 @@ public class MCToolsClient implements ClientModInitializer {
|
||||
CQServerPluginsCommand.register(dispatcher);
|
||||
CNoFallPacketCommand.register(dispatcher);
|
||||
CFindBlockCommand.register(dispatcher);
|
||||
CFastDropCommand.register(dispatcher);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.expvintl.mctools.commands;
|
||||
|
||||
import com.expvintl.mctools.FeaturesBool;
|
||||
import com.expvintl.mctools.Globals;
|
||||
import com.expvintl.mctools.events.MCEventBus;
|
||||
import com.expvintl.mctools.events.client.sounds.PlaySoundEvent;
|
||||
import com.expvintl.mctools.utils.Utils;
|
||||
@ -25,8 +25,8 @@ public class CAutoFishCommand {
|
||||
}
|
||||
|
||||
private static int execute(CommandContext<FabricClientCommandSource> context) {
|
||||
FeaturesBool.autoFish=context.getArgument("开关", Boolean.class);
|
||||
if(FeaturesBool.autoFish){
|
||||
Globals.autoFish=context.getArgument("开关", Boolean.class);
|
||||
if(Globals.autoFish){
|
||||
context.getSource().getPlayer().sendMessage(Text.literal("已启用自动钓鱼!"));
|
||||
}else{
|
||||
context.getSource().getPlayer().sendMessage(Text.literal("已禁用自动钓鱼!"));
|
||||
@ -35,7 +35,7 @@ public class CAutoFishCommand {
|
||||
}
|
||||
@Subscribe
|
||||
private void onPlaySound(PlaySoundEvent event){
|
||||
if(FeaturesBool.autoFish) {
|
||||
if(Globals.autoFish) {
|
||||
//自动钓鱼
|
||||
if (event.soundInstance.getId().getPath().equals("entity.fishing_bobber.splash")) {
|
||||
//收杆
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.expvintl.mctools.commands;
|
||||
|
||||
import com.expvintl.mctools.FeaturesBool;
|
||||
import com.expvintl.mctools.Globals;
|
||||
import com.expvintl.mctools.events.MCEventBus;
|
||||
import com.expvintl.mctools.events.client.OpenScreenEvent;
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
@ -24,8 +24,8 @@ public class CAutoRespawnCommand {
|
||||
}
|
||||
|
||||
private static int execute(CommandContext<FabricClientCommandSource> context) {
|
||||
FeaturesBool.autoRespawn=context.getArgument("开关", Boolean.class);
|
||||
if(FeaturesBool.autoRespawn){
|
||||
Globals.autoRespawn=context.getArgument("开关", Boolean.class);
|
||||
if(Globals.autoRespawn){
|
||||
context.getSource().getPlayer().sendMessage(Text.literal("已启用自动重生!"));
|
||||
}else{
|
||||
context.getSource().getPlayer().sendMessage(Text.literal("已禁用自动重生!"));
|
||||
@ -34,7 +34,7 @@ public class CAutoRespawnCommand {
|
||||
}
|
||||
@Subscribe
|
||||
private void onOpenScreen(OpenScreenEvent event){
|
||||
if(FeaturesBool.autoRespawn) {
|
||||
if(Globals.autoRespawn) {
|
||||
//自动重生
|
||||
if (event.screen instanceof DeathScreen) {
|
||||
if (MinecraftClient.getInstance().player != null) {
|
||||
|
@ -1,10 +1,12 @@
|
||||
package com.expvintl.mctools.commands;
|
||||
|
||||
import com.expvintl.mctools.FeaturesBool;
|
||||
import com.expvintl.mctools.Globals;
|
||||
import com.expvintl.mctools.events.MCEventBus;
|
||||
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.Utils;
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
import com.mojang.brigadier.Command;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
@ -12,15 +14,14 @@ import com.mojang.brigadier.arguments.BoolArgumentType;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
|
||||
import net.minecraft.block.BambooBlock;
|
||||
import net.minecraft.block.BambooSaplingBlock;
|
||||
import net.minecraft.block.BambooShootBlock;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.component.DataComponentTypes;
|
||||
import net.minecraft.enchantment.Enchantments;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ShearsItem;
|
||||
import net.minecraft.item.SwordItem;
|
||||
import net.minecraft.item.ToolItem;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.*;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument;
|
||||
@ -35,8 +36,8 @@ public class CAutoToolCommand {
|
||||
}
|
||||
|
||||
private static int execute(CommandContext<FabricClientCommandSource> context) {
|
||||
FeaturesBool.autoTool=context.getArgument("开关", Boolean.class);
|
||||
if(FeaturesBool.autoTool){
|
||||
Globals.autoTool=context.getArgument("开关", Boolean.class);
|
||||
if(Globals.autoTool){
|
||||
context.getSource().getPlayer().sendMessage(Text.literal("已启用智能工具!"));
|
||||
}else{
|
||||
context.getSource().getPlayer().sendMessage(Text.literal("已禁用智能工具!"));
|
||||
@ -45,32 +46,25 @@ public class CAutoToolCommand {
|
||||
}
|
||||
@Subscribe
|
||||
private void onBreakBlock(PlayerBreakBlockEvent event){
|
||||
if(!FeaturesBool.autoTool) return;
|
||||
if(!Globals.autoTool) return;
|
||||
MinecraftClient mc=MinecraftClient.getInstance();
|
||||
if (mc.world == null||mc.player==null) return;
|
||||
if (lastSlot!=-1){
|
||||
//破坏方块后切换回去
|
||||
mc.player.getInventory().selectedSlot=lastSlot;
|
||||
lastSlot=-1;
|
||||
}
|
||||
}
|
||||
@Subscribe
|
||||
private void onAttackBlock(PlayerAttackBlockEvent event){
|
||||
if(!FeaturesBool.autoTool) return;
|
||||
//自动工具
|
||||
MinecraftClient mc=MinecraftClient.getInstance();
|
||||
if (mc.world == null||mc.player==null) return;
|
||||
BlockState state= mc.world.getBlockState(event.blockPos);
|
||||
//跳过不可破坏
|
||||
if(state.getHardness(mc.world, event.blockPos) < 0) return;
|
||||
ItemStack currentItem = mc.player.getMainHandStack();
|
||||
//统计最好的挖掘分数
|
||||
double bestScore=-1;
|
||||
//工具槽
|
||||
private void onAttackEntity(PlayerAttackEntityEvent event){
|
||||
if(!Globals.autoTool) return;
|
||||
if(event.target.hasCustomName()) return;
|
||||
//不对玩家使用
|
||||
if(event.target.isPlayer()) return;
|
||||
float bestScore=-1;
|
||||
int slot=-1;
|
||||
//遍历每一个物品槽
|
||||
for(int i=0;i<9;i++){
|
||||
ItemStack item = mc.player.getInventory().getStack(i);
|
||||
double score=getScore(item,state);
|
||||
for(int i=0;i<9;i++) {
|
||||
float score=getWeaponScore(event.player,event.target,i);
|
||||
if(score<0) continue;
|
||||
//选出最好分数的工具
|
||||
if(score>bestScore){
|
||||
@ -78,8 +72,46 @@ public class CAutoToolCommand {
|
||||
slot=i;
|
||||
}
|
||||
}
|
||||
if(slot==-1) return;
|
||||
ItemStack currentItem = event.player.getInventory().getStack(slot);
|
||||
//低耐久测试
|
||||
if(!lowDurability(currentItem)) {
|
||||
//切换过去
|
||||
event.player.getInventory().selectedSlot = slot;
|
||||
MinecraftClient mc=MinecraftClient.getInstance();
|
||||
if(mc.interactionManager!=null) {
|
||||
((ClientPlayerInteractionManagerAccessor) mc.interactionManager).syncSelectedSlot();
|
||||
}
|
||||
}
|
||||
}
|
||||
@Subscribe
|
||||
private void onAttackBlock(PlayerAttackBlockEvent event){
|
||||
if(!Globals.autoTool) return;
|
||||
//自动工具
|
||||
MinecraftClient mc=MinecraftClient.getInstance();
|
||||
if (mc.world == null||mc.player==null) return;
|
||||
BlockState state= mc.world.getBlockState(event.blockPos);
|
||||
//跳过不可破坏
|
||||
if(state.getHardness(mc.world, event.blockPos) < 0) return;
|
||||
//统计最好的挖掘分数
|
||||
float bestScore=-1;
|
||||
//工具槽
|
||||
int slot=-1;
|
||||
//遍历每一个物品槽
|
||||
for(int i=0;i<9;i++){
|
||||
ItemStack item = mc.player.getInventory().getStack(i);
|
||||
float score=getScore(item,state);
|
||||
if(score<0) continue;
|
||||
//选出最好分数的工具
|
||||
if(score>bestScore){
|
||||
bestScore=score;
|
||||
slot=i;
|
||||
}
|
||||
}
|
||||
if(slot==-1) return;
|
||||
ItemStack currentItem = mc.player.getInventory().getStack(slot);
|
||||
//确定已经选择好了工具就切换
|
||||
if((slot!=-1&&bestScore>getScore(currentItem,state)&&!lowDurability(currentItem))||!isTools(currentItem)) {
|
||||
if(!lowDurability(currentItem)) {
|
||||
//记住上一次的槽方便恢复
|
||||
lastSlot=mc.player.getInventory().selectedSlot;
|
||||
//切换过去
|
||||
@ -89,30 +121,46 @@ public class CAutoToolCommand {
|
||||
}
|
||||
}
|
||||
}
|
||||
public double getScore(ItemStack item, BlockState state){
|
||||
double score=0;
|
||||
public float getScore(ItemStack item, BlockState state){
|
||||
float score=0;
|
||||
//Is Tool!!
|
||||
if(item.getItem() instanceof ToolItem || item.getItem() instanceof ShearsItem){
|
||||
//根据挖掘速度提升评分
|
||||
score+=item.getMiningSpeedMultiplier(state)*10;
|
||||
score+=item.getMiningSpeedMultiplier(state)*30;
|
||||
//附魔加分
|
||||
//耐久
|
||||
score+= EnchantmentHelper.getLevel(Enchantments.UNBREAKING,item)*10;
|
||||
score+= Utils.GetEnchantLevel(Enchantments.UNBREAKING, item);
|
||||
//效率
|
||||
score+=EnchantmentHelper.getLevel(Enchantments.EFFICIENCY,item)*5;
|
||||
score+=Utils.GetEnchantLevel(Enchantments.EFFICIENCY,item);
|
||||
//经验修补(此项最优先)
|
||||
score+=EnchantmentHelper.getLevel(Enchantments.MENDING,item)*20;
|
||||
if (item.getItem() instanceof SwordItem item1 && (state.getBlock() instanceof BambooBlock || state.getBlock() instanceof BambooSaplingBlock))
|
||||
score+=Utils.GetEnchantLevel(Enchantments.MENDING,item);
|
||||
if (item.getItem() instanceof SwordItem item1 && (state.getBlock() instanceof BambooBlock|| state.getBlock() instanceof BambooShootBlock))
|
||||
//根据挖掘等级加分
|
||||
score += 90 + (item1.getMaterial().getMiningLevel() * 10);
|
||||
score += 90 + (item1.getComponents().get(DataComponentTypes.TOOL).getSpeed(state) * 10);
|
||||
}
|
||||
return score;
|
||||
}
|
||||
public float getWeaponScore(PlayerEntity player,Entity target,int slot) {
|
||||
float damageScore = 0;
|
||||
ItemStack item = player.getInventory().getStack(slot);
|
||||
//剑优先
|
||||
if(item.getItem() instanceof SwordItem) damageScore+=10;
|
||||
//使用所有工具组
|
||||
if (item.getItem() instanceof ToolItem tool) {
|
||||
damageScore += tool.getMaterial().getAttackDamage();
|
||||
//锋利加分
|
||||
damageScore += Utils.GetEnchantLevel(Enchantments.SHARPNESS, item) * 2;
|
||||
//精修
|
||||
damageScore+=Utils.GetEnchantLevel(Enchantments.MENDING,item);
|
||||
//火焰附加
|
||||
damageScore+=Utils.GetEnchantLevel(Enchantments.FIRE_ASPECT,item)*3;
|
||||
//击退
|
||||
damageScore+=Utils.GetEnchantLevel(Enchantments.KNOCKBACK,item)*2;
|
||||
}
|
||||
return damageScore;
|
||||
}
|
||||
//停用低耐久度
|
||||
private boolean lowDurability(ItemStack itemStack) {
|
||||
return (itemStack.getMaxDamage() - itemStack.getDamage()) < (itemStack.getMaxDamage() * 10 / 100);
|
||||
}
|
||||
public boolean isTools(ItemStack item){
|
||||
return item.getItem() instanceof ToolItem || item.getItem() instanceof ShearsItem;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,54 @@
|
||||
package com.expvintl.mctools.commands;
|
||||
|
||||
import com.expvintl.mctools.mixin.interfaces.SimpleOptionAccessor;
|
||||
import com.mojang.brigadier.Command;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal;
|
||||
|
||||
public class CFastDropCommand {
|
||||
public static List<Item> trashItem=new ArrayList<>();
|
||||
public static void register(CommandDispatcher<FabricClientCommandSource> dispatcher){
|
||||
dispatcher.register(literal("cfastdrop").executes(CFastDropCommand::execute));
|
||||
trashItem.add(Items.COBBLESTONE);
|
||||
trashItem.add(Items.GRANITE);//花岗岩
|
||||
trashItem.add(Items.ANDESITE);//安山岩
|
||||
trashItem.add(Items.DIORITE);//闪长岩
|
||||
trashItem.add(Items.GRAVEL);//沙砾
|
||||
trashItem.add(Items.NETHERRACK);//地狱岩
|
||||
trashItem.add(Items.BLACKSTONE);//黑石
|
||||
trashItem.add(Items.BASALT); //玄武岩
|
||||
trashItem.add(Items.DIRT);//泥土
|
||||
trashItem.add(Items.PUFFERFISH);//河豚
|
||||
}
|
||||
|
||||
private static int execute(CommandContext<FabricClientCommandSource> context) {
|
||||
ClientPlayerEntity player=context.getSource().getPlayer();
|
||||
if(player==null){
|
||||
return 0;
|
||||
}
|
||||
PlayerInventory inv=player.getInventory();
|
||||
for(int i=0;i<inv.main.size();i++) {
|
||||
ItemStack item = inv.main.get(i);
|
||||
for (Item trash : trashItem) {
|
||||
if (item.getItem() == trash) {
|
||||
player.dropStack(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
player.sendMessage(Text.literal("已丢弃无用物品!"));
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
}
|
@ -1,13 +1,11 @@
|
||||
package com.expvintl.mctools.commands;
|
||||
|
||||
import com.expvintl.mctools.FeaturesBool;
|
||||
import com.expvintl.mctools.events.MCEventBus;
|
||||
import com.expvintl.mctools.events.client.RenderWorldEvent;
|
||||
import com.expvintl.mctools.utils.Utils;
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
import com.mojang.brigadier.Command;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.BoolArgumentType;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.expvintl.mctools.commands;
|
||||
|
||||
import com.expvintl.mctools.FeaturesBool;
|
||||
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;
|
||||
@ -26,11 +26,11 @@ public class CNoFallPacketCommand {
|
||||
}
|
||||
|
||||
private static int execute(CommandContext<FabricClientCommandSource> context) {
|
||||
FeaturesBool.noFallPacket=context.getArgument("开关", Boolean.class);
|
||||
if(FeaturesBool.noFallPacket){
|
||||
context.getSource().getPlayer().sendMessage(Text.literal("已启用无坠落数据包!"));
|
||||
Globals.noFallPacket=context.getArgument("开关", Boolean.class);
|
||||
if(Globals.noFallPacket){
|
||||
context.getSource().getPlayer().sendMessage(Text.literal("已启用摔落伤害!"));
|
||||
}else{
|
||||
context.getSource().getPlayer().sendMessage(Text.literal("已禁用无坠落数据包!"));
|
||||
context.getSource().getPlayer().sendMessage(Text.literal("已禁用摔落伤害!"));
|
||||
}
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
@ -39,9 +39,9 @@ public class CNoFallPacketCommand {
|
||||
//跳过非移动的数据包
|
||||
if(!(event.packet instanceof PlayerMoveC2SPacket)) return;
|
||||
//跳过创造
|
||||
if(FeaturesBool.noFallPacket&& !mc.player.getAbilities().creativeMode){
|
||||
if(Globals.noFallPacket&& !mc.player.getAbilities().creativeMode){
|
||||
if(mc.player.isFallFlying()) return;
|
||||
if(mc.player.getVelocity().y>-0.5) return;
|
||||
if(mc.player.getVelocity().y> -0.5) return;
|
||||
//直接发送在地面的数据包来免伤
|
||||
((PlayerMoveC2SPacketAccessor)event.packet).setOnGround(true);
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.expvintl.mctools.commands;
|
||||
|
||||
import com.expvintl.mctools.FeaturesBool;
|
||||
import com.expvintl.mctools.Globals;
|
||||
import com.expvintl.mctools.events.MCEventBus;
|
||||
import com.expvintl.mctools.events.network.PacketReceiveEvent;
|
||||
import com.expvintl.mctools.utils.Utils;
|
||||
@ -29,13 +29,13 @@ public class CQServerPluginsCommand {
|
||||
private static int execute(CommandContext<FabricClientCommandSource> context) {
|
||||
//注册数据包接受事件
|
||||
MCEventBus.INSTANCE.register(INSTANCE);
|
||||
FeaturesBool.checkBukkitPlugins=true;
|
||||
Globals.checkBukkitPlugins=true;
|
||||
context.getSource().getPlayer().networkHandler.sendPacket(new RequestCommandCompletionsC2SPacket(new Random().nextInt(200),"bukkit:ver "));
|
||||
//1秒后关闭避免识别其他命令提示
|
||||
Utils.timer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
FeaturesBool.checkBukkitPlugins=false;
|
||||
Globals.checkBukkitPlugins=false;
|
||||
MCEventBus.INSTANCE.unregister(INSTANCE);
|
||||
}
|
||||
},1000);
|
||||
@ -44,7 +44,7 @@ public class CQServerPluginsCommand {
|
||||
@Subscribe
|
||||
public void onReceivePacket(PacketReceiveEvent p){
|
||||
//探测bukkit服务器插件
|
||||
if (!MinecraftClient.getInstance().isIntegratedServerRunning()&&FeaturesBool.checkBukkitPlugins) {
|
||||
if (!MinecraftClient.getInstance().isIntegratedServerRunning()&& Globals.checkBukkitPlugins) {
|
||||
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()));
|
||||
}
|
||||
FeaturesBool.checkBukkitPlugins=false;
|
||||
Globals.checkBukkitPlugins=false;
|
||||
//取消事件注册
|
||||
MCEventBus.INSTANCE.unregister(INSTANCE);
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.expvintl.mctools.commands;
|
||||
|
||||
import com.expvintl.mctools.FeaturesBool;
|
||||
import com.expvintl.mctools.Globals;
|
||||
import com.mojang.brigadier.Command;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.BoolArgumentType;
|
||||
@ -17,8 +17,8 @@ public class CSafeWalkCommand {
|
||||
}
|
||||
|
||||
private static int execute(CommandContext<FabricClientCommandSource> context) {
|
||||
FeaturesBool.selfWalk=context.getArgument("开关", Boolean.class);
|
||||
if(FeaturesBool.selfWalk){
|
||||
Globals.selfWalk=context.getArgument("开关", Boolean.class);
|
||||
if(Globals.selfWalk){
|
||||
context.getSource().getPlayer().sendMessage(Text.literal("已启用自动挂边!"));
|
||||
}else{
|
||||
context.getSource().getPlayer().sendMessage(Text.literal("已禁用自动挂边!"));
|
||||
|
@ -0,0 +1,16 @@
|
||||
package com.expvintl.mctools.events.player;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public class PlayerAttackEntityEvent {
|
||||
private static final PlayerAttackEntityEvent INSTANCE=new PlayerAttackEntityEvent();
|
||||
public PlayerEntity player;
|
||||
public Entity target;
|
||||
public static PlayerAttackEntityEvent get(PlayerEntity playerEntity, Entity target){
|
||||
INSTANCE.player=playerEntity;
|
||||
INSTANCE.target=target;
|
||||
return INSTANCE;
|
||||
}
|
||||
}
|
22
src/main/java/com/expvintl/mctools/gui/MainMenu.java
Normal file
22
src/main/java/com/expvintl/mctools/gui/MainMenu.java
Normal file
@ -0,0 +1,22 @@
|
||||
package com.expvintl.mctools.gui;
|
||||
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
public class MainMenu extends Screen {
|
||||
public MainMenu(Text title) {
|
||||
super(title);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
|
||||
context.drawText(textRenderer,"Test",100,100,-1,false);
|
||||
super.render(context, mouseX, mouseY, delta);
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package com.expvintl.mctools.mixin;
|
||||
|
||||
import com.expvintl.mctools.events.MCEventBus;
|
||||
import com.expvintl.mctools.events.client.RenderWorldEvent;
|
||||
import net.minecraft.client.render.Camera;
|
||||
import net.minecraft.client.render.GameRenderer;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import org.joml.Matrix3f;
|
||||
import org.joml.Matrix4f;
|
||||
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.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
|
||||
|
||||
@Mixin(GameRenderer.class)
|
||||
public abstract class GameRendererMixin {
|
||||
|
||||
@Inject(method = "renderWorld",at=@At(value = "INVOKE_STRING",target = "Lnet/minecraft/util/profiler/Profiler;swap(Ljava/lang/String;)V",args = {"ldc=hand"}),locals = LocalCapture.CAPTURE_FAILEXCEPTION)
|
||||
private void onRenderWorld(float tickDelta, long limitTime, MatrixStack matrices, CallbackInfo ci, MatrixStack matrices1, boolean bl, Camera camera, MatrixStack matrixStack, double d, float f, float g, Matrix4f matrix4f, Matrix3f matrix3f){
|
||||
MCEventBus.INSTANCE.post(RenderWorldEvent.get(tickDelta,camera,matrices));
|
||||
}
|
||||
}
|
@ -2,13 +2,17 @@ package com.expvintl.mctools.mixin.player;
|
||||
|
||||
import com.expvintl.mctools.events.MCEventBus;
|
||||
import com.expvintl.mctools.events.player.PlayerAttackBlockEvent;
|
||||
import com.expvintl.mctools.events.player.PlayerAttackEntityEvent;
|
||||
import com.expvintl.mctools.events.player.PlayerBreakBlockEvent;
|
||||
import net.minecraft.client.network.ClientPlayerInteractionManager;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
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.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(ClientPlayerInteractionManager.class)
|
||||
@ -21,4 +25,8 @@ public class ClientPlayerInteractionManagerMixin {
|
||||
private void onAttackBlock(BlockPos blockPos, Direction direction, CallbackInfoReturnable<Boolean> info){
|
||||
MCEventBus.INSTANCE.post(PlayerAttackBlockEvent.get(blockPos,direction));
|
||||
}
|
||||
@Inject(method = "attackEntity",at=@At("HEAD"))
|
||||
private void onAttackEntity(PlayerEntity player, Entity target, CallbackInfo info){
|
||||
MCEventBus.INSTANCE.post(PlayerAttackEntityEvent.get(player,target));
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.expvintl.mctools.mixin.player;
|
||||
|
||||
import com.expvintl.mctools.FeaturesBool;
|
||||
import com.expvintl.mctools.Globals;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
@ -15,7 +15,7 @@ public class PlayerEntityMixin {
|
||||
if(MinecraftClient.getInstance().world!=null&&MinecraftClient.getInstance().player!=null) {
|
||||
if (!MinecraftClient.getInstance().world.isClient) return;
|
||||
//挂住边缘
|
||||
if (FeaturesBool.selfWalk && !MinecraftClient.getInstance().player.isSneaking()) cir.setReturnValue(true);
|
||||
if (Globals.selfWalk && !MinecraftClient.getInstance().player.isSneaking()) cir.setReturnValue(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.expvintl.mctools.utils;
|
||||
|
||||
import com.expvintl.mctools.mixin.interfaces.MinecraftClientAccessor;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
@ -9,7 +10,12 @@ import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.gui.hud.ChatHudLine;
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
import net.minecraft.client.network.PlayerListEntry;
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
import net.minecraft.enchantment.Enchantments;
|
||||
import net.minecraft.item.ItemStack;
|
||||
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.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
@ -20,7 +26,9 @@ import net.minecraft.world.biome.Biome;
|
||||
import java.awt.*;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.Timer;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class Utils {
|
||||
private static final MinecraftClient mc = MinecraftClient.getInstance();
|
||||
@ -28,7 +36,7 @@ public class Utils {
|
||||
|
||||
public static String getCurrentDimensionName() {
|
||||
if (mc.world != null) {
|
||||
String dismenName = mc.world.getDimensionKey().getValue().toString();
|
||||
String dismenName = mc.world.getDimensionEntry().getIdAsString();
|
||||
switch (dismenName) {
|
||||
case "minecraft:overworld":
|
||||
return "主世界";
|
||||
@ -183,23 +191,28 @@ public class Utils {
|
||||
return "未知";
|
||||
}
|
||||
|
||||
public static int GetEnchantLevel(RegistryKey<Enchantment> enchantName, ItemStack item){
|
||||
//跳过附魔书
|
||||
if(item.getItem()== Items.ENCHANTED_BOOK) return 0;
|
||||
Set<Object2IntMap.Entry<RegistryEntry<Enchantment>>> enchants=item.getEnchantments().getEnchantmentEntries();
|
||||
for(Object2IntMap.Entry<RegistryEntry<Enchantment>> entry:enchants){
|
||||
//返回找到的附魔等级
|
||||
if(entry.getKey().matchesKey(enchantName)) {
|
||||
return entry.getIntValue();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
public static void rightClick() {
|
||||
((MinecraftClientAccessor) mc).doItemUse();
|
||||
}
|
||||
|
||||
public static Identifier getPlayerSkinTexture(String name) {
|
||||
if (Objects.isNull(mc.getNetworkHandler())) return null;
|
||||
PlayerListEntry entry = mc.getNetworkHandler().getPlayerListEntry(name);
|
||||
if (Objects.isNull(entry)) return null;
|
||||
return entry.getSkinTexture();
|
||||
}
|
||||
|
||||
public static void findBlock(ClientPlayerEntity player, String itemName, int radius) {
|
||||
if (mc.world == null) return;
|
||||
Vec3d pos = player.getBlockPos().toCenterPos();
|
||||
for (int hight = (int)pos.y - 5; hight < pos.y; hight++) {
|
||||
for (int x = (int) pos.x; x < (pos.x + radius); x++) {
|
||||
for (int z = (int) pos.z; z < (pos.z + radius); z++) {
|
||||
for (int hight = (int)pos.y - 15; hight < pos.y; hight++) {
|
||||
for (int x = (int) -pos.x; x < (pos.x + radius); x++) {
|
||||
for (int z = (int) -pos.z; z < (pos.z + radius); z++) {
|
||||
BlockState b = mc.world.getBlockState(new BlockPos(x, hight, z));
|
||||
if (b.getBlock().asItem().getName().getString().equals(itemName)) {
|
||||
mc.player.sendMessage(Text.literal(String.format("找到方块:%d,%d,%d", x, hight, z)));
|
||||
|
@ -6,10 +6,9 @@
|
||||
"description": "",
|
||||
"authors": [],
|
||||
"contact": {
|
||||
"repo": "https://github.com/undefined/MCTools"
|
||||
"repo": "https://github.com/expvintl/MCTools"
|
||||
},
|
||||
"license": "All-Rights-Reserved",
|
||||
"icon": "assets/mctools/icon.png",
|
||||
"environment": "client",
|
||||
"entrypoints": {
|
||||
"client": [
|
||||
@ -20,8 +19,8 @@
|
||||
"mctools.mixins.json"
|
||||
],
|
||||
"depends": {
|
||||
"fabricloader": ">=${loader_version}",
|
||||
"fabricloader": ">=0.8.0",
|
||||
"fabric": "*",
|
||||
"minecraft": "1.20.1"
|
||||
"minecraft": "~1.21"
|
||||
}
|
||||
}
|
||||
|
@ -2,14 +2,13 @@
|
||||
"required": true,
|
||||
"minVersion": "0.8",
|
||||
"package": "com.expvintl.mctools.mixin",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"compatibilityLevel": "JAVA_21",
|
||||
"mixins": [
|
||||
"interfaces.PlayerMoveC2SPacketAccessor",
|
||||
"network.ClientConnectionMixin",
|
||||
"player.PlayerEntityMixin"
|
||||
],
|
||||
"client": [
|
||||
"GameRendererMixin",
|
||||
"MinecraftClientMixin",
|
||||
"SoundSystemMixin",
|
||||
"interfaces.ClientPlayerInteractionManagerAccessor",
|
||||
|
Reference in New Issue
Block a user