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 this.setSitting(par1NBTTagCompound.getBoolean("Sitting")); 057 } 058 059 /** 060 * Play the taming effect, will either be hearts or smoke depending on status 061 */ 062 protected void playTameEffect(boolean par1) 063 { 064 String var2 = "heart"; 065 066 if (!par1) 067 { 068 var2 = "smoke"; 069 } 070 071 for (int var3 = 0; var3 < 7; ++var3) 072 { 073 double var4 = this.rand.nextGaussian() * 0.02D; 074 double var6 = this.rand.nextGaussian() * 0.02D; 075 double var8 = this.rand.nextGaussian() * 0.02D; 076 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); 077 } 078 } 079 080 @SideOnly(Side.CLIENT) 081 public void handleHealthUpdate(byte par1) 082 { 083 if (par1 == 7) 084 { 085 this.playTameEffect(true); 086 } 087 else if (par1 == 6) 088 { 089 this.playTameEffect(false); 090 } 091 else 092 { 093 super.handleHealthUpdate(par1); 094 } 095 } 096 097 public boolean isTamed() 098 { 099 return (this.dataWatcher.getWatchableObjectByte(16) & 4) != 0; 100 } 101 102 public void setTamed(boolean par1) 103 { 104 byte var2 = this.dataWatcher.getWatchableObjectByte(16); 105 106 if (par1) 107 { 108 this.dataWatcher.updateObject(16, Byte.valueOf((byte)(var2 | 4))); 109 } 110 else 111 { 112 this.dataWatcher.updateObject(16, Byte.valueOf((byte)(var2 & -5))); 113 } 114 } 115 116 public boolean isSitting() 117 { 118 return (this.dataWatcher.getWatchableObjectByte(16) & 1) != 0; 119 } 120 121 public void setSitting(boolean par1) 122 { 123 byte var2 = this.dataWatcher.getWatchableObjectByte(16); 124 125 if (par1) 126 { 127 this.dataWatcher.updateObject(16, Byte.valueOf((byte)(var2 | 1))); 128 } 129 else 130 { 131 this.dataWatcher.updateObject(16, Byte.valueOf((byte)(var2 & -2))); 132 } 133 } 134 135 public String getOwnerName() 136 { 137 return this.dataWatcher.getWatchableObjectString(17); 138 } 139 140 public void setOwner(String par1Str) 141 { 142 this.dataWatcher.updateObject(17, par1Str); 143 } 144 145 public EntityLiving getOwner() 146 { 147 return this.worldObj.getPlayerEntityByName(this.getOwnerName()); 148 } 149 150 public EntityAISit func_70907_r() 151 { 152 return this.aiSit; 153 } 154 }