Beispiel #1
0
        public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel)
        {
            BlockEntity entity = world.BlockAccessor.GetBlockEntity(blockSel.Position);

            if (entity is BlockEntitySign)
            {
                BlockEntitySign besigh = (BlockEntitySign)entity;
                besigh.OpenDialog(byPlayer);
                return(true);
            }

            return(true);
        }
        public override bool TryPlaceBlock(IWorldAccessor world, IPlayer byPlayer, ItemStack itemstack, BlockSelection bs, ref string failureCode)
        {
            BlockPos supportingPos   = bs.Position.AddCopy(bs.Face.Opposite);
            Block    supportingBlock = world.BlockAccessor.GetBlock(supportingPos);

            if (bs.Face.IsHorizontal && (supportingBlock.CanAttachBlockAt(world.BlockAccessor, this, supportingPos, bs.Face) || supportingBlock.Attributes?.IsTrue("partialAttachable") == true))
            {
                Block wallblock = world.BlockAccessor.GetBlock(CodeWithParts("wall", bs.Face.Opposite.Code));

                if (!wallblock.CanPlaceBlock(world, byPlayer, bs, ref failureCode))
                {
                    return(false);
                }

                world.BlockAccessor.SetBlock(wallblock.BlockId, bs.Position);
                return(true);
            }



            if (!CanPlaceBlock(world, byPlayer, bs, ref failureCode))
            {
                return(false);
            }

            BlockFacing[] horVer = SuggestedHVOrientation(byPlayer, bs);

            AssetLocation blockCode = CodeWithParts(horVer[0].Code);
            Block         block     = world.BlockAccessor.GetBlock(blockCode);

            world.BlockAccessor.SetBlock(block.BlockId, bs.Position);

            BlockEntitySign bect = world.BlockAccessor.GetBlockEntity(bs.Position) as BlockEntitySign;

            if (bect != null)
            {
                BlockPos targetPos = bs.DidOffset ? bs.Position.AddCopy(bs.Face.Opposite) : bs.Position;
                double   dx        = byPlayer.Entity.Pos.X - (targetPos.X + bs.HitPosition.X);
                double   dz        = (float)byPlayer.Entity.Pos.Z - (targetPos.Z + bs.HitPosition.Z);
                float    angleHor  = (float)Math.Atan2(dx, dz);

                float deg45    = GameMath.PIHALF / 2;
                float roundRad = ((int)Math.Round(angleHor / deg45)) * deg45;
                bect.MeshAngleRad = roundRad;
            }


            return(true);
        }
        public override Cuboidf[] GetSelectionBoxes(IBlockAccessor blockAccessor, BlockPos pos)
        {
            if (Variant["attachment"] == "wall")
            {
                return(base.GetCollisionBoxes(blockAccessor, pos));
            }

            BlockEntitySign besign = blockAccessor.GetBlockEntity(pos) as BlockEntitySign;

            if (besign != null)
            {
                return(besign.colSelBox);
            }
            return(base.GetSelectionBoxes(blockAccessor, pos));
        }