Making Minecraft from scratch in 48 hours (NO GAME ENGINE)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

pretty good.

Here's a few suggestions I'd say:

  1. Replace define constants with enums.
    You have stuff like #define CONST const. I suggest replacing that with anonymous enums.
    It's not a wholly bad thing but less preprocessor stuff, the cleaner.
  2. struct Camera self; memset(&self, 0, sizeof(struct Camera));
    why not do struct Camera self = {0}; ?

Other than that, I like the design it has. I liked and shared this to my C programming group on Quora.

πŸ‘οΈŽ︎ 17 πŸ‘€οΈŽ︎ u/Adadum πŸ“…οΈŽ︎ Apr 26 2020 πŸ—«︎ replies

Here's a link to the source: https://github.com/jdah/minecraft-weekend (it's a bit of a mess!)

πŸ‘οΈŽ︎ 10 πŸ‘€οΈŽ︎ u/NotQuaggles πŸ“…οΈŽ︎ Apr 26 2020 πŸ—«︎ replies

I am really surprised how little code this is in the end. After watching the video with all the features you explained I thought it must be huge.

Still, mad props for finishing all this in two days, that's ridiculous!

πŸ‘οΈŽ︎ 5 πŸ‘€οΈŽ︎ u/darkslide3000 πŸ“…οΈŽ︎ Apr 26 2020 πŸ—«︎ replies

I really enjoyed watching this. Wish I knew what any of this code was (I really want to learn C, but can't find the drive). Keep up the great work!

πŸ‘οΈŽ︎ 3 πŸ‘€οΈŽ︎ u/AwlsomeAlex365 πŸ“…οΈŽ︎ Apr 26 2020 πŸ—«︎ replies

I think it's really inspiring to see projects like this completed to such an extent. I always work on projects and quit after less than a day of work but this was something really cool to watch! In the past I've tried to mess around with SDL to work on really small 2D projects but would you recommend using OpenGL (or a combination of such things) to work on 2D or 3D for game dev projects? (Also assuming they would be programmed in C)

πŸ‘οΈŽ︎ 5 πŸ‘€οΈŽ︎ u/avelez6 πŸ“…οΈŽ︎ Apr 26 2020 πŸ—«︎ replies

That is the coolest thing I've seen in a long time. Especially for a weekend project.

πŸ‘οΈŽ︎ 4 πŸ‘€οΈŽ︎ u/cjwelborn πŸ“…οΈŽ︎ Apr 27 2020 πŸ—«︎ replies

Next: minecraft in assembly

πŸ‘οΈŽ︎ 3 πŸ‘€οΈŽ︎ u/notYuriy πŸ“…οΈŽ︎ Apr 27 2020 πŸ—«︎ replies

I love this! Awesome job! This has inspired me to actually build things like these from scratch myself :)

πŸ‘οΈŽ︎ 2 πŸ‘€οΈŽ︎ u/saladthievez πŸ“…οΈŽ︎ Apr 27 2020 πŸ—«︎ replies

Very nice indeed! Great video, very instructional.

πŸ‘οΈŽ︎ 2 πŸ‘€οΈŽ︎ u/arthurno1 πŸ“…οΈŽ︎ Apr 28 2020 πŸ—«︎ replies
Captions
[Music] so I've seen a few other people around YouTube making Minecraft clones but they all use shortcuts like 3d engines or languages with classes and garbage collection and namespaces and things you don't really need but I'm too cool for all that stuff so I decided to challenge myself and ride my Minecraft Cologne in see here's how it went to get started as all good programmers should I made a quick hello world program to check if my build system was set up right and it totally wasn't after that the first thing I needed to do was to get the graphics player plate set up which means opening up a blank window with nothing in it thankfully I have a library called gfw which is most of the heavy lifting for me here so after about an hours of work I had a blank window open after that I wrote my input code so I could use the mouse and keyboard later on and then it was finally time to get something to draw out of the screen getting just one thing to render in modern OpenGL is actually pretty involved since you have to get things like shaders and buffer objects set up but I made sure to write the code in such a way so that the same code could be used very later on when I needed to start drawing cubes after a few failed attempts I finally got this green rectangle to drop in the top right and that's going to be the start of the first block but to see the block in 3d I had to get 3d camera working so that was my next task this is involved some pretty complicated linear algebra that would take me a while to implement on my own so I used another linear algebra library called C GOM to get the camera matrices in the right configuration for me and once that was working the last bit of housekeeping I had to do was getting textures to work so I'm not actually very good pixel artist at all but I decided in the spirit of the game to make some programmer art and I thought it turned out pretty ok what I was making here was something called the texture atlas for the sake of efficiency games like Minecraft stitch all of the textures for each block together into one big image like this called the texture atlas so that the render doesn't Efes what extras every time it draws a different block the renderer uses the atlas image by taking the offset of the texture for the block being drawn in the atlas and then mapping its pixel space coordinates in this 256 by 256 pixel image into the 0 to 1 UV coordinate space those are them the texture coordinates that are used for the block [Music] here we can finally see that working with a single grass block from there my next goal was to get multiple blocks drawn to the screen this involves a bit of infrastructure setup since it will be really inefficient to treat each blocks in individual and there needs to be some sort of subdivision system minecraft uses a system of chunking where each chunk is 16 by 16 by 256 blocks and I decided to do something similar after maybe an hour or so we can see that in action here with the small issue that we're still drawing faces on the inside of the chunk that aren't actually going to be visible to the player and you can see from this wireframe render how much extra rendering that is so it's pretty important for efficiency with the larger world that those extra faces are removed so I wrote a quick fix for that where each block face checks if the blocks neighbor in that direction is solid and if it is then the face doesn't render [Music] you can see the wireframe looks a lot better now and we're not drawing anything that the player isn't going to see from their audit was a good hour or so to get the world working with multiple chunks where extra block faces wouldn't dry in between chunks and then it's pretty simple to make the world infinite we just replace chunks that are further from the player with chunks that are nearer to the player as the player moves around in the world you can see that in action here as we fly away from far chunks they get replaced by ones that are near to the direction that we're flying and of course the next thing to do was to put together a few different block types and mess around with some world generation [Music] [Music] the last bit I wanted to finish before making this really look like Minecraft was making block breaking work this is done by casting array from where the camera is looking into the world and finding the coordinates and face of the first block that that ray intersects with and we can see block breaking and work here in this drawing that I made [Music] and to place blocks now that we know the coordinates and face of the block that the camera is looking at we can just place blocks on that face to test this out I had a sand block into the game so you can see it at work [Music] after that I could finally really dig into terrain generation generally the way procedurally generated games like Minecraft do terrain generation is through something called noise which is a function that takes in a specific number of parameters corresponding to its dimension in our case two and produces a random but smooth map of values in between negative 1 and 1 which can be mapped into terrain features [Music] in order to generate more than just a smooth heightmap techniques of layering noise like octave noise and combined noise can be used to produce more interesting terrain features like I made here I decided to follow after Minecraft classic in this respect and sample and layer noise the same way that it did because I thought it fit the vibe pretty well but the bright green grass and everything [Music] so I didn't use any real minecraft lighting in my clone but there is a quick hack that I wrote where I made the northern South faces of each block a different brightness than the east and west ones and the top and bottom this was done by giving each vertex some extra color information in addition to its texture information so when OpenGL is calculating the final color for each block vertex the vertex is multiplied by the RGB value of the texture and as you can see here that makes a big difference to how the terrain looks because we can see individual cubes now instead of just big masses of the state block the next thing that the terrain really needed was water water is actually pretty simple to add to the terrain generation we just pick a water level I said 64 blocks and then if the terrain height ends up being below that level we fill the rest up with water to that water level we can see here that that simple addition gives some pretty nice results but the one thing you're probably noticing is that the water isn't translucent and we can't see the ocean floor below it transparency and translucency are notoriously hard problems and 3d graphics but the first thing I had to do to get this right was to start separating out each chunks mesh into the solid geometry and the transparent and translucent geometry that way I could have two different sets of vertices that I could render differently the key to good looking transparency in 3d graphics is proper ordering you can see here how order matters we have four translucent squares and the left side the red one is on top of the green one and on the right side the green one is on top of the red one these different orderings give different colors where the squares overlap so it's important to make sure that the rendering order corresponds to the physical order of the squares this extends out into 3d space so we need to make sure that the player sees the correct ordering a block basis but that requires drawing all of the translucent faces from back to front relative to the player meaning they need to be sorted this can create issues in minecraft like games because there are so many different cube faces that it gets pretty expensive to sort them all every time frame needs to be drawn I made the mistake of trying to take a lot of shortcuts around this for performance reasons and none of them really worked out so here's view the best ones here we can see no water at all then a few minutes later whatever this is it clearly isn't working though the next attempt gave me an ominous looking black pillar then a weird sort of void world and then my personal favorite whatever this is and as the hours went by I got pretty close I got a few things working and I eventually ended up with a half solution like this you can see from the artifact in the chunk that the chunks are being rendered in the wrong order relative to the player so I needed to start rendering them from back to front sorted by their distance from the camera and you can see here I did finally get that working and then everything looked pretty good [Music] however the one problem I wasn't actually able to fix even with a few more hours of coding was that block faces also need to be sorted inside of each chunk so I had to leave that for the next day [Music] to start the next day I gave up on all of my shortcuts and decided on the proper sorting algorithm to sort the block basis by sorting every transparent or translucent block base inside of each chunk compactor front relative to where the camera was this solved all of my issues it did create a few performance problems initially so to combat the performance issues I came up with a few criteria of how when to sort the faces in each chunk the faces in the trunk the player is in are sorted whenever the player moves between blocks and the phases in the chunk the player is in in every chunk around that chunk are sorted when the player moves between chunks this leads to a good trade-off between proper transparency and actual playability and after around an hour of coding we can finally see that working I also added in some throttling so that only one chunk can change its mesh each frame this helps with making the game feel a little smoother and it's not really noticeable to the player from there I wanted to add some greenery into the world so I started to work on trees these are generated by giving every vertical column blocks that's in a Plains biome a five and a thousand chance of generating a tree trunk and some basic randomness like that generates a pretty nice distribution of trees throughout the world after that adding leaves onto trees is as simple as taking the position of the trunk and then building the cube of leezar path there is some extra variance in the corners of the leaves though just so that the world looks a little bit more interesting this is also about where my pixel artistry kind of falls apart so I spent some expert time trying to fix up the leaves texture and make it look a little bit nicer generating structures like trees though I started to encounter another really common issue with minecraft like games which is what should happen when a structure like a tree needs to generate leads across chunk borders but the chunk hasn't been loaded yet this can create issues like we see here where this tree has sort of just been cut off by a chunk order ended up going to the solution where the world keeps a list of blocks that have been set and chunks that haven't been loaded yet and then when each chunk is loaded it goes through that list and checks if it's had any blocks set before it was generated and once that was solved the world was filled with some pretty nice-looking trees the next thing I wanted to get working to give the world a little more life was animated water so the texture at was that the world uses is just a single static image that's used for every different block and even though this Atlas is static there's a trick that we can use to get animations for individual blocks the key is to duplicate the texture Atlas into the number of animation frames that we want and then make each version of the Atlas contain a different frame of each animated blocks texture in the same location on the Atlas if we number the animation frames for the water block on each texture Atlas and play them in sequence we can see what's going on by swapping out the texture Atlas five times a second like this the world doesn't need to change any meshes when the animation frame changes only the global texture needs to change so after some debugging I had that working and it looks something like this from there I thought I'd get flowers into the game which required some changes into the meshing code because flowers are sprites and not complete blocks this means that instead of making a textured cube where there's a flower the game generates a textured X shape that's dead and after adding flower patches into the world generator similarly to how trees are done this is what they look like I also decided one flower wasn't quite enough so I added in a second yellow one so the next thing I did was getting some more veins into the terrain generation and I decided I would add coal and copper these are generated pretty similarly to the way the trees are done except there's a random chance they'll be placed inside of each vertical column with blocks rather than on top the size is determined randomly and the likelihood that a block will be found decreases as the blocks get further from the center of the orbiting so here we can see some copper in the world and then after a little bit of flying around I also found some coal the next thing I did was to mitigate the popping effect you can see when flying around where chunks just sort of coming out of nowhere to do this added some distance fog into the world so the edge of the world will just kind of fade off into the sky and again I had a few funny-looking graphical glitches as I was trying to get this to work I think the effect ended up looking pretty nice though and it adds a lot to how the game looks as my time was wrapping up I added in lava pools with animated textures just like water and I fixed this up where liquid blocks were the same height as normal blocks it makes water and lava look a little better if they're a little below the height of regular blocks I also made water a little more blue to give it that classic Minecraft look and I really failed at trying to get a mountain biome into my game so instead I ended up adding in a couple of new blocks gravel and clay which can be found at generated randomly at the bottom of the ocean [Music] and the final thing I really needed to do was add in flock picking so I made the keys one through zero picked different blocks and gave it a quick try [Music] and then added in wooden planks so I could build myself a house and that was pretty much it I considered being able to build a house in my minecraft clone after a little over 12 hours of work a pretty big success so thanks for watching I know it's not exactly the most well featured version of Minecraft ever made but I think it's pretty good for just a couple of days work I'm included a link to the source code which I put up on github fair warning though it is a bit of a mess if you take a look at it anyway once again thanks for watching and goodbye [Music]
Info
Channel: jdh
Views: 795,373
Rating: 4.9561272 out of 5
Keywords: c++, programming, coding, minecraft, opengl, graphics, java, voxel, 3d, gamedev, gaming, code
Id: 4O0_-1NaWnY
Channel Id: undefined
Length: 16min 38sec (998 seconds)
Published: Sun Apr 26 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.