package minestrapteam.mods.minestrappolation.block;
import minestrapteam.mods.minestrappolation.Config;
import minestrapteam.mods.minestrappolation.lib.MItems;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyInteger;
import net.minecraft.block.state.BlockState;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World;
import net.minecraftforge.common.util.FakePlayer;
import java.util.Random;
public class BlockWolf extends BlockFlesh
{
public static final PropertyInteger AGE = PropertyInteger.create("age", 0, 5);
public BlockWolf(Material materialIn, MapColor mapColorIn)
{
super(materialIn, mapColorIn);
this.setDefaultState(this.blockState.getBaseState().withProperty(AGE, Integer.valueOf(0)));
this.setTickRandomly(true);
}
@Override
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
int j = state.getValue(AGE).intValue();
if (j < 5)
{
int chance = rand.nextInt(Config.bushGrowChance);
if (chance == 1)
{
worldIn.setBlockState(pos, state.withProperty(AGE, Integer.valueOf(j + 1)), 2);
}
}
}
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
{
if (worldIn.isRemote)
{
return true;
}
if (state.getValue(AGE) == 5 && playerIn.getCurrentEquippedItem().getItem() == Items.shears)
{
if (playerIn.getCurrentEquippedItem().getItemDamage() < playerIn.getCurrentEquippedItem().getMaxDamage())
{
playerIn.getCurrentEquippedItem().damageItem(1, playerIn);
}
else
{
playerIn.destroyCurrentEquippedItem();
}
worldIn.setBlockState(pos, this.getDefaultState(), 2);
EntityItem ei = new EntityItem(worldIn, playerIn.posX, playerIn.posY, playerIn.posZ,
new ItemStack(MItems.wolf_hide, 1));
worldIn.spawnEntityInWorld(ei);
if (playerIn instanceof FakePlayer)
ei.onCollideWithPlayer(playerIn);
return true;
}
return false;
}
@Override
public IBlockState getStateFromMeta(int meta)
{
return this.getDefaultState().withProperty(AGE, Integer.valueOf(meta));
}
@Override
public int getMetaFromState(IBlockState state)
{
return state.getValue(AGE).intValue();
}
@Override
protected BlockState createBlockState()
{
return new BlockState(this, AGE);
}
}