diff --git a/ClassicalSharp/Blocks/Block.cs b/ClassicalSharp/Blocks/Block.cs index a67ec53ff..2607264b0 100644 --- a/ClassicalSharp/Blocks/Block.cs +++ b/ClassicalSharp/Blocks/Block.cs @@ -101,7 +101,7 @@ namespace ClassicalSharp { public const int CpeCount = MaxCpeBlock + 1; #if USE16_BIT - public const BlockID MaxDefinedBlock = 0xFFF; + public const BlockID MaxDefinedBlock = 0x3FF; #else public const BlockID MaxDefinedBlock = 0xFF; #endif diff --git a/ClassicalSharp/Blocks/BlockInfo.Culling.cs b/ClassicalSharp/Blocks/BlockInfo.Culling.cs index 276159715..7c49d397c 100644 --- a/ClassicalSharp/Blocks/BlockInfo.Culling.cs +++ b/ClassicalSharp/Blocks/BlockInfo.Culling.cs @@ -100,7 +100,7 @@ namespace ClassicalSharp { /// should be drawn with the neighbour 'other' present on the other side of the face. public static bool IsFaceHidden(BlockID block, BlockID other, int tileSide) { #if USE16_BIT - return (hidden[(block << 12) | other] & (1 << tileSide)) != 0; + return (hidden[(block << 10) | other] & (1 << tileSide)) != 0; #else return (hidden[(block << 8) | other] & (1 << tileSide)) != 0; #endif diff --git a/ClassicalSharp/Game/Inventory.cs b/ClassicalSharp/Game/Inventory.cs index d61d1a7e2..ea231371b 100644 --- a/ClassicalSharp/Game/Inventory.cs +++ b/ClassicalSharp/Game/Inventory.cs @@ -107,7 +107,7 @@ namespace ClassicalSharp { BlockID DefaultMapping(int i) { #if USE16_BIT - if ((i >= Block.CpeCount && i < 256) || i == Block.Air) return Block.Air; + if ((i >= Block.CpeCount) || i == Block.Air) return Block.Air; #else if (i >= Block.CpeCount || i == Block.Air) return Block.Air; #endif diff --git a/ClassicalSharp/Math/Physics/Searcher.cs b/ClassicalSharp/Math/Physics/Searcher.cs index ccf0264ce..b13184a28 100644 --- a/ClassicalSharp/Math/Physics/Searcher.cs +++ b/ClassicalSharp/Math/Physics/Searcher.cs @@ -18,9 +18,13 @@ namespace ClassicalSharp.Physics { public State(int x, int y, int z, BlockID block, float tSquared) { X = x << 3; Y = y << 3; Z = z << 3; - X |= (block & 0x07); - Y |= (block & 0x38) >> 3; - Z |= (block & 0xC0) >> 6; + X |= (block & 0x007); + Y |= (block & 0x038) >> 3; + #if !USE16_BIT + Z |= (block & 0x0C0) >> 6; + #else + Z |= (block & 0x1C0) >> 6; + #endif this.tSquared = tSquared; } } diff --git a/ClassicalSharp/MeshBuilder/Builder.cs b/ClassicalSharp/MeshBuilder/Builder.cs index a7d0f348f..e89e91484 100644 --- a/ClassicalSharp/MeshBuilder/Builder.cs +++ b/ClassicalSharp/MeshBuilder/Builder.cs @@ -203,7 +203,7 @@ namespace ClassicalSharp { X = x; Y = y; Z = z; fullBright = BlockInfo.FullBright[b]; #if USE16_BIT - int tileIdx = b << 12; + int tileIdx = b << 10; #else int tileIdx = b << 8; #endif diff --git a/ClassicalSharp/Network/Protocols/Classic.cs b/ClassicalSharp/Network/Protocols/Classic.cs index 3c5a4aecd..879e21a00 100644 --- a/ClassicalSharp/Network/Protocols/Classic.cs +++ b/ClassicalSharp/Network/Protocols/Classic.cs @@ -120,6 +120,9 @@ namespace ClassicalSharp.Network.Protocols { if (mapSizeIndex == 4) { if (map == null) { int size = mapSize[0] << 24 | mapSize[1] << 16 | mapSize[2] << 8 | mapSize[3]; + #if USE16_BIT + if (reader.ExtendedBlocks) size *= 2; + #endif map = new byte[size]; } mapIndex += gzipStream.Read(map, mapIndex, map.Length - mapIndex); @@ -131,6 +134,14 @@ namespace ClassicalSharp.Network.Protocols { game.WorldEvents.RaiseMapLoading(progress); } + #if USE16_BIT + static ushort[] UInt8sToUInt16s(byte[] src) { + ushort[] dst = new ushort[src.Length / 2]; + Buffer.BlockCopy(src, 0, dst, 0, src.Length); + return dst; + } + #endif + void HandleLevelFinalise() { game.Gui.SetNewScreen(null); game.Gui.activeScreen = prevScreen; @@ -147,7 +158,11 @@ namespace ClassicalSharp.Network.Protocols { Utils.LogDebug("map loading took: " + loadingMs); #if USE16_BIT - game.World.SetNewMap(Utils.UInt8sToUInt16s(map), mapWidth, mapHeight, mapLength); + if (reader.ExtendedBlocks) { + game.World.SetNewMap(UInt8sToUInt16s(map), mapWidth, mapHeight, mapLength); + } else{ + game.World.SetNewMap(Utils.UInt8sToUInt16s(map), mapWidth, mapHeight, mapLength); + } #else game.World.SetNewMap(map, mapWidth, mapHeight, mapLength); #endif @@ -174,8 +189,8 @@ namespace ClassicalSharp.Network.Protocols { byte id = reader.ReadUInt8(); string name = reader.ReadString(); string skin = name; - net.CheckName(id, ref name, ref skin); - net.AddEntity(id, name, skin, true); + net.CheckName(id, ref name, ref skin); + net.AddEntity(id, name, skin, true); if (!net.addEntityHack) return; // Workaround for some servers that declare they support ExtPlayerList, @@ -253,7 +268,7 @@ namespace ClassicalSharp.Network.Protocols { } internal void ReadAbsoluteLocation(byte id, bool interpolate) { - Vector3 P = reader.ReadPosition(id); + Vector3 P = reader.ReadPosition(id); float rotY = (float)Utils.PackedToDegrees(reader.ReadUInt8()); float headX = (float)Utils.PackedToDegrees(reader.ReadUInt8()); @@ -267,7 +282,7 @@ namespace ClassicalSharp.Network.Protocols { internal void WriteChat(string text, bool partial) { int payload = !net.SupportsPartialMessages ? EntityList.SelfID : (partial ? 1 : 0); - writer.WriteUInt8((byte)Opcode.Message); + writer.WriteUInt8((byte)Opcode.Message); writer.WriteUInt8((byte)payload); writer.WriteString(text); }