diff --git a/README.md b/README.md index 510fcf1..e8ff2ca 100644 --- a/README.md +++ b/README.md @@ -12,5 +12,8 @@ http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/1286750- ## Bug report(Bug反馈/催更): Discord: [Here](https://discord.gg/7k6NcRRpGg) -## Update log: -A fatal bug was fixed. +### Update log: +``` +1.19.2-4.0.3: +Some fatal bug was fixed. +``` diff --git a/build.gradle b/build.gradle index e0df656..4301e29 100644 --- a/build.gradle +++ b/build.gradle @@ -13,7 +13,7 @@ apply plugin: 'dev.architectury.loom' group = 'cx.rain.mc.nbtedit' archivesBaseName = 'nbtedit' -version = '1.19.2-4.0.2' +version = '1.19.2-4.0.3' if (System.getenv("JITPACK") == "true") { version += "-${System.getenv("VERSION")}" } diff --git a/src/main/java/cx/rain/mc/nbtedit/nbt/NBTTree.java b/src/main/java/cx/rain/mc/nbtedit/nbt/NBTTree.java index 24677dc..f7e311e 100644 --- a/src/main/java/cx/rain/mc/nbtedit/nbt/NBTTree.java +++ b/src/main/java/cx/rain/mc/nbtedit/nbt/NBTTree.java @@ -19,52 +19,87 @@ public static NBTTree root(CompoundTag tag) { } public CompoundTag toCompound() { - var tag = new CompoundTag(); - toCompoundInternal(rootNode, tag); - return tag; +// var tag = new CompoundTag(); +// toCompoundInternal(rootNode, tag); +// return tag; + return compoundNodeToTag(rootNode); } public Node getRoot() { return rootNode; } - private void toCompoundInternal(Node node, CompoundTag tag) { + // Fixme: work, plz. + private CompoundTag compoundNodeToTag(Node node) { + var tag = new CompoundTag(); for (var child : node.getChildren()) { - String name = child.getName(); - Tag base = child.getTag(); - if (base instanceof CompoundTag compound) { - toCompoundInternal(child, compound); - tag.put(name, compound); - } else if (base instanceof ListTag list) { - toCompoundInternal(child, list); - tag.put(name, list); + var name = child.getName(); + var childTag = child.getTag(); + + if (childTag instanceof CompoundTag) { + tag.put(name, compoundNodeToTag(child)); + } else if (childTag instanceof ListTag) { + tag.put(name, listNodeToTag(child)); } else { - tag.put(name, base.copy()); + tag.put(name, childTag); } } + return tag; } - public void toCompoundInternal(Node node, ListTag list) { + private ListTag listNodeToTag(Node node) { + var tag = new ListTag(); for (var child : node.getChildren()) { - Tag childTag = child.getTag(); - if (childTag instanceof CompoundTag compound) { - toCompoundInternal(child, compound); - list.add(compound); - } else if (childTag instanceof ListTag childListTag) { - toCompoundInternal(child, childListTag); - list.add(childListTag); + var childTag = child.getTag(); + + if (childTag instanceof CompoundTag) { + tag.add(compoundNodeToTag(child)); + } else if (childTag instanceof ListTag) { + tag.add(listNodeToTag(child)); } else { - list.add(childTag.copy()); + tag.add(childTag); } } + return tag; } +// private void toCompoundInternal(Node node, CompoundTag tag) { +// for (var child : node.getChildren()) { +// String name = child.getName(); +// Tag base = child.getTag(); +// if (base instanceof CompoundTag compound) { +// toCompoundInternal(child, compound); +// tag.put(name, compound); +// } else if (base instanceof ListTag list) { +// toCompoundInternal(child, list); +// tag.put(name, list); +// } else { +// tag.put(name, base.copy()); +// } +// } +// } +// +// public void toCompoundInternal(Node node, ListTag list) { +// for (var child : node.getChildren()) { +// Tag childTag = child.getTag(); +// if (childTag instanceof CompoundTag compound) { +// toCompoundInternal(child, compound); +//// list.add(compound); +// } else if (childTag instanceof ListTag childListTag) { +// toCompoundInternal(child, childListTag); +//// list.add(childListTag); +// } else { +// list.add(childTag.copy()); +// } +// } +// } + public static class Node { private String nbtName; private T nbtTag; - private Node parent = null; - private List> children = new ArrayList<>(); + private Node parent = null; + private final List> children = new ArrayList<>(); private boolean shouldShowChildren = false; private Node(T tag) { @@ -140,7 +175,7 @@ public void removeChild(Node node) { } public boolean hasChild() { - return children.size() > 0; + return !children.isEmpty(); } public List> getChildren() {