Skip to content

Commit 6684380

Browse files
committed
error message
1 parent a26d01b commit 6684380

File tree

3 files changed

+21
-31
lines changed

3 files changed

+21
-31
lines changed

generators/javascript/minecraft.js

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,6 @@ Blockly.JavaScript.minecraft = function() {
1515
" return c;\n"+
1616
"};\n"+
1717
"\n"+
18-
"MCPI.mvMultiply = function(a,b) {\n"+
19-
" c = [0,0,0];\n"+
20-
" for (var i = 0; i < 3 ; i++)\n"+
21-
" c[i] = a[i][0]*b[0] + a[i][1]*b[1] + a[i][2]*b[2];\n"+
22-
" return c;\n"+
23-
"};\n"+
24-
"\n"+
25-
"MCPI.vvAdd = function(a,b) {\n"+
26-
" return [a[0]+b[0],a[1]+b[1],a[2]+b[2]];\n"+
27-
"};\n"+
28-
"\n"+
29-
"MCPI.vvSub = function(a,b) {\n"+
30-
" return [a[0]-b[0],a[1]-b[1],a[2]-b[2]];\n"+
31-
"};\n"+
32-
"\n"+
3318
"MCPI.yawMatrix = function(angleDegrees) {\n"+
3419
" var theta = angleDegrees * MCPI.TO_RADIANS;\n"+
3520
" return [[Math.cos(theta), 0., -Math.sin(theta)],\n"+
@@ -228,6 +213,14 @@ Blockly.JavaScript.minecraft = function() {
228213
"\n"+
229214
"MCPI.socket = new WebSocket(\"ws://127.0.0.1:14711\");\n"+
230215
"\n"+
216+
"MCPI.timeoutFunction = function() {\n"+
217+
" MCPI.socket.close();\n"+
218+
" window.alert('Cannot connect to Minecraft API. Make sure you have Minecraft running with Raspberry Jam Mod.');\n"+
219+
" exit();\n"+
220+
"};\n"+
221+
"\n"+
222+
"MCPI.timerID = setTimeout(MCPI.timeoutFunction, 5000);\n"+
223+
"\n"+
231224
"MCPI.socket.onopen = function(event) {\n"+
232225
" MCPI.socket.onmessage = function(event) {\n"+
233226
" var args = event.data.trim().split(\",\");\n"+
@@ -242,6 +235,8 @@ Blockly.JavaScript.minecraft = function() {
242235
" MCPI.socket.onmessage = function(event) {\n"+
243236
" var yaw = parseFloat(event.data.trim());\n"+
244237
" MCPI.matrix = MCPI.yawMatrix(yaw);\n"+
238+
" clearTimeout(MCPI.timerID);\n"+
239+
"\n"+
245240
"\n";
246241
Blockly.JavaScript.cleanups_['minecraft'] = "MCPI.socket.close();\n"+
247242
"}; // end MCPI.socket.onmessage for player.getRotation()\n"+

generators/javascript/source/mcinit.js

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,6 @@ MCPI.mmMultiply = function(a,b) {
1414
return c;
1515
};
1616

17-
MCPI.mvMultiply = function(a,b) {
18-
c = [0,0,0];
19-
for (var i = 0; i < 3 ; i++)
20-
c[i] = a[i][0]*b[0] + a[i][1]*b[1] + a[i][2]*b[2];
21-
return c;
22-
};
23-
24-
MCPI.vvAdd = function(a,b) {
25-
return [a[0]+b[0],a[1]+b[1],a[2]+b[2]];
26-
};
27-
28-
MCPI.vvSub = function(a,b) {
29-
return [a[0]-b[0],a[1]-b[1],a[2]-b[2]];
30-
};
31-
3217
MCPI.yawMatrix = function(angleDegrees) {
3318
var theta = angleDegrees * MCPI.TO_RADIANS;
3419
return [[Math.cos(theta), 0., -Math.sin(theta)],
@@ -227,6 +212,14 @@ MCPI.turtleGo = function(distance) {
227212

228213
MCPI.socket = new WebSocket("ws://127.0.0.1:14711");
229214

215+
MCPI.timeoutFunction = function() {
216+
MCPI.socket.close();
217+
window.alert('Cannot connect to Minecraft API. Make sure you have Minecraft running with Raspberry Jam Mod.');
218+
exit();
219+
};
220+
221+
MCPI.timerID = setTimeout(MCPI.timeoutFunction, 5000);
222+
230223
MCPI.socket.onopen = function(event) {
231224
MCPI.socket.onmessage = function(event) {
232225
var args = event.data.trim().split(",");
@@ -241,4 +234,6 @@ MCPI.socket.onopen = function(event) {
241234
MCPI.socket.onmessage = function(event) {
242235
var yaw = parseFloat(event.data.trim());
243236
MCPI.matrix = MCPI.yawMatrix(yaw);
237+
clearTimeout(MCPI.timerID);
238+
244239

javascript_compressed.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)