Skip to content

Commit

Permalink
Fix ability sources serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyrofab committed Jun 18, 2020
1 parent 37a1604 commit 02fdfe2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
11 changes: 7 additions & 4 deletions src/main/java/io/github/ladysnake/pal/SimpleAbilityTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.StringTag;
import net.minecraft.nbt.Tag;
import net.minecraft.util.Identifier;

import java.util.HashSet;
Expand Down Expand Up @@ -103,15 +102,19 @@ protected boolean shouldBeEnabled() {
public void save(CompoundTag tag) {
ListTag list = new ListTag();
for (AbilitySource abilitySource : this.abilitySources) {
list.add(StringTag.of(abilitySource.toString()));
list.add(StringTag.of(abilitySource.getId().toString()));
}
tag.put("ability_sources", list);
}

@Override
public void load(CompoundTag tag) {
for (Tag id : tag.getList("ability_sources", NbtType.STRING)) {
this.addSource(Pal.getAbilitySource(new Identifier(id.asString())));
ListTag list = tag.getList("ability_sources", NbtType.STRING);
for (int i = 0; i < list.size(); i++) {
Identifier sourceId = Identifier.tryParse(list.getString(i));
if (sourceId != null) {
this.addSource(Pal.getAbilitySource(sourceId));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,17 @@ private void writeAbilitiesToTag(CompoundTag tag, CallbackInfo ci) {
ListTag list = new ListTag();
for (Map.Entry<PlayerAbility, AbilityTracker> entry : this.palAbilities.entrySet()) {
CompoundTag abilityTag = new CompoundTag();
abilityTag.putString("ability_id", entry.getKey().toString());
abilityTag.putString("ability_id", entry.getKey().getId().toString());
entry.getValue().save(abilityTag);
list.add(abilityTag);
}
tag.put("playerabilitylib:abilities", list);
}

@Inject(method = "readCustomDataFromTag", at = @At("RETURN"))
@Inject(
method = "readCustomDataFromTag",
at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;readCustomDataFromTag(Lnet/minecraft/nbt/CompoundTag;)V", shift = At.Shift.AFTER)
)
private void readAbilitiesFromTag(CompoundTag tag, CallbackInfo ci) {
for (Tag t : tag.getList("playerabilitylib:abilities", NbtType.COMPOUND)) {
CompoundTag abilityTag = ((CompoundTag) t);
Expand Down

0 comments on commit 02fdfe2

Please sign in to comment.