Skip to content

Commit 3f97181

Browse files
committed
postToChat
1 parent 2a431f2 commit 3f97181

File tree

7 files changed

+49
-6
lines changed

7 files changed

+49
-6
lines changed

blocks/minecraft.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,20 @@ Blockly.Blocks['minecraft_turtle_go'] = {
3636
}
3737
};
3838

39+
Blockly.Blocks['minecraft_post_to_chat'] = {
40+
init: function() {
41+
this.appendValueInput("MESSAGE")
42+
.setCheck("String")
43+
.appendField("Post to chat");
44+
this.setInputsInline(true);
45+
this.setPreviousStatement(true);
46+
this.setNextStatement(true);
47+
this.setColour(164);
48+
this.setTooltip('');
49+
this.setHelpUrl('github.com/arpruss/raspberryjammod');
50+
}
51+
};
52+
3953
Blockly.Blocks['minecraft_turtle_yaw'] = {
4054
init: function() {
4155
this.appendDummyInput()

blocks_compressed.js

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

demos/code/index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ <h1><a href="https://developers.google.com/blockly/">Blockly</a>&rlm; &gt;
8888
</block>
8989
</value>
9090
</block>
91+
<block type="minecraft_post_to_chat">
92+
<value name="MESSAGE">
93+
<block type="text"></block>
94+
</value>
95+
</block>
9196
<block type="minecraft_turtle_go">
9297
<value name="DISTANCE">
9398
<block type="math_number">

generators/javascript/minecraft.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,18 @@ Blockly.JavaScript.minecraft = function() {
134134
" return line;\n"+
135135
"};\n"+
136136
"\n"+
137+
"MCPI.postToChat = function(message) {\n"+
138+
" MCPI.socket.send(\"chat.post(\"+message+\")\");\n"+
139+
"};\n"+
140+
"\n"+
137141
"MCPI.setBlock = function(x,y,z,block) {\n"+
138142
" if (block != \"0\" && Math.floor(x) == Math.floor(MCPI.playerX) && Math.floor(z) == Math.floor(MCPI.playerZ)\n"+
139143
" && (Math.floor(y) >= MCPI.playerShiftedHeight) ) {\n"+
140144
" MCPI.playerShiftedHeight = Math.floor(y) + 1;\n"+
141145
" MCPI.socket.send(\"player.setPos(\"+MCPI.playerX+\",\"+MCPI.playerShiftedHeight+\",\"+MCPI.playerZ+\")\");\n"+
142146
" }\n"+
143147
" MCPI.socket.send(\"world.setBlock(\"+x+\",\"+y+\",\"+z+\",\"+block+\")\");\n"+
144-
"}\n"+
148+
"};\n"+
145149
"\n"+
146150
"MCPI.drawPoint = function(x0,y0,z0) {\n"+
147151
" var l = MCPI.nib.length;\n"+
@@ -265,6 +269,13 @@ Blockly.JavaScript['minecraft_turtle_go'] = function(block) {
265269
return code;
266270
};
267271

272+
Blockly.JavaScript['minecraft_post_to_chat'] = function(block) {
273+
Blockly.JavaScript.minecraft();
274+
var value_message = Blockly.JavaScript.valueToCode(block, 'MESSAGE', Blockly.JavaScript.ORDER_ATOMIC);
275+
var code = 'MCPI.postToChat('+value_message+');\n';
276+
return code;
277+
};
278+
268279
Blockly.JavaScript['minecraft_turtle_yaw'] = function(block) {
269280
Blockly.JavaScript.minecraft();
270281
var dropdown_direction = block.getFieldValue('DIRECTION');

generators/javascript/source/mcinit.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,18 @@ MCPI.getLine = function(x1,y1,z1,x2,y2,z2) {
133133
return line;
134134
};
135135

136+
MCPI.postToChat = function(message) {
137+
MCPI.socket.send("chat.post("+message+")");
138+
};
139+
136140
MCPI.setBlock = function(x,y,z,block) {
137141
if (block != "0" && Math.floor(x) == Math.floor(MCPI.playerX) && Math.floor(z) == Math.floor(MCPI.playerZ)
138142
&& (Math.floor(y) >= MCPI.playerShiftedHeight) ) {
139143
MCPI.playerShiftedHeight = Math.floor(y) + 1;
140144
MCPI.socket.send("player.setPos("+MCPI.playerX+","+MCPI.playerShiftedHeight+","+MCPI.playerZ+")");
141145
}
142146
MCPI.socket.send("world.setBlock("+x+","+y+","+z+","+block+")");
143-
}
147+
};
144148

145149
MCPI.drawPoint = function(x0,y0,z0) {
146150
var l = MCPI.nib.length;

generators/javascript/source/minecraft-in.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ Blockly.JavaScript['minecraft_turtle_go'] = function(block) {
2121
return code;
2222
};
2323

24+
Blockly.JavaScript['minecraft_post_to_chat'] = function(block) {
25+
Blockly.JavaScript.minecraft();
26+
var value_message = Blockly.JavaScript.valueToCode(block, 'MESSAGE', Blockly.JavaScript.ORDER_ATOMIC);
27+
var code = 'MCPI.postToChat('+value_message+');\n';
28+
return code;
29+
};
30+
2431
Blockly.JavaScript['minecraft_turtle_yaw'] = function(block) {
2532
Blockly.JavaScript.minecraft();
2633
var dropdown_direction = block.getFieldValue('DIRECTION');

0 commit comments

Comments
 (0)