I Coded Minecraft in *Only* 3 MONTHS!!!!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so i decided to do something that's never been done before yep that's right i recreated minecraft [Music] now you may be thinking why in the world would you attempt such a feat it's impossible and i would agree with you in fact this was a huge headache in all seriousness why would i recreate something that a million other people have already recreated well i felt like everyone who had recreated minecraft just didn't do it justice it's not that their clones were inferior than mine but they really are just kidding but they didn't do some of the more gameplay-feeling stuff what i mean by that is they implemented a lot of the basic mechanics and then stopped they didn't add menus they didn't add debug statistics they didn't add saving and loading screens all that type of stuff so i decided i would implement all the parts of minecraft you know except all the hard stuff so here's how my journey went the first piece of any good minecraft clone puzzle is rendering a square this ended up taking me a lot longer than i thought it would have taken but eventually i got a square up on the screen and since this is a minecraft clone i decided to make it all minecraft like and added a grass block texture unfortunately i lost all the footage for this stream so here's the end result next i need to be able to place any old block texture in the game this can be done a huge number of ways but i decided to just do the stupidest simplest method out there which was to patch all the textures together into one big giant image it ended up looking like this this part wasn't that difficult but i don't like making my life easy so i had to make it more difficult i want it to be super easy to add new blocks into the game in the future so i came up with the most clever block creation scheme ever i call it yaml actually i didn't really come up with this basically you can just write up a description of the block put whichever textures you want to use in here add a few other details and bada bing bada boom you got your new block we've got squares and textures so we basically have minecraft right wrong minecraft needs a 3d player controller so i went ahead and wrote some super clever code that i stole directly from a website and next thing you know i've got a 3d player controller of course it never works right the first time anyways i fixed that up and thought to myself squares are great but what if we had cubes cubes are pretty simple in theory they consist of eight vertices which are just the different corners of the cube i also have to attach some extra data so the program can figure out which texture to apply to which face and once that's all figured out well you got a cube this took me way longer than it should have because i was over engineering the crap out of it i eventually got there in the end and i made this giant chunk of cubes now that we have cubes we need to create chunks and cull the interior faces you see if we just draw all the interior faces of the cubes the gpu does a lot of unnecessary work and ends up lagging horribly so we can just say hey computer if there's a block next to me don't draw that side and that's basically the process i take now there are some gotchas like if you have a glass block you clearly want to draw the side of the cube but those are pretty easy to add in once we get this done now we can save some gpu work and we can go ahead and generate a bunch of chunks now let's just apply some simplex noise and now we have terrain now we're getting places the next thing that would be nice to do is add chunk serialization and deserialization this is basically the process of saving and loading a chunk since i coded this in c plus and stayed pretty close to the hardware i can literally dump the raw binary straight to a file and then i just load that raw binary back in now we can save and load chunks this is great but i was running into some horrible lag issues and my program was using you know 30 gigabytes of ram for a 12 chunk radius so i had to fix that over the process of a couple weeks i added some horribly over engineered multi-threading and some janky vertex compression i basically stole hopsin's idea of compressing chunk data into a couple bytes per block which brought my ram down to like four gigabytes and then i added multi-threading to speed things up a bit what's next on the list well we need a way to handle entities we need a method of storing several entities in our world and having a way to iterate over those entities that have some features we're looking for for example our physics wants to find all the entities that have box colliders so it asks for those and it does some physics stuff i used something called an entity component system for this and added a quick and dirty method to add entities like players to the game with this in place i could add physics physics is harder than it looks well actually physics looks pretty hard but i won't bore you with the details i basically needed a way to stop the player from falling through trunks and a way to raycast into the world to see what the player's looking at so i eventually settled on a couple of methods i liked and was able to add some simple physics next up font rendering and hud stuff like i said before i wanted to add in the ability to do menu stuff that a lot of people didn't add in their clones so i had to code up a simple font render that basically loads a font on your pc generates all the glyphs puts them all in a texture so that i can display text to the user now i had some text alignment issues and everything but i eventually got it all sorted out now i can make menus and buttons and all that good stuff it's actually starting to feel like a game [Music] at this point my pc was just crying for some help the way i initially coded this wasn't the best basically i would calculate all the chunk stuff on the cpu then copy and transfer that to the gpu once it was ready and this was just horrible for performance and wasted a ton of ram i implemented this thing called opengl as do which basically allows me to ask the gpu for some pinned memory once i get a hold of this memory i can write to it as i please and it will automatically initiate a dma transfer when necessary and now the gpu just has the data it needs this sped things up and reduced my overall ram usage to around one gigabyte for a 12 chunk radius not too shabby next i decided to move on to more important things like hot bars commands and light coating up a hotbar was pretty quick and easy since i had all the other gui stuff done but i really wanted to add minecraft lighting into the mix now minecraft lighting is actually a lot harder than i thought it would be and i'm still trying to get it working really good the basic idea is simple enough in minecraft if you have an air block it gets a light value from 0 to 15. it generates its light value based on the blocks around it it takes the highest level around it and subtracts 1 from that if it has direct access to the sky then it automatically gets a light level of 7 to 15 depending on the time of day i spent so long trying to get this work just right it turns out i was using the wrong approach the whole time i was trying to calculate all the lighting at the same time and store sky levels and light source levels in the same memory turns out this was a dumb idea because it leads to all sorts of weird problems trying to figure out what a light level should be so instead i found a great article that stored the sky levels separately from light source levels this means that you can calculate all the sky levels once and as the day turns into night you don't have to do any fancy updates but can just take the sky level or the light source level for that specific air block you just choose whichever one is higher around this time i added in some cube maps which made the game feel much more like minecraft after that i added some proper command line parsing which was pretty quick and painless i basically just store a bunch of commands in the code and if anybody ever types in something that matches one of those commands i check if they passed in the proper arguments and stuff and that's basically where i'm at as you can see you can join a world play around in the world place blocks ad blocks place light sources and all sorts of stuff i plan on adding support for multi-colored lights crafting inventory management multiplayer support 3d models mobs and some more stuff if you're interested in seeing me code this in real time you can check out my twitch at twitch.tv slash games wthgate and if you want to download this clone you can download it in a link in the description i will warn you it will most likely crash but it won't break your computer at least i hope it won't i might post another video on youtube in the future with some updates if you want that and if this video gets like 10 000 likes i'll create some tutorials on how you can create your own minecraft clone using whatever language you want just kidding i'll be making those tutorials no matter what but you can still like this video anyways if you enjoyed this video please leave a like and subscribe and i will see you guys next time is [Music] you
Info
Channel: GamesWithGabe
Views: 74,711
Rating: undefined out of 5
Keywords: gameswithgabe, games with gabe, coding minecraft, how to code minecraft, how to program minecraft, technical minecraft, how to make a minecraft clone, c++, game programming, order independent transparency, opengl azdo, opengl, minecraft lighting, serialization, physics, 3d player controllers, program minecraft, voxels, coding voxels, how to program a game, how to code, how to code a game
Id: sMs28KxbHiA
Channel Id: undefined
Length: 8min 56sec (536 seconds)
Published: Mon Nov 15 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.