Skip to content

Commit

Permalink
upgrade blockly dev tools, start work on entity commands
Browse files Browse the repository at this point in the history
  • Loading branch information
ZXMushroom63 committed Dec 17, 2024
1 parent a3bb4e0 commit 3512e35
Show file tree
Hide file tree
Showing 6 changed files with 204 additions and 12 deletions.
2 changes: 1 addition & 1 deletion blocks/BlockPos.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Blockly.common.defineBlocks({ blockpos_getxyz: blockpos_getxyz });


javascript.javascriptGenerator.forBlock['blockpos_getxyz'] = function () {
const dropdown_tab = block.getFieldValue('TAB');
const dropdown_tab = this.getFieldValue('TAB');
const value_value = javascript.javascriptGenerator.valueToCode(this, 'VALUE', javascript.Order.ATOMIC);

const code = `(${value_value})["${dropdown_tab}"]`;
Expand Down
12 changes: 6 additions & 6 deletions blocks/Blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,12 @@ const blocks_boundingbox = {
};
Blockly.common.defineBlocks({ blocks_boundingbox: blocks_boundingbox });
javascript.javascriptGenerator.forBlock['blocks_boundingbox'] = function () {
const number_minx = block.getFieldValue('MINX');
const number_miny = block.getFieldValue('MINY');
const number_minz = block.getFieldValue('MINZ');
const number_maxx = block.getFieldValue('MAXX');
const number_maxy = block.getFieldValue('MAXY');
const number_maxz = block.getFieldValue('MAXZ');
const number_minx = this.getFieldValue('MINX');
const number_miny = this.getFieldValue('MINY');
const number_minz = this.getFieldValue('MINZ');
const number_maxx = this.getFieldValue('MAXX');
const number_maxy = this.getFieldValue('MAXY');
const number_maxz = this.getFieldValue('MAXZ');
const code = `this.$setBlockBounds(${number_minx}, ${number_miny}, ${number_minz}, ${number_maxx}, ${number_maxy}, ${number_maxz})`;
return code;
}
Expand Down
192 changes: 190 additions & 2 deletions blocks/Entity.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,38 @@
const ENTITY_NUMERICAL_PROPS = [
['x', '$posX'],
['y', '$posY'],
['z', '$posZ'],
['x velocity', '$motionX'],
['y velocity', '$motionY'],
['z velocity', '$motionZ'],
['yaw', '$rotationYaw'],
['pitch', '$rotationPitch'],
['fallDistance', '$fallDistance'],
['stepHeight', '$stepHeight'],
['age (ticks)', '$ticksExisted'],
['fire time (ticks)', '$fire'],
['chunk x', '$chunkCoordX'],
['chunk y', '$chunkCoordY'],
['chunk z', '$chunkCoordZ'],
['dimension', '$dimension'],
['collision reduction', "$entityCollisionReduction"]
];
const ENTITY_BOOLEAN_PROPS = [
['on ground', '$onGround'],
['collided horizontally', '$isCollidedHorizontally'],
['collided vertically', '$isCollidedVertically'],
['collided', '$isCollided'],
['is in web', '$isInWeb'],
['is outside border', '$isOutsideBorder'],
['is dead', '$isDead'],
['no clip', '$noClip'],
['in water', '$inWater'],
['is immune to fire', '$isImmuneToFire'],
['in portal', '$inPortal'],
['invulnerable', '$invulnerable']
];


const entity_set_position = {
init: function () {
this.appendValueInput('ENTITY')
Expand All @@ -11,14 +46,167 @@ const entity_set_position = {
this.setNextStatement(true, null);
this.setTooltip('Sets the position of the entity to a vector, and sends a packet.');
this.setHelpUrl('');
this.setColour(195);
this.setColour(30);
}
};
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)`;
const code = `var $$efb_vec3pos = ${value_pos};(${value_entity}).$setPositionAndUpdate($$efb_vec3pos.$xCoord,$$efb_vec3pos.$yCoord,$$efb_vec3pos.$zCoord)`;
return code;
}


const entity_set_position_xyz = {
init: function () {
this.appendValueInput('ENTITY')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField('set position of entity');
this.appendValueInput('X')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField('to X:');
this.appendValueInput('Y')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField('Y:');
this.appendValueInput('Z')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField('Z:');
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(30);
}
};
Blockly.common.defineBlocks({ entity_set_position_xyz: entity_set_position_xyz });

javascript.javascriptGenerator.forBlock['entity_set_position_xyz'] = function () {
const value_entity = javascript.javascriptGenerator.valueToCode(this, 'ENTITY', javascript.Order.ATOMIC);
const value_X = javascript.javascriptGenerator.valueToCode(this, 'X', javascript.Order.ATOMIC);
const value_Y = javascript.javascriptGenerator.valueToCode(this, 'Y', javascript.Order.ATOMIC);
const value_Z = javascript.javascriptGenerator.valueToCode(this, 'Z', javascript.Order.ATOMIC);
const code = `(${value_entity}).$setPositionAndUpdate(${value_X},${value_Y},${value_Z})`;
return code;
}





const entity_get_prop = {
init: function () {
this.appendDummyInput('PROP')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(new Blockly.FieldDropdown(ENTITY_NUMERICAL_PROPS), 'PROP');
this.appendValueInput('ENTITY')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField('of entity');
this.setInputsInline(true)
this.setOutput(true, "Number");
this.setTooltip('Gets a property of the entity. yaw and pitch are in radians, not degrees.');
this.setHelpUrl('');
this.setColour(30);
}
};
Blockly.common.defineBlocks({ entity_get_prop: entity_get_prop });

javascript.javascriptGenerator.forBlock['entity_get_prop'] = function () {
const dropdown_prop = this.getFieldValue('PROP');
const value_entity = javascript.javascriptGenerator.valueToCode(this, 'ENTITY', javascript.Order.ATOMIC);
const code = `(${value_entity})["${dropdown_prop}"]`;
return [code, javascript.Order.NONE];
}



const entity_set_prop = {
init: function () {
this.appendDummyInput('PROP')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField('set')
.appendField(new Blockly.FieldDropdown(ENTITY_NUMERICAL_PROPS), 'PROP');
this.appendValueInput('ENTITY')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField('of entity');
this.appendValueInput('VALUE')
.setAlign(Blockly.inputs.Align.RIGHT)
.setCheck('Number')
.appendField('to');
this.setInputsInline(true)
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip('Sets a property of the entity. yaw and pitch are in radians, not degrees.');
this.setHelpUrl('');
this.setColour(30);
}
};
Blockly.common.defineBlocks({ entity_set_prop: entity_set_prop });

javascript.javascriptGenerator.forBlock['entity_set_prop'] = function () {
const dropdown_prop = this.getFieldValue('PROP');
const value_entity = javascript.javascriptGenerator.valueToCode(this, 'ENTITY', javascript.Order.ATOMIC);
const value_value = javascript.javascriptGenerator.valueToCode(this, 'VALUE', javascript.Order.ATOMIC);
const code = `(${value_entity})["${dropdown_prop}"] = ${value_value}`;
return code;
}




const entity_set_switch = {
init: function () {
this.appendDummyInput('PROP')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField('set boolean')
.appendField(new Blockly.FieldDropdown(ENTITY_BOOLEAN_PROPS), 'PROP');
this.appendValueInput('ENTITY')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField('of entity');
this.appendValueInput('VALUE')
.setAlign(Blockly.inputs.Align.RIGHT)
.setCheck('Boolean')
.appendField('to');
this.setInputsInline(true)
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip('Sets a boolean property of the entity.');
this.setHelpUrl('');
this.setColour(30);
}
};
Blockly.common.defineBlocks({ entity_set_switch: entity_set_switch });
javascript.javascriptGenerator.forBlock['entity_set_switch'] = function () {
const dropdown_prop = this.getFieldValue('PROP');
const value_entity = javascript.javascriptGenerator.valueToCode(this, 'ENTITY', javascript.Order.ATOMIC);
const value_value = javascript.javascriptGenerator.valueToCode(this, 'VALUE', javascript.Order.ATOMIC);
const code = `(${value_entity})["${dropdown_prop}"] = ((${value_value}) ? 1 : 0)`;
return code;
}



const entity_get_switch = {
init: function () {
this.appendDummyInput('PROP')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(new Blockly.FieldDropdown(ENTITY_BOOLEAN_PROPS), 'PROP');
this.appendValueInput('ENTITY')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField('of entity');
this.setInputsInline(true)
this.setOutput(true, 'Boolean');
this.setTooltip('Sets a boolean property of the entity.');
this.setHelpUrl('');
this.setColour(30);
}
};
Blockly.common.defineBlocks({ entity_get_switch: entity_get_switch });
javascript.javascriptGenerator.forBlock['entity_get_switch'] = function () {
const dropdown_prop = this.getFieldValue('PROP');
const value_entity = javascript.javascriptGenerator.valueToCode(this, 'ENTITY', javascript.Order.ATOMIC);
const code = `((${value_entity})["${dropdown_prop}"] ? true : false)`;
return [code, javascript.Order.NONE];
}
2 changes: 1 addition & 1 deletion blocks/Vec3.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Blockly.common.defineBlocks({ vec3_getxyz: vec3_getxyz });


javascript.javascriptGenerator.forBlock['vec3_getxyz'] = function () {
const dropdown_tab = block.getFieldValue('TAB');
const dropdown_tab = this.getFieldValue('TAB');
const value_value = javascript.javascriptGenerator.valueToCode(this, 'VALUE', javascript.Order.ATOMIC);

const code = `(${value_value})["${dropdown_tab}"]`;
Expand Down
5 changes: 5 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,11 @@
</category>
<category name="Entity (C)" colour="#ff8811">
<block type="entity_set_position"> </block>
<block type="entity_set_position_xyz"> </block>
<block type="entity_get_prop"> </block>
<block type="entity_set_prop"> </block>
<block type="entity_get_switch"> </block>
<block type="entity_set_switch"> </block>
</category>
</xml>
</head>
Expand Down
3 changes: 1 addition & 2 deletions libs/blockly/blockly_dev_tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,12 +484,11 @@ function blocklyDeveloperTools() {
if (element.hasAttribute("data-id")) {
blockId = element.getAttribute("data-id");
internalBlock = workspace.getBlockById(blockId);
debugger;
var code;
try {
code = javascript.javascriptGenerator.blockToCode(internalBlock)
} catch (error) {
code = "Error occurred while previewing code.";
code = "ERR: " + error;
}
if (devWrapper.querySelector(".blockly-dev-tools-code-preview")) {
devWrapper.querySelectorAll(".blockly-dev-tools-code-preview").forEach(x=>x.remove());
Expand Down

0 comments on commit 3512e35

Please sign in to comment.