Posted March 17, 20178 yr 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
March 17, 20178 yr If you want your WorldGenerator to do something, you need to put code in the generate method. In your case, code to find stone blocks below a certain height and replace them with your block.
March 17, 20178 yr 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 March 17, 20178 yr 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.
March 17, 20178 yr Author 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 March 17, 20178 yr by Burpingdog1
March 18, 20178 yr Author is there an example of how to use ChunkProviders/IChunkGenerators? Through my googling all I found was tutorials using WorldGenerator
March 18, 20178 yr Author 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; } }
March 18, 20178 yr Author Alright, guess first time I read it forgot the offset part... so I offsetted the x/z values by 8 and it works great! Thanks, now what is the best way in making it gradually turning into the dense stone instead of just going straight to dense stone after y<=30
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.