2018-02-15 18:49:01 -08:00
|
|
|
package WayofTime.bloodmagic.util.helper;
|
2016-11-05 11:14:56 -04:00
|
|
|
|
2018-02-15 18:49:01 -08:00
|
|
|
import WayofTime.bloodmagic.util.Constants;
|
2016-11-05 11:14:56 -04:00
|
|
|
import net.minecraft.entity.passive.EntityAnimal;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
public class PurificationHelper {
|
|
|
|
public static double getCurrentPurity(EntityAnimal animal) {
|
2016-11-05 11:14:56 -04:00
|
|
|
NBTTagCompound data = animal.getEntityData();
|
2017-08-15 21:30:48 -07:00
|
|
|
if (data.hasKey(Constants.NBT.CURRENT_PURITY)) {
|
2016-11-05 11:14:56 -04:00
|
|
|
return data.getDouble(Constants.NBT.CURRENT_PURITY);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
public static void setCurrentPurity(EntityAnimal animal, double amount) {
|
2016-11-05 11:14:56 -04:00
|
|
|
NBTTagCompound data = animal.getEntityData();
|
|
|
|
data.setDouble(Constants.NBT.CURRENT_PURITY, amount);
|
|
|
|
}
|
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
public static double addPurity(EntityAnimal animal, double added, double max) {
|
2016-11-05 11:14:56 -04:00
|
|
|
double currentPurity = getCurrentPurity(animal);
|
|
|
|
double newAmount = Math.min(max, currentPurity + added);
|
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
if (newAmount < max) {
|
2016-11-05 11:14:56 -04:00
|
|
|
setCurrentPurity(animal, newAmount);
|
|
|
|
return newAmount - currentPurity;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|