Esempio n. 1
0
        private static byte[] DrawText(MapInfo map, string text)
        {
            Bitmap bitmap = new Bitmap(map.Col, map.Row);
            RectangleF rectf = new RectangleF(0, 0, map.Col, map.Row);
            Graphics g = Graphics.FromImage(bitmap);
            g.SmoothingMode = SmoothingMode.AntiAlias;
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;
            g.PixelOffsetMode = PixelOffsetMode.HighQuality;
            g.DrawString(text, new Font("SketchFlow Print", 10), Brushes.AntiqueWhite, rectf);
            g.Flush();

            byte[] bytes = new byte[bitmap.Height*bitmap.Width*4];

            int i = 0;
            for (int y = 0; y < bitmap.Height; y++)
            {
                for (int x = 0; x < bitmap.Width; x++)
                {
                    Color color = bitmap.GetPixel(x, y);
                    bytes[i++] = color.R;
                    bytes[i++] = color.G;
                    bytes[i++] = color.B;
                    bytes[i++] = 0xff;
                }
            }
            return bytes;
        }
Esempio n. 2
0
        public MapEntity(Level level, long mapId = EntityManager.EntityIdUndefined)
            : base(-1, level)
        {
            if (mapId != EntityManager.EntityIdUndefined)
            {
                EntityId = mapId;
            }
            else
            {
                EntityId = level.EntityManager.AddEntity(null, this) + 0xFFFF;
            }

            ImageProvider = new MapImageProvider();

            MapInfo mapInfo = new MapInfo
            {
                MapId = EntityId,
                UpdateType = 6,
                Direction = 0,
                X = 0,
                Z = 0,
                Col = 128,
                Row = 128,
                XOffset = 0,
                ZOffset = 0
            };

            MapInfo = mapInfo;
        }
Esempio n. 3
0
        public virtual byte[] GetData(MapInfo mapInfo, bool forced)
        {
            if (ClientboundMapItemData != null || Batch != null) return null;

            byte[] data = null;

            if (MapData == null)
            {
                return null;
            }

            if (MapData.Length != (mapInfo.Col*mapInfo.Row*4))
            {
                return null;
            }

            if (!_alreadySent)
            {
                _alreadySent = true;
                data = MapData;
            }
            else if (forced)
            {
                data = MapData;
            }

            return data;
        }
Esempio n. 4
0
        public object Clone()
        {
            MapInfo clone = new MapInfo();
            clone.MapId = MapId;
            clone.UpdateType = UpdateType;
            clone.Direction = Direction;
            clone.X = X;
            clone.Z = Z;
            clone.Col = Col;
            clone.Row = Row;
            clone.XOffset = XOffset;
            clone.ZOffset = ZOffset;
            clone.Data = (byte[]) Data?.Clone();

            return clone;
        }
Esempio n. 5
0
        public virtual byte[] GetData(MapInfo mapInfo, bool forced)
        {
            byte[] data = null;

            if (_mapData == null)
            {
                _mapData = DrawText(mapInfo, Text);
                data = _mapData;
            }
            else if (_mapData.Length != mapInfo.Col*mapInfo.Row)
            {
                _mapData = DrawText(mapInfo, Text);
                data = _mapData;
            }

            return data;
        }
Esempio n. 6
0
        private byte[] GenerateColors(MapInfo map)
        {
            byte[] bytes = new byte[map.Col*map.Row*4];

            int i = 0;
            for (byte y = 0; y < map.Col; y++)
            {
                for (byte x = 0; x < map.Row; x++)
                {
                    bytes[i++] = 255; // R
                    bytes[i++] = 0; // G
                    bytes[i++] = 0; // B
                    bytes[i++] = 0xff; // A
                }
            }

            return bytes;
        }
        private byte[] GenerateColors(MapInfo map, byte next)
        {
            byte[] bytes = new byte[map.Col*map.Row*4];

            int i = 0;
            for (byte y = 0; y < map.Col; y++)
            {
                for (byte x = 0; x < map.Row; x++)
                {
                    bytes[i++] = (byte) _random.NextInt(255); // R
                    bytes[i++] = (byte) _random.NextInt(255); // G
                    bytes[i++] = (byte) _random.NextInt(255); // B
                    bytes[i++] = 0xff; // A
                }
            }

            return bytes;
        }
Esempio n. 8
0
        private McpeBatch CreateCachedPacket(long mapId, byte[] bitmapToBytes)
        {
            MapInfo mapInfo = new MapInfo
            {
                MapId = mapId,
                UpdateType = 6,
                Direction = 0,
                X = 0,
                Z = 0,
                Col = 128,
                Row = 128,
                XOffset = 0,
                ZOffset = 0,
                Data = bitmapToBytes,
            };

            McpeClientboundMapItemData packet = McpeClientboundMapItemData.CreateObject();
            packet.mapinfo = mapInfo;
            var batch = CreateMcpeBatch(packet.Encode());

            return batch;
        }
Esempio n. 9
0
 public virtual byte[] GetData(MapInfo mapInfo, bool forced)
 {
     return null;
     //return Frames.Count == 0 ? new byte[mapInfo.Col*mapInfo.Row*4] : null;
 }
Esempio n. 10
0
 public McpeClientboundMapItemData GetClientboundMapItemData(MapInfo mapInfo)
 {
     return null;
 }
Esempio n. 11
0
        public McpeBatch GetBatch(MapInfo mapInfo, bool forced)
        {
            if (Frames.Count == 0) return null;

            var currentFrame = FrameTicker.GetCurrentFrame(this);
            if (currentFrame >= Frames.Count) return null;

            return Frames[currentFrame];
        }
Esempio n. 12
0
 public virtual McpeBatch GetBatch(MapInfo mapInfo, bool forced)
 {
     return null;
 }
 public virtual byte[] GetData(MapInfo mapInfo, bool forced)
 {
     return GenerateColors(mapInfo, (byte) _random.NextInt(255));
 }