mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Implement entity types (#1001)
Implement palette generation and investigate palette changes between versions. Turns out 1.13- has legacy IDs, 1.14 switches to entity palette and 1.15 refreshes the whole palette just to insert Bee. Also refactor entity handling code here and there.
This commit is contained in:
parent
5b0b0c9cc3
commit
bd85c46663
27 changed files with 1113 additions and 259 deletions
|
|
@ -1,7 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using MinecraftClient.Protocol;
|
||||
|
||||
namespace MinecraftClient.Inventory
|
||||
{
|
||||
|
|
@ -14,45 +11,10 @@ namespace MinecraftClient.Inventory
|
|||
/// Generate ItemType.cs from Minecraft registries.json
|
||||
/// </summary>
|
||||
/// <param name="registriesJsonFile">path to registries.json</param>
|
||||
/// <param name="outputEnum">output path for ItemTypes.cs</param>
|
||||
/// <remarks>java -cp minecraft_server.jar net.minecraft.data.Main --reports</remarks>
|
||||
public static void JsonToClass(string registriesJsonFile, string outputEnum)
|
||||
public static void GenerateItemTypes(string registriesJsonFile)
|
||||
{
|
||||
HashSet<int> itemIds = new HashSet<int>();
|
||||
Json.JSONData registries = Json.ParseJson(File.ReadAllText(registriesJsonFile));
|
||||
Json.JSONData itemRegistry = registries.Properties["minecraft:item"].Properties["entries"];
|
||||
List<string> outFile = new List<string>();
|
||||
|
||||
outFile.AddRange(new[] {
|
||||
"namespace MinecraftClient.Inventory",
|
||||
"{",
|
||||
" public enum ItemType",
|
||||
" {"
|
||||
});
|
||||
|
||||
foreach (KeyValuePair<string, Json.JSONData> item in itemRegistry.Properties)
|
||||
{
|
||||
int itemId = int.Parse(item.Value.Properties["protocol_id"].StringValue);
|
||||
|
||||
//minecraft:item_name => ItemName
|
||||
string itemName = String.Concat(
|
||||
item.Key.Replace("minecraft:", "")
|
||||
.Split('_')
|
||||
.Select(word => char.ToUpper(word[0]) + word.Substring(1))
|
||||
);
|
||||
|
||||
if (itemIds.Contains(itemId))
|
||||
throw new InvalidDataException("Duplicate item ID " + itemId + "!?");
|
||||
|
||||
outFile.Add(" " + itemName + " = " + itemId + ',');
|
||||
}
|
||||
|
||||
outFile.AddRange(new[] {
|
||||
" }",
|
||||
"}"
|
||||
});
|
||||
|
||||
File.WriteAllLines(outputEnum, outFile);
|
||||
DataTypeGenerator.GenerateEnum(registriesJsonFile, "minecraft:item", "ItemType", "MinecraftClient.Inventory");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue