Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.xlife.common.capability;
- import net.minecraft.nbt.CompoundNBT;
- import net.minecraft.nbt.INBT;
- import net.minecraft.nbt.ListNBT;
- import net.minecraft.nbt.StringNBT;
- import net.minecraft.util.Util;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.List;
- import java.util.UUID;
- import java.util.stream.Stream;
- /**
- * getPlayerDataByUUID(UUID uuid) - iterates through the map of players saved in the world cap.
- * getLife(int life) -
- */
- public class StoredLifeInformation implements ILifeInformation {
- /** This is what is stored in the worlds' nbt. */
- private float storedMaxHealth;
- private int currentLife;
- private UUID uuid;
- private final String[][] lives = new String[][]{new String[]{"", "", "", ""}, new String[]{"", "", "", ""}, new String[]{"", "", "", ""}, new String[]{"", "", "", ""}, new String[]{"", "", "", ""}, new String[]{"", "", "", ""}, new String[]{"", "", "", ""}, new String[]{"", "", "", ""}, new String[]{"", "", "", ""}, new String[]{"", "", "", ""}};
- public String[] getLife(int life) {
- return this.lives[life];
- }
- public void setLifeInfo(int life, float amountOfHearts, String causeOfDeath, String deathMessage, String timeLasted) {
- String[] array = this.getLife(life);
- array[0] = "" + amountOfHearts;
- array[1] = causeOfDeath;
- array[2] = deathMessage;
- array[3] = timeLasted;
- }
- public int getCurrentLife() {
- return this.currentLife;
- }
- public void setCurrentLife(int life) {
- this.currentLife = life;
- }
- public float getMaxHealth() {
- return this.storedMaxHealth;
- }
- public void setMaxHealth(float amount) {
- this.storedMaxHealth = amount;
- }
- public UUID getUUID() {
- return this.uuid;
- }
- public void setUUID(UUID uuid) {
- this.uuid = uuid;
- }
- public void cloneStoredInfo(StoredLifeInformation info) {
- info.setCurrentLife(this.currentLife);
- info.setMaxHealth(this.storedMaxHealth);
- info.setUUID(this.uuid);
- }
- public CompoundNBT writePlayerData() {
- CompoundNBT player = new CompoundNBT();
- player.put("Lives", this.writeLifeData());
- player.putInt("CurrentLife", this.getCurrentLife());
- player.putUniqueId("UUID", this.getUUID());
- return player;
- }
- public ListNBT writeLifeData() {
- ListNBT lives = new ListNBT();
- CompoundNBT lifeInfo = new CompoundNBT();
- for (int i = 0; i < this.getCurrentLife(); ++i) {
- for (String key : this.lives[i]) {
- lifeInfo.put(key, this.writeStringListAsArray(Arrays.stream(this.getLife(i))));
- }
- lives.add(i, lifeInfo);
- }
- return lives;
- }
- public ListNBT writeStringListAsArray(Stream<String> items) {
- return this.makeTagList(items.map(StringNBT::new));
- }
- public static String[] readStringListAsArray(CompoundNBT tag, String key) {
- final INBT var = tag.get(key);
- if (!(var instanceof ListNBT)) throw new IllegalArgumentException("Tag " + key + " is not list.");
- return ((ListNBT)var).stream().map(INBT::getString).toArray(String[]::new);
- }
- private ListNBT makeTagList(Stream<INBT> items) {
- return Util.make(new ListNBT(), list -> items.forEach(list::add));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement