From 84877ab1cf6fa96e2630b5a473db9d70d5d8f75b Mon Sep 17 00:00:00 2001 From: mezz Date: Fri, 29 Apr 2016 16:45:18 -0700 Subject: [PATCH] Close #1101 allow setting the health of IIndividualLiving --- .../forestry/api/genetics/IIndividualLiving.java | 5 +++++ .../forestry/core/genetics/IndividualLiving.java | 15 +++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) 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); } }