    001package net.minecraft.entity.item;
    002
    003import java.util.List;
    004import net.minecraft.block.Block;
    005import net.minecraft.command.IEntitySelector;
    006import net.minecraft.entity.player.EntityPlayer;
    007import net.minecraft.nbt.NBTTagCompound;
    008import net.minecraft.tileentity.Hopper;
    009import net.minecraft.tileentity.TileEntityHopper;
    010import net.minecraft.util.DamageSource;
    011import net.minecraft.world.World;
    012import net.minecraftforge.common.MinecraftForge;
    013import net.minecraftforge.event.entity.minecart.MinecartInteractEvent;
    014
    015public class EntityMinecartHopper extends EntityMinecartContainer implements Hopper
    016{
    017    private boolean field_96113_a = true;
    018    private int field_98044_b = -1;
    019
    020    public EntityMinecartHopper(World par1World)
    021    {
    022        super(par1World);
    023    }
    024
    025    public EntityMinecartHopper(World par1World, double par2, double par4, double par6)
    026    {
    027        super(par1World, par2, par4, par6);
    028    }
    029
    030    public int func_94087_l()
    031    {
    032        return 5;
    033    }
    034
    035    public Block func_94093_n()
    036    {
    037        return Block.field_94340_cs;
    038    }
    039
    040    public int func_94085_r()
    041    {
    042        return 1;
    043    }
    044
    045    /**
    046     * Returns the number of slots in the inventory.
    047     */
    048    public int getSizeInventory()
    049    {
    050        return 5;
    051    }
    052
    053    /**
    054     * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig.
    055     */
    056    public boolean interact(EntityPlayer par1EntityPlayer)
    057    {
    058        if(MinecraftForge.EVENT_BUS.post(new MinecartInteractEvent(this, par1EntityPlayer)))
    059        {
    060            return true;
    061        }
    062        if (!this.worldObj.isRemote)
    063        {
    064            par1EntityPlayer.func_96125_a(this);
    065        }
    066
    067        return true;
    068    }
    069
    070    public void func_96095_a(int par1, int par2, int par3, boolean par4)
    071    {
    072        boolean flag1 = !par4;
    073
    074        if (flag1 != this.func_96111_ay())
    075        {
    076            this.func_96110_f(flag1);
    077        }
    078    }
    079
    080    public boolean func_96111_ay()
    081    {
    082        return this.field_96113_a;
    083    }
    084
    085    public void func_96110_f(boolean par1)
    086    {
    087        this.field_96113_a = par1;
    088    }
    089
    090    /**
    091     * Returns the worldObj for this tileEntity.
    092     */
    093    public World getWorldObj()
    094    {
    095        return this.worldObj;
    096    }
    097
    098    public double func_96107_aA()
    099    {
    100        return this.posX;
    101    }
    102
    103    public double func_96109_aB()
    104    {
    105        return this.posY;
    106    }
    107
    108    public double func_96108_aC()
    109    {
    110        return this.posZ;
    111    }
    112
    113    /**
    114     * Called to update the entity's position/logic.
    115     */
    116    public void onUpdate()
    117    {
    118        super.onUpdate();
    119
    120        if (!this.worldObj.isRemote && this.isEntityAlive() && this.func_96111_ay())
    121        {
    122            --this.field_98044_b;
    123
    124            if (!this.func_98043_aE())
    125            {
    126                this.func_98042_n(0);
    127
    128                if (this.func_96112_aD())
    129                {
    130                    this.func_98042_n(4);
    131                    this.onInventoryChanged();
    132                }
    133            }
    134        }
    135    }
    136
    137    public boolean func_96112_aD()
    138    {
    139        if (TileEntityHopper.func_96116_a(this))
    140        {
    141            return true;
    142        }
    143        else
    144        {
    145            List list = this.worldObj.selectEntitiesWithinAABB(EntityItem.class, this.boundingBox.expand(0.25D, 0.0D, 0.25D), IEntitySelector.field_94557_a);
    146
    147            if (list.size() > 0)
    148            {
    149                TileEntityHopper.func_96114_a(this, (EntityItem)list.get(0));
    150            }
    151
    152            return false;
    153        }
    154    }
    155
    156    public void func_94095_a(DamageSource par1DamageSource)
    157    {
    158        super.func_94095_a(par1DamageSource);
    159        this.dropItemWithOffset(Block.field_94340_cs.blockID, 1, 0.0F);
    160    }
    161
    162    /**
    163     * (abstract) Protected helper method to write subclass entity data to NBT.
    164     */
    165    protected void writeEntityToNBT(NBTTagCompound par1NBTTagCompound)
    166    {
    167        super.writeEntityToNBT(par1NBTTagCompound);
    168        par1NBTTagCompound.setInteger("TransferCooldown", this.field_98044_b);
    169    }
    170
    171    /**
    172     * (abstract) Protected helper method to read subclass entity data from NBT.
    173     */
    174    protected void readEntityFromNBT(NBTTagCompound par1NBTTagCompound)
    175    {
    176        super.readEntityFromNBT(par1NBTTagCompound);
    177        this.field_98044_b = par1NBTTagCompound.getInteger("TransferCooldown");
    178    }
    179
    180    public void func_98042_n(int par1)
    181    {
    182        this.field_98044_b = par1;
    183    }
    184
    185    public boolean func_98043_aE()
    186    {
    187        return this.field_98044_b > 0;
    188    }
    189}