Exemplo n.º 1
0
        public override bool PlaceBlock(Level world, Player player, BlockCoordinates targetCoordinates, BlockFace face, Vector3 faceCoords)
        {
            int size = Metadata;

            if (size == 0)
            {
                Metadata = (byte)((int)(Math.Floor((player.KnownPosition.Yaw + 180) * 16 / 360) + 0.5) & 0x0f);

                var block = new Chalkboard
                {
                    Coordinates = Coordinates,
                    Metadata    = Metadata
                };
                world.SetBlock(block);

                var blockEntity = new ChalkboardBlockEntity
                {
                    BaseCoordinates = Coordinates,
                    Coordinates     = Coordinates,
                    Owner           = player.EntityId,
                    Size            = size,
                    OnGround        = true,
                };

                world.SetBlockEntity(blockEntity);
            }
            else if (size == 1)
            {
                Metadata = (byte)((int)(Math.Floor((player.KnownPosition.Yaw + 180) * 4 / 360) + 0.5) & 0x0f);

                var current = Coordinates;

                for (int x = 0; x < 2; x++)
                {
                    var block = new Chalkboard
                    {
                        Coordinates = current + GetDirCoord() * x,
                        Metadata    = Metadata
                    };
                    world.SetBlock(block);
                    var blockEntity = new ChalkboardBlockEntity
                    {
                        BaseCoordinates = Coordinates,
                        Coordinates     = current + GetDirCoord() * x,
                        Owner           = player.EntityId,
                        Size            = size,
                        OnGround        = true,
                    };
                    world.SetBlockEntity(blockEntity);
                }
            }
            else if (size == 2)
            {
                Metadata = (byte)((int)(Math.Floor((player.KnownPosition.Yaw + 180) * 4 / 360) + 0.5) & 0x0f);

                for (int y = 0; y < 2; y++)
                {
                    var current = Coordinates + BlockCoordinates.Up * y;

                    for (int x = -1; x < 2; x++)
                    {
                        var block = new Chalkboard
                        {
                            Coordinates = current + GetDirCoord() * x,
                            Metadata    = Metadata
                        };
                        world.SetBlock(block);
                        var blockEntity = new ChalkboardBlockEntity
                        {
                            BaseCoordinates = Coordinates,
                            Coordinates     = current + GetDirCoord() * x,
                            Owner           = player.EntityId,
                            Size            = size,
                            OnGround        = true,
                        };
                        world.SetBlockEntity(blockEntity);
                    }
                }
            }

            return(true);
        }
Exemplo n.º 2
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);
        }