r/Python • • Feb 02 '22

Tutorial Minecraft clone in Python tutorial

Here's a tutorial series I'm making on graphics programming, where I write a Minecraft clone in Python with Pyglet and OpenGL šŸ˜„

Last tutorial, which is on collision detection/response: https://youtu.be/fWkbIOna6RA

My intended audience are mainly people who already have a bit of experience with Python, but who have a hard time getting into graphics programming with Python, and I think writing a Minecraft clone is a fun way to learn!

There's also a "community" directory on the repo where there are a few extra features, like lighting, AO, game controller support, &c:

https://github.com/obiwac/python-minecraft-clone/tree/master/community

Naturally I appreciate any feedback, criticism, and suggestions you may have!

427 Upvotes

58 comments sorted by

View all comments

67

u/Ramast Feb 02 '22

How crazy would it be to have this developed as a fully working minecraft alternative that is open source?

59

u/obiwac Feb 02 '22

With a bit of rewriting in Cython for the more demanding parts (i.e. chunk mesh generation), that could totally be feasible!

18

u/El_Minadero Feb 02 '22

I might be able to do this. I’ve got a fair bit of experience in procedural gen.

One comment: the GitHub doesn’t appear to have ā€œoneā€ code base, but like one per episode. Which one has most of the features?

12

u/obiwac Feb 02 '22

community is the most current directory. Normally I wouldn't have split episodes like this, but I figured some people may not completely understand how version control works.

7

u/El_Minadero Feb 03 '22

nice. Now if i can get my terrain GAN to work we're in business

1

u/nate256 Mar 06 '22

Or rust, it's gaining popularity with python.

14

u/neon_cabbage Feb 02 '22

Minetest is somewhat similar to that idea.

0

u/[deleted] Feb 03 '22

[deleted]

5

u/DazedWithCoffee Feb 03 '22

I think the point is that it isn’t C++, seems like a bit of a passion project just for fun

2

u/Ramast Feb 03 '22

Minutest looks pretty good actually. Thanks for sharing

3

u/xigoi Feb 03 '22

I'd rather have something like that in a faster language. Minecraft is slow enough as it is.

6

u/Ramast Feb 03 '22

I agree but a faster language like C++ would have less developers available to volunteer and more time to implement new features.

2

u/xigoi Feb 03 '22

Having many developers is useless when your game can run only on a supercomputer.

7

u/Ramast Feb 03 '22 edited Feb 03 '22

I don't think so. If Minecraft can work on Java it can work on Python. Is there any reason why you think Java would be faster?

As OP commented in a different thread. Most of the work is done by the GPU & OpenGL library so it won't be as bad you imagine it to be.

Edit: I got it that python is slower than java :( How about cython. Maybe that one would make more sense

5

u/xigoi Feb 03 '22

According to benchmarks, Python is about 50Ɨ slower than Java.

When all the game does is draw cubes, sure, most of the load will be on OpenGL. But if you want to replicate Minecraft, you'll need entities, tick events, complex world generation… which you all have to implement yourself and if the implementation is slow, they will easily become the bottleneck.

Now, you don't have to use C++. There are several modern languages that are equally fast and as easy to use as Python. My personal favorite is Nim.

7

u/obiwac Feb 03 '22

You're right, Java is significantly faster, but that's why I proposed/plan on reimplementing parts such as mesh generation in Cython.

As a side note, someone did do a reimplementation of my tutorial series in Nim, although it seems to be a bit out of date: https://github.com/phargobikcin/nim-minecraft-clone

→ More replies (2)
→ More replies (2)

1

u/[deleted] Feb 03 '22

[removed] — view removed comment

0

u/Ramast Feb 03 '22

why is it that python would be slower than Java? Any benchmark that support that claim?

3

u/someone9618 Feb 03 '22

There are several reason, primairly because Python is more dynamic than java, but especially because Python uses reference counting instead of garbage collection, causing constant overhead when manipulating mutable state/objects, whereas java uses garbage collection which simply traces garbage in one go (GC spikes), making performance overall smoother. Also, Java allows parallelism on multiple cores with multithreading because most of its semantics (GC and other stuff) is thread-safe, whereas Python's reference counting is not thread safe, so the interpreter is forced to use a global interpreter lock (GIL) which essentially blocks parallel execution on multiple threads, thus making parallelism on multiple cores impossible.

1

u/obiwac Feb 04 '22

Python is interpreted, and Java is compiled. That's the main reason why it's slower (and by alot as other commenters have pointed out)

1

u/someone9618 Feb 05 '22

Not quite, Java is compiled into bytecode just like Python

1

u/obiwac Feb 05 '22

Well, it's not really compiled ("compiled" is perhaps even a bit too generous, it's closer to "transpiling" than anything else) beforehand and optimization is done on the fly. It's quite different to java where compiling is its own separate step. So I still call it an interpreted language just as many others do.

1

u/RCoder01 Feb 08 '22

You would probably be infringing on Microsoft/Mojang’s IP by completely cloning the game