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