Exemplo n.º 1
0
Arquivo: Level.cs Projeto: Eros/MiNET
        public void BreakBlock(Player player, BlockCoordinates blockCoordinates)
        {
            List <ItemStack> drops = new List <ItemStack>();

            Block block = GetBlock(blockCoordinates);

            drops.Add(block.GetDrops());
            if (OnBlockBreak(new BlockBreakEventArgs(player, this, block, drops)))
            {
                block.BreakBlock(this);

                BlockEntity blockEnity = GetBlockEntity(blockCoordinates);
                if (blockEnity != null)
                {
                    RemoveBlockEntity(blockCoordinates);
                    drops.AddRange(blockEnity.GetDrops());
                }

                if (player.GameMode != GameMode.Creative)
                {
                    foreach (ItemStack drop in drops)
                    {
                        DropItem(blockCoordinates, drop);
                    }
                }
            }
            else
            {
                var message = McpeUpdateBlock.CreateObject();
                message.blocks = new BlockRecords {
                    block
                };
                player.SendPackage(message);
            }
        }
Exemplo n.º 2
0
Arquivo: Level.cs Projeto: oizma/MiNET
        public void BreakBlock(Player player, BlockCoordinates blockCoordinates)
        {
            List <Item> drops = new List <Item>();

            Block       block       = GetBlock(blockCoordinates);
            BlockEntity blockEntity = GetBlockEntity(blockCoordinates);

            drops.AddRange(block.GetDrops());
            if (!AllowBreak || !OnBlockBreak(new BlockBreakEventArgs(player, this, block, drops)))
            {
                // Revert

                var message = McpeUpdateBlock.CreateObject();
                message.blockId              = block.Id;
                message.coordinates          = block.Coordinates;
                message.blockMetaAndPriority = (byte)(0xb << 4 | (block.Metadata & 0xf));
                player.SendPackage(message);

                // Revert block entity if exists
                if (blockEntity != null)
                {
                    Nbt nbt = new Nbt
                    {
                        NbtFile = new NbtFile
                        {
                            BigEndian = false,
                            RootTag   = blockEntity.GetCompound()
                        }
                    };

                    var entityData = McpeBlockEntityData.CreateObject();
                    entityData.namedtag    = nbt;
                    entityData.coordinates = blockEntity.Coordinates;

                    player.SendPackage(entityData);
                }
            }
            else
            {
                block.BreakBlock(this);

                if (blockEntity != null)
                {
                    RemoveBlockEntity(blockCoordinates);
                    drops.AddRange(blockEntity.GetDrops());
                }

                if (player.GameMode != GameMode.Creative)
                {
                    foreach (Item drop in drops)
                    {
                        DropItem(blockCoordinates, drop);
                    }
                }

                player.HungerManager.IncreaseExhaustion(0.025f);
            }
        }
Exemplo n.º 3
0
        public void BreakBlock(Player player, BlockCoordinates blockCoordinates)
        {
            List <Item> drops = new List <Item>();

            Block block = GetBlock(blockCoordinates);

            drops.AddRange(block.GetDrops());
            if (OnBlockBreak(new BlockBreakEventArgs(player, this, block, drops)))
            {
                block.BreakBlock(this);

                BlockEntity blockEnity = GetBlockEntity(blockCoordinates);
                if (blockEnity != null)
                {
                    RemoveBlockEntity(blockCoordinates);
                    drops.AddRange(blockEnity.GetDrops());
                }

                if (player.GameMode != GameMode.Creative)
                {
                    foreach (Item drop in drops)
                    {
                        DropItem(blockCoordinates, drop);
                    }
                }

                player.HungerManager.IncreaseExhaustion(0.025f);
            }
            else
            {
                Block sendBlock = new Block(block.Id)
                {
                    Coordinates = block.Coordinates,
                    Metadata    = (byte)(0xb << 4 | (block.Metadata & 0xf))
                };

                var message = McpeUpdateBlock.CreateObject();
                message.blocks = new BlockRecords {
                    sendBlock
                };
                player.SendPackage(message);
            }
        }
Exemplo n.º 4
0
Arquivo: Level.cs Projeto: wgaox/MiNET
        public void BreakBlock(BlockCoordinates blockCoordinates)
        {
            List <ItemStack> drops = new List <ItemStack>();

            Block block = GetBlock(blockCoordinates);

            block.BreakBlock(this);
            drops.Add(block.GetDrops());

            BlockEntity blockEnity = GetBlockEntity(blockCoordinates);

            if (blockEnity != null)
            {
                RemoveBlockEntity(blockCoordinates);
                drops.AddRange(blockEnity.GetDrops());
            }

            foreach (ItemStack drop in drops)
            {
                DropItem(blockCoordinates, drop);
            }
        }
Exemplo n.º 5
0
        public bool BreakBlock(Block block, BlockFace face, OpenPlayer player = null, Item tool = null)
        {
            BlockEntity blockEntity = GetBlockEntity(block.Coordinates);

            bool canBreak = player == null || tool == null || tool.BreakBlock(this, player, block, blockEntity);

            if (!canBreak || !AllowBreak || player?.GameMode == GameMode.Spectator)
            {
                if (player != null)
                {
                    RevertBlockAction(player, block, blockEntity);
                }

                return(false);
            }

            //	block.BreakBlock(this, face);
            List <Item> drops = new List <Item>();

            if (player == null || player.GameMode != GameMode.Creative)
            {
                drops.AddRange(block.GetDrops(tool ?? new ItemAir()));
            }

            if (blockEntity != null)
            {
                //	RemoveBlockEntity(block.Coordinates);
                drops.AddRange(blockEntity.GetDrops());
            }

            BlockBreakEvent e = new BlockBreakEvent(player, block, drops);

            EventDispatcher.DispatchEvent(e);
            if (e.IsCancelled)
            {
                if (player != null)
                {
                    RevertBlockAction(player, block, blockEntity);
                }

                return(false);
            }

            block.BreakBlock(this, face);

            if (blockEntity != null)
            {
                RemoveBlockEntity(block.Coordinates);
            }

            if (player == null || player.GameMode != GameMode.Creative)
            {
                foreach (Item drop in e.Drops)
                {
                    DropItem(block.Coordinates, drop);
                }
            }

            e.OnComplete();

            return(true);
        }