日本語版はこちら
MinecraftConnectionBE is a command sending library for MinecraftBE or Minecraft Education. It can be useful for automation and programming learning.
First, launch MinecraftBE or Minecraft Education. In the settings section, set "Require Encrypted Websockets" to Off.
This library is intended for .NET Standard 2.1 and above. This section describes how to create a .NET 6 console application.
Install MinecraftConnectionBE with the NuGet package manager, or run the following command in the package manager console.
Install-Package MinecraftConnectionBE -Version 1.0.0-beta1
or
dotnet add package MinecraftConnectionBE -v 1.0.0-beta1
After running the program, use the /connect
command in Minecraft to connect to the server.
For example:
/connect 127.0.0.1:8080
An OpenAI API key is always required to chat with an AI. If you have not obtained one, please click here to access and confirm it.
First, specify the IP address and port number to prepare the WebSocket server. Next, call the ChatAI()
method from the instance and assign the API key and the player ID to be conversed with, each as a string type. Using the Console.Readkey()
method, the server is open until a key is pressed.
using MinecraftConnectionBE;
using System.Net;
var address = IPAddress.Parse("127.0.0.1");
var port = 8080;
var apiKey = "<Your API key>";
var command = new MinecraftCommands(address, port);
command.AIChat(apiKey, "<Your ID>");
Console.ReadKey();
Result:
You can trigger a chat message to execute a specific command. Use the SubscribeCommand()
method to execute the command.
using MinecraftConnectionBE;
using System.Net;
var address = IPAddress.Parse("127.0.0.1");
var port = 8080;
var command = new MinecraftCommands(address, port);
command.SubscribeCommand("time set night", "night");
Console.ReadKey();
Result: