Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class WorldAttunement extends WorldSavedData {
- public static String name = PlanarMagic.modid + ":attunement";
- private HashMap<String, Attunement> attunements;
- private HashMap<String, Integer> strengths;
- public WorldAttunement(String name) {
- super(name);
- attunements = new HashMap<>();
- strengths = new HashMap<>();
- }
- public WorldAttunement() {
- super(PlanarMagic.modid + ":attunement");
- attunements = new HashMap<>();
- strengths = new HashMap<>();
- }
- public static WorldAttunement get(World world) {
- WorldAttunement instance = (WorldAttunement) world.getPerWorldStorage().getOrLoadData(WorldAttunement.class, WorldAttunement.name);
- if(instance == null) {
- instance = new WorldAttunement();
- world.setData(WorldAttunement.name, instance);
- }
- return instance;
- }
- @Override
- public void readFromNBT(NBTTagCompound nbt) {
- NBTTagCompound attunementTag = nbt.getCompoundTag("attunements");
- NBTTagCompound attunementStrengthTag = nbt.getCompoundTag("strengths");
- for(String key : attunementTag.getKeySet()) {
- attunements.put(key, Attunement.fromByte(attunementTag.getByte(key)));
- }
- for(String key : attunementStrengthTag.getKeySet()) {
- strengths.put(key, attunementStrengthTag.getInteger(key));
- }
- }
- @Override
- public NBTTagCompound writeToNBT(NBTTagCompound compound) {
- NBTTagCompound attunementTag = new NBTTagCompound();
- for(Map.Entry<String, Attunement> entry : attunements.entrySet()) {
- attunementTag.setByte(entry.getKey(), (byte) entry.getValue().ordinal());
- }
- compound.setTag("attunements", attunementTag);
- NBTTagCompound attunementStrengthTag = new NBTTagCompound();
- for(Map.Entry<String, Integer> entry : strengths.entrySet()) {
- attunementStrengthTag.setInteger(entry.getKey(), entry.getValue());
- }
- compound.setTag("strengths", attunementStrengthTag);
- return compound;
- }
- public Attunement getAttunement(int chunkX, int chunkY) {
- return attunements.get(chunkX + "," + chunkY);
- }
- public void setAttunement(int chunkX, int chunkY, Attunement attunement) {
- attunements.put(chunkX + "," + chunkY, attunement);
- this.markDirty();
- }
- public int getStrength(int chunkX, int chunkY) {
- return strengths.get(chunkX + "," + chunkY);
- }
- public void setStrength(int chunkX, int chunkY, int strength) {
- strengths.put(chunkX + "," + chunkY, strength);
- this.markDirty();
- }
- }
Add Comment
Please, Sign In to add comment