diff --git a/blocks/Blocks.js b/blocks/Blocks.js
index 73df5c8..f425607 100644
--- a/blocks/Blocks.js
+++ b/blocks/Blocks.js
@@ -7,7 +7,7 @@ const handle_BlockConstructor = {
.setAlign(Blockly.inputs.Align.LEFT)
.appendField('Block Constructor Handler');
this.appendStatementInput('CODE');
- this.setTooltip('');
+ this.setTooltip('Runs when the block type is initialised.\nNo return value expected.');
this.setHelpUrl('');
this.setColour(0);
}
@@ -16,7 +16,7 @@ Blockly.common.defineBlocks({ handle_BlockConstructor: handle_BlockConstructor }
javascript.javascriptGenerator.forBlock['handle_BlockConstructor'] = function (block) {
const statement = javascript.javascriptGenerator.statementToCode(this, 'CODE');
- return {code: statement, args: []};
+ return { code: statement, args: [] };
}
@@ -94,7 +94,7 @@ const handle_BlockBreak = {
.appendField(new Blockly.FieldVariable('position'), 'BLOCKPOS');
this.appendStatementInput('CODE');
this.setInputsInline(false)
- this.setTooltip('');
+ this.setTooltip('Runs when the block is removed from the world.\nNo return value expected.');
this.setHelpUrl('');
this.setColour(0);
}
@@ -121,7 +121,7 @@ const handle_BlockAdded = {
.appendField(new Blockly.FieldVariable('position'), 'BLOCKPOS');
this.appendStatementInput('CODE');
this.setInputsInline(false)
- this.setTooltip('');
+ this.setTooltip('Runs when the block is added to the world.\nNo return value expected.');
this.setHelpUrl('');
this.setColour(0);
}
@@ -148,7 +148,7 @@ const handle_BlockNeighbourChange = {
.appendField(new Blockly.FieldVariable('position'), 'BLOCKPOS');
this.appendStatementInput('CODE');
this.setInputsInline(false)
- this.setTooltip('');
+ this.setTooltip('Runs when a block\'s neighbor is changed.\nNo return value expected.');
this.setHelpUrl('');
this.setColour(0);
}
@@ -160,4 +160,130 @@ javascript.javascriptGenerator.forBlock['handle_BlockNeighbourChange'] = functio
const variable_blockpos = javascript.javascriptGenerator.getVariableName(this.getFieldValue('BLOCKPOS'));
const statement = javascript.javascriptGenerator.statementToCode(this, 'CODE');
return { code: statement, args: [variable_world, variable_blockpos, "$$blockstate"] };
+}
+
+
+
+const handle_BlockBrokenByPlayer = {
+ init: function () {
+ this.appendDummyInput('ID')
+ .appendField('Handler ID:')
+ .appendField(new Blockly.FieldTextInput('block broken by player 1'), 'ID');
+ this.appendDummyInput('')
+ .appendField('Block Broken By Player Handler with:')
+ .appendField(new Blockly.FieldVariable('world'), 'WORLD')
+ .appendField(new Blockly.FieldVariable('position'), 'BLOCKPOS');
+ this.appendStatementInput('CODE');
+ this.setInputsInline(false)
+ this.setTooltip('Runs when a block is broken by a player.\nNo return value expected.');
+ this.setHelpUrl('');
+ this.setColour(0);
+ }
+};
+Blockly.common.defineBlocks({ handle_BlockBrokenByPlayer: handle_BlockBrokenByPlayer });
+
+javascript.javascriptGenerator.forBlock['handle_BlockBrokenByPlayer'] = function () {
+ const variable_world = javascript.javascriptGenerator.getVariableName(this.getFieldValue('WORLD'));
+ const variable_blockpos = javascript.javascriptGenerator.getVariableName(this.getFieldValue('BLOCKPOS'));
+ const statement = javascript.javascriptGenerator.statementToCode(this, 'CODE');
+ return { code: statement, args: [variable_world, variable_blockpos, "$$blockstate"] };
+}
+
+
+const handle_BlockUpdateTick = {
+ init: function () {
+ this.appendDummyInput('ID')
+ .appendField('Handler ID:')
+ .appendField(new Blockly.FieldTextInput('block update tick 1'), 'ID');
+ this.appendDummyInput('')
+ .appendField('Block Update Tick Handler with:')
+ .appendField(new Blockly.FieldVariable('world'), 'WORLD')
+ .appendField(new Blockly.FieldVariable('position'), 'BLOCKPOS');
+ this.appendStatementInput('CODE');
+ this.setInputsInline(false)
+ this.setTooltip('Runs when a block is ticked.\nNo return value expected.');
+ this.setHelpUrl('');
+ this.setColour(0);
+ }
+};
+Blockly.common.defineBlocks({ handle_BlockUpdateTick: handle_BlockUpdateTick });
+
+javascript.javascriptGenerator.forBlock['handle_BlockUpdateTick'] = function () {
+ const variable_world = javascript.javascriptGenerator.getVariableName(this.getFieldValue('WORLD'));
+ const variable_blockpos = javascript.javascriptGenerator.getVariableName(this.getFieldValue('BLOCKPOS'));
+ const statement = javascript.javascriptGenerator.statementToCode(this, 'CODE');
+ return { code: statement, args: [variable_world, variable_blockpos, "$$blockstate", "$$random"] };
+}
+
+
+
+
+const blocks_boundingbox = {
+ init: function () {
+ this.appendDummyInput('MIN')
+ .setAlign(Blockly.inputs.Align.RIGHT)
+ .appendField('Set block bounds to min:')
+ .appendField(new Blockly.FieldNumber(0), 'MINX')
+ .appendField(new Blockly.FieldNumber(0), 'MINY')
+ .appendField(new Blockly.FieldNumber(0), 'MINZ');
+ this.appendDummyInput('MAX')
+ .setAlign(Blockly.inputs.Align.RIGHT)
+ .appendField('max:')
+ .appendField(new Blockly.FieldNumber(1), 'MAXX')
+ .appendField(new Blockly.FieldNumber(1), 'MAXY')
+ .appendField(new Blockly.FieldNumber(1), 'MAXZ');
+ this.setInputsInline(false)
+ this.setPreviousStatement(true, null);
+ this.setNextStatement(true, null);
+ this.setTooltip('Sets the block\'s bounding box');
+ this.setHelpUrl('');
+ this.setColour(0);
+ }
+};
+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 code = `this.$setBlockBounds(${number_minx}, ${number_miny}, ${number_minz}, ${number_maxx}, ${number_maxy}, ${number_maxz})`;
+ return code;
+}
+
+
+
+const blocks_creativetab = {
+ init: function () {
+ this.appendDummyInput('TAB')
+ .setAlign(Blockly.inputs.Align.RIGHT)
+ .appendField('Set block creative tab to')
+ .appendField(new Blockly.FieldDropdown([
+ ["tabBlock", "tabBlock"],
+ ["tabDecorations", "tabDecorations"],
+ ["tabRedstone", "tabRedstone"],
+ ["tabTransport", "tabTransport"],
+ ["tabMisc", "tabMisc"],
+ ["tabAllSearch", "tabAllSearch"],
+ ["tabFood", "tabFood"],
+ ["tabTools", "tabTools"],
+ ["tabCombat", "tabCombat"],
+ ["tabBrewing", "tabBrewing"],
+ ["tabMaterials", "tabMaterials"],
+ ["tabInventory", "tabInventory"]
+ ]), 'TAB');
+ this.setInputsInline(false)
+ this.setPreviousStatement(true, null);
+ this.setNextStatement(true, null);
+ this.setTooltip('Set the creative tab of the block');
+ this.setHelpUrl('');
+ this.setColour(0);
+ }
+};
+Blockly.common.defineBlocks({ blocks_creativetab: blocks_creativetab });
+javascript.javascriptGenerator.forBlock['blocks_creativetab'] = function() {
+ const dropdown_tab = this.getFieldValue('TAB');
+ const code = `this.$setCreativeTab(ModAPI.reflect.getClassById("net.minecraft.creativetab.CreativeTabs").staticVariables.${dropdown_tab});`;
+ return code;
}
\ No newline at end of file
diff --git a/blocks/ReturnBlock.js b/blocks/ReturnBlock.js
index b8eefeb..a54b10d 100644
--- a/blocks/ReturnBlock.js
+++ b/blocks/ReturnBlock.js
@@ -1,3 +1,20 @@
+const local_this = {
+ init: function () {
+ this.appendDummyInput('NAME')
+ .appendField('this');
+ this.setInputsInline(false)
+ this.setOutput(true, null);
+ this.setTooltip('The object the handler is running on.');
+ this.setHelpUrl('');
+ this.setColour(330);
+ }
+};
+Blockly.common.defineBlocks({ local_this: local_this });
+javascript.javascriptGenerator.forBlock['local_this'] = function () {
+ return 'this';
+}
+
+
const proc_return = {
init: function () {
this.appendDummyInput('NAME')
diff --git a/index.html b/index.html
index 7798886..3b6f63a 100644
--- a/index.html
+++ b/index.html
@@ -337,6 +337,7 @@
+
@@ -365,19 +366,19 @@
-
+
-
-
-
- TRUE
-
-
-
-
+
+
+
+
+
+
+
+
diff --git a/primitives/AdvancedBlock.js b/primitives/AdvancedBlock.js
index 0bc6aba..adfe966 100644
--- a/primitives/AdvancedBlock.js
+++ b/primitives/AdvancedBlock.js
@@ -12,6 +12,9 @@ PRIMITIVES["block_advanced"] = {
Break: VALUE_ENUMS.ABSTRACT_HANDLER + "BlockBreak",
Added: VALUE_ENUMS.ABSTRACT_HANDLER + "BlockAdded",
NeighborChange: VALUE_ENUMS.ABSTRACT_HANDLER + "NeighborChange",
+ Break: VALUE_ENUMS.ABSTRACT_HANDLER + "BlockBreak",
+ BrokenByPlayer: VALUE_ENUMS.ABSTRACT_HANDLER + "BlockBrokenByPlayer",
+ UpdateTick: VALUE_ENUMS.ABSTRACT_HANDLER + "BlockUpdateTick",
},
asJavaScript: function () {
console.log(this);
@@ -19,6 +22,8 @@ PRIMITIVES["block_advanced"] = {
var breakHandler = getHandlerCode("BlockBreak", this.tags.Break, ["$$world", "$$blockpos", "$$blockstate"]);
var addedHandler = getHandlerCode("BlockAdded", this.tags.Added, ["$$world", "$$blockpos", "$$blockstate"]);
var neighborHandler = getHandlerCode("NeighborChange", this.tags.NeighborChange, ["$$world", "$$blockpos", "$$blockstate"]);
+ var brokenByPlayerHandler = getHandlerCode("BrokenByPlayer", this.tags.BrokenByPlayer, ["$$world", "$$blockpos", "$$blockstate"]);
+ var updateTickHandler = getHandlerCode("UpdateTick", this.tags.UpdateTick, ["$$world", "$$blockpos", "$$blockstate", "$$random"]);
return `(function AdvancedBlockDatablock() {
const $$blockTexture = "${this.tags.texture}";
@@ -32,6 +37,8 @@ PRIMITIVES["block_advanced"] = {
var $$breakBlockMethod = $$blockClass.methods.breakBlock.method;
var $$onBlockAddedMethod = $$blockClass.methods.onBlockAdded.method;
var $$onNeighborBlockChangeMethod = $$blockClass.methods.onNeighborBlockChange.method;
+ var $$onBlockDestroyedByPlayerMethod = $$blockClass.methods.onBlockDestroyedByPlayer.method;
+ var $$updateTickMethod = $$blockClass.methods.updateTick.method;
var $$nmb_AdvancedBlock = function $$nmb_AdvancedBlock() {
$$blockSuper(this, ModAPI.materials.${this.tags.material}.getRef());
@@ -57,6 +64,14 @@ PRIMITIVES["block_advanced"] = {
${neighborHandler.code};
return $$onNeighborBlockChangeMethod(this, ${neighborHandler.args.join(", ")});
}
+ $$nmb_AdvancedBlock.prototype.$onBlockDestroyedByPlayer = function (${brokenByPlayerHandler.args.join(", ")}) {
+ ${brokenByPlayerHandler.code};
+ return $$onBlockDestroyedByPlayerMethod(this, ${brokenByPlayerHandler.args.join(", ")});
+ }
+ $$nmb_AdvancedBlock.prototype.$updateTick = function (${updateTickHandler.args.join(", ")}) {
+ ${updateTickHandler.code};
+ return $$updateTickMethod(this, ${updateTickHandler.args.join(", ")});
+ }
function $$internal_reg() {
var $$cblock = (new $$nmb_AdvancedBlock()).$setUnlocalizedName(
diff --git a/stylesheet.css b/stylesheet.css
index 31aeb62..b106c4e 100644
--- a/stylesheet.css
+++ b/stylesheet.css
@@ -105,7 +105,7 @@ td {
}
#propnav {
width: 100%;
- min-height: 2rem;
+ min-height: 5rem;
height: 4rem;
max-height: 80vh;
margin-bottom: 1rem;