Skip to content

Commit

Permalink
Fix favorites not being saved
Browse files Browse the repository at this point in the history
  • Loading branch information
CodexAdrian committed Dec 7, 2023
1 parent cbcdcf1 commit dbe562e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
6 changes: 2 additions & 4 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# 2.2.3
# 2.2.4

Fix bug that keybind is hardcoded on Forge
Fix bug that Tempad screen opens via keybind without having one in inventory
Fix bug that Favorited Location opens via keybind or shift right click when a location is not favorited
Fixed favorited locations not being saved
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,23 @@ public static boolean containsLocation(Level level, UUID player, UUID location)

@Override
public void loadData(CompoundTag tag) {
if (tag.contains("Favorites")) {
CompoundTag favorites = tag.getCompound("Favorites");
CompoundTag savedLocations = tag.getCompound("SavedLocations");

loadLocations(savedLocations);

for (String playerId : favorites.getAllKeys()) {
UUID player = UUID.fromString(playerId);
UUID favorite = favorites.getUUID(playerId);
this.favorites.put(player, favorite);
}
} else {
loadLocations(tag);
}
}

public void loadLocations(CompoundTag tag) {
for (String playerId : tag.getAllKeys()) {
UUID player = UUID.fromString(playerId);
for (Tag list : tag.getList(playerId, Tag.TAG_COMPOUND)) {
Expand All @@ -91,11 +108,19 @@ public void loadData(CompoundTag tag) {

@Override
public void saveData(CompoundTag tag) {
CompoundTag favorites = new CompoundTag();
CompoundTag savedLocations = new CompoundTag();

locations.forEach((player, locationMap) -> {
ListTag playerTag = new ListTag();
locationMap.forEach((uuid, location) -> playerTag.add(location.toTag()));
tag.put(player.toString(), playerTag);
savedLocations.put(player.toString(), playerTag);
});

this.favorites.forEach((player, location) -> favorites.putUUID(player.toString(), location));

tag.put("Favorites", favorites);
tag.put("SavedLocations", savedLocations);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
org.gradle.jvmargs=-Xmx4G
enabledPlatforms=fabric,forge
version=2.2.3
version=2.2.4
group=me.codexadrian.tempad
minecraftVersion=1.20.1
parchmentVersion=2023.07.30
Expand Down

0 comments on commit dbe562e

Please sign in to comment.