-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b540d49
commit 3ce36c3
Showing
2 changed files
with
80 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,79 @@ | ||
Big Rat under your Chair | ||
# 🛠️ Minecraft Bedrock Edition Client Library | ||
|
||
## 📌 Supported Version | ||
- **1.21.20** | ||
|
||
## ⚙️ Installation | ||
|
||
Install the library via npm: | ||
|
||
```bash | ||
npm i @sanctumterra/client | ||
``` | ||
|
||
## 🚀 Usage Example | ||
|
||
```typescript | ||
import { Client, Logger } from "@sanctumterra/client"; | ||
import { TextPacket } from "@serenityjs/protocol"; // Import packet types | ||
|
||
// 🎮 Create a new client instance with the necessary configurations | ||
const client = new Client({ | ||
host: "127.0.0.1", // 🖥️ Server IP address | ||
port: 19132, // 🌐 Server port | ||
offline: false, // 🔒 Set to true if the server is offline | ||
username: "SanctumTerra", // 🧑💻 Your Minecraft username | ||
version: "1.21.20" // 📦 The Minecraft Bedrock version | ||
}); | ||
|
||
// 🌐 Connect to the server | ||
client.connect(); | ||
|
||
// 📥 Handle incoming TextPacket events | ||
client.on(TextPacket.name, (packet: TextPacket): void => { | ||
if (packet.parameters) { | ||
// 🗨️ Handle standard chat messages | ||
if (packet.message.includes("chat.type.text")) { | ||
return Logger.chat(`§f<${packet.parameters[0]}> ${packet.parameters[1]}`); | ||
} | ||
// ➕ Handle player join messages | ||
if (packet.message.includes("multiplayer.player.joined")) { | ||
return Logger.chat(`§e${packet.parameters[0]} joined the game`); | ||
} | ||
// ➖ Handle player leave messages | ||
if (packet.message.includes("multiplayer.player.left")) { | ||
return Logger.chat(`§e${packet.parameters[0]} left the game`); | ||
} | ||
|
||
// 📝 Log any other message types | ||
console.log(packet.message); | ||
} | ||
// 📜 Default log for any packet message | ||
Logger.chat(packet.message); | ||
}); | ||
``` | ||
|
||
--- | ||
|
||
## 📚 Explanation | ||
|
||
### 🎛️ Client Configuration | ||
|
||
- **Required Parameters**: | ||
- **Host**: Server's IP address. | ||
- **Port**: Server's port number. | ||
|
||
### 📡 Event Handling | ||
|
||
- The example listens for `TextPacket` events: | ||
- **Chat Messages**: Identified by `chat.type.text`, and formatted using `Logger.chat`. | ||
- **Player Join**: Detected by `multiplayer.player.joined`, and logged with a join message. | ||
- **Player Leave**: Triggered by `multiplayer.player.left`, and logged with a leave message. | ||
- **Other Messages**: All other messages are logged to the console. | ||
|
||
### 🎨 Custom Logging | ||
|
||
- The custom `Logger` supports **Minecraft color codes**, enabling colorful, in-game styled message logging. | ||
- This feature allows for **seamless integration** with Minecraft’s native chat system, without the need for third-party color libraries. | ||
|
||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters