Spaces:
Runtime error
Runtime error
Update server.ts
Browse files
server.ts
CHANGED
|
@@ -10,6 +10,14 @@ import { GoogleGenAI, Type } from "@google/genai";
|
|
| 10 |
import { createProxyMiddleware } from 'http-proxy-middleware';
|
| 11 |
import pv from 'prismarine-viewer';
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
const app = express();
|
| 14 |
const httpServer = createServer(app);
|
| 15 |
const io = new Server(httpServer, {
|
|
@@ -18,7 +26,7 @@ const io = new Server(httpServer, {
|
|
| 18 |
},
|
| 19 |
});
|
| 20 |
|
| 21 |
-
const PORT =
|
| 22 |
|
| 23 |
let bot: mineflayer.Bot | null = null;
|
| 24 |
let ai: GoogleGenAI | null = null;
|
|
@@ -50,6 +58,7 @@ function stopAfkMode() {
|
|
| 50 |
if (bot) {
|
| 51 |
bot.pathfinder.setGoal(null);
|
| 52 |
bot.chat('/gamemode creative @s');
|
|
|
|
| 53 |
}
|
| 54 |
log("AFK mode stopped.", "info");
|
| 55 |
}
|
|
@@ -66,6 +75,7 @@ async function startAfkMode() {
|
|
| 66 |
setTimeout(() => {
|
| 67 |
if (!bot) return;
|
| 68 |
bot.chat('/tp @s ~ ~20 ~'); // Teleport up into the air
|
|
|
|
| 69 |
}, 500);
|
| 70 |
|
| 71 |
afkInterval = setInterval(() => {
|
|
@@ -170,6 +180,11 @@ async function startServer() {
|
|
| 170 |
const { host, port, version, username, apiKey, model } = config;
|
| 171 |
|
| 172 |
if (bot) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
bot.quit();
|
| 174 |
log("Existing bot disconnected");
|
| 175 |
}
|
|
@@ -227,7 +242,8 @@ async function startServer() {
|
|
| 227 |
if (!bot?.entity || isMlgWatering) return;
|
| 228 |
|
| 229 |
// If falling fast (velocity.y is negative)
|
| 230 |
-
|
|
|
|
| 231 |
const waterBucket = bot.inventory.items().find(item => item.name === 'water_bucket');
|
| 232 |
if (!waterBucket) return;
|
| 233 |
|
|
@@ -915,9 +931,9 @@ async function startServer() {
|
|
| 915 |
yaw: bot.entity.yaw,
|
| 916 |
pitch: bot.entity.pitch
|
| 917 |
});
|
| 918 |
-
const
|
| 919 |
-
bot.chat(`Here is the
|
| 920 |
-
log(`
|
| 921 |
} else if (action.length >= 4) {
|
| 922 |
const [x, y, z, rawBlock] = action;
|
| 923 |
const parseCoord = (c: any) => {
|
|
@@ -1017,6 +1033,19 @@ async function startServer() {
|
|
| 1017 |
appType: "spa",
|
| 1018 |
});
|
| 1019 |
app.use(vite.middlewares);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1020 |
} else {
|
| 1021 |
const distPath = path.join(process.cwd(), "dist");
|
| 1022 |
app.use(express.static(distPath));
|
|
|
|
| 10 |
import { createProxyMiddleware } from 'http-proxy-middleware';
|
| 11 |
import pv from 'prismarine-viewer';
|
| 12 |
|
| 13 |
+
process.on('uncaughtException', (err) => {
|
| 14 |
+
console.error('Uncaught Exception:', err);
|
| 15 |
+
});
|
| 16 |
+
|
| 17 |
+
process.on('unhandledRejection', (reason, promise) => {
|
| 18 |
+
console.error('Unhandled Rejection at:', promise, 'reason:', reason);
|
| 19 |
+
});
|
| 20 |
+
|
| 21 |
const app = express();
|
| 22 |
const httpServer = createServer(app);
|
| 23 |
const io = new Server(httpServer, {
|
|
|
|
| 26 |
},
|
| 27 |
});
|
| 28 |
|
| 29 |
+
const PORT = 3000;
|
| 30 |
|
| 31 |
let bot: mineflayer.Bot | null = null;
|
| 32 |
let ai: GoogleGenAI | null = null;
|
|
|
|
| 58 |
if (bot) {
|
| 59 |
bot.pathfinder.setGoal(null);
|
| 60 |
bot.chat('/gamemode creative @s');
|
| 61 |
+
bot.creative.stopFlying();
|
| 62 |
}
|
| 63 |
log("AFK mode stopped.", "info");
|
| 64 |
}
|
|
|
|
| 75 |
setTimeout(() => {
|
| 76 |
if (!bot) return;
|
| 77 |
bot.chat('/tp @s ~ ~20 ~'); // Teleport up into the air
|
| 78 |
+
bot.creative.startFlying();
|
| 79 |
}, 500);
|
| 80 |
|
| 81 |
afkInterval = setInterval(() => {
|
|
|
|
| 180 |
const { host, port, version, username, apiKey, model } = config;
|
| 181 |
|
| 182 |
if (bot) {
|
| 183 |
+
if ((bot as any).viewer) {
|
| 184 |
+
try {
|
| 185 |
+
(bot as any).viewer.close();
|
| 186 |
+
} catch (e) {}
|
| 187 |
+
}
|
| 188 |
bot.quit();
|
| 189 |
log("Existing bot disconnected");
|
| 190 |
}
|
|
|
|
| 242 |
if (!bot?.entity || isMlgWatering) return;
|
| 243 |
|
| 244 |
// If falling fast (velocity.y is negative)
|
| 245 |
+
const inWater = bot.blockAt(bot.entity.position)?.name === 'water' || bot.blockAt(bot.entity.position)?.name === 'flowing_water';
|
| 246 |
+
if (bot.entity.velocity.y < -0.6 && !bot.entity.onGround && !inWater) {
|
| 247 |
const waterBucket = bot.inventory.items().find(item => item.name === 'water_bucket');
|
| 248 |
if (!waterBucket) return;
|
| 249 |
|
|
|
|
| 931 |
yaw: bot.entity.yaw,
|
| 932 |
pitch: bot.entity.pitch
|
| 933 |
});
|
| 934 |
+
const hostUrl = process.env.PUBLIC_URL || "http://localhost:7860";
|
| 935 |
+
bot.chat(`Here is the live 3D view: ${hostUrl}/efir/`);
|
| 936 |
+
log(`Live 3D view requested: ${hostUrl}/efir/`, "success");
|
| 937 |
} else if (action.length >= 4) {
|
| 938 |
const [x, y, z, rawBlock] = action;
|
| 939 |
const parseCoord = (c: any) => {
|
|
|
|
| 1033 |
appType: "spa",
|
| 1034 |
});
|
| 1035 |
app.use(vite.middlewares);
|
| 1036 |
+
|
| 1037 |
+
app.use('*', async (req, res, next) => {
|
| 1038 |
+
try {
|
| 1039 |
+
const url = req.originalUrl;
|
| 1040 |
+
const fs = await import('fs');
|
| 1041 |
+
let template = fs.readFileSync(path.resolve(process.cwd(), 'index.html'), 'utf-8');
|
| 1042 |
+
template = await vite.transformIndexHtml(url, template);
|
| 1043 |
+
res.status(200).set({ 'Content-Type': 'text/html' }).end(template);
|
| 1044 |
+
} catch (e) {
|
| 1045 |
+
vite.ssrFixStacktrace(e as Error);
|
| 1046 |
+
next(e);
|
| 1047 |
+
}
|
| 1048 |
+
});
|
| 1049 |
} else {
|
| 1050 |
const distPath = path.join(process.cwd(), "dist");
|
| 1051 |
app.use(express.static(distPath));
|