public pos diff(pos newPos) { pos delta = new pos(); delta.x = (ushort)(newPos.x - x); delta.y = (ushort)(newPos.y - y); delta.z = (ushort)(newPos.z - z); delta.yaw = (byte)(newPos.yaw - pitch); delta.pitch = (byte)(newPos.yaw - pitch); return delta; }
void Load(string _name) { string tempPath = levelFolder + "/" + _name + compressedExtension; if (!File.Exists(tempPath)) throw new FileNotFoundException("Could not find file!", tempPath); FileStream fileStream = new FileStream(tempPath, FileMode.Open); GZipStream gzipStream = new GZipStream(fileStream, CompressionMode.Decompress); byte[] header = new byte[headerSize]; gzipStream.Read(header, 0, headerSize); name = encode.GetString(header, 0, 64).Trim(); sizeX = BitConverter.ToUInt16(header, 64); sizeY = BitConverter.ToUInt16(header, 66); sizeZ = BitConverter.ToUInt16(header, 68); spawnPos = new pos(); spawnPos.x = BitConverter.ToUInt16(header, 70); spawnPos.y = BitConverter.ToUInt16(header, 72); spawnPos.z = BitConverter.ToUInt16(header, 74); spawnPos.pitch = header[76]; spawnPos.pitch = header[77]; bool physics = BitConverter.ToBoolean(header, 78); bool realistic = BitConverter.ToBoolean(header, 78); this.physics = new PhysicsHandler(this, physics); this.physics.realistic = realistic; int blockCount = sizeX * sizeY * sizeZ; blocks = new byte[blockCount]; gzipStream.Read(blocks, 0, blockCount); gzipStream.Close(); fileStream.Close(); LevelHandler.levels.Add(this); }
//todo add type void Create(ushort inx, ushort iny, ushort inz) { sizeX = inx; sizeY = iny; sizeZ = inz; spawnPos = new pos { x = (ushort)((sizeX * 32) / 2), y = (ushort)(((sizeY * 32) / 2) + 64), z = (ushort)((sizeZ * 32) / 2), pitch = 0, yaw = 0 }; blocks = new byte[sizeX * sizeY * sizeZ]; ushort half = (ushort)(sizeY / 2); for (ushort x = 0; x < sizeX; ++x) { for (ushort z = 0; z < sizeZ; ++z) { for (ushort y = 0; y < sizeY; ++y) { if (y != half) { SetTile(x, y, z, (byte)((y >= half) ? Blocks.Air : Blocks.Dirt)); } else { SetTile(x, y, z, (byte)Blocks.Grass); } } } } physics = new PhysicsHandler(this, true); LevelHandler.levels.Add(this); }
void SendTeleportThisPlayer(pos newPosition) { oldPosition = position; position = newPosition; Packet p = new Packet(); p.id = PacketType.PositionAndOrientationTeleport; p.AddVar((byte)255); p.AddVar(position.x); p.AddVar(position.y); p.AddVar(position.z); p.AddVar(position.yaw); p.AddVar(position.pitch); SendPacket(p); }
void HandlePosAndOrientPacket(object incoming) { byte[] data = (byte[])incoming; byte _id = data[0]; ushort x = NTHO(data, 1); ushort y = NTHO(data, 3); ushort z = NTHO(data, 5); byte yaw = data[7]; byte pitch = data[8]; oldPosition = position; position.x = x; position.y = y; position.z = z; position.yaw = yaw; position.pitch = pitch; delta = oldPosition.diff(position); UpdatePlayerPos(); }