Skip to content

Commit

Permalink
integrate blockly dev tools and codegen previewing
Browse files Browse the repository at this point in the history
  • Loading branch information
ZXMushroom63 committed Dec 17, 2024
1 parent 7b723f3 commit a3bb4e0
Show file tree
Hide file tree
Showing 5 changed files with 601 additions and 2 deletions.
2 changes: 1 addition & 1 deletion blocks/BlockPos.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ javascript.javascriptGenerator.forBlock['blockpos_fromxyz'] = function () {
const value_y = javascript.javascriptGenerator.valueToCode(this, 'Y', javascript.Order.ATOMIC);
const value_z = javascript.javascriptGenerator.valueToCode(this, 'Z', javascript.Order.ATOMIC);

const code = `efb2__makeBlockPos(${value_x},${value_y},${value_z})`;
const code = `efb2__makeBlockPos(Math.floor(${value_x}),Math.floor(${value_y}),Math.floor(${value_z}))`;
return [code, javascript.Order.NONE];
}
24 changes: 24 additions & 0 deletions blocks/Entity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const entity_set_position = {
init: function () {
this.appendValueInput('ENTITY')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField('set position of entity');
this.appendValueInput('POS')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField('to Vec3');
this.setInputsInline(true)
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip('Sets the position of the entity to a vector, and sends a packet.');
this.setHelpUrl('');
this.setColour(195);
}
};
Blockly.common.defineBlocks({ entity_set_position: entity_set_position });

javascript.javascriptGenerator.forBlock['entity_set_position'] = function () {
const value_entity = javascript.javascriptGenerator.valueToCode(this, 'ENTITY', javascript.Order.ATOMIC);
const value_pos = javascript.javascriptGenerator.valueToCode(this, 'POS', javascript.Order.ATOMIC);
const code = `(${value_entity}).$setPositionAndUpdate((${value_pos}).$xCoord,(${value_pos}).$yCoord,(${value_pos}).$zCoord)`;
return code;
}
5 changes: 4 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<script src="./libs/blockly/en.js"></script>
<!-- Load dark mode -->
<script src="./libs/blockly/darktheme.js"></script>
<!-- Load dark mode -->
<script src="./libs/blockly/blockly_dev_tools.js"></script>

<xml
xmlns="https://developers.google.com/blockly/xml"
Expand Down Expand Up @@ -405,7 +407,7 @@
<block type="world_get_player_entities"> </block>
</category>
<category name="Entity (C)" colour="#ff8811">

<block type="entity_set_position"> </block>
</category>
</xml>
</head>
Expand Down Expand Up @@ -465,6 +467,7 @@ <h4>Dirt Block</h4>
<!-- Additional blocks -->
<script src="blocks/World.js"></script>
<script src="blocks/Blocks.js"></script>
<script src="blocks/Entity.js"></script>
<script src="blocks/Vec3.js"></script>
<script src="blocks/BlockPos.js"></script>
<script src="blocks/Events.js"></script> <!-- Currently unused -->
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var workspace = globalThis.workspace = Blockly.inject('blockly', {
pinch: true
},
});
blocklyDeveloperTools();
var handlers = {};
var handlerMapDict = {};
function getHandlers(type) {
Expand Down
Loading

0 comments on commit a3bb4e0

Please sign in to comment.