Jump to content

Recommended Posts

Posted

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

 

?

Posted

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

Posted

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

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