This commit is contained in:
@ -2,6 +2,7 @@ package com.expvintl.mctools;
|
|||||||
|
|
||||||
import com.expvintl.mctools.commands.*;
|
import com.expvintl.mctools.commands.*;
|
||||||
import com.expvintl.mctools.modules.BetterTooltip;
|
import com.expvintl.mctools.modules.BetterTooltip;
|
||||||
|
import com.expvintl.mctools.modules.CameraZoom;
|
||||||
import com.expvintl.mctools.modules.PlayerListTextLatency;
|
import com.expvintl.mctools.modules.PlayerListTextLatency;
|
||||||
import com.expvintl.mctools.texthud.MCInfo;
|
import com.expvintl.mctools.texthud.MCInfo;
|
||||||
import com.expvintl.mctools.texthud.PotionInfo;
|
import com.expvintl.mctools.texthud.PotionInfo;
|
||||||
@ -34,6 +35,7 @@ public class MCToolsClient implements ClientModInitializer {
|
|||||||
public void InitModules(){
|
public void InitModules(){
|
||||||
BetterTooltip.INSTANCE.init();
|
BetterTooltip.INSTANCE.init();
|
||||||
PlayerListTextLatency.INSTANCE.init();
|
PlayerListTextLatency.INSTANCE.init();
|
||||||
|
CameraZoom.INSTANCE.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void registerCommands(CommandDispatcher<FabricClientCommandSource> dispatcher, CommandRegistryAccess registryAccess) {
|
private static void registerCommands(CommandDispatcher<FabricClientCommandSource> dispatcher, CommandRegistryAccess registryAccess) {
|
||||||
|
@ -19,21 +19,24 @@ import net.minecraft.block.BambooShootBlock;
|
|||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.component.DataComponentTypes;
|
import net.minecraft.component.DataComponentTypes;
|
||||||
|
import net.minecraft.component.type.AttributeModifiersComponent;
|
||||||
import net.minecraft.enchantment.EnchantmentHelper;
|
import net.minecraft.enchantment.EnchantmentHelper;
|
||||||
import net.minecraft.enchantment.Enchantments;
|
import net.minecraft.enchantment.Enchantments;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.EquipmentSlot;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.attribute.EntityAttribute;
|
||||||
|
import net.minecraft.entity.attribute.EntityAttributeModifier;
|
||||||
|
import net.minecraft.entity.attribute.EntityAttributes;
|
||||||
import net.minecraft.item.*;
|
import net.minecraft.item.*;
|
||||||
|
import net.minecraft.registry.entry.RegistryEntry;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.util.function.BiConsumer;
|
||||||
|
|
||||||
import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument;
|
import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument;
|
||||||
import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal;
|
import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal;
|
||||||
|
|
||||||
public class CAutoToolCommand {
|
public class CAutoToolCommand {
|
||||||
private static final CAutoToolCommand INSTANCE=new CAutoToolCommand();
|
private static final CAutoToolCommand INSTANCE=new CAutoToolCommand();
|
||||||
private int lastSlot=-1;
|
|
||||||
public static void register(CommandDispatcher<FabricClientCommandSource> dispatcher){
|
public static void register(CommandDispatcher<FabricClientCommandSource> dispatcher){
|
||||||
MCEventBus.INSTANCE.register(INSTANCE);
|
MCEventBus.INSTANCE.register(INSTANCE);
|
||||||
CommandUtils.CreateStatusCommand("cautotool",Globals.autoTool,dispatcher);
|
CommandUtils.CreateStatusCommand("cautotool",Globals.autoTool,dispatcher);
|
||||||
@ -49,17 +52,12 @@ public class CAutoToolCommand {
|
|||||||
}
|
}
|
||||||
return Command.SINGLE_SUCCESS;
|
return Command.SINGLE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
private void onBreakBlock(PlayerBreakBlockEvent event){
|
private void onBreakBlock(PlayerBreakBlockEvent event){
|
||||||
if(!Globals.autoTool.get()) return;
|
if(!Globals.autoTool.get()) return;
|
||||||
MinecraftClient mc=MinecraftClient.getInstance();
|
MinecraftClient mc=MinecraftClient.getInstance();
|
||||||
if (mc.world == null||mc.player==null) return;
|
if (mc.world == null||mc.player==null) return;
|
||||||
//TODO: 因bug禁用
|
|
||||||
// if (lastSlot!=-1){
|
|
||||||
// //破坏方块后切换回去
|
|
||||||
// mc.player.getInventory().setSelectedSlot(lastSlot);
|
|
||||||
// lastSlot=-1;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
@Subscribe
|
@Subscribe
|
||||||
private void onAttackEntity(PlayerAttackEntityEvent event){
|
private void onAttackEntity(PlayerAttackEntityEvent event){
|
||||||
@ -70,8 +68,10 @@ public class CAutoToolCommand {
|
|||||||
float bestScore=-1;
|
float bestScore=-1;
|
||||||
int slot=-1;
|
int slot=-1;
|
||||||
for(int i=0;i<9;i++) {
|
for(int i=0;i<9;i++) {
|
||||||
float score=getWeaponScore(event.player,i);
|
ItemStack item = event.player.getInventory().getStack(i);
|
||||||
if(score<0) continue;
|
if(!isSwordItem(item.getItem())&&!isToolItem(item.getItem())) continue;
|
||||||
|
float score=getWeaponScore(item);
|
||||||
|
if(score<=0) continue;
|
||||||
//选出最好分数的工具
|
//选出最好分数的工具
|
||||||
if(score>bestScore){
|
if(score>bestScore){
|
||||||
bestScore=score;
|
bestScore=score;
|
||||||
@ -81,7 +81,7 @@ public class CAutoToolCommand {
|
|||||||
if(slot==-1) return;
|
if(slot==-1) return;
|
||||||
ItemStack currentItem = event.player.getInventory().getStack(slot);
|
ItemStack currentItem = event.player.getInventory().getStack(slot);
|
||||||
//低耐久测试
|
//低耐久测试
|
||||||
if(!lowDurability(currentItem)) {
|
if(!isLowDurability(currentItem)) {
|
||||||
//切换过去
|
//切换过去
|
||||||
event.player.getInventory().setSelectedSlot(slot);
|
event.player.getInventory().setSelectedSlot(slot);
|
||||||
MinecraftClient mc=MinecraftClient.getInstance();
|
MinecraftClient mc=MinecraftClient.getInstance();
|
||||||
@ -90,6 +90,7 @@ public class CAutoToolCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//方块挖掘
|
||||||
@Subscribe
|
@Subscribe
|
||||||
private void onAttackBlock(PlayerAttackBlockEvent event){
|
private void onAttackBlock(PlayerAttackBlockEvent event){
|
||||||
if(!Globals.autoTool.get()) return;
|
if(!Globals.autoTool.get()) return;
|
||||||
@ -117,9 +118,7 @@ public class CAutoToolCommand {
|
|||||||
if(slot==-1) return;
|
if(slot==-1) return;
|
||||||
ItemStack currentItem = mc.player.getInventory().getStack(slot);
|
ItemStack currentItem = mc.player.getInventory().getStack(slot);
|
||||||
//确定已经选择好了工具就切换
|
//确定已经选择好了工具就切换
|
||||||
if(!lowDurability(currentItem)) {
|
if(!isLowDurability(currentItem)) {
|
||||||
//记住上一次的槽方便恢复
|
|
||||||
lastSlot=mc.player.getInventory().getSelectedSlot();
|
|
||||||
//切换过去
|
//切换过去
|
||||||
mc.player.getInventory().setSelectedSlot(slot);
|
mc.player.getInventory().setSelectedSlot(slot);
|
||||||
if(mc.interactionManager!=null) {
|
if(mc.interactionManager!=null) {
|
||||||
@ -158,27 +157,43 @@ public class CAutoToolCommand {
|
|||||||
}
|
}
|
||||||
return score;
|
return score;
|
||||||
}
|
}
|
||||||
public float getWeaponScore(PlayerEntity player,int slot) {
|
public float getWeaponScore(ItemStack item) {
|
||||||
float damageScore = 0;
|
float damageScore = 0;
|
||||||
ItemStack item = player.getInventory().getStack(slot);
|
|
||||||
//剑优先
|
//剑优先
|
||||||
if(isSwordItem(item.getItem())) damageScore+=10;
|
if (isSwordItem(item.getItem())) damageScore += 100;
|
||||||
//使用所有工具组
|
AttributeModifiersComponent comp=item.getOrDefault(DataComponentTypes.ATTRIBUTE_MODIFIERS, AttributeModifiersComponent.DEFAULT);
|
||||||
if (isToolItem(item.getItem())) {
|
final float[] damageHolder = {0.0f};
|
||||||
damageScore += item.getDamage();
|
BiConsumer<RegistryEntry<EntityAttribute>, EntityAttributeModifier> baseDamage=(attentry, modify)->{
|
||||||
|
if(attentry.matches(EntityAttributes.ATTACK_DAMAGE)){
|
||||||
|
//计算基础伤害
|
||||||
|
damageHolder [0]= (float)modify.value();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
comp.applyModifiers(EquipmentSlot.MAINHAND,baseDamage);
|
||||||
|
damageScore+=damageHolder[0];
|
||||||
//锋利加分
|
//锋利加分
|
||||||
damageScore += Utils.GetEnchantLevel(Enchantments.SHARPNESS, item) * 2;
|
damageScore += Utils.GetEnchantLevel(Enchantments.SHARPNESS, item) * 2;
|
||||||
//精修
|
//精修
|
||||||
damageScore+=Utils.GetEnchantLevel(Enchantments.MENDING,item);
|
damageScore += Utils.GetEnchantLevel(Enchantments.MENDING, item);
|
||||||
//火焰附加
|
//火焰附加
|
||||||
damageScore+=Utils.GetEnchantLevel(Enchantments.FIRE_ASPECT,item)*3;
|
damageScore += Utils.GetEnchantLevel(Enchantments.FIRE_ASPECT, item) * 3;
|
||||||
//击退
|
//击退
|
||||||
damageScore+=Utils.GetEnchantLevel(Enchantments.KNOCKBACK,item)*2;
|
damageScore += Utils.GetEnchantLevel(Enchantments.KNOCKBACK, item) * 2;
|
||||||
}
|
|
||||||
return damageScore;
|
return damageScore;
|
||||||
}
|
}
|
||||||
//停用低耐久度
|
//停用低耐久度
|
||||||
private boolean lowDurability(ItemStack itemStack) {
|
private boolean isLowDurability(ItemStack itemStack) {
|
||||||
return (itemStack.getMaxDamage() - itemStack.getDamage()) < (itemStack.getMaxDamage() * 10 / 100);
|
Item item = itemStack.getItem();
|
||||||
|
boolean isWooden = item == Items.WOODEN_SWORD || item == Items.WOODEN_PICKAXE ||
|
||||||
|
item == Items.WOODEN_AXE || item == Items.WOODEN_SHOVEL ||
|
||||||
|
item == Items.WOODEN_HOE;
|
||||||
|
boolean isStone = item == Items.STONE_SWORD || item == Items.STONE_PICKAXE ||
|
||||||
|
item == Items.STONE_AXE || item == Items.STONE_SHOVEL ||
|
||||||
|
item == Items.STONE_HOE;
|
||||||
|
boolean isIron = item == Items.IRON_SWORD || item == Items.IRON_PICKAXE ||
|
||||||
|
item == Items.IRON_AXE || item == Items.IRON_SHOVEL ||
|
||||||
|
item == Items.IRON_HOE;
|
||||||
|
return !(isWooden||isStone||isIron) //忽略木/石/铁工具
|
||||||
|
&&(itemStack.getMaxDamage() - itemStack.getDamage()) < (itemStack.getMaxDamage() * 10 / 100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,19 @@
|
|||||||
|
package com.expvintl.mctools.mixin.client;
|
||||||
|
|
||||||
|
import com.expvintl.mctools.modules.CameraZoom;
|
||||||
|
import com.expvintl.mctools.utils.Utils;
|
||||||
|
import com.llamalad7.mixinextras.injector.ModifyReturnValue;
|
||||||
|
import net.minecraft.client.MinecraftClient;
|
||||||
|
import net.minecraft.client.render.GameRenderer;
|
||||||
|
import net.minecraft.util.math.MathHelper;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
||||||
|
|
||||||
|
@Mixin(GameRenderer.class)
|
||||||
|
public class GameRendererMixin {
|
||||||
|
@ModifyReturnValue(method = "getFov",at=@At("RETURN"))
|
||||||
|
private float getFov(float origin){
|
||||||
|
return CameraZoom.INSTANCE.isZoom?20.f:origin;
|
||||||
|
}
|
||||||
|
}
|
20
src/main/java/com/expvintl/mctools/modules/CameraZoom.java
Normal file
20
src/main/java/com/expvintl/mctools/modules/CameraZoom.java
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package com.expvintl.mctools.modules;
|
||||||
|
|
||||||
|
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||||
|
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
|
||||||
|
import net.minecraft.client.MinecraftClient;
|
||||||
|
import net.minecraft.client.option.KeyBinding;
|
||||||
|
import net.minecraft.client.util.InputUtil;
|
||||||
|
import org.lwjgl.glfw.GLFW;
|
||||||
|
|
||||||
|
public class CameraZoom {
|
||||||
|
public static CameraZoom INSTANCE=new CameraZoom();
|
||||||
|
public boolean isZoom=false;
|
||||||
|
public void init(){
|
||||||
|
KeyBinding zoom= KeyBindingHelper.registerKeyBinding(new KeyBinding("镜头放大", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_C,"MyTools"));
|
||||||
|
ClientTickEvents.END_CLIENT_TICK.register(client -> {
|
||||||
|
isZoom=zoom.isPressed();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -14,6 +14,7 @@
|
|||||||
"client": [
|
"client": [
|
||||||
"MinecraftClientMixin",
|
"MinecraftClientMixin",
|
||||||
"SoundSystemMixin",
|
"SoundSystemMixin",
|
||||||
|
"client.GameRendererMixin",
|
||||||
"interfaces.ClientPlayerInteractionManagerAccessor",
|
"interfaces.ClientPlayerInteractionManagerAccessor",
|
||||||
"interfaces.MinecraftClientAccessor",
|
"interfaces.MinecraftClientAccessor",
|
||||||
"interfaces.SimpleOptionAccessor",
|
"interfaces.SimpleOptionAccessor",
|
||||||
|
Reference in New Issue
Block a user