示例#1
0
        public override bool PlaceBlock(Level world, Player player, BlockCoordinates targetCoordinates, BlockFace face, Vector3 faceCoords)
        {
            var blockEntity = new StructureBlockBlockEntity {
                Coordinates = Coordinates
            };

            world.SetBlockEntity(blockEntity);

            return(false);
        }
示例#2
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);
            }
        }
示例#3
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);
        }