Beispiel #1
0
        public override void UseItem(Level world, Player player, BlockCoordinates blockCoordinates)
        {
            MapEntity mapEntity = new MapEntity(world);
            mapEntity.SpawnEntity();

            // Initialize a new map and add it.
            ItemMap itemMap = new ItemMap(mapEntity.EntityId);
            player.Inventory.SetFirstEmptySlot(itemMap, true, false);
        }
Beispiel #2
0
        public void Video2X(Player player, int numberOfFrames, bool color)
        {
            Task.Run(delegate
            {
                try
                {
                    Dictionary<Tuple<int, int>, List<MapEntity>> entities = new Dictionary<Tuple<int, int>, List<MapEntity>>();

                    int width = 3;
                    int height = 2;
                    int frameCount = numberOfFrames;
                    //int frameOffset = 0;
                    int frameOffset = 120;

                    var frameTicker = new FrameTicker(frameCount);

                    // 768x384
                    for (int frame = frameOffset; frame < frameCount + frameOffset; frame++)
                    {
                        Log.Info($"Generating frame {frame}");

                        string file = Path.Combine(@"D:\Development\Other\Smash Heroes 3x6 (128)\Smash Heroes 3x6 (128)", $"Smash Heroes Trailer{frame:D4}.bmp");
                        //string file = Path.Combine(@"D:\Development\Other\2 by 1 PE test app ad for Gurun-2\exported frames 2", $"pe app ad{frame:D2}.bmp");
                        if (!File.Exists(file)) continue;

                        Bitmap image = new Bitmap((Bitmap) Image.FromFile(file), width*128, height*128);

                        for (int x = 0; x < width; x++)
                        {
                            for (int y = 0; y < height; y++)
                            {
                                var key = new Tuple<int, int>(x, y);
                                if (!entities.ContainsKey(key))
                                {
                                    entities.Add(key, new List<MapEntity>());
                                }

                                List<MapEntity> frames = entities[key];

                                var croppedImage = CropImage(image, new Rectangle(new Point(x*128, y*128), new Size(128, 128)));
                                byte[] bitmapToBytes = BitmapToBytes(croppedImage, color);

                                if (bitmapToBytes.Length != 128*128*4) return;

                                MapEntity entity = new MapEntity(player.Level);
                                entity.ImageProvider = new MapImageProvider {Batch = CreateCachedPacket(entity.EntityId, bitmapToBytes)};
                                entity.SpawnEntity();
                                frames.Add(entity);
                            }
                        }
                    }

                    int i = 0;

                    player.Inventory.Slots[i++] = new ItemBlock(new Planks(), 0) {Count = 64};

                    foreach (var entites in entities.Values)
                    {
                        player.Inventory.Slots[i++] = new CustomItemItemFrame(entites, frameTicker) {Count = 64};
                    }

                    player.SendPlayerInventory();
                    player.SendMessage("Done generating video.", MessageType.Raw);

                    BlockCoordinates center = player.KnownPosition.GetCoordinates3D();
                    var level = player.Level;

                    for (int x = 0; x < width; x++)
                    {
                        for (int y = 0; y < height; y++)
                        {
                            var key = new Tuple<int, int>(x, y);
                            List<MapEntity> frames = entities[key];

                            BlockCoordinates bc = new BlockCoordinates(center.X - x, center.Y + height - y - 1, center.Z + 2);
                            var wood = new Planks {Coordinates = bc};
                            level.SetBlock(wood);

                            BlockCoordinates frambc = new BlockCoordinates(center.X - x, center.Y + height - y - 1, center.Z + 1);
                            ItemFrameBlockEntity itemFrameBlockEntity = new ItemFrameBlockEntity
                            {
                                Coordinates = frambc
                            };

                            var itemFrame = new CustomItemFrame(frames, itemFrameBlockEntity, level, frameTicker) {Coordinates = frambc, Metadata = 3};
                            level.SetBlock(itemFrame);
                            level.SetBlockEntity(itemFrameBlockEntity);
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Error("Aborted video generation", e);
                }
            });

            player.SendMessage("Generating video...", MessageType.Raw);
        }