Jump to content

Grass generation in nether-type dimension


X Squishling X

Recommended Posts

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.

Link to comment
Share on other sites

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.

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.

Announcements



×
×
  • Create New...

Important Information

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