Skip to content

Commit

Permalink
items coming soon!
Browse files Browse the repository at this point in the history
  • Loading branch information
ZXMushroom63 committed Dec 20, 2024
1 parent 7b4ce42 commit ff2a395
Show file tree
Hide file tree
Showing 10 changed files with 253 additions and 18 deletions.
12 changes: 6 additions & 6 deletions blocks/Blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const blocks_blockswitch = {
['full block', 'fullBlock'],
['translucent', 'translucent'],
['use neighbor brightness', 'useNeighborBrightness'],
['needs random tick', 'blockHardness']
['needs random tick', 'needsRandomTick']
]), 'PROPERTY');
this.appendDummyInput('VALUE')
.setAlign(Blockly.inputs.Align.CENTRE)
Expand Down Expand Up @@ -190,13 +190,13 @@ javascript.javascriptGenerator.forBlock['handle_BlockBrokenByPlayer'] = function
}


const handle_BlockUpdateTick = {
const handle_BlockRandomTick = {
init: function () {
this.appendDummyInput('ID')
.appendField('Handler ID:')
.appendField(new Blockly.FieldTextInput('block update tick 1'), 'ID');
.appendField(new Blockly.FieldTextInput('block random tick 1'), 'ID');
this.appendDummyInput('')
.appendField('Block Update Tick Handler with:')
.appendField('Block Random Tick Handler with:')
.appendField(new Blockly.FieldVariable('world'), 'WORLD')
.appendField(new Blockly.FieldVariable('position'), 'BLOCKPOS');
this.appendStatementInput('CODE');
Expand All @@ -206,9 +206,9 @@ const handle_BlockUpdateTick = {
this.setColour(0);
}
};
Blockly.common.defineBlocks({ handle_BlockUpdateTick: handle_BlockUpdateTick });
Blockly.common.defineBlocks({ handle_BlockRandomTick: handle_BlockRandomTick });

javascript.javascriptGenerator.forBlock['handle_BlockUpdateTick'] = function () {
javascript.javascriptGenerator.forBlock['handle_BlockRandomTick'] = 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');
Expand Down
203 changes: 203 additions & 0 deletions blocks/ItemStack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
const itemstack_stacksize = {
init: function () {
this.appendValueInput('ITEMSTACK')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField('get itemstack stack size');
this.setInputsInline(true)
this.setOutput(true, 'Number');
this.setTooltip('Gets the stacksize of an ItemStack');
this.setHelpUrl('');
this.setColour(165);
}
};
Blockly.common.defineBlocks({ itemstack_stacksize: itemstack_stacksize });

javascript.javascriptGenerator.forBlock['itemstack_stacksize'] = function () {
const value_itemstack = javascript.javascriptGenerator.valueToCode(this, 'ITEMSTACK', javascript.Order.ATOMIC);
const code = `(${value_itemstack}).$stackSize`;
return [code, javascript.Order.NONE];
}



const itemstack_setstacksize = {
init: function () {
this.appendValueInput('ITEMSTACK')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField('set itemstack stack size');
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 the stacksize of an ItemStack');
this.setHelpUrl('');
this.setColour(165);
}
};
Blockly.common.defineBlocks({ itemstack_setstacksize: itemstack_setstacksize });

javascript.javascriptGenerator.forBlock['itemstack_setstacksize'] = function () {
const value_itemstack = javascript.javascriptGenerator.valueToCode(this, 'ITEMSTACK', javascript.Order.ATOMIC);
const value_value = javascript.javascriptGenerator.valueToCode(this, 'VALUE', javascript.Order.ATOMIC);
const code = `(${value_itemstack}).$stackSize = (${value_value})`;
return code;
}


const itemstack_displayname = {
init: function () {
this.appendValueInput('ITEMSTACK')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField('get itemstack display name');
this.setInputsInline(true)
this.setOutput(true, 'String');
this.setTooltip('Gets the display name of an ItemStack');
this.setHelpUrl('');
this.setColour(165);
}
};
Blockly.common.defineBlocks({ itemstack_displayname: itemstack_displayname });

javascript.javascriptGenerator.forBlock['itemstack_displayname'] = function () {
const value_itemstack = javascript.javascriptGenerator.valueToCode(this, 'ITEMSTACK', javascript.Order.ATOMIC);
const code = `ModAPI.util.ustr((${value_itemstack}).$getDisplayName())`;
return [code, javascript.Order.NONE];
}


const itemstack_setdisplayname = {
init: function () {
this.appendValueInput('ITEMSTACK')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField('set itemstack display name');
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 the display name of an ItemStack');
this.setHelpUrl('');
this.setColour(165);
}
};
Blockly.common.defineBlocks({ itemstack_setdisplayname: itemstack_setdisplayname });

javascript.javascriptGenerator.forBlock['itemstack_setdisplayname'] = function () {
const value_itemstack = javascript.javascriptGenerator.valueToCode(this, 'ITEMSTACK', javascript.Order.ATOMIC);
const value_value = javascript.javascriptGenerator.valueToCode(this, 'VALUE', javascript.Order.ATOMIC);
const code = `(${value_itemstack}).$setStackDisplayName(ModAPI.util.str(${value_value}))`;
return code;
}


const itemstack_enchant = {
init: function () {
this.appendValueInput('ITEMSTACK')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField('enchant itemstack');
this.appendDummyInput('ENCHANTMENT')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField('with enchantment')
.appendField(new Blockly.FieldDropdown([
["protection", "protection"],
["fireProtection", "fireProtection"],
["featherFalling", "featherFalling"],
["blastProtection", "blastProtection"],
["projectileProtection", "projectileProtection"],
["respiration", "respiration"],
["aquaAffinity", "aquaAffinity"],
["thorns", "thorns"],
["depthStrider", "depthStrider"],
["sharpness", "sharpness"],
["smite", "smite"],
["baneOfArthropods", "baneOfArthropods"],
["knockback", "knockback"],
["fireAspect", "fireAspect"],
["looting", "looting"],
["efficiency", "efficiency"],
["silkTouch", "silkTouch"],
["unbreaking", "unbreaking"],
["fortune", "fortune"],
["power", "power"],
["punch", "punch"],
["flame", "flame"],
["infinity", "infinity"],
["luckOfTheSea", "luckOfTheSea"],
["lure", "lure"]
]), 'ENCHANTMENT');
this.appendValueInput('LEVEL')
.setAlign(Blockly.inputs.Align.RIGHT)
.setCheck('Number')
.appendField('at level');
this.setInputsInline(true)
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip('Adds an enchantment to an ItemStack');
this.setHelpUrl('');
this.setColour(165);
}
};
Blockly.common.defineBlocks({ itemstack_enchant: itemstack_enchant });

javascript.javascriptGenerator.forBlock['itemstack_enchant'] = function () {
const value_itemstack = javascript.javascriptGenerator.valueToCode(this, 'ITEMSTACK', javascript.Order.ATOMIC);
const dropdown_enchantment = this.getFieldValue('ENCHANTMENT');
const value_level = javascript.javascriptGenerator.valueToCode(this, 'LEVEL', javascript.Order.ATOMIC);
const code = `(${value_itemstack}).$addEnchantment(ModAPI.enchantments["${dropdown_enchantment}"], (${value_level}))`;
return code;
}



const itemstack_repaircost = {
init: function () {
this.appendValueInput('ITEMSTACK')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField('get itemstack repair cost');
this.setInputsInline(true)
this.setOutput(true, 'Number');
this.setTooltip('Gets the repair cost of an ItemStack');
this.setHelpUrl('');
this.setColour(165);
}
};
Blockly.common.defineBlocks({ itemstack_repaircost: itemstack_repaircost });

javascript.javascriptGenerator.forBlock['itemstack_repaircost'] = function () {
const value_itemstack = javascript.javascriptGenerator.valueToCode(this, 'ITEMSTACK', javascript.Order.ATOMIC);
const code = `(${value_itemstack}).$getRepairCost()`;
return [code, javascript.Order.NONE];
}



const itemstack_setrepaircost = {
init: function () {
this.appendValueInput('ITEMSTACK')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField('set itemstack repair cost');
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 the repair cost of an ItemStack');
this.setHelpUrl('');
this.setColour(165);
}
};
Blockly.common.defineBlocks({ itemstack_setrepaircost: itemstack_setrepaircost });

javascript.javascriptGenerator.forBlock['itemstack_setrepaircost'] = function () {
const value_itemstack = javascript.javascriptGenerator.valueToCode(this, 'ITEMSTACK', javascript.Order.ATOMIC);
const value_value = javascript.javascriptGenerator.valueToCode(this, 'VALUE', javascript.Order.ATOMIC);
const code = `(${value_itemstack}).$setRepairCost(${value_value})`;
return code;
}
2 changes: 1 addition & 1 deletion blocks/World.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Blockly.common.defineBlocks({ world_get_loaded_entities: world_get_loaded_entiti

javascript.javascriptGenerator.forBlock['world_get_loaded_entities'] = function () {
const value_world = javascript.javascriptGenerator.valueToCode(this, 'WORLD', javascript.Order.ATOMIC);
const code = `(${value_world}).loadedEntityList.toArray1().getRef().data`;
const code = `(${value_world}).$loadedEntityList.$toArray1().data`;
return [code, javascript.Order.NONE];
}

Expand Down
4 changes: 4 additions & 0 deletions functions.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Math.clamp = function clamp(x, min, max) {
return Math.max(Math.min(x, max), min);
}

const codeGrabberRegex = /(?<=function \(\) {)[\s\S]+(?=}$)/gm; //regex to get the contents of a stringified function
const FUNCTIONS = {};

Expand Down
12 changes: 10 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@
<block type="handle_BlockAdded"> </block>
<block type="handle_BlockNeighbourChange"> </block>
<block type="handle_BlockBrokenByPlayer"> </block>
<block type="handle_BlockUpdateTick"> </block>
<block type="handle_BlockRandomTick"> </block>
<block type="handle_BlockEntityCollision"> </block>
</category>
<category name="Blocks (C)" colour="#dd11dd">
Expand All @@ -390,7 +390,13 @@

</category>
<category name="ItemStack (C)" colour="#44eebb">

<block type="itemstack_stacksize"> </block>
<block type="itemstack_setstacksize"> </block>
<block type="itemstack_displayname"> </block>
<block type="itemstack_setdisplayname"> </block>
<block type="itemstack_enchant"> </block>
<block type="itemstack_repaircost"> </block>
<block type="itemstack_setrepaircost"> </block>
</category>
<category name="BlockPos (C)" colour="#6633cc">
<block type="blockpos_fromxyz"> </block>
Expand Down Expand Up @@ -480,6 +486,7 @@ <h4>Dirt Block</h4>

<!-- Additional blocks -->
<script src="blocks/World.js"></script>
<script src="blocks/ItemStack.js"></script>
<script src="blocks/Blocks.js"></script>
<script src="blocks/Entity.js"></script>
<script src="blocks/Vec3.js"></script>
Expand All @@ -494,6 +501,7 @@ <h4>Dirt Block</h4>
<script src="primitives/Metadata.js"></script>
<script src="primitives/Icon.js"></script>
<script src="primitives/AdvancedBlock.js"></script>
<script src="primitives/Item.js"></script>

<!-- Web App GUI and Engine -->
<script src="functions.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion libs/blockly/blockly_compressed.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ff2a395

Please sign in to comment.