package com.knights.entity;
import java.util.UUID;
import net.minecraft.block.BlockColored;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityAgeable;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.INpc;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAIAttackOnCollide;
import net.minecraft.entity.ai.EntityAIFollowOwner;
import net.minecraft.entity.ai.EntityAIHurtByTarget;
import net.minecraft.entity.ai.EntityAILeapAtTarget;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAIMate;
import net.minecraft.entity.ai.EntityAIOwnerHurtByTarget;
import net.minecraft.entity.ai.EntityAIOwnerHurtTarget;
import net.minecraft.entity.ai.EntityAISit;
import net.minecraft.entity.ai.EntityAISwimming;
import net.minecraft.entity.ai.EntityAITargetNonTamed;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.monster.EntityCreeper;
import net.minecraft.entity.monster.EntityGhast;
import net.minecraft.entity.passive.EntityHorse;
import net.minecraft.entity.passive.EntitySheep;
import net.minecraft.entity.passive.EntityTameable;
import net.minecraft.entity.passive.EntityWolf;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.pathfinding.PathEntity;
import net.minecraft.scoreboard.Team;
import net.minecraft.server.management.PreYggdrasilConverter;
import net.minecraft.util.DamageSource;
import net.minecraft.world.World;
import com.knights.item.ItemManager;
import com.knights.lib.StringLibrary;
public class ChadWarden extends EntityTameable{ //implements INpc
protected EntityAISit aiSit = new EntityAISit(this);
private static final String __OBFID = "CL_00001561";
public ChadWarden(World par1World) {
super(par1World);
this.setSize(0.6F, 1.8F);
this.getNavigator().setAvoidsWater(true);
this.tasks.addTask(1, new EntityAISwimming(this));
this.tasks.addTask(2, this.aiSit);
this.tasks.addTask(3, new EntityAILeapAtTarget(this, 0.4F));
this.tasks.addTask(4, new EntityAIAttackOnCollide(this, 1.0D, true));
this.tasks.addTask(5, new EntityAIFollowOwner(this, 1.0D, 10.0F, 2.0F));
this.tasks.addTask(6, new EntityAIMate(this, 1.0D));
this.tasks.addTask(7, new EntityAIWander(this, 1.0D));
this.tasks.addTask(9, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
this.tasks.addTask(9, new EntityAILookIdle(this));
this.targetTasks.addTask(1, new EntityAIOwnerHurtByTarget(this));
this.targetTasks.addTask(2, new EntityAIOwnerHurtTarget(this));
this.targetTasks.addTask(3, new EntityAIHurtByTarget(this, true));
this.targetTasks.addTask(4, new EntityAITargetNonTamed(this, EntitySheep.class, 200, false));
this.setTamed(false);
}
public boolean func_142018_a1(EntityLivingBase p_142018_1_, EntityLivingBase p_142018_2_)
{
return true;
}
public Team getTeam()
{
if (this.isTamed())
{
EntityLivingBase entitylivingbase = this.getOwner();
if (entitylivingbase != null)
{
return entitylivingbase.getTeam();
}
}
return super.getTeam();
}
public boolean isOnSameTeam(EntityLivingBase p_142014_1_)
{
if (this.isTamed())
{
EntityLivingBase entitylivingbase1 = this.getOwner();
if (p_142014_1_ == entitylivingbase1)
{
return true;
}
if (entitylivingbase1 != null)
{
return entitylivingbase1.isOnSameTeam(p_142014_1_);
}
}
return super.isOnSameTeam(p_142014_1_);
}
public boolean func_152114_e(EntityLivingBase p_152114_1_)
{
return p_152114_1_ == this.getOwner();
}
public String func_152113_b()
{
return this.dataWatcher.getWatchableObjectString(17);
}
public void func_152115_b(String p_152115_1_)
{
this.dataWatcher.updateObject(17, p_152115_1_);
}
public EntityLivingBase getOwner()
{
try
{
UUID uuid = UUID.fromString(this.func_152113_b());
return uuid == null ? null : this.worldObj.func_152378_a(uuid);
}
catch (IllegalArgumentException illegalargumentexception)
{
return null;
}
}
protected void entityInit1()
{
super.entityInit();
this.dataWatcher.addObject(16, Byte.valueOf((byte)0));
this.dataWatcher.addObject(17, "");
}
/**
* (abstract) Protected helper method to write subclass entity data to NBT.
*/
public void writeEntityToNBT1(NBTTagCompound p_70014_1_)
{
super.writeEntityToNBT(p_70014_1_);
if (this.func_152113_b() == null)
{
p_70014_1_.setString("OwnerUUID", "");
}
else
{
p_70014_1_.setString("OwnerUUID", this.func_152113_b());
}
p_70014_1_.setBoolean("Sitting", this.isSitting());
}
/**
* (abstract) Protected helper method to read subclass entity data from NBT.
*/
public void readEntityFromNBT1(NBTTagCompound p_70037_1_)
{
super.readEntityFromNBT(p_70037_1_);
String s = "";
if (p_70037_1_.hasKey("OwnerUUID", )
{
s = p_70037_1_.getString("OwnerUUID");
}
else
{
String s1 = p_70037_1_.getString("Owner");
s = PreYggdrasilConverter.func_152719_a(s1);
}
if (s.length() > 0)
{
this.func_152115_b(s);
this.setTamed(true);
}
this.aiSit.setSitting(p_70037_1_.getBoolean("Sitting"));
this.setSitting(p_70037_1_.getBoolean("Sitting"));
}
public boolean isAIEnabled(){
return true;
}
public void setAttackTarget(EntityLivingBase p_70624_1_)
{
super.setAttackTarget(p_70624_1_);
if (p_70624_1_ == null)
{
this.setAngry(false);
}
else if (!this.isTamed())
{
this.setAngry(true);
}
}
public void setAngry(boolean p_70916_1_)
{
byte b0 = this.dataWatcher.getWatchableObjectByte(16);
if (p_70916_1_)
{
this.dataWatcher.updateObject(16, Byte.valueOf((byte)(b0 | 2)));
}
else
{
this.dataWatcher.updateObject(16, Byte.valueOf((byte)(b0 & -3)));
}
}
public void func_70918_i(boolean p_70918_1_)
{
if (p_70918_1_)
{
this.dataWatcher.updateObject(19, Byte.valueOf((byte)1));
}
else
{
this.dataWatcher.updateObject(19, Byte.valueOf((byte)0));
}
}
public boolean func_70922_bv()
{
return this.dataWatcher.getWatchableObjectByte(19) == 1;
}
protected void applyEntityAttributes()
{
super.applyEntityAttributes();
this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.3D);
if (this.isTamed()) {
this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(100.0D); //The value after it's tamed.
}
else {
this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(8.0D); //The value before it's tamed.
}
}
public void setTamed(boolean par1)
{
super.setTamed(par1);
if (par1)
{
this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(100.0D);
}
else
{
this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(8.0D);
}
}
protected void updateAITick()
{
this.dataWatcher.updateObject(18, Float.valueOf(this.getHealth()));
}
public void writeEntityToNBT(NBTTagCompound p_70014_1_)
{
super.writeEntityToNBT(p_70014_1_);
p_70014_1_.setBoolean("Angry", this.isAngry());
}
protected void entityInit()
{
super.entityInit();
this.dataWatcher.addObject(18, new Float(this.getHealth()));
this.dataWatcher.addObject(19, new Byte((byte)0));
this.dataWatcher.addObject(20, new Byte((byte)BlockColored.func_150032_b(1)));
}
/**
* Random Drop Between 1 - 3 dropped at a time
*/
// protected Item getDropItem(){
// return Items.apple;
// }
//
protected boolean canDespawn()
{
return !this.isTamed() && this.ticksExisted > 2400;
}
public boolean func_142018_a11(EntityLivingBase p_142018_1_, EntityLivingBase p_142018_2_)
{
if (!(p_142018_1_ instanceof EntityCreeper) && !(p_142018_1_ instanceof EntityGhast))
{
if (p_142018_1_ instanceof EntityWolf)
{
EntityWolf entitywolf = (EntityWolf)p_142018_1_;
if (entitywolf.isTamed() && entitywolf.getOwner() == p_142018_2_)
{
return false;
}
}
return p_142018_1_ instanceof EntityPlayer && p_142018_2_ instanceof EntityPlayer && !((EntityPlayer)p_142018_2_).canAttackPlayer((EntityPlayer)p_142018_1_) ? false : !(p_142018_1_ instanceof EntityHorse) || !((EntityHorse)p_142018_1_).isTame();
}
else
{
return false;
}
}
public void readEntityFromNBT(NBTTagCompound p_70037_1_)
{
super.readEntityFromNBT(p_70037_1_);
this.setAngry(p_70037_1_.getBoolean("Angry"));
}
public void onLivingUpdate()
{
super.onLivingUpdate();
if (!this.worldObj.isRemote && !this.hasPath() && this.onGround)
{
this.worldObj.setEntityState(this, (byte);
}
}
public boolean interact(EntityPlayer par1EntityPlayer)
{
ItemStack itemstack = par1EntityPlayer.inventory.getCurrentItem();
if (this.isTamed())
{
if (itemstack != null)
{
if (itemstack.getItem() instanceof ItemFood)
{
ItemFood itemfood = (ItemFood)itemstack.getItem();
if (itemfood.isWolfsFavoriteMeat() && this.dataWatcher.getWatchableObjectFloat(18) < 20.0F)
{
if (!par1EntityPlayer.capabilities.isCreativeMode)
{
--itemstack.stackSize;
}
this.heal((float)itemfood.func_150905_g(itemstack));
if (itemstack.stackSize <= 0)
{
par1EntityPlayer.inventory.setInventorySlotContents(par1EntityPlayer.inventory.currentItem, (ItemStack)null);
}
return true;
}
}
}
if (par1EntityPlayer.getCommandSenderName().equalsIgnoreCase(this.getOwnerName()) && !this.worldObj.isRemote && !this.isBreedingItem(itemstack))
{
this.aiSit.setSitting(!this.isSitting());
System.out.println("sit");
this.isJumping = false;
this.setPathToEntity((PathEntity)null);
this.setTarget((Entity)null);
this.setAttackTarget((EntityLivingBase)null);
}
}
else if (itemstack != null && itemstack.getItem() == ItemManager.ps3)
{
if (!par1EntityPlayer.capabilities.isCreativeMode)
{
--itemstack.stackSize;
}
if (itemstack.stackSize <= 0)
{
par1EntityPlayer.inventory.setInventorySlotContents(par1EntityPlayer.inventory.currentItem, (ItemStack)null);
}
if (!this.worldObj.isRemote)
{
if (this.rand.nextInt(3) == 0)
{
this.setTamed(true);
this.setPathToEntity((PathEntity)null);
this.setAttackTarget((EntityLivingBase)null);
this.aiSit.setSitting(true);
this.setHealth(100.0F);
this.setOwner(par1EntityPlayer.getCommandSenderName());
this.playTameEffect(true);
this.worldObj.setEntityState(this, (byte)7);
}
else
{
this.playTameEffect(false);
this.worldObj.setEntityState(this, (byte)6);
}
}
return true;
}
return super.interact(par1EntityPlayer);
}
public ChadWarden createChild(EntityAgeable par1EntityAgeable)
{
ChadWarden entityneola = new ChadWarden(this.worldObj);
String s = this.getOwnerName();
if (s != null && s.trim().length() > 0)
{
entityneola.setOwner(s);
entityneola.setTamed(true);
}
return entityneola;
}
private String getOwnerName() {
// TODO Auto-generated method stub
return null;
}
private void setOwner(String s) {
// TODO Auto-generated method stub
}
protected void entityInit11()
{
super.entityInit();
this.dataWatcher.addObject(16, Byte.valueOf((byte)0));
this.dataWatcher.addObject(17, "");
}
public void writeEntityToNBT2(NBTTagCompound p_70014_1_)
{
super.writeEntityToNBT(p_70014_1_);
if (this.func_152113_b() == null)
{
p_70014_1_.setString("OwnerUUID", "");
}
else
{
p_70014_1_.setString("OwnerUUID", this.func_152113_b());
}
p_70014_1_.setBoolean("Sitting", this.isSitting());
}
public boolean isTamed()
{
return (this.dataWatcher.getWatchableObjectByte(16) & 4) != 0;
}
public EntityLivingBase getOwner1()
{
try
{
UUID uuid = UUID.fromString(this.func_152113_b());
return uuid == null ? null : this.worldObj.func_152378_a(uuid);
}
catch (IllegalArgumentException illegalargumentexception)
{
return null;
}
}
public boolean func_152114_e1(EntityLivingBase p_152114_1_)
{
return p_152114_1_ == this.getOwner();
}
public EntityAISit func_70907_r()
{
return this.aiSit;
}
public boolean func_142018_a(EntityLivingBase p_142018_1_, EntityLivingBase p_142018_2_)
{
return true;
}
public void setTamed1(boolean p_70903_1_)
{
byte b0 = this.dataWatcher.getWatchableObjectByte(16);
if (p_70903_1_)
{
this.dataWatcher.updateObject(16, Byte.valueOf((byte)(b0 | 4)));
}
else
{
this.dataWatcher.updateObject(16, Byte.valueOf((byte)(b0 & -5)));
}
}
public boolean isOnSameTeam1(EntityLivingBase p_142014_1_)
{
if (this.isTamed())
{
EntityLivingBase entitylivingbase1 = this.getOwner();
if (p_142014_1_ == entitylivingbase1)
{
return true;
}
if (entitylivingbase1 != null)
{
return entitylivingbase1.isOnSameTeam(p_142014_1_);
}
}
return super.isOnSameTeam(p_142014_1_);
}
public boolean isSitting()
{
return (this.dataWatcher.getWatchableObjectByte(16) & 1) != 0;
}
public void setSitting(boolean p_70904_1_)
{
byte b0 = this.dataWatcher.getWatchableObjectByte(16);
if (p_70904_1_)
{
this.dataWatcher.updateObject(16, Byte.valueOf((byte)(b0 | 1)));
}
else
{
this.dataWatcher.updateObject(16, Byte.valueOf((byte)(b0 & -2)));
}
}
/**
* (abstract) Protected helper method to read subclass entity data from NBT.
*/
public void readEntityFromNBT11(NBTTagCompound p_70037_1_)
{
super.readEntityFromNBT(p_70037_1_);
String s = "";
if (p_70037_1_.hasKey("OwnerUUID", )
{
s = p_70037_1_.getString("OwnerUUID");
}
else
{
String s1 = p_70037_1_.getString("Owner");
s = PreYggdrasilConverter.func_152719_a(s1);
}
if (s.length() > 0)
{
this.func_152115_b(s);
this.setTamed(true);
}
this.aiSit.setSitting(p_70037_1_.getBoolean("Sitting"));
this.setSitting(p_70037_1_.getBoolean("Sitting"));
}
public int getMaxSpawnedInChunk(){
return 8;
}
public boolean attackEntityFrom(DamageSource par1DamageSource, int par2)
{
if (this.isEntityInvulnerable())
{
return false;
}
else
{
Entity entity = par1DamageSource.getEntity();
if (entity != null && !(entity instanceof EntityPlayer) && !(entity instanceof EntityArrow))
{
par2 = (par2 + 1) / 2;
}
return super.attackEntityFrom(par1DamageSource, par2);
}
}
public boolean attackEntityAsMob(Entity par1Entity)
{
int i = this.isTamed() ? 4 : 2;
return par1Entity.attackEntityFrom(DamageSource.causeMobDamage(this), i);
}
protected String getLivingSound()
{
return this.isAngry() ? (StringLibrary.MODID + ":growlc") : (this.rand.nextInt(3) == 0 ? (this.isTamed() && this.dataWatcher.getWatchableObjectFloat(18) < 10.0F ? (StringLibrary.MODID + ":whinec") : StringLibrary.MODID + ":pantingc") : (StringLibrary.MODID + ":barkc"));
}
/**
* Returns the sound this mob makes when it is hurt.
*/
protected String getHurtSound()
{
return (StringLibrary.MODID + ":hurtc");
}
/**
* Returns the sound this mob makes on death.
*/
protected String getDeathSound()
{
return (StringLibrary.MODID + ":deathc");
}
/**
* Returns the volume for the sounds this mob makes.
*/
protected float getSoundVolume()
{
return 0.4F;
}
public boolean isAngry()
{
return (this.dataWatcher.getWatchableObjectByte(16) & 2) != 0;
}
}
I am using minecraft forge 1.7.10