Hacker News new | past | comments | ask | show | jobs | submit login
Show HN: Learn Python with Minecraft (github.com/gilesknap)
171 points by gilesknap 11 months ago | hide | past | favorite | 53 comments
Looking for feedback on my project to teach python by writing code that interacts with a Minecraft World.



When I worked at Skyscanner, we'd volunteer at events where high school kids would be shown tech stuff. We'd setup Raspberry Pis with Minecraft on them and show them some basics of running Python scripts to alter the world (with the conclusion being programmatically create loads of dynamite blocks and explode them). Then at the end of the session, give every kid their own Raspberry Pi.

It was interesting reaching the occasional child who assumed this kind of thing wasn't for them.


Before I started MCIWB I hosted Minecraft servers on my Raspberry Pi during lockdown. My son would meet up with friends on these servers every day.

I was impressed how low resource requirements are for the server.

We had quite big world's with 5 or more players running pretty well.

The client is a different story and the graphics capability of a pi is five for pi edition but struggles with the others.


was this by injecting from the pi to a capable Minecraft server? because exploding loads of TNT on a pi itself would run at a painful framerate, I presume

edit: actually mc renders locally so unless it was running at a really low resolution, I suppose it must have been painful


There is an official release of minecraft optimized for the Pi: https://www.minecraft.net/en-us/edition/pi


no info on which Pis are supported, or if network/XBox Live is enabled


It mentions running on Wheezy, which from a bit of digging looks like the 2013-2015 version of Raspbian, based on the 3.x kernel. Wheezy is only listed for the 1/1+ and 2. https://minecraft.fandom.com/wiki/Pi_Edition lists it as being slightly stripped down from Alpha 0.6.1 of Pocket Edition.

Also a quote from 2016: "The original team has stopped supporting it and starting with 0.9 MCPE became a lot more ambitious technically, which also means that it became a lot harder to strip down to run on a Raspberry Pi. Actually, we finished removing all Pi related code to reduce complexity in 2015."

If your interest is simply in running MC on a Pi you're probably best off looking into Java Edition, though I have no idea how capable the hardware actually is graphics-wise. If you're more interested in MC on cheap hardware, you're probably better off with a cheap Windows machine and the Microsoft Store/Bedrock edition written in C++ for performance.


I'm not sure how impressed the average kid would be comparing dated, underpowered with current Minecraft

also, I never understood the meme but can it run Minecraft? since the game engine and mods can be pushed as far as you want on latest high-end hardware, and does struggle/gives bad playability on low-end hardware

that said they have made an outstanding effort to at least make the game run on potatoes, even if it looks less glamorous


I think the "can it run" bit is more with Doom, which runs on all sorts of absurd things (arguably including a lamp, but I don't think it counts if you actually have to mod it to add a display).


Minecraft on a Pi is insanely stripped down. So much so, you have to re-code some things with Python if you want to get closer to what actual Minecraft gameplay is like.


If you don't mind using Lua instead, I can recommended minetest as a free alternative. I've had a lot of fun messing around in it. It has a lot of great games and mods as well.

https://www.minetest.net/


Minetest is definitely fun, and I've had good luck using Miney to build in it with Python

https://miney.readthedocs.io/en/dev/index.html



lua! great! There's also blockly (which is a free version of scratch, the visual programming language), but i wanna have a real language! thanks!


I like this. Obviously, internally, the original Minecraft runs Java, but that's quite a difficult sell to an 8-year-old.

This is potentially a nice way to get them into programming for the game - the only thing I worry about is maintaining compatibility with a product which Microsoft seem intent on wresting away from modders, perhaps only indirectly. Even making logins work is fraught with peril thanks to Microsoft's appalling IAM solution.


> Microsoft seem intent on wresting away from modders, perhaps only indirectly

What is Microsoft doing in that regard? Last I was working on Minecraft mods they did a lot to support them, such as sharing the obfuscation map or making Brigadier open-source. Have there been other developments since then?

The IAM logins seem more like a security decision to me (assumably Microsoft has requirements on how their products need to do authentication), not one to keep away modders.


Microsoft also published DataFixerUpper and added some packets specifically for servers such as the "Ping" packet and the "Bundle" packet and the 1.19.4 display entities.

Ping being to synchronously measure latency of the client - unused by vanilla

Bundle being to force packets to be processed together - very useful for sending clients display animations all at once

And then all the display entities to display text and itemstacks in the air, with custom interpolation and stretching - so advanced animations can easily be made.

The most hostile thing is Microsoft pushing the locked down Bedrock edition.


Mostly passively by trying to push stuff like Realms more instead of letting the community run their own servers (which could also be modded).

Bedrock Edition is also iirc insanely locked down in terms of modding and it's the version Microsoft pushes the sales of the most. There's some amount of it possible, but forget about any of the ludicrous automation/engineering mods like you had back in Java edition.


Really? My last info was that in Minecraft Bedrock, you even need to buy "coins" with real money to change simple things like Skin Packs. What a shame


That's just not the case at all. You can certainly buy mods from the Minecraft store (or whatever it's called). But you can also write behavior packs and make skins and textures without paying for anything (besides the base game).

My son and I spent some time making custom weapons and the like using a tool called Bridge (https://bridge-core.app/). It's definitely not as powerful as modding once was in the Java version of the game, but you can do lots of pretty wild stuff with Bedrock if you're willing to jump through the hoops.

One "mod" that recently caught my eye was this one: https://www.youtube.com/watch?v=IUWRK0Jy9d0

Yeah, you have to buy it with "Minecoins", but I can't get too upset that Microsoft has allowed devs to monetize their efforts on the platform. There's still plenty of free stuff available and nothing to prevent kids (or adults) from taking a crack at their own mods.

My son was just recently playing with a site called Tynker, and without any help from me managed to get a custom item into the game, so if an 8 year old can do it, it's about as accessible as you could hope for.


This sounds quite interesting. I've really only spent much time with Java and although it has a great modding scene it is unofficial and nothing ever works with updated versions (My Python approach is immune to this issue as it uses official RCON interface).

I have always been put off by how commercial Bedrock seems as soon as you open it. But at the same time it sounds like interesting and official modding is available there.


afaik they're still developing the java version as well, though



So we should be good for a while. The RCON interface this uses is always forward compatible with new Java editions.

Bedrock also uses RCON but there are subtle differences with the commands available.

If Microsoft ever does drop Java Edition I'd likely rework this to support Bedrock. I'm hoping this won't happen - they are keeping Java up to date with Bedrock presently but the new editor mode for Bedrock is a worrying development (maybe).


Minecraft Education edition already does this.

Press C, code window appears, you can use Python, Javascript or a visual Scratch-like language, controlling an agent in the minecraft world to go and do things

https://education.minecraft.net/en-us/resources/computer-sci...


I've taken a detailed look at MC EE vs MCIWB and taken some notes here: https://gilesknap.github.io/mciwb/main/user/explanations/mce...


It seems EE is more about programming agents that interact with the world (like in survival mode), whereas this tool interacts with creative mode to edit the world (think generative terrain, copy-pasting bits of your build, etc). I'd say they complement each other, but unfortunately Minecraft JE and EE are two entirely different programs[1].

[1]: https://news.ycombinator.com/item?id=35150691#35152941


Last time I looked into it, which I do fairly often because Education Edition has some interesting features not in other versions, you need to be an educator to even get a license for Education Edition.


Well that's a shame because I am pretty sere education edition supports RCON so I could adapt MCIWB to use it.

I happen to know that EE commands include the elusive 'GetBlock' that let's you query the contents of the world. I had to jump through some embarrassing hoops to provide this function for MCIWB.


If you are interested in this sort of tools, look into Baritone and Schematica

https://github.com/cabaletta/baritone

https://github.com/Lunatrius/Schematica


If you like clojure (which can interact with the jvm directly) there's also witchcraft: https://github.com/lambdaisland/witchcraft


If you would have asked me which language would be taught with Minecraft I would have answered Lua. I don't know why. But I was instantly wondering why Python instead of the obvious answer which is Lua.


The computercraft mod allowed one to program lua robots inside minecraft


Is what you are doing similar to "Adventures In Minecraft"? [0]. My kid and I went through that and is was great. Last adventure involves hooking up a micro:bit to control in-game elements. [0] https://www.wiley.com/en-us/Adventures+in+Minecraft,+2nd+Edi...


It looks like this book will be using the education edition of minecraft. It does have a limited python programming interface.

My approach uses a remote interface called RCON to send Minecraft operator commands to the world. It can do everything you could do with Command Blocks or Operator commands and more because of the Python constructs like loops and branching.

The other benefit is that you get to use the latest developer tools such as VSCode and the latest version of Python as you are working outside of the Minecraft game to write your code.


Nope, it uses regular Minecraft with https://pypi.org/project/mcpi/ and https://dev.bukkit.org/projects/raspberryjuice so full Python.


Thanks for the link. I did not know about raspberry juice.

It does provide a similar capability to MCIWB. It recreates the Education edition python interface which does let you set and get blocks and see when a player hits something.

Its a solution for people who learn education edition and then want to run the same code at home on a BUkkit server. (Bukkit is a Java server mod )


We did it and we've never had education edition.


I honestly cannot understand how Microsoft is running Minecraft.

How do they not seem to realize the value in making it easy for people to hack it like this?

Look at the installation page...

https://gilesknap.github.io/mciwb/main/user/tutorials/01-set...

Why?

Can't we please have a way to trivially do this?


To be fair. My instruction page is setting up Minecraft, Docker to run a minecraft server in, Python and VSCode.

So I have quite a few prerequisites for my Python tutorials and this makes the first page intimidating.

However, installing and running MC java edition has got more fiddly since Microsoft took over. There was a horrible transition phase where accounts were being migrated from Mojang.

It's kind of OK now. But I'm sad that Microsoft is pushing hard on Bedrock Edition and look like they may try to ditch Java. This project could be adapted to Bedrock without much trouble but there is a whole class of things {NBT related} that you don't seem to be able to do via the remote interface in Bedrock.


Minecraft (Bedrock) API Dev here, we also started publishing TypeScript types for our JavaScript API!

The API is still really new and sparse but we are getting there.


So this sounds like fun.

What kind of interface - operator commands? or something more low level? The operator commands that MCIWB uses are really poor for querying the state of the world - hopefully this API would give us that?


Curious timing! I signed my niece up for a programming course for children yesterday where they are going to learn python with Minecraft!

Now I wonder if they'll use your project, or if there's another similar project they'll be using?

Regardless, the idea is great! I wish you luck!


It won't be MCIWB :-) Nobody had heard of it until last week! :-)

They may be using Minecraft Education Edition which as come up a few times in the above conversations.


What's the advantage over MakeCode for Minecraft (other than that requiring Minecraft education edition)?


Believe it or not I did not know about this. I'm aware of Education Edition but the projects in MakeCode look more sophisticated than I expected.

I'm going to take a look into it and come back to you on this question!


I've looked into MC EE and MakeCode.

Here is my summary of findings https://gilesknap.github.io/mciwb/main/user/explanations/mce...


Nice. When I was teaching with MCEE, the code server was painfully slow. I think MS employees don't test this kind of thing on real hardware that real students use.


I'm doing this with teenagers, but using Clojure.


whoa it'd be cool to use this to build an experience within minecraft where a world builds up around the player as they move around it.


Yes, you could absolutely do that. I've even used it to create moving structures that players can get inside and be carried around in.


My son will be interested in this for sure.


This is so sick!


Interesting repo




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: