Jump to content

creating stone layers using WorldGenerator 1.10.2


Burpingdog1

Recommended Posts

Lately I've been working with WorldGenerator trying to replace stone below a certain y level  with a harder stone and I have been stuck for few days figuring out so decided to ask for help on here. 

public class WorldGen implements IWorldGenerator
{

	private WorldGenerator genDenseStone;
	
	public WorldGen() 
	{ 
		genDenseStone = new WorldGenDenseStone();
	}
	
	@Override
	public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator,
			IChunkProvider chunkProvider)
	{  
		
		switch(world.provider.getDimension())
		{
		case -1:
			netherGen(world, random, chunkX, chunkZ);
			break;
		case 0:
			overworldGen(world, random, chunkX, chunkZ);
			break; 
		case 1:
			endGen(world, random, chunkX, chunkZ);
			break;
		}
	}
 
	private void overworldGen(World world, Random random, int chunkX, int chunkZ) 
	{    
      
	}

	private void netherGen(World world, Random random, int blockX, int blockZ) 
	{  
		
	}
	
	private void endGen(World world, Random random, int blockX, int blockZ) 
	{ 
		
	} 
}
public class WorldGenDenseStone extends WorldGenerator
{

	
	@Override
	public boolean generate(World worldIn, Random rand, BlockPos pos)
	{    
		return false;
	}

}

 

the worldgen class for dense stone is default because I've been taking away code since it wasn't working guessing I don't really have a good idea how generating stuff works even at looking at some tutorials. I am bad at explaining, so hope you guys understand what i mean and can push me in the right direction

Link to comment
Share on other sites

You say you want to change all the stone below a certain Y-level to your own block.
If we are speaking more than 3-5 layers thick, the you will notice lag-spikes wherever you go, as using world#getBlockState and/or world#setBlockState is not optimized for large-scale operations.

If you look at the ChunkProvider/IChunkGenerators, they deal with worldgen in a more optimized way, though in a completely different context.

 

Depending on the amount of blocks you want to change, you might want to rethink how you are going to do it.
you may want to place down a new block that on random ticks, replaces all stone (and itself) within the chunk below your wanted level to this dense stone.

As such, you would only need to have your worldgen place 1 block in each chunk, and due to the random ticking, there will rarely be 2 chunks or more having their blocks changed at the same time.

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.

Link to comment
Share on other sites

Few questions, do you know any good tutorials that go in depth with world generation(Explains what chunkX/chunkZ is)? and can I use the ChunkProvider/IChunkGenerator variables in the generate method in the WorldGen class, or would I need to make a new ChunkProvider class? if so would I just use chunkProvider.getLoadedChunk(chunkX, chunkZ).setBlockState(pos, state);

Edited by Burpingdog1
Link to comment
Share on other sites

when loading new chunks the game freezes making me have to force close.. this is my code I used

public class WorldGen implements IWorldGenerator
{

	private WorldGenerator genDenseStone;
	
	public WorldGen() 
	{ 
		genDenseStone = new GenDenseStone(); 
	}
	
	@Override
	public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator,
			IChunkProvider chunkProvider)
	{   
		switch(world.provider.getDimension())
		{
		case -1:
			netherGen(world, random, chunkX, chunkZ, chunkGenerator, chunkProvider);
			break;
		case 0:
			overworldGen(world, random, chunkX, chunkZ, chunkGenerator, chunkProvider);
			break; 
		case 1:
			endGen(world, random, chunkX, chunkZ);
			break;
		}
	}
 
	private void overworldGen(World world, Random random, int chunkX, int chunkZ, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) 
	{   
		genDenseStone.generate(world, random, new BlockPos(chunkX, 30, chunkZ)); 
	}

	private void netherGen(World world, Random random, int blockX, int blockZ, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) 
	{  
		
	}
	
	private void endGen(World world, Random random, int blockX, int blockZ) 
	{ 
		
	}
public class GenDenseStone extends WorldGenerator
{
	
	
	@Override
	public boolean generate(World worldIn, Random rand, BlockPos pos)
	{    
		int x = pos.getX()*16;
		int yMax = pos.getY();
		int z = pos.getZ()*16;
		
		for(int a = 0; a < 16; a++)
		{
			for(int b = 0; b < 16; b++)
			{
				for(int c = 0; c <= yMax; c++)
				{
					if(worldIn.getBlockState(new BlockPos(a+x,c,b+z)).getBlock() == Blocks.STONE)
					{
						worldIn.setBlockState(new BlockPos(a+x, c, b+z), GCBlocks.denseStone.getDefaultState());
					}
				}
			}
		}
		
		return true;
	}

}

 

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.