The project is refactory version for version of three years (2021) ago base on TypeScript.
A simple Minecraft Bedrock Edition websocket server framework, help developer to setup websocket server faster for Minecraft or your self package depend on it.Its core Mcwss
base a events emiter and provide many of events which can be listened.In addition,it provides Client
instance object to interact with every client.
What? You donot know how to install Node.js program? Are you kidding me? Please find Google Search to help you.
Base on program cli to start:
mcwss
For C(Z)hinese(English understanding hard population):
mcwss --lang zh_CN
Start your Minecraft Bedrock Edition and input commands:
/wsserver ws://localhost:1
# or:
/connect ws://localhost:1
Test a few:
*/help
*/helph
--port [num]
Set websocket server port--mode [type]
Set logger level, debug or build--lang [locale]
Set view language, en_US, ja_JP, zh_TW, zh_CN-v, --version
Display version number-h, --help
Display this message
Example:
mcwss --port 2333 --mode debug --lang ja_JP
*/help
Show Mcwss command help*/connect
Show WebSocket connection time*/about
Show about informatio*/clears
Clear chat content*/func <path>
Execute mcfunction on server*/helph
Show hidden command help,
Game hidden Command:
./closewebsocket
Close websocket connection./gettopsolidblock <x> <y> <z>
Get top solid block coordinates./querytarget <selector>
Get precise float coordinates of entity./agent
Mascot./enableencryption
Unknown./closechat
Close chat./geteduclientinfo
Get version info./getlocalplayername
Return player name
Lifecycle Events:
- ready
- dispose
- error
- connection
- message
- close
Minecraft Events:
- block_broken
- block_placed
- end_of_day
- entity_spawned
- item_acquired
- item_crafted
- item_destroyed
- item_smelted
- item_used
- jukebox_used
- mob_interacted
- mob_killed
- player_bounced
- player_died
- player_message
- player_teleported
- player_transform
- player_travelled
- unknown_minecraft_event
- command_response
start(): void
Start a websocket serverstop(): void
Stop a websocket server
Extends Events
:
emit<T extends keyof EventsList>(type: T, ...data: [...Parameters<EventsList[T]>]): void
Emit a eventparallel<T extends keyof EventsList>(type: T, ...data: [...Parameters<EventsList[T]>]): Promise<void>
Emit a event asynchronouson<T extends keyof EventsList>(type: T, callback: EventsList[T]): void
Listen a eventonce<T extends keyof EventsList>(type: T, callback: EventsList[T]): void
Listen a event onceoff<T extends keyof EventsList>(type: T, callback: EventsList[T]): void
Cancel to listen a eventoffAll<T extends keyof EventsList>(type: T): void
Cancel to listen all events
req: IncomingMessage
Client websocket objectsessionId: number
Connection identify atMcwss
sessionDate: Date
Connection setup timesend(data: SendPacket): void
Send a packet to clientclose(): void
Close connection with clientsubscribe(event: MinecraftEvents): void
Subscribe a minecraft eventunsubscribe(event: MinecraftEvents): void
Unsubscribe a minecraft eventrun(cmd: string | string[]): void
Run a or many of command to clientchat(message: string): void
Send a normal message to client (Base for/say
)chatf(message: string, color?: TextColor, sender?: string, target: CommandTarget = CommandTarget.SELF): void
Send a advanced message to client (Base for/tellraw
)func(file: string): void
Run a.mcfunction
file to client
const enum TextColor {
GREEN = '§a',
RED = '§c',
BLUE = '§b',
YELLOW = '§e'
}
const enum CommandTarget {
ALL = '@a',
SELF = '@s',
RANDOM = '@r',
EVERY = '@e',
NEAR = '@p'
}
Supports languages:
- English
- 日本語 (Japanese)
- 繁體中文 (Traditional Chinese)
- 简体中文(Simplified Chinese)
Setup your self program or package base on Mcwss, refer to src/utils/line.ts
for more information.
import Mcwss from 'mcwss';
import { log, error } from 'console';
const mcwss = new Mcwss({ port: 2333 });
/* events register */
mcwss.on('ready', () => log(`WebSocketServer started at ws://localehost:${port} `));
mcwss.on('dispose', () => log('WebSocketServer stopped'));
mcwss.on('error', (data) =>
error(data.client ? `[Client:${data.client.sessionId}]` : '[Server]', data.error.name, data.error.message)
);
mcwss.on('connection', (data) =>
log(`[Client:${data.client.sessionId}]`, 'new connection from', data.client.req.socket.remoteAddress)
);
mcwss.on('close', (data) => {
if (data.raw) {
log(`[Client:${data.raw.client.sessionId}]`, 'Closing in progress code:', data.raw.code);
return;
}
log('WebSocketServer is closeing...');
});
mcwss.on('block_broken', (data) => {
const { block, player, tool } = data.body;
/* ... */
});
mcwss.on('end_of_day', (data) => {
const { player } = data.body;
/* ... */
});
/* ... */
mcwss.start();
Comply with The GNU General Public License v3.0 open-source license.