Skip to content

Commit d4753de

Browse files
committed
Quick crash fix #10
1 parent 69ca697 commit d4753de

1 file changed

Lines changed: 40 additions & 5 deletions

File tree

Program.cs

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ internal static class Program
3131
private static JsonDocument AllBlockModelsJsonDocument;
3232
private static List<string> BlocksAtlasTextures = new();
3333

34-
private static readonly Version CurrentVersion = new Version(55, 4);
34+
private static readonly Version CurrentVersion = new Version(55, 5);
3535
private const string UserAgent = "VaniFine";
3636
private const string MapLink = "https://vf.cmdev.pw/map";
3737
private const string MinimumVersion = "1.21.5";
@@ -370,7 +370,7 @@ public static void GenerateItemJsonFiles(Dictionary<string, List<Dictionary<stri
370370
$"Generated and converted using VaniFine(v{CurrentVersion}) tool. See https://github.com/DimucaTheDev/VaniFine\r\nItems: {itemDefinitions.Count}");
371371

372372
foreach (var (item, definitions) in itemDefinitions)
373-
{
373+
{
374374
File.AppendAllText(allNames, $"\r\n{++index}) {item}\r\n");
375375
GenerateJsonForItem(item, definitions, index, allNames);
376376
}
@@ -487,6 +487,12 @@ public static void GenerateJsonForItem(string item, List<Dictionary<string, stri
487487
//trimmed armor
488488
foreach (var definition in definitions)
489489
{
490+
if (definition["FILE_NAME"].Contains(" "))
491+
{
492+
// just whyyyyy
493+
Console.WriteLine($"Skipped '{definition["FILE_NAME"]}' cuz of space in name. NotImplemented. why, author!!!!");
494+
continue;
495+
}
490496
var pattern = definition.First(s =>
491497
s.Key.Contains("nbt.trim.pattern", StringComparison.InvariantCultureIgnoreCase)).Value;
492498
var material = definition.First(s =>
@@ -517,6 +523,13 @@ public static void GenerateJsonForItem(string item, List<Dictionary<string, stri
517523
{
518524
foreach (var config in definitions)
519525
{
526+
if (config["FILE_NAME"].Contains(" "))
527+
{
528+
// just whyyyyy
529+
Console.WriteLine($"Skipped '{config["FILE_NAME"]}' cuz of space in name. NotImplemented. why, author!!!!");
530+
continue;
531+
}
532+
520533
if (config.Keys.Any(k => k.Contains("nbt.StoredEnchantments")))
521534
{
522535
Console.WriteLine($"SKIPPED {config["FILE_NAME"]}: TODO");
@@ -569,6 +582,12 @@ public static void GenerateJsonForItem(string item, List<Dictionary<string, stri
569582
int max = 0; //get max damage value
570583
foreach (var definition in definitions)
571584
{
585+
if (definition["FILE_NAME"].Contains(" "))
586+
{
587+
// just whyyyyy
588+
Console.WriteLine($"Skipped '{definition["FILE_NAME"]}' cuz of space in name. NotImplemented. why, author!!!!");
589+
continue;
590+
}
572591
if (int.TryParse(definition["damage"].Split('-').Last(), out int damage) && damage > max)
573592
max = damage;
574593
}
@@ -722,9 +741,25 @@ public static IEnumerable<string> GenerateEnchantmentCases(Dictionary<string, st
722741
usedEnchantments.TryAdd(enchantment, []);
723742
usedEnchantments[enchantment].Add(level);
724743

725-
yield return Templates.CaseTemplate
726-
.Replace("MODEL", $"item/{Path.GetFileNameWithoutExtension(config["texture"])}")
727-
.Replace("WHEN", JsonSerializer.Serialize(new Dictionary<string, int> { { $"minecraft:{enchantment}", level } }));
744+
string r = null!;
745+
try
746+
{
747+
r = Templates.CaseTemplate
748+
.Replace("MODEL",
749+
$"item/{Path.GetFileNameWithoutExtension(config.TryGetValue("texture", out var t) ? t : config["model"])}")
750+
.Replace("WHEN",
751+
JsonSerializer.Serialize(new Dictionary<string, int>
752+
{ { $"minecraft:{enchantment}", level } }));
753+
}
754+
catch (Exception e)
755+
{
756+
var c = Console.ForegroundColor;
757+
Console.ForegroundColor = ConsoleColor.Red;
758+
Console.WriteLine($"[!] Error occured when trying to process enchantment {enchantment} on {config["FULL_FILE_NAME"]} : {e.Message}");
759+
Console.ForegroundColor = c;
760+
}
761+
if (r != null!)
762+
yield return r;
728763
}
729764
else
730765
{

0 commit comments

Comments
 (0)