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

    public void updateTick(World world, int x, int y, int z, Random random)
    {
            if (!world.isRemote && world.getBlockLightValue(x, y + 1, z) >= 9)

                for (int i = 0; i < 4; ++i)
                {
                    int randX = x + random.nextInt(3) - 1;
                    int randY = y + random.nextInt(3) - 1;
                    int randZ = z + random.nextInt(3) - 1;


                    if (world.getBlock(randX, randY, randZ) != Blocks.air && world.getBlock(randX, randY, randZ) != this && world.getBlock(randX, randY+1, randZ).isReplaceable(world, x, y, z))
                        world.setBlock(randX, randY+1, randZ, this);
                }
    }

 

?

gracious me is this thread still going? :P

 

So what are we trying to accomplish?

After the block is freshly placed, it should check all four spaces next to it, on the same y level.  If any of them are empty, and the block underneath the empty space is full, then we fill the space with our block.

 

That's it!  Each time we place our block, it will schedule a random UpdateTick, so after a bit of time, that new block will be called with UpdateTick to check for adjacent spaces, and so on, until the block spreads out over the entire plateau.

 

So long as we keep that in mind, the code for that is really pretty simple.

No need for random stuff, no need to try the same twenty seven locations 45000 times.

 

  public void updateTick(World world, int x, int y, int z, Random random) {
    if (!world.isRemote) {  // execute on server side only to avoid strange ghost blocks and disturbing things
        checkAndFillBlock(world, x - 1, y, z);
        checkAndFillBlock(world, x + 1, y, z);
        checkAndFillBlock(world, x, y, z - 1);
        checkAndFillBlock(world, x, y, z + 1);
    }
  }  

// check if this block is empty (air) and the block underneath it is solid (not air).  If so, fill it with the this Block
  private void checkAndFillBlock(World world, int wx, int wy, int wz) {
    if (world.getBlock(wx, wy, wz) == Blocks.air  && world.getBlock(wx, wy-1, wz) != Blocks.air) {
      world.setBlock(wx, wy, wz, this);
    }
  }

 

All that other stuff is baggage that I'm guessing you probably don't want, eg getBlockLightValue -> only growing near torches or glowstone.

 

-TGG

  • Author

whoever keeps deleting my reply i'm not bumping this for no reason my problem has not been solved i want the block to spread over the top of adjacent blocks and all of the people trying to help reply's don't work 

BioWarfare Mod: http://goo.gl/BYWQty

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.