Jump to content

1.8 IWorldGenerator


Sessional

Recommended Posts

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());
            }
        }

    }

Link to comment
Share on other sites

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.

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.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.