mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
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:
parent
d2cbc9f1c3
commit
0d58fb9063
11 changed files with 2703 additions and 8900 deletions
|
|
@ -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
1116
MinecraftClient/Mapping/BlockPalettes/Palette114.cs
Normal file
1116
MinecraftClient/Mapping/BlockPalettes/Palette114.cs
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -142,6 +142,9 @@
|
|||
WhiteTulip,
|
||||
PinkTulip,
|
||||
OxeyeDaisy,
|
||||
Cornflower,
|
||||
WitherRose,
|
||||
LilyOfTheValley,
|
||||
BrownMushroom,
|
||||
RedMushroom,
|
||||
GoldBlock,
|
||||
|
|
@ -164,12 +167,22 @@
|
|||
Wheat,
|
||||
Farmland,
|
||||
Furnace,
|
||||
Sign,
|
||||
OakSign,
|
||||
SpruceSign,
|
||||
BirchSign,
|
||||
AcaciaSign,
|
||||
JungleSign,
|
||||
DarkOakSign,
|
||||
OakDoor,
|
||||
Ladder,
|
||||
Rail,
|
||||
CobblestoneStairs,
|
||||
WallSign,
|
||||
OakWallSign,
|
||||
SpruceWallSign,
|
||||
BirchWallSign,
|
||||
AcaciaWallSign,
|
||||
JungleWallSign,
|
||||
DarkOakWallSign,
|
||||
Lever,
|
||||
StonePressurePlate,
|
||||
IronDoor,
|
||||
|
|
@ -222,16 +235,16 @@
|
|||
JungleTrapdoor,
|
||||
AcaciaTrapdoor,
|
||||
DarkOakTrapdoor,
|
||||
StoneBricks,
|
||||
MossyStoneBricks,
|
||||
CrackedStoneBricks,
|
||||
ChiseledStoneBricks,
|
||||
InfestedStone,
|
||||
InfestedCobblestone,
|
||||
InfestedStoneBricks,
|
||||
InfestedMossyStoneBricks,
|
||||
InfestedCrackedStoneBricks,
|
||||
InfestedChiseledStoneBricks,
|
||||
StoneBricks,
|
||||
MossyStoneBricks,
|
||||
CrackedStoneBricks,
|
||||
ChiseledStoneBricks,
|
||||
BrownMushroomBlock,
|
||||
RedMushroomBlock,
|
||||
MushroomStem,
|
||||
|
|
@ -292,6 +305,9 @@
|
|||
PottedWhiteTulip,
|
||||
PottedPinkTulip,
|
||||
PottedOxeyeDaisy,
|
||||
PottedCornflower,
|
||||
PottedLilyOfTheValley,
|
||||
PottedWitherRose,
|
||||
PottedRedMushroom,
|
||||
PottedBrownMushroom,
|
||||
PottedDeadBush,
|
||||
|
|
@ -304,18 +320,18 @@
|
|||
JungleButton,
|
||||
AcaciaButton,
|
||||
DarkOakButton,
|
||||
SkeletonWallSkull,
|
||||
SkeletonSkull,
|
||||
WitherSkeletonWallSkull,
|
||||
SkeletonWallSkull,
|
||||
WitherSkeletonSkull,
|
||||
ZombieWallHead,
|
||||
WitherSkeletonWallSkull,
|
||||
ZombieHead,
|
||||
PlayerWallHead,
|
||||
ZombieWallHead,
|
||||
PlayerHead,
|
||||
CreeperWallHead,
|
||||
PlayerWallHead,
|
||||
CreeperHead,
|
||||
DragonWallHead,
|
||||
CreeperWallHead,
|
||||
DragonHead,
|
||||
DragonWallHead,
|
||||
Anvil,
|
||||
ChippedAnvil,
|
||||
DamagedAnvil,
|
||||
|
|
@ -449,7 +465,9 @@
|
|||
AcaciaSlab,
|
||||
DarkOakSlab,
|
||||
StoneSlab,
|
||||
SmoothStoneSlab,
|
||||
SandstoneSlab,
|
||||
CutSandstoneSlab,
|
||||
PetrifiedOakSlab,
|
||||
CobblestoneSlab,
|
||||
BrickSlab,
|
||||
|
|
@ -457,6 +475,7 @@
|
|||
NetherBrickSlab,
|
||||
QuartzSlab,
|
||||
RedSandstoneSlab,
|
||||
CutRedSandstoneSlab,
|
||||
PurpurSlab,
|
||||
SmoothStone,
|
||||
SmoothSandstone,
|
||||
|
|
@ -585,16 +604,6 @@
|
|||
BubbleCoral,
|
||||
FireCoral,
|
||||
HornCoral,
|
||||
DeadTubeCoralWallFan,
|
||||
DeadBrainCoralWallFan,
|
||||
DeadBubbleCoralWallFan,
|
||||
DeadFireCoralWallFan,
|
||||
DeadHornCoralWallFan,
|
||||
TubeCoralWallFan,
|
||||
BrainCoralWallFan,
|
||||
BubbleCoralWallFan,
|
||||
FireCoralWallFan,
|
||||
HornCoralWallFan,
|
||||
DeadTubeCoralFan,
|
||||
DeadBrainCoralFan,
|
||||
DeadBubbleCoralFan,
|
||||
|
|
@ -605,12 +614,81 @@
|
|||
BubbleCoralFan,
|
||||
FireCoralFan,
|
||||
HornCoralFan,
|
||||
DeadTubeCoralWallFan,
|
||||
DeadBrainCoralWallFan,
|
||||
DeadBubbleCoralWallFan,
|
||||
DeadFireCoralWallFan,
|
||||
DeadHornCoralWallFan,
|
||||
TubeCoralWallFan,
|
||||
BrainCoralWallFan,
|
||||
BubbleCoralWallFan,
|
||||
FireCoralWallFan,
|
||||
HornCoralWallFan,
|
||||
SeaPickle,
|
||||
BlueIce,
|
||||
Conduit,
|
||||
BambooSapling,
|
||||
Bamboo,
|
||||
PottedBamboo,
|
||||
VoidAir,
|
||||
CaveAir,
|
||||
BubbleColumn,
|
||||
PolishedGraniteStairs,
|
||||
SmoothRedSandstoneStairs,
|
||||
MossyStoneBrickStairs,
|
||||
PolishedDioriteStairs,
|
||||
MossyCobblestoneStairs,
|
||||
EndStoneBrickStairs,
|
||||
StoneStairs,
|
||||
SmoothSandstoneStairs,
|
||||
SmoothQuartzStairs,
|
||||
GraniteStairs,
|
||||
AndesiteStairs,
|
||||
RedNetherBrickStairs,
|
||||
PolishedAndesiteStairs,
|
||||
DioriteStairs,
|
||||
PolishedGraniteSlab,
|
||||
SmoothRedSandstoneSlab,
|
||||
MossyStoneBrickSlab,
|
||||
PolishedDioriteSlab,
|
||||
MossyCobblestoneSlab,
|
||||
EndStoneBrickSlab,
|
||||
SmoothSandstoneSlab,
|
||||
SmoothQuartzSlab,
|
||||
GraniteSlab,
|
||||
AndesiteSlab,
|
||||
RedNetherBrickSlab,
|
||||
PolishedAndesiteSlab,
|
||||
DioriteSlab,
|
||||
BrickWall,
|
||||
PrismarineWall,
|
||||
RedSandstoneWall,
|
||||
MossyStoneBrickWall,
|
||||
GraniteWall,
|
||||
StoneBrickWall,
|
||||
NetherBrickWall,
|
||||
AndesiteWall,
|
||||
RedNetherBrickWall,
|
||||
SandstoneWall,
|
||||
EndStoneBrickWall,
|
||||
DioriteWall,
|
||||
Scaffolding,
|
||||
Loom,
|
||||
Barrel,
|
||||
Smoker,
|
||||
BlastFurnace,
|
||||
CartographyTable,
|
||||
FletchingTable,
|
||||
Grindstone,
|
||||
Lectern,
|
||||
SmithingTable,
|
||||
Stonecutter,
|
||||
Bell,
|
||||
Lantern,
|
||||
Campfire,
|
||||
SweetBerryBush,
|
||||
StructureBlock,
|
||||
Jigsaw,
|
||||
Composter,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -135,7 +135,6 @@ namespace MinecraftClient.Mapping
|
|||
case Material.CraftingTable:
|
||||
case Material.Farmland:
|
||||
case Material.Furnace:
|
||||
case Material.Sign:
|
||||
case Material.OakDoor:
|
||||
case Material.Ladder:
|
||||
case Material.CobblestoneStairs:
|
||||
|
|
@ -176,16 +175,16 @@ namespace MinecraftClient.Mapping
|
|||
case Material.JungleTrapdoor:
|
||||
case Material.AcaciaTrapdoor:
|
||||
case Material.DarkOakTrapdoor:
|
||||
case Material.StoneBricks:
|
||||
case Material.MossyStoneBricks:
|
||||
case Material.CrackedStoneBricks:
|
||||
case Material.ChiseledStoneBricks:
|
||||
case Material.InfestedStone:
|
||||
case Material.InfestedCobblestone:
|
||||
case Material.InfestedStoneBricks:
|
||||
case Material.InfestedMossyStoneBricks:
|
||||
case Material.InfestedCrackedStoneBricks:
|
||||
case Material.InfestedChiseledStoneBricks:
|
||||
case Material.StoneBricks:
|
||||
case Material.MossyStoneBricks:
|
||||
case Material.CrackedStoneBricks:
|
||||
case Material.ChiseledStoneBricks:
|
||||
case Material.BrownMushroomBlock:
|
||||
case Material.RedMushroomBlock:
|
||||
case Material.MushroomStem:
|
||||
|
|
@ -236,22 +235,25 @@ namespace MinecraftClient.Mapping
|
|||
case Material.PottedWhiteTulip:
|
||||
case Material.PottedPinkTulip:
|
||||
case Material.PottedOxeyeDaisy:
|
||||
case Material.PottedCornflower:
|
||||
case Material.PottedLilyOfTheValley:
|
||||
case Material.PottedWitherRose:
|
||||
case Material.PottedRedMushroom:
|
||||
case Material.PottedBrownMushroom:
|
||||
case Material.PottedDeadBush:
|
||||
case Material.PottedCactus:
|
||||
case Material.SkeletonWallSkull:
|
||||
case Material.SkeletonSkull:
|
||||
case Material.WitherSkeletonWallSkull:
|
||||
case Material.SkeletonWallSkull:
|
||||
case Material.WitherSkeletonSkull:
|
||||
case Material.ZombieWallHead:
|
||||
case Material.WitherSkeletonWallSkull:
|
||||
case Material.ZombieHead:
|
||||
case Material.PlayerWallHead:
|
||||
case Material.ZombieWallHead:
|
||||
case Material.PlayerHead:
|
||||
case Material.CreeperWallHead:
|
||||
case Material.PlayerWallHead:
|
||||
case Material.CreeperHead:
|
||||
case Material.DragonWallHead:
|
||||
case Material.CreeperWallHead:
|
||||
case Material.DragonHead:
|
||||
case Material.DragonWallHead:
|
||||
case Material.Anvil:
|
||||
case Material.ChippedAnvil:
|
||||
case Material.DamagedAnvil:
|
||||
|
|
@ -327,7 +329,9 @@ namespace MinecraftClient.Mapping
|
|||
case Material.AcaciaSlab:
|
||||
case Material.DarkOakSlab:
|
||||
case Material.StoneSlab:
|
||||
case Material.SmoothStoneSlab:
|
||||
case Material.SandstoneSlab:
|
||||
case Material.CutSandstoneSlab:
|
||||
case Material.PetrifiedOakSlab:
|
||||
case Material.CobblestoneSlab:
|
||||
case Material.BrickSlab:
|
||||
|
|
@ -335,6 +339,7 @@ namespace MinecraftClient.Mapping
|
|||
case Material.NetherBrickSlab:
|
||||
case Material.QuartzSlab:
|
||||
case Material.RedSandstoneSlab:
|
||||
case Material.CutRedSandstoneSlab:
|
||||
case Material.PurpurSlab:
|
||||
case Material.SmoothStone:
|
||||
case Material.SmoothSandstone:
|
||||
|
|
@ -451,8 +456,64 @@ namespace MinecraftClient.Mapping
|
|||
case Material.SeaPickle:
|
||||
case Material.BlueIce:
|
||||
case Material.Conduit:
|
||||
case Material.Bamboo:
|
||||
case Material.PottedBamboo:
|
||||
case Material.BubbleColumn:
|
||||
case Material.PolishedGraniteStairs:
|
||||
case Material.SmoothRedSandstoneStairs:
|
||||
case Material.MossyStoneBrickStairs:
|
||||
case Material.PolishedDioriteStairs:
|
||||
case Material.MossyCobblestoneStairs:
|
||||
case Material.EndStoneBrickStairs:
|
||||
case Material.StoneStairs:
|
||||
case Material.SmoothSandstoneStairs:
|
||||
case Material.SmoothQuartzStairs:
|
||||
case Material.GraniteStairs:
|
||||
case Material.AndesiteStairs:
|
||||
case Material.RedNetherBrickStairs:
|
||||
case Material.PolishedAndesiteStairs:
|
||||
case Material.DioriteStairs:
|
||||
case Material.PolishedGraniteSlab:
|
||||
case Material.SmoothRedSandstoneSlab:
|
||||
case Material.MossyStoneBrickSlab:
|
||||
case Material.PolishedDioriteSlab:
|
||||
case Material.MossyCobblestoneSlab:
|
||||
case Material.EndStoneBrickSlab:
|
||||
case Material.SmoothSandstoneSlab:
|
||||
case Material.SmoothQuartzSlab:
|
||||
case Material.GraniteSlab:
|
||||
case Material.AndesiteSlab:
|
||||
case Material.RedNetherBrickSlab:
|
||||
case Material.PolishedAndesiteSlab:
|
||||
case Material.DioriteSlab:
|
||||
case Material.BrickWall:
|
||||
case Material.PrismarineWall:
|
||||
case Material.RedSandstoneWall:
|
||||
case Material.MossyStoneBrickWall:
|
||||
case Material.GraniteWall:
|
||||
case Material.StoneBrickWall:
|
||||
case Material.NetherBrickWall:
|
||||
case Material.AndesiteWall:
|
||||
case Material.RedNetherBrickWall:
|
||||
case Material.SandstoneWall:
|
||||
case Material.EndStoneBrickWall:
|
||||
case Material.DioriteWall:
|
||||
case Material.Loom:
|
||||
case Material.Barrel:
|
||||
case Material.Smoker:
|
||||
case Material.BlastFurnace:
|
||||
case Material.CartographyTable:
|
||||
case Material.FletchingTable:
|
||||
case Material.Grindstone:
|
||||
case Material.Lectern:
|
||||
case Material.SmithingTable:
|
||||
case Material.Stonecutter:
|
||||
case Material.Bell:
|
||||
case Material.Lantern:
|
||||
case Material.Campfire:
|
||||
case Material.StructureBlock:
|
||||
case Material.Jigsaw:
|
||||
case Material.Composter:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
|
|
@ -472,6 +533,7 @@ namespace MinecraftClient.Mapping
|
|||
case Material.Cactus:
|
||||
case Material.Lava:
|
||||
case Material.MagmaBlock:
|
||||
case Material.Campfire:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -99,6 +99,7 @@
|
|||
<Compile Include="Commands\Set.cs" />
|
||||
<Compile Include="Mapping\BlockPalettes\Palette112.cs" />
|
||||
<Compile Include="Mapping\BlockPalettes\Palette113.cs" />
|
||||
<Compile Include="Mapping\BlockPalettes\Palette114.cs" />
|
||||
<Compile Include="Mapping\BlockPalettes\PaletteGenerator.cs" />
|
||||
<Compile Include="Mapping\BlockPalettes\PaletteMapping.cs" />
|
||||
<Compile Include="Mapping\MaterialExtensions.cs" />
|
||||
|
|
@ -107,6 +108,7 @@
|
|||
<Compile Include="Protocol\Handlers\PacketOutgoingType.cs" />
|
||||
<Compile Include="Protocol\Handlers\Protocol18Forge.cs" />
|
||||
<Compile Include="Protocol\Handlers\Protocol18PacketTypes.cs" />
|
||||
<Compile Include="Protocol\Handlers\Protocol18Terrain.cs" />
|
||||
<Compile Include="Protocol\Handlers\SocketWrapper.cs" />
|
||||
<Compile Include="Protocol\Session\SessionFileMonitor.cs" />
|
||||
<Compile Include="WinAPI\ConsoleIcon.cs" />
|
||||
|
|
|
|||
|
|
@ -86,6 +86,17 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
return BitConverter.ToInt32(rawValue, 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a long integer from a cache of bytes and remove it from the cache
|
||||
/// </summary>
|
||||
/// <returns>The unsigned long integer value</returns>
|
||||
public long ReadNextLong(List<byte> cache)
|
||||
{
|
||||
byte[] rawValue = ReadData(8, cache);
|
||||
Array.Reverse(rawValue); //Endianness
|
||||
return BitConverter.ToInt64(rawValue, 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read an unsigned short integer from a cache of bytes and remove it from the cache
|
||||
/// </summary>
|
||||
|
|
@ -299,6 +310,88 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read an uncompressed Named Binary Tag blob and remove it from the cache
|
||||
/// </summary>
|
||||
public Dictionary<string, object> ReadNextNbt(List<byte> cache)
|
||||
{
|
||||
return ReadNextNbt(cache, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read an uncompressed Named Binary Tag blob and remove it from the cache (internal)
|
||||
/// </summary>
|
||||
private Dictionary<string, object> ReadNextNbt(List<byte> cache, bool root)
|
||||
{
|
||||
if (root)
|
||||
{
|
||||
if (cache[0] != 10) // TAG_Compound
|
||||
throw new System.IO.InvalidDataException("Failed to decode NBT: Does not start with TAG_Compound");
|
||||
ReadNextByte(cache); // Tag type (TAG_Compound)
|
||||
ReadData(ReadNextUShort(cache), cache); // NBT root name
|
||||
}
|
||||
|
||||
Dictionary<string, object> NbtData = new Dictionary<string, object>();
|
||||
|
||||
while (true)
|
||||
{
|
||||
int fieldType = ReadNextByte(cache);
|
||||
|
||||
if (fieldType == 0) // TAG_End
|
||||
return NbtData;
|
||||
|
||||
int fieldNameLength = ReadNextUShort(cache);
|
||||
string fieldName = Encoding.ASCII.GetString(ReadData(fieldNameLength, cache));
|
||||
object fieldValue = ReadNbtField(cache, fieldType);
|
||||
|
||||
// This will override previous tags with the same name
|
||||
NbtData[fieldName] = fieldValue;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a single Named Binary Tag field of the specified type and remove it from the cache
|
||||
/// </summary>
|
||||
private object ReadNbtField(List<byte> cache, int fieldType)
|
||||
{
|
||||
switch (fieldType)
|
||||
{
|
||||
case 1: // TAG_Byte
|
||||
return ReadNextByte(cache);
|
||||
case 2: // TAG_Short
|
||||
return ReadNextShort(cache);
|
||||
case 3: // TAG_Int
|
||||
return ReadNextInt(cache);
|
||||
case 4: // TAG_Long
|
||||
return ReadNextLong(cache);
|
||||
case 5: // TAG_Float
|
||||
return ReadNextFloat(cache);
|
||||
case 6: // TAG_Double
|
||||
return ReadNextDouble(cache);
|
||||
case 7: // TAG_Byte_Array
|
||||
return ReadData(ReadNextInt(cache), cache);
|
||||
case 8: // TAG_String
|
||||
return Encoding.UTF8.GetString(ReadData(ReadNextUShort(cache), cache));
|
||||
case 9: // TAG_List
|
||||
int listType = ReadNextByte(cache);
|
||||
int listLength = ReadNextInt(cache);
|
||||
object[] listItems = new object[listLength];
|
||||
for (int i = 0; i < listLength; i++)
|
||||
listItems[i] = ReadNbtField(cache, listType);
|
||||
return listItems;
|
||||
case 10: // TAG_Compound
|
||||
return ReadNextNbt(cache, false);
|
||||
case 11: // TAG_Int_Array
|
||||
cache.Insert(0, 3); // List type = TAG_Int
|
||||
return ReadNbtField(cache, 9); // Read as TAG_List
|
||||
case 12: // TAG_Long_Array
|
||||
cache.Insert(0, 4); // List type = TAG_Long
|
||||
return ReadNbtField(cache, 9); // Read as TAG_List
|
||||
default:
|
||||
throw new System.IO.InvalidDataException("Failed to decode NBT: Unknown field type " + fieldType);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Build an integer for sending over the network
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
private int currentDimension;
|
||||
|
||||
Protocol18Forge pForge;
|
||||
Protocol18Terrain pTerrain;
|
||||
IMinecraftComHandler handler;
|
||||
SocketWrapper socketWrapper;
|
||||
DataTypes dataTypes;
|
||||
|
|
@ -58,11 +59,19 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
this.protocolversion = protocolVersion;
|
||||
this.handler = handler;
|
||||
this.pForge = new Protocol18Forge(forgeInfo, protocolVersion, dataTypes, this, handler);
|
||||
this.pTerrain = new Protocol18Terrain(protocolVersion, dataTypes, handler);
|
||||
|
||||
if (protocolversion >= MC113Version)
|
||||
Block.Palette = new Palette113();
|
||||
{
|
||||
if (protocolVersion > MC114Version && handler.GetTerrainEnabled())
|
||||
throw new NotImplementedException("Please update block types handling for this Minecraft version. See Material.cs");
|
||||
if (protocolVersion >= MC114Version)
|
||||
Block.Palette = new Palette114();
|
||||
else Block.Palette = new Palette113();
|
||||
}
|
||||
else Block.Palette = new Palette112();
|
||||
|
||||
if (handler.GetTerrainEnabled() && protocolversion >= MC114Version)
|
||||
if (handler.GetTerrainEnabled() && protocolversion > MC114Version)
|
||||
{
|
||||
ConsoleIO.WriteLineFormatted("§8Terrain & Movements currently not handled for that MC version.");
|
||||
handler.SetTerrainEnabled(false);
|
||||
|
|
@ -250,16 +259,14 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
int compressedDataSize = dataTypes.ReadNextInt(packetData);
|
||||
byte[] compressed = dataTypes.ReadData(compressedDataSize, packetData);
|
||||
byte[] decompressed = ZlibUtils.Decompress(compressed);
|
||||
ProcessChunkColumnData(chunkX, chunkZ, chunkMask, addBitmap, currentDimension == 0, chunksContinuous, new List<byte>(decompressed));
|
||||
pTerrain.ProcessChunkColumnData(chunkX, chunkZ, chunkMask, addBitmap, currentDimension == 0, chunksContinuous, currentDimension, new List<byte>(decompressed));
|
||||
}
|
||||
else
|
||||
{
|
||||
//TODO skip NBT Heightmaps field for 1.14
|
||||
//if (protocolversion >= MC114Version)
|
||||
// dataTypes.ReadNextNBT(packetData);
|
||||
//TODO update Material.cs for 1.14
|
||||
if (protocolversion >= MC114Version)
|
||||
dataTypes.ReadNextNbt(packetData); // Heightmaps - 1.14 and above
|
||||
int dataSize = dataTypes.ReadNextVarInt(packetData);
|
||||
ProcessChunkColumnData(chunkX, chunkZ, chunkMask, 0, false, chunksContinuous, packetData);
|
||||
pTerrain.ProcessChunkColumnData(chunkX, chunkZ, chunkMask, 0, false, chunksContinuous, currentDimension, packetData);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
@ -353,7 +360,7 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
|
||||
//Process chunk records
|
||||
for (int chunkColumnNo = 0; chunkColumnNo < chunkCount; chunkColumnNo++)
|
||||
ProcessChunkColumnData(chunkXs[chunkColumnNo], chunkZs[chunkColumnNo], chunkMasks[chunkColumnNo], addBitmaps[chunkColumnNo], hasSkyLight, true, chunkData);
|
||||
pTerrain.ProcessChunkColumnData(chunkXs[chunkColumnNo], chunkZs[chunkColumnNo], chunkMasks[chunkColumnNo], addBitmaps[chunkColumnNo], hasSkyLight, true, currentDimension, chunkData);
|
||||
}
|
||||
break;
|
||||
case PacketIncomingType.UnloadChunk:
|
||||
|
|
@ -484,221 +491,6 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Process chunk column data from the server and (un)load the chunk from the Minecraft world
|
||||
/// </summary>
|
||||
/// <param name="chunkX">Chunk X location</param>
|
||||
/// <param name="chunkZ">Chunk Z location</param>
|
||||
/// <param name="chunkMask">Chunk mask for reading data</param>
|
||||
/// <param name="chunkMask2">Chunk mask for some additional 1.7 metadata</param>
|
||||
/// <param name="hasSkyLight">Contains skylight info</param>
|
||||
/// <param name="chunksContinuous">Are the chunk continuous</param>
|
||||
/// <param name="cache">Cache for reading chunk data</param>
|
||||
private void ProcessChunkColumnData(int chunkX, int chunkZ, ushort chunkMask, ushort chunkMask2, bool hasSkyLight, bool chunksContinuous, List<byte> cache)
|
||||
{
|
||||
if (protocolversion >= MC19Version)
|
||||
{
|
||||
// 1.9 and above chunk format
|
||||
// Unloading chunks is handled by a separate packet
|
||||
for (int chunkY = 0; chunkY < ChunkColumn.ColumnSize; chunkY++)
|
||||
{
|
||||
if ((chunkMask & (1 << chunkY)) != 0)
|
||||
{
|
||||
byte bitsPerBlock = dataTypes.ReadNextByte(cache);
|
||||
bool usePalette = (bitsPerBlock <= 8);
|
||||
|
||||
// Vanilla Minecraft will use at least 4 bits per block
|
||||
if (bitsPerBlock < 4)
|
||||
bitsPerBlock = 4;
|
||||
|
||||
// MC 1.9 to 1.12 will set palette length field to 0 when palette
|
||||
// is not used, MC 1.13+ does not send the field at all in this case
|
||||
int paletteLength = 0; // Assume zero when length is absent
|
||||
if (usePalette || protocolversion < MC113Version)
|
||||
paletteLength = dataTypes.ReadNextVarInt(cache);
|
||||
|
||||
int[] palette = new int[paletteLength];
|
||||
for (int i = 0; i < paletteLength; i++)
|
||||
{
|
||||
palette[i] = dataTypes.ReadNextVarInt(cache);
|
||||
}
|
||||
|
||||
// Bit mask covering bitsPerBlock bits
|
||||
// EG, if bitsPerBlock = 5, valueMask = 00011111 in binary
|
||||
uint valueMask = (uint)((1 << bitsPerBlock) - 1);
|
||||
|
||||
ulong[] dataArray = dataTypes.ReadNextULongArray(cache);
|
||||
|
||||
Chunk chunk = new Chunk();
|
||||
|
||||
if (dataArray.Length > 0)
|
||||
{
|
||||
for (int blockY = 0; blockY < Chunk.SizeY; blockY++)
|
||||
{
|
||||
for (int blockZ = 0; blockZ < Chunk.SizeZ; blockZ++)
|
||||
{
|
||||
for (int blockX = 0; blockX < Chunk.SizeX; blockX++)
|
||||
{
|
||||
int blockNumber = (blockY * Chunk.SizeZ + blockZ) * Chunk.SizeX + blockX;
|
||||
|
||||
int startLong = (blockNumber * bitsPerBlock) / 64;
|
||||
int startOffset = (blockNumber * bitsPerBlock) % 64;
|
||||
int endLong = ((blockNumber + 1) * bitsPerBlock - 1) / 64;
|
||||
|
||||
// TODO: In the future a single ushort may not store the entire block id;
|
||||
// the Block code may need to change if block state IDs go beyond 65535
|
||||
ushort blockId;
|
||||
if (startLong == endLong)
|
||||
{
|
||||
blockId = (ushort)((dataArray[startLong] >> startOffset) & valueMask);
|
||||
}
|
||||
else
|
||||
{
|
||||
int endOffset = 64 - startOffset;
|
||||
blockId = (ushort)((dataArray[startLong] >> startOffset | dataArray[endLong] << endOffset) & valueMask);
|
||||
}
|
||||
|
||||
if (usePalette)
|
||||
{
|
||||
// Get the real block ID out of the palette
|
||||
blockId = (ushort)palette[blockId];
|
||||
}
|
||||
|
||||
chunk[blockX, blockY, blockZ] = new Block(blockId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//We have our chunk, save the chunk into the world
|
||||
if (handler.GetWorld()[chunkX, chunkZ] == null)
|
||||
handler.GetWorld()[chunkX, chunkZ] = new ChunkColumn();
|
||||
handler.GetWorld()[chunkX, chunkZ][chunkY] = chunk;
|
||||
|
||||
//Skip block light
|
||||
dataTypes.ReadData((Chunk.SizeX * Chunk.SizeY * Chunk.SizeZ) / 2, cache);
|
||||
|
||||
//Skip sky light
|
||||
if (this.currentDimension == 0)
|
||||
// Sky light is not sent in the nether or the end
|
||||
dataTypes.ReadData((Chunk.SizeX * Chunk.SizeY * Chunk.SizeZ) / 2, cache);
|
||||
}
|
||||
}
|
||||
|
||||
// Don't worry about skipping remaining data since there is no useful data afterwards in 1.9
|
||||
// (plus, it would require parsing the tile entity lists' NBT)
|
||||
}
|
||||
else if (protocolversion >= MC18Version)
|
||||
{
|
||||
// 1.8 chunk format
|
||||
if (chunksContinuous && chunkMask == 0)
|
||||
{
|
||||
//Unload the entire chunk column
|
||||
handler.GetWorld()[chunkX, chunkZ] = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Load chunk data from the server
|
||||
for (int chunkY = 0; chunkY < ChunkColumn.ColumnSize; chunkY++)
|
||||
{
|
||||
if ((chunkMask & (1 << chunkY)) != 0)
|
||||
{
|
||||
Chunk chunk = new Chunk();
|
||||
|
||||
//Read chunk data, all at once for performance reasons, and build the chunk object
|
||||
Queue<ushort> queue = new Queue<ushort>(dataTypes.ReadNextUShortsLittleEndian(Chunk.SizeX * Chunk.SizeY * Chunk.SizeZ, cache));
|
||||
for (int blockY = 0; blockY < Chunk.SizeY; blockY++)
|
||||
for (int blockZ = 0; blockZ < Chunk.SizeZ; blockZ++)
|
||||
for (int blockX = 0; blockX < Chunk.SizeX; blockX++)
|
||||
chunk[blockX, blockY, blockZ] = new Block(queue.Dequeue());
|
||||
|
||||
//We have our chunk, save the chunk into the world
|
||||
if (handler.GetWorld()[chunkX, chunkZ] == null)
|
||||
handler.GetWorld()[chunkX, chunkZ] = new ChunkColumn();
|
||||
handler.GetWorld()[chunkX, chunkZ][chunkY] = chunk;
|
||||
}
|
||||
}
|
||||
|
||||
//Skip light information
|
||||
for (int chunkY = 0; chunkY < ChunkColumn.ColumnSize; chunkY++)
|
||||
{
|
||||
if ((chunkMask & (1 << chunkY)) != 0)
|
||||
{
|
||||
//Skip block light
|
||||
dataTypes.ReadData((Chunk.SizeX * Chunk.SizeY * Chunk.SizeZ) / 2, cache);
|
||||
|
||||
//Skip sky light
|
||||
if (hasSkyLight)
|
||||
dataTypes.ReadData((Chunk.SizeX * Chunk.SizeY * Chunk.SizeZ) / 2, cache);
|
||||
}
|
||||
}
|
||||
|
||||
//Skip biome metadata
|
||||
if (chunksContinuous)
|
||||
dataTypes.ReadData(Chunk.SizeX * Chunk.SizeZ, cache);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 1.7 chunk format
|
||||
if (chunksContinuous && chunkMask == 0)
|
||||
{
|
||||
//Unload the entire chunk column
|
||||
handler.GetWorld()[chunkX, chunkZ] = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Count chunk sections
|
||||
int sectionCount = 0;
|
||||
int addDataSectionCount = 0;
|
||||
for (int chunkY = 0; chunkY < ChunkColumn.ColumnSize; chunkY++)
|
||||
{
|
||||
if ((chunkMask & (1 << chunkY)) != 0)
|
||||
sectionCount++;
|
||||
if ((chunkMask2 & (1 << chunkY)) != 0)
|
||||
addDataSectionCount++;
|
||||
}
|
||||
|
||||
//Read chunk data, unpacking 4-bit values into 8-bit values for block metadata
|
||||
Queue<byte> blockTypes = new Queue<byte>(dataTypes.ReadData(Chunk.SizeX * Chunk.SizeY * Chunk.SizeZ * sectionCount, cache));
|
||||
Queue<byte> blockMeta = new Queue<byte>();
|
||||
foreach (byte packed in dataTypes.ReadData((Chunk.SizeX * Chunk.SizeY * Chunk.SizeZ * sectionCount) / 2, cache))
|
||||
{
|
||||
byte hig = (byte)(packed >> 4);
|
||||
byte low = (byte)(packed & (byte)0x0F);
|
||||
blockMeta.Enqueue(hig);
|
||||
blockMeta.Enqueue(low);
|
||||
}
|
||||
|
||||
//Skip data we don't need
|
||||
dataTypes.ReadData((Chunk.SizeX * Chunk.SizeY * Chunk.SizeZ * sectionCount) / 2, cache); //Block light
|
||||
if (hasSkyLight)
|
||||
dataTypes.ReadData((Chunk.SizeX * Chunk.SizeY * Chunk.SizeZ * sectionCount) / 2, cache); //Sky light
|
||||
dataTypes.ReadData((Chunk.SizeX * Chunk.SizeY * Chunk.SizeZ * addDataSectionCount) / 2, cache); //BlockAdd
|
||||
if (chunksContinuous)
|
||||
dataTypes.ReadData(Chunk.SizeX * Chunk.SizeZ, cache); //Biomes
|
||||
|
||||
//Load chunk data
|
||||
for (int chunkY = 0; chunkY < ChunkColumn.ColumnSize; chunkY++)
|
||||
{
|
||||
if ((chunkMask & (1 << chunkY)) != 0)
|
||||
{
|
||||
Chunk chunk = new Chunk();
|
||||
|
||||
for (int blockY = 0; blockY < Chunk.SizeY; blockY++)
|
||||
for (int blockZ = 0; blockZ < Chunk.SizeZ; blockZ++)
|
||||
for (int blockX = 0; blockX < Chunk.SizeX; blockX++)
|
||||
chunk[blockX, blockY, blockZ] = new Block(blockTypes.Dequeue(), blockMeta.Dequeue());
|
||||
|
||||
if (handler.GetWorld()[chunkX, chunkZ] == null)
|
||||
handler.GetWorld()[chunkX, chunkZ] = new ChunkColumn();
|
||||
handler.GetWorld()[chunkX, chunkZ][chunkY] = chunk;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Start the updating thread. Should be called after login success.
|
||||
/// </summary>
|
||||
|
|
@ -1148,28 +940,7 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
protocolversion = dataTypes.Atoi(versionData.Properties["protocol"].StringValue);
|
||||
|
||||
// Check for forge on the server.
|
||||
if (jsonData.Properties.ContainsKey("modinfo") && jsonData.Properties["modinfo"].Type == Json.JSONData.DataType.Object)
|
||||
{
|
||||
Json.JSONData modData = jsonData.Properties["modinfo"];
|
||||
if (modData.Properties.ContainsKey("type") && modData.Properties["type"].StringValue == "FML")
|
||||
{
|
||||
forgeInfo = new ForgeInfo(modData);
|
||||
|
||||
if (forgeInfo.Mods.Any())
|
||||
{
|
||||
if (Settings.DebugMessages)
|
||||
{
|
||||
ConsoleIO.WriteLineFormatted("§8Server is running Forge. Mod list:");
|
||||
foreach (ForgeInfo.ForgeMod mod in forgeInfo.Mods)
|
||||
{
|
||||
ConsoleIO.WriteLineFormatted("§8 " + mod.ToString());
|
||||
}
|
||||
}
|
||||
else ConsoleIO.WriteLineFormatted("§8Server is running Forge.");
|
||||
}
|
||||
else forgeInfo = null;
|
||||
}
|
||||
}
|
||||
Protocol18Forge.ServerInfoCheckForge(jsonData, ref forgeInfo);
|
||||
|
||||
ConsoleIO.WriteLineFormatted("§8Server version : " + version + " (protocol v" + protocolversion + (forgeInfo != null ? ", with Forge)." : ")."));
|
||||
|
||||
|
|
|
|||
|
|
@ -234,7 +234,7 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send a forge plugin channel packet ("FML|HS"). Compression and encryption will be handled automatically
|
||||
/// Send a forge plugin channel packet ("FML|HS"). Compression and encryption will be handled automatically.
|
||||
/// </summary>
|
||||
/// <param name="discriminator">Discriminator to use.</param>
|
||||
/// <param name="data">packet Data</param>
|
||||
|
|
@ -242,5 +242,36 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
{
|
||||
protocol18.SendPluginChannelPacket("FML|HS", dataTypes.ConcatBytes(new byte[] { (byte)discriminator }, data));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Server Info: Check for For Forge on a Minecraft server Ping result
|
||||
/// </summary>
|
||||
/// <param name="jsonData">JSON data returned by the server</param>
|
||||
/// <param name="forgeInfo">ForgeInfo to populate</param>
|
||||
public static void ServerInfoCheckForge(Json.JSONData jsonData, ref ForgeInfo forgeInfo)
|
||||
{
|
||||
if (jsonData.Properties.ContainsKey("modinfo") && jsonData.Properties["modinfo"].Type == Json.JSONData.DataType.Object)
|
||||
{
|
||||
Json.JSONData modData = jsonData.Properties["modinfo"];
|
||||
if (modData.Properties.ContainsKey("type") && modData.Properties["type"].StringValue == "FML")
|
||||
{
|
||||
forgeInfo = new ForgeInfo(modData);
|
||||
|
||||
if (forgeInfo.Mods.Any())
|
||||
{
|
||||
if (Settings.DebugMessages)
|
||||
{
|
||||
ConsoleIO.WriteLineFormatted("§8Server is running Forge. Mod list:");
|
||||
foreach (ForgeInfo.ForgeMod mod in forgeInfo.Mods)
|
||||
{
|
||||
ConsoleIO.WriteLineFormatted("§8 " + mod.ToString());
|
||||
}
|
||||
}
|
||||
else ConsoleIO.WriteLineFormatted("§8Server is running Forge.");
|
||||
}
|
||||
else forgeInfo = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
254
MinecraftClient/Protocol/Handlers/Protocol18Terrain.cs
Normal file
254
MinecraftClient/Protocol/Handlers/Protocol18Terrain.cs
Normal file
|
|
@ -0,0 +1,254 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
//using System.Linq;
|
||||
//using System.Text;
|
||||
using MinecraftClient.Mapping;
|
||||
|
||||
namespace MinecraftClient.Protocol.Handlers
|
||||
{
|
||||
/// <summary>
|
||||
/// Terrain Decoding handler for Protocol18
|
||||
/// </summary>
|
||||
class Protocol18Terrain
|
||||
{
|
||||
private int protocolversion;
|
||||
private DataTypes dataTypes;
|
||||
private IMinecraftComHandler handler;
|
||||
|
||||
/// <summary>
|
||||
/// Initialize a new Terrain Decoder
|
||||
/// </summary>
|
||||
/// <param name="protocolVersion">Minecraft Protocol Version</param>
|
||||
/// <param name="dataTypes">Minecraft Protocol Data Types</param>
|
||||
public Protocol18Terrain(int protocolVersion, DataTypes dataTypes, IMinecraftComHandler handler)
|
||||
{
|
||||
this.protocolversion = protocolVersion;
|
||||
this.dataTypes = dataTypes;
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Process chunk column data from the server and (un)load the chunk from the Minecraft world
|
||||
/// </summary>
|
||||
/// <param name="chunkX">Chunk X location</param>
|
||||
/// <param name="chunkZ">Chunk Z location</param>
|
||||
/// <param name="chunkMask">Chunk mask for reading data</param>
|
||||
/// <param name="chunkMask2">Chunk mask for some additional 1.7 metadata</param>
|
||||
/// <param name="hasSkyLight">Contains skylight info</param>
|
||||
/// <param name="chunksContinuous">Are the chunk continuous</param>
|
||||
/// <param name="currentDimension">Current dimension type (0 = overworld)</param>
|
||||
/// <param name="cache">Cache for reading chunk data</param>
|
||||
public void ProcessChunkColumnData(int chunkX, int chunkZ, ushort chunkMask, ushort chunkMask2, bool hasSkyLight, bool chunksContinuous, int currentDimension, List<byte> cache)
|
||||
{
|
||||
if (protocolversion >= Protocol18Handler.MC19Version)
|
||||
{
|
||||
// 1.9 and above chunk format
|
||||
// Unloading chunks is handled by a separate packet
|
||||
for (int chunkY = 0; chunkY < ChunkColumn.ColumnSize; chunkY++)
|
||||
{
|
||||
if ((chunkMask & (1 << chunkY)) != 0)
|
||||
{
|
||||
// 1.14 and above Non-air block count inside chunk section, for lighting purposes
|
||||
if (protocolversion >= Protocol18Handler.MC114Version)
|
||||
dataTypes.ReadNextShort(cache);
|
||||
|
||||
byte bitsPerBlock = dataTypes.ReadNextByte(cache);
|
||||
bool usePalette = (bitsPerBlock <= 8);
|
||||
|
||||
// Vanilla Minecraft will use at least 4 bits per block
|
||||
if (bitsPerBlock < 4)
|
||||
bitsPerBlock = 4;
|
||||
|
||||
// MC 1.9 to 1.12 will set palette length field to 0 when palette
|
||||
// is not used, MC 1.13+ does not send the field at all in this case
|
||||
int paletteLength = 0; // Assume zero when length is absent
|
||||
if (usePalette || protocolversion < Protocol18Handler.MC113Version)
|
||||
paletteLength = dataTypes.ReadNextVarInt(cache);
|
||||
|
||||
int[] palette = new int[paletteLength];
|
||||
for (int i = 0; i < paletteLength; i++)
|
||||
{
|
||||
palette[i] = dataTypes.ReadNextVarInt(cache);
|
||||
}
|
||||
|
||||
// Bit mask covering bitsPerBlock bits
|
||||
// EG, if bitsPerBlock = 5, valueMask = 00011111 in binary
|
||||
uint valueMask = (uint)((1 << bitsPerBlock) - 1);
|
||||
|
||||
ulong[] dataArray = dataTypes.ReadNextULongArray(cache);
|
||||
|
||||
Chunk chunk = new Chunk();
|
||||
|
||||
if (dataArray.Length > 0)
|
||||
{
|
||||
for (int blockY = 0; blockY < Chunk.SizeY; blockY++)
|
||||
{
|
||||
for (int blockZ = 0; blockZ < Chunk.SizeZ; blockZ++)
|
||||
{
|
||||
for (int blockX = 0; blockX < Chunk.SizeX; blockX++)
|
||||
{
|
||||
int blockNumber = (blockY * Chunk.SizeZ + blockZ) * Chunk.SizeX + blockX;
|
||||
|
||||
int startLong = (blockNumber * bitsPerBlock) / 64;
|
||||
int startOffset = (blockNumber * bitsPerBlock) % 64;
|
||||
int endLong = ((blockNumber + 1) * bitsPerBlock - 1) / 64;
|
||||
|
||||
// TODO: In the future a single ushort may not store the entire block id;
|
||||
// the Block code may need to change if block state IDs go beyond 65535
|
||||
ushort blockId;
|
||||
if (startLong == endLong)
|
||||
{
|
||||
blockId = (ushort)((dataArray[startLong] >> startOffset) & valueMask);
|
||||
}
|
||||
else
|
||||
{
|
||||
int endOffset = 64 - startOffset;
|
||||
blockId = (ushort)((dataArray[startLong] >> startOffset | dataArray[endLong] << endOffset) & valueMask);
|
||||
}
|
||||
|
||||
if (usePalette)
|
||||
{
|
||||
// Get the real block ID out of the palette
|
||||
blockId = (ushort)palette[blockId];
|
||||
}
|
||||
|
||||
chunk[blockX, blockY, blockZ] = new Block(blockId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//We have our chunk, save the chunk into the world
|
||||
if (handler.GetWorld()[chunkX, chunkZ] == null)
|
||||
handler.GetWorld()[chunkX, chunkZ] = new ChunkColumn();
|
||||
handler.GetWorld()[chunkX, chunkZ][chunkY] = chunk;
|
||||
|
||||
//Pre-1.14 Lighting data
|
||||
if (protocolversion < Protocol18Handler.MC114Version)
|
||||
{
|
||||
//Skip block light
|
||||
dataTypes.ReadData((Chunk.SizeX * Chunk.SizeY * Chunk.SizeZ) / 2, cache);
|
||||
|
||||
//Skip sky light
|
||||
if (currentDimension == 0)
|
||||
// Sky light is not sent in the nether or the end
|
||||
dataTypes.ReadData((Chunk.SizeX * Chunk.SizeY * Chunk.SizeZ) / 2, cache);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Don't worry about skipping remaining data since there is no useful data afterwards in 1.9
|
||||
// (plus, it would require parsing the tile entity lists' NBT)
|
||||
}
|
||||
else if (protocolversion >= Protocol18Handler.MC18Version)
|
||||
{
|
||||
// 1.8 chunk format
|
||||
if (chunksContinuous && chunkMask == 0)
|
||||
{
|
||||
//Unload the entire chunk column
|
||||
handler.GetWorld()[chunkX, chunkZ] = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Load chunk data from the server
|
||||
for (int chunkY = 0; chunkY < ChunkColumn.ColumnSize; chunkY++)
|
||||
{
|
||||
if ((chunkMask & (1 << chunkY)) != 0)
|
||||
{
|
||||
Chunk chunk = new Chunk();
|
||||
|
||||
//Read chunk data, all at once for performance reasons, and build the chunk object
|
||||
Queue<ushort> queue = new Queue<ushort>(dataTypes.ReadNextUShortsLittleEndian(Chunk.SizeX * Chunk.SizeY * Chunk.SizeZ, cache));
|
||||
for (int blockY = 0; blockY < Chunk.SizeY; blockY++)
|
||||
for (int blockZ = 0; blockZ < Chunk.SizeZ; blockZ++)
|
||||
for (int blockX = 0; blockX < Chunk.SizeX; blockX++)
|
||||
chunk[blockX, blockY, blockZ] = new Block(queue.Dequeue());
|
||||
|
||||
//We have our chunk, save the chunk into the world
|
||||
if (handler.GetWorld()[chunkX, chunkZ] == null)
|
||||
handler.GetWorld()[chunkX, chunkZ] = new ChunkColumn();
|
||||
handler.GetWorld()[chunkX, chunkZ][chunkY] = chunk;
|
||||
}
|
||||
}
|
||||
|
||||
//Skip light information
|
||||
for (int chunkY = 0; chunkY < ChunkColumn.ColumnSize; chunkY++)
|
||||
{
|
||||
if ((chunkMask & (1 << chunkY)) != 0)
|
||||
{
|
||||
//Skip block light
|
||||
dataTypes.ReadData((Chunk.SizeX * Chunk.SizeY * Chunk.SizeZ) / 2, cache);
|
||||
|
||||
//Skip sky light
|
||||
if (hasSkyLight)
|
||||
dataTypes.ReadData((Chunk.SizeX * Chunk.SizeY * Chunk.SizeZ) / 2, cache);
|
||||
}
|
||||
}
|
||||
|
||||
//Skip biome metadata
|
||||
if (chunksContinuous)
|
||||
dataTypes.ReadData(Chunk.SizeX * Chunk.SizeZ, cache);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 1.7 chunk format
|
||||
if (chunksContinuous && chunkMask == 0)
|
||||
{
|
||||
//Unload the entire chunk column
|
||||
handler.GetWorld()[chunkX, chunkZ] = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Count chunk sections
|
||||
int sectionCount = 0;
|
||||
int addDataSectionCount = 0;
|
||||
for (int chunkY = 0; chunkY < ChunkColumn.ColumnSize; chunkY++)
|
||||
{
|
||||
if ((chunkMask & (1 << chunkY)) != 0)
|
||||
sectionCount++;
|
||||
if ((chunkMask2 & (1 << chunkY)) != 0)
|
||||
addDataSectionCount++;
|
||||
}
|
||||
|
||||
//Read chunk data, unpacking 4-bit values into 8-bit values for block metadata
|
||||
Queue<byte> blockTypes = new Queue<byte>(dataTypes.ReadData(Chunk.SizeX * Chunk.SizeY * Chunk.SizeZ * sectionCount, cache));
|
||||
Queue<byte> blockMeta = new Queue<byte>();
|
||||
foreach (byte packed in dataTypes.ReadData((Chunk.SizeX * Chunk.SizeY * Chunk.SizeZ * sectionCount) / 2, cache))
|
||||
{
|
||||
byte hig = (byte)(packed >> 4);
|
||||
byte low = (byte)(packed & (byte)0x0F);
|
||||
blockMeta.Enqueue(hig);
|
||||
blockMeta.Enqueue(low);
|
||||
}
|
||||
|
||||
//Skip data we don't need
|
||||
dataTypes.ReadData((Chunk.SizeX * Chunk.SizeY * Chunk.SizeZ * sectionCount) / 2, cache); //Block light
|
||||
if (hasSkyLight)
|
||||
dataTypes.ReadData((Chunk.SizeX * Chunk.SizeY * Chunk.SizeZ * sectionCount) / 2, cache); //Sky light
|
||||
dataTypes.ReadData((Chunk.SizeX * Chunk.SizeY * Chunk.SizeZ * addDataSectionCount) / 2, cache); //BlockAdd
|
||||
if (chunksContinuous)
|
||||
dataTypes.ReadData(Chunk.SizeX * Chunk.SizeZ, cache); //Biomes
|
||||
|
||||
//Load chunk data
|
||||
for (int chunkY = 0; chunkY < ChunkColumn.ColumnSize; chunkY++)
|
||||
{
|
||||
if ((chunkMask & (1 << chunkY)) != 0)
|
||||
{
|
||||
Chunk chunk = new Chunk();
|
||||
|
||||
for (int blockY = 0; blockY < Chunk.SizeY; blockY++)
|
||||
for (int blockZ = 0; blockZ < Chunk.SizeZ; blockZ++)
|
||||
for (int blockX = 0; blockX < Chunk.SizeX; blockX++)
|
||||
chunk[blockX, blockY, blockZ] = new Block(blockTypes.Dequeue(), blockMeta.Dequeue());
|
||||
|
||||
if (handler.GetWorld()[chunkX, chunkZ] == null)
|
||||
handler.GetWorld()[chunkX, chunkZ] = new ChunkColumn();
|
||||
handler.GetWorld()[chunkX, chunkZ][chunkY] = chunk;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue