Jump to content

A block that spreads over every block but air?


Looke81

Recommended Posts

Hi everyone i have made a block that can spread over the top of grass next to it and i tried to do this with all blocks by using block not Blocks.grass but of course this uses air so it spreads in the air i only want it to spread over the surface is there anyway i can make it spread over every block but air?

 

update tick

 

public void updateTick(World p_149674_1_, int p_149674_2_, int p_149674_3_, int p_149674_4_, Random p_149674_5_)

            {

                if (!p_149674_1_.isRemote)

               

                if (p_149674_1_.getBlockLightValue(p_149674_2_, p_149674_3_ + 1, p_149674_4_) >= 9)

                    {

                        for (int l = 0; l < 45000; ++l)

                        {

                            int i1 = p_149674_2_ + p_149674_5_.nextInt(3) - 1;

                            int j1 = p_149674_3_ + p_149674_5_.nextInt(5) - 3;

                            int k1 = p_149674_4_ + p_149674_5_.nextInt(3) - 1;

                            Block block = p_149674_1_.getBlock(i1, j1 + 1, k1);

 

                            if (p_149674_1_.getBlock(i1, j1, k1) == block && p_149674_1_.getBlockMetadata(i1, j1, k1) == 0 && p_149674_1_.getBlockLightValue(i1, j1 + 1, k1) >= 4 && p_149674_1_.getBlockLightOpacity(i1, j1 + 1, k1) <= 2)

                           

                                p_149674_1_.setBlock(i1, j1 + 1, k1, this);

                            }

                           

                           

                        }

                    }

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

Link to comment
Share on other sites

better?

 

 

public void updateTick(World world, int x, int y, int z, Random random)

            {

                if (!world.isRemote)

               

                if (world.getBlockLightValue(x, y + 1, z) >= 9)

                    {

                        for (int l = 0; l < 45000; ++l)

                        {

                            int i1 = x + random.nextInt(3) - 1;

                            int j1 = y + random.nextInt(5) - 3;

                            int k1 = z + random.nextInt(3) - 1;

                            Block block = world.getBlock(i1, j1 + 1, k1);

 

                            if (world.getBlock(i1, j1, k1) == block && world.getBlockMetadata(i1, j1, k1) == 0 && world.getBlockLightValue(i1, j1 + 1, k1) >= 4 && world.getBlockLightOpacity(i1, j1 + 1, k1) <= 2)

                           

                                world.setBlock(i1, j1 + 1, k1, this);

                            }

                           

                           

                        }

                    }

             

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

Link to comment
Share on other sites

yeah, way better.

 

public void updateTick(World world, int x, int y, int z, Random random)
            {
                if (!world.isRemote)
                   

                        for (int i = 0; l < 45000; ++l)
                        {
                            int i1 = x + random.nextInt(3) - 1;
                            int j1 = y + random.nextInt(3) - 1;
                            int k1 = z + random.nextInt(3) - 1;
                            Block block = world.getBlock(i1, j1 + 1, k1);

                            if (world.getBlock(i1, j1, k1) != Blocks.air){
                           
                                world.setBlock(i1, j1 + 1, k1, this);
                            }
                           
                           
                        
                    }

try something like thisthis

Here could be your advertisement!

Link to comment
Share on other sites

ive done this and its fixed the problem but now it is spreading down :(

 

  if (world.getBlock(i1, j1, k1) ==block &&  (world.getBlock(i1, j1, k1) != Blocks.air)){

                               

                                world.setBlock(i1, j1 + 1, k1, this);

                            }

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

Link to comment
Share on other sites

yeah, i know.

 

                            int i1 = x + random.nextInt(3) - 1;
                            int j1 = y + random.nextInt(3) - 1;
                            int k1 = z + random.nextInt(3) - 1;
                            Block block = world.getBlock(i1, j1 + 1, k1);

                            if (world.getBlock(i1, j1, k1) != Blocks.air){
                           
                                world.setBlock(i1, j1 + 1, k1, this);
                            }

 

j1 is the y coordinate (height) from the block it spreads to, right?. it basically is the blocks current location plus a random number.

ok, what is this random number?

int j1 = y + random.nextInt(3) - 1;

it is either:

0

1 or

2

minus 1. his means that it can spread

-1(down)

0(same y)

+1(up)

 

 

 

sry accidentaly had a 2 there, my fault, fixed it secs before your post

Here could be your advertisement!

Link to comment
Share on other sites

By crikey dude, where did that 45000 come from?  You will be running that setBlock loop 45000 times for every block you add.

 

                        for (int l = 0; l < 45000; ++l)
                        {

 

 

Another question  - what's the point of having a random value for y?

 

And in fact, why are you using random values for x and z as well?  Why not just try the four adjacent blocks?

 

This link might help you a bit, perhaps?

http://greyminecraftcoder.blogspot.com.au/2013/07/blocks.html

-TGG[/code]

Link to comment
Share on other sites

"if you want that your block spreads only upwards you have to remove the -1 from the new y(j1) coordinate and change the 3 to a 2"

 

No i want it so that it dosen't spread upwards

it shouldn't spread up/down?

than you can us your block y coordinate 1:1 for your new blocks y(=j1) coordinate.

Here could be your advertisement!

Link to comment
Share on other sites

i dont know if i have done the right thing but this dosen't work.

 

public void updateTick(World world, int x, int y, int z, Random random)

            {

                if (!world.isRemote)

               

                if (world.getBlockLightValue(x, y + 1, z) >= 9)

                    {

                        for (int l = 0; l < 45000; ++l)

                        {

                        int i1 = x + random.nextInt(3) - 1;

                            int j1 = y + random.nextInt(3) - 1;

                            int k1 = z + random.nextInt(3) - 1;

                            Block block = world.getBlock(i1, j1 + 1, k1);

 

                            if (world.getBlock(i1, j1, k1) != Blocks.air){

                         

                                world.setBlock(x, j1 + 1, z, this);

                            }

                        }

                        }

                    }

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

Link to comment
Share on other sites

now this is just spreading up :(

 

public void updateTick(World world, int x, int y, int z, Random random)

            {

                if (!world.isRemote)

               

                if (world.getBlockLightValue(x, y + 1, z) >= 9)

                    {

                        for (int l = 0; l < 45000; ++l)

                        {

                        int i1 = x + random.nextInt(3) - 1;

                        int j1=y;

                            int k1 = z + random.nextInt(3) - 1;

                            Block block = world.getBlock(i1, j1 + 1, k1);

 

                            if (world.getBlock(i1, j1, k1) != Blocks.air){

                         

                                world.setBlock(i1, j1 + 1, k1, this);

                            }

                        }

                        }

                    }

             

 

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

Link to comment
Share on other sites

Please use [ code ] tags.

 

It's just spreading up because you're setting the block above with your

j1 + 1

. Change that to just

j1

.

 

In fact, remove

j1

altogether and just use

y

.

 

Also, as has been pointed out, running 45000 iterations is a bit overkill.

Link to comment
Share on other sites

I dunno, it works

 

    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.setBlock(randX, randY, randZ, Yormod.yourblock);
                }
    }

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.