Make weapon attachments unremovable?

Hi, 
I created a weapon and add attachments to it like this.

player.GiveItem(gun, BaseEntity.GiveItemReason.PickedUp);
gun.MoveToContainer(player.inventory.containerBelt, 0);
var holo = ItemManager.CreateByName("weapon.mod.holosight", 1);
var light = ItemManager.CreateByName("weapon.mod.flashlight", 1);
holo.MoveToContainer(gun.contents);
light.MoveToContainer(gun.contents);​

I was wondering if anybody knew a way to make it so that a player cant take the attachments off.

You can lock the weapon inventory (weaponItem.contents.SetLocked(true)). I have an example of this in Turret Loadouts.

https://github.com/WheteThunger/TurretLoadouts/blob/55ba5d3733c8fdbe5540fb05d9b7b344e870ccba/TurretLoadouts.cs#L127

Generally when locking things that the game doesn't normally lock, there can be some edge cases where right-clicking an item for instance can still move the item, but you can fix such cases with the CanMoveItem hook. I don't believe that was needed in this case though.

Well you can try to set them locked as item or lock weapon container itself, or maybe make weapon container 0 size after adding mods