Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[solved][1.8] Custom mob with maxHealth attribute


wojinwomackacz
 Share

Recommended Posts

hello guys, i have been trying this for couple of hours and i am really stuck. I tried to find some examples from the internet that would be helpfull but nothing helped. So i have my "customEntity" which extends simply EntityZombie .

public class EntityTest extends EntityZombie {
private double maxHealth = 100.0D;

public EntityTest(World par1World) {
	super(par1World);
	((PathNavigateGround)this.getNavigator()).func_179688_b(true);
    this.tasks.addTask(0, new EntityAISwimming(this));
}


@Override
    protected void applyEntityAttributes()
    {
        super.applyEntityAttributes();
        this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(this.maxHealth);
        this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.30000001192092896D);
    }

}

this should be really easy and there is nothing i can screw but propably i did.. When i spawn this entity by using my own command which is like:

				
EntityTest entit = new EntityTest(world);
entit.setPosition(player.posX+1, player.posY, player.posZ+1);
world.spawnEntityInWorld(entit);
player.addChatComponentMessage(new ChatComponentText("SUMMON!"));

Entity is spawned but it instantly die.

But when i change

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

to

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

it works perfectly.. So i am asking where is the problem and why is this happening :)

and sorry for my English (not everyone is borned at the right place :( ).

Link to comment
Share on other sites

applyEntityAttributes() is called by super-constructor of this entity (in EntityLivingBase i think) at which time any global member of your object variable is not yet set (which happens after call to super(); ). Therefore at the time of calling applyEntityAttributes() your global this.maxHealth is 0.0D.

 

Proper way to go about this is declare static baseMaxHealth for all entities or put value direclty in method (like test(10.0D); ).

1.7.10 is no longer supported by forge, you are on your own.

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

 Share



×
×
  • Create New...

Important Information

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