Skip to content

Commit

Permalink
Add stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
ZXMushroom63 committed Dec 15, 2024
1 parent e260cc3 commit 604f6dd
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 15 deletions.
136 changes: 131 additions & 5 deletions blocks/Blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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: [] };
}


Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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;
}
17 changes: 17 additions & 0 deletions blocks/ReturnBlock.js
Original file line number Diff line number Diff line change
@@ -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')
Expand Down
19 changes: 10 additions & 9 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@
</category>
<sep></sep>
<category name="Return" colour="#008855">
<block type="local_this"> </block>
<block type="proc_return"> </block>
<block type="proc_returnvalue">
<value name="VALUE">
Expand Down Expand Up @@ -365,19 +366,19 @@
<category name="Variables" colour="#a55b80" custom="VARIABLE"></category>
<!-- <category name="Functions" colour="#995ba5" custom="PROCEDURE"></category> -->
<sep></sep>
<category name="Blocks" colour="#ff00ff">
<category name="Blocks (H)" colour="#ff00ff">
<block type="handle_BlockConstructor"> </block>
<block type="blocks_blockproperty">
<value name="VALUE">
<block type="logic_boolean">
<field name="BOOL">TRUE</field>
</block>
</value>
</block>
<block type="blocks_blockswitch"> </block>
<block type="handle_BlockBreak"> </block>
<block type="handle_BlockAdded"> </block>
<block type="handle_BlockNeighbourChange"> </block>
<block type="handle_BlockBrokenByPlayer"> </block>
<block type="handle_BlockUpdateTick"> </block>
</category>
<category name="Blocks (C)" colour="#ff00ff">
<block type="blocks_blockproperty"> </block>
<block type="blocks_blockswitch"> </block>
<block type="blocks_boundingbox"> </block>
<block type="blocks_creativetab"> </block>
</category>
<category name="World" colour="#22aabb">
<block type="world_explosion"> </block>
Expand Down
15 changes: 15 additions & 0 deletions primitives/AdvancedBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@ 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);
var constructorHandler = getHandlerCode("BlockConstructor", this.tags.Constructor, []);
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}";
Expand All @@ -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());
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion stylesheet.css
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ td {
}
#propnav {
width: 100%;
min-height: 2rem;
min-height: 5rem;
height: 4rem;
max-height: 80vh;
margin-bottom: 1rem;
Expand Down

0 comments on commit 604f6dd

Please sign in to comment.