-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
204 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Obsidian.API.Registry.Codecs.ArmorTrims; | ||
public sealed class TrimDescription | ||
{ | ||
public required string Translate { get; init; } | ||
|
||
public string? Color { get; init; } | ||
} |
9 changes: 9 additions & 0 deletions
9
Obsidian.API/Registry/Codecs/ArmorTrims/TrimMaterial/TrimMaterialCodec.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Obsidian.API.Registry.Codecs.ArmorTrims.TrimMaterial; | ||
public sealed class TrimMaterialCodec : ICodec | ||
{ | ||
public required string Name { get; init; } | ||
|
||
public required int Id { get; init; } | ||
|
||
public required TrimMaterialElement Element { get; init; } | ||
} |
13 changes: 13 additions & 0 deletions
13
Obsidian.API/Registry/Codecs/ArmorTrims/TrimMaterial/TrimMaterialElement.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace Obsidian.API.Registry.Codecs.ArmorTrims.TrimMaterial; | ||
public sealed class TrimMaterialElement | ||
{ | ||
public required string Ingredient { get; init; } | ||
|
||
public required string AssetName { get; init; } | ||
|
||
public required double ItemModelIndex { get; init; } | ||
|
||
public required TrimDescription Description { get; init; } | ||
|
||
public Dictionary<string, string>? OverrideArmorMaterials { get; init; } | ||
} |
9 changes: 9 additions & 0 deletions
9
Obsidian.API/Registry/Codecs/ArmorTrims/TrimPattern/TrimPatternCodec.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Obsidian.API.Registry.Codecs.ArmorTrims.TrimPattern; | ||
public sealed class TrimPatternCodec : ICodec | ||
{ | ||
public required string Name { get; init; } | ||
|
||
public required int Id { get; init; } | ||
|
||
public required TrimPatternElement Element { get; init; } | ||
} |
11 changes: 11 additions & 0 deletions
11
Obsidian.API/Registry/Codecs/ArmorTrims/TrimPattern/TrimPatternElement.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace Obsidian.API.Registry.Codecs.ArmorTrims.TrimPattern; | ||
public sealed class TrimPatternElement | ||
{ | ||
public required string TemplateItem { get; init; } | ||
|
||
public required TrimDescription Description { get; init; } | ||
|
||
public required string AssetId { get; init; } | ||
|
||
public required bool Decal { get; init; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
Obsidian.SourceGenerators/Registry/RegistryAssetsGenerator.ArmorTrims.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
using Obsidian.SourceGenerators.Registry.Models; | ||
using System.Text.Json; | ||
|
||
namespace Obsidian.SourceGenerators.Registry; | ||
public partial class RegistryAssetsGenerator | ||
{ | ||
private static void GenerateTrimMaterial(Codec[] trimMaterials, CodeBuilder builder, SourceProductionContext ctx) | ||
{ | ||
builder.Type($"public static class TrimMaterials"); | ||
|
||
builder.Indent().Append("public const string CodecKey = \"minecraft:trim_material\";").Line().Line(); | ||
builder.Indent().Append($"public const int GlobalBitsPerEntry = {(int)Math.Ceiling(Math.Log(trimMaterials.Length, 2))};").Line().Line(); | ||
|
||
foreach (var trimMaterial in trimMaterials) | ||
{ | ||
var propertyName = trimMaterial.Name.RemoveNamespace().ToPascalCase(); | ||
|
||
builder.Indent().Append($"public static TrimMaterialCodec {propertyName} {{ get; }} = new() {{ Id = {trimMaterial.RegistryId}, Name = \"{trimMaterial.Name}\", Element = new() {{ "); | ||
|
||
foreach (var property in trimMaterial.Properties) | ||
{ | ||
var name = property.Key; | ||
var value = property.Value; | ||
|
||
builder.Append($"{name} = "); | ||
|
||
if (value.ValueKind == JsonValueKind.Object) | ||
{ | ||
ParseProperty(builder, value, ctx, name == "OverrideArmorMaterials"); | ||
continue; | ||
} | ||
|
||
AppendValueType(builder, value, ctx, name == "OverrideArmorMaterials"); | ||
} | ||
|
||
builder.Append("} };").Line(); | ||
} | ||
|
||
builder.Line().Statement("public static IReadOnlyDictionary<string, TrimMaterialCodec> All { get; } = new Dictionary<string, TrimMaterialCodec>"); | ||
|
||
foreach (var name in trimMaterials.Select(x => x.Name)) | ||
{ | ||
var propertyName = name.RemoveNamespace().ToPascalCase(); | ||
builder.Line($"{{ \"{name}\", {propertyName} }},"); | ||
} | ||
|
||
builder.EndScope(".AsReadOnly()", true).Line(); | ||
|
||
builder.EndScope(); | ||
} | ||
|
||
private static void GenerateTrimPattern(Codec[] trimPatterns, CodeBuilder builder, SourceProductionContext ctx) | ||
{ | ||
builder.Type($"public static class TrimPatterns"); | ||
|
||
builder.Indent().Append("public const string CodecKey = \"minecraft:trim_pattern\";").Line().Line(); | ||
builder.Indent().Append($"public const int GlobalBitsPerEntry = {(int)Math.Ceiling(Math.Log(trimPatterns.Length, 2))};").Line().Line(); | ||
|
||
foreach (var trimPattern in trimPatterns) | ||
{ | ||
var propertyName = trimPattern.Name.RemoveNamespace().ToPascalCase(); | ||
|
||
builder.Indent().Append($"public static TrimPatternCodec {propertyName} {{ get; }} = new() {{ Id = {trimPattern.RegistryId}, Name = \"{trimPattern.Name}\", Element = new() {{ "); | ||
|
||
foreach (var property in trimPattern.Properties) | ||
{ | ||
var name = property.Key; | ||
var value = property.Value; | ||
|
||
builder.Append($"{name} = "); | ||
|
||
if (value.ValueKind == JsonValueKind.Object) | ||
{ | ||
ParseProperty(builder, value, ctx); | ||
continue; | ||
} | ||
|
||
AppendValueType(builder, value, ctx); | ||
} | ||
|
||
builder.Append("} };").Line(); | ||
} | ||
|
||
builder.Line().Statement("public static IReadOnlyDictionary<string, TrimPatternCodec> All { get; } = new Dictionary<string, TrimPatternCodec>"); | ||
|
||
foreach (var name in trimPatterns.Select(x => x.Name)) | ||
{ | ||
var propertyName = name.RemoveNamespace().ToPascalCase(); | ||
builder.Line($"{{ \"{name}\", {propertyName} }},"); | ||
} | ||
|
||
builder.EndScope(".AsReadOnly()", true).Line(); | ||
|
||
builder.EndScope(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters