Esempio n. 1
0
        public void SetBlockEntity(BlockEntity blockEntity, bool broadcast = true)
        {
            ChunkColumn chunk = _worldProvider.GenerateChunkColumn(new ChunkCoordinates(blockEntity.Coordinates.X >> 4, blockEntity.Coordinates.Z >> 4));

            chunk.SetBlockEntity(blockEntity.Coordinates, blockEntity.GetCompound());

            if (blockEntity.UpdatesOnTick)
            {
                BlockEntities.Add(blockEntity);
            }

            if (!broadcast)
            {
                return;
            }

            Nbt nbt = new Nbt
            {
                NbtFile = new NbtFile
                {
                    BigEndian = false,
                    UseVarInt = true,
                    RootTag   = blockEntity.GetCompound()
                }
            };

            var entityData = McpeBlockEntityData.CreateObject();

            entityData.namedtag    = nbt;
            entityData.coordinates = blockEntity.Coordinates;

            RelayBroadcast(entityData);
        }
Esempio n. 2
0
        /// <inheritdoc />
        public override void HandleMcpeBlockEntityData(McpeBlockEntityData message)
        {
            var playerPosition = KnownPosition.ToBlockCoordinates();

            if (playerPosition.DistanceTo(message.coordinates) > 1000)
            {
                return;
            }

            var nbt = message.namedtag.NbtFile.RootTag;

            if (nbt is NbtCompound compound)
            {
                var blockEntity = Level.GetBlockEntity(message.coordinates);
                EventDispatcher.DispatchEventAsync(new PlayerSetBlockEntityDataEvent(this, blockEntity, compound)).Then(
                    (result) =>
                {
                    if (result.IsCancelled)
                    {
                        return;
                    }

                    blockEntity.SetCompound(compound);
                    Level.SetBlockEntity(blockEntity);
                });
            }

            //base.HandleMcpeBlockEntityData(message);
        }
Esempio n. 3
0
        private static void RevertBlockAction(OpenPlayer player, Block block, BlockEntity blockEntity)
        {
            var message = McpeUpdateBlock.CreateObject();

            message.blockRuntimeId = (uint)block.GetRuntimeId();
            message.coordinates    = block.Coordinates;
            message.blockPriority  = 0xb;
            player.SendPacket(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.SendPacket(entityData);
            }
        }
Esempio n. 4
0
 public override void HandleMcpeBlockEntityData(McpeBlockEntityData message)
 {
     Log.DebugFormat("X: {0}", message.coordinates.X);
     Log.DebugFormat("Y: {0}", message.coordinates.Y);
     Log.DebugFormat("Z: {0}", message.coordinates.Z);
     Log.DebugFormat("NBT:\n{0}", message.namedtag.NbtFile.RootTag);
 }
Esempio n. 5
0
File: Level.cs Progetto: 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);
            }
        }
        public override void HandleMcpeBlockEntityData(McpeBlockEntityData message)
        {
            BlockCoordinates coordinates = message.coordinates;
            Nbt         nbt   = message.namedtag;
            ChunkColumn chunk = _worldProvider.GenerateChunkColumn((ChunkCoordinates)coordinates, true);

            if (chunk == null)
            {
                //Log.Warn($"Got block entity for non existing chunk at {coordinates}\n{nbt.NbtFile.RootTag}");
                _futureBlockEntities.TryAdd(coordinates, (NbtCompound)nbt.NbtFile.RootTag);
            }
            else
            {
                //Log.Warn($"Got block entity for existing chunk at {coordinates}\n{nbt.NbtFile.RootTag}");
                chunk.SetBlockEntity(coordinates, (NbtCompound)nbt.NbtFile.RootTag);
            }
        }
Esempio n. 7
0
        public void BlockEntityTest()
        {
            NbtFile file = new NbtFile();

            file.BigEndian = false;
            var compound = file.RootTag = new NbtCompound(string.Empty);

            compound.Add(new NbtString("Text1", "first line"));
            compound.Add(new NbtString("Text2", "second line"));
            compound.Add(new NbtString("Text3", "third line"));
            compound.Add(new NbtString("Text4", "forth line"));
            compound.Add(new NbtString("id", "Sign"));
            compound.Add(new NbtInt("x", 6));
            compound.Add(new NbtInt("y", 6));
            compound.Add(new NbtInt("z", 6));

            Console.WriteLine(file.ToString());

            Nbt nbt = new Nbt();

            nbt.NbtFile = file;
            McpeBlockEntityData message = McpeBlockEntityData.CreateObject();

            message.x        = 6;
            message.y        = 6;
            message.z        = 6;
            message.namedtag = nbt;

            Assert.NotNull(message.Encode());
            Console.WriteLine(ByteArrayToString(message.Encode()));

            var b = new byte[]
            {
                0xb8, 0x00, 0x00, 0x00, 0x06, 0x06, 0x00, 0x00, 0x00, 0x06, 0x0a, 0x00, 0x00, 0x08, 0x02,
                0x00, 0x49, 0x64, 0x04, 0x00, 0x53, 0x69, 0x67, 0x6e, 0x03, 0x01, 0x00, 0x78, 0x06, 0x00,
                0x00, 0x00, 0x03, 0x01, 0x00, 0x79, 0x06, 0x00, 0x00, 0x00, 0x03, 0x01, 0x00, 0x7a, 0x06,
                0x00, 0x00, 0x00, 0x08, 0x05, 0x00, 0x54, 0x65, 0x78, 0x74, 0x31, 0x0a, 0x00, 0x66, 0x69,
                0x72, 0x73, 0x74, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x08, 0x05, 0x00, 0x54, 0x65, 0x78, 0x74,
                0x32, 0x0b, 0x00, 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x08,
                0x05, 0x00, 0x54, 0x65, 0x78, 0x74, 0x33, 0x0a, 0x00, 0x74, 0x68, 0x69, 0x72, 0x64, 0x20,
                0x6c, 0x69, 0x6e, 0x65, 0x08, 0x05, 0x00, 0x54, 0x65, 0x78, 0x74, 0x34, 0x0a, 0x00, 0x66,
                0x6f, 0x72, 0x74, 0x68, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x00,
            };
        }
Esempio n. 8
0
 public void HandleMcpeBlockEntityData(McpeBlockEntityData message)
 {
 }
 public abstract void HandleMcpeBlockEntityData(McpeBlockEntityData message);
        public void OpenInventory(Player player)
        {
            //Log.Info("Command Executed!");
            player.SendMessage("Opening Chest...");

            /*BlockCoordinates coords = (BlockCoordinates) player.KnownPosition;
             * coords.Y = 0;*/
            BlockCoordinates coords = new BlockCoordinates(0);

            //Block past = player.Level.GetBlock(coords);

            McpeUpdateBlock chest = Package <McpeUpdateBlock> .CreateObject();

            chest.blockId              = 54;
            chest.coordinates          = coords;
            chest.blockMetaAndPriority = 0 & 15;
            player.SendPackage(chest);

            ChestBlockEntity blockEntity = new ChestBlockEntity {
                Coordinates = coords
            };
            NbtCompound compound = blockEntity.GetCompound();

            compound["CustomName"] = new NbtString("CustomName", "§5§k--§r §l§o§2Virtual Chest§r §5§k--§r");
            //player.Level.SetBlockEntity(blockEntity);
            McpeBlockEntityData chestEntity = Package <McpeBlockEntityData> .CreateObject();

            chestEntity.namedtag = new Nbt
            {
                NbtFile = new NbtFile
                {
                    BigEndian = false,
                    UseVarInt = true,
                    RootTag   = compound
                }
            };
            chestEntity.coordinates = coords;
            player.SendPackage(chestEntity);

            //player.OpenInventory(coords);
            Inventory inventory = new Inventory(0, blockEntity, 1, new NbtList())
            {
                Type      = 0,
                WindowsId = 10
            };

            //inventory.InventoryChange += new Action<Player, MiNET.Inventory, byte, Item>(player.OnInventoryChange);
            inventory.AddObserver(player);
            McpeContainerOpen mcpeContainerOpen = Package <McpeContainerOpen> .CreateObject(1L);

            mcpeContainerOpen.windowId               = inventory.WindowsId;
            mcpeContainerOpen.type                   = inventory.Type;
            mcpeContainerOpen.coordinates            = coords;
            mcpeContainerOpen.unknownRuntimeEntityId = 1L;
            player.SendPackage((Package)mcpeContainerOpen);
            McpeInventoryContent inventoryContent = Package <McpeInventoryContent> .CreateObject(1L);

            inventoryContent.inventoryId = (uint)inventory.WindowsId;
            inventoryContent.input       = inventory.Slots;
            player.SendPackage((Package)inventoryContent);
        }
 public void HandleMcpeBlockEntityData(McpeBlockEntityData message)
 {
     WritePackage(message);
 }
Esempio n. 12
0
        public void DisplaySelection(bool forceDisplay = false, bool forceHide = false)
        {
            if (!forceDisplay && _structureBlockBlockEntity != null && (forceHide || _structureBlockBlockEntity.ShowBoundingBox != ShowSelection))
            {
                bool showBoundingBox = !forceHide && ShowSelection;
                if (_structureBlockBlockEntity.ShowBoundingBox == showBoundingBox)
                {
                    return;
                }

                _structureBlockBlockEntity.ShowBoundingBox = showBoundingBox;

                var nbt = new Nbt
                {
                    NbtFile = new NbtFile
                    {
                        BigEndian = false,
                        UseVarInt = true,
                        RootTag   = _structureBlockBlockEntity.GetCompound()
                    }
                };

                var entityData = McpeBlockEntityData.CreateObject();
                entityData.namedtag    = nbt;
                entityData.coordinates = _structureBlockBlockEntity.Coordinates;
                Player.SendPacket(entityData);
            }

            if (forceHide)
            {
                return;
            }

            if (!forceDisplay && !ShowSelection)
            {
                return;                                              // don't render at all
            }
            if (forceDisplay && ShowSelection)
            {
                return;                                            // Will be rendered on regular tick instead
            }
            if (!Monitor.TryEnter(_sync))
            {
                return;
            }

            try
            {
                BoundingBox box = GetSelection().GetAdjustedBoundingBox();
                if (!forceDisplay && box == _currentDisplayedSelection)
                {
                    return;
                }
                _currentDisplayedSelection = box;

                int minX = (int)Math.Min(box.Min.X, box.Max.X);
                int maxX = (int)(Math.Max(box.Min.X, box.Max.X) + 1);

                int minY = (int)Math.Max(0, Math.Min(box.Min.Y, box.Max.Y));
                int maxY = (int)(Math.Min(255, Math.Max(box.Min.Y, box.Max.Y)) + 1);

                int minZ = (int)Math.Min(box.Min.Z, box.Max.Z);
                int maxZ = (int)(Math.Max(box.Min.Z, box.Max.Z) + 1);

                int width  = maxX - minX;
                int height = maxY - minY;
                int depth  = maxZ - minZ;

                if (_structureBlock != null)
                {
                    {
                        var block       = Player.Level.GetBlock(_structureBlock.Coordinates);
                        var updateBlock = McpeUpdateBlock.CreateObject();
                        updateBlock.blockRuntimeId = (uint)block.GetRuntimeId();
                        updateBlock.coordinates    = _structureBlock.Coordinates;
                        updateBlock.blockPriority  = 0xb;
                        Player.SendPacket(updateBlock);
                    }

                    _structureBlock            = null;
                    _structureBlockBlockEntity = null;
                }

                _structureBlock = new StructureBlock
                {
                    StructureBlockType = "save",
                    Coordinates        = new BlockCoordinates(minX, 255, minZ),
                };

                {
                    var updateBlock = McpeUpdateBlock.CreateObject();
                    updateBlock.blockRuntimeId = (uint)_structureBlock.GetRuntimeId();
                    updateBlock.coordinates    = _structureBlock.Coordinates;
                    updateBlock.blockPriority  = 0xb;
                    Player.SendPacket(updateBlock);
                }

                _structureBlockBlockEntity = new StructureBlockBlockEntity
                {
                    ShowBoundingBox = true,
                    Coordinates     = _structureBlock.Coordinates,
                    Offset          = new BlockCoordinates(0, minY - _structureBlock.Coordinates.Y, 0),
                    Size            = new BlockCoordinates(width, height, depth)
                };

                {
                    Log.Debug($"Structure:\n{box}\n{_structureBlockBlockEntity.GetCompound()}");
                    var nbt = new Nbt
                    {
                        NbtFile = new NbtFile
                        {
                            BigEndian = false,
                            UseVarInt = true,
                            RootTag   = _structureBlockBlockEntity.GetCompound()
                        }
                    };

                    var entityData = McpeBlockEntityData.CreateObject();
                    entityData.namedtag    = nbt;
                    entityData.coordinates = _structureBlockBlockEntity.Coordinates;
                    Player.SendPacket(entityData);
                }

                return;
            }
            catch (Exception e)
            {
                Log.Error("Display selection", e);
            }
            finally
            {
                Monitor.Exit(_sync);
            }
        }
Esempio n. 13
0
 public override void HandleMcpeBlockEntityData(McpeBlockEntityData message)
 {
     UnhandledPackage(message);
 }
Esempio n. 14
0
 public override void HandleMcpeBlockEntityData(McpeBlockEntityData message)
 {
 }
Esempio n. 15
0
 public void HandleMcpeBlockEntityData(McpeBlockEntityData message)
 {
 }