Make sure id-entries for the WorldDataAPI are fixed as well
This commit is contained in:
parent
dffda00940
commit
bc4ec0660f
3 changed files with 72 additions and 14 deletions
|
@ -403,7 +403,7 @@ public class DataFixerAPI {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static void fixID(CompoundTag inTag, boolean[] changed, MigrationProfile data, boolean recursive) {
|
static void fixID(CompoundTag inTag, boolean[] changed, MigrationProfile data, boolean recursive) {
|
||||||
final CompoundTag tag = inTag;
|
final CompoundTag tag = inTag;
|
||||||
|
|
||||||
changed[0] |= data.replaceStringFromIDs(tag, "id");
|
changed[0] |= data.replaceStringFromIDs(tag, "id");
|
||||||
|
|
|
@ -19,6 +19,7 @@ public class MigrationProfile {
|
||||||
final Map<String, String> idReplacements;
|
final Map<String, String> idReplacements;
|
||||||
final List<PatchFunction<CompoundTag, Boolean>> levelPatchers;
|
final List<PatchFunction<CompoundTag, Boolean>> levelPatchers;
|
||||||
final List<Patch> worldDataPatchers;
|
final List<Patch> worldDataPatchers;
|
||||||
|
final Map<String, List<String>> worldDataIDPaths;
|
||||||
|
|
||||||
private final CompoundTag config;
|
private final CompoundTag config;
|
||||||
|
|
||||||
|
@ -33,11 +34,16 @@ public class MigrationProfile {
|
||||||
HashMap<String, String> replacements = new HashMap<String, String>();
|
HashMap<String, String> replacements = new HashMap<String, String>();
|
||||||
List<PatchFunction<CompoundTag, Boolean>> levelPatches = new LinkedList<>();
|
List<PatchFunction<CompoundTag, Boolean>> levelPatches = new LinkedList<>();
|
||||||
List<Patch> worldDataPatches = new LinkedList<>();
|
List<Patch> worldDataPatches = new LinkedList<>();
|
||||||
|
HashMap<String, List<String>> worldDataIDPaths = new HashMap<>();
|
||||||
for (String modID : mods) {
|
for (String modID : mods) {
|
||||||
|
|
||||||
Patch.getALL()
|
Patch.getALL()
|
||||||
.stream()
|
.stream()
|
||||||
.filter(p -> p.modID.equals(modID))
|
.filter(p -> p.modID.equals(modID))
|
||||||
.forEach(patch -> {
|
.forEach(patch -> {
|
||||||
|
List<String> paths = patch.getWorldDataIDPaths();
|
||||||
|
if (paths!=null) worldDataIDPaths.put(modID, paths);
|
||||||
|
|
||||||
if (currentPatchLevel(modID) < patch.level) {
|
if (currentPatchLevel(modID) < patch.level) {
|
||||||
replacements.putAll(patch.getIDReplacements());
|
replacements.putAll(patch.getIDReplacements());
|
||||||
if (patch.getLevelDatPatcher()!=null)
|
if (patch.getLevelDatPatcher()!=null)
|
||||||
|
@ -51,7 +57,8 @@ public class MigrationProfile {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.worldDataIDPaths = Collections.unmodifiableMap(worldDataIDPaths);
|
||||||
this.idReplacements = Collections.unmodifiableMap(replacements);
|
this.idReplacements = Collections.unmodifiableMap(replacements);
|
||||||
this.levelPatchers = Collections.unmodifiableList(levelPatches);
|
this.levelPatchers = Collections.unmodifiableList(levelPatches);
|
||||||
this.worldDataPatchers = Collections.unmodifiableList(worldDataPatches);
|
this.worldDataPatchers = Collections.unmodifiableList(worldDataPatches);
|
||||||
|
@ -97,7 +104,7 @@ public class MigrationProfile {
|
||||||
if (level == parts.length-1) {
|
if (level == parts.length-1) {
|
||||||
DataFixerAPI.fixItemArrayWithID(list, changed, this, true);
|
DataFixerAPI.fixItemArrayWithID(list, changed, this, true);
|
||||||
} else {
|
} else {
|
||||||
list.forEach(inTag -> changed[0] |= replaceIDatPath((CompoundTag)inTag, parts, level));
|
list.forEach(inTag -> changed[0] |= replaceIDatPath((CompoundTag)inTag, parts, level+1));
|
||||||
}
|
}
|
||||||
return changed[0];
|
return changed[0];
|
||||||
}
|
}
|
||||||
|
@ -107,12 +114,12 @@ public class MigrationProfile {
|
||||||
for (int i=level; i<parts.length-1; i++) {
|
for (int i=level; i<parts.length-1; i++) {
|
||||||
final String part = parts[i];
|
final String part = parts[i];
|
||||||
if (tag.contains(part)) {
|
if (tag.contains(part)) {
|
||||||
final Tag subTag = tag.get(part);
|
final byte type = tag.getTagType(part);
|
||||||
if (subTag instanceof ListTag) {
|
if (type == Tag.TAG_LIST) {
|
||||||
ListTag list = (ListTag)subTag;
|
ListTag list = tag.getList(part, 10);
|
||||||
return replaceIDatPath(list, parts, i+1);
|
return replaceIDatPath(list, parts, i);
|
||||||
} else if (subTag instanceof CompoundTag) {
|
} else if (type == Tag.TAG_COMPOUND) {
|
||||||
tag = (CompoundTag)tag;
|
tag = tag.getCompound(part);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
@ -120,7 +127,21 @@ public class MigrationProfile {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tag!=null && parts.length>0) {
|
if (tag!=null && parts.length>0) {
|
||||||
replaceStringFromIDs(tag, parts[parts.length-1]);
|
final String key = parts[parts.length-1];
|
||||||
|
final byte type = tag.getTagType(key);
|
||||||
|
if (type == Tag.TAG_LIST) {
|
||||||
|
final ListTag list = tag.getList(key, 10);
|
||||||
|
final boolean[] _changed = {false};
|
||||||
|
DataFixerAPI.fixItemArrayWithID(list, _changed, this, true);
|
||||||
|
return _changed[0];
|
||||||
|
} else if (type == Tag.TAG_STRING) {
|
||||||
|
return replaceStringFromIDs(tag, key);
|
||||||
|
} else if (type == Tag.TAG_COMPOUND) {
|
||||||
|
final CompoundTag cTag = tag.getCompound(key);
|
||||||
|
boolean[] _changed = {false};
|
||||||
|
DataFixerAPI.fixID(cTag, _changed, this, true);
|
||||||
|
return _changed[0];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -148,5 +169,17 @@ public class MigrationProfile {
|
||||||
WorldDataAPI.saveFile(patch.modID);
|
WorldDataAPI.saveFile(patch.modID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (Map.Entry<String, List<String>> entry : worldDataIDPaths.entrySet()){
|
||||||
|
CompoundTag root = WorldDataAPI.getRootTag(entry.getKey());
|
||||||
|
boolean[] changed = {false};
|
||||||
|
entry.getValue().forEach(path -> {
|
||||||
|
changed[0] |= replaceIDatPath(root, path);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (changed[0]){
|
||||||
|
WorldDataAPI.saveFile(entry.getKey());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -158,12 +158,37 @@ public abstract class Patch {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of paths,where your mod stores IDs in your {@link ru.bclib.api.WorldDataAPI}-File.
|
* Returns a list of paths,where your mod may IDs in your {@link ru.bclib.api.WorldDataAPI}-File.
|
||||||
* <p>
|
* <p>
|
||||||
* {@link DataFixerAPI} will use information from the latest patch that returns a non-null-result.
|
* {@link DataFixerAPI} will use information from the latest patch that returns a non-null-result. This list is used
|
||||||
* @return {@code null} if nothing changes or a list of Paths in your {@link ru.bclib.api.WorldDataAPI}-File
|
* to automatically fix changed IDs from all active patches (see {@link Patch#getIDReplacements()}
|
||||||
|
* <p>
|
||||||
|
* The end of the path can either be a {@link net.minecraft.nbt.StringTag}, a {@link net.minecraft.nbt.ListTag} or
|
||||||
|
* a {@link CompoundTag}. If the Path contains a non-leaf {@link net.minecraft.nbt.ListTag}, all members of that
|
||||||
|
* list will be processed. For example:
|
||||||
|
* <pre>
|
||||||
|
* - global +
|
||||||
|
* | - key (String)
|
||||||
|
* | - items (List) +
|
||||||
|
* | - { id (String) }
|
||||||
|
* | - { id (String) }
|
||||||
|
* </pre>
|
||||||
|
* The path <b>global.items.id</b> will fix all <i>id</i>-entries in the <i>items</i>-list, while the path
|
||||||
|
* <b>global.key</b> will only fix the <i>key</i>-entry.
|
||||||
|
* <p>
|
||||||
|
* if the leaf-entry (= the last part of the path, which would be <i>items</i> in <b>global.items</b>) is a
|
||||||
|
* {@link CompoundTag}, the system will fix any <i>id</i> entry. If the {@link CompoundTag} contains an <i>item</i>
|
||||||
|
* or <i>tag.BlockEntityTag</i> entry, the system will recursivley continue with those. If an <i>items</i>
|
||||||
|
* or <i>inventory</i>-{@link net.minecraft.nbt.ListTag} was found, the system will continue recursivley with
|
||||||
|
* every item of that list.
|
||||||
|
* <p>
|
||||||
|
* if the leaf-entry is a {@link net.minecraft.nbt.ListTag}, it is handle the same as a child <i>items</i> entry
|
||||||
|
* of a {@link CompoundTag}.
|
||||||
|
*
|
||||||
|
* @return {@code null} if nothing changes or a list of Paths in your {@link ru.bclib.api.WorldDataAPI}-File.
|
||||||
|
* Paths are dot-seperated (see {@link ru.bclib.api.WorldDataAPI#getCompoundTag(String, String)}).
|
||||||
*/
|
*/
|
||||||
public List<String> getIIDPathsInWorldDataAPI() {
|
public List<String> getWorldDataIDPaths() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue