blockmine 1.25.0 → 1.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +46 -3
- package/backend/cli.js +1 -1
- package/backend/package.json +2 -2
- package/backend/prisma/migrations/20260328173000_add_plugin_source_ref/migration.sql +2 -0
- package/backend/prisma/migrations/migration_lock.toml +2 -2
- package/backend/prisma/schema.prisma +2 -0
- package/backend/src/api/routes/apiKeys.js +8 -0
- package/backend/src/api/routes/bots.js +258 -9
- package/backend/src/api/routes/eventGraphs.js +151 -1
- package/backend/src/api/routes/health.js +38 -0
- package/backend/src/api/routes/nodeRegistry.js +63 -0
- package/backend/src/api/routes/plugins.js +254 -29
- package/backend/src/container.js +11 -8
- package/backend/src/core/BotCommandLoader.js +161 -0
- package/backend/src/core/BotConnection.js +125 -0
- package/backend/src/core/BotEventHandlers.js +234 -0
- package/backend/src/core/BotIPCHandler.js +445 -0
- package/backend/src/core/BotManager.js +15 -7
- package/backend/src/core/BotProcess.js +75 -142
- package/backend/src/core/EventGraphManager.js +7 -3
- package/backend/src/core/GraphDebugHandler.js +229 -0
- package/backend/src/core/GraphDebugIPC.js +117 -0
- package/backend/src/core/GraphExecutionEngine.js +545 -978
- package/backend/src/core/GraphTraversal.js +80 -0
- package/backend/src/core/GraphValidation.js +73 -0
- package/backend/src/core/NodeDefinition.js +138 -0
- package/backend/src/core/NodeRegistry.js +153 -141
- package/backend/src/core/PluginManager.js +272 -31
- package/backend/src/core/RewindSignal.js +9 -0
- package/backend/src/core/config/ConfigValidator.js +72 -0
- package/backend/src/core/config/FeatureFlags.js +52 -0
- package/backend/src/core/config/__tests__/ConfigValidator.test.js +232 -0
- package/backend/src/core/domain/entities/Bot.js +39 -0
- package/backend/src/core/domain/entities/Command.js +41 -0
- package/backend/src/core/domain/entities/EventGraph.js +39 -0
- package/backend/src/core/domain/entities/Plugin.js +45 -0
- package/backend/src/core/domain/entities/User.js +40 -0
- package/backend/src/core/domain/services/DependencyResolver.js +168 -0
- package/backend/src/core/domain/services/GraphValidator.js +117 -0
- package/backend/src/core/domain/services/PermissionChecker.js +34 -0
- package/backend/src/core/domain/services/__tests__/DependencyResolver.test.js +126 -0
- package/backend/src/core/domain/valueObjects/BotConfig.js +27 -0
- package/backend/src/core/domain/valueObjects/DependencyGraph.js +86 -0
- package/backend/src/core/domain/valueObjects/PluginManifest.js +36 -0
- package/backend/src/core/errors/BaseError.js +29 -0
- package/backend/src/core/errors/ErrorHandler.js +81 -0
- package/backend/src/core/errors/__tests__/ErrorHandler.test.js +188 -0
- package/backend/src/core/errors/index.js +68 -0
- package/backend/src/core/infrastructure/BatchingUtility.js +66 -0
- package/backend/src/core/infrastructure/CircuitBreaker.js +103 -0
- package/backend/src/core/infrastructure/ConnectionPool.js +81 -0
- package/backend/src/core/infrastructure/RateLimiter.js +64 -0
- package/backend/src/core/infrastructure/__tests__/BatchingUtility.test.js +86 -0
- package/backend/src/core/infrastructure/__tests__/CircuitBreaker.test.js +156 -0
- package/backend/src/core/infrastructure/__tests__/ConnectionPool.test.js +146 -0
- package/backend/src/core/infrastructure/__tests__/RateLimiter.test.js +171 -0
- package/backend/src/core/ipc/botApiFactory.js +72 -0
- package/backend/src/core/ipc/ipcMessageTypes.js +115 -0
- package/backend/src/core/logging/AuditLogger.js +61 -0
- package/backend/src/core/logging/StructuredLogger.js +80 -0
- package/backend/src/core/logging/__tests__/StructuredLogger.test.js +213 -0
- package/backend/src/core/logging/index.js +7 -0
- package/backend/src/core/metrics/MetricsCollector.js +104 -0
- package/backend/src/core/metrics/__tests__/MetricsCollector.test.js +131 -0
- package/backend/src/core/node-registries/actionsNodes.js +191 -0
- package/backend/src/core/node-registries/arraysNodes.js +152 -0
- package/backend/src/core/node-registries/botNodes.js +48 -0
- package/backend/src/core/node-registries/containerNodes.js +141 -0
- package/backend/src/core/node-registries/dataNodes.js +284 -0
- package/backend/src/core/node-registries/debugNodes.js +23 -0
- package/backend/src/core/node-registries/eventsNodes.js +223 -0
- package/backend/src/core/node-registries/flowNodes.js +151 -0
- package/backend/src/core/node-registries/furnaceNodes.js +123 -0
- package/backend/src/core/node-registries/index.js +108 -0
- package/backend/src/core/node-registries/inventory.js +102 -106
- package/backend/src/core/node-registries/logicNodes.js +54 -0
- package/backend/src/core/node-registries/mathNodes.js +38 -0
- package/backend/src/core/node-registries/navigationNodes.js +109 -0
- package/backend/src/core/node-registries/objectsNodes.js +90 -0
- package/backend/src/core/node-registries/stringsNodes.js +165 -0
- package/backend/src/core/node-registries/timeNodes.js +105 -0
- package/backend/src/core/node-registries/typeNodes.js +22 -0
- package/backend/src/core/node-registries/usersNodes.js +126 -0
- package/backend/src/core/nodes/arrays/shuffle.js +14 -0
- package/backend/src/core/nodes/bot/get_name.js +8 -0
- package/backend/src/core/nodes/bot/stop_bot.js +5 -0
- package/backend/src/core/nodes/container/open.js +101 -111
- package/backend/src/core/nodes/data/store_read.js +26 -0
- package/backend/src/core/nodes/data/store_write.js +23 -0
- package/backend/src/core/nodes/event/call_event.js +31 -0
- package/backend/src/core/nodes/event/custom_event.js +8 -0
- package/backend/src/core/nodes/flow/timer.js +35 -0
- package/backend/src/core/nodes/inventory/drop.js +73 -65
- package/backend/src/core/nodes/inventory/equip.js +54 -45
- package/backend/src/core/nodes/inventory/select_slot.js +48 -46
- package/backend/src/core/nodes/navigation/follow.js +54 -51
- package/backend/src/core/nodes/navigation/go_to.js +41 -53
- package/backend/src/core/nodes/navigation/go_to_entity.js +65 -69
- package/backend/src/core/nodes/navigation/go_to_player.js +65 -70
- package/backend/src/core/nodes/navigation/stop.js +17 -26
- package/backend/src/core/nodes/users/add_to_group.js +24 -0
- package/backend/src/core/nodes/users/check_permission.js +26 -0
- package/backend/src/core/nodes/users/remove_from_group.js +24 -0
- package/backend/src/core/services/BotIPCMessageRouter.js +337 -0
- package/backend/src/core/services/BotLifecycleService.js +41 -632
- package/backend/src/core/services/CacheManager.js +83 -23
- package/backend/src/core/services/CrashRestartManager.js +42 -0
- package/backend/src/core/services/DebugSessionManager.js +114 -12
- package/backend/src/core/services/EventGraphService.js +69 -0
- package/backend/src/core/services/MinecraftBotManager.js +9 -1
- package/backend/src/core/services/PluginManagementService.js +84 -0
- package/backend/src/core/services/TestModeContext.js +65 -0
- package/backend/src/core/services/__tests__/CacheManager.test.js +168 -0
- package/backend/src/core/services.js +1 -11
- package/backend/src/core/validation/InputValidator.js +167 -0
- package/backend/src/core/validation/__tests__/InputValidator.test.js +296 -0
- package/backend/src/real-time/botApi/index.js +1 -1
- package/backend/src/real-time/socketHandler.js +26 -0
- package/backend/src/server.js +10 -5
- package/frontend/dist/assets/{browser-ponyfill-DN7pwmHT.js → browser-ponyfill-D8y0Ty7C.js} +1 -1
- package/frontend/dist/assets/index-CFJLS0dk.css +32 -0
- package/frontend/dist/assets/{index-LSy71uwm.js → index-D91UGNMG.js} +1880 -1881
- package/frontend/dist/index.html +2 -2
- package/frontend/dist/locales/en/bots.json +4 -1
- package/frontend/dist/locales/en/common.json +7 -1
- package/frontend/dist/locales/en/login.json +2 -0
- package/frontend/dist/locales/en/management.json +79 -1
- package/frontend/dist/locales/en/nodes.json +59 -4
- package/frontend/dist/locales/en/plugin-detail.json +24 -4
- package/frontend/dist/locales/en/plugins.json +226 -7
- package/frontend/dist/locales/en/setup.json +2 -0
- package/frontend/dist/locales/en/sidebar.json +171 -3
- package/frontend/dist/locales/en/visual-editor.json +230 -31
- package/frontend/dist/locales/ru/bots.json +4 -1
- package/frontend/dist/locales/ru/login.json +2 -0
- package/frontend/dist/locales/ru/management.json +79 -1
- package/frontend/dist/locales/ru/minecraft-viewer.json +3 -0
- package/frontend/dist/locales/ru/nodes.json +105 -51
- package/frontend/dist/locales/ru/plugins.json +103 -4
- package/frontend/dist/locales/ru/setup.json +2 -0
- package/frontend/dist/locales/ru/sidebar.json +171 -3
- package/frontend/dist/locales/ru/visual-editor.json +232 -33
- package/frontend/package.json +2 -0
- package/nul +12 -0
- package/package.json +3 -3
- package/backend/package-lock.json +0 -6801
- package/backend/src/core/node-registries/actions.js +0 -202
- package/backend/src/core/node-registries/arrays.js +0 -155
- package/backend/src/core/node-registries/bot.js +0 -23
- package/backend/src/core/node-registries/container.js +0 -162
- package/backend/src/core/node-registries/data.js +0 -290
- package/backend/src/core/node-registries/debug.js +0 -26
- package/backend/src/core/node-registries/events.js +0 -201
- package/backend/src/core/node-registries/flow.js +0 -139
- package/backend/src/core/node-registries/furnace.js +0 -143
- package/backend/src/core/node-registries/logic.js +0 -62
- package/backend/src/core/node-registries/math.js +0 -42
- package/backend/src/core/node-registries/navigation.js +0 -111
- package/backend/src/core/node-registries/objects.js +0 -98
- package/backend/src/core/node-registries/strings.js +0 -187
- package/backend/src/core/node-registries/time.js +0 -113
- package/backend/src/core/node-registries/type.js +0 -25
- package/backend/src/core/node-registries/users.js +0 -79
- package/frontend/dist/assets/index-SfhKxI4-.css +0 -32
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
const mineflayer = require('mineflayer');
|
|
2
|
+
const { SocksClient } = require('socks');
|
|
3
|
+
const { Vec3 } = require('vec3');
|
|
4
|
+
const EventEmitter = require('events');
|
|
5
|
+
const MessageQueue = require('./MessageQueue');
|
|
6
|
+
|
|
7
|
+
let connectionTimeout = null;
|
|
8
|
+
let botReadySent = false;
|
|
9
|
+
|
|
10
|
+
function buildBotOptions(config) {
|
|
11
|
+
const options = {
|
|
12
|
+
host: config.server.host,
|
|
13
|
+
port: config.server.port,
|
|
14
|
+
username: config.username,
|
|
15
|
+
password: config.password,
|
|
16
|
+
version: config.server.version,
|
|
17
|
+
auth: 'offline',
|
|
18
|
+
hideErrors: false,
|
|
19
|
+
chat: 'enabled',
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
if (config.proxyHost && config.proxyPort) {
|
|
23
|
+
const cleanProxyUsername = config.proxyUsername ? config.proxyUsername.trim() : null;
|
|
24
|
+
const cleanProxyPassword = config.proxyPassword || null;
|
|
25
|
+
|
|
26
|
+
options.connect = (client) => {
|
|
27
|
+
SocksClient.createConnection({
|
|
28
|
+
proxy: {
|
|
29
|
+
host: config.proxyHost,
|
|
30
|
+
port: config.proxyPort,
|
|
31
|
+
type: 5,
|
|
32
|
+
userId: cleanProxyUsername,
|
|
33
|
+
password: cleanProxyPassword
|
|
34
|
+
},
|
|
35
|
+
command: 'connect',
|
|
36
|
+
destination: {
|
|
37
|
+
host: config.server.host,
|
|
38
|
+
port: config.server.port
|
|
39
|
+
}
|
|
40
|
+
}).then(info => {
|
|
41
|
+
client.setSocket(info.socket);
|
|
42
|
+
client.emit('connect');
|
|
43
|
+
}).catch(err => {
|
|
44
|
+
client.emit('error', err);
|
|
45
|
+
process.exit(1);
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return options;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function createBotConnection(config, sendLog) {
|
|
54
|
+
return new Promise((resolve, reject) => {
|
|
55
|
+
const botOptions = buildBotOptions(config);
|
|
56
|
+
|
|
57
|
+
if (config.proxyHost && config.proxyPort) {
|
|
58
|
+
sendLog(`[System] Используется прокси: ${config.proxyHost}:${config.proxyPort}`);
|
|
59
|
+
} else {
|
|
60
|
+
sendLog(`[System] Прокси не настроен, используется прямое подключение.`);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const bot = mineflayer.createBot(botOptions);
|
|
64
|
+
|
|
65
|
+
connectionTimeout = setTimeout(() => {
|
|
66
|
+
if (bot && !bot.player) {
|
|
67
|
+
sendLog('[System] Таймаут подключения к серверу (30 секунд). Завершение работы...');
|
|
68
|
+
process.exit(1);
|
|
69
|
+
}
|
|
70
|
+
}, 30000);
|
|
71
|
+
|
|
72
|
+
bot.on('login', () => {
|
|
73
|
+
if (connectionTimeout) {
|
|
74
|
+
clearTimeout(connectionTimeout);
|
|
75
|
+
connectionTimeout = null;
|
|
76
|
+
}
|
|
77
|
+
sendLog('[Event: login] Успешно залогинился!');
|
|
78
|
+
if (process.send && !botReadySent) {
|
|
79
|
+
process.send({ type: 'bot_ready' });
|
|
80
|
+
process.send({ type: 'status', status: 'running' });
|
|
81
|
+
botReadySent = true;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
bot.on('error', (err) => {
|
|
86
|
+
if (connectionTimeout) {
|
|
87
|
+
clearTimeout(connectionTimeout);
|
|
88
|
+
connectionTimeout = null;
|
|
89
|
+
}
|
|
90
|
+
sendLog(`[Event: error] Произошла ошибка: ${err.stack || err.message}`);
|
|
91
|
+
reject(err);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
bot.on('end', (reason) => {
|
|
95
|
+
if (connectionTimeout) {
|
|
96
|
+
clearTimeout(connectionTimeout);
|
|
97
|
+
connectionTimeout = null;
|
|
98
|
+
}
|
|
99
|
+
const restartableReasons = ['socketClosed', 'keepAliveError'];
|
|
100
|
+
const exitCode = restartableReasons.includes(reason) ? 1 : 0;
|
|
101
|
+
sendLog(`[Event: end] Отключен от сервера. Причина: ${reason}`);
|
|
102
|
+
process.exit(exitCode);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
resolve(bot);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function clearConnectionTimeout() {
|
|
110
|
+
if (connectionTimeout) {
|
|
111
|
+
clearTimeout(connectionTimeout);
|
|
112
|
+
connectionTimeout = null;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function resetBotReadySent() {
|
|
117
|
+
botReadySent = false;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
module.exports = {
|
|
121
|
+
createBotConnection,
|
|
122
|
+
buildBotOptions,
|
|
123
|
+
clearConnectionTimeout,
|
|
124
|
+
resetBotReadySent
|
|
125
|
+
};
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
const { EventTypes, MessageTypes } = require('./ipc/ipcMessageTypes');
|
|
2
|
+
const { Vec3 } = require('vec3');
|
|
3
|
+
|
|
4
|
+
const entityMoveThrottles = new Map();
|
|
5
|
+
|
|
6
|
+
function serializeEntity(entity) {
|
|
7
|
+
if (!entity) return null;
|
|
8
|
+
return {
|
|
9
|
+
id: entity.id,
|
|
10
|
+
type: entity.type,
|
|
11
|
+
username: entity.username,
|
|
12
|
+
displayName: entity.displayName,
|
|
13
|
+
position: entity.position,
|
|
14
|
+
yaw: entity.yaw,
|
|
15
|
+
pitch: entity.pitch,
|
|
16
|
+
onGround: entity.onGround,
|
|
17
|
+
isValid: entity.isValid,
|
|
18
|
+
heldItem: entity.heldItem,
|
|
19
|
+
equipment: entity.equipment,
|
|
20
|
+
metadata: entity.metadata
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function attachBotEvents(bot, handlers) {
|
|
25
|
+
const { onChat, onUserAction, sendLog, sendEvent } = handlers;
|
|
26
|
+
let messageHandledByCustomParser = false;
|
|
27
|
+
let isReady = false;
|
|
28
|
+
|
|
29
|
+
bot.on('message', (jsonMsg) => {
|
|
30
|
+
const logContent = jsonMsg.toAnsi();
|
|
31
|
+
|
|
32
|
+
if (logContent.trim()) {
|
|
33
|
+
sendLog(logContent);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
messageHandledByCustomParser = false;
|
|
37
|
+
const rawMessageText = jsonMsg.toString();
|
|
38
|
+
bot.events.emit('core:raw_message', rawMessageText, jsonMsg);
|
|
39
|
+
|
|
40
|
+
sendEvent('raw_message', {
|
|
41
|
+
rawText: rawMessageText,
|
|
42
|
+
json: jsonMsg
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
if (process.send && rawMessageText.trim()) {
|
|
46
|
+
process.send({
|
|
47
|
+
type: MessageTypes.VIEWER.CHAT,
|
|
48
|
+
payload: {
|
|
49
|
+
rawText: rawMessageText,
|
|
50
|
+
timestamp: Date.now()
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
bot.events.on('chat:message', (data) => {
|
|
57
|
+
messageHandledByCustomParser = true;
|
|
58
|
+
sendEvent('chat', {
|
|
59
|
+
username: data.username,
|
|
60
|
+
message: data.message,
|
|
61
|
+
chatType: data.type,
|
|
62
|
+
raw: data.raw,
|
|
63
|
+
});
|
|
64
|
+
if (onChat) onChat(data.type, data.username, data.message);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
bot.on('chat', (username, message) => {
|
|
68
|
+
if (messageHandledByCustomParser) return;
|
|
69
|
+
bot.events.emit('chat:message', {
|
|
70
|
+
username,
|
|
71
|
+
message,
|
|
72
|
+
type: EventTypes.CHAT,
|
|
73
|
+
raw: message
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
bot.on('whisper', (username, message) => {
|
|
78
|
+
if (messageHandledByCustomParser) return;
|
|
79
|
+
bot.events.emit('chat:message', {
|
|
80
|
+
username,
|
|
81
|
+
message,
|
|
82
|
+
type: EventTypes.WHISPER,
|
|
83
|
+
raw: message
|
|
84
|
+
});
|
|
85
|
+
if (onChat) onChat('whisper', username, message);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
bot.on('userAction', async ({ action, target, ...data }) => {
|
|
89
|
+
if (!target) return;
|
|
90
|
+
if (onUserAction) {
|
|
91
|
+
await onUserAction(action, target, data);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
bot.on('death', () => {
|
|
96
|
+
sendEvent('botDied', { user: { username: bot.username } });
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
bot.on('health', () => {
|
|
100
|
+
sendEvent('health', {
|
|
101
|
+
health: bot.health,
|
|
102
|
+
food: bot.food,
|
|
103
|
+
saturation: bot.foodSaturation
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
if (process.send) {
|
|
107
|
+
process.send({
|
|
108
|
+
type: MessageTypes.VIEWER.HEALTH,
|
|
109
|
+
payload: {
|
|
110
|
+
health: bot.health,
|
|
111
|
+
food: bot.food
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
bot.on('kicked', (reason) => {
|
|
118
|
+
let reasonText;
|
|
119
|
+
if (typeof reason === 'string') {
|
|
120
|
+
try { reasonText = JSON.parse(reason).text || reason; } catch (e) { reasonText = reason; }
|
|
121
|
+
} else if (reason && typeof reason === 'object') {
|
|
122
|
+
reasonText = reason.text || reason.message || reason.reason || JSON.stringify(reason);
|
|
123
|
+
} else {
|
|
124
|
+
reasonText = String(reason);
|
|
125
|
+
}
|
|
126
|
+
sendLog(`[Event: kicked] Меня кикнули. Причина: ${reasonText}.`);
|
|
127
|
+
process.exit(0);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
bot.on('error', (err) => {
|
|
131
|
+
sendLog(`[Event: error] Произошла ошибка: ${err.stack || err.message}`);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
bot.on('end', (reason) => {
|
|
135
|
+
const restartableReasons = ['socketClosed', 'keepAliveError'];
|
|
136
|
+
const exitCode = restartableReasons.includes(reason) ? 1 : 0;
|
|
137
|
+
sendLog(`[Event: end] Отключен от сервера. Причина: ${reason}`);
|
|
138
|
+
process.exit(exitCode);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
bot.on('playerJoined', (player) => {
|
|
142
|
+
if (!isReady) return;
|
|
143
|
+
sendEvent('playerJoined', { user: { username: player.username, uuid: player.uuid } });
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
bot.on('playerLeft', (player) => {
|
|
147
|
+
if (!isReady) return;
|
|
148
|
+
sendEvent('playerLeft', { user: { username: player.username, uuid: player.uuid } });
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
bot.on('entitySpawn', (entity) => {
|
|
152
|
+
if (!isReady) return;
|
|
153
|
+
sendEvent('entitySpawn', { entity: serializeEntity(entity) });
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
bot.on('entityMoved', (entity) => {
|
|
157
|
+
if (!isReady) return;
|
|
158
|
+
const now = Date.now();
|
|
159
|
+
const lastSent = entityMoveThrottles.get(entity.id);
|
|
160
|
+
if (!lastSent || now - lastSent > 500) {
|
|
161
|
+
entityMoveThrottles.set(entity.id, now);
|
|
162
|
+
sendEvent('entityMoved', { entity: serializeEntity(entity) });
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
bot.on('entityGone', (entity) => {
|
|
167
|
+
if (!isReady) return;
|
|
168
|
+
sendEvent('entityGone', { entity: serializeEntity(entity) });
|
|
169
|
+
entityMoveThrottles.delete(entity.id);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
bot.on('spawn', () => {
|
|
173
|
+
try {
|
|
174
|
+
if (bot._client && bot._client.options) {
|
|
175
|
+
bot._client.options.chat = 'enabled';
|
|
176
|
+
}
|
|
177
|
+
if (bot.chatEnabled !== undefined) {
|
|
178
|
+
bot.chatEnabled = true;
|
|
179
|
+
}
|
|
180
|
+
} catch (err) {}
|
|
181
|
+
|
|
182
|
+
setTimeout(() => {
|
|
183
|
+
isReady = true;
|
|
184
|
+
}, 3000);
|
|
185
|
+
|
|
186
|
+
if (process.send) {
|
|
187
|
+
process.send({
|
|
188
|
+
type: MessageTypes.VIEWER.SPAWN,
|
|
189
|
+
payload: {
|
|
190
|
+
position: bot.entity?.position,
|
|
191
|
+
yaw: bot.entity?.yaw,
|
|
192
|
+
pitch: bot.entity?.pitch
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
bot.on('move', () => {
|
|
199
|
+
if (process.send) {
|
|
200
|
+
process.send({
|
|
201
|
+
type: MessageTypes.VIEWER.MOVE,
|
|
202
|
+
payload: {
|
|
203
|
+
position: bot.entity?.position,
|
|
204
|
+
yaw: bot.entity?.yaw,
|
|
205
|
+
pitch: bot.entity?.pitch
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
bot.on('blockUpdate', (oldBlock, newBlock) => {
|
|
212
|
+
if (process.send && oldBlock && newBlock) {
|
|
213
|
+
process.send({
|
|
214
|
+
type: 'viewer:blockUpdate',
|
|
215
|
+
payload: {
|
|
216
|
+
position: {
|
|
217
|
+
x: newBlock.position.x,
|
|
218
|
+
y: newBlock.position.y,
|
|
219
|
+
z: newBlock.position.z
|
|
220
|
+
},
|
|
221
|
+
oldBlock: { type: oldBlock.type, name: oldBlock.name },
|
|
222
|
+
newBlock: { type: newBlock.type, name: newBlock.name }
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
return { setReady: (value) => { isReady = value; } };
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
module.exports = {
|
|
232
|
+
attachBotEvents,
|
|
233
|
+
serializeEntity
|
|
234
|
+
};
|