To get started go to the scripts folder and make a new script called structure generator once Unity is done compiling attach the structure generator onto the game master object once that is done open up visual studio to edit the structure generator and the structure generator class add in The following class the offset from o Point represents the Delta from a given point in a chunk of data where o means origin of the structure root in a given chunk the type to assign stores the block type that will be assigned to the origin of the structure root plus the offset from The origin next up add in the following variables the structure info array will store data of a specific structure that an instance of the structure generator will be responsible for creating and the Gen threshold will store the smallest number that the random gen variable below will have to generate in Order for the structure generator to make an instance of a structure after the variables in an awake method initialize the random gen variable if you’re wondering why system.random is being used over Unity engine.random system.random is thread safe now create a new function called apply structure what this function does is iterate over The structured block info array get the chunk chords of the block that will be changed to the iterated structure block after that the function will attempt to assign the given structure block info block type to the chunk cords of the block that is meant to be changed if the Assignment throws an error saying that the point generated is not within the array bounds then the position generated will be converted to World coordinates the world coordinates will then be used to get the new chunk coordinates and will be converted back to local coordinates using the new chunk coordinates After that a dictionary that will be declared in the world generator will be used to dump the out of bounds chunk data to be applied to Natural generation when the time comes for the given chunk data now in the world generator class let’s make the additive World data dictionary We will also have to change the private access modifiers on the utility functions we made earlier so no more access errors will be thrown now back in the structure generated class add in the following functions the get top block from data XZ will determine the root position of a structure to be generated And the generate structure function is the function that will be ran in the process of generating a new chunk this is the part that actually determines whether or not a structure will be generated at the currently iterated XZ position once that is done the structure generator is complete now it is time to Make some changes to the data generator class in the data generator class have the Constructor taken an instance of the structure generator that is stored in a variable now in the generate data core routine add in the following changes the first change applies additive data if it exists so structures are whole and Seamless a quick check if the current block being iterated over is an error block will prevent structures from being overwritten and the generate structure function is called on the data generators structure generator instance if it exists with that done the changes to the data generator is complete now back in the World generator all that needs to be done is have the second argument of the creation of the data generator via get component call for an instance of a structure generator and with the line finish the implementation of structures is complete all that needs to be done is to go back Into Unity add in some block info in the structure generator and mess around with the Gen threshold and when you feel happy with the changes if you press play you’ll see structures being generated with customizable data thank you all for watching and I hope to see you all in the next video goodbye Video Information
This video, titled ‘Minecraft Structure Generation in 4 Minutes [C#] [Unity3D] | How Minecraft Works Pt. 8’, was uploaded by Rytech on 2022-10-29 14:30:48. It has garnered 1153 views and 38 likes. The duration of the video is 00:03:40 or 220 seconds.
Join my Discord! ► https://discord.gg/jrRJgfBz2y Tutorial Github ► https://github.com/Rytecc/How-Minecraft-Works-Tutorial-Series -= Other Stuff =- #unity3d #unitytutorials