Creating new procedure blocks

Making the procedure block

Setting up the folders 

To create all of the procedure blocks, you will need to create a new folder inside of your main folder. The name of this folder has to be ”procedures”. If you put another name, it could not work correctly. 

Making the JSON file

When it’s done, create a new JSON file with the name of your procedure block. When it’s created, you can open it. To explain the code of the file, I will use the code of one of the procedure block of SomeoneElse.

 The name of custom procedure blocks should be prefixed with pluginid_ to avoid collisions with other plugins.

{
  "message0": "Increase size of item stack %1 by %2",
  "args0": [
    {
      "type": "input_value",
      "name": "item_stack",
      "check": "MCItemStack"
    },
{
      "type": "input_value",
      "name": "amount",
      "check": "Number"
    }
  ],
  "inputsInline": true,
  "previousStatement": null,
  "nextStatement": null,
  "colour": 350,
  "mcreator": {
    "toolbox_id": "itemstackmanagement",
"toolbox_init": [
      "<value name=\"amount\"><block type=\"math_number\"><field name=\"NUM\">1</field></block></value>"
    ],
"inputs": [
  "item_stack",
  "amount"
]
  }
}

Explanation of the code

The first line is used to write the text displayed on the block. If you look correctly, you can see a %1. The % symbol followed by a number is used to tell to MCreator and Blockly there is a field to fill by the user. The number is only used to say his place in the args list after. You have to put % symbols as much as you want the user to change variables.

After the first line, you have the ”args0” section. This section is used to declare the type of each variable you have put before. The first variable will be the %1 you have put in the ”message0”.

There are three types, field_number to write a number, input_value to have a value(items, String, etc.), and field_checkbox to have a checkbox.

  • The name section is only the name of your variable.
  • Value (field_number): Write a number. It will be the default value.
  • Check (input_value): MCItem is to have the item window. A String is for text. MCItemStack is about the ItemStack variable.
  • Checked (field_checkbox): true/false (true = checked, false = Not checked)

After, go to ”colour”. This section is to set up the colour of the block.

The ”toolbox_id” is the section where your block will be. To have your own section check below.

The ”toolbox_init" sets the initial values of the variable parts. In this case, it sets the "amount" variable to 16, so when you grab the procedure block, it automatically has a 16 number block in it.

The ”inputs" just tell MCreator what the arguments are (the names here are the same names in "args0").

To have the list of all entities, dimensions or biomes, you will need to add a new section after the ”args0” section. Copy and paste this code. You don’t have to put the % symbol. Here is an example with the entities.

   "extensions": [
    "entity_list_provider"
  ],

You will also have to add an ”entity” line in the ”fields” section.

Create your own procedure block section

To have your own section, return into your ”procedures” folder. Then, create a new JSON file. The name your file has to start with a $. After, put the name of your section without space. You will have to write this name (without the $) in the procedure files. When it’s done, open it and paste this code.

{
  "name": "Wiki tutorial",
  "color": 110
}
  • ”name” is the same who will be displayed in MCreator.
  • ”colour” is the colour if the section.

After this, you can save and close your file.

Great job! You have finished creating the AI task block. You have now to set the code.

Make the code of your procedure block

In this section, I will only speak of the 1.12.2, but it is the same thing. You have only to create a folder named 1.14.4 instead.

Setting up the folders

First of all, go back into the main folder (you have to see your ”procedures” folder). Then, create a new folder named 1.12.2. It is in this folder you will put all of the files with code. Go inside, and create a new folder name also ”procedures”. Enter in this folder.

Making the code file

When you are inside of the folder, create a new file with the extension .java.ftl. For the name of the file, write the same name you have wrote for the JSON file. Open the file, and write the code of the AI task. This is the code of my block :

${input$item_stack}.grow((int) ${input$amount});

You can see a ${input$item_stack} and a ${input$amount}. The first is used to put the first variable of the procedure block (named in this case ”item_stack”), and the second is used to put the number of the variable amount.

Save your file and you are done! You can now export your plugin in a .zip file and test it.



Donate to MCreator

By donating to developers you can speed up development, as with more resources, we can dedicate more time to MCreator. It is a free project made by developers working on it in their free time.