Jump to content

[1.14.4] [SOLVED] Replace a Block on World Gen


gendeathrow

Recommended Posts

I'm attempting to replace water with a custom block based on its biome. But seem to be having an issue figuring out the proper way to handle this in 1.14.  I believe earlier versions had an event for population. But am unclear of a way in 1.14 I never messed with world gen in the earlier versions, but looks like its changed in 1.14 from what I can tell. Any help to some reading material or examples would be great. 

Edited by gendeathrow
Link to comment
Share on other sites

Yes, it changed. Worldgen is threaded now.

You have to create a Feature and register it with each biome (biome.addFeature(...)) you want it to appear in. Note that it is more complicated than that, as Features require a FeatureConfig class. NoFeatureConfig does exist if you don't need anything special.

 

An example:

https://github.com/Draco18s/ReasonableRealism/blob/1.14.4/src/main/java/com/draco18s/harderores/world/HardOreFeature.java#L16

 

I recommend at least looking over how vanilla uses these classes and their methods.

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.

Link to comment
Share on other sites

Hey appreciate you getting back. I had sort of looked at the features, but was not be entirely sure if a feature was even meant to replace all blocks of a certain type in a chunk. Last thing I want to do is cause unnecessary lag during world gen; Seeing that when messing with world gen, its an easy possibility to do. I think this helped me understand a bit more though. I will post back up here after I play around with a few things. 

Link to comment
Share on other sites

Just to give an updated on this. I did finally get the block to replace other blocks. This is more of a demo than what I'm actually doing. Replacing water with a new type of water does not have the intended effects that I would like. As I think it breaks some of the game mechanics now. I will still play around with it. But the code for anyone else that would like to try this for their projects.  This doesn't feel like the most cleanest way of doing it. Seems a bit heavy scanning each block in a chunk again. But it works.

 

public class FluidGenReplace extends Feature<NoFeatureConfig> {

	public FluidGenReplace(Function<Dynamic<?>, ? extends NoFeatureConfig> configFactoryIn) {
		super(configFactoryIn);
	}

	public static Block fromBlock = Blocks.WATER; // change this to suit your need
	public static Block toBlock = Blocks.SLIME_BLOCK; // change this to suit your need

	@Override
	public boolean place(IWorld worldIn, ChunkGenerator<? extends GenerationSettings> generator, Random rand,
			BlockPos pos, NoFeatureConfig config) {


			IChunk currentChunk = worldIn.getChunk(pos); // get Chunk
			int startX = currentChunk.getPos().getXStart(); // get starting X of chunk
			int startZ = currentChunk.getPos().getZStart(); // get starting Z of chunk
			int endX = currentChunk.getPos().getXEnd(); // get ending X of chunk
			int endZ = currentChunk.getPos().getZEnd(); // get ending Z of chunk
			int startY = 0; // get starting X of chunk (In this case 0)
			int endY = worldIn.getSeaLevel(); // get ending X of chunk (only replacing up to sea level to reduce amount of scaninng. )

			for (int x = startX; x <= endX; ++x) {
				for (int z = startZ; z <= endZ; ++z) {
					for (int y = startY; y <= endY; ++y) {
						BlockState state = worldIn.getBlockState(new BlockPos(x, y, z));
						Block block = state.getBlock();
						if (block == fromBlock) {
							worldIn.setBlockState(new BlockPos(x, y, z), toBlock.getDefaultState(), 2);
						}
					}
				}
			}
		return false;
	}

}

 

 

 

Edited by gendeathrow
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.