    001    package net.minecraft.entity.passive;
    002
    003    import cpw.mods.fml.relauncher.Side;
    004    import cpw.mods.fml.relauncher.SideOnly;
    005    import net.minecraft.entity.EntityLiving;
    006    import net.minecraft.entity.ai.EntityAISit;
    007    import net.minecraft.nbt.NBTTagCompound;
    008    import net.minecraft.world.World;
    009
    010    public abstract class EntityTameable extends EntityAnimal
    011    {
    012        protected EntityAISit aiSit = new EntityAISit(this);
    013
    014        public EntityTameable(World par1World)
    015        {
    016            super(par1World);
    017        }
    018
    019        protected void entityInit()
    020        {
    021            super.entityInit();
    022            this.dataWatcher.addObject(16, Byte.valueOf((byte)0));
    023            this.dataWatcher.addObject(17, "");
    024        }
    025
    026        /**
    027         * (abstract) Protected helper method to write subclass entity data to NBT.
    028         */
    029        public void writeEntityToNBT(NBTTagCompound par1NBTTagCompound)
    030        {
    031            super.writeEntityToNBT(par1NBTTagCompound);
    032
    033            if (this.getOwnerName() == null)
    034            {
    035                par1NBTTagCompound.setString("Owner", "");
    036            }
    037            else
    038            {
    039                par1NBTTagCompound.setString("Owner", this.getOwnerName());
    040            }
    041
    042            par1NBTTagCompound.setBoolean("Sitting", this.isSitting());
    043        }
    044
    045        /**
    046         * (abstract) Protected helper method to read subclass entity data from NBT.
    047         */
    048        public void readEntityFromNBT(NBTTagCompound par1NBTTagCompound)
    049        {
    050            super.readEntityFromNBT(par1NBTTagCompound);
    051            String var2 = par1NBTTagCompound.getString("Owner");
    052
    053            if (var2.length() > 0)
    054            {
    055                this.setOwner(var2);
    056                this.setTamed(true);
    057            }
    058
    059            this.aiSit.setSitting(par1NBTTagCompound.getBoolean("Sitting"));
    060            this.setSitting(par1NBTTagCompound.getBoolean("Sitting"));
    061        }
    062
    063        /**
    064         * Play the taming effect, will either be hearts or smoke depending on status
    065         */
    066        protected void playTameEffect(boolean par1)
    067        {
    068            String var2 = "heart";
    069
    070            if (!par1)
    071            {
    072                var2 = "smoke";
    073            }
    074
    075            for (int var3 = 0; var3 < 7; ++var3)
    076            {
    077                double var4 = this.rand.nextGaussian() * 0.02D;
    078                double var6 = this.rand.nextGaussian() * 0.02D;
    079                double var8 = this.rand.nextGaussian() * 0.02D;
    080                this.worldObj.spawnParticle(var2, this.posX + (double)(this.rand.nextFloat() * this.width * 2.0F) - (double)this.width, this.posY + 0.5D + (double)(this.rand.nextFloat() * this.height), this.posZ + (double)(this.rand.nextFloat() * this.width * 2.0F) - (double)this.width, var4, var6, var8);
    081            }
    082        }
    083
    084        @SideOnly(Side.CLIENT)
    085        public void handleHealthUpdate(byte par1)
    086        {
    087            if (par1 == 7)
    088            {
    089                this.playTameEffect(true);
    090            }
    091            else if (par1 == 6)
    092            {
    093                this.playTameEffect(false);
    094            }
    095            else
    096            {
    097                super.handleHealthUpdate(par1);
    098            }
    099        }
    100
    101        public boolean isTamed()
    102        {
    103            return (this.dataWatcher.getWatchableObjectByte(16) & 4) != 0;
    104        }
    105
    106        public void setTamed(boolean par1)
    107        {
    108            byte var2 = this.dataWatcher.getWatchableObjectByte(16);
    109
    110            if (par1)
    111            {
    112                this.dataWatcher.updateObject(16, Byte.valueOf((byte)(var2 | 4)));
    113            }
    114            else
    115            {
    116                this.dataWatcher.updateObject(16, Byte.valueOf((byte)(var2 & -5)));
    117            }
    118        }
    119
    120        public boolean isSitting()
    121        {
    122            return (this.dataWatcher.getWatchableObjectByte(16) & 1) != 0;
    123        }
    124
    125        public void setSitting(boolean par1)
    126        {
    127            byte var2 = this.dataWatcher.getWatchableObjectByte(16);
    128
    129            if (par1)
    130            {
    131                this.dataWatcher.updateObject(16, Byte.valueOf((byte)(var2 | 1)));
    132            }
    133            else
    134            {
    135                this.dataWatcher.updateObject(16, Byte.valueOf((byte)(var2 & -2)));
    136            }
    137        }
    138
    139        public String getOwnerName()
    140        {
    141            return this.dataWatcher.getWatchableObjectString(17);
    142        }
    143
    144        public void setOwner(String par1Str)
    145        {
    146            this.dataWatcher.updateObject(17, par1Str);
    147        }
    148
    149        public EntityLiving getOwner()
    150        {
    151            return this.worldObj.getPlayerEntityByName(this.getOwnerName());
    152        }
    153
    154        public EntityAISit func_70907_r()
    155        {
    156            return this.aiSit;
    157        }
    158    }