环境:Minecraft 1.16.5,Fabric 0.11.6
我编写这些代码是为了尝试在 Minecraft 中执行命令。
@Override
public void inventoryTick(ItemStack stack, World world, Entity entity, int slot, boolean selected) {
if (entity instanceof final PlayerEntity player) {
if (player.getEquippedStack(EquipmentSlot.CHEST) == stack) {
CommandDispatcher<PlayerEntity> cDispatcher = new CommandDispatcher<PlayerEntity>();
final String command = "/time set 0";
try {
cDispatcher.execute(command, player);
} catch (CommandSyntaxException e) {
e.printStackTrace();
}
}
}
}
但是 Minecraft 会抛出这些错误:
[main/INFO] (Minecraft) [STDERR]: com.mojang.brigadier.exceptions.CommandSyntaxException: Unknown or incomplete command, see below for error at position 0: <--[HERE]
[Server thread/INFO] (Minecraft) [STDERR]: com.mojang.brigadier.exceptions.CommandSyntaxException: Unknown or incomplete command, see below for error at position 0: <--[HERE]
我尝试了很多命令,但它只给出这些相同的错误。那么如何在游戏中执行命令呢?