Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.xlife.common.item;
- import com.xlife.common.data.LifeData;
- import com.xlife.common.data.PlayerInformationData;
- import net.minecraft.nbt.StringNBT;
- import net.minecraft.util.text.TextFormatting;
- import static net.minecraft.util.text.TextFormatting.*;
- /**
- * Book containing a players past life information.
- */
- public class LifeHistoryBookItem {
- private final TextFormatting[] formatting = new TextFormatting[]{RED, BLUE, DARK_GREEN, GOLD, LIGHT_PURPLE, DARK_PURPLE, YELLOW, AQUA, GREEN, BLACK};
- public StringNBT setPages(PlayerInformationData information, int page) {
- return new StringNBT(header(addInformation(information, page)));
- }
- private String header(String page) {
- return "{\"extra\":[{\"bold\":true,\"text\":\"Life History\"}," + page + "],\"text\":\"\"}";
- }
- private String addInformation(PlayerInformationData information, int page) {
- return "";
- }
- private String addPastLife(PlayerInformationData information, int life) {
- LifeData data = information.getLives().get(life - 1);
- 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() + "\"}";
- }
- private String addCurrentLife(PlayerInformationData information) {
- return "{\"color\":\"reset\",\"text\":\"\\n\\n\"}," + hearts((int) information.getCurrentLife().getHealth()) + "{\"color\":\"reset\",\"text\":\"\\n\"},{\"color\":\"black\",\"text\":\"Living " + time(information.getCurrentLife()) + "\"}";
- }
- private String hearts(int amount) {
- StringBuilder value = new StringBuilder();
- int hearts = Math.round(amount);
- while (hearts > 0) {
- value.append(new Character((char)10084));
- hearts -= 2;
- }
- return "{\"text\":\"" + formatting[(amount / 2) - 1] + value + "\"},";
- }
- private String time(StoredCurrentLife life) {
- if (life.getTimeLiving() == 1) {
- return "1 second";
- } else if (life.getTimeLiving() < 60) {
- return life.getTimeLiving() + " seconds";
- } else if (life.getTimeLiving() >= 60 && life.getTimeLiving() < 120) {
- return "1 minute";
- } else if (life.getTimeLiving() >= 120 && life.getTimeLiving() < 3600) {
- return life.getTimeLiving() / 60 + " minutes";
- } else if (life.getTimeLiving() >= 3600 && life.getTimeLiving() < 7200) {
- return "1 hour";
- } else {
- return life.getTimeLiving() / 3600 + " hours";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement