Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Is there any way to add or remove health after an entity has been created?

For example, I'd like to have a mob regenerate "hearts" when some event happens.

share|improve this question
2  
Why the -1? Modding is on-topic and this is a good question. –  Anko Feb 23 '13 at 3:20

3 Answers 3

up vote 7 down vote accepted

There are two ways. Using MCP obfuscation mappings, the first and proper way to do so is with:

EntityLiving.attackEntityFrom(DamageSource, damageDealt);

You need to specify where the damage came from in the first parameter though, so the simpler one is to simply use:

EntityLiving.setEntityHealth(health);

Use this with getHealth so you can do stuff like entity.setEntityHealth(entity.getHealth() - 1);

share|improve this answer

Use MCedit to give mobs more/less heath. Or you could give it something like 5 seconds before it gets a regeneration effect. If you havn't got MCEdit look it up on youtube and download it :)

share|improve this answer

Use this JSON Code:

{HealF:0,Attributes:[{Name:"generic.maxHealth",Base:0}]} 

, use

/entitydata @e[type=MOBNAME] JSON

or use

/summon MOBNAME ~ ~ ~ JSON

to summon the mob or change the mobs health. Change the two 0's in the JSON code to whatever health you want that mobs health to be, but the format is set in half hearts, so you may want to double the number (So 100 full hearts would be 200 as the number in the JSON). This is completely vanilla, and uses no external resources.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.