Advertisement
jayhillx

LifeHistoryBookItem

Mar 21st, 2023
823
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.79 KB | None | 0 0
  1. package com.xlife.common.item;
  2.  
  3. import com.xlife.common.data.LifeData;
  4. import com.xlife.common.data.PlayerInformationData;
  5. import net.minecraft.nbt.StringNBT;
  6. import net.minecraft.util.text.TextFormatting;
  7.  
  8. import static net.minecraft.util.text.TextFormatting.*;
  9.  
  10. /**
  11.  * Book containing a players past life information.
  12.  */
  13. public class LifeHistoryBookItem {
  14.     private final TextFormatting[] formatting = new TextFormatting[]{RED, BLUE, DARK_GREEN, GOLD, LIGHT_PURPLE, DARK_PURPLE, YELLOW, AQUA, GREEN, BLACK};
  15.  
  16.     public StringNBT setPages(PlayerInformationData information, int page) {
  17.         return new StringNBT(header(addInformation(information, page)));
  18.     }
  19.  
  20.     private String header(String page) {
  21.         return "{\"extra\":[{\"bold\":true,\"text\":\"Life History\"}," + page + "],\"text\":\"\"}";
  22.     }
  23.  
  24.     private String addInformation(PlayerInformationData information, int page) {
  25.         return "";
  26.     }
  27.  
  28.     private String addPastLife(PlayerInformationData information, int life) {
  29.         LifeData data = information.getLives().get(life - 1);
  30.  
  31.         return "{\"color\":\"reset\",\"text\":\"\\n\\n\"}," + hearts(data.getId() * 2) + "{\"color\":\"reset\",\"text\":\"\\n\"},{\"color\":\"black\",\"text\":\"Lasted " + data.getTimeLasted() + "\\nEnded by \"},{\"color\":\"dark_red\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"" + data.getDeathMessage() + "\"}},\"text\":\"" + data.getCauseOfDeath() + "\"}";
  32.     }
  33.  
  34.     private String addCurrentLife(PlayerInformationData information) {
  35.         return "{\"color\":\"reset\",\"text\":\"\\n\\n\"}," + hearts((int) information.getCurrentLife().getHealth()) + "{\"color\":\"reset\",\"text\":\"\\n\"},{\"color\":\"black\",\"text\":\"Living " + time(information.getCurrentLife()) + "\"}";
  36.     }
  37.  
  38.     private String hearts(int amount) {
  39.         StringBuilder value = new StringBuilder();
  40.         int hearts = Math.round(amount);
  41.  
  42.         while (hearts > 0) {
  43.             value.append(new Character((char)10084));
  44.             hearts -= 2;
  45.         }
  46.         return "{\"text\":\"" + formatting[(amount / 2) - 1] + value + "\"},";
  47.     }
  48.  
  49.     private String time(StoredCurrentLife life) {
  50.         if (life.getTimeLiving() == 1) {
  51.             return "1 second";
  52.         } else if (life.getTimeLiving() < 60) {
  53.             return life.getTimeLiving() + " seconds";
  54.         } else if (life.getTimeLiving() >= 60 && life.getTimeLiving() < 120) {
  55.             return "1 minute";
  56.         } else if (life.getTimeLiving() >= 120 && life.getTimeLiving() < 3600) {
  57.             return life.getTimeLiving() / 60 + " minutes";
  58.         } else if (life.getTimeLiving() >= 3600 && life.getTimeLiving() < 7200) {
  59.             return "1 hour";
  60.         } else {
  61.             return life.getTimeLiving() / 3600 + " hours";
  62.         }
  63.     }
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement