package net.minecraft.block;
import java.util.Random;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.common.EnumPlantType;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.common.IPlantable;
import static net.minecraftforge.common.EnumPlantType.*;
public class BlockBush extends Block implements IPlantable
{
private static final String __OBFID = "CL_00000208";
protected BlockBush(Material materialIn)
{
super(materialIn);
this.setTickRandomly(true);
float f = 0.2F;
this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, f * 3.0F, 0.5F + f);
this.setCreativeTab(CreativeTabs.tabDecorations);
}
protected BlockBush()
{
this(Material.plants);
}
public boolean canPlaceBlockAt(World worldIn, int x, int y, int z)
{
return super.canPlaceBlockAt(worldIn, x, y, z) && this.canBlockStay(worldIn, x, y, z);
}
/**
* is the block grass, dirt or farmland
*/
protected boolean canPlaceBlockOn(Block ground)
{
return ground == Blocks.grass || ground == Blocks.dirt || ground == Blocks.farmland;
}
public void onNeighborBlockChange(World worldIn, int x, int y, int z, Block neighbor)
{
super.onNeighborBlockChange(worldIn, x, y, z, neighbor);
this.checkAndDropBlock(worldIn, x, y, z);
}
/**
* Ticks the block if it's been scheduled
*/
public void updateTick(World worldIn, int x, int y, int z, Random random)
{
this.checkAndDropBlock(worldIn, x, y, z);
}
/**
* checks if the block can stay, if not drop as item
*/
protected void checkAndDropBlock(World worldIn, int x, int y, int z)
{
if (!this.canBlockStay(worldIn, x, y, z))
{
this.dropBlockAsItem(worldIn, x, y, z, worldIn.getBlockMetadata(x, y, z), 0);
worldIn.setBlock(x, y, z, getBlockById(0), 0, 2);
}
}
/**
* Can this block stay at this position. Similar to canPlaceBlockAt except gets checked often with plants.
*/
public boolean canBlockStay(World worldIn, int x, int y, int z)
{
return worldIn.getBlock(x, y - 1, z).canSustainPlant(worldIn, x, y - 1, z, ForgeDirection.UP, this);
}
/**
* Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been
* cleared to be reused)
*/
public AxisAlignedBB getCollisionBoundingBoxFromPool(World worldIn, int x, int y, int z)
{
return null;
}
public boolean isOpaqueCube()
{
return false;
}
public boolean renderAsNormalBlock()
{
return false;
}
/**
* The type of render function that is called for this block
*/
public int getRenderType()
{
return 1;
}
@Override
public EnumPlantType getPlantType(IBlockAccess world, int x, int y, int z)
{
if (this == Blocks.wheat) return Crop;
if (this == Blocks.carrots) return Crop;
if (this == Blocks.potatoes) return Crop;
if (this == Blocks.melon_stem) return Crop;
if (this == Blocks.pumpkin_stem) return Crop;
if (this == Blocks.deadbush) return Desert;
if (this == Blocks.waterlily) return Water;
if (this == Blocks.red_mushroom) return Cave;
if (this == Blocks.brown_mushroom) return Cave;
if (this == Blocks.nether_wart) return Nether;
if (this == Blocks.sapling) return Plains;
if (this == Blocks.tallgrass) return Plains;
if (this == Blocks.double_plant) return Plains;
if (this == Blocks.red_flower) return Plains;
if (this == Blocks.yellow_flower) return Plains;
return Plains;
}
@Override
public Block getPlant(IBlockAccess world, int x, int y, int z)
{
return this;
}
@Override
public int getPlantMetadata(IBlockAccess world, int x, int y, int z)
{
return world.getBlockMetadata(x, y, z);
}
}