Skip to content

Commit

Permalink
added support of old versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Megageorgio committed Jul 1, 2022
1 parent 0777988 commit f84ab28
Showing 1 changed file with 31 additions and 9 deletions.
40 changes: 31 additions & 9 deletions NbtScrapper/NbtScrapper/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private void FindBooksAndSigns(ICollection<string> regionFiles, ICollection<stri
infoTextBox.InvokeIfRequired(() =>
{
infoTextBox.Text =
$@"Players: {progressBar.Value}/{playerFiles.Count}\nSigns found: {signCount}\nBooks found: {bookCount}";
$@"Players: {progressBar.Value}/{playerFiles.Count}{{Environment.NewLine}}Signs found: {signCount}{Environment.NewLine}Books found: {bookCount}";
});
CyclicSearch(playerData.RootTag as NbtContainerTag, SearchMethod);
GC.Collect();
Expand Down Expand Up @@ -166,7 +166,7 @@ void SearchMethod(NbtContainerTag container, NbtTag tag)
{
if (tag.Name == "id")
{
if (tag.StringValue is "minecraft:written_book" or "minecraft:writable_book")
if ((tag.TagType == NbtTagType.String && tag.StringValue is "minecraft:written_book" or "minecraft:writable_book") || (tag.TagType == NbtTagType.Short && tag.ShortValue is 386 or 387))
{
var book = container["tag"] as NbtCompound;
if (book == null)
Expand All @@ -182,7 +182,7 @@ void SearchMethod(NbtContainerTag container, NbtTag tag)
foreach (var page in pages)
{
var isSnbt = SnbtParser.ClassicTryParse(page.StringValue, false, out var result);
text += isSnbt ? result["text"].StringValue : page.StringValue;
text += isSnbt && result.TagType != NbtTagType.String ? result["text"].StringValue : page.StringValue;
}

var bookHash = HashString(text);
Expand Down Expand Up @@ -232,7 +232,7 @@ void SearchMethod(NbtContainerTag container, NbtTag tag)
{
bookFileWriter.WriteLine($"--- Page {i} ---");
var isSnbt = SnbtParser.ClassicTryParse(page.StringValue, false, out var result);
bookFileWriter.WriteLine(isSnbt ? result["text"].StringValue : page.StringValue);
bookFileWriter.WriteLine(isSnbt && page.TagType != NbtTagType.String ? result["text"].StringValue : page.StringValue);
i++;
}
}
Expand All @@ -241,22 +241,44 @@ void SearchMethod(NbtContainerTag container, NbtTag tag)
return;
}

if (tag.StringValue is "minecraft:sign")
else if ((tag.TagType == NbtTagType.String && tag.StringValue is "minecraft:sign" or "Sign") || (tag.TagType == NbtTagType.Short && tag.ShortValue is 63 or 68))
{
var list = new[] { "Text1", "Text2", "Text3", "Text4" };
var rows = new List<string>();
foreach (var item in list)
{
var row = SnbtParser.Parse(container[item].StringValue, false);
var isParsed = SnbtParser.ClassicTryParse(container[item].StringValue, false, out var row);
if (!isParsed)
{
rows.Add(string.Empty);
continue;
}
else if (row.TagType == NbtTagType.String)
{
rows.Add(row.StringValue);
continue;
}
var extra = row["extra"];
if (extra != null)
if (extra?[0] != null)
{
rows.Add(extra[0]["text"].StringValue);
if (extra[0].TagType == NbtTagType.String)
{
rows.Add(extra[0].StringValue);
}
else
{
rows.Add(extra[0]["text"].StringValue);
}

}
else
else if (row["text"] != null)
{
rows.Add(row["text"].StringValue);
}
else
{
rows.Add(string.Empty);
}
}

if (rows.All(string.IsNullOrEmpty))
Expand Down

0 comments on commit f84ab28

Please sign in to comment.