Creating new AI task blocks

Making the AI block

Setting up the folders 

To create all of the AI blocks, you will need to create a new folder inside of your main folder. The name of this folder has to be ”aitasks”. 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 AI task. When it’s created, you can open it. To explain the code of the file, I will use the code for the AI task ”Follow Parent”.

The name of custom AI task blocks should be prefixed with pluginid_ to avoid collisions with other plugins

{
  "message0": "Follow parent with speed %1",
  "args0": [
    {
      "type": "field_number",
      "name": "speed",
      "value": 1.0
    }
  ],
  "inputsInline": true,
  "previousStatement": null,
  "nextStatement": null,
  "colour": 20,
  "mcreator": {
    "toolbox_id": "wikiplugin",
    "fields": [
      "speed"
    ]
  }
}

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.
  • 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 last section in this code is the fields/inputs. In the ”fields” section, you have to write all the field_number and field_checkbox you have used (write their names).

If you have one or many inputs_values, duplicate the ”fields” section, and change ”fields” by ”inputs”.

To have the list of all entities, 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.

   "extensions": [
    "entity_list_provider"
  ],

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

 

Create your own AI task section

To have your own section, return into your ”aitask” 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 AI 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.

You have the code color for the blocks here. https://developers.google.com/blockly/guides/create-custom-blocks/block-colourhttps://developers.google.com/blockly/guides/create-custom-blocks/block-colour

Coding your AI task

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

Setting up the folders

First of all, go back into the main folder (you have to see your ”aitasks” folder). Then, create a new folder named 1.14.4. It is in this folder you will put all of the files with code. Go inside, and create a new folder name also ”aitasks”. 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 :

this.goalSelector.addGoal(${customBlockIndex+1}, new FollowParentGoal(this, ${field$speed}));

You can see a ${customBlockIndex+1} and a ${field$speed}. The first one is used to set the position number of the task whatever where it will be in the builder. The second is used to set the number (in this case) that the player has put for the argument ”speed”. For your fields, change ”speed” by the name you have set up. If you have inputs, change the ”field” for ”input”.

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.