Jump to content

[1.7.10] Help with structure generation


graywolf69

Recommended Posts

I am making a structure that I want to randomly generate in minecraft. I was following a tutorial, but when I tried to run the game and make a new world, it froze while "building terrain". I closed mc, commented out the line where it generated the structure, and tried it again. When I opened the world, I saw that it had generated structures on top of eachother, basically carpeting the world with my structure. How can I change my code to make it more rare? Here is my structure: http://pastebin.com/9h4ek94g And here is my world gen file: http://pastebin.com/iwvdakTK. The tutorial I was following said to change this line to make it more common/rare, specifically the 10: for(int l = 0; l < 10; l++). How do I fix this, and narrow it down to about 4 per biome (Only spawns in plains) so that I can find it quickly in testing? Thank you for any help you can give, I am new to modding!

Link to comment
Share on other sites

You just have to think through the math and logic to understand it. In this case there are two things wrong. In the for loop the number 10 represents how many structures will generate per chunk. So in this case you're getting 10 per chunk. There is randomness in the position but not in the generation so I think there will always be 10 per chunk.

 

Next you need to consider the size of your structure. A chunk is only 16 x 16 (x and z) and it looks like your structure is around 35 x 35. So your structure can't even fit into one chunk! So you definitely don't want 10 per chunk...

 

Instead what you need to do is to use a random chance of even calling the spawn so it is only called every several chunks. I'm not sure what the average biome size is, but I feel it is something like 20 chunks per side or something like that. So that means 400 chunks per biome and you want 4 structures per biome so you want a 1 percent chance of generation per chunk.

 

So I would get rid of the for loop entirely -- you definitely don't want multiple per chunk. The spawn function should just be called if a rand.nextInt(100) < 1 (gives 1 percent chance).

 

I hope you understand my points...

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Thank you, it works (sort of)! one problem after another in modding. I found the structure... well, bits of the roof at least. It spawns submerged in the ground, and also the ground overrides the structure (as in, the structure is generated, and then the ground is generated, replacing the structure). Is there something I can add to my code to make it only spawn on top of the ground, and also a way to make it generate after the ground (i.e. if it needed to, it would replace the ground instead of the ground replacing it). Thank you for your help so far!!!

Link to comment
Share on other sites

I haven't done a lot of world gen stuff. I've done a lot of structures, but only as something that appears later in the game -- like is auto-built by an item. So I'm not sure how to control the order.

 

But generally, in terms of being on top of the ground, you need to think through the logic of your code -- currently you just set a Y height for the starting point randomly. Obviously that could have some weird effects. So the Y should not be random.

 

I know that after things are generated, there is a getHeightValue() method in the World class which gives you the position on the top of a x, y position.

 

Putting this together, assuming your structure is generating after the ground, you would pick a random x and random z but then set y to be world.getHeightValue(x, z).

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Since you are using IWorldGenerator, I assume you are registering it to the GameRegistry and letting that handle it? In that case, you need to give it a higher 'weight' so it generates later, but I prefer to call my world gen code for structures personally from PopulateChunkEvent.Post rather than using the normal IWorldGenerator.

 

The reason for that is that PCE.Post is called AFTER all other gen code, and the IWorldGenerator is, I think, mainly intended for things like ore gen, not necessarily structures.

 

Another consideration is that you'll want to make sure you generate your structure entirely within the chunk that is currently generating - if you spill over into other chunks, it is possible that the chunk has not yet loaded and you will cause it to load, but since it didn't exist yet that entire portion of your structure may be missing or overwritten by the chunk as it loads.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.