From ff2a3957236b01e202ffd45827ffc6c2f11f7f14 Mon Sep 17 00:00:00 2001 From: ZXMushroom63 Date: Fri, 20 Dec 2024 16:06:08 +0800 Subject: [PATCH] items coming soon! --- blocks/Blocks.js | 12 +- blocks/ItemStack.js | 203 ++++++++++++++++++++++++++ blocks/World.js | 2 +- functions.js | 4 + index.html | 12 +- libs/blockly/blockly_compressed.js | 2 +- libs/blockly/javascript_compressed.js | 2 +- primitives/AdvancedBlock.js | 17 ++- primitives/Item.js | 13 ++ serialise.js | 4 + 10 files changed, 253 insertions(+), 18 deletions(-) create mode 100644 blocks/ItemStack.js create mode 100644 primitives/Item.js diff --git a/blocks/Blocks.js b/blocks/Blocks.js index efb0a06..ec8ac08 100644 --- a/blocks/Blocks.js +++ b/blocks/Blocks.js @@ -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) @@ -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'); @@ -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'); diff --git a/blocks/ItemStack.js b/blocks/ItemStack.js new file mode 100644 index 0000000..8773474 --- /dev/null +++ b/blocks/ItemStack.js @@ -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; +} \ No newline at end of file diff --git a/blocks/World.js b/blocks/World.js index 26cb68a..5bc2023 100644 --- a/blocks/World.js +++ b/blocks/World.js @@ -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]; } diff --git a/functions.js b/functions.js index d60c1b5..2aacb9c 100644 --- a/functions.js +++ b/functions.js @@ -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 = {}; diff --git a/index.html b/index.html index 93065ed..5c613e0 100644 --- a/index.html +++ b/index.html @@ -374,7 +374,7 @@ - + @@ -390,7 +390,13 @@ - + + + + + + + @@ -480,6 +486,7 @@

Dirt Block

+ @@ -494,6 +501,7 @@

Dirt Block

+ diff --git a/libs/blockly/blockly_compressed.js b/libs/blockly/blockly_compressed.js index 36fe43c..415e681 100644 --- a/libs/blockly/blockly_compressed.js +++ b/libs/blockly/blockly_compressed.js @@ -582,7 +582,7 @@ this.workspace.zoomCenter(a);this.fireZoomEvent();clearTouchIdentifier$$module$b "pointerdown",null,this.resetZoom.bind(this)))}resetZoom(a){this.workspace.markFocused();const b=Math.log(this.workspace.options.zoomOptions.startScale/this.workspace.scale)/Math.log(this.workspace.options.zoomOptions.scaleSpeed);this.workspace.beginCanvasTransition();this.workspace.zoomCenter(b);this.workspace.scrollCenter();setTimeout(this.workspace.endCanvasTransition.bind(this.workspace),500);this.fireZoomEvent();clearTouchIdentifier$$module$build$src$core$touch();a.stopPropagation();a.preventDefault()}fireZoomEvent(){const a= new (get$$module$build$src$core$events$utils(CLICK$$module$build$src$core$events$utils))(null,this.workspace.id,"zoom_controls");fire$$module$build$src$core$events$utils(a)}};register$$module$build$src$core$css("\n.blocklyZoom>image, .blocklyZoom>svg>image {\n opacity: .4;\n}\n\n.blocklyZoom>image:hover, .blocklyZoom>svg>image:hover {\n opacity: .6;\n}\n\n.blocklyZoom>image:active, .blocklyZoom>svg>image:active {\n opacity: .8;\n}\n");var module$build$src$core$zoom_controls={}; module$build$src$core$zoom_controls.ZoomControls=ZoomControls$$module$build$src$core$zoom_controls;var COLLAPSED_INPUT_NAME$$module$build$src$core$constants="_TEMP_COLLAPSED_INPUT",COLLAPSED_FIELD_NAME$$module$build$src$core$constants="_TEMP_COLLAPSED_FIELD",MANUALLY_DISABLED$$module$build$src$core$constants="MANUALLY_DISABLED",module$build$src$core$constants={COLLAPSED_FIELD_NAME:COLLAPSED_FIELD_NAME$$module$build$src$core$constants,COLLAPSED_INPUT_NAME:COLLAPSED_INPUT_NAME$$module$build$src$core$constants,MANUALLY_DISABLED:MANUALLY_DISABLED$$module$build$src$core$constants};var IconType$$module$build$src$core$icons$icon_types=class{constructor(a){this.name=a}toString(){return this.name}equals(a){return this.name===a.toString()}};IconType$$module$build$src$core$icons$icon_types.MUTATOR=new IconType$$module$build$src$core$icons$icon_types("mutator");IconType$$module$build$src$core$icons$icon_types.WARNING=new IconType$$module$build$src$core$icons$icon_types("warning");IconType$$module$build$src$core$icons$icon_types.COMMENT=new IconType$$module$build$src$core$icons$icon_types("comment"); -var module$build$src$core$icons$icon_types={};module$build$src$core$icons$icon_types.IconType=IconType$$module$build$src$core$icons$icon_types;(function(a){a[a.VALUE=1]="VALUE";a[a.STATEMENT=3]="STATEMENT";a[a.DUMMY=5]="DUMMY";a[a.CUSTOM=6]="CUSTOM";a[a.END_ROW=7]="END_ROW"})($.inputTypes$$module$build$src$core$inputs$input_types||($.inputTypes$$module$build$src$core$inputs$input_types={}));var module$build$src$core$inputs$input_types={};module$build$src$core$inputs$input_types.inputTypes=$.inputTypes$$module$build$src$core$inputs$input_types;var alertImplementation$$module$build$src$core$dialog=function(a,b){window.alert(a);b&&b()},confirmImplementation$$module$build$src$core$dialog=function(a,b){b(window.confirm(a))},promptImplementation$$module$build$src$core$dialog=function(a,b,c){c(window.prompt(a,b))},TEST_ONLY$$module$build$src$core$dialog={confirmInternal:confirmInternal$$module$build$src$core$dialog},module$build$src$core$dialog={TEST_ONLY:TEST_ONLY$$module$build$src$core$dialog};module$build$src$core$dialog.alert=alert$$module$build$src$core$dialog; +var module$build$src$core$icons$icon_types={};module$build$src$core$icons$icon_types.IconType=IconType$$module$build$src$core$icons$icon_types;(function(a){a[a.VALUE=1]="VALUE";a[a.STATEMENT=3]="STATEMENT";a[a.DUMMY=5]="DUMMY";a[a.CUSTOM=6]="CUSTOM";a[a.END_ROW=7]="END_ROW"})($.inputTypes$$module$build$src$core$inputs$input_types||($.inputTypes$$module$build$src$core$inputs$input_types={}));var module$build$src$core$inputs$input_types={};module$build$src$core$inputs$input_types.inputTypes=$.inputTypes$$module$build$src$core$inputs$input_types;var alertImplementation$$module$build$src$core$dialog=function(a,b){console.log(a);b&&b()},confirmImplementation$$module$build$src$core$dialog=function(a,b){b(window.confirm(a))},promptImplementation$$module$build$src$core$dialog=function(a,b,c){c(window.prompt(a,b))},TEST_ONLY$$module$build$src$core$dialog={confirmInternal:confirmInternal$$module$build$src$core$dialog},module$build$src$core$dialog={TEST_ONLY:TEST_ONLY$$module$build$src$core$dialog};module$build$src$core$dialog.alert=alert$$module$build$src$core$dialog; module$build$src$core$dialog.confirm=confirm$$module$build$src$core$dialog;module$build$src$core$dialog.prompt=prompt$$module$build$src$core$dialog;module$build$src$core$dialog.setAlert=setAlert$$module$build$src$core$dialog;module$build$src$core$dialog.setConfirm=setConfirm$$module$build$src$core$dialog;module$build$src$core$dialog.setPrompt=setPrompt$$module$build$src$core$dialog;var module$build$src$core$interfaces$i_variable_backed_parameter_model={};module$build$src$core$interfaces$i_variable_backed_parameter_model.isVariableBackedParameterModel=isVariableBackedParameterModel$$module$build$src$core$interfaces$i_variable_backed_parameter_model;var setLocale$$module$build$src$core$msg,module$build$src$core$msg;$.Msg$$module$build$src$core$msg=Object.create(null);setLocale$$module$build$src$core$msg=function(a){Object.keys(a).forEach(function(b){$.Msg$$module$build$src$core$msg[b]=a[b]})};module$build$src$core$msg={Msg:$.Msg$$module$build$src$core$msg,setLocale:setLocale$$module$build$src$core$msg};var module$build$src$core$interfaces$i_legacy_procedure_blocks={};module$build$src$core$interfaces$i_legacy_procedure_blocks.isLegacyProcedureCallBlock=isLegacyProcedureCallBlock$$module$build$src$core$interfaces$i_legacy_procedure_blocks;module$build$src$core$interfaces$i_legacy_procedure_blocks.isLegacyProcedureDefBlock=isLegacyProcedureDefBlock$$module$build$src$core$interfaces$i_legacy_procedure_blocks;var VarBase$$module$build$src$core$events$events_var_base=class extends Abstract$$module$build$src$core$events$events_abstract{constructor(a){super();this.isBlank="undefined"===typeof a;a&&(this.varId=a.getId(),this.workspaceId=a.workspace.id)}toJson(){const a=super.toJson();if(!this.varId)throw Error("The var ID is undefined. Either pass a variable to the constructor, or call fromJson");a.varId=this.varId;return a}static fromJson(a,b,c){b=super.fromJson(a,b,null!=c?c:new VarBase$$module$build$src$core$events$events_var_base); b.varId=a.varId;return b}},module$build$src$core$events$events_var_base={};module$build$src$core$events$events_var_base.VarBase=VarBase$$module$build$src$core$events$events_var_base;var VarCreate$$module$build$src$core$events$events_var_create=class extends VarBase$$module$build$src$core$events$events_var_base{constructor(a){super(a);this.type=VAR_CREATE$$module$build$src$core$events$utils;a&&(this.varType=a.type,this.varName=a.name)}toJson(){const a=super.toJson();if(void 0===this.varType)throw Error("The var type is undefined. Either pass a variable to the constructor, or call fromJson");if(!this.varName)throw Error("The var name is undefined. Either pass a variable to the constructor, or call fromJson"); a.varType=this.varType;a.varName=this.varName;return a}static fromJson(a,b,c){b=super.fromJson(a,b,null!=c?c:new VarCreate$$module$build$src$core$events$events_var_create);b.varType=a.varType;b.varName=a.varName;return b}run(a){const b=this.getEventWorkspace_();if(!this.varId)throw Error("The var ID is undefined. Either pass a variable to the constructor, or call fromJson");if(!this.varName)throw Error("The var name is undefined. Either pass a variable to the constructor, or call fromJson");a?b.createVariable(this.varName, diff --git a/libs/blockly/javascript_compressed.js b/libs/blockly/javascript_compressed.js index cea1b65..8c19f0a 100644 --- a/libs/blockly/javascript_compressed.js +++ b/libs/blockly/javascript_compressed.js @@ -208,7 +208,7 @@ function ${b.FUNCTION_NAME_PLACEHOLDER_}(str) { function(txt) {return txt[0].toUpperCase() + txt.substring(1).toLowerCase();}); } `)+"("+a+")",Order$$module$build$src$generators$javascript$javascript_generator.FUNCTION_CALL]},text_trim$$module$build$src$generators$javascript$text=function(a,b){const c={LEFT:".replace(/^[\\s\\xa0]+/, '')",RIGHT:".replace(/[\\s\\xa0]+$/, '')",BOTH:".trim()"}[a.getFieldValue("MODE")];return[(b.valueToCode(a,"TEXT",Order$$module$build$src$generators$javascript$javascript_generator.MEMBER)||"''")+c,Order$$module$build$src$generators$javascript$javascript_generator.FUNCTION_CALL]},text_print$$module$build$src$generators$javascript$text= -function(a,b){return"window.alert("+(b.valueToCode(a,"TEXT",Order$$module$build$src$generators$javascript$javascript_generator.NONE)||"''")+");\n"},text_prompt_ext$$module$build$src$generators$javascript$text=function(a,b){b="window.prompt("+(a.getField("TEXT")?b.quote_(a.getFieldValue("TEXT")):b.valueToCode(a,"TEXT",Order$$module$build$src$generators$javascript$javascript_generator.NONE)||"''")+")";"NUMBER"===a.getFieldValue("TYPE")&&(b="Number("+b+")");return[b,Order$$module$build$src$generators$javascript$javascript_generator.FUNCTION_CALL]}, +function(a,b){return"console.log("+(b.valueToCode(a,"TEXT",Order$$module$build$src$generators$javascript$javascript_generator.NONE)||"''")+");\n"},text_prompt_ext$$module$build$src$generators$javascript$text=function(a,b){b="window.prompt("+(a.getField("TEXT")?b.quote_(a.getFieldValue("TEXT")):b.valueToCode(a,"TEXT",Order$$module$build$src$generators$javascript$javascript_generator.NONE)||"''")+")";"NUMBER"===a.getFieldValue("TYPE")&&(b="Number("+b+")");return[b,Order$$module$build$src$generators$javascript$javascript_generator.FUNCTION_CALL]}, text_count$$module$build$src$generators$javascript$text=function(a,b){const c=b.valueToCode(a,"TEXT",Order$$module$build$src$generators$javascript$javascript_generator.NONE)||"''";a=b.valueToCode(a,"SUB",Order$$module$build$src$generators$javascript$javascript_generator.NONE)||"''";return[b.provideFunction_("textCount",` function ${b.FUNCTION_NAME_PLACEHOLDER_}(haystack, needle) { if (needle.length === 0) { diff --git a/primitives/AdvancedBlock.js b/primitives/AdvancedBlock.js index 01cfcc9..2a551ad 100644 --- a/primitives/AdvancedBlock.js +++ b/primitives/AdvancedBlock.js @@ -7,6 +7,7 @@ PRIMITIVES["block_advanced"] = { id: "advanced_block", name: "Advanced Block", texture: VALUE_ENUMS.IMG, + tickRatio: 10, material: ['rock', 'air', 'grass', 'ground', 'wood', 'iron', 'anvil', 'water', 'lava', 'leaves', 'plants', 'vine', 'sponge', 'cloth', 'fire', 'sand', 'circuits', 'carpet', 'glass', 'redstoneLight', 'tnt', 'coral', 'ice', 'packedIce', 'snow', 'craftedSnow', 'cactus', 'clay', 'gourd', 'dragonEgg', 'portal', 'cake', 'web', 'piston', 'barrier'], Constructor: VALUE_ENUMS.ABSTRACT_HANDLER + "BlockConstructor", Break: VALUE_ENUMS.ABSTRACT_HANDLER + "BlockBreak", @@ -14,17 +15,16 @@ PRIMITIVES["block_advanced"] = { NeighborChange: VALUE_ENUMS.ABSTRACT_HANDLER + "BlockNeighbourChange", Break: VALUE_ENUMS.ABSTRACT_HANDLER + "BlockBreak", BrokenByPlayer: VALUE_ENUMS.ABSTRACT_HANDLER + "BlockBrokenByPlayer", - UpdateTick: VALUE_ENUMS.ABSTRACT_HANDLER + "BlockUpdateTick", + RandomTick: VALUE_ENUMS.ABSTRACT_HANDLER + "BlockRandomTick", EntityCollided: VALUE_ENUMS.ABSTRACT_HANDLER + "BlockEntityCollision", }, 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("BlockNeighbourChange", this.tags.NeighborChange, ["$$world", "$$blockpos", "$$blockstate"]); var brokenByPlayerHandler = getHandlerCode("BlockBrokenByPlayer", this.tags.BrokenByPlayer, ["$$world", "$$blockpos", "$$blockstate"]); - var updateTickHandler = getHandlerCode("BlockUpdateTick", this.tags.UpdateTick, ["$$world", "$$blockpos", "$$blockstate", "$$random"]); + var randomTickHandler = getHandlerCode("BlockRandomTick", this.tags.RandomTick, ["$$world", "$$blockpos", "$$blockstate", "$$random"]); var entityCollisionHandler = getHandlerCode("BlockEntityCollision", this.tags.EntityCollided, ["$$world", "$$blockpos", "$$entity"]); return `(function AdvancedBlockDatablock() { const $$blockTexture = "${this.tags.texture}"; @@ -40,7 +40,7 @@ PRIMITIVES["block_advanced"] = { 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 $$randomTickMethod = $$blockClass.methods.randomTick.method; var $$entityCollisionMethod = $$blockClass.methods.onEntityCollidedWithBlock.method; var $$nmb_AdvancedBlock = function $$nmb_AdvancedBlock() { @@ -71,9 +71,12 @@ PRIMITIVES["block_advanced"] = { ${brokenByPlayerHandler.code}; return $$onBlockDestroyedByPlayerMethod(this, ${brokenByPlayerHandler.args.join(", ")}); } - $$nmb_AdvancedBlock.prototype.$updateTick = function (${updateTickHandler.args.join(", ")}) { - ${updateTickHandler.code}; - return $$updateTickMethod(this, ${updateTickHandler.args.join(", ")}); + $$nmb_AdvancedBlock.prototype.$randomTick = function (${randomTickHandler.args.join(", ")}) { + ${randomTickHandler.code}; + return $$randomTickMethod(this, ${randomTickHandler.args.join(", ")}); + } + $$nmb_AdvancedBlock.prototype.$tickRate = function () { + return ${Math.max(1, Math.floor(this.tags.tickRatio || 10))}; } $$nmb_AdvancedBlock.prototype.$onEntityCollidedWithBlock = function (${entityCollisionHandler.args.join(", ")}) { ${entityCollisionHandler.code}; diff --git a/primitives/Item.js b/primitives/Item.js new file mode 100644 index 0000000..bc30d62 --- /dev/null +++ b/primitives/Item.js @@ -0,0 +1,13 @@ +PRIMITIVES["item"] = { + name: "Item", + uses: [], + type: "item", + tags: { + id: "custom_item", + name: "Custom Item", + texture: VALUE_ENUMS.IMG, + }, + asJavaScript: function () { + return ''; + } +} \ No newline at end of file diff --git a/serialise.js b/serialise.js index 1cf326a..15acbfb 100644 --- a/serialise.js +++ b/serialise.js @@ -15,6 +15,10 @@ function deserialise(data) { } globalThis.state = data; + data.nodes.forEach(node => { + var prim = getPrimitive(node.type); + node.tags = Object.assign(prim.tags, node.tags); //load new tags + }); reloadUI(); } function fileRead(handler) {