package com.dynious.biota.block;
import com.dynious.biota.api.IBiotaAPI;
import com.dynious.biota.api.IPlant;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.EnumPlantType;
import net.minecraftforge.common.IPlantable;
import net.minecraftforge.common.util.ForgeDirection;
import java.util.Random;
public class BlockBiotaPlant extends BlockBiota implements IPlant, IPlantable
{
public BlockBiotaPlant(float biomass)
{
this(Material.plants, biomass);
}
public BlockBiotaPlant(Material material, float biomass)
{
super(material);
this.setTickRandomly(true);
this.setStepSound(soundTypeGrass);
float f = 0.2F;
this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, f * 3.0F, 0.5F + f);
IBiotaAPI.API.registerPlantValue(this, biomass);
}
@Override
public void updateTick(World world, int x, int y, int z, Random random)
{
IBiotaAPI.API.onPlantTick(this, world, x, y, z);
super.updateTick(world, x, y, z, random);
this.checkAndDropBlock(world, x, y, z);
}
@Override
@SideOnly(Side.CLIENT)
public int colorMultiplier(IBlockAccess world, int x, int y, int z)
{
int color = super.colorMultiplier(world, x, y, z);
color = IBiotaAPI.API.getPlantColorMultiplier(color, x, z);
return color;
}
@Override
public void onBlockAdded(World world, int x, int y, int z)
{
IBiotaAPI.API.onPlantBlockAdded(this, world, x, y, z);
super.onBlockAdded(world, x, y, z);
}
@Override
public void breakBlock(World world, int x, int y, int z, Block block, int meta)
{
IBiotaAPI.API.onPlantBlockRemoved(this, world, x, y, z);
super.breakBlock(world, x, y, z, block, meta);
}
/**
* Checks to see if its valid to put this block at the specified coordinates. Args: world, x, y, z
*/
@Override
public boolean canPlaceBlockAt(World world, int x, int y, int z)
{
return super.canPlaceBlockAt(world, x, y, z) && this.canBlockStay(world, x, y, z);
}
/**
* Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
* their own) Args: x, y, z, neighbor Block
*/
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, Block neighborBlock)
{
super.onNeighborBlockChange(world, x, y, z, neighborBlock);
this.checkAndDropBlock(world, x, y, z);
}
/**
* checks if the block can stay, if not drop as item
*/
protected void checkAndDropBlock(World world, int x, int y, int z)
{
if (!this.canBlockStay(world, x, y, z))
{
this.dropBlockAsItem(world, x, y, z, world.getBlockMetadata(x, y, z), 0);
world.setBlockToAir(x, y, z);
}
}
/**
* Can this block stay at this position. Similar to canPlaceBlockAt except gets checked often with plants.
*/
@Override
public boolean canBlockStay(World world, int x, int y, int z)
{
return world.getBlock(x, y - 1, z).canSustainPlant(world, x, y, z - 1, 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)
*/
@Override
public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z)
{
return null;
}
/**
* Is this block (a) opaque and (b) a full 1m cube? This determines whether or not to render the shared face of two
* adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
*/
@Override
public boolean isOpaqueCube()
{
return false;
}
/**
* If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
*/
@Override
public boolean renderAsNormalBlock()
{
return false;
}
/**
* The type of render function that is called for this block
*/
@Override
public int getRenderType()
{
return 1;
}
@Override
public EnumPlantType getPlantType(IBlockAccess world, int x, int y, int z)
{
return EnumPlantType.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);
}
}