So it has been quite a long time since i recreated minecraft over time i have done some refinements on my clone and now i feel confident enough to finally make a tutorial series and share the code of my rendition of minecraft’s terrain generation for this video i will show you how to Make the data generation of the terrain before we get into coding let’s understand how it works first so as a quick rundown we will first sample points from a purl and noise which is a pseudo-random pattern of floats across a 2d plane with the values sampled they will be used to deviate From a starting offset after those calculations we will start at the generated height and iterate down towards zero to assign the block types necessary to complete the chunk so without further ado let’s dive into the data generation for minecraft’s terrain so to start off create a new unity Project which i am already in and create a scripts folder in your assets and in that scripts folder create a new c-sharp script in it called the world generator after that is done attach the world generator class to a new game object in your scene called game master and once The script is attached open up visual studio now the first thing to do in our class is remove the update function and now create four variables the first variable will be a vector3 int which will store the size of the chunks that our world generator will use The second variable will be a vector 2 which will store the scale of the noise that will be generated the third variable will be a vector 2 which will store the offset of the generation on the noise algorithm and the fourth variable will be a three-dimensional integer array this is temporary but it Will allow us to see if the data generation is working as intended now in our start method initialize our three-dimensional integer array with our chunk size for the arrays different lengths after we initialize the integer matrix create a for loop which will loop from zero to the width of the 3d array minus One and in the for loop we created create another for loop which will loop from 0 to the depth of the 3d array minus 1. now in the nested for loop create two float variables one called purlin chord x and the other called purlin chord y Now initialize them the way i did it it is important to ensure that the values being used in this calculation are floats because if they remain as whole integer numbers the purlin noise function that we will use will remain the value 0.46527 after the creation of those two Temporary variables go to the top of the class and add in two more variables the first variable being an int which will be the height offset of the terrain and the second variable being a float which will control how intense the heights and depths of the terrain will be Set the default values of the height offset to 60 and the default height intensity to 5. now back in the nested for loop create a new int value and call this height gen and set it to be the following this line is the part where we will be using the Perlin noise function and we can simply just pass in the purlin chord x and purling chord y as the arguments after the height gen line create a new for loop in the for loop that is in the for loop holy crap this for loop will start at the height Gen value and decrement until it hits zero now this is where we can do some fun customization with this height variable we can iterate from the index of the height down to the lower build limit and set each coordinate to a specific block id of our choice This code below is what i believe is the default data generation for a plains biome in minecraft you can pause the copy it over into this for loop you created now the data generation code is complete to visualize the data you can use the on draw gizmos function provided by unity And iterate over each point of data in the 3d matrix and draw a wire cube with a specific color based on the block id in the data Now if we go back into unity and test our game we can see the different layers of blocks with that said that is my rendition of how the terrain data is generated in minecraft in the next video i’ll go over how the data is actually visualized using meshes to resemble blocks So if you’re interested consider liking and subscribing i’m trying to hit 1000 subscribers sometime near the end of 2022 but other than that i’ll see you all in the next video goodbye Video Information
This video, titled ‘How Minecraft Works | Chunk Data Generation [C#] [Unity3D]’, was uploaded by Rytech on 2021-12-28 18:52:32. It has garnered 8847 views and 243 likes. The duration of the video is 00:04:43 or 283 seconds.
In this video, I go over how I recreated Minecraft’s chunk data generation. This series of ‘How Minecraft Works’ will go over how I recreated many features of Minecraft on my own, and the code behind it so you can learn from the process.
Join my Discord! ► https://discord.gg/jrRJgfBz2y
-= Music =-
***************************************** Music: Dopamine Artist : DZGRIMX link to the video: https://youtu.be/3S6uyNk9HpY channel: https://www.youtube.com/channel/UCBhW… *****************************************
Operatic 3 – Vibe Mountain