How to make plants that can grow on specific blocks

Started by SomeoneElse on

Topic category: User side tutorials

Joined Nov 2017
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How to make plants that can grow on specific blocks
Mon, 09/30/2019 - 22:26 (edited)

(this tutorial is specifically for plants on vanilla blocks. Eventually, I might just redo this tutorial for any block)

  1. Create your plant element;
  2. Open the code of the plant element, add this line in the list of imports;
    import net.minecraft.init.Blocks;
  3. Add this

    @Override
    protected boolean canSustainBush(IBlockState state)
    {
            return state.getBlock() == Blocks.BLOCK;
    }
  4. You can change the blocks the plant can grow on by editing "Blocks.BLOCK" (typing Blocks. shows a list of all vanilla blocks)
    You can add more blocks by adding "|| state.getBlock() == Blocks.BLOCK" to the list.
    This doesn't prevent plants from growing on grass and dirt, but you can check my other comment for a fix.

You can also use materials instead of specific blocks by using:

import net.minecraft.block.material.Material;
state.getMaterial() == Material.MATERIAL

 

Edited by SomeoneElse on Mon, 09/30/2019 - 22:26
Joined Oct 2014
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Where exactly do we add the:…
Sun, 09/08/2019 - 15:49

Where exactly do we add the:

@Override

protected boolean canSustainBush(IBlockState state)

{

return state.getBlock() == Blocks.BLOCK;

}

Joined Nov 2017
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Pretty much anywhere inside…
Sun, 09/08/2019 - 17:18

Pretty much anywhere inside of

public static class BlockCustomFlower extends BlockFlower {
...
...
...
} //This is the second to last bracket

 

Since I made this tutorial, I found a way to remove dirt and grass. The required code is

@Override
public boolean canPlaceBlockAt(World worldIn, BlockPos pos) {
	IBlockState soil = worldIn.getBlockState(pos.down());
	Block block = soil.getBlock();
	return block == Blocks.BLOCK;
}

as well as

@Override
public boolean canBlockStay(World worldIn, BlockPos pos, IBlockState state) {
	if (pos.getY() >= 0 && pos.getY() < 256) {
		IBlockState iblockstate = worldIn.getBlockState(pos.down());
		Block block = iblockstate.getBlock();
		return block == Blocks.BLOCK;
	} else
		return false;
}

If you don't use Blocks.DIRT or Blocks.GRASS, the plant won't be able to grow on those blocks. Also, make sure the list of 'block ==' is the same in all the three methods. You might have to reformat the imports (ctrl+w)

Joined May 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Where do I add the "…
Tue, 10/01/2019 - 15:31

Where do I add the "@Override protected boolean canSustainBush(IBlockState state) { return state.getBlock() == Blocks.BLOCK; }" Do I press shift and do it 1 line under and paste it? or do I paste it on the same line as "import net.minecraft.init.Blocks;" I'm not sure and I'm confused.

Joined Feb 2015
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
is there a newer method? Its…
Thu, 02/13/2020 - 03:28

is there a newer method? Its not working for me because the import doesnt exist /:

Joined Nov 2017
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Are you using 1.14? This was…
Sat, 02/15/2020 - 10:11

Are you using 1.14? This was made for 1.12; I'll try to find a way to do this in 1.14 too

Joined Feb 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
You can make it so that if…
Fri, 07/24/2020 - 11:41

You can make it so that if the block below the plant isn't the particular block, your plant breaks.

Joined Jul 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
hi i am new on mcretor i…
Sat, 07/25/2020 - 11:58

hi i am new on mcretor i wanted to ask if it is possible to make a plant created by me born on a block created by me?