Jump to content

[1.7.10] Problems with entity attacking


Waabbuffet

Recommended Posts

I created this entity warrior that follows you and attacks whatever you attack. The only problem is when he attacks he goes super sonic, and runs circles around the target hes attacking. The code for the class is here. How do i fix this?

 

 

public class IamAWarrior extends EntityTameable{

 

 

EntityPlayer player = Minecraft.getMinecraft().thePlayer;

 

 

 

public IamAWarrior(World par1World)

{

super(par1World);

this.setSize(0.6F, 0.8F);

        this.getNavigator().setAvoidsWater(true);

        this.tasks.addTask(1, new EntityAISwimming(this));

        this.tasks.addTask(4, new EntityAIAttackOnCollide(this, 4.0D, true));

        this.tasks.addTask(5, new EntityAIFollowOwner(this, 1.0D, 10.0F, 2.0F));

        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.setTamed(true);

     

}

 

protected void applyEntityAttributes(){

super.applyEntityAttributes();

this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.23D);

this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(40.0D);

//this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(3.0D);

}

 

@Override

protected boolean isAIEnabled()

{

return true;

 

}

@Override

protected boolean canDespawn()

{

return false;

}

 

@Override

public boolean attackEntityAsMob(Entity p_70652_1_)

  {

        int i = 10;

        return p_70652_1_.attackEntityFrom(DamageSource.causeMobDamage(this), (float)i);

  }

 

 

@Override

    public void writeEntityToNBT(NBTTagCompound cmp)

    {

        super.writeEntityToNBT(cmp);

        cmp.setString("Owners Name", player.getUniqueID().toString());

       

    }

 

    @Override

    public void readEntityFromNBT(NBTTagCompound cmp)

    {

        super.readEntityFromNBT(cmp);

        this.func_152115_b(cmp.getString("Owners Name"));

       

    }

 

    @Override

public EntityAgeable createChild(EntityAgeable entityageable)

{

return null;

 

}

 

 

}

 

 

Link to comment
Share on other sites

OHH lol ok thanks for the quick reply. One more thing how do i make him hold a iron sword?

There's a whole topic about it that may help, but basically:

 

1. Set your entity's held item to what you want (use addRandomArmor or whatever else you need upon spawning)

 

2. To make your life easy, extend both RenderBiped and ModelBiped where appropriate

 

3. Make sure whatever attack AI you are using calls #swingItem when attacking - EntityAIAttackOnCollide does this.

 

4. Make sure you call updateArmSwingProgress() from your entity's onLivingUpdate method, otherwise the swing animation won't work despite your entity holding the sword

Link to comment
Share on other sites

Alright thanks ill take a look, last thing xD. The entity doesnt seem to remember that i am the owner when i log out completely and come back, how do i fix this?

Are you logging in with the same name each time? The default development environment settings log you in with a new user name each time - you need to set it in the run-time configuration: --username Me. You can even add your password (if the username is your real one) to log in using your actual account, if you want.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.