diff --git a/src/main/java/forestry/api/genetics/IIndividualLiving.java b/src/main/java/forestry/api/genetics/IIndividualLiving.java index f935dd204..a1f8c7598 100644 --- a/src/main/java/forestry/api/genetics/IIndividualLiving.java +++ b/src/main/java/forestry/api/genetics/IIndividualLiving.java @@ -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. */ diff --git a/src/main/java/forestry/core/genetics/IndividualLiving.java b/src/main/java/forestry/core/genetics/IndividualLiving.java index 0c077b58e..9ff968f60 100755 --- a/src/main/java/forestry/core/genetics/IndividualLiving.java +++ b/src/main/java/forestry/core/genetics/IndividualLiving.java @@ -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); } }