From dffda009407ebeb41b58d2aa994cbebc725c15bb Mon Sep 17 00:00:00 2001 From: Frank Date: Sat, 7 Aug 2021 02:08:17 +0200 Subject: [PATCH] Added API to fix id's on paths that can contain Lists/CompundTags --- .../ru/bclib/api/datafixer/DataFixerAPI.java | 4 +- .../bclib/api/datafixer/MigrationProfile.java | 42 +++++++++++++++++++ .../java/ru/bclib/api/datafixer/Patch.java | 10 +++++ 3 files changed, 54 insertions(+), 2 deletions(-) diff --git a/src/main/java/ru/bclib/api/datafixer/DataFixerAPI.java b/src/main/java/ru/bclib/api/datafixer/DataFixerAPI.java index 474666fe..0bc48aae 100644 --- a/src/main/java/ru/bclib/api/datafixer/DataFixerAPI.java +++ b/src/main/java/ru/bclib/api/datafixer/DataFixerAPI.java @@ -323,11 +323,11 @@ public class DataFixerAPI { private static void fixPlayerNbt(CompoundTag player, boolean[] changed, MigrationProfile data) { //Checking Inventory ListTag inventory = player.getList("Inventory", 10); - fixInventory(inventory, changed, data, true); + fixItemArrayWithID(inventory, changed, data, true); //Checking EnderChest ListTag enderitems = player.getList("EnderItems", 10); - fixInventory(enderitems, changed, data, true); + fixItemArrayWithID(enderitems, changed, data, true); } private static void fixRegion(MigrationProfile data, State state, File file) { diff --git a/src/main/java/ru/bclib/api/datafixer/MigrationProfile.java b/src/main/java/ru/bclib/api/datafixer/MigrationProfile.java index d58f793c..8877c0ff 100644 --- a/src/main/java/ru/bclib/api/datafixer/MigrationProfile.java +++ b/src/main/java/ru/bclib/api/datafixer/MigrationProfile.java @@ -1,6 +1,8 @@ package ru.bclib.api.datafixer; import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.ListTag; +import net.minecraft.nbt.Tag; import org.jetbrains.annotations.NotNull; import ru.bclib.api.WorldDataAPI; @@ -89,6 +91,46 @@ public class MigrationProfile { return false; } + + private boolean replaceIDatPath(@NotNull ListTag list, @NotNull String[] parts, int level){ + boolean[] changed = {false}; + if (level == parts.length-1) { + DataFixerAPI.fixItemArrayWithID(list, changed, this, true); + } else { + list.forEach(inTag -> changed[0] |= replaceIDatPath((CompoundTag)inTag, parts, level)); + } + return changed[0]; + } + + private boolean replaceIDatPath(@NotNull CompoundTag tag, @NotNull String[] parts, int level){ + boolean changed = false; + for (int i=level; i0) { + replaceStringFromIDs(tag, parts[parts.length-1]); + } + + + return false; + } + + public boolean replaceIDatPath(@NotNull CompoundTag root, @NotNull String path){ + String[] parts = path.split("\\."); + return replaceIDatPath(root, parts, 0); + } public boolean patchLevelDat(@NotNull CompoundTag level) throws PatchDidiFailException { boolean changed = false; diff --git a/src/main/java/ru/bclib/api/datafixer/Patch.java b/src/main/java/ru/bclib/api/datafixer/Patch.java index e687f3a6..56b1d242 100644 --- a/src/main/java/ru/bclib/api/datafixer/Patch.java +++ b/src/main/java/ru/bclib/api/datafixer/Patch.java @@ -156,5 +156,15 @@ public abstract class Patch { static MigrationProfile createMigrationData(CompoundTag config) { return new MigrationProfile(config); } + + /** + * Returns a list of paths,where your mod stores IDs in your {@link ru.bclib.api.WorldDataAPI}-File. + *

+ * {@link DataFixerAPI} will use information from the latest patch that returns a non-null-result. + * @return {@code null} if nothing changes or a list of Paths in your {@link ru.bclib.api.WorldDataAPI}-File + */ + public List getIIDPathsInWorldDataAPI() { + return null; + } }