Advertisement
jayhillx

HistoryBookUtils

Sep 6th, 2021
1,413
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.36 KB | None | 0 0
  1. public class HealthBookUtils {
  2.  
  3.     public static StringNBT setPageOne(PlayerEntity player) {
  4.         return StringNBT.valueOf(TextFormatting.BOLD + "Life History\n" + getPageOne(player));
  5.     }
  6.  
  7.     public static StringNBT setPageTwo(PlayerEntity player) {
  8.         return StringNBT.valueOf(TextFormatting.BOLD + "Life History\n" + getPageTwo(player));
  9.     }
  10.  
  11.     private static String getPageOne(PlayerEntity player) {
  12.         IStatsCapability stats = player.getCapability(StatsCapability.STATS_CAPABILITY).orElse(null);
  13.         String[] time = stats.getTime();
  14.         String[] cause = stats.getCause();
  15.  
  16.         if (player.getMaxHealth() == 2.0F) {
  17.             return hearts(1) + living(player);
  18.         } else if (player.getMaxHealth() == 4.0F) {
  19.             return hearts(1) + lasted(time[0], cause[0]) + hearts(2) + living(player);
  20.         } else if (player.getMaxHealth() == 6.0F) {
  21.             return hearts(1) + lasted(time[0], cause[0]) + hearts(2) + lasted(time[1], cause[1]) + hearts(3) + living(player);
  22.         } else {
  23.             return hearts(1) + lasted(time[0], cause[0]) + hearts(2) + lasted(time[1], cause[1]) + hearts(3) + lasted(time[2], cause[2]);
  24.         }
  25.     }
  26.  
  27.     private static String getPageTwo(PlayerEntity player) {
  28.         IStatsCapability stats = player.getCapability(StatsCapability.STATS_CAPABILITY).orElse(null);
  29.         String[] time = stats.getTime();
  30.         String[] cause = stats.getCause();
  31.  
  32.         if (player.getMaxHealth() == 2.0F) {
  33.             return hearts(4) + living(player);
  34.         } else if (player.getMaxHealth() == 4.0F) {
  35.             return hearts(4) + lasted(time[3], cause[3]) + hearts(5) + living(player);
  36.         } else if (player.getMaxHealth() == 6.0F) {
  37.             return hearts(4) + lasted(time[3], cause[3]) + hearts(5) + lasted(time[4], cause[4]) + hearts(6) + living(player);
  38.         } else {
  39.             return hearts(4) + lasted(time[3], cause[3]) + hearts(5) + lasted(time[4], cause[4]) + hearts(6) + lasted(time[5], cause[5]);
  40.         }
  41.     }
  42.  
  43.     /** Returns how long the player has been living. */
  44.     private static String living(PlayerEntity player) {
  45.         ITimeCapability time = player.getCapability(TimeCapability.TIME_CAPABILITY).orElse(null);
  46.  
  47.         if (time.getTime() == 1) {
  48.             return TextFormatting.BLACK + "\nLiving 1 second";
  49.         } else if (time.getTime() < 60) {
  50.             return TextFormatting.BLACK + "\nLiving " + time.getTime() + " seconds";
  51.         } else if (time.getTime() >= 60 && time.getTime() < 120) {
  52.             return TextFormatting.BLACK + "\nLiving 1 minute";
  53.         } else if (time.getTime() >= 120 && time.getTime() < 3600) {
  54.             return TextFormatting.BLACK + "\nLiving " + time.getTime() / 60 + " minutes";
  55.         } else if (time.getTime() >= 3600 && time.getTime() < 7200) {
  56.             return TextFormatting.BLACK + "\nLiving 1 hour";
  57.         } else {
  58.             return TextFormatting.BLACK + "\nLiving " + time.getTime() / 3600 + " hours";
  59.         }
  60.     }
  61.  
  62.     private static String lasted(String lasted, String cause) {
  63.         return TextFormatting.BLACK + "\nLasted " + lasted + "\nEnded by " + TextFormatting.DARK_RED + cause + "\n";
  64.     }
  65.  
  66.     private static String hearts(float hearts) {
  67.         char h = 10084;
  68.  
  69.         if (hearts == 1) {
  70.             return TextFormatting.RED + "\n" + h;
  71.         } else if (hearts == 2) {
  72.             return TextFormatting.BLUE + "\n" + h + h;
  73.         } else if (hearts == 3) {
  74.             return TextFormatting.DARK_GREEN + "\n" + h + h + h;
  75.         } else if (hearts == 4) {
  76.             return TextFormatting.GOLD + "\n" + h + h + h + h;
  77.         } else if (hearts == 5) {
  78.             return TextFormatting.LIGHT_PURPLE + "\n" + h + h + h + h + h;
  79.         } else if (hearts == 6) {
  80.             return TextFormatting.DARK_PURPLE + "\n" + h + h + h + h + h + h;
  81.         } else if (hearts == 7) {
  82.             return TextFormatting.YELLOW + "\n" + h + h + h + h + h + h + h;
  83.         } else if (hearts == 8) {
  84.             return TextFormatting.DARK_AQUA + "\n" + h + h + h + h + h + h + h + h;
  85.         } else if (hearts == 9) {
  86.             return TextFormatting.GREEN + "\n" + h + h + h + h + h + h + h + h + h;
  87.         } else if (hearts == 10) {
  88.             return TextFormatting.BLACK + "\n" + h + h + h + h + h + h + h + h + h + h;
  89.         } else {
  90.             return "\n";
  91.         }
  92.     }
  93.  
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement