示例#1
0
        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);
        }
示例#2
0
        public override void UseItem(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords)
        {
            var coor = GetNewCoordinatesFromFace(blockCoordinates, face);

            ItemFrame itemFrame = new ItemFrame
            {
                Coordinates = coor,
            };

            if (!itemFrame.CanPlace(world, face))
            {
                return;
            }

            itemFrame.PlaceBlock(world, player, coor, face, faceCoords);

            // Then we create and set the sign block entity that has all the intersting data

            ItemFrameBlockEntity itemFrameBlockEntity = new ItemFrameBlockEntity
            {
                Coordinates = coor
            };

            world.SetBlockEntity(itemFrameBlockEntity);
        }
示例#3
0
        private void Tick(object state)
        {
            if (!Monitor.TryEnter(_tickSync))
            {
                return;
            }

            try
            {
                if (_frames.Count == 0)
                {
                    return;
                }

                var currentFrame = _frameTicker.GetCurrentFrame(this);
                if (currentFrame >= _frames.Count)
                {
                    return;
                }

                ItemMap map = new ItemMap(_frames[currentFrame].EntityId);

                ItemFrameBlockEntity blockEntity = _itemFrameBlockEntity;
                if (blockEntity != null)
                {
                    blockEntity.SetItem(map, 0);
                    _level.SetBlockEntity(blockEntity);
                }
            }
            finally
            {
                Monitor.Exit(_tickSync);
            }
        }
示例#4
0
        public override bool PlaceBlock(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords)
        {
            switch (face)
            {
            case BlockFace.Down:
            case BlockFace.Up:
                return(true);                        // Do nothing

            case BlockFace.East:                     // ok
                Metadata = 0;
                break;

            case BlockFace.West:
                Metadata = 1;
                break;

            case BlockFace.South:
                Metadata = 2;
                break;

            case BlockFace.North:                     // ok
                Metadata = 3;
                break;
            }

            ItemFrameBlockEntity itemFrameBlockEntity = new ItemFrameBlockEntity
            {
                Coordinates = Coordinates
            };

            world.SetBlockEntity(itemFrameBlockEntity);

            return(false);
        }
示例#5
0
        public static BlockEntity GetBlockEntityById(string blockEntityId)
        {
            BlockEntity blockEntity = null;

            if (blockEntityId == "Sign")
            {
                blockEntity = new Sign();
            }
            else if (blockEntityId == "Chest")
            {
                blockEntity = new ChestBlockEntity();
            }
            else if (blockEntityId == "EnchantTable")
            {
                blockEntity = new EnchantingTableBlockEntity();
            }
            else if (blockEntityId == "Furnace")
            {
                blockEntity = new FurnaceBlockEntity();
            }
            else if (blockEntityId == "Skull")
            {
                blockEntity = new SkullBlockEntity();
            }
            else if (blockEntityId == "ItemFrame")
            {
                blockEntity = new ItemFrameBlockEntity();
            }

            return(blockEntity);
        }
示例#6
0
        public override void PlaceBlock(Level world, MiNET.Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords)
        {
            var coor = GetNewCoordinatesFromFace(blockCoordinates, face);

            ItemFrameBlockEntity itemFrameBlockEntity = new ItemFrameBlockEntity
            {
                Coordinates = coor
            };

            FullyLuminousItemFrame itemFrame = new FullyLuminousItemFrame(_frame, itemFrameBlockEntity, world)
            {
                Coordinates = coor,
            };

            if (!itemFrame.CanPlace(world, blockCoordinates, face))
            {
                return;
            }

            itemFrame.PlaceBlock(world, player, coor, face, faceCoords);

            // Then we create and set the block entity that has all the intersting data

            world.SetBlockEntity(itemFrameBlockEntity);
        }
示例#7
0
 public CustomFrame(List <MapEntity> frames, ItemFrameBlockEntity itemFrameBlockEntity, Level level, FrameTicker frameTicker) : base()
 {
     Log.Error("Created new Custom Item Frame");
     _frames = frames;
     _itemFrameBlockEntity = itemFrameBlockEntity;
     _level       = level;
     _frameTicker = frameTicker;
     _timer       = new Timer(Tick, null, 33, 33);
     _frameTicker.Register(this);
 }
示例#8
0
        public override bool PlaceBlock(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords)
        {
            FacingDirection = (int)face;

            var itemFrameBlockEntity = new ItemFrameBlockEntity {
                Coordinates = Coordinates
            };

            world.SetBlockEntity(itemFrameBlockEntity);

            return(false);
        }
示例#9
0
        public FullyLuminousItemFrame(MapEntity frame, ItemFrameBlockEntity itemFrameBlockEntity, Level level) : this()
        {
            ItemMap map = new ItemMap(frame.EntityId);

            ItemFrameBlockEntity blockEntity = itemFrameBlockEntity;

            if (blockEntity != null)
            {
                blockEntity.SetItem(map);
                level.SetBlockEntity(blockEntity);
            }
        }
示例#10
0
        public static BlockEntity GetBlockEntityById(string blockEntityId)
        {
            BlockEntity blockEntity = null;

            if (blockEntityId == "Sign") blockEntity = new Sign();
            else if (blockEntityId == "Chest") blockEntity = new ChestBlockEntity();
            else if (blockEntityId == "EnchantTable") blockEntity = new EnchantingTableBlockEntity();
            else if (blockEntityId == "Furnace") blockEntity = new FurnaceBlockEntity();
            else if (blockEntityId == "Skull") blockEntity = new SkullBlockEntity();
            else if (blockEntityId == "ItemFrame") blockEntity = new ItemFrameBlockEntity();

            return blockEntity;
        }
示例#11
0
        public static BlockEntity GetBlockEntityById(string blockEntityId)
        {
            BlockEntity blockEntity = null;

            if (blockEntityId == "Sign")
            {
                blockEntity = new Sign();
            }
            else if (blockEntityId == "Chest")
            {
                blockEntity = new ChestBlockEntity();
            }
            else if (blockEntityId == "EnchantTable")
            {
                blockEntity = new EnchantingTableBlockEntity();
            }
            else if (blockEntityId == "Furnace")
            {
                blockEntity = new FurnaceBlockEntity();
            }
            else if (blockEntityId == "Skull")
            {
                blockEntity = new SkullBlockEntity();
            }
            else if (blockEntityId == "ItemFrame")
            {
                blockEntity = new ItemFrameBlockEntity();
            }
            else if (blockEntityId == "Bed")
            {
                blockEntity = new BedBlockEntity();
            }
            else if (blockEntityId == "Banner")
            {
                blockEntity = new BannerBlockEntity();
            }
            else if (blockEntityId == "FlowerPot")
            {
                blockEntity = new FlowerPotBlockEntity();
            }
            else if (blockEntityId == "Beacon")
            {
                blockEntity = new BeaconBlockEntity();
            }
            else if (blockEntityId == "MobSpawner")
            {
                blockEntity = new MobSpawnerBlockEntity();
            }

            return(blockEntity);
        }
示例#12
0
        public override bool Interact(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoord)
        {
            Item itemInHande = player.Inventory.GetItemInHand();

            ItemFrameBlockEntity blockEntity = world.GetBlockEntity(blockCoordinates) as ItemFrameBlockEntity;

            if (blockEntity != null)
            {
                blockEntity.SetItem(itemInHande);
                world.SetBlockEntity(blockEntity);
            }

            return(true);
        }
示例#13
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);
        }
示例#14
0
        public void Video2X(Player player, int numberOfFrames, bool color)
        {
            Task.Run(delegate
            {
                try
                {
                    var entities = new ConcurrentDictionary <Tuple <int, int>, MapEntity[]>();

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

                    var frameTicker = new FrameTicker(frameCount);

                    // 768x384
                    Parallel.For(frameOffset, frameOffset + frameCount, (frame) =>
                    {
                        Log.Info($"Generating frame {frame}");

                        string file = Path.Combine(@"C:\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))
                        {
                            Log.Warn($"Couldn't find file: {file}");
                            return;
                        }

                        var 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);
                                var frames = entities.GetOrAdd(key, new MapEntity[frameCount]);

                                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;
                                }

                                var entity       = new MapEntity(player.Level);
                                var cachedPacket = CreateCachedPacket(entity.EntityId, bitmapToBytes);

                                player.SendPacket(cachedPacket);
                                entity.ImageProvider = new MapImageProvider {
                                    Batch = cachedPacket
                                };
                                entity.SpawnEntity();

                                frames[frame - frameOffset] = entity;
                            }
                        }
                    });

                    //int i = 0;
                    //player.Inventory.Slots[i++] = new ItemBlock(new Planks(), 0) {Count = 64, UniqueId = Environment.TickCount};
                    //foreach (var entites in entities.Values)
                    //{
                    //	player.Inventory.Slots[i++] = new CustomItemFrame(entites.Keys.ToList(), frameTicker) {Count = 64, UniqueId = Environment.TickCount};
                    //}
                    //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);
                            var frames = new List <MapEntity>(entities[key]);
                            frames     = frames.Where(f => f != null).ToList();

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

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

                            var itemFrame = new CustomFrame(frames, itemFrameBlockEntity, level, frameTicker)
                            {
                                Coordinates     = frambc,
                                FacingDirection = (int)BlockFace.North
                            };
                            level.SetBlock(itemFrame);
                            level.SetBlockEntity(itemFrameBlockEntity);
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Error("Aborted video generation", e);
                }
            });

            player.SendMessage("Generating video...", MessageType.Raw);
        }
示例#15
0
        /**
         * Credit to @gurun, as what is below is based on his work.
         */
        public static List <Entity> SpawnMapImage(string imageLocation, int width, int height, Level level, BlockCoordinates spawnLocation, MapDirection mapDirection = MapDirection.South)
        {
            var spawnedEntities = new List <Entity>();

            try
            {
                Bitmap    image;
                CachedMap cachedMap;

                if (CachedMaps.ContainsKey(imageLocation))
                {
                    cachedMap = CachedMaps[imageLocation];
                    image     = cachedMap.CachedImage;

                    //Dodgily ensure the building flag is disabled
                    cachedMap.IsBuilding = false;
                    //SkyUtil.log($"Using Cached Image for {imageLocation}");
                }
                else
                {
                    if (!File.Exists(imageLocation))
                    {
                        SkyUtil.log($"File doesn't exist for Map ({imageLocation})");
                        return(spawnedEntities);
                    }

                    image     = new Bitmap((Bitmap)Image.FromFile(imageLocation), width * 128, height * 128);
                    cachedMap = new CachedMap(image);

                    //SkyUtil.log($"Loading Image for {imageLocation}");
                }

                BlockCoordinates center = spawnLocation;

                for (int x = 0; x < width; x++)
                {
                    int xSpawnLoc = center.X + x;
                    for (int y = 0; y < height; y++)
                    {
                        byte[] bitmapToBytes;
                        if (cachedMap.IsBuilding)
                        {
                            var croppedImage = CropImage(image, new Rectangle(new Point(x * 128, y * 128), new Size(128, 128)));
                            bitmapToBytes = BitmapToBytes(croppedImage, true);

                            if (bitmapToBytes.Length != 128 * 128 * 4)
                            {
                                return(spawnedEntities);                                //TODO: Throw Exception/Alert Log?
                            }

                            cachedMap.CachedBitmaps.Add(new Tuple <int, int>(x, y), bitmapToBytes);
                        }
                        else
                        {
                            bitmapToBytes = cachedMap.CachedBitmaps[new Tuple <int, int>(x, y)];
                        }

                        MapEntity frame = new MapEntity(level);
                        frame.ImageProvider = new MapImageProvider {
                            Batch = CreateCachedPacket(frame.EntityId, bitmapToBytes)
                        };
                        frame.SpawnEntity();

                        AddMapIdToDictionary(level is GameLevel gameLevel ? gameLevel.GameId : level.LevelId, frame.EntityId);

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

                        var itemFrame = new FullyLuminousItemFrame(frame, itemFrameBlockEntity, level)
                        {
                            Coordinates = frambc,
                            Metadata    = (byte)mapDirection,
                        };
                        level.SetBlock(itemFrame, true, false);
                        level.SetBlockEntity(itemFrameBlockEntity);

                        spawnedEntities.Add(frame);
                    }
                }

                if (cachedMap.IsBuilding)
                {
                    CachedMaps.TryAdd(imageLocation, cachedMap);
                    cachedMap.IsBuilding = false;                     //Completely Cached
                }
            }
            catch (Exception e)
            {
                SkyUtil.log("Aborted image generation");
                BugSnagUtil.ReportBug(e);
            }

            return(spawnedEntities);
        }
示例#16
0
        public static BlockEntity GetBlockEntityById(string blockEntityId)
        {
            BlockEntity blockEntity = CustomBlockEntityFactory?.GetBlockEntityById(blockEntityId);

            if (blockEntity != null)
            {
                return(blockEntity);
            }

            if (blockEntityId == "Sign")
            {
                blockEntity = new SignBlockEntity();
            }
            else if (blockEntityId == "Chest")
            {
                blockEntity = new ChestBlockEntity();
            }
            else if (blockEntityId == "EnchantTable")
            {
                blockEntity = new EnchantingTableBlockEntity();
            }
            else if (blockEntityId == "Furnace")
            {
                blockEntity = new FurnaceBlockEntity();
            }
            else if (blockEntityId == "BlastFurnace")
            {
                blockEntity = new BlastFurnaceBlockEntity();
            }
            else if (blockEntityId == "Skull")
            {
                blockEntity = new SkullBlockEntity();
            }
            else if (blockEntityId == "ItemFrame")
            {
                blockEntity = new ItemFrameBlockEntity();
            }
            else if (blockEntityId == "Bed")
            {
                blockEntity = new BedBlockEntity();
            }
            else if (blockEntityId == "Banner")
            {
                blockEntity = new BannerBlockEntity();
            }
            else if (blockEntityId == "FlowerPot")
            {
                blockEntity = new FlowerPotBlockEntity();
            }
            else if (blockEntityId == "Beacon")
            {
                blockEntity = new BeaconBlockEntity();
            }
            else if (blockEntityId == "MobSpawner")
            {
                blockEntity = new MobSpawnerBlockEntity();
            }
            else if (blockEntityId == "ChalkboardBlock")
            {
                blockEntity = new ChalkboardBlockEntity();
            }
            else if (blockEntityId == "ShulkerBox")
            {
                blockEntity = new ShulkerBoxBlockEntity();
            }
            else if (blockEntityId == "StructureBlock")
            {
                blockEntity = new StructureBlockBlockEntity();
            }

            return(blockEntity);
        }