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 would like to have a nether-like dimension with dirt, which on top turns to grass.  Obviously I can't use the vanilla `topBlock`, because the nether has multiple layers atop eachother. 

What method would I write this in?  I have tried just looping through all the blocks in the chunk, and checking if the above block is air, but this is painfully inefficient and causes cascading world generation.

Is there a better way to do this?  It doesnt appear to work in `populate` either.

  • Author
private void replaceTopBlocks(int chunkX, int chunkZ) {
    int x = (chunkX * 16) + 8;
    int z = (chunkZ * 16) + 8;

    for (int a = x; a < x + 16; a++) {
        for (int b = 0; b < world.getHeight(); b++) {
            for (int c = z; c < z + 16; c++) {
                replaceTopBlock(a, b, c);
            }
        }
    }
}

private void replaceTopBlock(int x, int y, int z) {
    BlockPos position = new BlockPos(x, y, z);

    if (topBlockReplacements.containsKey(world.getBlockState(position)) && world.getBlockState(position.up()).getBlock() == Blocks.AIR) {
        world.setBlockState(position, topBlockReplacements.get(world.getBlockState(position)));
    }
}

This is the code I am using, topBlockReplacments is a HashMap of two IBlockStates; the first being the original block, second being the block to replace it with.

  • Author

You'd probably want to replace the air check with something else, because it means it wont replace the block under tallgrass and such.

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.