Jump to content

Recommended Posts

Posted

I did some research on how to prevent chunks from loading that shouldn't be loaded yet(caused by world generators generating across the edge of a chunk). So far what I have found is that usually, the generation is offset into the middle of the chunk.
But I need to generate structures bigger than a chunk. How do I do that? I considered using isChunkGeneratedAt(). However, for big structures, I would then need to offset generation far into chunks that were already loaded a long time ago, giving the impression that the structure simply "popped up". There has to be a solution to this. Of course I already checked Minecraft Village generation, but they all seem to have chunk-sized structure components. The only thing that is close to what I want to do is the Mansion, but it

 is a pain to understand it because of the insane amount of pieces it uses.

Posted (edited)

Well, the difficulties you're facing are pretty typical. If you try to only generate the portion of your structure in the loaded chunk there is potential that when the next chunk is generated that it isn't suitable for your structure. With smaller structures it kinda works because the village houses can be on a hillside or something, but it can look strange if your castle is halfway into a cliff or something. But like you said you can't wait until all the chunks are loaded to check for suitabiliy because then the structure will sort of "pop up" as you said.

 

And also, it is true that there are vanilla structures to look at but the code is kinda complicated. Also, depending on the structure it may not always make sense to break it up in same way as vanilla.

 

One solution could be that the generation of the chunk depends on whether there is a structure rather than the other way around. Like lets say the natural generation happens and then eventually provides a suitable place to start your structure. Well, then the next chunk maybe shouldn't be fully "natural" generation. Instead you can control it so you know it is suitable for the remainder of the structure. Basically prevent it from creating an ocean, lake or mountainside in the way of the structure you need to create. In fact, if parts of your structure cover a whole chunk, you could basically make sure that that chunk is generated as a "flat" structure.

 

Another solution was whenever you find a place that might be suitable for your structure to start, that you force the generation of the addtional chunks and then only build your structure if the overall area is suitable for it.

 

Overall, there isn't really a good general way to generate a structure because it really depends on the structure. For example, if your structure is very regular and symmetrical you might be able to generate it with a formula, but if it is very intricate and asymmetric then you will need to generate it block by block from a blueprint. If some parts of the structure are repeated then you will want to break it up into smaller pieces. If the structure has a lot of randonmess you will have to figure out how to ensure it all fits together. And so forth.

Edited by jabelar

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

Posted (edited)

I had a similar issue in one of my mods, trying to streamline snow/grass/sand/clay generation, with their location being determined by a noise-generator (hence I would have no control over chunk boundaries)
What I ended up doing, is creating a placeholder block, that when randomly ticked (which should provide ample time for the chunks around it to get generated) would first check the environment, and then act accordingly, and here, the first one to tick would replace itself and several others within range to the mentioned blocks.

What I'm trying to say here is, a single block placed during worldgen, and then "activated" afterwards, would perhaps be the best option to the "bigger than one chunk" issue.
Once it is activated, it checks if it can actually do everything. If it cannot, well, then it can just replace itself with air.
If it can do something, which here would be to build something, well, then time to pack up, cause it's settling in. (eg, start building)
Perhaps have the block contain a TileEntity that can perform higher logic, like "place x blocks per tick" to make the strain even less.

Edited by Matryoshika

Also previously known as eAndPi.

"Pi, is there a station coming up where we can board your train of thought?" -Kronnn

Published Mods: Underworld

Handy links: Vic_'s Forge events Own WIP Tutorials.

Posted

While having a placeholder block can definitely simplify the generation logic, I don't think it helps this particular issue. The problem here is that he didn't want the structure gen to force the load of a chunk, but without loading the chunk you won't know if the next chunk is suitable for continuing the structure. You'd have the same problem with your placeholder block -- it wouldn't be able to generate the structure even on the next tick because the next chunk wouldn't necessarily be loaded. 

 

There is really only three possible strategies. 1) When a chunk seems suitable to start a structure go ahead and force the additional chunks to load and then determine whether the overall area is suitable for your structure, 2)  You can make the presence of the start of your structure force the next chunks to be suitable, 3) design your structure so it kinda works in all possible cases -- like can extend into the ocean or into a mountainside or ravine, etc.

 

I kinda like strategy #2 in terms of liking creating the best result (because the surrounding chunks will be purposefully generated to be suitable).

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

Posted

If you are in a chunk, you can be absolutely sure that the chunk +X and +Z exist. You cannot be sure that -X or -Z exist.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Well, I've been working on the same program.  My main mod (Doomlike Dungeons) does this all wrong, intentionally generating the whole thing across a huge area -- mostly because that's what I could figure out easily as a new modder back in 2014 and didn't think about the consequences.  I've been working out a new system for a sequel (since core parts like this are too broken so start over would be easier).

 

My plan, if it works, is very simple, though it requires slightly more complex data structures to store the structure.  Split the structure up into many structures along chunk boundaries and build only the part that is in the chunk being generated.  I don't know how well this will work with what you are trying to do, but that is how I would (hopefully) will do it.

Developer of Doomlike Dungeons.

Posted (edited)
2 hours ago, JaredBGreat said:

My plan, if it works, is very simple, though it requires slightly more complex data structures to store the structure.  Split the structure up into many structures along chunk boundaries and build only the part that is in the chunk being generated.  I don't know how well this will work with what you are trying to do, but that is how I would (hopefully) will do it.

That's honestly the easy part, the difficult part is knowing whether the additional chunks that aren't generated yet will be suitable for your structure. imagine you start generating a big castle and then the next chunk ends up being a mountainside or ocean or ravine. As Draco18s says, the chunk +1, +1 is generated so you can check its suitability but I expect some people need to span even more chunks than that.

 

I think the easiest solution is to simply accept that Minecraft sometimes generates some weird stuff and do your best to have the structure work in all situations. Vanilla villages often generate on some weird hills, but that is fun when it happens. To do this approach you can make your structure also include the blocks underneath and above so that if it does end up getting generated in the middle of a lava lake it basically creates an island for it to be on, and if it gets generated in a mountain side it sort of chops out the mountain above it.

Edited by jabelar

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

Posted (edited)

Ah, I'm use to building huge things, but always underground.  For things on the surface I have only vague ideas -- I've toyed with the idea of building biome-sized cities and roads that stretch 1000 blocks for one mod idea, but never actually tried it or worked a precise system for doing that, or any really good ideas, really.  Oh well, I tried to help.

 

But for many structures I'm quite happy to have them half-burried, etc.  -- though for a ravine I might just put a foundation under the castle, or similar, so it will either reach the bottom of believable bridge it.

 

For the technical issue of just avoiding generating chuck it simple, but yeah, if you really want to check the terrain it would get harder.

Edited by JaredBGreat

Developer of Doomlike Dungeons.

Posted (edited)

While developing the structure generation system for my mod I had the same problem. I solved it with a pretty complex system involving a chunk cache.

It is not really completed yet, but maybe it helps you anyway. My mod replaces the vanilla (overworld) ChunkProvider with a modified one.

Source on github (my mod changes some other worldgen related things too, sorry if it is hard to read or understand the code)

 

How it works:

- Structure data is saved in NBT format (similiar to vanilla structures) and loaded on server start

- When a chunk is generated, it checks for suitable positions based on the conditions saved in the NBT data, for example a block at a specific position in the structure needs to be grass or dirt. If all conditions match, it adds the position to my StructurePositionMap and generates it in the world later during chunk population, chunk by chunk. StructurePositionMap source

 

The problem: What happens when the condition block that needs to be checked is in a chunk that is not generated yet?

My solution:

If the chunk that needs to be checked has not been generated yet, the ChunkProvider just 'pre-generates' it and stores it in a cache, like this (ChunkProviderDoomed.getChunk) :

 

public Chunk getChunk(int x, int z) { // called when checking structure conditions
		if (world.getChunkProvider().isChunkGeneratedAt(x, z)) { // if chunk is already generated, just retrieve it (vanilla)
			return world.getChunkFromChunkCoords(x, z);
		} else { 
			long c = ChunkPos.asLong(x, z); // if not, try to get it from our own chunk cache
			if (chunkCache.containsKey(c)) { 
				return chunkCache.get(c); // if it is cached, return it
			} else {
				return this.preGenerate(x, z); // if not, pre-generate it and put it into the cache
			}
		}
	}

 

Then it performs the checks, and later when the chunk is actually generated by minecraft it just retrieves the chunk from the cache instead of generating it again:

public Chunk generateChunk(int x, int z) { // (override: ChunkProvider)
		Chunk cached = getChunkFromCache(x, z, true); 
		if (cached!=null) { // if chunk has been pre-generated, we dont need to generate it again
			this.createVanillaStructures(x, z, null); //create vanilla structure data, everything else is already done
			this.createStructures(x, z);
			return cached;
		}
		return this.generateChunk(x, z, false); // if not, generate it normally
	}

 

However, I cant tell if this causes problems with vanilla structure generation (not tested yet)

But so far, it worked for me without any problems or lag.

 

I hope it helps :)

 

 

 

Edited by m00nl1ght
updated github links
  • Like 1
Posted

I think I will somehow manage to prevent weird looks on my Gens, by checking corners and altering terrain. The only issue I really have problems with is lag prevention. Look at for example how my Fortress Generator works(I hope it is on Github). Thanks for all the replies

  • Like 1
Posted
On 2/6/2018 at 8:22 AM, jabelar said:

I think the easiest solution is to simply accept that Minecraft sometimes generates some weird stuff and do your best to have the structure work in all situations. Vanilla villages often generate on some weird hills, but that is fun when it happens. To do this approach you can make your structure also include the blocks underneath and above so that if it does end up getting generated in the middle of a lava lake it basically creates an island for it to be on, and if it gets generated in a mountain side it sort of chops out the mountain above it.

 

Just ran across this example after reading this. :D

2018-01-30_23.05.03.png

  • Like 1
Posted (edited)

 

 

I created a different-from-vanilla system now. I looked up some source code from other mods and saw that they raise terrain additionally to world generation. I have a custom ChunkGenerator that

uses completely different height generation than Vanilla, so my conditions are a bit different. Basically, what I planned/already did until now was:

 

-Create ModStructure, quite similar to the Vanillas' structure start. 

-Create ModStructureType, determining how to generate in specific ModStructure instances.

-Have a List in my ChunkGenerator that holds all ModStructure instances.

 

Planned:

- Call generate() for all structures in the list

-Precalculating which chunks will be needed for the structure, so that I can raise the terrain. I think this will be the hardest part. Another idea: Raise terrain for each structure piece.

-Generating the structure itself on the terrain!

 

These are some screenshots of my dimension. As you can see, single fortresses spawn quite well, but I don't think this will be the case for other structures.

https://imgur.com/a/MWPHS (Somehow Uploading won't work)

 

 

 

Edited by ArmamentHaki

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.