Scott Hanselman

Teaching Kids to Code with Minecraft Mods made easy using MakeCode and Code Connection

February 06, 2019 Comment on this post [6] Posted in Gaming | Musings
Sponsored By

Back in the day, making a Minecraft mod was...challenging. It was a series of JAR files and Java hacks and deep folder structures. It was possible, but it wasn't fun and it surely wasn't easy. I wanted to revisit things now that Minecraft is easily installed from the Windows Store.

Today, it couldn't be easier to make a Minecraft Mod, so I know what my kids and I are doing tonight!

I headed over to https://minecraft.makecode.com/setup/minecraft-windows10 and followed the instructions. I already have Minecraft installed, so I just had to install the Minecraft Code Connection app. The architecture here is very clean and clever. Basically you turn on cheats in Minecraft and use a local websockets connection between the Code Connection app and Minecraft - you're automating Minecraft from an external application!

Here I'm turning on cheats in a new Miencraft world:

Minecraft Allow Cheats

Then from the Code Connection app, I get a URL for the automation server, then go back to Minecraft, hit "t" and paste it in the URL. Now the two apps are talking to each other.

Connecting Minecraft to MakeCode

I can automate with MakeCode, Scratch, or other editors. I'll do MakeCode.

Make Code is amazing

Then an editor opens. This is the same base open source Make Code editor I used when I was coding for an Adafruit Circuit Playground Express earlier this year.

Now, I'll setup a chat command in Make Code that makes it rain chickens when I type the chat command "chicken." It runs a loop and spawns 100 chickens 10 blocks above my character's head.

Chicken rain

I was really surprised how easy this was. It was maybe 10 mins end to end, which is WAY easier than the Java add-ins I learned about just a few years ago.

Minecraft Chicken Rain

There are a ton of tutorials here, including Chicken Rain. https://minecraft.makecode.com/tutorials

The one I'm most excited to show my kids is the Agent. Your connection to the remote Code Connection app includes an avatar or "agent." Just like Logo (remember that, robot turtles?) you can control your agent and make him build stuff. No more tedious house building for us! Let's for-loop our way to glory and teach dude how to make us a castle!


Sponsor: Get the latest JetBrains Rider with Code Vision, Rename Project refactoring, and the Assembly Explorer. Improved support for C#, VB.NET, F#, TypeScript, and Angular is all included.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Hosting By
Hosted in an Azure App Service
February 09, 2019 16:04
Thanks Scott for sharing this! Just tried this with my kid, and it seems working, except one thing - the code on chat command is executed twice, for example a simple command to move forward 1 block runs twice and the agent is moving 2 blocks. Trying to figure this out, but with no results yet. Didn't you face with similar issue? (minecraft windows 10 edition v1.9.0, code connection v1.5.0)
February 09, 2019 21:45
Dmitry, I'm seeing the same duplicate commands. Doing something awful with state variables works to hide the extra command:


let fdCalled = false
player.onChat("fd", function () {
fdCalled = !(fdCalled)
if (!(fdCalled)) {
agent.move(SixDirection.Forward, 3)
}
})


I'm also not getting console.log() to work. In the MakeCode simulator, you can navigate to core/helpers.ts and see the definition of console.log shims to minecraft::serialSendString, but when I try to use it I get "Program Error: Cannot read property 'serialSendString' of undefined"
February 09, 2019 23:40
Carl, I was thinking about this workaround as well, but it's hard to explain this for the kid never saw the code before :)
February 12, 2019 7:39
I talked to the team and confirmed this is a bug and they know about it and it should be fixed ASAP in a minecraft update.
February 15, 2019 18:40
I am using Minecraft Windows 10 Edition v1.9.0, and Code Connection v1.50.
I am following the instructions above, as I did in Minecraft Windows 10 Edition v1.8.0 and Minecraft Windows 10 Edition v1.8.1.
When I try to connect with "/connect 192.168.178.30:19131", I get this error: "Kan geen verbinding maken met server ws://192.168.178.30:19131" which translates to: "Can not connect to server ws://192.168.178.30:19131".
Any suggestions?
February 20, 2019 15:40
Is there any way to get this working for regular Java Minecraft? I am running Minecraft on Windows 10 but I don't want to buy another version of Minecraft.

Comments are closed.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.