Jump to content

[Solved] [1.7.2] Custom Entity does not have Attack Damage attribute


Mateiaru

Recommended Posts

Hello!

 

I have another problem: my custom entity does not have attack damage attribute. It is an entity extending EntityWolf, if that causes the problem.

 

Anyway, "this.getEntityAttribute(SharedMonstersAttributes.attackDamage)" returns null. So I decided to investigate and I ran it in debug mode. I F5-ed until I reached the base of it: the class called BaseAttributeMap. And the program was at the function "getAttributeInstance". So I hovered over the 2 variables (attributes and attributesByName) and they had many entries, but not attack damage. They had:

- maxHealth

- followRange

- knockbackResistance

- movementSpeed.

Why is this happening? I'll try changing from "EntityWolf" to "EntityTameable" to see if it fixes it.

 

Thanks in advance,

Mateiaru

Link to comment
Share on other sites

"Available" doesn't mean "used".

The wolf damage value is hard-coded in its attack routine.

public boolean attackEntityAsMob(Entity par1Entity)
    {
        int i = this.isTamed() ? 4 : 2;
        return par1Entity.attackEntityFrom(DamageSource.causeMobDamage(this), (float)i);
    }

 

See EntityLivingBase#applyEntityAttributes() for the attributes actually registered in all "living" entities.

EntityLiving only adds the "follow range" attribute.

Only EntityMob and EntityPlayer register the "attack damage" attribute.

Link to comment
Share on other sites

All entities are supposed to have this attribute. Also, when the dog attacks it has the default damage.

http://minecraft.gamepedia.com/Attribute#Attributes_Available_on_All_Living_Entities

 

That wiki is wrong.  I was just working on attributes for my custom entities this morning. 

 

EntityLivingBase has the following:

   protected void applyEntityAttributes()
    {
        this.getAttributeMap().registerAttribute(SharedMonsterAttributes.maxHealth);
        this.getAttributeMap().registerAttribute(SharedMonsterAttributes.knockbackResistance);
        this.getAttributeMap().registerAttribute(SharedMonsterAttributes.movementSpeed);

        if (!this.isAIEnabled())
        {
            this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.10000000149011612D);
        }
    }

 

And then EntityLiving (which extends EntityLivingBase) has following:

    protected void applyEntityAttributes()
    {
        super.applyEntityAttributes();
        this.getAttributeMap().registerAttribute(SharedMonsterAttributes.followRange).setBaseValue(16.0D);
    }

 

 

In my custom entities, like GoToLink says, I had to register the additional attack damage attribute and then set it. 

 

Note that the full list of built-in attributes available to register are (from ShareMonsterAttributes class):

    public static final IAttribute [b]maxHealth [/b] = (new RangedAttribute("generic.maxHealth", 20.0D, 0.0D, Double.MAX_VALUE)).setDescription("Max Health").setShouldWatch(true);
    public static final IAttribute [b]followRange [/b] = (new RangedAttribute("generic.followRange", 32.0D, 0.0D, 2048.0D)).setDescription("Follow Range");
    public static final IAttribute [b]knockbackResistance [/b] = (new RangedAttribute("generic.knockbackResistance", 0.0D, 0.0D, 1.0D)).setDescription("Knockback Resistance");
    public static final IAttribute [b]movementSpeed [/b] = (new RangedAttribute("generic.movementSpeed", 0.699999988079071D, 0.0D, Double.MAX_VALUE)).setDescription("Movement Speed").setShouldWatch(true);
    public static final IAttribute [b]attackDamage [/b] = new RangedAttribute("generic.attackDamage", 2.0D, 0.0D, Double.MAX_VALUE);

 

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

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.