- Joined
- Sep 6, 2020
- Messages
- 362
- Reaction score
- 95
So what makes generating terrain in 5.2 so much easier? Well it's mainly based on Repeat: On Grid. In simple terms, this just repeats across each block in a grid, setting a variable to the location that it's on each iteration. Now instead of having to use 2 perlin noises, basic terrain gens only require 1! On a lesser note, 5.2 has also introduced Processes. These are like functions, but they run asynchronously. In this case you can use either a process or function, however if you want to generate your terrain and run code at the same time a process is what you need to use.
To start of just place down a Player Event: Join and set their gamemode to creative using Player Action: Set Gamemode. It's also worth setting the player's spawn high up so that they don't suffocate. Then place down a call process and process called "terrainGen". You should have something that looks like this:
Inside your process is where all the terrain generation will happen. Before placing down the repeat, we'll need to generate a seed; simple Set Var and %random(1,9999999) will work. The seed is what determines how the Perlin Noise will generate. You can chose to have this as a set value though if you want to generate the same terrain every time. Next up place down your Repeat: On Grid. Inside the chest you'll need to place a Local Dynamic Variable (I just used currentLoc), and 2 Location Variables. These location variables should be at opposite corners of your plot, at about Y-Level 65. You should have this:
Now inside of your repeat place down a Set Var: Perlin Noise (This is located inside of Advance Actions). So what is a Perlin Noise? A visual representation will probably help the most:
It's basically a heat map that allows us to simulate different elevation and terrain. The function itself requires quite a bit of parameters that you can tweak if you want, however the default values work fine for a basic terrain gen. Though I'm sure someone else could explain what each individual parameter does better than me.
Variable: Perlin Noise returns a value between 0 and 1 (Regarding the Perlin Noise image, the darker areas are higher numbers and lighter areas lowers numbers. Starting to get it?) This will be the variable that we can use to determine the Y-coordinate of our location.
Location: The location in the Perlin Noise map, for this we will use the dynamic location variable in the Repeat: On Grid (for me it was currentLoc).
Frequency: This is how close together the different "patches" will be. We can leave this as 1.
Octaves: This will affect the amount of layers of Perlin Noises there will be, thereby affective how blurry/fine the final map will be. For this 1 is fine.
Octave Frequency Gain: This is how close together the octave layers will be to each other. The default is fine.
Octave Amplitude Gain: This is how extreme the values will change. 0.75 is fine, however if you want flatter lands then higher numbers are better.
Seed: This is the seed variable that we set beforehand.
Fractal Type (tag): These are just different ways of generating the perlin noise. You can leave these alone for now.
Inside of this you should have this, keep in mind that you need all of the number variables so that the game doesn't think that the seed is the frequency:
Alright nice, next up we need to convert that Perlin variable into something actually usable. Place down a Set Var: Shift Axis, and inside of it place down your "currentLoc" and a number variable. So at the moment our Perlin Noise variable will just be some random number between 0 and 1 (e.g 0.562). If we were to set the block as it is now, DF would just set a line, as it's all on one Y coordinate. All we have to do is just multiply that variable by a number, 18 worked for me, and shift our "currentLoc" by it. So the number variable will be %math(%var(perlinNoise)*18). Make sure that the tag in the bottom right is set to Y and not X.
All that's left to do is just place down a Game Action: Set Block, and inside of it just put a Grass block and your "currentLoc"! And you should be left with this:
Now just run your code there you go! Regarding the wait, at the moment it's quite slow so implementing a ten-tick wait could probably work. Here's an example of a terrain that was generated by this:
Links
In case you want to do some further work, I'll give some links that give you further insight into Minecraft's terrain generation system.
Structures
Complex Overview
Blog Post By Notch (2011)
Biome Borders
Making Maps with Noise Functions
Part 2 Below!
To start of just place down a Player Event: Join and set their gamemode to creative using Player Action: Set Gamemode. It's also worth setting the player's spawn high up so that they don't suffocate. Then place down a call process and process called "terrainGen". You should have something that looks like this:
Inside your process is where all the terrain generation will happen. Before placing down the repeat, we'll need to generate a seed; simple Set Var and %random(1,9999999) will work. The seed is what determines how the Perlin Noise will generate. You can chose to have this as a set value though if you want to generate the same terrain every time. Next up place down your Repeat: On Grid. Inside the chest you'll need to place a Local Dynamic Variable (I just used currentLoc), and 2 Location Variables. These location variables should be at opposite corners of your plot, at about Y-Level 65. You should have this:
Now inside of your repeat place down a Set Var: Perlin Noise (This is located inside of Advance Actions). So what is a Perlin Noise? A visual representation will probably help the most:
It's basically a heat map that allows us to simulate different elevation and terrain. The function itself requires quite a bit of parameters that you can tweak if you want, however the default values work fine for a basic terrain gen. Though I'm sure someone else could explain what each individual parameter does better than me.
Variable: Perlin Noise returns a value between 0 and 1 (Regarding the Perlin Noise image, the darker areas are higher numbers and lighter areas lowers numbers. Starting to get it?) This will be the variable that we can use to determine the Y-coordinate of our location.
Location: The location in the Perlin Noise map, for this we will use the dynamic location variable in the Repeat: On Grid (for me it was currentLoc).
Frequency: This is how close together the different "patches" will be. We can leave this as 1.
Octaves: This will affect the amount of layers of Perlin Noises there will be, thereby affective how blurry/fine the final map will be. For this 1 is fine.
Octave Frequency Gain: This is how close together the octave layers will be to each other. The default is fine.
Octave Amplitude Gain: This is how extreme the values will change. 0.75 is fine, however if you want flatter lands then higher numbers are better.
Seed: This is the seed variable that we set beforehand.
Fractal Type (tag): These are just different ways of generating the perlin noise. You can leave these alone for now.
Inside of this you should have this, keep in mind that you need all of the number variables so that the game doesn't think that the seed is the frequency:
Alright nice, next up we need to convert that Perlin variable into something actually usable. Place down a Set Var: Shift Axis, and inside of it place down your "currentLoc" and a number variable. So at the moment our Perlin Noise variable will just be some random number between 0 and 1 (e.g 0.562). If we were to set the block as it is now, DF would just set a line, as it's all on one Y coordinate. All we have to do is just multiply that variable by a number, 18 worked for me, and shift our "currentLoc" by it. So the number variable will be %math(%var(perlinNoise)*18). Make sure that the tag in the bottom right is set to Y and not X.
All that's left to do is just place down a Game Action: Set Block, and inside of it just put a Grass block and your "currentLoc"! And you should be left with this:
Now just run your code there you go! Regarding the wait, at the moment it's quite slow so implementing a ten-tick wait could probably work. Here's an example of a terrain that was generated by this:
Links
In case you want to do some further work, I'll give some links that give you further insight into Minecraft's terrain generation system.
Structures
Complex Overview
Blog Post By Notch (2011)
Biome Borders
Making Maps with Noise Functions
Part 2 Below!
Last edited: