Update server.ts
Browse files
server.ts
CHANGED
|
@@ -123,8 +123,8 @@ async function startServer() {
|
|
| 123 |
|
| 124 |
try {
|
| 125 |
const systemPrompt = `You are a Minecraft architect and admin. The user "${requestingUser}" wants: "${prompt}".
|
| 126 |
-
You can build structures
|
| 127 |
-
Coordinates (x, y, z) for blocks are relative to the bot's
|
| 128 |
For commands (like /summon), use relative coordinates (~ ~ ~) which are relative to the bot!
|
| 129 |
Use standard Minecraft 1.21.1 block names and command syntax.
|
| 130 |
|
|
@@ -132,17 +132,24 @@ async function startServer() {
|
|
| 132 |
- Items with custom names/enchantments: give ${requestingUser} cobblestone[custom_name=[{"text":"Name","italic":false}],enchantments={channeling:1}]
|
| 133 |
- Summoning entities with visible names: summon armor_stand ~2 ~ ~ {CustomName:'{"text":"Palace"}',CustomNameVisible:1b,ArmorItems:[{},{},{},{id:"minecraft:shield",count:1}]}
|
| 134 |
|
|
|
|
|
|
|
| 135 |
You can build large structures up to ${maxBlocks} blocks.
|
| 136 |
To save tokens, output a JSON object containing an "actions" array.
|
| 137 |
Action type 1 (Place Block): [x, y, z, "block_name"]
|
| 138 |
Action type 2 (Execute Command): ["cmd", "command_string"]
|
|
|
|
|
|
|
|
|
|
| 139 |
Example:
|
| 140 |
{
|
| 141 |
"actions": [
|
|
|
|
|
|
|
| 142 |
[0, 0, 0, "stone"],
|
| 143 |
[0, 1, 0, "oak_planks"],
|
| 144 |
-
["
|
| 145 |
-
["cmd", "
|
| 146 |
]
|
| 147 |
}
|
| 148 |
Output ONLY the JSON object.`;
|
|
@@ -223,6 +230,7 @@ async function startServer() {
|
|
| 223 |
// Disable command feedback in Minecraft to prevent chat spam
|
| 224 |
bot.chat('/gamerule sendCommandFeedback false');
|
| 225 |
bot.chat('/gamerule logAdminCommands false');
|
|
|
|
| 226 |
|
| 227 |
const startPos = bot.entity.position.clone();
|
| 228 |
|
|
@@ -239,6 +247,26 @@ async function startServer() {
|
|
| 239 |
if (cmd.startsWith("/")) cmd = cmd.substring(1);
|
| 240 |
log(`Executing command: /${cmd}`, "info");
|
| 241 |
bot.chat(`/${cmd}`);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 242 |
} else if (action.length >= 4) {
|
| 243 |
const [x, y, z, rawBlock] = action;
|
| 244 |
const targetPos = startPos.offset(x, y, z);
|
|
@@ -285,4 +313,4 @@ async function startServer() {
|
|
| 285 |
});
|
| 286 |
}
|
| 287 |
|
| 288 |
-
startServer();
|
|
|
|
| 123 |
|
| 124 |
try {
|
| 125 |
const systemPrompt = `You are a Minecraft architect and admin. The user "${requestingUser}" wants: "${prompt}".
|
| 126 |
+
You can build structures, execute commands, or move around.
|
| 127 |
+
Coordinates (x, y, z) for blocks and movement are relative to the bot's starting position (0,0,0).
|
| 128 |
For commands (like /summon), use relative coordinates (~ ~ ~) which are relative to the bot!
|
| 129 |
Use standard Minecraft 1.21.1 block names and command syntax.
|
| 130 |
|
|
|
|
| 132 |
- Items with custom names/enchantments: give ${requestingUser} cobblestone[custom_name=[{"text":"Name","italic":false}],enchantments={channeling:1}]
|
| 133 |
- Summoning entities with visible names: summon armor_stand ~2 ~ ~ {CustomName:'{"text":"Palace"}',CustomNameVisible:1b,ArmorItems:[{},{},{},{id:"minecraft:shield",count:1}]}
|
| 134 |
|
| 135 |
+
IMPORTANT: To avoid getting stuck inside the blocks you place, ALWAYS start your actions by teleporting or moving away from the build area (e.g., teleporting 5 blocks up and 5 blocks back).
|
| 136 |
+
|
| 137 |
You can build large structures up to ${maxBlocks} blocks.
|
| 138 |
To save tokens, output a JSON object containing an "actions" array.
|
| 139 |
Action type 1 (Place Block): [x, y, z, "block_name"]
|
| 140 |
Action type 2 (Execute Command): ["cmd", "command_string"]
|
| 141 |
+
Action type 3 (Walk/Parkour): ["move", x, y, z]
|
| 142 |
+
Action type 4 (Teleport): ["tp", x, y, z]
|
| 143 |
+
|
| 144 |
Example:
|
| 145 |
{
|
| 146 |
"actions": [
|
| 147 |
+
["cmd", "gamemode creative @s"],
|
| 148 |
+
["tp", 0, 5, -5],
|
| 149 |
[0, 0, 0, "stone"],
|
| 150 |
[0, 1, 0, "oak_planks"],
|
| 151 |
+
["move", 2, 0, 0],
|
| 152 |
+
["cmd", "give ${requestingUser} diamond_sword 1"]
|
| 153 |
]
|
| 154 |
}
|
| 155 |
Output ONLY the JSON object.`;
|
|
|
|
| 230 |
// Disable command feedback in Minecraft to prevent chat spam
|
| 231 |
bot.chat('/gamerule sendCommandFeedback false');
|
| 232 |
bot.chat('/gamerule logAdminCommands false');
|
| 233 |
+
bot.chat('/gamemode creative @s'); // Ensure bot is in creative so it doesn't suffocate
|
| 234 |
|
| 235 |
const startPos = bot.entity.position.clone();
|
| 236 |
|
|
|
|
| 247 |
if (cmd.startsWith("/")) cmd = cmd.substring(1);
|
| 248 |
log(`Executing command: /${cmd}`, "info");
|
| 249 |
bot.chat(`/${cmd}`);
|
| 250 |
+
} else if (action[0] === "move") {
|
| 251 |
+
const dx = Number(action[1]) || 0;
|
| 252 |
+
const dy = Number(action[2]) || 0;
|
| 253 |
+
const dz = Number(action[3]) || 0;
|
| 254 |
+
const targetPos = startPos.offset(dx, dy, dz);
|
| 255 |
+
log(`Walking to ~${dx} ~${dy} ~${dz}...`, "info");
|
| 256 |
+
const defaultMove = new Movements(bot);
|
| 257 |
+
bot.pathfinder.setMovements(defaultMove);
|
| 258 |
+
try {
|
| 259 |
+
await bot.pathfinder.goto(new goals.GoalBlock(targetPos.x, targetPos.y, targetPos.z));
|
| 260 |
+
} catch (e) {
|
| 261 |
+
log(`Pathfinding failed or interrupted`, "error");
|
| 262 |
+
}
|
| 263 |
+
} else if (action[0] === "tp") {
|
| 264 |
+
const dx = Number(action[1]) || 0;
|
| 265 |
+
const dy = Number(action[2]) || 0;
|
| 266 |
+
const dz = Number(action[3]) || 0;
|
| 267 |
+
log(`Teleporting to ~${dx} ~${dy} ~${dz}`, "info");
|
| 268 |
+
bot.chat(`/tp @s ~${dx} ~${dy} ~${dz}`);
|
| 269 |
+
await new Promise(r => setTimeout(r, 500)); // Wait for teleport to complete
|
| 270 |
} else if (action.length >= 4) {
|
| 271 |
const [x, y, z, rawBlock] = action;
|
| 272 |
const targetPos = startPos.offset(x, y, z);
|
|
|
|
| 313 |
});
|
| 314 |
}
|
| 315 |
|
| 316 |
+
startServer();
|