public Pos Diff(Pos newPos) { var delta = new Pos { X = (ushort) (newPos.X - X), Y = (ushort) (newPos.Y - Y), Z = (ushort) (newPos.Z - Z), Yaw = (byte) (newPos.Yaw - Pitch), Pitch = (byte) (newPos.Yaw - Pitch) }; return delta; }
public void Load(string name) { string tempPath = LevelFolder + "/" + name + CompressedExtension; if (!File.Exists(tempPath)) throw new FileNotFoundException("Could not find file!", tempPath); var fileStream = new FileStream(tempPath, FileMode.Open); var gzipStream = new GZipStream(fileStream, CompressionMode.Decompress); var 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); Server.Log("Loading level " + Name + " which is " + SizeX + "x" + SizeY + "x" + SizeZ, LogTypesEnum.Debug); SpawnPos = new Pos { X = BitConverter.ToUInt16(header, 70), Y = BitConverter.ToUInt16(header, 72), Z = BitConverter.ToUInt16(header, 74), Pitch = header[76] }; SpawnPos.Pitch = header[77]; bool physics = BitConverter.ToBoolean(header, 78); bool realistic = BitConverter.ToBoolean(header, 79); BuildPermissions = header[80]; VisitPermissions = header[81]; Physics = new PhysicsHandler(this, physics) {Realistic = realistic}; int blockCount = SizeX*SizeY*SizeZ; BlockData = new byte[blockCount]; gzipStream.Read(BlockData, 0, blockCount); gzipStream.Close(); fileStream.Close(); LevelHandler.Levels.Add(this); }
//todo add type public 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 }; BlockData = new byte[SizeX*SizeY*SizeZ]; var 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) ? MCBlocks.Air : MCBlocks.Dirt)); } else { SetTile(x, y, z, (byte) MCBlocks.Grass); } } } } Physics = new PhysicsHandler(this, true); LevelHandler.Levels.Add(this); }
private void HandlePosAndOrientPacket(object incoming) { var data = (byte[]) incoming; 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(); }
/* private void SendFullPosPacketTeleport(Player player) { var p = new Packet {id = PacketType.PositionAndOrientationTeleport}; p.AddVar(player.UserId); p.AddVar(player.Position.x); p.AddVar(player.Position.y); p.AddVar(player.Position.z); p.AddVar(player.Position.yaw); p.AddVar(player.Position.pitch); SendPacket(p); } */ private void SendTeleportThisPlayer(Pos newPosition) { OldPosition = Position; Position = newPosition; newPosition.X = 64; newPosition.Y = 64; newPosition.Z = 64; var p = new Packet {Id = PacketType.PositionAndOrientationTeleport}; p.AddVar(255); p.AddVar(Position.X); p.AddVar(Position.Y); p.AddVar(Position.Z); p.AddVar(Position.Yaw); p.AddVar(Position.Pitch); SendPacket(p); }
public void Create(ushort inx, ushort iny, ushort inz, string type) { SizeX = inx; SizeY = iny; SizeZ = inz; SizeXZmultiplied = SizeX * SizeZ; SpawnPos = new Pos { X = (ushort)((SizeX * 32) / 2), Y = (ushort)(((SizeY * 32) / 2) + 64), Z = (ushort)((SizeZ * 32) / 2), Pitch = 0, Yaw = 0 }; BlockData = new byte[SizeX * SizeY * SizeZ]; switch (type) { //TODO: Add more level types. case "flatgrass": Generator = new FlatGrassGenerator(this); break; default: Generator = new FlatGrassGenerator(this); break; } Physics = new PhysicsHandler(this, true); LevelHandler.Levels.Add(this); }