Skip to content

Commit d7d965d

Browse files
committed
use const and let instead of var
1 parent c3ed335 commit d7d965d

24 files changed

+282
-295
lines changed

index.js

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
var version = "1.16.5";
2-
var opn = require("open");
3-
var express = require("express");
4-
var app = express();
5-
var server = require("http").createServer(app);
6-
var mineflayer = require("mineflayer");
7-
var Chunk = require("prismarine-chunk")(version);
8-
var vec3 = require("vec3");
9-
var Convert = require("ansi-to-html");
10-
var convert = new Convert();
11-
var helmet = require("helmet");
12-
var compression = require("compression");
1+
const version = "1.16.5";
2+
const opn = require("open");
3+
const express = require("express");
4+
const app = express();
5+
const server = require("http").createServer(app);
6+
const mineflayer = require("mineflayer");
7+
const Chunk = require("prismarine-chunk")(version);
8+
const vec3 = require("vec3");
9+
const Convert = require("ansi-to-html");
10+
const convert = new Convert();
11+
const helmet = require("helmet");
12+
const compression = require("compression");
1313
const WebSocket = require("ws");
1414
const { encode, decode } = require("@msgpack/msgpack");
15-
var port = process.env.PORT || 8080;
15+
const port = process.env.PORT || 8080;
1616

1717
app.use(
1818
helmet({
@@ -26,14 +26,14 @@ const wss = new WebSocket.Server({
2626
clientTracking: false,
2727
});
2828

29-
var mode = process.argv[2];
29+
const mode = process.argv[2];
3030
if (mode === "production") {
3131
app.use(express.static(`${__dirname}/src/dist`));
3232
} else if (mode === "development") {
33-
var webpack = require("webpack");
34-
var middleware = require("webpack-dev-middleware");
35-
var devconfig = require(`${__dirname}/src/webpack.dev.js`);
36-
var compiler = webpack(devconfig);
33+
const webpack = require("webpack");
34+
const middleware = require("webpack-dev-middleware");
35+
const devconfig = require(`${__dirname}/src/webpack.dev.js`);
36+
const compiler = webpack(devconfig);
3737
app.use(middleware(compiler));
3838
} else {
3939
console.log("Incorrect mode!");
@@ -43,10 +43,10 @@ server.listen(port, function () {
4343
return console.log(`Server is running on \x1b[34m*:${port}\x1b[0m`);
4444
});
4545

46-
var botByNick = new Map();
46+
const botByNick = new Map();
4747

4848
wss.on("connection", (socket, req) => {
49-
var query = new URLSearchParams(req.url.substr(2, req.url.length));
49+
const query = new URLSearchParams(req.url.substr(2, req.url.length));
5050
const emit = (type, ...data) => {
5151
socket.send(encode([type, ...data]));
5252
};
@@ -56,8 +56,8 @@ wss.on("connection", (socket, req) => {
5656
return;
5757
}
5858
console.log(`[\x1b[32m+\x1b[0m] ${query.get("nick")}`);
59-
var heldItem = null;
60-
var bot = mineflayer.createBot({
59+
let heldItem = null;
60+
const bot = mineflayer.createBot({
6161
host: query.get("server"),
6262
port: query.get("port") !== "null" ? query.get("port") : null,
6363
username: query.get("nick"),
@@ -67,7 +67,7 @@ wss.on("connection", (socket, req) => {
6767
});
6868
botByNick.set(query.get("nick"), bot);
6969
bot._client.on("map_chunk", function (packet) {
70-
var cell = new Chunk();
70+
const cell = new Chunk();
7171
cell.load(packet.chunkData, packet.bitMap, true, true);
7272
emit("mapChunk", cell.sections, packet.x, packet.z);
7373
});
@@ -127,19 +127,19 @@ wss.on("connection", (socket, req) => {
127127
bot.on("game", function () {
128128
emit("game", bot.game);
129129
});
130-
var inv = "";
131-
var interval = setInterval(function () {
132-
var inv_new = JSON.stringify(bot.inventory.slots);
130+
let inv = "";
131+
const interval = setInterval(function () {
132+
const inv_new = JSON.stringify(bot.inventory.slots);
133133
if (inv !== inv_new) {
134134
inv = inv_new;
135135
emit("inventory", bot.inventory.slots);
136136
}
137-
var entities = {
137+
let entities = {
138138
mobs: [],
139139
players: [],
140140
};
141-
for (var k in bot.entities) {
142-
var v = bot.entities[k];
141+
for (let k in bot.entities) {
142+
const v = bot.entities[k];
143143
if (v.type === "mob") {
144144
entities.mobs.push([v.position.x, v.position.y, v.position.z]);
145145
}
@@ -166,7 +166,7 @@ wss.on("connection", (socket, req) => {
166166
}
167167
});
168168
handlers.set("blockPlace", function (pos, vec) {
169-
var block = bot.blockAt(new vec3(...pos));
169+
const block = bot.blockAt(new vec3(...pos));
170170
if (heldItem !== void 0 && heldItem !== null) {
171171
console.log(heldItem);
172172
bot.placeBlock(block, new vec3(...vec), function (r) {
@@ -175,7 +175,7 @@ wss.on("connection", (socket, req) => {
175175
}
176176
});
177177
handlers.set("invc", function (num) {
178-
var item = bot.inventory.slots[num + 36];
178+
const item = bot.inventory.slots[num + 36];
179179
if (item !== null && item !== void 0) {
180180
bot.equip(item, "hand");
181181
} else if (heldItem !== void 0) {
@@ -197,9 +197,9 @@ wss.on("connection", (socket, req) => {
197197
bot.look(...data);
198198
});
199199
handlers.set("dig", function (pos) {
200-
var block = bot.blockAt(vec3(pos[0], pos[1] - 16, pos[2]));
200+
const block = bot.blockAt(vec3(pos[0], pos[1] - 16, pos[2]));
201201
if (block !== null) {
202-
var digTime = bot.digTime(block);
202+
const digTime = bot.digTime(block);
203203
if (bot.targetDigBlock !== null) {
204204
console.log("Already digging...");
205205
bot.stopDigging();

lib/atlasCreator.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
var path = require("path");
1+
const path = require("path");
22

3-
var fs = require("fs");
3+
const fs = require("fs");
44

5-
var Canvas = require("canvas");
5+
const Canvas = require("canvas");
66

7-
var AtlasCreator = class AtlasCreator {
7+
const AtlasCreator = class AtlasCreator {
88
constructor(options) {
99
this.pref = options.pref;
1010
this.oneFrame = options.oneFrame;
@@ -34,15 +34,15 @@ var AtlasCreator = class AtlasCreator {
3434

3535
firstLoad() {
3636
fs.readdir(this.loadPath, (err, files) => {
37-
var totalImages = 0;
37+
let totalImages = 0;
3838
files.forEach((file) => {
3939
if (path.extname(file) === ".png") {
4040
totalImages += 1;
4141
}
4242
});
4343
this.totalImages = totalImages;
4444
files.forEach((file) => {
45-
var filePath = `${this.loadPath}/${file}`;
45+
const filePath = `${this.loadPath}/${file}`;
4646
if (path.extname(file) === ".png") {
4747
// console.log filePath
4848
this.addImageToLoad(filePath, file);
@@ -52,7 +52,7 @@ var AtlasCreator = class AtlasCreator {
5252
}
5353

5454
addImageToLoad(filePath, name) {
55-
var img = new Canvas.Image();
55+
const img = new Canvas.Image();
5656
img.onload = () => {
5757
this.images[name] = img;
5858
this.loadedImages++;
@@ -65,15 +65,15 @@ var AtlasCreator = class AtlasCreator {
6565

6666
forEachToxel() {
6767
Object.keys(this.images).forEach((name) => {
68-
var img = this.images[name];
68+
const img = this.images[name];
6969
this.addToxelToAtlas(img, name);
7070
});
7171
return this.updateAtlas();
7272
}
7373

7474
addToxelToAtlas(img, name) {
75-
var w = img.width / this.toxelSize;
76-
var h = img.height / this.toxelSize;
75+
const w = img.width / this.toxelSize;
76+
const h = img.height / this.toxelSize;
7777
if (this.oneFrame) {
7878
this.ctx.drawImage(
7979
img,

lib/postinstall.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var extract = require("extract-zip");
1+
const extract = require("extract-zip");
22
extract(
33
`${__dirname}/../assets/pack.zip`,
44
{ dir: `${__dirname}/../assets/pack` },

lib/prebuild.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
var version = "1.16.5";
2-
var fs = require("fs");
3-
var pBlock = require("prismarine-block")(version);
4-
var atlasCreator = require("./atlasCreator");
1+
const version = "1.16.5";
2+
const fs = require("fs");
3+
const pBlock = require("prismarine-block")(version);
4+
const atlasCreator = require("./atlasCreator");
55

66
new atlasCreator({
77
pref: "items",
@@ -30,10 +30,10 @@ new atlasCreator({
3030
oneFrame: true,
3131
});
3232

33-
var maxStateId = 0;
33+
let maxStateId = 0;
3434

35-
for (var i = 0; i < 100000; i++) {
36-
var block = pBlock.fromStateId(i);
35+
for (let i = 0; i < 100000; i++) {
36+
const block = pBlock.fromStateId(i);
3737
if (block.type === void 0) {
3838
maxStateId = i - 1;
3939
break;
@@ -42,18 +42,18 @@ for (var i = 0; i < 100000; i++) {
4242

4343
console.log(`\x1b[33mBlock max stateId: ${maxStateId}\x1b[0m`);
4444

45-
var result = [];
45+
const result = [];
4646

4747
for (let i = 0; i <= maxStateId; i++) {
48-
block = pBlock.fromStateId(i);
48+
const block = pBlock.fromStateId(i);
4949
result.push([
5050
block.name,
5151
block.boundingBox === "block" ? 1 : 0,
5252
block.transparent ? 1 : 0,
5353
]);
5454
}
5555

56-
var buildPath = `${__dirname}/../src/assets/blocks/blocksDef.json`;
56+
const buildPath = `${__dirname}/../src/assets/blocks/blocksDef.json`;
5757

5858
fs.writeFileSync(buildPath, JSON.stringify(result));
5959

src/scripts/AssetLoader.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ class AssetLoader {
1414

1515
async load(assets) {
1616
return new Promise((resolve) => {
17-
var textureLoader = new TextureLoader();
18-
var fbxl = new FBXLoader();
19-
var assetsNumber = Object.keys(assets).length;
20-
var assetsLoaded = 0;
17+
const textureLoader = new TextureLoader();
18+
const fbxl = new FBXLoader();
19+
const assetsNumber = Object.keys(assets).length;
20+
let assetsLoaded = 0;
2121

2222
for (const assetName in assets) {
2323
// eslint-disable-next-line no-prototype-builtins
2424
if (!assets.hasOwnProperty(assetName)) continue;
2525

2626
let asset = assets[assetName];
27-
27+
const img = new Image();
2828
switch (asset.type) {
2929
case "texture":
3030
textureLoader.load(asset.path, (texture) => {
@@ -45,7 +45,6 @@ class AssetLoader {
4545
});
4646
break;
4747
case "image":
48-
var img = new Image();
4948
img.onload = () => {
5049
this.assets.set(assetName, img);
5150
assetsLoaded++;

src/scripts/BlockBreak.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ class BlockBreak {
3939
return (this.cursor.material.visible = false);
4040
} else {
4141
this.cursor.material.visible = true;
42-
var toxX = 6 + state;
43-
var toxY = 8;
44-
var q = 1 / 27;
42+
const toxX = 6 + state;
43+
const toxY = 8;
44+
const q = 1 / 27;
4545
for (
46-
var i = 0;
46+
let i = 0;
4747
i <= this.cursor.geometry.attributes.uv.array.length;
4848
i++
4949
) {
@@ -84,13 +84,13 @@ class BlockBreak {
8484
}
8585

8686
updatePos(cb) {
87-
var rayBlock = this.game.world.getRayBlock();
87+
const rayBlock = this.game.world.getRayBlock();
8888
if (JSON.stringify(this.lastPos) !== JSON.stringify(rayBlock)) {
8989
this.lastPos = rayBlock;
9090
cb();
9191
}
9292
if (rayBlock) {
93-
var pos = rayBlock.posBreak;
93+
const pos = rayBlock.posBreak;
9494
this.cursor.position.set(...pos);
9595
this.cursor.visible = true;
9696
this.cursorOut.position.set(...pos);
@@ -103,15 +103,15 @@ class BlockBreak {
103103

104104
digRequest() {
105105
console.log("REQUESTING DIGGING...");
106-
var pos = this.game.world.getRayBlock().posBreak;
106+
const pos = this.game.world.getRayBlock().posBreak;
107107
if (pos !== void 0) {
108108
this.game.socket.emit("dig", pos);
109109
this.done = false;
110110
}
111111
}
112112

113113
startDigging(time) {
114-
var ile = 0;
114+
let ile = 0;
115115
if (this.isDigging === false) {
116116
this.isDigging = true;
117117
this.int = setInterval(() => {

src/scripts/BlockPlace.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ class BlockPlace {
44
}
55

66
placeBlock() {
7-
var pos = this.game.world.getRayBlock();
8-
var vector = [
7+
const pos = this.game.world.getRayBlock();
8+
const vector = [
99
pos.posPlace[0] - pos.posBreak[0],
1010
pos.posPlace[1] - pos.posBreak[1],
1111
pos.posPlace[2] - pos.posBreak[2],

src/scripts/Entities.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ class Entities {
3838
}
3939

4040
update(entities) {
41-
var offset = [-0.5, 16, -0.5];
42-
var num_mobs = 0;
41+
const offset = [-0.5, 16, -0.5];
42+
let num_mobs = 0;
4343
this.mobMesh.count = entities.mobs.length;
4444
num_mobs = 0;
4545
for (let i in entities.mobs) {
@@ -52,7 +52,7 @@ class Entities {
5252
this.mobMesh.setMatrixAt(num_mobs++, this.dummy.matrix);
5353
}
5454
this.mobMesh.instanceMatrix.needsUpdate = true;
55-
var num_players = 0;
55+
let num_players = 0;
5656
for (let i in entities.players) {
5757
if (entities.players[i][0] !== this.game.nick) {
5858
num_players++;

0 commit comments

Comments
 (0)