在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):PrismarineJS/node-minecraft-protocol开源软件地址(OpenSource Url):https://github.com/PrismarineJS/node-minecraft-protocol开源编程语言(OpenSource Language):JavaScript 100.0%开源软件介绍(OpenSource Introduction):minecraft protocolParse and serialize minecraft packets, plus authentication and encryption. Features
Want to contribute on something important for PrismarineJS ? go to https://github.com/PrismarineJS/mineflayer/wiki/Big-Prismarine-projects Third Party Pluginsnode-minecraft-protocol is pluggable.
Projects Using node-minecraft-protocol
Installation
DocumentationUsageEcho client examplevar mc = require('minecraft-protocol');
var client = mc.createClient({
host: "localhost", // optional
port: 25565, // optional
username: "[email protected]",
password: "12345678",
auth: 'microsoft' // optional; by default uses offline mode, if using a microsoft account, set to 'microsoft'
});
client.on('chat', function(packet) {
// Listen for chat messages and echo them back.
var jsonMsg = JSON.parse(packet.message);
if(jsonMsg.translate == 'chat.type.announcement' || jsonMsg.translate == 'chat.type.text') {
var username = jsonMsg.with[0].text;
var msg = jsonMsg.with[1];
if(username === client.username) return;
client.write('chat', {message: msg.text});
}
}); If the server is in offline mode, you may leave out the Hello World server examplevar mc = require('minecraft-protocol');
var server = mc.createServer({
'online-mode': true, // optional
encryption: true, // optional
host: '0.0.0.0', // optional
port: 25565, // optional
version: '1.16.3'
});
const mcData = require('minecraft-data')(server.version)
server.on('login', function(client) {
let loginPacket = mcData.loginPacket
client.write('login', {
entityId: client.id,
isHardcore: false,
gameMode: 0,
previousGameMode: 255,
worldNames: loginPacket.worldNames,
dimensionCodec: loginPacket.dimensionCodec,
dimension: loginPacket.dimension,
worldName: 'minecraft:overworld',
hashedSeed: [0, 0],
maxPlayers: server.maxPlayers,
viewDistance: 10,
reducedDebugInfo: false,
enableRespawnScreen: true,
isDebug: false,
isFlat: false
});
client.write('position', {
x: 0,
y: 1.62,
z: 0,
yaw: 0,
pitch: 0,
flags: 0x00
});
var msg = {
translate: 'chat.type.announcement',
"with": [
'Server',
'Hello, world!'
]
};
client.write("chat", { message: JSON.stringify(msg), position: 0, sender: '0' });
}); Testing
DebuggingYou can enable some protocol debugging output using DEBUG="minecraft-protocol" node [...] On windows :
ContributePlease read https://github.com/PrismarineJS/prismarine-contribute HistorySee history Related
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论