Automation Techs For Productivity And Fun

3 Ways To Run Commands Externally For Minecraft Bedrock Edition

My kids are into Minecraft lately, especially for building houses and other buildings in Creative Mode. It's like playing with LEGO blocks in a virtual world.

https://minecraft.net/en-us/

Minecraft provides a command system to control the world, like putting blocks to specified point and teleporting objects. And I found some ways to run these commands from outside of Minecraft, that means that I can create programs to build complex buildings automatically without clicking or tapping for each block.

These are the 3 ways I found to run Minecraft commands from external programs.

Using "function" command

The first and the easiest way is to use the "function" command.

https://minecraft.gamepedia.com/Function_(Bedrock)

As it's explained in the document above, create a function file with the extension ".mcfunction", write list of commands in it, and save it in function file directory.

If you create a function file named "Sample1.mcfunction", you can run in Minecraft by using the function command like this:

/function Sample1

The "function" command was only allowed in Java Edition before, but it was added to Bedrock Edition in version 1.8.

MakeCode For Minecraft

The second way is to use MakeCode For Minecraft.

https://minecraft.makecode.com/

This is a Scratch like graphical application provided by Microsoft. You can create a custom command by dragging and dropping Minecraft commands together. It seems custom commands are converted to Javascript programs, and you can also write custom commands directly with Javascript.

I think this is the best way for kids, not only for automation, but also for programming education.

Unfortunately I couldn't use this app because my Windows PC was too weak to run Minecraft and MakeCode together.

Creating An Original WebSocket Server

This is the third way, and the way I've adopted.

As I wrote above, MakeCode was too heavy for my Windows PC, so I needed a more lightweight tool to send commands to Minecraft. MakeCode communicates with Minecraft using WebSocket, so it should be possible to replace MakeCode with another original lightweight WebSocket server.

I found hints from these links:

https://www.reddit.com/r/MCPE/comments/5ta719/mcpewin10_global_chat_using_websockets/

https://gist.github.com/jocopa3/5f718f4198f1ea91a37e3a9da468675c

https://gist.github.com/jocopa3/54b42fb6361952997c4a6e38945e306f

It seems Minecraft uses JSON data for request and response.

You can catch events in Minecraft by subscribing it, and run commands by firing "commandRequest"s.

What you have to do is...


  1. Write a WebSocket script to subscribe events and send command requests
  2. Start your WebSocket server
  3. Connect to your WebSocket server from Minecraft by running "/connect" command
  4. Fire events from Minecraft to trigger your custom commands


For example, I wrote a WebSocket server that puts a block in front of the player when the player says "build" with Node.js.

Connect to this server from Minecraft with "/connect" command.

/connect SERVER_IPADDRESS:3000

Then just say "build" from Minecraft, and you would see a stone brick block put in front of the player.

Conclusion

Whichever way you choose, it would make it easy to create more complex buildings like these.


https://www.instagram.com/p/BrrYC3LAf9y/


https://www.instagram.com/p/BriMXvyA6VQ/


Share:

Search This Blog

Labels

Generate Data For Testing With PostgreSQL

When developing a software using PostgreSQL database as storage, the function "generated_series" is very useful to create data ...

Powered by Blogger.

Labels

Recent Posts