MC 1.14 Terrain support (#703)

Minecraft 1.14 is now fully supported.

- Implement NBT parsing to skip NBT field in chunk data
- Update lighting data format in Chunk Data parsing
- Move Chunk Data parsing into Protocol18Terrain.cs
- Improve PaletteGenerator to greatly reduce palette files sizes
- Re-Generate Palette113.cs to reduce its size (378 Kib -> 50 Kib)
- Generate Palette114.cs (57 Kib instead of 516 Kib with prev format)
- Update Material.cs and MaterialExtensions.cs for new block types
This commit is contained in:
ORelio 2019-05-01 15:23:30 +02:00
parent d2cbc9f1c3
commit 0d58fb9063
11 changed files with 2703 additions and 8900 deletions

View file

@ -76,12 +76,12 @@ namespace MinecraftClient.Mapping.BlockPalettes
{ 60, Material.Farmland }, // Soil
{ 61, Material.Furnace }, // Furnace
{ 62, Material.Furnace }, // BurningFurnace
{ 63, Material.WallSign }, // SignPost
{ 63, Material.OakWallSign }, // SignPost
{ 64, Material.OakDoor }, // WoodenDoor:0
{ 65, Material.Ladder },
{ 66, Material.Rail }, // Rails
{ 67, Material.CobblestoneStairs },
{ 68, Material.WallSign },
{ 68, Material.OakWallSign }, // WallSign
{ 69, Material.Lever },
{ 70, Material.StonePressurePlate }, // StonePlate
{ 71, Material.IronDoor }, // IronDoorBlock

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -20,16 +20,32 @@ namespace MinecraftClient.Mapping.BlockPalettes
/// <returns>state => block name mappings</returns>
public static void JsonToClass(string blocksJsonFile, string outputClass, string outputEnum = null)
{
Dictionary<int, string> blocks = new Dictionary<int, string>();
HashSet<int> knownStates = new HashSet<int>();
Dictionary<string, HashSet<int>> blocks = new Dictionary<string, HashSet<int>>();
Json.JSONData palette = Json.ParseJson(File.ReadAllText(blocksJsonFile));
foreach (KeyValuePair<string, Json.JSONData> item in palette.Properties)
{
string blockType = item.Key;
//minecraft:item_name => ItemName
string blockType = String.Concat(
item.Key.Replace("minecraft:", "")
.Split('_')
.Select(word => char.ToUpper(word[0]) + word.Substring(1))
);
if (blocks.ContainsKey(blockType))
throw new InvalidDataException("Duplicate block type " + blockType + "!?");
blocks[blockType] = new HashSet<int>();
foreach (Json.JSONData state in item.Value.Properties["states"].DataArray)
{
int id = int.Parse(state.Properties["id"].StringValue);
blocks[id] = blockType;
if (knownStates.Contains(id))
throw new InvalidDataException("Duplicate state id " + id + "!?");
knownStates.Add(id);
blocks[blockType].Add(id);
}
}
@ -43,24 +59,46 @@ namespace MinecraftClient.Mapping.BlockPalettes
"{",
" public class PaletteXXX : PaletteMapping",
" {",
" private static Dictionary<int, Material> materials = new Dictionary<int, Material>()",
" private static Dictionary<int, Material> materials = new Dictionary<int, Material>();",
"",
" static PaletteXXX()",
" {",
});
foreach (KeyValuePair<int, string> item in blocks)
foreach (KeyValuePair<string, HashSet<int>> blockType in blocks)
{
//minecraft:item_name => ItemName
string name = String.Concat(
item.Value.Replace("minecraft:", "")
.Split('_')
.Select(word => char.ToUpper(word[0]) + word.Substring(1))
);
outFile.Add(" { " + item.Key + ", Material." + name + " },");
materials.Add(name);
if (blockType.Value.Count > 0)
{
List<int> idList = blockType.Value.ToList();
string materialName = blockType.Key;
materials.Add(materialName);
if (idList.Count > 1)
{
idList.Sort();
Queue<int> idQueue = new Queue<int>(idList);
while (idQueue.Count > 0)
{
int startValue = idQueue.Dequeue();
int endValue = startValue;
while (idQueue.Count > 0 && idQueue.Peek() == endValue + 1)
endValue = idQueue.Dequeue();
if (endValue > startValue)
{
outFile.Add(" for (int i = " + startValue + "; i <= " + endValue + "; i++)");
outFile.Add(" materials[i] = Material." + materialName + ";");
}
else outFile.Add(" materials[" + startValue + "] = Material." + materialName + ";");
}
}
else outFile.Add(" materials[" + idList[0] + "] = Material." + materialName + ";");
}
else throw new InvalidDataException("No state id for block type " + blockType.Key + "!?");
}
outFile.AddRange(new[] {
" };",
" }",
"",
" protected override Dictionary<int, Material> GetDict()",
" {",
@ -75,11 +113,18 @@ namespace MinecraftClient.Mapping.BlockPalettes
if (outputEnum != null)
{
outFile = new List<string>();
outFile.Add(" public enum Material");
outFile.Add(" {");
outFile.AddRange(new[] {
"namespace MinecraftClient.Mapping",
"{",
" public enum Material",
" {"
});
foreach (string material in materials)
outFile.Add(" " + material + ",");
outFile.Add(" }");
outFile.AddRange(new[] {
" }",
"}"
});
File.WriteAllLines(outputEnum, outFile);
}
}