Skip to content

Commit 8ef1303

Browse files
author
Picoseconds
committed
Fix multiple dimensions and issues with older server versions
1 parent ac95464 commit 8ef1303

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

src/client/scripts/index.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ import { BlockPlace } from "./BlockPlace.js";
1616
import { DistanceBasedFog } from "./DistanceBasedFog.js";
1717
import { EventHandler } from "./EventHandler.js";
1818

19+
const dimNamesInt = {
20+
"-1": "minecraft:nether",
21+
0: "minecraft:overworld",
22+
1: "minecraft:end",
23+
};
24+
1925
class Game {
2026
constructor() {
2127
var _this = this;
@@ -49,6 +55,9 @@ class Game {
4955
"minecraft:overworld": [165 / 255, 192 / 255, 254 / 255],
5056
"minecraft:the_end": [1 / 255, 20 / 255, 51 / 255],
5157
"minecraft:the_nether": [133 / 255, 40 / 255, 15 / 255],
58+
59+
"minecraft:end": [1 / 255, 20 / 255, 51 / 255],
60+
"minecraft:nether": [133 / 255, 40 / 255, 15 / 255],
5261
};
5362
this.camera = new THREE.PerspectiveCamera(this.fov, 2, 0.1, 1000);
5463
this.camera.rotation.order = "YXZ";
@@ -101,12 +110,25 @@ class Game {
101110
_this.camera.rotation.y = yaw;
102111
_this.camera.rotation.x = pitch;
103112
});
104-
this.socket.on("dimension", function (dim) {
113+
this.socket.on("dimension", function (dim, format) {
114+
switch (format) {
115+
case "int":
116+
dim = dimNamesInt[dim];
117+
break;
118+
119+
case "world":
120+
// idk what this is yet
121+
break;
122+
}
123+
105124
_this.dimension = dim;
106125
console.log(`Player dimension has been changed: ${dim}`);
107126
_this.world.resetWorld();
127+
108128
var bg = _this.dimBg[dim];
109129
if (bg === undefined) {
130+
bg = _this.dimBg["minecraft:overworld"];
131+
110132
_this.scene.background = new THREE.Color(
111133
..._this.dimBg["minecraft:overworld"]
112134
);
@@ -138,7 +160,9 @@ class Game {
138160
_this.chat.log(msg);
139161
});
140162
this.socket.on("kicked", function (reason) {
141-
_this.chat.log("You have been kicked! Reason: " + JSON.parse(reason).text);
163+
_this.chat.log(
164+
"You have been kicked! Reason: " + JSON.parse(reason).text
165+
);
142166
});
143167
this.socket.on("xp", function (xp) {
144168
_this.inv_bar.setXp(xp.level, xp.progress);

src/index.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,15 @@ io.sockets.on("connection", function (socket) {
5454
socket.emit("mapChunk", cell.sections, packet.x, packet.z);
5555
});
5656
bot._client.on("respawn", function (packet) {
57-
socket.emit("dimension", packet.dimension.value.effects.value);
57+
socket.emit(
58+
"dimension",
59+
packet.dimension,
60+
bot.supportFeature("dimensionIsAWorld")
61+
? "world"
62+
: bot.supportFeature("dimensionIsAString")
63+
? "string"
64+
: "int"
65+
);
5866
});
5967
bot.on("heldItemChanged", function (item) {
6068
heldItem = item;
@@ -156,6 +164,7 @@ io.sockets.on("connection", function (socket) {
156164
} else if (state === "left") {
157165
state = "right";
158166
}
167+
159168
bot.setControlState(state, toggle);
160169
});
161170
socket.on("command", function (com) {

0 commit comments

Comments
 (0)