Translations:Modding:Adding Block Behavior/40/en
From Vintage Story Wiki
The next thing we need to change is the interact method itself, so that it takes care of the distance and the pull properties ...
public override bool OnPlayerInteract(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel, ref EnumHandling handling)
{
BlockPos pos = blockSel.Position.AddCopy(pull && byPlayer.WorldData.EntityControls.Sneak ? blockSel.Face : blockSel.Face.GetOpposite(), distance);
if (world.BlockAccessor.GetBlock(pos).IsReplacableBy(block))
{
world.BlockAccessor.SetBlock(0, blockSel.Position);
world.BlockAccessor.SetBlock(block.BlockId, pos);
}
handling = EnumHandling.PreventDefault;
return true;
}