Minecraft自动点击器模组导入报错求助:无法解析v1与LiteralText
解决方案
1. 修复「Cannot resolve symbol 'v1'」问题
这个错误是因为Fabric API版本与代码中的包结构不兼容,新版本的Fabric API已移除了v1子包结构:
- 替换客户端命令相关的导入语句,移除
v1后缀:import net.fabricmc.fabric.api.client.command.ClientCommandManager; import net.fabricmc.fabric.api.client.event.lifecycle.ClientTickEvents; import net.fabricmc.fabric.api.client.keybinding.KeyBindingHelper; - 同时检查
build.gradle(或build.gradle.kts)中的Fabric API依赖,确保版本与你使用的Minecraft版本匹配,比如1.20.1对应的Fabric API版本为0.91.1+1.20.1,依赖配置示例:dependencies { modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" }
2. 修复「Cannot resolve symbol 'LiteralText'」问题
LiteralText在Minecraft 1.19+版本中被废弃并移除,需改用Text.literal()静态方法创建文本:
- 替换导入语句:
import net.minecraft.text.Text; - 修改代码中所有
new LiteralText(...)的调用为Text.literal(...),示例:// 原代码 MinecraftClient.getInstance().player.sendMessage(new LiteralText("Bound clicker toggle to key: " + keyName), false); // 修改后 MinecraftClient.getInstance().player.sendMessage(Text.literal("Bound clicker toggle to key: " + keyName), false);
修正后的完整代码
import net.fabricmc.fabric.api.client.command.ClientCommandManager; import net.fabricmc.fabric.api.client.event.lifecycle.ClientTickEvents; import net.fabricmc.fabric.api.client.keybinding.KeyBindingHelper; import net.minecraft.client.MinecraftClient; import net.minecraft.client.option.KeyBinding; import net.minecraft.text.Text; import org.lwjgl.glfw.GLFW; import com.mojang.brigadier.StringArgumentType; import com.mojang.brigadier.IntegerArgumentType; public class ModInitializer implements net.fabricmc.api.ModInitializer { private static KeyBinding keyBinding; private static boolean isClickerActive = false; private static int clicksPerMillisecond = 1; @Override public void onInitialize() { keyBinding = KeyBindingHelper.registerKeyBinding(new KeyBinding( "key.autoclickermod.toggle", GLFW.GLFW_KEY_UNKNOWN, "category.autoclickermod" )); ClientCommandManager.DISPATCHER.register(ClientCommandManager.literal("bind") .then(ClientCommandManager.argument("key", StringArgumentType.word()) .executes(context -> { String keyName = StringArgumentType.getString(context, "key"); int keyCode = GLFW.glfwGetKeyScancode(GLFW.glfwGetKeyName(keyName)); keyBinding.setBoundKey(keyCode); MinecraftClient.getInstance().player.sendMessage(Text.literal("Bound clicker toggle to key: " + keyName), false); return 1; }))); ClientCommandManager.DISPATCHER.register(ClientCommandManager.literal("cpms") .then(ClientCommandManager.argument("rate", IntegerArgumentType.integer(1)) .executes(context -> { clicksPerMillisecond = IntegerArgumentType.getInteger(context, "rate"); MinecraftClient.getInstance().player.sendMessage(Text.literal("Set clicks per millisecond to: " + clicksPerMillisecond), false); return 1; }))); ClientTickEvents.END_CLIENT_TICK.register(client -> { while (keyBinding.wasPressed()) { isClickerActive = !isClickerActive; client.player.sendMessage(Text.literal("Auto-clicker " + (isClickerActive ? "enabled" : "disabled")), false); } if (isClickerActive) { for (int i = 0; i < clicksPerMillisecond; i++) { client.mouse.click(MinecraftClient.Mouse.ClickType.LEFT); } } }); } }
额外说明
- 代码中还修正了
MouseHelper.ClickType的引用,新版Minecraft中该类已移至MinecraftClient.Mouse.ClickType。
内容的提问来源于stack exchange,提问作者D a n c h
相关产品推荐
相关产品推荐

