Skip to content

Commit 78bac98

Browse files
committed
fix old socket emitting
1 parent d22409a commit 78bac98

File tree

1 file changed

+73
-77
lines changed

1 file changed

+73
-77
lines changed

src/index.js

Lines changed: 73 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -47,85 +47,81 @@ io.sockets.on("connection", function (socket) {
4747
version: config.version,
4848
});
4949
botByNick[query.nick] = bot;
50-
bot.once("spawn", function () {
51-
bot._client.on("map_chunk", function (packet) {
52-
var cell = new Chunk();
53-
cell.load(packet.chunkData, packet.bitMap, true, true);
54-
socket.emit("mapChunk", cell.sections, packet.x, packet.z);
55-
});
56-
bot._client.on("respawn", function (packet) {
57-
socket.emit("dimension", packet.dimension.value.effects.value);
58-
});
59-
bot.on("heldItemChanged", function (item) {
60-
heldItem = item;
61-
});
62-
bot.on("login", function () {
63-
socket.emit("dimension", bot.game.dimension);
64-
});
65-
bot.on("move", function () {
66-
socket.emit("move", bot.entity.position);
67-
});
68-
bot.on("health", function () {
69-
socket.emit("hp", bot.health);
70-
socket.emit("food", bot.food);
71-
});
72-
bot.on("spawn", function () {
73-
socket.emit("spawn", bot.entity.yaw, bot.entity.pitch);
74-
});
75-
bot.on("kicked", function (reason) {
76-
socket.emit("kicked", reason);
77-
});
78-
bot.on("message", function (msg) {
79-
socket.emit("msg", convert.toHtml(msg.toAnsi()));
80-
});
81-
bot.on("experience", function () {
82-
socket.emit("xp", bot.experience);
83-
});
84-
bot.on("blockUpdate", function (oldb, newb) {
85-
socket.emit("blockUpdate", [
86-
newb.position.x,
87-
newb.position.y,
88-
newb.position.z,
89-
newb.stateId,
90-
]);
91-
});
92-
bot.on("diggingCompleted", function (block) {
93-
socket.emit("diggingCompleted", block);
94-
});
95-
bot.on("diggingAborted", function (block) {
96-
socket.emit("diggingAborted", block);
97-
});
98-
var inv = "";
99-
var interval = setInterval(function () {
100-
var inv_new = JSON.stringify(bot.inventory.slots);
101-
if (inv !== inv_new) {
102-
inv = inv_new;
103-
socket.emit("inventory", bot.inventory.slots);
50+
bot._client.on("map_chunk", function (packet) {
51+
var cell = new Chunk();
52+
cell.load(packet.chunkData, packet.bitMap, true, true);
53+
socket.emit("mapChunk", cell.sections, packet.x, packet.z);
54+
});
55+
bot._client.on("respawn", function (packet) {
56+
socket.emit("dimension", packet.dimension.value.effects.value);
57+
});
58+
bot.on("heldItemChanged", function (item) {
59+
heldItem = item;
60+
});
61+
bot.on("login", function () {
62+
socket.emit("dimension", bot.game.dimension);
63+
});
64+
bot.on("move", function () {
65+
socket.emit("move", bot.entity.position);
66+
});
67+
bot.on("health", function () {
68+
socket.emit("hp", bot.health);
69+
socket.emit("food", bot.food);
70+
});
71+
bot.on("spawn", function () {
72+
socket.emit("spawn", bot.entity.yaw, bot.entity.pitch);
73+
});
74+
bot.on("kicked", function (reason) {
75+
socket.emit("kicked", reason);
76+
});
77+
bot.on("message", function (msg) {
78+
socket.emit("msg", convert.toHtml(msg.toAnsi()));
79+
});
80+
bot.on("experience", function () {
81+
socket.emit("xp", bot.experience);
82+
});
83+
bot.on("blockUpdate", function (oldb, newb) {
84+
socket.emit("blockUpdate", [
85+
newb.position.x,
86+
newb.position.y,
87+
newb.position.z,
88+
newb.stateId,
89+
]);
90+
});
91+
bot.on("diggingCompleted", function (block) {
92+
socket.emit("diggingCompleted", block);
93+
});
94+
bot.on("diggingAborted", function (block) {
95+
socket.emit("diggingAborted", block);
96+
});
97+
var inv = "";
98+
var interval = setInterval(function () {
99+
var inv_new = JSON.stringify(bot.inventory.slots);
100+
if (inv !== inv_new) {
101+
inv = inv_new;
102+
socket.emit("inventory", bot.inventory.slots);
103+
}
104+
var entities = {
105+
mobs: [],
106+
players: [],
107+
};
108+
for (var k in bot.entities) {
109+
var v = bot.entities[k];
110+
if (v.type === "mob") {
111+
entities.mobs.push([v.position.x, v.position.y, v.position.z]);
104112
}
105-
var entities = {
106-
mobs: [],
107-
players: [],
108-
};
109-
for (var k in bot.entities) {
110-
var v = bot.entities[k];
111-
if (v.type === "mob") {
112-
entities.mobs.push([
113-
v.position.x,
114-
v.position.y,
115-
v.position.z,
116-
]);
117-
}
118-
if (v.type === "player") {
119-
entities.players.push([
120-
v.username,
121-
v.position.x,
122-
v.position.y,
123-
v.position.z,
124-
]);
125-
}
113+
if (v.type === "player") {
114+
entities.players.push([
115+
v.username,
116+
v.position.x,
117+
v.position.y,
118+
v.position.z,
119+
]);
126120
}
127-
socket.emit("entities", entities);
128-
}, 10);
121+
}
122+
socket.emit("entities", entities);
123+
}, 10);
124+
bot.once("spawn", function () {
129125
socket.on("fly", function (toggle) {
130126
if (toggle) {
131127
bot.creative.startFlying();

0 commit comments

Comments
 (0)