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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hello...I got a crash, "The game crashed whilst rendering entity in world Error: java.lang.IllegalArgumentException: Duplicate delegates" In game I was walking upstairs in a house, and it suddenly crashed on me. Now it keeps crashing when I try to enter that world. I tried to give more RAM by changing it to 4...I'm not really wanting to get rid of any of the mods I have if possible. I'm absolutely clueless about crashes and whatnot...can anyone tell me what's gone wrong? This is the pastebin crash report Here Let me know if I need to include anything else
    • Hello!! Waiting around 45 seconds to reply can be a drag, especially when you're in the middle of a conversation. It might be worth looking into whether the forum software can tweak things a bit. Like maybe active members could have a shorter delay or none at all, while newbies or less active folks still have to wait. I don't have the power to change this myself, but I'll mention it to the forum mods.  Hang in there!
    • HELLO!! With your setup, you should be getting better performance. Try using Minecraft version 1.12.2 or 1.16.5 for better mod compatibility. I personally advice you to have the latest Optifine installed and tweak settings like lowering render distance and graphics. Also, consider using performance mods like Sodium and updating your GPU drivers. Allocating 4-8 GB RAM in the launcher might help too. Good luck!
    • Getting back into modding, the last time I seriously modded was almost 6 years ago.  I'm pretty rusty and a lot has changed.  What I'm trying to do right now is right a method that can remove an item's recipe using only said item's ResourceLocation as an input. From what I've gathered from older examples online it seems like the preferred method to do this involves using a DummyRecipe as that breaks the least amount of stuff (such as achievements related to a given item). The problem I'm having is that most of these examples are quite dated, usually being for 1.12. It seems that enough of the methods have changed for 1.18.2 forge that the implementation will be quite different, and that is what I'm struggling with so right now.  The basic concepts are still the same, but some of the classes I need to reference and what methods are where on said classes has been swapped around, and its giving me trouble.   I'm sure I could figure it out after a few days, but I figured it would make sense to ask for help as that may expedite the process.   Thanks in advance.
    • i getting same issue with my modpack so how can find the which mod not incompatible with i like wood, i removed variant vanilla mod because was most sense but still red loading screen and closing with world generating screen appering without crash. anyone can help me?
  • Topics

×
×
  • Create New...

Important Information

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