MCreator Link: API

Section

CurrentDevice

Most of the interaction with MCreator Link can be done using net.mcreator.minecraft.link.CurrentDevice class. This class contains methods to interact with the currently connected device. If there is no device connected, calls are ignored and return values are -1.

Some of the methods of this class are:

  • public static void pinMode(int port, PinMode pinMode)
  • public static void digitalWrite(int port, byte value)
  • public static void analogWrite(int port, short value)
  • public static byte digitalRead(int port)
  • public static short analogRead(int port)
  • public static void enableDigitalInputEvents(int port)
  • public static void disableDigitalInputEvents(int port)
  • public static void sendMessage(String message)
  • public static int getDigitalPinsCount()
  • public static int getAnalogPinsCount()

All methods are static so example usage of this class would be:

import net.mcreator.minecraft.link.CurrentDevice;
import net.mcreator.minecraft.link.devices.PinMode;

...

CurrentDevice.pinMode(13, PinMode.OUTPUT);
CurrentDevice.digitalWrite(13, 1);

...

Events

MCreator Link uses Minecraft Forge event bus to register events. In order to use LinkDigitalPinChangedEvent, link needs to have events enabled. By default, no events are triggered by pin state changes.

CurrentDevice.enableDigitalInputEvents(15);

This call will enable events on pin 15. If the pin value changes, such events will be propagated to the Minecraft Forge event bus. Example usage of such event would look like this:

import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

import net.mcreator.minecraft.link.event.LinkDigitalPinChangedEvent;

public class LinkPinEventHandler {

	@SubscribeEvent
	public void onMCreatorLinkPinChanged(LinkDigitalPinChangedEvent event) {
		
        // handle the event here

	}

}

...

In Main mod class:

MinecraftForge.EVENT_BUS.register(new LinkPinEventHandler());

Link protocol

LinkProtocol class parses and constructs link messages so you can use this class for the reference on how the link protocol looks like.

DeviceManager

This class takes care of the device connections. This is internal class. More info can be found in the documentation.

Documentation

Documentation of MCreator Link is hosted on GitHub pages.



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.