Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

    }

Copy and paste all method contents, not the actual method, and replace the 1st block with the 2nd.

Maker of the Craft++ mod.

  • 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.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.