    001package net.minecraft.item;
    002
    003import net.minecraft.creativetab.CreativeTabs;
    004import net.minecraft.entity.EntityHanging;
    005import net.minecraft.entity.item.EntityItemFrame;
    006import net.minecraft.entity.item.EntityPainting;
    007import net.minecraft.entity.player.EntityPlayer;
    008import net.minecraft.util.Direction;
    009import net.minecraft.world.World;
    010
    011public class ItemHangingEntity extends Item
    012{
    013    private final Class hangingEntityClass;
    014
    015    public ItemHangingEntity(int par1, Class par2Class)
    016    {
    017        super(par1);
    018        this.hangingEntityClass = par2Class;
    019        this.setCreativeTab(CreativeTabs.tabDecorations);
    020    }
    021
    022    /**
    023     * Callback for item usage. If the item does something special on right clicking, he will have one of those. Return
    024     * True if something happen and false if it don't. This is for ITEMS, not BLOCKS
    025     */
    026    public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
    027    {
    028        if (par7 == 0)
    029        {
    030            return false;
    031        }
    032        else if (par7 == 1)
    033        {
    034            return false;
    035        }
    036        else
    037        {
    038            int var11 = Direction.vineGrowth[par7];
    039            EntityHanging var12 = this.createHangingEntity(par3World, par4, par5, par6, var11);
    040
    041            if (!par2EntityPlayer.canPlayerEdit(par4, par5, par6, par7, par1ItemStack))
    042            {
    043                return false;
    044            }
    045            else
    046            {
    047                if (var12 != null && var12.onValidSurface())
    048                {
    049                    if (!par3World.isRemote)
    050                    {
    051                        par3World.spawnEntityInWorld(var12);
    052                    }
    053
    054                    --par1ItemStack.stackSize;
    055                }
    056
    057                return true;
    058            }
    059        }
    060    }
    061
    062    /**
    063     * Create the hanging entity associated to this item.
    064     */
    065    private EntityHanging createHangingEntity(World par1World, int par2, int par3, int par4, int par5)
    066    {
    067        return (EntityHanging)(this.hangingEntityClass == EntityPainting.class ? new EntityPainting(par1World, par2, par3, par4, par5) : (this.hangingEntityClass == EntityItemFrame.class ? new EntityItemFrame(par1World, par2, par3, par4, par5) : null));
    068    }
    069}