Posted January 14, 201510 yr I have two generators that run using identical code (aside from the set block state). The generator that runs first is working fine, however, the generator that runs second will not spawn the block ever, every block it tries to spawn in has already been populated by the previous generator. If I switch the order that these generators run in, the same thing happens but I will get the other block. Should I be using a different method to generate these randomly in chunks? @Override public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider) { int numPerChunk = 4; for (int curSpawn = 0; curSpawn < numPerChunk; curSpawn++) { if (random.nextInt(15) != 0) { continue; } int xOffset = random.nextInt(15); int zOffset = random.nextInt(15); BlockPos topBlock = world.getTopSolidOrLiquidBlock(new BlockPos(chunkX * 16 + xOffset, 0, chunkZ * 16 + zOffset)); if (world.getBlockState(topBlock) == Blocks.air.getDefaultState() && world.getBlockState(topBlock.down()) == Blocks.grass.getDefaultState()) { world.setBlockState(topBlock, Homestead.blockTomatoCrop.getDefaultState()); } } }
January 15, 201510 yr Copy and paste all method contents, not the actual method, and replace the 1st block with the 2nd. Maker of the Craft++ mod.
January 15, 201510 yr Author Solved it... The IWorldGenerators are all called during world generation with a Random that is initialized to the world seed. Therefore both blocks grabbing the same nextInt(15) repeatedly generates identical numbers. To fix this I just create a new random using random.nextInt() * some arbitrary constant number.
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.