MCreator Link: MCreator procedures

Section

Creating MCreator Link workspace

Create a new workspace and give it a name and set a mod id. Open workspace settings by clicking on the settings button.

MCreator workspace settings

Next, check the MCreator Link under External API settings and click Save changes.

Enabling MCreator Link

Setting default pin modes

We need to add a procedure that will set the pin modes on the device connect. To do this, add a new mod element with type Procedure. After the procedure editor is open, set the global event to MCreator Link: New device connected. Then we add the pin mode procedure blocks (found in MCreator Link category in the block palette). This will ensure that pins will be set to the proper modes when the device is connected. If you are connecting LED or any other actuator on the pin, set this to output, if you are connecting a button or other sensors to the pin, set the mode to output. An example can be seen below:

Setting pin mode from the procedure block with global trigger

Controlling devices from MCreator mods

MCreator Link procedure blocks can be used to control the currently connected device. If no device is connected, these blocks are simply ignored.

You can use them from any procedure as they require no dependencies. Digital read, and analog read blocks return values that can be used in conditions.

Example 1: Turning on LED at daytime

In this example, we make a block that turns on the onboard LED on Arduino (pin 13) at daytime but can be used on any other device too. We just use pin 13 in this example as this is commonly used on Arduinos as the onboard LED. Make sure to set the pin 13 mode to output for this example to work.

Creating a block

First, create a new block and call it NightDetector. Give it any properties you wish, but make sure to keep tick rate on 10 or set it higher, so we don't send too much data to the device at once.

In the procedures section of the block, we click + on the Update tick procedure trigger.

Procedure trigger

Defining the procedure

Keep the default name and define the following procedure:

MCreator Link LED light sensor

This procedure will turn on the LED on the pin 13 if the block can see the sky and there is a day in the world. We can simplify this procedure to this one too, but you can keep the first version for better readability:

Simplified procedure for MCreator Link example

Click Add procedure to add the procedure to the trigger. Then save the block.

Testing it out

Open test Minecraft in MCreator, press 'L' in the main screen to open MCreator Link screen. Connect to your device and close MCreator Link screen. Create a new world, place your block and test it by setting the world time and watch as your LED turns on on the daytime and turns off in the night.

Example 2: Exploding block when a button is pressed on the device

In this example, we will make a block that will check if a button on the device on pin 1 is pressed and if it is, the block will explode.

Wiring the button

Connect the button to the pin 1 and the other connector of the button to the ground. In the pin modes procedure, define pin 1 as input with internal pull-up resistor enabled:

Setting the pinmode of pin 1 for the example

Creating a block

First, create a new block and call it ExplodingBlock. Give it any properties you wish.

In the procedures section of the block, we click + on the Update tick procedure trigger.

Procedure trigger

Defining the procedure

Keep the default name and define the following procedure:

Procedure that check digital pin value

This procedure will explode when a digital pin will be low (button is pressed). In some cases, you might need to remove the not block if your block explodes when the button is not pressed.

Testing it out

Open test Minecraft in MCreator, press 'L' in the main screen to open MCreator Link screen. Connect to your device and close MCreator Link screen. Create a new world and place your block. Click on the button connected to your device and watch as the block explodes when you trigger it by pressing the button.



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.