Jump to content

[1.8]Set Block State


KingOfMiners

Recommended Posts

I'm making a cherry leaf block and i want it so it has a small chance to change into a leaf that has cherries on it and i would be able to do it but i don't know how to use setBlockState[move]*Fail*[/move] but i need help

if(this.hasCharry == false && rand.nextInt(500) < 1){
        	
        	int i = pos.getX();
        	int j = pos.getY();
        	int k = pos.getZ();
        	BlockPos bpos = new BlockPos(i, j, k);
        	
        	worldIn.setBlockState(bpos, state);
        	
        }

oh and yes i googled it. -_-

 

Link to comment
Share on other sites

Will It Work Now:

public void updateTick(World world, BlockPos pos, IBlockState state, Random rand)
    {
        super.updateTick(world, pos, state, rand);

        if(this.hasCharry == false && rand.nextInt(500) < 1){
        	
        	int i = pos.getX();
        	int j = pos.getY();
        	int k = pos.getZ();
        	BlockPos bpos = new BlockPos(i, j, k);
        	
        	world.setBlockState(bpos, MoreOresModBlocks.charry_leaves_full.getDefaultState(), 0);
        	
        }
        
    }

Link to comment
Share on other sites

Will It Work Now:

Why ask when you can simply try it in your development environment? Then you can find out immediately whether it works or not.

 

Btw, that last argument to setBlockState is a bit flag that tells Minecraft whether or not to update the client side / notify neighboring blocks / other things, and you almost always want it set to either 2 (notify client) or 3 (notify client AND notify neighbors, IIRC).

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.