mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-23 21:39:51 +00:00
Close #1101 allow setting the health of IIndividualLiving
This commit is contained in:
1 parent
1d676bc3f1
commit
84877ab1cf
2 files changed
+18
-2
No files matched your search
@@ -19,6 +19,11 @@ public interface IIndividualLiving extends IIndividual {
|
||||
*/
|
||||
int getHealth();
|
||||
|
||||
/**
|
||||
* Set the current health of the individual.
|
||||
*/
|
||||
void setHealth(int health);
|
||||
|
||||
/**
|
||||
* @return Maximum health of the individual.
|
||||
*/
|
||||
|
||||
@@ -71,6 +71,17 @@ public abstract class IndividualLiving extends Individual implements IIndividual
|
||||
return health;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void setHealth(int health) {
|
||||
if (health < 0) {
|
||||
health = 0;
|
||||
} else if (health > getMaxHealth()) {
|
||||
health = getMaxHealth();
|
||||
}
|
||||
|
||||
this.health = health;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxHealth() {
|
||||
return this.maxHealth;
|
||||
@@ -80,7 +91,7 @@ public abstract class IndividualLiving extends Individual implements IIndividual
|
||||
public void age(World world, float lifespanModifier) {
|
||||
|
||||
if (lifespanModifier < 0.001f) {
|
||||
this.health = 0;
|
||||
setHealth(0);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -97,7 +108,7 @@ public abstract class IndividualLiving extends Individual implements IIndividual
|
||||
|
||||
private void decreaseHealth() {
|
||||
if (health > 0) {
|
||||
health--;
|
||||
setHealth(health - 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user