Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

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

Featured Replies

Posted

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

And ?

The thing about attributes is they are optional. If you want it for your entity, register it into the entity attribute map by overriding the entity attribute initialization.

"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.

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/

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.