Jump to content

OnBlockActivated to Cause Custom Crop to go Back a Stage


InYourPotato

Recommended Posts

I have made an OnBlockActivated method in my custom crop which causes the crop to drop 1-3 apples when right clicked. However, how would I make it so it also goes back a stage? Help much appreciated thank you.

 

Crop class:

 

public class IYPLettuceCrop extends BlockCrops{

 

public IYPLettuceCrop(String name){

this.setUnlocalizedName(name);

}

 

public Item getSeed(){

return IYPItems.LettuceSlice;

}

 

public Item getCrop(){

return IYPItems.Lettuce;

}

 

public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)

    {

int i = (((Integer) state.getValue(AGE)).intValue());

 

if (i > 6)

 

Block.spawnAsEntity(worldIn, pos, new ItemStack(Items.apple, new Random().nextInt(3) + 1));

 

return false;

 

 

    }

 

@Override

    public java.util.List<ItemStack> getDrops(net.minecraft.world.IBlockAccess world, BlockPos pos, IBlockState state, int fortune)

    {

List<ItemStack> ret = new ArrayList<ItemStack>();

 

int i = (((Integer) state.getValue(AGE)).intValue());

 

if (i < 7)

ret.add(new ItemStack ( this.getSeed(), 1, 0));

 

else

if (i > 6)

        {

ret.add(new ItemStack ( this.getCrop(), 1, 0));

}

        return ret;

    }

 

 

}

 

This is my first thread thus I'm not sure how to create text boxes to place your code, sorry about that!

Link to comment
Share on other sites

You either click the '#' symbol in the toolbar or manually type [ code ] your code here [ /code ] without the spaces.

 

As for your issue, you need to set the block state with the appropriate AGE property, e.g.

world.setBlockState(pos, state.withProperty(AGE, 1));

Note that the actual code may be slightly different - I don't have an IDE in front of me.

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.