Skip to content

Instantly share code, notes, and snippets.

@walterhiggins
Last active January 3, 2016 10:09
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save walterhiggins/ab049f18cd23323bc2a3 to your computer and use it in GitHub Desktop.
Save walterhiggins/ab049f18cd23323bc2a3 to your computer and use it in GitHub Desktop.
Minecraft + ScriptCraft + MQTT

Some quick notes on publishing to a MQTT broker from within Minecraft using ScriptCraft and mqtt protocol. Get wmqtt.jar here...

http://www-01.ibm.com/support/docview.wss?rs=171&uid=swg24006006&loc=en_US&cs=utf-8&lang=en .

Follow these instructions to download and install the Mosquitto MQTT broker...

http://mosquitto.org/download/

Once Mosquitto is running, start Craftbukkit like this...

java -cp ia92/J2SE/wmqtt.jar:craftbukkit.jar org.bukkit.craftbukkit.Main

... to include wmqtt.jar in the classpath so that ScriptCraft can use it. Then add a minecraft event handler which when fired will publish to a mqtt broker like this...

var MqttClient = com.ibm.mqtt.MqttClient;
var connStr = 'tcp://localhost:1883';
var client = new MqttClient(connStr);
client.connect('scriptcraftjs.org', true, 5);
events.on('block.BlockBreakEvent', function (listener, event){
    client.publish('blockbreak', [1], 1, false);
});

... and you have a hook from minecraft to mqtt. Wire up an arduino to subscribe to the 'blockbreak' topic on that broker and do something interesting.

@andypiper
Copy link

FYI wmqtt.jar is outdated and deprecated, recommend Eclipse Paho instead - see eclipse.org/paho - Open Source and more modern.

@walterhiggins
Copy link
Author

Thanks Andy, Am currently working on a bare-bones wrapper around eclipse paho for use in ScriptCraft.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment