Skip to content

Commit

Permalink
bugfix, more entity operators
Browse files Browse the repository at this point in the history
  • Loading branch information
ZXMushroom63 committed Dec 17, 2024
1 parent 3512e35 commit dfe213c
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 1 deletion.
124 changes: 124 additions & 0 deletions blocks/Entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,128 @@ javascript.javascriptGenerator.forBlock['entity_get_switch'] = function () {
const value_entity = javascript.javascriptGenerator.valueToCode(this, 'ENTITY', javascript.Order.ATOMIC);
const code = `((${value_entity})["${dropdown_prop}"] ? true : false)`;
return [code, javascript.Order.NONE];
}



const entity_get_world = {
init: function () {
this.appendValueInput('ENTITY')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField('get world of entity');
this.setInputsInline(true)
this.setOutput(true, null);
this.setTooltip('Gets the entity\'s world object.');
this.setHelpUrl('');
this.setColour(30);
}
};
Blockly.common.defineBlocks({ entity_get_world: entity_get_world });

javascript.javascriptGenerator.forBlock['entity_get_world'] = function () {
const value_entity = javascript.javascriptGenerator.valueToCode(this, 'ENTITY', javascript.Order.ATOMIC);
const code = `(${value_entity}).$worldObj`;
return [code, javascript.Order.NONE];
}



const entity_get_position = {
init: function () {
this.appendValueInput('ENTITY')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField('get position of entity');
this.appendDummyInput('AS')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField('as')
.appendField(new Blockly.FieldDropdown([
['BlockPos', '$getPosition'],
['Vec3', '$getPositionVector']
]), 'AS');
this.setInputsInline(true)
this.setOutput(true, null);
this.setTooltip('Gets the entity\'s position object.');
this.setHelpUrl('');
this.setColour(30);
}
};
Blockly.common.defineBlocks({ entity_get_position: entity_get_position });
javascript.javascriptGenerator.forBlock['entity_get_position'] = function () {
const value_entity = javascript.javascriptGenerator.valueToCode(this, 'ENTITY', javascript.Order.ATOMIC);
const dropdown_as = this.getFieldValue('AS');
const code = `(${value_entity})["${dropdown_as}"]()`;
return [code, javascript.Order.NONE];
}



const entity_distance = {
init: function () {
this.appendValueInput('A')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField('distance from entity');
this.appendValueInput('B')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField('to entity');
this.setInputsInline(true)
this.setOutput(true, 'Number');
this.setTooltip('Get the distance between two entities');
this.setHelpUrl('');
this.setColour(30);
}
};
Blockly.common.defineBlocks({ entity_distance: entity_distance });
javascript.javascriptGenerator.forBlock['entity_distance'] = function () {
const value_a = javascript.javascriptGenerator.valueToCode(this, 'A', javascript.Order.ATOMIC);
const value_b = javascript.javascriptGenerator.valueToCode(this, 'B', javascript.Order.ATOMIC);
const code = `(${value_a}).$getDistanceToEntity(${value_b})`;
return [code, javascript.Order.NONE];
}



const entity_distance_vec3 = {
init: function () {
this.appendValueInput('A')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField('distance from entity');
this.appendValueInput('B')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField('to Vec3');
this.setInputsInline(true)
this.setOutput(true, 'Number');
this.setTooltip('Get the distance from an entity to a Vec3 position');
this.setHelpUrl('');
this.setColour(30);
}
};
Blockly.common.defineBlocks({ entity_distance_vec3: entity_distance_vec3 });

javascript.javascriptGenerator.forBlock['entity_distance_vec3'] = function () {
const value_a = javascript.javascriptGenerator.valueToCode(this, 'A', javascript.Order.ATOMIC);
const value_b = javascript.javascriptGenerator.valueToCode(this, 'B', javascript.Order.ATOMIC);
const code = `(($$efb2_arg_a, $$efb2_arg_b)=>$$efb2_arg_a.$getDistance($$efb2_arg_b.$x,$$efb2_arg_b.$y,$$efb2_arg_b.$z))(${value_a}, ${value_b})`;
return [code, javascript.Order.NONE];
}



const entity_get_lookvec = {
init: function () {
this.appendValueInput('ENTITY')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField('get look vector of entity');
this.setInputsInline(true)
this.setOutput(true, 'Number');
this.setTooltip('Get\'s an entity\'s look vector (Vec3)');
this.setHelpUrl('');
this.setColour(30);
}
};
Blockly.common.defineBlocks({ entity_get_lookvec: entity_get_lookvec });

javascript.javascriptGenerator.forBlock['entity_get_lookvec'] = function () {
const value_entity = javascript.javascriptGenerator.valueToCode(this, 'ENTITY', javascript.Order.ATOMIC);
const code = `(${value_entity}).$getLook(1)`;
return [code, javascript.Order.NONE];
}
2 changes: 1 addition & 1 deletion blocks/World.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const world_get_loaded_entities = {
Blockly.common.defineBlocks({ world_get_loaded_entities: world_get_loaded_entities });

javascript.javascriptGenerator.forBlock['world_get_loaded_entities'] = function () {
const value_world = generator.valueToCode(this, 'WORLD', javascript.Order.ATOMIC);
const value_world = javascript.javascriptGenerator.valueToCode(this, 'WORLD', javascript.Order.ATOMIC);
const code = `(${value_world}).loadedEntityList.toArray1().getRef().data`;
return [code, javascript.Order.NONE];
}
Expand Down
5 changes: 5 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,11 @@
<block type="entity_set_prop"> </block>
<block type="entity_get_switch"> </block>
<block type="entity_set_switch"> </block>
<block type="entity_get_world"> </block>
<block type="entity_get_position"> </block>
<block type="entity_distance"> </block>
<block type="entity_distance_vec3"> </block>
<block type="entity_get_lookvec"> </block>
</category>
</xml>
</head>
Expand Down
1 change: 1 addition & 0 deletions stylesheet.css
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ td {
overflow-y: scroll;
border-bottom: 1px solid white;
resize: vertical;
overflow-x: visible;
}
.datablock.selected {
outline: 4px solid rgba(255, 255, 255, 0.4);
Expand Down

0 comments on commit dfe213c

Please sign in to comment.