Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class HealthBookUtils {
- public static StringNBT setPageOne(PlayerEntity player) {
- return StringNBT.valueOf(TextFormatting.BOLD + "Life History\n" + getPageOne(player));
- }
- public static StringNBT setPageTwo(PlayerEntity player) {
- return StringNBT.valueOf(TextFormatting.BOLD + "Life History\n" + getPageTwo(player));
- }
- private static String getPageOne(PlayerEntity player) {
- IStatsCapability stats = player.getCapability(StatsCapability.STATS_CAPABILITY).orElse(null);
- String[] time = stats.getTime();
- String[] cause = stats.getCause();
- if (player.getMaxHealth() == 2.0F) {
- return hearts(1) + living(player);
- } else if (player.getMaxHealth() == 4.0F) {
- return hearts(1) + lasted(time[0], cause[0]) + hearts(2) + living(player);
- } else if (player.getMaxHealth() == 6.0F) {
- return hearts(1) + lasted(time[0], cause[0]) + hearts(2) + lasted(time[1], cause[1]) + hearts(3) + living(player);
- } else {
- return hearts(1) + lasted(time[0], cause[0]) + hearts(2) + lasted(time[1], cause[1]) + hearts(3) + lasted(time[2], cause[2]);
- }
- }
- private static String getPageTwo(PlayerEntity player) {
- IStatsCapability stats = player.getCapability(StatsCapability.STATS_CAPABILITY).orElse(null);
- String[] time = stats.getTime();
- String[] cause = stats.getCause();
- if (player.getMaxHealth() == 2.0F) {
- return hearts(4) + living(player);
- } else if (player.getMaxHealth() == 4.0F) {
- return hearts(4) + lasted(time[3], cause[3]) + hearts(5) + living(player);
- } else if (player.getMaxHealth() == 6.0F) {
- return hearts(4) + lasted(time[3], cause[3]) + hearts(5) + lasted(time[4], cause[4]) + hearts(6) + living(player);
- } else {
- return hearts(4) + lasted(time[3], cause[3]) + hearts(5) + lasted(time[4], cause[4]) + hearts(6) + lasted(time[5], cause[5]);
- }
- }
- /** Returns how long the player has been living. */
- private static String living(PlayerEntity player) {
- ITimeCapability time = player.getCapability(TimeCapability.TIME_CAPABILITY).orElse(null);
- if (time.getTime() == 1) {
- return TextFormatting.BLACK + "\nLiving 1 second";
- } else if (time.getTime() < 60) {
- return TextFormatting.BLACK + "\nLiving " + time.getTime() + " seconds";
- } else if (time.getTime() >= 60 && time.getTime() < 120) {
- return TextFormatting.BLACK + "\nLiving 1 minute";
- } else if (time.getTime() >= 120 && time.getTime() < 3600) {
- return TextFormatting.BLACK + "\nLiving " + time.getTime() / 60 + " minutes";
- } else if (time.getTime() >= 3600 && time.getTime() < 7200) {
- return TextFormatting.BLACK + "\nLiving 1 hour";
- } else {
- return TextFormatting.BLACK + "\nLiving " + time.getTime() / 3600 + " hours";
- }
- }
- private static String lasted(String lasted, String cause) {
- return TextFormatting.BLACK + "\nLasted " + lasted + "\nEnded by " + TextFormatting.DARK_RED + cause + "\n";
- }
- private static String hearts(float hearts) {
- char h = 10084;
- if (hearts == 1) {
- return TextFormatting.RED + "\n" + h;
- } else if (hearts == 2) {
- return TextFormatting.BLUE + "\n" + h + h;
- } else if (hearts == 3) {
- return TextFormatting.DARK_GREEN + "\n" + h + h + h;
- } else if (hearts == 4) {
- return TextFormatting.GOLD + "\n" + h + h + h + h;
- } else if (hearts == 5) {
- return TextFormatting.LIGHT_PURPLE + "\n" + h + h + h + h + h;
- } else if (hearts == 6) {
- return TextFormatting.DARK_PURPLE + "\n" + h + h + h + h + h + h;
- } else if (hearts == 7) {
- return TextFormatting.YELLOW + "\n" + h + h + h + h + h + h + h;
- } else if (hearts == 8) {
- return TextFormatting.DARK_AQUA + "\n" + h + h + h + h + h + h + h + h;
- } else if (hearts == 9) {
- return TextFormatting.GREEN + "\n" + h + h + h + h + h + h + h + h + h;
- } else if (hearts == 10) {
- return TextFormatting.BLACK + "\n" + h + h + h + h + h + h + h + h + h + h;
- } else {
- return "\n";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement