public override void PlaceBlock(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords) { Log.Warn("Using custom item frame"); var coor = GetNewCoordinatesFromFace(blockCoordinates, face); ItemFrameBlockEntity itemFrameBlockEntity = new ItemFrameBlockEntity { Coordinates = coor }; CustomFrame frame = new CustomFrame(_frames, itemFrameBlockEntity, world, _frameTicker) { Coordinates = coor, }; if (!frame.CanPlace(world, player, blockCoordinates, face)) { return; } frame.PlaceBlock(world, player, coor, face, faceCoords); // Then we create and set the sign block entity that has all the intersting data world.SetBlockEntity(itemFrameBlockEntity); }
//[Authorize(Permission = UserPermission.Op)] 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 = 6; int height = 3; 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 CustomItemFrame(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 CustomFrame(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); }