Guest User

Untitled

a guest
May 31st, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.69 KB | None | 0 0
  1. public class WorldAttunement extends WorldSavedData {
  2.  
  3.     public static String name = PlanarMagic.modid + ":attunement";
  4.  
  5.     private HashMap<String, Attunement> attunements;
  6.     private HashMap<String, Integer> strengths;
  7.  
  8.     public WorldAttunement(String name) {
  9.         super(name);
  10.         attunements = new HashMap<>();
  11.         strengths = new HashMap<>();
  12.     }
  13.  
  14.     public WorldAttunement() {
  15.         super(PlanarMagic.modid + ":attunement");
  16.         attunements = new HashMap<>();
  17.         strengths = new HashMap<>();
  18.     }
  19.  
  20.     public static WorldAttunement get(World world) {
  21.         WorldAttunement instance = (WorldAttunement) world.getPerWorldStorage().getOrLoadData(WorldAttunement.class, WorldAttunement.name);
  22.         if(instance == null) {
  23.             instance = new WorldAttunement();
  24.             world.setData(WorldAttunement.name, instance);
  25.         }
  26.  
  27.         return instance;
  28.     }
  29.  
  30.     @Override
  31.     public void readFromNBT(NBTTagCompound nbt) {
  32.         NBTTagCompound attunementTag = nbt.getCompoundTag("attunements");
  33.         NBTTagCompound attunementStrengthTag = nbt.getCompoundTag("strengths");
  34.         for(String key : attunementTag.getKeySet()) {
  35.             attunements.put(key, Attunement.fromByte(attunementTag.getByte(key)));
  36.         }
  37.  
  38.         for(String key : attunementStrengthTag.getKeySet()) {
  39.             strengths.put(key, attunementStrengthTag.getInteger(key));
  40.         }
  41.     }
  42.  
  43.     @Override
  44.     public NBTTagCompound writeToNBT(NBTTagCompound compound) {
  45.         NBTTagCompound attunementTag = new NBTTagCompound();
  46.         for(Map.Entry<String, Attunement> entry : attunements.entrySet()) {
  47.             attunementTag.setByte(entry.getKey(), (byte) entry.getValue().ordinal());
  48.         }
  49.         compound.setTag("attunements", attunementTag);
  50.  
  51.         NBTTagCompound attunementStrengthTag = new NBTTagCompound();
  52.         for(Map.Entry<String, Integer> entry : strengths.entrySet()) {
  53.             attunementStrengthTag.setInteger(entry.getKey(), entry.getValue());
  54.         }
  55.         compound.setTag("strengths", attunementStrengthTag);
  56.  
  57.         return compound;
  58.     }
  59.  
  60.     public Attunement getAttunement(int chunkX, int chunkY) {
  61.         return attunements.get(chunkX + "," + chunkY);
  62.     }
  63.  
  64.     public void setAttunement(int chunkX, int chunkY, Attunement attunement) {
  65.         attunements.put(chunkX + "," + chunkY, attunement);
  66.         this.markDirty();
  67.     }
  68.  
  69.     public int getStrength(int chunkX, int chunkY) {
  70.         return strengths.get(chunkX + "," + chunkY);
  71.     }
  72.  
  73.     public void setStrength(int chunkX, int chunkY, int strength) {
  74.         strengths.put(chunkX + "," + chunkY, strength);
  75.         this.markDirty();
  76.     }
  77. }
Add Comment
Please, Sign In to add comment